about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-11-25 18:41:53 +0100
committerRalf Jung <post@ralfj.de>2023-12-07 17:46:36 +0100
commitcb32ffd8da5831c7052362fa58d27b36558b3b78 (patch)
tree5c287ddf627cf3b03b7630cb6c00f40c0ac8055c
parent8e13be084a316883b4aadabbc9ff08aaaf676aa6 (diff)
downloadrust-cb32ffd8da5831c7052362fa58d27b36558b3b78.tar.gz
rust-cb32ffd8da5831c7052362fa58d27b36558b3b78.zip
ctfe interpreter: extend provenance so that it can track whether a pointer is immutable
-rw-r--r--src/common.rs3
-rw-r--r--src/consts.rs5
2 files changed, 5 insertions, 3 deletions
diff --git a/src/common.rs b/src/common.rs
index 93fe27e547a..b7ddc410315 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -199,7 +199,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
                 }
             }
             Scalar::Ptr(ptr, _size) => {
-                let (alloc_id, offset) = ptr.into_parts();
+                let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative
+                let alloc_id = prov.alloc_id();
                 let base_addr =
                     match self.tcx.global_alloc(alloc_id) {
                         GlobalAlloc::Memory(alloc) => {
diff --git a/src/consts.rs b/src/consts.rs
index d8a1fd315c0..f06416b9bb5 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -285,7 +285,8 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
     let pointer_size = dl.pointer_size.bytes() as usize;
 
     let mut next_offset = 0;
-    for &(offset, alloc_id) in alloc.provenance().ptrs().iter() {
+    for &(offset, prov) in alloc.provenance().ptrs().iter() {
+        let alloc_id = prov.alloc_id();
         let offset = offset.bytes();
         assert_eq!(offset as usize as u64, offset);
         let offset = offset as usize;
@@ -313,7 +314,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
 
         llvals.push(cx.scalar_to_backend(
             InterpScalar::from_pointer(
-                interpret::Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
+                interpret::Pointer::new(prov, Size::from_bytes(ptr_offset)),
                 &cx.tcx,
             ),
             abi::Scalar::Initialized { value: Primitive::Pointer(address_space), valid_range: WrappingRange::full(dl.pointer_size) },