Skip to content

Commit 63915be

Browse files
committed
Statics used in reachable function's inline asm are reachable
1 parent 8a09420 commit 63915be

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

compiler/rustc_passes/src/reachable.rs

+11
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
116116

117117
intravisit::walk_expr(self, expr)
118118
}
119+
120+
fn visit_inline_asm(&mut self, asm: &'tcx hir::InlineAsm<'tcx>, id: hir::HirId) {
121+
for (op, _) in asm.operands {
122+
if let hir::InlineAsmOperand::SymStatic { def_id, .. } = op {
123+
if let Some(def_id) = def_id.as_local() {
124+
self.reachable_symbols.insert(def_id);
125+
}
126+
}
127+
}
128+
intravisit::walk_inline_asm(self, asm, id);
129+
}
119130
}
120131

121132
impl<'tcx> ReachableContext<'tcx> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// needs-asm-support
2+
// compile-flags: -Ccodegen-units=1 -Zprint-mono-items=lazy --crate-type=lib
3+
4+
#[inline(always)]
5+
pub unsafe fn f() {
6+
//~ MONO_ITEM static f::S @@ asm_sym-cgu.0[External]
7+
static S: usize = 1;
8+
//~ MONO_ITEM fn f::fun @@ asm_sym-cgu.0[External]
9+
fn fun() {}
10+
core::arch::asm!("/* {0} {1} */", sym S, sym fun);
11+
}
12+
13+
//~ MONO_ITEM fn g @@ asm_sym-cgu.0[External]
14+
pub unsafe fn g() {
15+
//~ MONO_ITEM static g::S @@ asm_sym-cgu.0[Internal]
16+
static S: usize = 2;
17+
//~ MONO_ITEM fn g::fun @@ asm_sym-cgu.0[Internal]
18+
fn fun() {}
19+
core::arch::asm!("/* {0} {1} */", sym S, sym fun);
20+
}

0 commit comments

Comments
 (0)