Skip to content

Commit ddaee78

Browse files
Taint body on invalid call ABI
1 parent 36b2163 commit ddaee78

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-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.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Fix for #142969.
2+
3+
#![feature(abi_c_cmse_nonsecure_call)]
4+
5+
const extern "C-cmse-nonsecure-call" fn foo() {
6+
//~^ ERROR "C-cmse-nonsecure-call" is not a supported ABI for the current target
7+
//~| ERROR the `"C-cmse-nonsecure-call"` ABI is only allowed on function pointers
8+
panic!()
9+
}
10+
11+
const _: () = foo();
12+
13+
14+
fn main() {}

tests/ui/abi/invalid-call-abi.stderr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0570]: "C-cmse-nonsecure-call" is not a supported ABI for the current target
2+
--> $DIR/invalid-call-abi.rs:5:14
3+
|
4+
LL | const extern "C-cmse-nonsecure-call" fn foo() {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0781]: the `"C-cmse-nonsecure-call"` ABI is only allowed on function pointers
8+
--> $DIR/invalid-call-abi.rs:5:1
9+
|
10+
LL | const extern "C-cmse-nonsecure-call" fn foo() {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0570, E0781.
16+
For more information about an error, try `rustc --explain E0570`.

0 commit comments

Comments
 (0)