Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0f77e83

Browse files
Rollup merge of #142983 - compiler-errors:taint-invalid-call-abi, r=workingjubilee
Taint body on invalid call ABI Fixes #142969 I'm not certain if there are any other paths that should be tainted, but they would operate similarly. Perhaps pointer coercion. Introduces `extern "rust-invalid"` for testing purposes. r? ```@workingjubilee``` or ```@oli-obk``` (or anyone)
2 parents d392e88 + e776065 commit 0f77e83

File tree

13 files changed

+70
-3
lines changed

13 files changed

+70
-3
lines changed

‎compiler/rustc_abi/src/extern_abi.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub enum ExternAbi {
3636
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
3737
RustCold,
3838

39+
/// An always-invalid ABI that's used to test "this ABI is not supported by this platform"
40+
/// in a platform-agnostic way.
41+
RustInvalid,
42+
3943
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
4044
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
4145
Unadjusted,
@@ -157,6 +161,7 @@ abi_impls! {
157161
RiscvInterruptS =><= "riscv-interrupt-s",
158162
RustCall =><= "rust-call",
159163
RustCold =><= "rust-cold",
164+
RustInvalid =><= "rust-invalid",
160165
Stdcall { unwind: false } =><= "stdcall",
161166
Stdcall { unwind: true } =><= "stdcall-unwind",
162167
System { unwind: false } =><= "system",

‎compiler/rustc_ast_lowering/src/stability.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
9696
ExternAbi::RustCold => {
9797
Err(UnstableAbi { abi, feature: sym::rust_cold_cc, explain: GateReason::Experimental })
9898
}
99+
ExternAbi::RustInvalid => {
100+
Err(UnstableAbi { abi, feature: sym::rustc_attrs, explain: GateReason::ImplDetail })
101+
}
99102
ExternAbi::GpuKernel => Err(UnstableAbi {
100103
abi,
101104
feature: sym::abi_gpu_kernel,

‎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 {

‎compiler/rustc_middle/src/ty/layout.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
12531253
| CCmseNonSecureCall
12541254
| CCmseNonSecureEntry
12551255
| Custom
1256-
| Unadjusted => false,
1256+
| Unadjusted
1257+
| RustInvalid => false,
12571258
Rust | RustCall | RustCold => tcx.sess.panic_strategy() == PanicStrategy::Unwind,
12581259
}
12591260
}

‎compiler/rustc_smir/src/rustc_internal/internal.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ impl RustcInternal for Abi {
494494
Abi::RustCall => rustc_abi::ExternAbi::RustCall,
495495
Abi::Unadjusted => rustc_abi::ExternAbi::Unadjusted,
496496
Abi::RustCold => rustc_abi::ExternAbi::RustCold,
497+
Abi::RustInvalid => rustc_abi::ExternAbi::RustInvalid,
497498
Abi::RiscvInterruptM => rustc_abi::ExternAbi::RiscvInterruptM,
498499
Abi::RiscvInterruptS => rustc_abi::ExternAbi::RiscvInterruptS,
499500
Abi::Custom => rustc_abi::ExternAbi::Custom,

‎compiler/rustc_smir/src/rustc_smir/convert/ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
877877
ExternAbi::RustCall => Abi::RustCall,
878878
ExternAbi::Unadjusted => Abi::Unadjusted,
879879
ExternAbi::RustCold => Abi::RustCold,
880+
ExternAbi::RustInvalid => Abi::RustInvalid,
880881
ExternAbi::RiscvInterruptM => Abi::RiscvInterruptM,
881882
ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
882883
ExternAbi::Custom => Abi::Custom,

‎compiler/rustc_smir/src/stable_mir/ty.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ pub enum Abi {
11261126
RustCold,
11271127
RiscvInterruptM,
11281128
RiscvInterruptS,
1129+
RustInvalid,
11291130
Custom,
11301131
}
11311132

‎compiler/rustc_target/src/spec/abi_map.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ impl AbiMap {
156156
| ExternAbi::Msp430Interrupt
157157
| ExternAbi::RiscvInterruptM
158158
| ExternAbi::RiscvInterruptS
159-
| ExternAbi::X86Interrupt,
159+
| ExternAbi::X86Interrupt
160+
| ExternAbi::RustInvalid,
160161
_,
161162
) => return AbiMapping::Invalid,
162163
};
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)

AltStyle によって変換されたページ (->オリジナル) /