Skip to content

Commit 8459a16

Browse files
committed
Auto merge of rust-lang#2683 - RalfJung:align_offset, r=RalfJung
make align_offset always work on no-provenance pointers Fixes rust-lang/miri#2682
2 parents c26b510 + c8c82a0 commit 8459a16

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/tools/miri/src/shims/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8989
}
9090

9191
let ptr = this.read_pointer(ptr_op)?;
92+
// If this carries no provenance, treat it like an integer.
93+
if ptr.provenance.is_none() {
94+
// Use actual implementation.
95+
return Ok(false);
96+
}
97+
9298
if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
9399
// Only do anything if we can identify the allocation this goes to.
94100
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);

src/tools/miri/tests/pass/align_offset_symbolic.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@compile-flags: -Zmiri-symbolic-alignment-check
2+
#![feature(strict_provenance)]
3+
4+
use std::ptr;
25

36
fn test_align_offset() {
47
let d = Box::new([0u32; 4]);
@@ -16,6 +19,9 @@ fn test_align_offset() {
1619
assert_eq!(raw.wrapping_offset(2).align_offset(2), 0);
1720
assert_eq!(raw.wrapping_offset(2).align_offset(4), 2);
1821
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment
22+
23+
let p = ptr::invalid::<()>(1);
24+
assert_eq!(p.align_offset(1), 0);
1925
}
2026

2127
fn test_align_to() {

0 commit comments

Comments
 (0)