Auto merge of #73065 - Amanieu:tls-fix, r=oli-obk

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

r? @oli-obk
This commit is contained in:
bors 2020-06-18 00:29:10 +00:00
commit 7d16c1d5f5
2 changed files with 22 additions and 0 deletions

View File

@ -586,6 +586,14 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {
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 */ }
}

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

@ -0,0 +1,14 @@
// run-pass
// ignore-emscripten no threads support
// compile-flags: -O
#![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);
}