Skip to content

Commit 8b8eff5

Browse files
Auto merge of #142134 - workingjubilee:reject-unsupported-abi, r=<try>
Reject `extern "{abi}"` when the target does not support it ## What Promote [`unsupported_fn_ptr_calling_conventions`] from a warning to a hard error, making sure edge-cases will not escape. We now emit hard errors for every case we would return `Invalid` from `AbiMap::canonize_abi` during AST to HIR lowering. In particular, these architecture-specific ABIs now only compile on their architectures[^1]: - amdgpu: "gpu-kernel" - arm: "aapcs", "C-cmse-nonsecure-entry" - avr: "avr-interrupt", "avr-non-blocking-interrupt" - msp430: "msp430-interrupt" - nvptx64: "gpu-kernel", "ptx-kernel" - riscv32 and riscv64: "riscv-interrupt-machine", "riscv-interrupt-supervisor" - x86: "thiscall" - x86 and x86_64: "x86-interrupt" - x86_64: "sysv64", "win64" The panoply of ABIs that are logically x86-specific but actually permitted on all Windows targets remain supported on Windows, as they were before. For non-Windows targets they error if the architecture does not match. Moving the check into AST lowering **is itself a breaking change in rare cases**, above and beyond the cases rustc currently warns about. See "Why or Why Not" for details. ## How We modify rustc_ast_lowering to prevent unsupported ABIs from leaking through the HIR without being checked for target support. Previously ad-hoc checking on various HIR items required making sure we check every HIR item which could contain an `extern "{abi}"` string. This is a losing proposition compared to gating the lowering itself. As a consequence, unsupported ABI strings will now hard-error instead of triggering the FCW `unsupported_fn_ptr_calling_conventions`. However, per #86232 this does cause errors for rare usages of `extern "{abi}"` that were theoretically possible to write in Rust source, without previous warning or error. For instance, trait declarations without impls were never checked. These are the exact kinds of leakages that this new approach prevents. This differs from the following PRs: - #141435 is orthogonal, as it adds a new lint for ABIs we have not warned on and are not touched by this PR - #141877 is subsumed by this, in that this simply cuts out bad functionality instead of adding epicycles for stable code ## Why or Why Not We already made the decision to issue the `unsupported_fn_ptr_calling_conventions` future compatibility warning. It has warned in dependencies since #135767, which reached stable with Rust 1.87. That was released on 2025 May 17, and it is now June. As we already had erred on these ABI strings in most other positions, and warn on stable for function pointer types, this breakage has had reasonable foreshadowing. Upgrading the warning to an error addresses a real problem. In some cases the Rust compiler can attempt to actually compute the ABI for calling a function. We could accept this case and compute unsupported ABIs according to some other ABI, silently[^0]. However, this obviously exposes Rust to errors in codegen. We cannot lower directly to the "obvious" ABI and then trust code generators like LLVM to reliably error on these cases, either. Refactoring the compiler so we could defer more ABI computations would be possible, but seems weakly motivated. Even if we succeeded, we would at minimum risk: - exposing the "whack-a-mole" problem but "approaching linking" instead of "leaving AST" - making it harder to reason about functions we *can* lower further - complicating the compiler for no clear benefit A deprecation cycle for the edge-cases could be implemented first, but it is not very useful for such marginal cases, like this trait declaration without a definition: ```rust pub trait UsedToSneakBy { pub extern "gpu-kernel" fn sneaky(); } ``` Upon any impl, even for provided fn within trait declarations, e.g. `pub extern "gpu-kernel" fn sneaky() {}`, different HIR types were used which would, in fact, get checked. Likewise with anything with function pointers. Thus we would be discussing deprecation cycles for code that is impotent or forewarned[^2]. Implementing a deprecation cycle _is_ possible, but it would likely require emitting multiple of a functionally identical warning or error on code that would not have multiple warnings or errors before. It is also not clear to me we would not find **another**, even more marginal edge-case that slipped through, as "things slip through" is the motivation for checking earlier. Additional effort spent on additional warnings should require committing to a hard limit first. r? lang Fixes #86232 Fixes #132430 Fixes #138738 Fixes #142107 [`unsupported_fn_ptr_calling_conventions`]: #130260 [^1]: Some already will not compile, due to reaching ICEs or LLVM errors. [^0]: We already do this for all `AbiStr` we cannot parse, pretending they are `ExternAbi::Rust`, but we also emit an error to prevent reaching too far into codegen. [^2]: It actually did appear in two cases in rustc's test suite because we are a collection of Rust edge-cases by the simple fact that we don't care if the code actually runs. These cases were excised in c1db989.
2 parents 44f415c + c1db989 commit 8b8eff5

