Skip to content

Commit f838699

Browse files
Rollup merge of rust-lang#96650 - tmiasko:global-asm-sym-fn, r=Amanieu
Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. Fixes rust-lang#96623.
2 parents 3fcb6ab + e626634 commit f838699

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compiler/rustc_monomorphize/src/collector.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,9 @@ fn collect_items_rec<'tcx>(
446446
// depend on any other items.
447447
}
448448
hir::InlineAsmOperand::SymFn { anon_const } => {
449-
let def_id = tcx.hir().body_owner_def_id(anon_const.body).to_def_id();
450-
if let Ok(val) = tcx.const_eval_poly(def_id) {
451-
rustc_data_structures::stack::ensure_sufficient_stack(|| {
452-
collect_const_value(tcx, val, &mut neighbors);
453-
});
454-
}
449+
let fn_ty =
450+
tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
451+
visit_fn_use(tcx, fn_ty, false, *op_sp, &mut neighbors);
455452
}
456453
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
457454
let instance = Instance::mono(tcx, *def_id);

src/test/assembly/asm/global_asm.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// only-linux
33
// assembly-output: emit-asm
44
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
5+
// compile-flags: -C symbol-mangling-version=v0
56

67
#![feature(asm_const, asm_sym)]
78
#![crate_type = "rlib"]
@@ -24,3 +25,7 @@ global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
2425
global_asm!("call {}", sym my_func);
2526
// CHECK: lea rax, [rip + MY_STATIC]
2627
global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
28+
// CHECK: call _RNvCsiubXh4Yz005_10global_asm6foobar
29+
global_asm!("call {}", sym foobar);
30+
// CHECK: _RNvCsiubXh4Yz005_10global_asm6foobar:
31+
fn foobar() { loop {} }

0 commit comments

Comments
 (0)