Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial stabilisation of c_unwind #106075

Merged
merged 3 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ declare_features! (
(active, async_closure, "1.37.0", Some(62290), None),
/// Allows async functions to be declared, implemented, and used in traits.
(incomplete, async_fn_in_trait, "1.66.0", Some(91611), None),
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
/// Treat `extern "C"` function as nounwind.
(active, c_unwind, "1.52.0", Some(74990), None),
/// Allows using C-variadics.
(active, c_variadic, "1.34.0", Some(44930), None),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(c_unwind)]
/// #![warn(ffi_unwind_calls)]
///
/// extern "C-unwind" {
Expand All @@ -4037,8 +4036,7 @@ declare_lint! {
/// that desire this ability it is therefore necessary to avoid such calls.
pub FFI_UNWIND_CALLS,
Allow,
"call to foreign functions or function pointers with FFI-unwind ABI",
@feature_gate = sym::c_unwind;
"call to foreign functions or function pointers with FFI-unwind ABI"
}

declare_lint! {
Expand Down
53 changes: 11 additions & 42 deletions compiler/rustc_target/src/spec/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ pub fn is_enabled(
pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
match name {
// Stable
"Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64"
| "system" | "efiapi" => Ok(()),
"Rust" | "C" | "C-unwind" | "cdecl" | "cdecl-unwind" | "stdcall" | "stdcall-unwind"
| "fastcall" | "fastcall-unwind" | "aapcs" | "aapcs-unwind" | "win64" | "win64-unwind"
| "sysv64" | "sysv64-unwind" | "system" | "system-unwind" | "efiapi" => Ok(()),
"rust-intrinsic" => Err(AbiDisabled::Unstable {
feature: sym::intrinsics,
explain: "intrinsics are subject to change",
Expand All @@ -162,10 +163,18 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
feature: sym::abi_vectorcall,
explain: "vectorcall is experimental and subject to change",
}),
"vectorcall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::abi_vectorcall,
explain: "vectorcall-unwind ABI is experimental and subject to change",
}),
"thiscall" => Err(AbiDisabled::Unstable {
feature: sym::abi_thiscall,
explain: "thiscall is experimental and subject to change",
}),
"thiscall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::abi_thiscall,
explain: "thiscall-unwind ABI is experimental and subject to change",
}),
"rust-call" => Err(AbiDisabled::Unstable {
feature: sym::unboxed_closures,
explain: "rust-call ABI is subject to change",
Expand Down Expand Up @@ -202,46 +211,6 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
feature: sym::abi_c_cmse_nonsecure_call,
explain: "C-cmse-nonsecure-call ABI is experimental and subject to change",
}),
"C-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "C-unwind ABI is experimental and subject to change",
}),
"stdcall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "stdcall-unwind ABI is experimental and subject to change",
}),
"system-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "system-unwind ABI is experimental and subject to change",
}),
"thiscall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "thiscall-unwind ABI is experimental and subject to change",
}),
"cdecl-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "cdecl-unwind ABI is experimental and subject to change",
}),
"fastcall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "fastcall-unwind ABI is experimental and subject to change",
}),
"vectorcall-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "vectorcall-unwind ABI is experimental and subject to change",
}),
"aapcs-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "aapcs-unwind ABI is experimental and subject to change",
}),
"win64-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "win64-unwind ABI is experimental and subject to change",
}),
"sysv64-unwind" => Err(AbiDisabled::Unstable {
feature: sym::c_unwind,
explain: "sysv64-unwind ABI is experimental and subject to change",
}),
"wasm" => Err(AbiDisabled::Unstable {
feature: sym::wasm_abi,
explain: "wasm ABI is experimental and subject to change",
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/src/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static EXCEPTION_TYPE_INFO: TypeInfo = TypeInfo {
name: b"rust_panic\0".as_ptr(),
};

// NOTE(nbdd0121): The `canary` field will be part of stable ABI after `c_unwind` stabilization.
// NOTE(nbdd0121): The `canary` field is part of stable ABI.
#[repr(C)]
struct Exception {
// See `gcc.rs` on why this is present. We already have a static here so just use it.
Expand Down
4 changes: 2 additions & 2 deletions library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use unwind as uw;
static CANARY: u8 = 0;

// NOTE(nbdd0121)
// Once `c_unwind` feature is stabilized, there will be ABI stability requirement
// on this struct. The first two field must be `_Unwind_Exception` and `canary`,
// There is an ABI stability requirement on this struct.
// The first two field must be `_Unwind_Exception` and `canary`,
// as it may be accessed by a different version of the std with a different compiler.
#[repr(C)]
struct Exception {
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/src/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use core::mem::{self, ManuallyDrop};
use core::ptr;
use libc::{c_int, c_uint, c_void};

// NOTE(nbdd0121): The `canary` field will be part of stable ABI after `c_unwind` stabilization.
// NOTE(nbdd0121): The `canary` field is part of stable ABI.
#[repr(C)]
struct Exception {
// See `gcc.rs` on why this is present. We already have a static here so just use it.
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/c-unwind-abi-catch-lib-panic/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! This test triggers a panic in a Rust library that our foreign function invokes. This shows
//! that we can unwind through the C code in that library, and catch the underlying panic.
#![feature(c_unwind)]

use std::panic::{catch_unwind, AssertUnwindSafe};

Expand Down
1 change: 0 additions & 1 deletion tests/run-make/c-unwind-abi-catch-lib-panic/panic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_type = "staticlib"]
#![feature(c_unwind)]

/// This function will panic if `x` is greater than 10.
///
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/c-unwind-abi-catch-panic/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! A test for calling `C-unwind` functions across foreign function boundaries.
//!
//! This test triggers a panic when calling a foreign function that calls *back* into Rust.
#![feature(c_unwind)]

use std::panic::{catch_unwind, AssertUnwindSafe};

Expand Down
2 changes: 0 additions & 2 deletions tests/run-make/foreign-double-unwind/foo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Tests that C++ double unwinding through Rust code will be properly guarded
// against instead of exhibiting undefined behaviour.

#![feature(c_unwind)]

extern "C-unwind" {
fn throw_cxx_exception();
fn cxx_catch_callback(cb: extern "C-unwind" fn());
Expand Down
2 changes: 0 additions & 2 deletions tests/run-make/foreign-exceptions/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// are caught by catch_unwind. Also tests that Rust panics can unwind through
// C++ code.

#![feature(c_unwind)]

use std::panic::{catch_unwind, AssertUnwindSafe};

struct DropCheck<'a>(&'a mut bool);
Expand Down
1 change: 0 additions & 1 deletion tests/run-make/foreign-rust-exceptions/bar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_type = "cdylib"]
#![feature(c_unwind)]

#[no_mangle]
extern "C-unwind" fn panic() {
Expand Down
2 changes: 0 additions & 2 deletions tests/run-make/foreign-rust-exceptions/foo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(c_unwind)]

#[cfg_attr(not(windows), link(name = "bar"))]
#[cfg_attr(windows, link(name = "bar.dll"))]
extern "C-unwind" {
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/fn_pointer/abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]
#![feature(c_unwind)]

// @is "$.index[*][?(@.name=='AbiRust')].inner.type.inner.header.abi" \"Rust\"
pub type AbiRust = fn();
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/fns/abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]
#![feature(c_unwind)]

// @is "$.index[*][?(@.name=='abi_rust')].inner.header.abi" \"Rust\"
pub fn abi_rust() {}
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc-json/methods/abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// ignore-tidy-linelength

#![feature(abi_vectorcall)]
#![feature(c_unwind)]
#![feature(no_core)]
#![no_core]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// gate-test-abi_thiscall
// gate-test-c_unwind
// needs-llvm-components: x86
// compile-flags: --target=i686-pc-windows-msvc --crate-type=rlib
#![no_core]
#![feature(no_core, lang_items)]
#[lang="sized"]
trait Sized { }

// Test that the "thiscall-unwind" ABI is feature-gated, and cannot be used when
// the `c_unwind` feature gate is not used.
// Test that the "thiscall" ABI is feature-gated, and cannot be used when
// the `abi_thiscall` feature gate is not used.

extern "thiscall-unwind" fn fu() {} //~ ERROR thiscall-unwind ABI is experimental
extern "thiscall" fn f() {} //~ ERROR thiscall is experimental
Expand Down
Original file line number Diff line number Diff line change
@@ -1,121 +1,114 @@
error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:13:8
--> $DIR/feature-gate-thiscall.rs:12:8
|
LL | extern "thiscall-unwind" fn fu() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:14:8
--> $DIR/feature-gate-thiscall.rs:13:8
|
LL | extern "thiscall" fn f() {}
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:17:12
--> $DIR/feature-gate-thiscall.rs:16:12
|
LL | extern "thiscall" fn m();
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:18:12
--> $DIR/feature-gate-thiscall.rs:17:12
|
LL | extern "thiscall-unwind" fn mu();
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:20:12
--> $DIR/feature-gate-thiscall.rs:19:12
|
LL | extern "thiscall" fn dm() {}
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:21:12
--> $DIR/feature-gate-thiscall.rs:20:12
|
LL | extern "thiscall-unwind" fn dmu() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:26:12
--> $DIR/feature-gate-thiscall.rs:25:12
|
LL | extern "thiscall" fn m() {}
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:27:12
--> $DIR/feature-gate-thiscall.rs:26:12
|
LL | extern "thiscall-unwind" fn mu() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:31:12
--> $DIR/feature-gate-thiscall.rs:30:12
|
LL | extern "thiscall" fn im() {}
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:32:12
--> $DIR/feature-gate-thiscall.rs:31:12
|
LL | extern "thiscall-unwind" fn imu() {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:35:18
--> $DIR/feature-gate-thiscall.rs:34:18
|
LL | type TA = extern "thiscall" fn();
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:36:19
--> $DIR/feature-gate-thiscall.rs:35:19
|
LL | type TAU = extern "thiscall-unwind" fn();
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:38:8
--> $DIR/feature-gate-thiscall.rs:37:8
|
LL | extern "thiscall" {}
| ^^^^^^^^^^
|
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error[E0658]: thiscall-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-thiscall-unwind.rs:39:8
--> $DIR/feature-gate-thiscall.rs:38:8
|
LL | extern "thiscall-unwind" {}
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
= help: add `#![feature(abi_thiscall)]` to the crate attributes to enable

error: aborting due to 14 previous errors

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-vectorcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#[lang="sized"]
trait Sized { }

// Test that the "vectorcall-unwind" ABI is feature-gated, and cannot be used when
// the `c_unwind` feature gate is not used.
// Test that the "vectorcall" ABI is feature-gated, and cannot be used when
// the `vectorcall` feature gate is not used.

extern "vectorcall" fn f() {} //~ ERROR vectorcall is experimental

Expand Down
1 change: 0 additions & 1 deletion tests/ui/panic-runtime/auxiliary/needs-unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#![crate_type = "rlib"]
#![no_std]
#![feature(c_unwind)]

extern "C-unwind" fn foo() {}

Expand Down
Loading