Skip to content

Commit c7af4e6

Browse files
Rollup merge of #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 #96623.
2 parents fcb0bce + e626634 commit c7af4e6

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
@@ -445,12 +445,9 @@ fn collect_items_rec<'tcx>(
445445
// depend on any other items.
446446
}
447447
hir::InlineAsmOperand::SymFn { anon_const } => {
448-
let def_id = tcx.hir().body_owner_def_id(anon_const.body).to_def_id();
449-
if let Ok(val) = tcx.const_eval_poly(def_id) {
450-
rustc_data_structures::stack::ensure_sufficient_stack(|| {
451-
collect_const_value(tcx, val, &mut neighbors);
452-
});
453-
}
448+
let fn_ty =
449+
tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
450+
visit_fn_use(tcx, fn_ty, false, *op_sp, &mut neighbors);
454451
}
455452
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
456453
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)