Fix trans_get_discriminant for uninhabited types

This commit is contained in:
bjorn3 2019-02-24 17:38:31 +01:00
parent 8a9cadcd4c
commit a5fdefe45a
2 changed files with 9 additions and 4 deletions

View File

@ -739,7 +739,7 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
let layout = place.layout();
if layout.abi == layout::Abi::Uninhabited {
trap_unreachable(&mut fx.bcx);
return trap_unreachable_ret_value(fx, dest_layout);
}
match layout.variants {
layout::Variants::Single { index } => {

View File

@ -1,6 +1,4 @@
use cranelift::prelude::*;
use cranelift::codegen::ir::TrapCode;
use crate::prelude::*;
/// Trap code: user0
pub fn trap_panic(bcx: &mut FunctionBuilder) {
@ -11,3 +9,10 @@ pub fn trap_panic(bcx: &mut FunctionBuilder) {
pub fn trap_unreachable(bcx: &mut FunctionBuilder) {
bcx.ins().trap(TrapCode::User(!0));
}
pub fn trap_unreachable_ret_value<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>) -> CValue<'tcx> {
let true_ = fx.bcx.ins().iconst(types::I32, 1);
fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
CValue::ByRef(zero, dest_layout)
}