Skip to content

Commit f5bd947

Browse files
committed
use abort instead of unreachable
1 parent e5d50e3 commit f5bd947

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/librustc_codegen_ssa/mir/block.rs

+6
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
261261
if self.fn_abi.ret.layout.abi.is_uninhabited() {
262262
// Functions with uninhabited return values are marked `noreturn`,
263263
// so we should make sure that we never actually do.
264+
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
265+
// if that turns out to be helpful.
264266
bx.abort();
267+
// `abort` does not terminate the block, so we still need to generate
268+
// an `unreachable` terminator after it.
265269
bx.unreachable();
266270
return;
267271
}
@@ -825,6 +829,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
825829

826830
mir::TerminatorKind::Abort => {
827831
bx.abort();
832+
// `abort` does not terminate the block, so we still need to generate
833+
// an `unreachable` terminator after it.
828834
bx.unreachable();
829835
}
830836

src/librustc_codegen_ssa/mir/place.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
333333
variant_index: VariantIdx
334334
) {
335335
if self.layout.for_variant(bx.cx(), variant_index).abi.is_uninhabited() {
336-
bx.unreachable();
336+
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
337+
// if that turns out to be helpful.
338+
bx.abort();
337339
return;
338340
}
339341
match self.layout.variants {

src/test/codegen/set-discriminant-invalid.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ impl IntoError<Error> for Api
2020
{
2121
type Source = ApiError;
2222
// CHECK-LABEL: @into_error
23-
// CHECK: unreachable
24-
// Also check the next two instructions to make sure we do not match against `unreachable`
25-
// elsewhere in the code (e.g., in the closure bode).
23+
// CHECK: llvm.trap()
24+
// Also check the next two instructions to make sure we do not match against `trap`
25+
// elsewhere in the code.
2626
// CHECK-NEXT: load
2727
// CHECK-NEXT: ret
2828
#[no_mangle]

0 commit comments

Comments
 (0)