-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Fix runtime UI test that expected drop of panic payload to unwind 2. Add panic payload tests: ensure proper drop, and add one with catch_unwind 3. Add test asserting proper abort of unwind in panic payload
- Loading branch information
1 parent
6d7ee4b
commit 94118a4
Showing
4 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/ui/panics/drop_in_panic_payload_does_not_unwind.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// run-pass | ||
// needs-unwind | ||
// ignore-emscripten no processes | ||
// ignore-sgx no processes | ||
// ignore-wasm32-bare no unwinding panic | ||
// ignore-avr no unwinding panic | ||
// ignore-nvptx64 no unwinding panic | ||
|
||
use std::{env, ops::Not, panic, process}; | ||
|
||
fn main() { | ||
match &env::args().collect::<Vec<_>>()[..] { | ||
[just_me] => parent(just_me), | ||
[_me, subprocess] if subprocess == "panic" => subprocess_panic(), | ||
[_me, subprocess] if subprocess == "resume_unwind" => subprocess_resume_unwind(), | ||
_ => unreachable!(), | ||
} | ||
} | ||
|
||
fn parent(self_exe: &str) { | ||
// call the subprocess 1: panic with a drop bomb | ||
let status = | ||
process::Command::new(self_exe) | ||
.arg("panic") | ||
.status() | ||
.expect("running the command should have succeeded") | ||
; | ||
assert!(status.success().not(), "`subprocess_panic()` is expected to have aborted"); | ||
|
||
// call the subprocess 2: resume_unwind with a drop bomb | ||
let status = | ||
process::Command::new(self_exe) | ||
.arg("resume_unwind") | ||
.status() | ||
.expect("running the command should have succeeded") | ||
; | ||
assert!(status.success().not(), "`subprocess_resume_unwind()` is expected to have aborted"); | ||
} | ||
|
||
fn subprocess_panic() { | ||
let _ = panic::catch_unwind(|| { | ||
struct Bomb; | ||
|
||
impl Drop for Bomb { | ||
fn drop(&mut self) { | ||
panic!(); | ||
} | ||
} | ||
|
||
let panic_payload = panic::catch_unwind(|| panic::panic_any(Bomb)).unwrap_err(); | ||
// Calls `Bomb::drop`, which starts unwinding. But since this is a panic payload already, | ||
// the drop glue is amended to abort on unwind. So this ought to abort the process. | ||
drop(panic_payload); | ||
}); | ||
} | ||
|
||
fn subprocess_resume_unwind() { | ||
use panic::resume_unwind; | ||
let _ = panic::catch_unwind(|| { | ||
struct Bomb; | ||
|
||
impl Drop for Bomb { | ||
fn drop(&mut self) { | ||
panic!(); | ||
} | ||
} | ||
|
||
let panic_payload = panic::catch_unwind(|| resume_unwind(Box::new(Bomb))).unwrap_err(); | ||
// Calls `Bomb::drop`, which starts unwinding. But since this is a panic payload already, | ||
// the drop glue is amended to abort on unwind. So this ought to abort the process. | ||
drop(panic_payload); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters