Fix panic with reported const_eval promoted error

This commit is contained in:
bjorn3 2019-02-24 18:07:20 +01:00
parent a5fdefe45a
commit 11af20b156
3 changed files with 18 additions and 5 deletions

View File

@ -1134,7 +1134,7 @@ pub fn trans_place<'a, 'tcx: 'a>(
match place { match place {
Place::Base(base) => match base { Place::Base(base) => match base {
PlaceBase::Local(local) => fx.get_local_place(*local), PlaceBase::Local(local) => fx.get_local_place(*local),
PlaceBase::Promoted(promoted) => crate::constant::trans_promoted(fx, promoted.0), PlaceBase::Promoted(data) => crate::constant::trans_promoted(fx, data.0, data.1),
PlaceBase::Static(static_) => crate::constant::codegen_static_ref(fx, static_), PlaceBase::Static(static_) => crate::constant::codegen_static_ref(fx, static_),
} }
Place::Projection(projection) => { Place::Projection(projection) => {

View File

@ -53,16 +53,22 @@ pub fn codegen_static_ref<'a, 'tcx: 'a>(
pub fn trans_promoted<'a, 'tcx: 'a>( pub fn trans_promoted<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>, fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
promoted: Promoted, promoted: Promoted,
dest_ty: Ty<'tcx>,
) -> CPlace<'tcx> { ) -> CPlace<'tcx> {
let const_ = fx match fx
.tcx .tcx
.const_eval(ParamEnv::reveal_all().and(GlobalId { .const_eval(ParamEnv::reveal_all().and(GlobalId {
instance: fx.instance, instance: fx.instance,
promoted: Some(promoted), promoted: Some(promoted),
})) }))
.unwrap(); {
Ok(const_) => {
trans_const_place(fx, const_) let cplace = trans_const_place(fx, const_);
debug_assert_eq!(cplace.layout(), fx.layout_of(dest_ty));
cplace
}
Err(_) => crate::trap::trap_unreachable_ret_place(fx, fx.layout_of(dest_ty)),
}
} }
pub fn trans_constant<'a, 'tcx: 'a>( pub fn trans_constant<'a, 'tcx: 'a>(

View File

@ -16,3 +16,10 @@ pub fn trap_unreachable_ret_value<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl crane
let zero = fx.bcx.ins().iconst(fx.pointer_type, 0); let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
CValue::ByRef(zero, dest_layout) CValue::ByRef(zero, dest_layout)
} }
pub fn trap_unreachable_ret_place<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>) -> CPlace<'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);
CPlace::Addr(zero, None, dest_layout)
}