Skip to content

Commit f2d73af

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 7006047 + c32ad5c commit f2d73af

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/consts.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
127127
//
128128
// We could remove this hack whenever we decide to drop macOS 10.10 support.
129129
if self.tcx.sess.target.options.is_like_osx {
130-
// The `inspect` method is okay here because we checked relocations, and
130+
// The `inspect` method is okay here because we checked for provenance, and
131131
// because we are doing this access to inspect the final interpreter state
132132
// (not as part of the interpreter execution).
133133
//
@@ -296,17 +296,17 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
296296

297297
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAllocation<'tcx>) -> RValue<'gcc> {
298298
let alloc = alloc.inner();
299-
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
299+
let mut llvals = Vec::with_capacity(alloc.provenance().len() + 1);
300300
let dl = cx.data_layout();
301301
let pointer_size = dl.pointer_size.bytes() as usize;
302302

303303
let mut next_offset = 0;
304-
for &(offset, alloc_id) in alloc.relocations().iter() {
304+
for &(offset, alloc_id) in alloc.provenance().iter() {
305305
let offset = offset.bytes();
306306
assert_eq!(offset as usize as u64, offset);
307307
let offset = offset as usize;
308308
if offset > next_offset {
309-
// This `inspect` is okay since we have checked that it is not within a relocation, it
309+
// This `inspect` is okay since we have checked that it is not within a pointer with provenance, it
310310
// is within the bounds of the allocation, and it doesn't affect interpreter execution
311311
// (we inspect the result after interpreter execution). Any undef byte is replaced with
312312
// some arbitrary byte value.
@@ -319,7 +319,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
319319
read_target_uint( dl.endian,
320320
// This `inspect` is okay since it is within the bounds of the allocation, it doesn't
321321
// affect interpreter execution (we inspect the result after interpreter execution),
322-
// and we properly interpret the relocation as a relocation pointer offset.
322+
// and we properly interpret the provenance as a relocation pointer offset.
323323
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
324324
)
325325
.expect("const_alloc_to_llvm: could not read relocation pointer")
@@ -336,7 +336,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl
336336
}
337337
if alloc.len() >= next_offset {
338338
let range = next_offset..alloc.len();
339-
// This `inspect` is okay since we have check that it is after all relocations, it is
339+
// This `inspect` is okay since we have check that it is after all provenance, it is
340340
// within the bounds of the allocation, and it doesn't affect interpreter execution (we
341341
// inspect the result after interpreter execution). Any undef byte is replaced with some
342342
// arbitrary byte value.

0 commit comments

Comments
 (0)