Fix trans_get_discriminant for uninhabited types
This commit is contained in:
parent
8a9cadcd4c
commit
a5fdefe45a
@ -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 } => {
|
||||
|
11
src/trap.rs
11
src/trap.rs
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user