Skip to content

Commit 3e698d0

Browse files
committed
Auto merge of rust-lang#3822 - RalfJung:tls, r=RalfJung
tls_leak_main_thread_allowed: make test check target_thread_local Instead of ignoring the test entirely on some targets, make the test check the `target_thread_local` flag to determine whether `thread_local!` statics can be tracked by Miri and hence can have main-thread-TLS leaks ignored.
2 parents 0058752 + bd4ef64 commit 3e698d0

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/tools/miri/ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ case $HOST_TARGET in
150150
UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
151151
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
152152
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
153-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
154-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
153+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
154+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
155155
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
156156
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
157157
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//@ignore-target-windows: Windows uses a different mechanism for `thread_local!`
2-
#![feature(thread_local)]
1+
#![feature(thread_local, cfg_target_thread_local)]
32

43
use std::cell::Cell;
54

@@ -8,16 +7,20 @@ use std::cell::Cell;
87
//
98
// The test covers both TLS statics and the TLS macro.
109
pub fn main() {
11-
thread_local! {
12-
static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
13-
}
14-
15-
TLS_KEY.with(|cell| {
16-
cell.set(Some(Box::leak(Box::new(123))));
17-
});
18-
1910
#[thread_local]
2011
static TLS: Cell<Option<&'static i32>> = Cell::new(None);
2112

2213
TLS.set(Some(Box::leak(Box::new(123))));
14+
15+
// We can only ignore leaks on targets that use `#[thread_local]` statics to implement
16+
// `thread_local!`. Ignore the test on targest that don't.
17+
if cfg!(target_thread_local) {
18+
thread_local! {
19+
static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
20+
}
21+
22+
TLS_KEY.with(|cell| {
23+
cell.set(Some(Box::leak(Box::new(123))));
24+
});
25+
}
2326
}

0 commit comments

Comments
 (0)