Let codegen_get_discriminant accept CValue instead of CPlace
This commit is contained in:
parent
5b818e5e0f
commit
1bee110d95
@ -367,10 +367,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
||||
_ => unreachable!("cast adt {} -> {}", from_ty, to_ty),
|
||||
}
|
||||
|
||||
// FIXME avoid forcing to stack
|
||||
let place =
|
||||
CPlace::for_addr(operand.force_stack(fx), operand.layout());
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, place, fx.layout_of(to_ty));
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, operand, fx.layout_of(to_ty));
|
||||
lval.write_cvalue(fx, discr);
|
||||
} else {
|
||||
let to_clif_ty = fx.clif_type(to_ty).unwrap();
|
||||
@ -405,7 +402,8 @@ fn trans_stmt<'a, 'tcx: 'a>(
|
||||
}
|
||||
Rvalue::Discriminant(place) => {
|
||||
let place = trans_place(fx, place);
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, place, dest_layout);
|
||||
let value = place.to_cvalue(fx);
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
|
||||
lval.write_cvalue(fx, discr);
|
||||
}
|
||||
Rvalue::Repeat(operand, times) => {
|
||||
|
@ -58,10 +58,10 @@ pub fn codegen_set_discriminant<'tcx>(
|
||||
|
||||
pub fn codegen_get_discriminant<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||
place: CPlace<'tcx>,
|
||||
value: CValue<'tcx>,
|
||||
dest_layout: TyLayout<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let layout = place.layout();
|
||||
let layout = value.layout();
|
||||
|
||||
if layout.abi == layout::Abi::Uninhabited {
|
||||
return trap_unreachable_ret_value(fx, dest_layout, "[panic] Tried to get discriminant for uninhabited type.");
|
||||
@ -82,7 +82,7 @@ pub fn codegen_get_discriminant<'tcx>(
|
||||
}
|
||||
};
|
||||
|
||||
let discr = place.place_field(fx, mir::Field::new(discr_index)).to_cvalue(fx);
|
||||
let discr = value.value_field(fx, mir::Field::new(discr_index));
|
||||
let discr_ty = discr.layout().ty;
|
||||
let lldiscr = discr.load_scalar(fx);
|
||||
match discr_kind {
|
||||
|
@ -374,10 +374,10 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
|
||||
fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
|
||||
}
|
||||
};
|
||||
discriminant_value, (c val) {
|
||||
let pointee_layout = fx.layout_of(val.layout().ty.builtin_deref(true).unwrap().ty);
|
||||
let place = CPlace::for_addr(val.load_scalar(fx), pointee_layout);
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, place, ret.layout());
|
||||
discriminant_value, (c ptr) {
|
||||
let pointee_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
|
||||
let val = CValue::by_ref(ptr.load_scalar(fx), pointee_layout);
|
||||
let discr = crate::discriminant::codegen_get_discriminant(fx, val, ret.layout());
|
||||
ret.write_cvalue(fx, discr);
|
||||
};
|
||||
size_of, <T> () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user