-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Reject unsupported extern "{abi}"
s consistently in all positions
#142134
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
base: master
Are you sure you want to change the base?
Changes from all commits
5761d63
f622040
d41534d
23b15b4
e427e3e
2c27b58
93caa6c
de099a1
7aee1f3
97b74a8
f36d716
9c46666
f8deb15
03564e5
57553ef
c284e0a
4e01198
c314a5b
999c1ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use std::cell::LazyCell; | ||
use std::ops::ControlFlow; | ||
|
||
use rustc_abi::FieldIdx; | ||
use rustc_abi::{ExternAbi, FieldIdx}; | ||
use rustc_attr_data_structures::ReprAttr::ReprPacked; | ||
use rustc_data_structures::unord::{UnordMap, UnordSet}; | ||
use rustc_errors::codes::*; | ||
|
@@ -12,7 +12,6 @@ use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt}; | |
use rustc_infer::traits::{Obligation, ObligationCauseCode}; | ||
use rustc_lint_defs::builtin::{ | ||
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS, | ||
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, | ||
}; | ||
use rustc_middle::hir::nested_filter; | ||
use rustc_middle::middle::resolve_bound_vars::ResolvedArg; | ||
|
@@ -52,49 +51,22 @@ fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T | |
} | ||
|
||
pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) { | ||
// FIXME: this should be checked earlier, e.g. in `rustc_ast_lowering`, to fix | ||
// things like #86232. | ||
// FIXME: This should be checked earlier, e.g. in `rustc_ast_lowering`, as this | ||
// currently only guards function imports, function definitions, and function pointer types. | ||
// Functions in trait declarations can still use "deprecated" ABIs without any warning. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding the FIXME just above this line: since #86232 will be marked as fixed, it seems good to update the FIXME. Github doesn't think this is useful though so we have to do it by hand:
|
||
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) { | ||
AbiMapping::Direct(..) => (), | ||
// already erred in rustc_ast_lowering | ||
AbiMapping::Invalid => { | ||
let mut err = struct_span_code_err!( | ||
tcx.dcx(), | ||
span, | ||
E0570, | ||
"`{abi}` is not a supported ABI for the current target", | ||
); | ||
add_abi_diag_help(abi, &mut err); | ||
err.emit(); | ||
tcx.dcx().span_delayed_bug(span, format!("{abi} should be rejected in ast_lowering")); | ||
} | ||
AbiMapping::Deprecated(..) => { | ||
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| { | ||
lint.primary_message("use of calling convention not supported on this target"); | ||
add_abi_diag_help(abi, lint); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi) { | ||
// This is always an FCW, even for `AbiMapping::Invalid`, since we started linting later than | ||
// in `check_abi` above. | ||
match AbiMap::from_target(&tcx.sess.target).canonize_abi(abi, false) { | ||
AbiMapping::Direct(..) => (), | ||
// This is not a redundant match arm: these ABIs started linting after introducing | ||
// UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS already existed and we want to | ||
// avoid expanding the scope of that lint so it can move to a hard error sooner. | ||
AbiMapping::Deprecated(..) => { | ||
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| { | ||
lint.primary_message("use of calling convention not supported on this target"); | ||
add_abi_diag_help(abi, lint); | ||
}); | ||
} | ||
AbiMapping::Invalid => { | ||
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| { | ||
lint.primary_message(format!( | ||
"the calling convention {abi} is not supported on this target" | ||
"{abi} is not a supported ABI for the current target" | ||
)); | ||
add_abi_diag_help(abi, lint); | ||
}); | ||
} | ||
} | ||
|
@@ -855,6 +827,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) { | |
let hir::ItemKind::ForeignMod { abi, items } = it.kind else { | ||
return; | ||
}; | ||
|
||
check_abi(tcx, it.hir_id(), it.span, abi); | ||
|
||
for item in items { | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//@ add-core-stubs | ||
//@ compile-flags: --crate-type=lib --target x86_64-unknown-none | ||
//@ needs-llvm-components: x86 | ||
//@ edition: 2018 | ||
#![no_core] | ||
#![feature(no_core, lang_items)] | ||
extern crate minicore; | ||
use minicore::*; | ||
|
||
// Check we error before unsupported ABIs reach codegen stages. | ||
|
||
fn anything() { | ||
let a = unsafe { mem::transmute::<usize, extern "thiscall" fn(i32)>(4) }(2); | ||
//~^ ERROR: is not a supported ABI for the current target [E0570] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0570]: `"thiscall"` is not a supported ABI for the current target | ||
--> $DIR/unsupported-abi-transmute.rs:13:53 | ||
| | ||
LL | let a = unsafe { mem::transmute::<usize, extern "thiscall" fn(i32)>(4) }(2); | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0570`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// FIXME(workingjubilee): add revisions and generalize to other platform-specific varargs ABIs, | ||
// preferably after the only-arch directive is enhanced with an "or pattern" syntax | ||
//@ only-x86_64 | ||
|
||
// We have to use this flag to force ABI computation of an invalid ABI | ||
//@ compile-flags: -Clink-dead-code | ||
|
||
#![feature(extended_varargs_abi_support)] | ||
|
||
// sometimes fn ptrs with varargs make layout and ABI computation ICE | ||
// as found in https://github.com/rust-lang/rust/issues/142107 | ||
|
||
fn aapcs(f: extern "aapcs" fn(usize, ...)) { | ||
//~^ ERROR [E0570] | ||
// Note we DO NOT have to actually make a call to trigger the ICE! | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0570]: `"aapcs"` is not a supported ABI for the current target | ||
--> $DIR/unsupported-varargs-fnptr.rs:13:20 | ||
| | ||
LL | fn aapcs(f: extern "aapcs" fn(usize, ...)) { | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0570`. |
Uh oh!
There was an error while loading. Please reload this page.