Skip to content

Commit 5fc8ef2

Browse files
committed
Stabilise c_unwind
1 parent e4133ba commit 5fc8ef2

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
@@ -78,6 +78,8 @@ declare_features! (
7878
(accepted, bindings_after_at, "1.56.0", Some(65490), None),
7979
/// Allows empty structs and enum variants with braces.
8080
(accepted, braced_empty_structs, "1.8.0", Some(29720), None),
81+
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries and treat `extern "C" fn` as nounwind.
82+
(accepted, c_unwind, "CURRENT_RUSTC_VERSION", Some(74990), None),
8183
/// Allows `#[cfg_attr(predicate, multiple, attributes, here)]`.
8284
(accepted, cfg_attr_multi, "1.33.0", Some(54881), None),
8385
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.

compiler/rustc_feature/src/active.rs

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

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@
166166
//
167167
// Language features:
168168
// tidy-alphabetical-start
169+
#![cfg_attr(bootstrap, feature(c_unwind))]
169170
#![cfg_attr(not(test), feature(generator_trait))]
170171
#![cfg_attr(test, feature(panic_update_hook))]
171172
#![cfg_attr(test, feature(test))]
172173
#![feature(allocator_internals)]
173174
#![feature(allow_internal_unstable)]
174175
#![feature(associated_type_bounds)]
175-
#![feature(c_unwind)]
176176
#![feature(cfg_sanitize)]
177177
#![feature(const_mut_refs)]
178178
#![feature(const_precise_live_drops)]

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
//
196196
// Language features:
197197
// tidy-alphabetical-start
198+
#![cfg_attr(bootstrap, feature(c_unwind))]
198199
#![cfg_attr(not(bootstrap), feature(effects))]
199200
#![feature(abi_unadjusted)]
200201
#![feature(adt_const_params)]
@@ -203,7 +204,6 @@
203204
#![feature(asm_const)]
204205
#![feature(associated_type_bounds)]
205206
#![feature(auto_traits)]
206-
#![feature(c_unwind)]
207207
#![feature(cfg_sanitize)]
208208
#![feature(cfg_target_has_atomic)]
209209
#![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
@@ -264,11 +264,11 @@
264264
//
265265
// Language features:
266266
// tidy-alphabetical-start
267+
#![cfg_attr(bootstrap, feature(c_unwind))]
267268
#![feature(alloc_error_handler)]
268269
#![feature(allocator_internals)]
269270
#![feature(allow_internal_unsafe)]
270271
#![feature(allow_internal_unstable)]
271-
#![feature(c_unwind)]
272272
#![feature(cfg_target_thread_local)]
273273
#![feature(concat_idents)]
274274
#![feature(const_mut_refs)]

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
#![cfg_attr(not(target_env = "msvc"), feature(libc))]
88
#![allow(internal_features)]

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

-26
This file was deleted.

0 commit comments

Comments
 (0)