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

Stabilize extended_varargs_abi_support #116161

Merged
merged 1 commit into from
Nov 30, 2024
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
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ declare_features! (
(accepted, expr_fragment_specifier_2024, "1.83.0", Some(123742)),
/// Allows arbitrary expressions in key-value attributes at parse time.
(accepted, extended_key_value_attributes, "1.54.0", Some(78835)),
/// Allows using `efiapi`, `aapcs`, `sysv64` and `win64` as calling
/// convention for functions with varargs.
(accepted, extended_varargs_abi_support, "CURRENT_RUSTC_VERSION", Some(100189)),
/// Allows resolving absolute paths as paths from other crates.
(accepted, extern_absolute_paths, "1.30.0", Some(44660)),
/// Allows `extern crate foo as bar;`. This puts `bar` into extern prelude.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,6 @@ declare_features! (
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Allows explicit tail calls via `become` expression.
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
/// for functions with varargs.
(unstable, extended_varargs_abi_support, "1.65.0", Some(100189)),
/// Allows defining `extern type`s.
(unstable, extern_types, "1.23.0", Some(43467)),
/// Allow using 128-bit (quad precision) floating point numbers.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ hir_analysis_value_of_associated_struct_already_specified =
.label = re-bound here
.previous_bound_label = `{$item_name}` bound here first
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
.label = C-variadic function must have a compatible calling convention
hir_analysis_variances_of = {$variances}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,10 @@ pub(crate) struct MainFunctionGenericParameters {

#[derive(Diagnostic)]
#[diag(hir_analysis_variadic_function_compatible_convention, code = E0045)]
pub(crate) struct VariadicFunctionCompatibleConvention<'a> {
pub(crate) struct VariadicFunctionCompatibleConvention {
#[primary_span]
#[label]
pub span: Span,
pub conventions: &'a str,
}

#[derive(Diagnostic)]
Expand Down
31 changes: 2 additions & 29 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ use rustc_middle::middle;
use rustc_middle::mir::interpret::GlobalId;
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
use rustc_session::parse::feature_err;
use rustc_span::Span;
use rustc_span::symbol::sym;
use rustc_trait_selection::traits;

use self::hir_ty_lowering::{FeedConstTy, HirTyLowerer};
Expand All @@ -113,34 +111,9 @@ fn require_c_abi_if_c_variadic(
abi: ExternAbi,
span: Span,
) {
const CONVENTIONS_UNSTABLE: &str =
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
const UNSTABLE_EXPLAIN: &str =
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";

if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
return;
if decl.c_variadic && !abi.supports_varargs() {
tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span });
}

let extended_abi_support = tcx.features().extended_varargs_abi_support();
let conventions = match (extended_abi_support, abi.supports_varargs()) {
// User enabled additional ABI support for varargs and function ABI matches those ones.
(true, true) => return,

// Using this ABI would be ok, if the feature for additional ABI support was enabled.
// Return CONVENTIONS_STABLE, because we want the other error to look the same.
(false, true) => {
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
.emit();
CONVENTIONS_STABLE
}

(false, false) => CONVENTIONS_STABLE,
(true, false) => CONVENTIONS_UNSTABLE,
};

tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span, conventions });
}

pub fn provide(providers: &mut Providers) {
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@
#![feature(doc_masked)]
#![feature(doc_notable_trait)]
#![feature(dropck_eyepatch)]
#![feature(extended_varargs_abi_support)]
#![feature(f128)]
#![feature(f16)]
#![feature(if_let_guard)]
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/c-variadic/feature-gate-extended_varargs_abi_support.rs

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/c-variadic/variadic-ffi-1.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
--> $DIR/variadic-ffi-1.rs:9:5
|
LL | fn printf(_: *const u8, ...);
Expand Down
1 change: 0 additions & 1 deletion tests/ui/c-variadic/variadic-ffi-2-arm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ only-arm
//@ build-pass
#![feature(extended_varargs_abi_support)]

fn aapcs(f: extern "aapcs" fn(usize, ...)) {
f(22, 44);
Expand Down
1 change: 0 additions & 1 deletion tests/ui/c-variadic/variadic-ffi-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ ignore-arm stdcall isn't supported
#![feature(extended_varargs_abi_support)]

#[allow(unsupported_fn_ptr_calling_conventions)]
fn baz(f: extern "stdcall" fn(usize, ...)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/variadic-ffi-2.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
--> $DIR/variadic-ffi-2.rs:5:11
--> $DIR/variadic-ffi-2.rs:4:11
|
LL | fn baz(f: extern "stdcall" fn(usize, ...)) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ type WithTransparentTraitObject =
//~^ ERROR return value of `"C-cmse-nonsecure-call"` function too large to pass via registers [E0798]

type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
//~^ ERROR C-variadic function must have a compatible calling convention, like `C` or `cdecl` [E0045]
//~^ ERROR C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi` [E0045]
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ LL | extern "C-cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTranspa
= note: functions with the `"C-cmse-nonsecure-call"` ABI must pass their result via the available return registers
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size

error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
--> $DIR/generics.rs:41:20
|
LL | type WithVarArgs = extern "C-cmse-nonsecure-call" fn(u32, ...);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0045.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0045]: C-variadic function must have a compatible calling convention, like `C` or `cdecl`
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
--> $DIR/E0045.rs:1:17
|
LL | extern "Rust" { fn foo(x: u8, ...); }
Expand Down
Loading