Skip to content

Commit

Permalink
Auto merge of #73065 - Amanieu:tls-fix, r=oli-obk
Browse files Browse the repository at this point in the history
Fix link error with #[thread_local] introduced by #71192

r? @oli-obk
  • Loading branch information
bors committed Jun 18, 2020
2 parents 2935d29 + 01e29c7 commit 7d16c1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ }
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/tls.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 7d16c1d

Please sign in to comment.