Skip to content

Commit a994dcc

Browse files
committed
Revert "implement unwinding abi's (RFC 2945)"
This reverts commit 0f33e9f.
1 parent bfbcf87 commit a994dcc

File tree

7 files changed

+16
-176
lines changed

7 files changed

+16
-176
lines changed

compiler/rustc_middle/src/ty/layout.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,6 @@ fn fn_can_unwind(
25622562
panic_strategy: PanicStrategy,
25632563
codegen_fn_attr_flags: CodegenFnAttrFlags,
25642564
call_conv: Conv,
2565-
abi: SpecAbi,
25662565
) -> bool {
25672566
if panic_strategy != PanicStrategy::Unwind {
25682567
// In panic=abort mode we assume nothing can unwind anywhere, so
@@ -2587,16 +2586,17 @@ fn fn_can_unwind(
25872586
//
25882587
// 2. A Rust item using a non-Rust ABI (like `extern "C" fn foo() { ... }`).
25892588
//
2590-
// In both of these cases, we should refer to the ABI to determine whether or not we
2591-
// should unwind. See Rust RFC 2945 for more information on this behavior, here:
2592-
// https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
2593-
use SpecAbi::*;
2594-
match abi {
2595-
C { unwind } | Stdcall { unwind } | System { unwind } | Thiscall { unwind } => {
2596-
unwind
2597-
}
2598-
_ => false,
2599-
}
2589+
// Foreign items (case 1) are assumed to not unwind; it is
2590+
// UB otherwise. (At least for now; see also
2591+
// rust-lang/rust#63909 and Rust RFC 2753.)
2592+
//
2593+
// Items defined in Rust with non-Rust ABIs (case 2) are also
2594+
// not supposed to unwind. Whether this should be enforced
2595+
// (versus stating it is UB) and *how* it would be enforced
2596+
// is currently under discussion; see rust-lang/rust#58794.
2597+
//
2598+
// In either case, we mark item as explicitly nounwind.
2599+
false
26002600
}
26012601
}
26022602
}
@@ -2823,12 +2823,7 @@ where
28232823
c_variadic: sig.c_variadic,
28242824
fixed_count: inputs.len(),
28252825
conv,
2826-
can_unwind: fn_can_unwind(
2827-
cx.tcx().sess.panic_strategy(),
2828-
codegen_fn_attr_flags,
2829-
conv,
2830-
sig.abi,
2831-
),
2826+
can_unwind: fn_can_unwind(cx.tcx().sess.panic_strategy(), codegen_fn_attr_flags, conv),
28322827
};
28332828
fn_abi.adjust_for_abi(cx, sig.abi);
28342829
debug!("FnAbi::new_internal = {:?}", fn_abi);

compiler/rustc_mir_build/src/build/mod.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ macro_rules! unpack {
563563
}};
564564
}
565565

566-
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bool {
566+
fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, _abi: Abi) -> bool {
567567
// Validate `#[unwind]` syntax regardless of platform-specific panic strategy.
568568
let attrs = &tcx.get_attrs(fn_def_id.to_def_id());
569569
let unwind_attr = attr::find_unwind_attr(&tcx.sess, attrs);
@@ -573,26 +573,12 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bo
573573
return false;
574574
}
575575

576+
// This is a special case: some functions have a C abi but are meant to
577+
// unwind anyway. Don't stop them.
576578
match unwind_attr {
577-
// If an `#[unwind]` attribute was found, we should adhere to it.
579+
None => false, // FIXME(#58794); should be `!(abi == Abi::Rust || abi == Abi::RustCall)`
578580
Some(UnwindAttr::Allowed) => false,
579581
Some(UnwindAttr::Aborts) => true,
580-
// If no attribute was found and the panic strategy is `unwind`, then we should examine
581-
// the function's ABI string to determine whether it should abort upon panic.
582-
None => {
583-
use Abi::*;
584-
match abi {
585-
// In the case of ABI's that have an `-unwind` equivalent, check whether the ABI
586-
// permits unwinding. If so, we should not abort. Otherwise, we should.
587-
C { unwind } | Stdcall { unwind } | System { unwind } | Thiscall { unwind } => {
588-
!unwind
589-
}
590-
// Rust and `rust-call` functions are allowed to unwind, and should not abort.
591-
Rust | RustCall => false,
592-
// Other ABI's should abort.
593-
_ => true,
594-
}
595-
}
596582
}
597583
}
598584

src/test/codegen/unwind-abis/c-unwind-abi-panic-abort.rs

-18
This file was deleted.

src/test/codegen/unwind-abis/c-unwind-abi.rs

-29
This file was deleted.

src/test/codegen/unwind-abis/stdcall-unwind-abi.rs

-32
This file was deleted.

src/test/codegen/unwind-abis/system-unwind-abi.rs

-29
This file was deleted.

src/test/codegen/unwind-abis/thiscall-unwind-abi.rs

-33
This file was deleted.

0 commit comments

Comments
 (0)