Skip to content

Commit 24d57be

Browse files
authored
Rollup merge of rust-lang#65347 - RalfJung:unwind-abort-rust, r=varkor
Fix #[unwind(abort)] with Rust ABI Fixes rust-lang#63883.
2 parents a53028e + df93351 commit 24d57be

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/librustc_mir/build/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -502,24 +502,21 @@ macro_rules! unpack {
502502
};
503503
}
504504

505-
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: DefId, abi: Abi) -> bool {
506-
// Not callable from C, so we can safely unwind through these
507-
if abi == Abi::Rust || abi == Abi::RustCall { return false; }
508-
509-
// Validate `#[unwind]` syntax regardless of platform-specific panic strategy
505+
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: DefId, _abi: Abi) -> bool {
506+
// Validate `#[unwind]` syntax regardless of platform-specific panic strategy.
510507
let attrs = &tcx.get_attrs(fn_def_id);
511508
let unwind_attr = attr::find_unwind_attr(Some(tcx.sess.diagnostic()), attrs);
512509

513-
// We never unwind, so it's not relevant to stop an unwind
510+
// We never unwind, so it's not relevant to stop an unwind.
514511
if tcx.sess.panic_strategy() != PanicStrategy::Unwind { return false; }
515512

516-
// We cannot add landing pads, so don't add one
513+
// We cannot add landing pads, so don't add one.
517514
if tcx.sess.no_landing_pads() { return false; }
518515

519516
// This is a special case: some functions have a C abi but are meant to
520517
// unwind anyway. Don't stop them.
521518
match unwind_attr {
522-
None => false, // FIXME(#58794)
519+
None => false, // FIXME(#58794); should be `!(abi == Abi::Rust || abi == Abi::RustCall)`
523520
Some(UnwindAttr::Allowed) => false,
524521
Some(UnwindAttr::Aborts) => true,
525522
}

src/test/ui/abi/abort-on-c-abi.rs renamed to src/test/ui/panics/abort-on-panic.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,51 @@ use std::io::prelude::*;
1414
use std::io;
1515
use std::process::{Command, Stdio};
1616

17-
#[unwind(aborts)] // FIXME(#58794)
17+
#[unwind(aborts)] // FIXME(#58794) should work even without the attribute
1818
extern "C" fn panic_in_ffi() {
1919
panic!("Test");
2020
}
2121

22+
#[unwind(aborts)]
23+
extern "Rust" fn panic_in_rust_abi() {
24+
panic!("TestRust");
25+
}
26+
2227
fn test() {
2328
let _ = panic::catch_unwind(|| { panic_in_ffi(); });
2429
// The process should have aborted by now.
2530
io::stdout().write(b"This should never be printed.\n");
2631
let _ = io::stdout().flush();
2732
}
2833

34+
fn testrust() {
35+
let _ = panic::catch_unwind(|| { panic_in_rust_abi(); });
36+
// The process should have aborted by now.
37+
io::stdout().write(b"This should never be printed.\n");
38+
let _ = io::stdout().flush();
39+
}
40+
2941
fn main() {
3042
let args: Vec<String> = env::args().collect();
31-
if args.len() > 1 && args[1] == "test" {
32-
return test();
43+
if args.len() > 1 {
44+
// This is inside the self-executed command.
45+
match &*args[1] {
46+
"test" => return test(),
47+
"testrust" => return testrust(),
48+
_ => panic!("bad test"),
49+
}
3350
}
3451

52+
// These end up calling the self-execution branches above.
3553
let mut p = Command::new(&args[0])
3654
.stdout(Stdio::piped())
3755
.stdin(Stdio::piped())
3856
.arg("test").spawn().unwrap();
3957
assert!(!p.wait().unwrap().success());
58+
59+
let mut p = Command::new(&args[0])
60+
.stdout(Stdio::piped())
61+
.stdin(Stdio::piped())
62+
.arg("testrust").spawn().unwrap();
63+
assert!(!p.wait().unwrap().success());
4064
}

0 commit comments

Comments
 (0)