mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
allow mplace_to_imm_ptr to return different types of pointers
This commit is contained in:
@@ -261,7 +261,7 @@ fn write_field(
|
||||
None => Cow::Owned(idx.to_string()), // For tuples
|
||||
};
|
||||
let name_place = self.allocate_str_dedup(&name)?;
|
||||
let ptr = self.mplace_to_imm_ptr(&name_place)?;
|
||||
let ptr = self.mplace_to_imm_ptr(&name_place, None)?;
|
||||
self.write_immediate(*ptr, &field_place)?
|
||||
}
|
||||
sym::ty => {
|
||||
@@ -444,7 +444,7 @@ pub(crate) fn write_fn_ptr_type_info(
|
||||
other_abi => {
|
||||
let (variant, variant_place) = self.downcast(&field_place, sym::Named)?;
|
||||
let str_place = self.allocate_str_dedup(other_abi.as_str())?;
|
||||
let str_ref = self.mplace_to_imm_ptr(&str_place)?;
|
||||
let str_ref = self.mplace_to_imm_ptr(&str_place, None)?;
|
||||
let payload = self.project_field(&variant_place, FieldIdx::ZERO)?;
|
||||
self.write_immediate(*str_ref, &payload)?;
|
||||
self.write_discriminant(variant, &field_place)?;
|
||||
|
||||
@@ -165,7 +165,7 @@ fn write_enum_variant(
|
||||
match field_def.name {
|
||||
sym::name => {
|
||||
let name_place = self.allocate_str_dedup(variant_def.name.as_str())?;
|
||||
let ptr = self.mplace_to_imm_ptr(&name_place)?;
|
||||
let ptr = self.mplace_to_imm_ptr(&name_place, None)?;
|
||||
self.write_immediate(*ptr, &field_place)?
|
||||
}
|
||||
sym::fields => {
|
||||
|
||||
@@ -898,7 +898,7 @@ pub(super) fn init_drop_in_place_call(
|
||||
};
|
||||
let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?;
|
||||
|
||||
let arg = self.mplace_to_imm_ptr(&place)?;
|
||||
let arg = self.mplace_to_imm_ptr(&place, None)?;
|
||||
let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?);
|
||||
|
||||
self.init_fn_call(
|
||||
|
||||
@@ -439,14 +439,24 @@ pub fn imm_ptr_to_mplace(
|
||||
}
|
||||
|
||||
/// Turn a mplace into a (thin or wide) mutable raw pointer, pointing to the same space.
|
||||
///
|
||||
/// `align` information is lost!
|
||||
/// This is the inverse of `imm_ptr_to_mplace`.
|
||||
///
|
||||
/// If `ptr_ty` is provided, the resulting pointer will be of that type. Otherwise, it defaults to `*mut _`.
|
||||
/// `ptr_ty` must be a type with builtin deref which derefs to the type of `mplace` (`mplace.layout.ty`).
|
||||
pub fn mplace_to_imm_ptr(
|
||||
&self,
|
||||
mplace: &MPlaceTy<'tcx, M::Provenance>,
|
||||
ptr_ty: Option<Ty<'tcx>>,
|
||||
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
||||
let imm = mplace.mplace.to_ref(self);
|
||||
let layout = self.layout_of(Ty::new_mut_ptr(self.tcx.tcx, mplace.layout.ty))?;
|
||||
|
||||
let ptr_ty = ptr_ty
|
||||
.inspect(|t| assert_eq!(t.builtin_deref(true), Some(mplace.layout.ty)))
|
||||
.unwrap_or_else(|| Ty::new_mut_ptr(self.tcx.tcx, mplace.layout.ty));
|
||||
|
||||
let layout = self.layout_of(ptr_ty)?;
|
||||
interp_ok(ImmTy::from_immediate(imm, layout))
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ fn start_panic(&mut self, msg: &str, unwind: mir::UnwindAction) -> InterpResult<
|
||||
this.call_function(
|
||||
panic,
|
||||
ExternAbi::Rust,
|
||||
&[this.mplace_to_imm_ptr(&msg)?],
|
||||
&[this.mplace_to_imm_ptr(&msg, None)?],
|
||||
None,
|
||||
ReturnContinuation::Goto { ret: None, unwind },
|
||||
)
|
||||
@@ -39,7 +39,7 @@ fn start_panic_nounwind(&mut self, msg: &str) -> InterpResult<'tcx> {
|
||||
this.call_function(
|
||||
panic,
|
||||
ExternAbi::Rust,
|
||||
&[this.mplace_to_imm_ptr(&msg)?],
|
||||
&[this.mplace_to_imm_ptr(&msg, None)?],
|
||||
None,
|
||||
ReturnContinuation::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user