Skip to content

Commit e776065

Browse files
Taint body on invalid call ABI
1 parent e245570 commit e776065

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156156
pub(crate) fn check_call_abi(&self, abi: ExternAbi, span: Span) {
157157
let canon_abi = match AbiMap::from_target(&self.sess().target).canonize_abi(abi, false) {
158158
AbiMapping::Direct(canon_abi) | AbiMapping::Deprecated(canon_abi) => canon_abi,
159-
AbiMapping::Invalid => return,
159+
AbiMapping::Invalid => {
160+
// This should be reported elsewhere, but we want to taint this body
161+
// so that we don't try to evaluate calls to ABIs that are invalid.
162+
let guar = self.dcx().span_delayed_bug(
163+
span,
164+
format!("invalid abi for platform should have reported an error: {abi}"),
165+
);
166+
self.set_tainted_by_errors(guar);
167+
return;
168+
}
160169
};
161170

162171
let valid = match canon_abi {

tests/ui/abi/invalid-call-abi-ctfe.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Fix for #142969 where an invalid ABI in a signature still had its call ABI computed
2+
// because CTFE tried to evaluate it, despite previous errors during AST-to-HIR lowering.
3+
4+
#![feature(rustc_attrs)]
5+
6+
const extern "rust-invalid" fn foo() {
7+
//~^ ERROR "rust-invalid" is not a supported ABI for the current target
8+
panic!()
9+
}
10+
11+
const _: () = foo();
12+
13+
14+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0570]: "rust-invalid" is not a supported ABI for the current target
2+
--> $DIR/invalid-call-abi-ctfe.rs:6:14
3+
|
4+
LL | const extern "rust-invalid" fn foo() {
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)