Skip to content

Commit 9713294

Browse files
committed
Auto merge of rust-lang#3501 - RalfJung:tls-many-seeds, r=RalfJung
add a test for the TLS memory leak This is a regression test for rust-lang#123583.
2 parents e22a73c + 247e82c commit 9713294

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

src/tools/miri/ci/ci.sh

+11-7
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,18 @@ function run_tests_minimal {
128128
## Main Testing Logic ##
129129

130130
# In particular, fully cover all tier 1 targets.
131+
# We also want to run the many-seeds tests on all tier 1 targets.
131132
case $HOST_TARGET in
132133
x86_64-unknown-linux-gnu)
133134
# Host
134135
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
135136
# Extra tier 1
136-
MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
137-
MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
138-
MIRI_TEST_TARGET=x86_64-apple-darwin run_tests
139-
MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
140-
MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
137+
# With reduced many-seed count to avoid spending too much time on that.
138+
# (All OSes are run with 64 seeds at least once though via the macOS runner.)
139+
MANY_SEEDS=16 MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
140+
MANY_SEEDS=16 MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
141+
MANY_SEEDS=16 MIRI_TEST_TARGET=x86_64-apple-darwin run_tests
142+
MANY_SEEDS=16 MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
141143
# Extra tier 2
142144
MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
143145
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
@@ -155,13 +157,15 @@ case $HOST_TARGET in
155157
# Host (tier 2)
156158
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
157159
# Extra tier 1
158-
MIRI_TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
160+
MANY_SEEDS=64 MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
161+
MANY_SEEDS=64 MIRI_TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
159162
# Extra tier 2
160163
MIRI_TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture
161164
;;
162165
i686-pc-windows-msvc)
163166
# Host
164-
# Only smoke-test `many-seeds`; 64 runs take 15min here!
167+
# Only smoke-test `many-seeds`; 64 runs of just the scoped-thread-leak test take 15min here!
168+
# See <https://github.com/rust-lang/miri/issues/3509>.
165169
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=1 TEST_BENCH=1 run_tests
166170
# Extra tier 1
167171
# We really want to ensure a Linux target works on a Windows host,

src/tools/miri/src/concurrency/weak_memory.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
520520
validate,
521521
)?;
522522
if global.track_outdated_loads && recency == LoadRecency::Outdated {
523-
this.emit_diagnostic(NonHaltingDiagnostic::WeakMemoryOutdatedLoad);
523+
this.emit_diagnostic(NonHaltingDiagnostic::WeakMemoryOutdatedLoad {
524+
ptr: place.ptr(),
525+
});
524526
}
525527

526528
return Ok(loaded);

src/tools/miri/src/diagnostics.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ pub enum NonHaltingDiagnostic {
125125
Int2Ptr {
126126
details: bool,
127127
},
128-
WeakMemoryOutdatedLoad,
128+
WeakMemoryOutdatedLoad {
129+
ptr: Pointer<Option<Provenance>>,
130+
},
129131
}
130132

131133
/// Level of Miri specific diagnostics
@@ -583,7 +585,8 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
583585
| AccessedAlloc(..)
584586
| FreedAlloc(..)
585587
| ProgressReport { .. }
586-
| WeakMemoryOutdatedLoad => ("tracking was triggered".to_string(), DiagLevel::Note),
588+
| WeakMemoryOutdatedLoad { .. } =>
589+
("tracking was triggered".to_string(), DiagLevel::Note),
587590
};
588591

589592
let msg = match &e {
@@ -610,8 +613,8 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
610613
ProgressReport { .. } =>
611614
format!("progress report: current operation being executed is here"),
612615
Int2Ptr { .. } => format!("integer-to-pointer cast"),
613-
WeakMemoryOutdatedLoad =>
614-
format!("weak memory emulation: outdated value returned from load"),
616+
WeakMemoryOutdatedLoad { ptr } =>
617+
format!("weak memory emulation: outdated value returned from load at {ptr}"),
615618
};
616619

617620
let notes = match &e {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/123583>.
2+
use std::thread;
3+
4+
fn with_thread_local1() {
5+
thread_local! { static X: Box<u8> = Box::new(0); }
6+
X.with(|_x| {})
7+
}
8+
9+
fn with_thread_local2() {
10+
thread_local! { static Y: Box<u8> = Box::new(0); }
11+
Y.with(|_y| {})
12+
}
13+
14+
fn main() {
15+
// Here we have two threads racing on initializing the thread-local and adding it to the global
16+
// dtor list (on targets that have such a list, i.e., targets without target_thread_local).
17+
let t = thread::spawn(with_thread_local1);
18+
with_thread_local1();
19+
t.join().unwrap();
20+
21+
// Here we have one thread running the destructors racing with another thread initializing a
22+
// thread-local. The second thread adds a destructor that could be picked up by the first.
23+
let t = thread::spawn(|| { /* immediately just run destructors */ });
24+
with_thread_local2(); // initialize thread-local
25+
t.join().unwrap();
26+
}

0 commit comments

Comments
 (0)