Fix panic with reported const_eval promoted error
This commit is contained in:
parent
a5fdefe45a
commit
11af20b156
@ -1134,7 +1134,7 @@ pub fn trans_place<'a, 'tcx: 'a>(
|
||||
match place {
|
||||
Place::Base(base) => match base {
|
||||
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_),
|
||||
}
|
||||
Place::Projection(projection) => {
|
||||
|
@ -53,16 +53,22 @@ pub fn codegen_static_ref<'a, 'tcx: 'a>(
|
||||
pub fn trans_promoted<'a, 'tcx: 'a>(
|
||||
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
||||
promoted: Promoted,
|
||||
dest_ty: Ty<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
let const_ = fx
|
||||
match fx
|
||||
.tcx
|
||||
.const_eval(ParamEnv::reveal_all().and(GlobalId {
|
||||
instance: fx.instance,
|
||||
promoted: Some(promoted),
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
trans_const_place(fx, const_)
|
||||
{
|
||||
Ok(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>(
|
||||
|
@ -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);
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user