Skip to content

Commit 43ae54d

Browse files
authored
Rollup merge of rust-lang#72521 - Amanieu:fix-72484, r=petrochenkov
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items Fixes rust-lang#72484
2 parents 8d64fd8 + 3ed1e79 commit 43ae54d

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/librustc_codegen_ssa/mir/block.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
908908
mir::InlineAsmOperand::SymFn { ref value } => {
909909
let literal = self.monomorphize(&value.literal);
910910
if let ty::FnDef(def_id, substs) = literal.ty.kind {
911-
let instance = ty::Instance::resolve(
911+
let instance = ty::Instance::resolve_for_fn_ptr(
912912
bx.tcx(),
913913
ty::ParamEnv::reveal_all(),
914914
def_id,
915915
substs,
916916
)
917-
.unwrap()
918917
.unwrap();
919918
InlineAsmOperandRef::SymFn { instance }
920919
} else {

src/librustc_mir/monomorphize/collector.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,21 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
632632
let ty = self.monomorphize(ty);
633633
visit_drop_use(self.tcx, ty, true, self.output);
634634
}
635+
mir::TerminatorKind::InlineAsm { ref operands, .. } => {
636+
for op in operands {
637+
if let mir::InlineAsmOperand::SymFn { value } = op {
638+
let fn_ty = self.monomorphize(value.literal.ty);
639+
visit_fn_use(self.tcx, fn_ty, false, &mut self.output);
640+
}
641+
}
642+
}
635643
mir::TerminatorKind::Goto { .. }
636644
| mir::TerminatorKind::SwitchInt { .. }
637645
| mir::TerminatorKind::Resume
638646
| mir::TerminatorKind::Abort
639647
| mir::TerminatorKind::Return
640648
| mir::TerminatorKind::Unreachable
641-
| mir::TerminatorKind::Assert { .. }
642-
| mir::TerminatorKind::InlineAsm { .. } => {}
649+
| mir::TerminatorKind::Assert { .. } => {}
643650
mir::TerminatorKind::GeneratorDrop
644651
| mir::TerminatorKind::Yield { .. }
645652
| mir::TerminatorKind::FalseEdges { .. }

src/test/ui/asm/sym.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// no-system-llvm
2+
// only-x86_64
3+
// run-pass
4+
5+
#![feature(asm, track_caller)]
6+
7+
extern "C" fn f1() -> i32 {
8+
111
9+
}
10+
11+
// The compiler will generate a shim to hide the caller location parameter.
12+
#[track_caller]
13+
fn f2() -> i32 {
14+
222
15+
}
16+
17+
macro_rules! call {
18+
($func:path) => {{
19+
let result: i32;
20+
unsafe {
21+
asm!("call {}", sym $func,
22+
out("rax") result,
23+
out("rcx") _, out("rdx") _, out("rdi") _, out("rsi") _,
24+
out("r8") _, out("r9") _, out("r10") _, out("r11") _,
25+
out("xmm0") _, out("xmm1") _, out("xmm2") _, out("xmm3") _,
26+
out("xmm4") _, out("xmm5") _, out("xmm6") _, out("xmm7") _,
27+
out("xmm8") _, out("xmm9") _, out("xmm10") _, out("xmm11") _,
28+
out("xmm12") _, out("xmm13") _, out("xmm14") _, out("xmm15") _,
29+
);
30+
}
31+
result
32+
}}
33+
}
34+
35+
fn main() {
36+
assert_eq!(call!(f1), 111);
37+
assert_eq!(call!(f2), 222);
38+
}

0 commit comments

Comments
 (0)