about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkatelyn a. martin <me+rustlang@katelyn.world>2020-10-23 18:49:34 -0400
committerkatelyn a. martin <me+rustlang@katelyn.world>2021-03-09 14:40:33 -0500
commit05bf037fecfad619e140877769379a1d24952bad (patch)
treec109a2e7e2b610e1ca4809f83be00d8a51ccca25
parentbaf227ea0c1e07fc54395a51e4b3881d701180cb (diff)
downloadrust-05bf037fecfad619e140877769379a1d24952bad.tar.gz
rust-05bf037fecfad619e140877769379a1d24952bad.zip
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 <amanieu@gmail.com>
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs20
-rw-r--r--compiler/rustc_mir_build/src/build/mod.rs18
-rw-r--r--compiler/rustc_target/src/spec/abi.rs15
-rw-r--r--src/doc/unstable-book/src/language-features/c-unwind.md3
4 files changed, 51 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index ee2dffd8bae..814581a6cf1 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -2595,7 +2595,25 @@ fn fn_can_unwind(
                 C { unwind } | Stdcall { unwind } | System { unwind } | Thiscall { unwind } => {
                     unwind
                 }
-                _ => false,
+                Cdecl
+                | Fastcall
+                | Vectorcall
+                | Aapcs
+                | Win64
+                | SysV64
+                | PtxKernel
+                | Msp430Interrupt
+                | X86Interrupt
+                | AmdGpuKernel
+                | EfiApi
+                | AvrInterrupt
+                | AvrNonBlockingInterrupt
+                | CCmseNonSecureCall
+                | RustIntrinsic
+                | PlatformIntrinsic
+                | Unadjusted => false,
+                // In the `if` above, we checked for functions with the Rust calling convention.
+                Rust | RustCall => unreachable!(),
             }
         }
     }
diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs
index dd9c859544f..3ac9c631d03 100644
--- a/compiler/rustc_mir_build/src/build/mod.rs
+++ b/compiler/rustc_mir_build/src/build/mod.rs
@@ -575,7 +575,23 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bo
                 // Rust and `rust-call` functions are allowed to unwind, and should not abort.
                 Rust | RustCall => false,
                 // Other ABI's should abort.
-                _ => true,
+                Cdecl
+                | Fastcall
+                | Vectorcall
+                | Aapcs
+                | Win64
+                | SysV64
+                | PtxKernel
+                | Msp430Interrupt
+                | X86Interrupt
+                | AmdGpuKernel
+                | EfiApi
+                | AvrInterrupt
+                | AvrNonBlockingInterrupt
+                | CCmseNonSecureCall
+                | RustIntrinsic
+                | PlatformIntrinsic
+                | Unadjusted => true,
             }
         }
     }
diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs
index f7f9c30d3b7..17eb33b8f2e 100644
--- a/compiler/rustc_target/src/spec/abi.rs
+++ b/compiler/rustc_target/src/spec/abi.rs
@@ -107,7 +107,7 @@ impl Abi {
         // N.B., this ordering MUST match the AbiDatas array above.
         // (This is ensured by the test indices_are_correct().)
         use Abi::*;
-        match self {
+        let i = match self {
             // Cross-platform ABIs
             Rust => 0,
             C { unwind: false } => 1,
@@ -138,7 +138,18 @@ impl Abi {
             RustCall => 24,
             PlatformIntrinsic => 25,
             Unadjusted => 26,
-        }
+        };
+        debug_assert!(
+            AbiDatas
+                .iter()
+                .enumerate()
+                .find(|(_, AbiData { abi, .. })| *abi == self)
+                .map(|(index, _)| index)
+                .expect("abi variant has associated data")
+                == i,
+            "Abi index did not match `AbiDatas` ordering"
+        );
+        i
     }
 
     #[inline]
diff --git a/src/doc/unstable-book/src/language-features/c-unwind.md b/src/doc/unstable-book/src/language-features/c-unwind.md
index c1705d59acc..2801d9b5e77 100644
--- a/src/doc/unstable-book/src/language-features/c-unwind.md
+++ b/src/doc/unstable-book/src/language-features/c-unwind.md
@@ -6,7 +6,8 @@ The tracking issue for this feature is: [#74990]
 
 ------------------------
 
-Introduces a new ABI string, "C-unwind", to enable unwinding from other
+Introduces four new ABI strings: "C-unwind", "stdcall-unwind",
+"thiscall-unwind", and "system-unwind". These enable unwinding from other
 languages (such as C++) into Rust frames and from Rust into other languages.
 
 See [RFC 2945] for more information.