about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2019-12-05 23:59:30 +0100
committerRalf Jung <post@ralfj.de>2019-12-06 00:10:01 +0100
commitf5bd94768a5ca901eb7555a4c3fd4d3005c1ad76 (patch)
tree04f463e9088538296eddbbfdc346ae495aa7d50c
parente5d50e3e88f88e8a8b20e90bb0d561e1ed71fe5f (diff)
downloadrust-f5bd94768a5ca901eb7555a4c3fd4d3005c1ad76.tar.gz
rust-f5bd94768a5ca901eb7555a4c3fd4d3005c1ad76.zip
use abort instead of unreachable
-rw-r--r--src/librustc_codegen_ssa/mir/block.rs6
-rw-r--r--src/librustc_codegen_ssa/mir/place.rs4
-rw-r--r--src/test/codegen/set-discriminant-invalid.rs6
3 files changed, 12 insertions, 4 deletions
diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs
index 6dccf329c9f..ce703f24335 100644
--- a/src/librustc_codegen_ssa/mir/block.rs
+++ b/src/librustc_codegen_ssa/mir/block.rs
@@ -261,7 +261,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
         if self.fn_abi.ret.layout.abi.is_uninhabited() {
             // Functions with uninhabited return values are marked `noreturn`,
             // so we should make sure that we never actually do.
+            // We play it safe by using a well-defined `abort`, but we could go for immediate UB
+            // if that turns out to be helpful.
             bx.abort();
+            // `abort` does not terminate the block, so we still need to generate
+            // an `unreachable` terminator after it.
             bx.unreachable();
             return;
         }
@@ -825,6 +829,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 
             mir::TerminatorKind::Abort => {
                 bx.abort();
+                // `abort` does not terminate the block, so we still need to generate
+                // an `unreachable` terminator after it.
                 bx.unreachable();
             }
 
diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs
index b8ff2249dcb..e60b8861faf 100644
--- a/src/librustc_codegen_ssa/mir/place.rs
+++ b/src/librustc_codegen_ssa/mir/place.rs
@@ -333,7 +333,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
         variant_index: VariantIdx
     ) {
         if self.layout.for_variant(bx.cx(), variant_index).abi.is_uninhabited() {
-            bx.unreachable();
+            // We play it safe by using a well-defined `abort`, but we could go for immediate UB
+            // if that turns out to be helpful.
+            bx.abort();
             return;
         }
         match self.layout.variants {
diff --git a/src/test/codegen/set-discriminant-invalid.rs b/src/test/codegen/set-discriminant-invalid.rs
index 65e07fff1e4..d9614f062b7 100644
--- a/src/test/codegen/set-discriminant-invalid.rs
+++ b/src/test/codegen/set-discriminant-invalid.rs
@@ -20,9 +20,9 @@ impl IntoError<Error> for Api
 {
     type Source = ApiError;
     // CHECK-LABEL: @into_error
-    // CHECK: unreachable
-    // Also check the next two instructions to make sure we do not match against `unreachable`
-    // elsewhere in the code (e.g., in the closure bode).
+    // CHECK: llvm.trap()
+    // Also check the next two instructions to make sure we do not match against `trap`
+    // elsewhere in the code.
     // CHECK-NEXT: load
     // CHECK-NEXT: ret
     #[no_mangle]