Skip to content

Commit 5e494b4

Browse files
authored
Rollup merge of #101101 - RalfJung:read-pointer-as-bytes, r=oli-obk
interpret: make read-pointer-as-bytes a CTFE-only error with extra information Next step in the reaction to rust-lang/rust#99923. Also teaches Miri to implicitly strip provenance in more situations when transmuting pointers to integers, which fixes rust-lang/miri#2456. Pointer-to-int transmutation during CTFE now produces a message like this: ``` = help: this code performed an operation that depends on the underlying bytes representing a pointer = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported ``` r? ``@oli-obk``
2 parents 663b894 + 94f2fef commit 5e494b4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
430430
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec();
431431
data_ctx.define(bytes.into_boxed_slice());
432432

433-
for &(offset, alloc_id) in alloc.relocations().iter() {
433+
for &(offset, alloc_id) in alloc.provenance().iter() {
434434
let addend = {
435435
let endianness = tcx.data_layout.endian;
436436
let offset = offset.bytes() as usize;

src/intrinsics/simd.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
186186
let size = Size::from_bytes(
187187
4 * ret_lane_count, /* size_of([u32; ret_lane_count]) */
188188
);
189-
alloc.inner().get_bytes(fx, alloc_range(offset, size)).unwrap()
189+
alloc
190+
.inner()
191+
.get_bytes_strip_provenance(fx, alloc_range(offset, size))
192+
.unwrap()
190193
}
191194
_ => unreachable!("{:?}", idx_const),
192195
};

0 commit comments

Comments
 (0)