From e9b67d281a3a1e740217ded7df9fc292f5ba6559 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sat, 6 Jun 2020 18:26:15 +0100 Subject: [PATCH 1/3] Fix link error with #[thread_local] introduced by #71192 --- src/librustc_mir/monomorphize/collector.rs | 8 ++++++++ src/test/ui/tls.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/test/ui/tls.rs diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 297b899ef0bd6..e0e9bea5eb225 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -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 */ } } diff --git a/src/test/ui/tls.rs b/src/test/ui/tls.rs new file mode 100644 index 0000000000000..cfc94c10c9e9b --- /dev/null +++ b/src/test/ui/tls.rs @@ -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); +} From 2af53e9a15aed1e9798867c9233a722530d03177 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 10 Jun 2020 22:11:17 +0100 Subject: [PATCH 2/3] Add -O compile flag to test --- src/test/ui/tls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/tls.rs b/src/test/ui/tls.rs index cfc94c10c9e9b..c696318e70f5f 100644 --- a/src/test/ui/tls.rs +++ b/src/test/ui/tls.rs @@ -1,4 +1,5 @@ // run-pass +// compile-flags: -O #![feature(thread_local)] From 01e29c778c3749bca42e38adaad5a5ff58449031 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Sat, 13 Jun 2020 13:24:19 +0100 Subject: [PATCH 3/3] Don't run test on emscripten which doesn't have threads --- src/test/ui/tls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/tls.rs b/src/test/ui/tls.rs index c696318e70f5f..fbd3413885f8f 100644 --- a/src/test/ui/tls.rs +++ b/src/test/ui/tls.rs @@ -1,4 +1,5 @@ // run-pass +// ignore-emscripten no threads support // compile-flags: -O #![feature(thread_local)]