Skip to content

Commit

Permalink
Rollup merge of rust-lang#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 rust-lang#71192

r? @oli-obk
  • Loading branch information
RalfJung authored Jun 13, 2020
2 parents de144aa + 2af53e9 commit ff4ed9c
Show file tree
Hide file tree
Showing 2 changed files with 21 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
13 changes: 13 additions & 0 deletions src/test/ui/tls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-pass
// 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 ff4ed9c

Please sign in to comment.