Take an AllocId in intern_const_alloc_for_constprop.

This commit is contained in:
Camille GILLOT 2023-10-12 16:17:06 +00:00
parent e3538d11f1
commit f08dc9be17
2 changed files with 3 additions and 9 deletions

View File

@ -459,10 +459,9 @@ pub fn intern_const_alloc_for_constprop<
M: CompileTimeMachine<'mir, 'tcx, T>,
>(
ecx: &mut InterpCx<'mir, 'tcx, M>,
ret: &MPlaceTy<'tcx>,
alloc_id: AllocId,
) -> InterpResult<'tcx, ()> {
// Move allocation to `tcx`.
let alloc_id = ret.ptr().provenance.unwrap();
let Some((_, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) else {
// Pointer not found in local memory map. It is either a pointer to the global
// map, or dangling.

View File

@ -61,7 +61,6 @@ use rustc_hir::def::DefKind;
use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec;
use rustc_macros::newtype_index;
use rustc_middle::mir::interpret::GlobalAlloc;
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::layout::LayoutOf;
@ -861,14 +860,10 @@ fn op_to_prop_const<'tcx>(
return None;
}
intern_const_alloc_for_constprop(ecx, &mplace).ok()?;
let pointer = mplace.ptr().into_pointer_or_addr().ok()?;
let (alloc_id, offset) = pointer.into_parts();
match ecx.tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(_) => return Some(ConstValue::Indirect { alloc_id, offset }),
// Fallthrough to copying the data.
_ => {}
}
intern_const_alloc_for_constprop(ecx, alloc_id).ok()?;
return Some(ConstValue::Indirect { alloc_id, offset });
}
// Everything failed: create a new allocation to hold the data.