Skip to content

Commit 05bf037

Browse files
katelyn a. martinAmanieunikomatsakis
committed
address pr review comments
### Add debug assertion to check `AbiDatas` ordering This makes a small alteration to `Abi::index`, so that we include a debug assertion to check that the index we are returning corresponds with the same abi in our data array. This will help prevent ordering bugs in the future, which can manifest in rather strange errors. ### Using exhaustive ABI matches This slightly modifies the changes from our previous commits, favoring exhaustive matches in place of `_ => ...` fall-through arms. This should help with maintenance in the future, when additional ABI's are added, or when existing ABI's are modified. ### List all `-unwind` ABI's in unstable book This updates the `c-unwind` page in the unstable book to list _all_ of the other ABI strings that are introduced by this feature gate. Now, all of the ABI's specified by RFC 2945 are shown. Co-authored-by: Amanieu d'Antras <[email protected]> Co-authored-by: Niko Matsakis <[email protected]>
1 parent baf227e commit 05bf037

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

compiler/rustc_middle/src/ty/layout.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,25 @@ fn fn_can_unwind(
25952595
C { unwind } | Stdcall { unwind } | System { unwind } | Thiscall { unwind } => {
25962596
unwind
25972597
}
2598-
_ => false,
2598+
Cdecl
2599+
| Fastcall
2600+
| Vectorcall
2601+
| Aapcs
2602+
| Win64
2603+
| SysV64
2604+
| PtxKernel
2605+
| Msp430Interrupt
2606+
| X86Interrupt
2607+
| AmdGpuKernel
2608+
| EfiApi
2609+
| AvrInterrupt
2610+
| AvrNonBlockingInterrupt
2611+
| CCmseNonSecureCall
2612+
| RustIntrinsic
2613+
| PlatformIntrinsic
2614+
| Unadjusted => false,
2615+
// In the `if` above, we checked for functions with the Rust calling convention.
2616+
Rust | RustCall => unreachable!(),
25992617
}
26002618
}
26012619
}

compiler/rustc_mir_build/src/build/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,23 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bo
575575
// Rust and `rust-call` functions are allowed to unwind, and should not abort.
576576
Rust | RustCall => false,
577577
// Other ABI's should abort.
578-
_ => true,
578+
Cdecl
579+
| Fastcall
580+
| Vectorcall
581+
| Aapcs
582+
| Win64
583+
| SysV64
584+
| PtxKernel
585+
| Msp430Interrupt
586+
| X86Interrupt
587+
| AmdGpuKernel
588+
| EfiApi
589+
| AvrInterrupt
590+
| AvrNonBlockingInterrupt
591+
| CCmseNonSecureCall
592+
| RustIntrinsic
593+
| PlatformIntrinsic
594+
| Unadjusted => true,
579595
}
580596
}
581597
}

compiler/rustc_target/src/spec/abi.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Abi {
107107
// N.B., this ordering MUST match the AbiDatas array above.
108108
// (This is ensured by the test indices_are_correct().)
109109
use Abi::*;
110-
match self {
110+
let i = match self {
111111
// Cross-platform ABIs
112112
Rust => 0,
113113
C { unwind: false } => 1,
@@ -138,7 +138,18 @@ impl Abi {
138138
RustCall => 24,
139139
PlatformIntrinsic => 25,
140140
Unadjusted => 26,
141-
}
141+
};
142+
debug_assert!(
143+
AbiDatas
144+
.iter()
145+
.enumerate()
146+
.find(|(_, AbiData { abi, .. })| *abi == self)
147+
.map(|(index, _)| index)
148+
.expect("abi variant has associated data")
149+
== i,
150+
"Abi index did not match `AbiDatas` ordering"
151+
);
152+
i
142153
}
143154

144155
#[inline]

src/doc/unstable-book/src/language-features/c-unwind.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ The tracking issue for this feature is: [#74990]
66

77
------------------------
88

9-
Introduces a new ABI string, "C-unwind", to enable unwinding from other
9+
Introduces four new ABI strings: "C-unwind", "stdcall-unwind",
10+
"thiscall-unwind", and "system-unwind". These enable unwinding from other
1011
languages (such as C++) into Rust frames and from Rust into other languages.
1112

1213
See [RFC 2945] for more information.

0 commit comments

Comments
 (0)