Skip to content

Commit 47449a8

Browse files
authored
Rollup merge of rust-lang#140374 - compiler-errors:global_asm-bug, r=lcnr
Resolve instance for SymFn in global/naked asm `Instance::expect_resolve` ensures that we're actually going from trait item -> impl item. Fixes rust-lang#140373
2 parents f56ac14 + 8f55844 commit 47449a8

File tree

22 files changed

+116
-32
lines changed

22 files changed

+116
-32
lines changed

compiler/rustc_codegen_cranelift/src/global_asm.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
6565

6666
let ty = tcx.typeck(item_id.owner_id).expr_ty(expr);
6767
let instance = match ty.kind() {
68-
&ty::FnDef(def_id, args) => Instance::new(def_id, args),
68+
&ty::FnDef(def_id, args) => Instance::expect_resolve(
69+
tcx,
70+
ty::TypingEnv::fully_monomorphized(),
71+
def_id,
72+
args,
73+
expr.span,
74+
),
6975
_ => span_bug!(op_sp, "asm sym is not a function"),
7076
};
7177
let symbol = tcx.symbol_name(instance);

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
12821282
intrinsic.name,
12831283
);
12841284
}
1285-
return Err(Instance::new(instance.def_id(), instance.args));
1285+
return Err(Instance::new_raw(instance.def_id(), instance.args));
12861286
}
12871287
}
12881288

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
399399
}
400400

401401
// Fall back to default body
402-
_ => return Err(Instance::new(instance.def_id(), instance.args)),
402+
_ => return Err(Instance::new_raw(instance.def_id(), instance.args)),
403403
};
404404

405405
if !fn_abi.ret.is_ignore() {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn make_dummy_instance<'tcx>(tcx: TyCtxt<'tcx>, local_def_id: LocalDefId) -> ty:
157157
let def_id = local_def_id.to_def_id();
158158

159159
// Make a dummy instance that fills in all generics with placeholders.
160-
ty::Instance::new(
160+
ty::Instance::new_raw(
161161
def_id,
162162
ty::GenericArgs::for_item(tcx, def_id, |param, _| {
163163
if let ty::GenericParamDefKind::Lifetime = param.kind {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
613613
_ => {
614614
debug!("unknown intrinsic '{}' -- falling back to default body", name);
615615
// Call the fallback body instead of generating the intrinsic code
616-
return Err(ty::Instance::new(instance.def_id(), instance.args));
616+
return Err(ty::Instance::new_raw(instance.def_id(), instance.args));
617617
}
618618
};
619619

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>(
565565
ExportedSymbol::Generic(def_id, args) => {
566566
rustc_symbol_mangling::symbol_name_for_instance_in_crate(
567567
tcx,
568-
Instance::new(def_id, args),
568+
Instance::new_raw(def_id, args),
569569
instantiating_crate,
570570
)
571571
}
@@ -613,7 +613,7 @@ fn calling_convention_for_symbol<'tcx>(
613613
None
614614
}
615615
ExportedSymbol::NonGeneric(def_id) => Some(Instance::mono(tcx, def_id)),
616-
ExportedSymbol::Generic(def_id, args) => Some(Instance::new(def_id, args)),
616+
ExportedSymbol::Generic(def_id, args) => Some(Instance::new_raw(def_id, args)),
617617
// DropGlue always use the Rust calling convention and thus follow the target's default
618618
// symbol decoration scheme.
619619
ExportedSymbol::DropGlue(..) => None,

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ fn inline_to_global_operand<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
8686
);
8787

8888
let instance = match mono_type.kind() {
89-
&ty::FnDef(def_id, args) => Instance::new(def_id, args),
89+
&ty::FnDef(def_id, args) => {
90+
Instance::expect_resolve(cx.tcx(), cx.typing_env(), def_id, args, value.span)
91+
}
9092
_ => bug!("asm sym is not a function"),
9193
};
9294

compiler/rustc_codegen_ssa/src/mono_item.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
7474
hir::InlineAsmOperand::SymFn { expr } => {
7575
let ty = cx.tcx().typeck(item_id.owner_id).expr_ty(expr);
7676
let instance = match ty.kind() {
77-
&ty::FnDef(def_id, args) => Instance::new(def_id, args),
77+
&ty::FnDef(def_id, args) => Instance::expect_resolve(
78+
cx.tcx(),
79+
ty::TypingEnv::fully_monomorphized(),
80+
def_id,
81+
args,
82+
expr.span,
83+
),
7884
_ => span_bug!(*op_sp, "asm sym is not a function"),
7985
};
8086

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
216216
check::maybe_check_static_with_link_section(tcx, item_def_id);
217217
}
218218
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
219-
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
219+
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
220220
let cid = GlobalId { instance, promoted: None };
221221
let typing_env = ty::TypingEnv::fully_monomorphized();
222222
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));

compiler/rustc_lint/src/foreign_modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl ClashingExternDeclarations {
104104
/// for the item, return its HirId without updating the set.
105105
fn insert(&mut self, tcx: TyCtxt<'_>, fi: hir::ForeignItemId) -> Option<hir::OwnerId> {
106106
let did = fi.owner_id.to_def_id();
107-
let instance = Instance::new(did, ty::List::identity_for_item(tcx, did));
107+
let instance = Instance::new_raw(did, ty::List::identity_for_item(tcx, did));
108108
let name = Symbol::intern(tcx.symbol_name(instance).name);
109109
if let Some(&existing_id) = self.seen_decls.get(&name) {
110110
// Avoid updating the map with the new entry when we do find a collision. We want to

0 commit comments

Comments
 (0)