Skip to content

Commit

Permalink
use abort instead of unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 5, 2019
1 parent e5d50e3 commit f5bd947
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/librustc_codegen_ssa/mir/block.rs
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_codegen_ssa/mir/place.rs
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/test/codegen/set-discriminant-invalid.rs
Expand Up @@ -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]
Expand Down

0 comments on commit f5bd947

Please sign in to comment.