Skip to content

Commit 7d16c1d

Browse files
committed
Auto merge of #73065 - Amanieu:tls-fix, r=oli-obk
Fix link error with #[thread_local] introduced by #71192 r? @oli-obk
2 parents 2935d29 + 01e29c7 commit 7d16c1d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Diff for: src/librustc_mir/monomorphize/collector.rs

+8
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,14 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
586586
self.output.push(create_fn_mono_item(instance));
587587
}
588588
}
589+
mir::Rvalue::ThreadLocalRef(def_id) => {
590+
assert!(self.tcx.is_thread_local_static(def_id));
591+
let instance = Instance::mono(self.tcx, def_id);
592+
if should_monomorphize_locally(self.tcx, &instance) {
593+
trace!("collecting thread-local static {:?}", def_id);
594+
self.output.push(MonoItem::Static(def_id));
595+
}
596+
}
589597
_ => { /* not interesting */ }
590598
}
591599

Diff for: src/test/ui/tls.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
// ignore-emscripten no threads support
3+
// compile-flags: -O
4+
5+
#![feature(thread_local)]
6+
7+
#[thread_local]
8+
static S: u32 = 222;
9+
10+
fn main() {
11+
let local = &S as *const u32 as usize;
12+
let foreign = std::thread::spawn(|| &S as *const u32 as usize).join().unwrap();
13+
assert_ne!(local, foreign);
14+
}

0 commit comments

Comments
 (0)