40 files changed

+978
-1556
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
22
use rustc_ast::ptr::P;
33
use rustc_ast::visit::AssocCtxt;
44
use rustc_ast::*;
5-
use rustc_errors::ErrorGuaranteed;
5+
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
88
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
@@ -1617,9 +1617,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
16171617
self.error_on_invalid_abi(abi_str);
16181618
ExternAbi::Rust
16191619
});
1620-
let sess = self.tcx.sess;
1621-
let features = self.tcx.features();
1622-
gate_unstable_abi(sess, features, span, extern_abi);
1620+
let tcx = self.tcx;
1621+
1622+
// we can't do codegen for unsupported ABIs, so error now so we won't get farther
1623+
if !tcx.sess.target.is_abi_supported(extern_abi) {
1624+
struct_span_code_err!(
1625+
tcx.dcx(),
1626+
span,
1627+
E0570,
1628+
"`{extern_abi}` is not a supported ABI for the current target",
1629+
)
1630+
.emit();
1631+
}
1632+
// stability gate even things that are already errored on
1633+
gate_unstable_abi(tcx.sess, tcx.features(), span, extern_abi);
16231634
extern_abi
16241635
}
16251636

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use rustc_hir::def::{CtorKind, DefKind};
1010
use rustc_hir::{LangItem, Node, intravisit};
1111
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1212
use rustc_infer::traits::{Obligation, ObligationCauseCode};
13-
use rustc_lint_defs::builtin::{
14-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
15-
};
13+
use rustc_lint_defs::builtin::REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS;
1614
use rustc_middle::hir::nested_filter;
1715
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
1816
use rustc_middle::middle::stability::EvalResult;
@@ -35,28 +33,6 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
3533
use super::compare_impl_item::check_type_bounds;
3634
use super::*;
3735

38-
pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: ExternAbi) {
39-
if !tcx.sess.target.is_abi_supported(abi) {
40-
struct_span_code_err!(
41-
tcx.dcx(),
42-
span,
43-
E0570,
44-
"`{abi}` is not a supported ABI for the current target",
45-
)
46-
.emit();
47-
}
48-
}
49-
50-
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) {
51-
if !tcx.sess.target.is_abi_supported(abi) {
52-
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
53-
lint.primary_message(format!(
54-
"the calling convention {abi} is not supported on this target"
55-
));
56-
});
57-
}
58-
}
59-
6036
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {
6137
let def = tcx.adt_def(def_id);
6238
let span = tcx.def_span(def_id);
@@ -779,7 +755,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
779755
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
780756
return;
781757
};
782-
check_abi(tcx, it.span, abi);
783758

784759
for item in items {
785760
let def_id = item.id.owner_id.def_id;

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ pub mod wfcheck;
7272

7373
use std::num::NonZero;
7474

75-
pub use check::{check_abi, check_abi_fn_ptr};
76-
use rustc_abi::{ExternAbi, VariantIdx};
75+
use rustc_abi::VariantIdx;
7776
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
7877
use rustc_errors::{Diag, ErrorGuaranteed, pluralize, struct_span_code_err};
7978
use rustc_hir::def_id::{DefId, LocalDefId};

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use rustc_trait_selection::traits::wf::object_region_bounds;
5050
use rustc_trait_selection::traits::{self, ObligationCtxt};
5151
use tracing::{debug, instrument};
5252

53-
use crate::check::check_abi_fn_ptr;
5453
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation};
5554
use crate::hir_ty_lowering::errors::{GenericsArgsErrExtend, prohibit_assoc_item_constraint};
5655
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
@@ -2736,12 +2735,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27362735
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, safety, abi);
27372736
let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
27382737

