about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-17 14:45:42 +0000
committerbors <bors@rust-lang.org>2024-08-17 14:45:42 +0000
commit3e698d0287f2fd5635666f26e5f866712d4c9f6a (patch)
tree4a170dab68a1f622988b53145b7ec58970caa16e
parent00587529867b9b93505397c7885178b656c35499 (diff)
parentbd4ef64a60f2c49b9ca2ea6fe394364177033ae6 (diff)
downloadrust-3e698d0287f2fd5635666f26e5f866712d4c9f6a.tar.gz
rust-3e698d0287f2fd5635666f26e5f866712d4c9f6a.zip
Auto merge of #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.
-rwxr-xr-xsrc/tools/miri/ci/ci.sh4
-rw-r--r--src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs23
2 files changed, 15 insertions, 12 deletions
diff --git a/src/tools/miri/ci/ci.sh b/src/tools/miri/ci/ci.sh
index 3e90ecc5c03..1f66b6fa776 100755
--- a/src/tools/miri/ci/ci.sh
+++ b/src/tools/miri/ci/ci.sh
@@ -150,8 +150,8 @@ case $HOST_TARGET in
     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
     TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
     TEST_TARGET=i686-unknown-freebsd   run_tests_minimal $BASIC $UNIX threadname libc-time fs
-    TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
-    TEST_TARGET=x86_64-pc-solaris      run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time
+    TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
+    TEST_TARGET=x86_64-pc-solaris      run_tests_minimal $BASIC $UNIX threadname pthread-sync available-parallelism libc-time tls
     TEST_TARGET=aarch64-linux-android  run_tests_minimal $BASIC $UNIX
     TEST_TARGET=wasm32-wasip2          run_tests_minimal empty_main wasm heap_alloc libc-mem
     TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm
diff --git a/src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs b/src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs
index 7732e3f9217..341b2280e01 100644
--- a/src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs
+++ b/src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs
@@ -1,5 +1,4 @@
-//@ignore-target-windows: Windows uses a different mechanism for `thread_local!`
-#![feature(thread_local)]
+#![feature(thread_local, cfg_target_thread_local)]
 
 use std::cell::Cell;
 
@@ -8,16 +7,20 @@ use std::cell::Cell;
 //
 // The test covers both TLS statics and the TLS macro.
 pub fn main() {
-    thread_local! {
-        static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
-    }
-
-    TLS_KEY.with(|cell| {
-        cell.set(Some(Box::leak(Box::new(123))));
-    });
-
     #[thread_local]
     static TLS: Cell<Option<&'static i32>> = Cell::new(None);
 
     TLS.set(Some(Box::leak(Box::new(123))));
+
+    // We can only ignore leaks on targets that use `#[thread_local]` statics to implement
+    // `thread_local!`. Ignore the test on targest that don't.
+    if cfg!(target_thread_local) {
+        thread_local! {
+            static TLS_KEY: Cell<Option<&'static i32>> = Cell::new(None);
+        }
+
+        TLS_KEY.with(|cell| {
+            cell.set(Some(Box::leak(Box::new(123))));
+        });
+    }
 }