Skip to content

Commit

Permalink
Auto merge of rust-lang#2929 - RalfJung:tls-panic, r=RalfJung
Browse files Browse the repository at this point in the history
add tests for panicky drop in thread_local destructor

Adds a test for rust-lang#112285
  • Loading branch information
bors committed Jun 16, 2023
2 parents c853744 + f3b52fd commit 6f771c8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tools/miri/tests/fail/panic/thread_local_const_drop_panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@error-in-other-file: aborted execution
// Backtraces vary wildly between platforms, we have to normalize away almost the entire thing.
// Full backtraces avoid annoying empty line differences.
//@compile-flags: -Zmiri-backtrace=full
//@normalize-stderr-test: "'main'|'<unnamed>'" -> "$$NAME"
//@normalize-stderr-test: ".*(note|-->|\|).*\n" -> ""

pub struct NoisyDrop {}

impl Drop for NoisyDrop {
fn drop(&mut self) {
panic!("ow");
}
}

thread_local! {
pub static NOISY: NoisyDrop = const { NoisyDrop {} };
}

fn main() {
NOISY.with(|_| ());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
thread $NAME panicked at 'ow', $DIR/thread_local_const_drop_panic.rs:LL:CC
fatal runtime error: thread local panicked on drop
error: abnormal termination: the program aborted execution

error: aborting due to previous error

20 changes: 20 additions & 0 deletions src/tools/miri/tests/fail/panic/thread_local_drop_panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@error-in-other-file: aborted execution
// Backtraces vary wildly between platforms, we have to normalize away almost the entire thing
//@normalize-stderr-test: "'main'|'<unnamed>'" -> "$$NAME"
//@normalize-stderr-test: ".*(note|-->|\|).*\n" -> ""

pub struct NoisyDrop {}

impl Drop for NoisyDrop {
fn drop(&mut self) {
panic!("ow");
}
}

thread_local! {
pub static NOISY: NoisyDrop = NoisyDrop {};
}

fn main() {
NOISY.with(|_| ());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
thread $NAME panicked at 'ow', $DIR/thread_local_drop_panic.rs:LL:CC
fatal runtime error: thread local panicked on drop
error: abnormal termination: the program aborted execution

error: aborting due to previous error

0 comments on commit 6f771c8

Please sign in to comment.