2739-
if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(bare_fn_ty), span, .. }) =
2740-
tcx.hir_node(hir_id)
2741-
{
2742-
check_abi_fn_ptr(tcx, hir_id, *span, bare_fn_ty.abi);
2743-
}
2744-
27452738
// reject function types that violate cmse ABI requirements
27462739
cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, bare_fn_ty);
27472740

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use rustc_errors::{Applicability, ErrorGuaranteed, pluralize, struct_span_code_e
4949
use rustc_hir as hir;
5050
use rustc_hir::def::{DefKind, Res};
5151
use rustc_hir::{HirId, HirIdMap, Node};
52-
use rustc_hir_analysis::check::check_abi;
5352
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
5453
use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc};
5554
use rustc_middle::query::Providers;
@@ -150,8 +149,6 @@ fn typeck_with_inspect<'tcx>(
150149
tcx.fn_sig(def_id).instantiate_identity()
151150
};
152151

153-
check_abi(tcx, span, fn_sig.abi());
154-
155152
// Compute the function signature from point of view of inside the fn.
156153
let mut fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
157154

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ fn register_builtins(store: &mut LintStore) {
610610
"converted into hard error, see issue #127323 \
611611
<https://github.com/rust-lang/rust/issues/127323> for more information",
612612
);
613+
store.register_removed("unsupported_fn_ptr_calling_conventions", "converted into hard error");
613614
store.register_removed(
614615
"undefined_naked_function_abi",
615616
"converted into hard error, see PR #139001 \

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ declare_lint_pass! {
123123
UNSAFE_OP_IN_UNSAFE_FN,
124124
UNSTABLE_NAME_COLLISIONS,
125125
UNSTABLE_SYNTAX_PRE_EXPANSION,
126-
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
127126
UNUSED_ASSIGNMENTS,
128127
UNUSED_ASSOCIATED_TYPE_BOUNDS,
129128
UNUSED_ATTRIBUTES,

tests/crashes/132430.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/crashes/138738.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/debuginfo/type-names.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// gdb-check:type = type_names::GenericStruct<type_names::mod1::Struct2, type_names::mod1::mod2::Struct3>
2020

2121
// gdb-command:whatis generic_struct2
22-
// gdb-check:type = type_names::GenericStruct<type_names::Struct1, extern "fastcall" fn(isize) -> usize>
22+
// gdb-check:type = type_names::GenericStruct<type_names::Struct1, extern "system" fn(isize) -> usize>
2323

2424
// gdb-command:whatis mod_struct
2525
// gdb-check:type = type_names::mod1::Struct2
@@ -379,7 +379,7 @@ fn main() {
379379
let simple_struct = Struct1;
380380
let generic_struct1: GenericStruct<mod1::Struct2, mod1::mod2::Struct3> =
381381
GenericStruct(PhantomData);
382-
let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
382+
let generic_struct2: GenericStruct<Struct1, extern "system" fn(isize) -> usize> =
383383
GenericStruct(PhantomData);
384384
let mod_struct = mod1::Struct2;
385385

tests/incremental/hashes/trait_defs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ trait TraitAddExternModifier {
440440

441441
// Change extern "C" to extern "stdcall"
442442
#[cfg(any(cfail1,cfail4))]
443-
trait TraitChangeExternCToRustIntrinsic {
443+
trait TraitChangeExternCToExternSystem {
444444
// --------------------------------------------------------------
445445
// -------------------------
446446
// --------------------------------------------------------------
@@ -458,7 +458,7 @@ trait TraitChangeExternCToRustIntrinsic {
458458
#[rustc_clean(cfg="cfail3")]
459459
#[rustc_clean(except="opt_hir_owner_nodes,fn_sig", cfg="cfail5")]
460460
#[rustc_clean(cfg="cfail6")]
461-
extern "stdcall" fn method();
461+
extern "system" fn method();
462462
}
463463

464464

tests/rustdoc-json/fn_pointer/abi.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(abi_vectorcall)]
1+
#![feature(rust_cold_cc)]
22

33
//@ is "$.index[?(@.name=='AbiRust')].inner.type_alias.type.function_pointer.header.abi" \"Rust\"
44
pub type AbiRust = fn();
@@ -15,8 +15,5 @@ pub type AbiCUnwind = extern "C-unwind" fn();
1515
//@ is "$.index[?(@.name=='AbiSystemUnwind')].inner.type_alias.type.function_pointer.header.abi" '{"System": {"unwind": true}}'
1616
pub type AbiSystemUnwind = extern "system-unwind" fn();
1717

18-
//@ is "$.index[?(@.name=='AbiVecorcall')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall\""'
19-
pub type AbiVecorcall = extern "vectorcall" fn();
20-
21-
//@ is "$.index[?(@.name=='AbiVecorcallUnwind')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall-unwind\""'
22-
pub type AbiVecorcallUnwind = extern "vectorcall-unwind" fn();
18+
//@ is "$.index[?(@.name=='AbiRustCold')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"rust-cold\""'
19+
pub type AbiRustCold = extern "rust-cold" fn();

tests/rustdoc-json/fns/abi.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(abi_vectorcall)]
1+
#![feature(rust_cold_cc)]
22

33
//@ is "$.index[?(@.name=='abi_rust')].inner.function.header.abi" \"Rust\"
44
pub fn abi_rust() {}
@@ -15,8 +15,5 @@ pub extern "C-unwind" fn abi_c_unwind() {}
1515
//@ is "$.index[?(@.name=='abi_system_unwind')].inner.function.header.abi" '{"System": {"unwind": true}}'
1616
pub extern "system-unwind" fn abi_system_unwind() {}
1717

18-
//@ is "$.index[?(@.name=='abi_vectorcall')].inner.function.header.abi.Other" '"\"vectorcall\""'
19-
pub extern "vectorcall" fn abi_vectorcall() {}
20-
21-
//@ is "$.index[?(@.name=='abi_vectorcall_unwind')].inner.function.header.abi.Other" '"\"vectorcall-unwind\""'
22-
pub extern "vectorcall-unwind" fn abi_vectorcall_unwind() {}
18+
//@ is "$.index[?(@.name=='abi_rust_cold')].inner.function.header.abi.Other" '"\"rust-cold\""'
19+
pub extern "rust-cold" fn abi_rust_cold() {}

tests/rustdoc-json/methods/abi.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(abi_vectorcall)]
2-
1+
#![feature(rust_cold_cc)]
32
//@ has "$.index[?(@.name=='Foo')]"
43
pub struct Foo;
54

@@ -19,11 +18,8 @@ impl Foo {
1918
//@ is "$.index[?(@.name=='abi_system_unwind')].inner.function.header.abi" '{"System": {"unwind": true}}'
2019
pub extern "system-unwind" fn abi_system_unwind() {}
2120

22-
//@ is "$.index[?(@.name=='abi_vectorcall')].inner.function.header.abi.Other" '"\"vectorcall\""'
23-
pub extern "vectorcall" fn abi_vectorcall() {}
24-
25-
//@ is "$.index[?(@.name=='abi_vectorcall_unwind')].inner.function.header.abi.Other" '"\"vectorcall-unwind\""'
26-
pub extern "vectorcall-unwind" fn abi_vectorcall_unwind() {}
21+
//@ is "$.index[?(@.name=='abi_rust_cold')].inner.function.header.abi.Other" '"\"rust-cold\""'
22+
pub extern "rust-cold" fn abi_rust_cold() {}
2723
}
2824

2925
pub trait Bar {
@@ -42,9 +38,6 @@ pub trait Bar {
4238
//@ is "$.index[?(@.name=='trait_abi_system_unwind')].inner.function.header.abi" '{"System": {"unwind": true}}'
4339
extern "system-unwind" fn trait_abi_system_unwind() {}
4440

45-
//@ is "$.index[?(@.name=='trait_abi_vectorcall')].inner.function.header.abi.Other" '"\"vectorcall\""'
46-
extern "vectorcall" fn trait_abi_vectorcall() {}
47-
48-
//@ is "$.index[?(@.name=='trait_abi_vectorcall_unwind')].inner.function.header.abi.Other" '"\"vectorcall-unwind\""'
49-
extern "vectorcall-unwind" fn trait_abi_vectorcall_unwind() {}
41+
//@ is "$.index[?(@.name=='trait_abi_rust_cold')].inner.function.header.abi.Other" '"\"rust-cold\""'
42+
extern "rust-cold" fn trait_abi_rust_cold() {}
5043
}

tests/rustdoc-json/vectorcall.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![feature(abi_vectorcall)]
2+
//@ only-x86_64
3+
4+
//@ is "$.index[?(@.name=='AbiVectorcall')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall\""'
5+
pub type AbiVectorcall = extern "vectorcall" fn();
6+
7+
//@ is "$.index[?(@.name=='AbiVectorcallUnwind')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall-unwind\""'
8+
pub type AbiVectorcallUnwind = extern "vectorcall-unwind" fn();
9+
10+
//@ has "$.index[?(@.name=='Foo')]"
11+
pub struct Foo;
12+
13+
impl Foo {
14+
//@ is "$.index[?(@.name=='abi_vectorcall')].inner.function.header.abi.Other" '"\"vectorcall\""'
15+
pub extern "vectorcall" fn abi_vectorcall() {}
16+
17+
//@ is "$.index[?(@.name=='abi_vectorcall_unwind')].inner.function.header.abi.Other" '"\"vectorcall-unwind\""'
18+
pub extern "vectorcall-unwind" fn abi_vectorcall_unwind() {}
19+
}
20+
21+
pub trait Bar {
22+
//@ is "$.index[?(@.name=='trait_abi_vectorcall')].inner.function.header.abi.Other" '"\"vectorcall\""'
23+
extern "vectorcall" fn trait_abi_vectorcall() {}
24+
25+
//@ is "$.index[?(@.name=='trait_abi_vectorcall_unwind')].inner.function.header.abi.Other" '"\"vectorcall-unwind\""'
26+
extern "vectorcall-unwind" fn trait_abi_vectorcall_unwind() {}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(abi_gpu_kernel)]
2+
// Check we error before unsupported ABIs reach codegen stages.
3+
4+
fn main() {
5+
let a = unsafe { core::mem::transmute::<usize, extern "gpu-kernel" fn(i32)>(4) }(2);
6+
//~^ ERROR E0570
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0570]: `"gpu-kernel"` is not a supported ABI for the current target
2+
--> $DIR/unsupported-abi-transmute.rs:5:59
3+
|
4+
LL | let a = unsafe { core::mem::transmute::<usize, extern "gpu-kernel" fn(i32)>(4) }(2);
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0570`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ compile-flags: --crate-type=lib
2+
//@ edition: 2018
3+
#![feature(abi_gpu_kernel)]
4+
struct Test;
5+
6+
impl Test {
7+
pub extern "gpu-kernel" fn test(val: &str) {}
8+
//~^ ERROR [E0570]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0570]: `"gpu-kernel"` is not a supported ABI for the current target
2+
--> $DIR/unsupported-extern-abi-in-type-impl.rs:7:16
3+
|
4+
LL | pub extern "gpu-kernel" fn test(val: &str) {}
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0570`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --crate-type=lib
2+
3+
#![feature(abi_gpu_kernel)]
4+
5+
trait T {
6+
extern "gpu-kernel" fn mu();
7+
//~^ ERROR[E0570]
8+
}
9+
10+
type TAU = extern "gpu-kernel" fn();
11+
//~^ ERROR[E0570]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0570]: `"gpu-kernel"` is not a supported ABI for the current target
2+
--> $DIR/unsupported-trait-decl.rs:6:12
3+
|
4+
LL | extern "gpu-kernel" fn mu();
5+
| ^^^^^^^^^^^^
6+
7+
error[E0570]: `"gpu-kernel"` is not a supported ABI for the current target
8+
--> $DIR/unsupported-trait-decl.rs:10:19
9+
|
10+
LL | type TAU = extern "gpu-kernel" fn();
11+
| ^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0570`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// FIXME(workingjubilee): add revisions and generalize to other platform-specific varargs ABIs,
2+
// preferably after the only-arch directive is enhanced with an "or pattern" syntax
3+
//@ only-x86_64
4+
5+
// We have to use this flag to force ABI computation of an invalid ABI
6+
//@ compile-flags: -Clink-dead-code
7+
8+
#![feature(extended_varargs_abi_support)]
9+
10+
// sometimes fn ptrs with varargs make layout and ABI computation ICE
11+
// as found in https://github.com/rust-lang/rust/issues/142107
12+
13+
fn aapcs(f: extern "aapcs" fn(usize, ...)) {
14+
//~^ ERROR [E0570]
15+
// Note we DO NOT have to actually make a call to trigger the ICE!
16+
}
17+
18+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0570]: `"aapcs"` is not a supported ABI for the current target
2+
--> $DIR/unsupported-varargs-fnptr.rs:13:20
3+
|
4+
LL | fn aapcs(f: extern "aapcs" fn(usize, ...)) {
5+
| ^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0570`.

0 commit comments

Comments
 (0)