diff options
| author | Michael Goulet <michael@errs.io> | 2025-06-24 19:32:29 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-06-24 22:43:00 +0000 |
| commit | e776065164f22872e8cadf5bc5e47352c27982dc (patch) | |
| tree | 1ef6eb5c2249794df52b61b0683e19473c492ad0 | |
| parent | e245570def155191b61f73647eb543dd45685b2f (diff) | |
| download | rust-e776065164f22872e8cadf5bc5e47352c27982dc.tar.gz rust-e776065164f22872e8cadf5bc5e47352c27982dc.zip | |
Taint body on invalid call ABI
| -rw-r--r-- | compiler/rustc_hir_typeck/src/callee.rs | 11 | ||||
| -rw-r--r-- | tests/ui/abi/invalid-call-abi-ctfe.rs | 14 | ||||
| -rw-r--r-- | tests/ui/abi/invalid-call-abi-ctfe.stderr | 9 |
3 files changed, 33 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 7a3647df0c4..f790c51f8f1 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -156,7 +156,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(crate) fn check_call_abi(&self, abi: ExternAbi, span: Span) { let canon_abi = match AbiMap::from_target(&self.sess().target).canonize_abi(abi, false) { AbiMapping::Direct(canon_abi) | AbiMapping::Deprecated(canon_abi) => canon_abi, - AbiMapping::Invalid => return, + AbiMapping::Invalid => { + // This should be reported elsewhere, but we want to taint this body + // so that we don't try to evaluate calls to ABIs that are invalid. + let guar = self.dcx().span_delayed_bug( + span, + format!("invalid abi for platform should have reported an error: {abi}"), + ); + self.set_tainted_by_errors(guar); + return; + } }; let valid = match canon_abi { diff --git a/tests/ui/abi/invalid-call-abi-ctfe.rs b/tests/ui/abi/invalid-call-abi-ctfe.rs new file mode 100644 index 00000000000..343cc728fe3 --- /dev/null +++ b/tests/ui/abi/invalid-call-abi-ctfe.rs @@ -0,0 +1,14 @@ +// Fix for #142969 where an invalid ABI in a signature still had its call ABI computed +// because CTFE tried to evaluate it, despite previous errors during AST-to-HIR lowering. + +#![feature(rustc_attrs)] + +const extern "rust-invalid" fn foo() { + //~^ ERROR "rust-invalid" is not a supported ABI for the current target + panic!() +} + +const _: () = foo(); + + +fn main() {} diff --git a/tests/ui/abi/invalid-call-abi-ctfe.stderr b/tests/ui/abi/invalid-call-abi-ctfe.stderr new file mode 100644 index 00000000000..402de4b69b9 --- /dev/null +++ b/tests/ui/abi/invalid-call-abi-ctfe.stderr @@ -0,0 +1,9 @@ +error[E0570]: "rust-invalid" is not a supported ABI for the current target + --> $DIR/invalid-call-abi-ctfe.rs:6:14 + | +LL | const extern "rust-invalid" fn foo() { + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0570`. |
