Skip to content

Commit 7064f69

Browse files
committed
Abort instead of UB if promotion fails
1 parent 3bea4d1 commit 7064f69

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc_codegen_llvm/mir/operand.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::indexed_vec::Idx;
1818
use rustc_data_structures::sync::Lrc;
1919

2020
use base;
21-
use common::{CodegenCx, C_null, C_undef, C_usize};
21+
use common::{CodegenCx, C_undef, C_usize};
2222
use builder::{Builder, MemFlags};
2323
use value::Value;
2424
use type_of::LayoutLlvmExt;
@@ -411,7 +411,10 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
411411
.unwrap_or_else(|err| {
412412
match constant.literal {
413413
mir::Literal::Promoted { .. } => {
414-
// FIXME: generate a panic here
414+
// this is unreachable as long as runtime
415+
// and compile-time agree on values
416+
// With floats that won't always be true
417+
// so we generate an abort below
415418
},
416419
mir::Literal::Value { .. } => {
417420
err.report_as_error(
@@ -420,10 +423,12 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
420423
);
421424
},
422425
}
426+
let fnname = bx.cx.get_intrinsic(&("llvm.trap"));
427+
bx.call(fnname, &[], None);
423428
// We've errored, so we don't have to produce working code.
424429
let layout = bx.cx.layout_of(ty);
425430
PlaceRef::new_sized(
426-
C_null(layout.llvm_type(bx.cx).ptr_to()),
431+
C_undef(layout.llvm_type(bx.cx).ptr_to()),
427432
layout,
428433
layout.align,
429434
).load(bx)

0 commit comments

Comments
 (0)