Skip to content

Commit 6b4c9ee

Browse files
committed
ctfe interpreter: extend provenance so that it can track whether a pointer is immutable
1 parent 3b14266 commit 6b4c9ee

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum TerminationInfo {
4444
},
4545
DataRace {
4646
involves_non_atomic: bool,
47-
ptr: Pointer,
47+
ptr: Pointer<AllocId>,
4848
op1: RacingOp,
4949
op2: RacingOp,
5050
extra: Option<&'static str>,

src/intptrcast.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
256256
/// Convert a relative (tcx) pointer to a Miri pointer.
257257
fn ptr_from_rel_ptr(
258258
&self,
259-
ptr: Pointer<AllocId>,
259+
ptr: Pointer<CtfeProvenance>,
260260
tag: BorTag,
261261
) -> InterpResult<'tcx, Pointer<Provenance>> {
262262
let ecx = self.eval_context_ref();
263263

264-
let (alloc_id, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
264+
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
265+
let alloc_id = prov.alloc_id();
265266
let base_addr = ecx.addr_from_alloc_id(alloc_id)?;
266267

267268
// Add offset with the right kind of pointer-overflowing arithmetic.

src/machine.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1175,11 +1175,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11751175

11761176
fn adjust_alloc_base_pointer(
11771177
ecx: &MiriInterpCx<'mir, 'tcx>,
1178-
ptr: Pointer<AllocId>,
1178+
ptr: Pointer<CtfeProvenance>,
11791179
) -> InterpResult<'tcx, Pointer<Provenance>> {
1180+
let alloc_id = ptr.provenance.alloc_id();
11801181
if cfg!(debug_assertions) {
11811182
// The machine promises to never call us on thread-local or extern statics.
1182-
let alloc_id = ptr.provenance;
11831183
match ecx.tcx.try_get_global_alloc(alloc_id) {
11841184
Some(GlobalAlloc::Static(def_id)) if ecx.tcx.is_thread_local_static(def_id) => {
11851185
panic!("adjust_alloc_base_pointer called on thread-local static")
@@ -1190,8 +1190,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11901190
_ => {}
11911191
}
11921192
}
1193+
// FIXME: can we somehow preserve the immutability of `ptr`?
11931194
let tag = if let Some(borrow_tracker) = &ecx.machine.borrow_tracker {
1194-
borrow_tracker.borrow_mut().base_ptr_tag(ptr.provenance, &ecx.machine)
1195+
borrow_tracker.borrow_mut().base_ptr_tag(alloc_id, &ecx.machine)
11951196
} else {
11961197
// Value does not matter, SB is disabled
11971198
BorTag::default()

0 commit comments

Comments
 (0)