Skip to content

Commit 74befd9

Browse files
committed
Fix #[thread_local] statics as asm! sym operands
1 parent 2a5cbb0 commit 74befd9

File tree

11 files changed

+78
-45
lines changed

11 files changed

+78
-45
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
921921
span_bug!(span, "invalid type for asm sym (fn)");
922922
}
923923
}
924-
mir::InlineAsmOperand::SymStatic { ref value } => {
925-
if let Some(def_id) = value.check_static_ptr(bx.tcx()) {
926-
InlineAsmOperandRef::SymStatic { def_id }
927-
} else {
928-
span_bug!(span, "invalid type for asm sym (static)");
929-
}
924+
mir::InlineAsmOperand::SymStatic { def_id } => {
925+
InlineAsmOperandRef::SymStatic { def_id }
930926
}
931927
})
932928
.collect();

src/librustc_middle/mir/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ pub enum InlineAsmOperand<'tcx> {
12401240
value: Box<Constant<'tcx>>,
12411241
},
12421242
SymStatic {
1243-
value: Box<Constant<'tcx>>,
1243+
def_id: DefId,
12441244
},
12451245
}
12461246

@@ -1636,9 +1636,11 @@ impl<'tcx> TerminatorKind<'tcx> {
16361636
InlineAsmOperand::Const { value } => {
16371637
write!(fmt, "const {:?}", value)?;
16381638
}
1639-
InlineAsmOperand::SymFn { value }
1640-
| InlineAsmOperand::SymStatic { value } => {
1641-
write!(fmt, "sym {:?}", value)?;
1639+
InlineAsmOperand::SymFn { value } => {
1640+
write!(fmt, "sym_fn {:?}", value)?;
1641+
}
1642+
InlineAsmOperand::SymStatic { def_id } => {
1643+
write!(fmt, "sym_static {:?}", def_id)?;
16421644
}
16431645
}
16441646
}

src/librustc_middle/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,10 @@ macro_rules! make_mir_visitor {
563563
);
564564
}
565565
}
566-
InlineAsmOperand::SymFn { value }
567-
| InlineAsmOperand::SymStatic { value } => {
566+
InlineAsmOperand::SymFn { value } => {
568567
self.visit_constant(value, source_location);
569568
}
569+
InlineAsmOperand::SymStatic { def_id: _ } => {}
570570
}
571571
}
572572
}

src/librustc_mir/borrow_check/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
208208
}
209209
}
210210
InlineAsmOperand::SymFn { value: _ }
211-
| InlineAsmOperand::SymStatic { value: _ } => {}
211+
| InlineAsmOperand::SymStatic { def_id: _ } => {}
212212
}
213213
}
214214
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
759759
}
760760
}
761761
InlineAsmOperand::SymFn { value: _ }
762-
| InlineAsmOperand::SymStatic { value: _ } => {}
762+
| InlineAsmOperand::SymStatic { def_id: _ } => {}
763763
}
764764
}
765765
}

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
439439
}
440440
}
441441
InlineAsmOperand::SymFn { value: _ }
442-
| InlineAsmOperand::SymStatic { value: _ } => {}
442+
| InlineAsmOperand::SymStatic { def_id: _ } => {}
443443
}
444444
}
445445
}

src/librustc_mir/monomorphize/collector.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,19 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
634634
}
635635
mir::TerminatorKind::InlineAsm { ref operands, .. } => {
636636
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);
637+
match *op {
638+
mir::InlineAsmOperand::SymFn { ref value } => {
639+
let fn_ty = self.monomorphize(value.literal.ty);
640+
visit_fn_use(self.tcx, fn_ty, false, &mut self.output);
641+
}
642+
mir::InlineAsmOperand::SymStatic { def_id } => {
643+
let instance = Instance::mono(self.tcx, def_id);
644+
if should_monomorphize_locally(self.tcx, &instance) {
645+
trace!("collecting asm sym static {:?}", def_id);
646+
self.output.push(MonoItem::Static(def_id));
647+
}
648+
}
649+
_ => {}
640650
}
641651
}
642652
}

src/librustc_mir_build/build/expr/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
353353
hair::InlineAsmOperand::SymFn { expr } => {
354354
mir::InlineAsmOperand::SymFn { value: box this.as_constant(expr) }
355355
}
356-
hair::InlineAsmOperand::SymStatic { expr } => {
357-
mir::InlineAsmOperand::SymStatic { value: box this.as_constant(expr) }
356+
hair::InlineAsmOperand::SymStatic { def_id } => {
357+
mir::InlineAsmOperand::SymStatic { def_id }
358358
}
359359
})
360360
.collect();

src/librustc_mir_build/hair/cx/expr.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -465,25 +465,8 @@ fn make_mirror_unadjusted<'a, 'tcx>(
465465
}
466466
}
467467

468-
Res::Def(DefKind::Static, id) => {
469-
ty = cx.tcx.static_ptr_ty(id);
470-
let ptr = cx.tcx.create_static_alloc(id);
471-
InlineAsmOperand::SymStatic {
472-
expr: Expr {
473-
ty,
474-
temp_lifetime,
475-
span: expr.span,
476-
kind: ExprKind::StaticRef {
477-
literal: ty::Const::from_scalar(
478-
cx.tcx,
479-
Scalar::Ptr(ptr.into()),
480-
ty,
481-
),
482-
def_id: id,
483-
},
484-
}
485-
.to_ref(),
486-
}
468+
Res::Def(DefKind::Static, def_id) => {
469+
InlineAsmOperand::SymStatic { def_id }
487470
}
488471

489472
_ => {

src/librustc_mir_build/hair/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ crate enum InlineAsmOperand<'tcx> {
374374
expr: ExprRef<'tcx>,
375375
},
376376
SymStatic {
377-
expr: ExprRef<'tcx>,
377+
def_id: DefId,
378378
},
379379
}
380380

0 commit comments

Comments
 (0)