Fix link error with #[thread_local] introduced by #71192

This commit is contained in:
Amanieu d'Antras 2020-06-06 18:26:15 +01:00
parent 826cb062a6
commit e9b67d281a
2 changed files with 20 additions and 0 deletions

View File

@ -586,6 +586,14 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
self.output.push(create_fn_mono_item(instance));
}
}
mir::Rvalue::ThreadLocalRef(def_id) => {
assert!(self.tcx.is_thread_local_static(def_id));
let instance = Instance::mono(self.tcx, def_id);
if should_monomorphize_locally(self.tcx, &instance) {
trace!("collecting thread-local static {:?}", def_id);
self.output.push(MonoItem::Static(def_id));
}
}
_ => { /* not interesting */ }
}

12
src/test/ui/tls.rs Normal file
View File

@ -0,0 +1,12 @@
// run-pass
#![feature(thread_local)]
#[thread_local]
static S: u32 = 222;
fn main() {
let local = &S as *const u32 as usize;
let foreign = std::thread::spawn(|| &S as *const u32 as usize).join().unwrap();
assert_ne!(local, foreign);
}