Skip to content

Commit 3cecbac

Browse files
committed
Stabilise c_unwind
1 parent 8c2b577 commit 3cecbac

File tree

10 files changed

+9
-69
lines changed

10 files changed

+9
-69
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ declare_features! (
7979
(accepted, braced_empty_structs, "1.8.0", Some(29720), None),
8080
/// Allows `c"foo"` literals.
8181
(accepted, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
82+
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries and treat `extern "C" fn` as nounwind.
83+
(accepted, c_unwind, "CURRENT_RUSTC_VERSION", Some(74990), None),
8284
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
8385
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
8486
/// 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
@@ -354,8 +354,6 @@ declare_features! (
354354
(unstable, async_fn_track_caller, "1.73.0", Some(110011), None),
355355
/// Allows builtin # foo() syntax
356356
(unstable, builtin_syntax, "1.71.0", Some(110680), None),
357-
/// Treat `extern "C"` function as nounwind.
358-
(unstable, c_unwind, "1.52.0", Some(74990), None),
359357
/// Allows using C-variadics.
360358
(unstable, c_variadic, "1.34.0", Some(44930), None),
361359
/// 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
@@ -1197,37 +1197,6 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
11971197
// ABIs have such an option. Otherwise the only other thing here is Rust
11981198
// itself, and those ABIs are determined by the panic strategy configured
11991199
// for this compilation.
1200-
//
1201-
// Unfortunately at this time there's also another caveat. Rust [RFC
1202-
// 2945][rfc] has been accepted and is in the process of being implemented
1203-
// and stabilized. In this interim state we need to deal with historical
1204-
// rustc behavior as well as plan for future rustc behavior.
1205-
//
1206-
// Historically functions declared with `extern "C"` were marked at the
1207-
// codegen layer as `nounwind`. This happened regardless of `panic=unwind`
1208-
// or not. This is UB for functions in `panic=unwind` mode that then
1209-
// actually panic and unwind. Note that this behavior is true for both
1210-
// externally declared functions as well as Rust-defined function.
1211-
//
1212-
// To fix this UB rustc would like to change in the future to catch unwinds
1213-
// from function calls that may unwind within a Rust-defined `extern "C"`
1214-
// function and forcibly abort the process, thereby respecting the
1215-
// `nounwind` attribute emitted for `extern "C"`. This behavior change isn't
1216-
// ready to roll out, so determining whether or not the `C` family of ABIs
1217-
// unwinds is conditional not only on their definition but also whether the
1218-
// `#![feature(c_unwind)]` feature gate is active.
1219-
//
1220-
// Note that this means that unlike historical compilers rustc now, by
1221-
// default, unconditionally thinks that the `C` ABI may unwind. This will
1222-
// prevent some optimization opportunities, however, so we try to scope this
1223-
// change and only assume that `C` unwinds with `panic=unwind` (as opposed
1224-
// to `panic=abort`).
1225-
//
1226-
// Eventually the check against `c_unwind` here will ideally get removed and
1227-
// this'll be a little cleaner as it'll be a straightforward check of the
1228-
// ABI.
1229-
//
1230-
// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
12311200
use SpecAbi::*;
12321201
match abi {
12331202
C { unwind }
@@ -1239,10 +1208,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12391208
| Thiscall { unwind }
12401209
| Aapcs { unwind }
12411210
| Win64 { unwind }
1242-
| SysV64 { unwind } => {
1243-
unwind
1244-
|| (!tcx.features().c_unwind && tcx.sess.panic_strategy() == PanicStrategy::Unwind)
1245-
}
1211+
| SysV64 { unwind } => unwind,
12461212
PtxKernel
12471213
| Msp430Interrupt
12481214
| X86Interrupt

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@
167167
//
168168
// Language features:
169169
// tidy-alphabetical-start
170+
#![cfg_attr(bootstrap, feature(c_unwind))]
170171
#![cfg_attr(not(test), feature(coroutine_trait))]
171172
#![cfg_attr(test, feature(panic_update_hook))]
172173
#![cfg_attr(test, feature(test))]
173174
#![feature(allocator_internals)]
174175
#![feature(allow_internal_unstable)]
175176
#![feature(associated_type_bounds)]
176-
#![feature(c_unwind)]
177177
#![feature(cfg_sanitize)]
178178
#![feature(const_mut_refs)]
179179
#![feature(const_precise_live_drops)]

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@
198198
//
199199
// Language features:
200200
// tidy-alphabetical-start
201+
#![cfg_attr(bootstrap, feature(c_unwind))]
201202
#![feature(abi_unadjusted)]
202203
#![feature(adt_const_params)]
203204
#![feature(allow_internal_unsafe)]
204205
#![feature(allow_internal_unstable)]
205206
#![feature(asm_const)]
206207
#![feature(associated_type_bounds)]
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
@@ -13,7 +13,7 @@
1313
#![feature(std_internals)]
1414
#![feature(staged_api)]
1515
#![feature(rustc_attrs)]
16-
#![feature(c_unwind)]
16+
#![cfg_attr(bootstrap, feature(c_unwind))]
1717
#![allow(internal_features)]
1818

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

library/panic_unwind/src/lib.rs

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

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@
265265
//
266266
// Language features:
267267
// tidy-alphabetical-start
268+
#![cfg_attr(bootstrap, feature(c_unwind))]
268269
#![feature(alloc_error_handler)]
269270
#![feature(allocator_internals)]
270271
#![feature(allow_internal_unsafe)]
271272
#![feature(allow_internal_unstable)]
272-
#![feature(c_unwind)]
273273
#![feature(cfg_target_thread_local)]
274274
#![feature(cfi_encoding)]
275275
#![feature(concat_idents)]

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(cfg_target_abi)]
77
#![feature(strict_provenance)]
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)