Skip to content

Commit ebdfcd9

Browse files
committed
Stabilise c_unwind
1 parent 5978f35 commit ebdfcd9

File tree

11 files changed

+10
-102
lines changed

11 files changed

+10
-102
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ declare_features! (
8080
(accepted, braced_empty_structs, "1.8.0", Some(29720)),
8181
/// Allows `c"foo"` literals.
8282
(accepted, c_str_literals, "1.77.0", Some(105723)),
83+
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries and treat `extern "C" fn` as nounwind.
84+
(accepted, c_unwind, "CURRENT_RUSTC_VERSION", Some(74990)),
8385
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
8486
(accepted, cfg_attr_multi, "1.33.0", Some(54881)),
8587
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ declare_features! (
363363
(unstable, async_for_loop, "1.77.0", Some(118898)),
364364
/// Allows builtin # foo() syntax
365365
(unstable, builtin_syntax, "1.71.0", Some(110680)),
366-
/// Treat `extern "C"` function as nounwind.
367-
(unstable, c_unwind, "1.52.0", Some(74990)),
368366
/// Allows using C-variadics.
369367
(unstable, c_variadic, "1.34.0", Some(44930)),
370368
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.

compiler/rustc_middle/src/ty/layout.rs

+1-35
Original file line numberDiff line numberDiff line change
@@ -1182,37 +1182,6 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
11821182
// ABIs have such an option. Otherwise the only other thing here is Rust
11831183
// itself, and those ABIs are determined by the panic strategy configured
11841184
// for this compilation.
1185-
//
1186-
// Unfortunately at this time there's also another caveat. Rust [RFC
1187-
// 2945][rfc] has been accepted and is in the process of being implemented
1188-
// and stabilized. In this interim state we need to deal with historical
1189-
// rustc behavior as well as plan for future rustc behavior.
1190-
//
1191-
// Historically functions declared with `extern "C"` were marked at the
1192-
// codegen layer as `nounwind`. This happened regardless of `panic=unwind`
1193-
// or not. This is UB for functions in `panic=unwind` mode that then
1194-
// actually panic and unwind. Note that this behavior is true for both
1195-
// externally declared functions as well as Rust-defined function.
1196-
//
1197-
// To fix this UB rustc would like to change in the future to catch unwinds
1198-
// from function calls that may unwind within a Rust-defined `extern "C"`
1199-
// function and forcibly abort the process, thereby respecting the
1200-
// `nounwind` attribute emitted for `extern "C"`. This behavior change isn't
1201-
// ready to roll out, so determining whether or not the `C` family of ABIs
1202-
// unwinds is conditional not only on their definition but also whether the
1203-
// `#![feature(c_unwind)]` feature gate is active.
1204-
//
1205-
// Note that this means that unlike historical compilers rustc now, by
1206-
// default, unconditionally thinks that the `C` ABI may unwind. This will
1207-
// prevent some optimization opportunities, however, so we try to scope this
1208-
// change and only assume that `C` unwinds with `panic=unwind` (as opposed
1209-
// to `panic=abort`).
1210-
//
1211-
// Eventually the check against `c_unwind` here will ideally get removed and
1212-
// this'll be a little cleaner as it'll be a straightforward check of the
1213-
// ABI.
1214-
//
1215-
// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
12161185
use SpecAbi::*;
12171186
match abi {
12181187
C { unwind }
@@ -1224,10 +1193,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12241193
| Thiscall { unwind }
12251194
| Aapcs { unwind }
12261195
| Win64 { unwind }
1227-
| SysV64 { unwind } => {
1228-
unwind
1229-
|| (!tcx.features().c_unwind && tcx.sess.panic_strategy() == PanicStrategy::Unwind)
1230-
}
1196+
| SysV64 { unwind } => unwind,
12311197
PtxKernel
12321198
| Msp430Interrupt
12331199
| X86Interrupt

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

+1-33
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,6 @@ use rustc_target::spec::PanicStrategy;
1111

1212
use crate::errors;
1313

14-
/// Some of the functions declared as "may unwind" by `fn_can_unwind` can't actually unwind. In
15-
/// particular, `extern "C"` is still considered as can-unwind on stable, but we need to consider
16-
/// it cannot-unwind here. So below we check `fn_can_unwind() && abi_can_unwind()` before concluding
17-
/// that a function call can unwind.
18-
fn abi_can_unwind(abi: Abi) -> bool {
19-
use Abi::*;
20-
match abi {
21-
C { unwind }
22-
| System { unwind }
23-
| Cdecl { unwind }
24-
| Stdcall { unwind }
25-
| Fastcall { unwind }
26-
| Vectorcall { unwind }
27-
| Thiscall { unwind }
28-
| Aapcs { unwind }
29-
| Win64 { unwind }
30-
| SysV64 { unwind } => unwind,
31-
PtxKernel
32-
| Msp430Interrupt
33-
| X86Interrupt
34-
| EfiApi
35-
| AvrInterrupt
36-
| AvrNonBlockingInterrupt
37-
| RiscvInterruptM
38-
| RiscvInterruptS
39-
| CCmseNonSecureCall
40-
| Wasm
41-
| Unadjusted => false,
42-
RustIntrinsic | Rust | RustCall | RustCold => unreachable!(), // these ABIs are already skipped earlier
43-
}
44-
}
45-
4614
// Check if the body of this def_id can possibly leak a foreign unwind into Rust code.
4715
fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
4816
debug!("has_ffi_unwind_calls({local_def_id:?})");
@@ -103,7 +71,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
10371
_ => bug!("invalid callee of type {:?}", ty),
10472
};
10573

106-
if layout::fn_can_unwind(tcx, fn_def_id, sig.abi()) && abi_can_unwind(sig.abi()) {
74+
if layout::fn_can_unwind(tcx, fn_def_id, sig.abi()) {
10775
// We have detected a call that can possibly leak foreign unwind.
10876
//
10977
// Because the function body itself can unwind, we are not aborting this function call

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@
165165
//
166166
// Language features:
167167
// tidy-alphabetical-start
168+
#![cfg_attr(bootstrap, feature(c_unwind))]
168169
#![cfg_attr(not(test), feature(coroutine_trait))]
169170
#![cfg_attr(test, feature(panic_update_hook))]
170171
#![cfg_attr(test, feature(test))]
171172
#![feature(allocator_internals)]
172173
#![feature(allow_internal_unstable)]
173-
#![feature(c_unwind)]
174174
#![feature(cfg_sanitize)]
175175
#![feature(const_mut_refs)]
176176
#![feature(const_precise_live_drops)]

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@
199199
//
200200
// Language features:
201201
// tidy-alphabetical-start
202+
#![cfg_attr(bootstrap, feature(c_unwind))]
202203
#![feature(abi_unadjusted)]
203204
#![feature(adt_const_params)]
204205
#![feature(allow_internal_unsafe)]
205206
#![feature(allow_internal_unstable)]
206207
#![feature(asm_const)]
207208
#![feature(auto_traits)]
208-
#![feature(c_unwind)]
209209
#![feature(cfg_sanitize)]
210210
#![feature(cfg_target_has_atomic)]
211211
#![feature(cfg_target_has_atomic_equal_alignment)]

library/panic_abort/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![feature(std_internals)]
1515
#![feature(staged_api)]
1616
#![feature(rustc_attrs)]
17-
#![feature(c_unwind)]
17+
#![cfg_attr(bootstrap, feature(c_unwind))]
1818
#![allow(internal_features)]
1919

2020
#[cfg(target_os = "android")]

library/panic_unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#![feature(rustc_attrs)]
2525
#![panic_runtime]
2626
#![feature(panic_runtime)]
27-
#![feature(c_unwind)]
27+
#![cfg_attr(bootstrap, feature(c_unwind))]
2828
// `real_imp` is unused with Miri, so silence warnings.
2929
#![cfg_attr(miri, allow(dead_code))]
3030
#![allow(internal_features)]

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@
273273
//
274274
// Language features:
275275
// tidy-alphabetical-start
276+
#![cfg_attr(bootstrap, feature(c_unwind))]
276277
#![feature(alloc_error_handler)]
277278
#![feature(allocator_internals)]
278279
#![feature(allow_internal_unsafe)]
279280
#![feature(allow_internal_unstable)]
280281
#![feature(asm_experimental_arch)]
281-
#![feature(c_unwind)]
282282
#![feature(cfg_sanitizer_cfi)]
283283
#![feature(cfg_target_thread_local)]
284284
#![feature(cfi_encoding)]

library/unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![unstable(feature = "panic_unwind", issue = "32837")]
33
#![feature(link_cfg)]
44
#![feature(staged_api)]
5-
#![feature(c_unwind)]
5+
#![cfg_attr(bootstrap, feature(c_unwind))]
66
#![feature(strict_provenance)]
77
#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
88
#![cfg_attr(not(target_env = "msvc"), feature(libc))]

src/doc/unstable-book/src/language-features/c-unwind.md

-26
This file was deleted.

0 commit comments

Comments
 (0)