Skip to content

Commit

Permalink
Auto merge of rust-lang#3822 - RalfJung:tls, r=RalfJung
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Aug 17, 2024
2 parents 0058752 + bd4ef64 commit 3e698d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/tools/miri/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions src/tools/miri/tests/pass/tls/tls_leak_main_thread_allowed.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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))));
});
}
}

0 comments on commit 3e698d0

Please sign in to comment.