Skip to content

Commit

Permalink
Auto merge of #2683 - RalfJung:align_offset, r=RalfJung
Browse files Browse the repository at this point in the history
make align_offset always work on no-provenance pointers

Fixes #2682
  • Loading branch information
bors committed Nov 20, 2022
2 parents e76a959 + 7a3aa54 commit 94ddca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
}

let ptr = this.read_pointer(ptr_op)?;
// If this carries no provenance, treat it like an integer.
if ptr.provenance.is_none() {
// Use actual implementation.
return Ok(false);
}

if let Ok((alloc_id, _offset, _)) = this.ptr_try_get_alloc_id(ptr) {
// Only do anything if we can identify the allocation this goes to.
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);
Expand Down
6 changes: 6 additions & 0 deletions tests/pass/align_offset_symbolic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//@compile-flags: -Zmiri-symbolic-alignment-check
#![feature(strict_provenance)]

use std::ptr;

fn test_align_offset() {
let d = Box::new([0u32; 4]);
Expand All @@ -16,6 +19,9 @@ fn test_align_offset() {
assert_eq!(raw.wrapping_offset(2).align_offset(2), 0);
assert_eq!(raw.wrapping_offset(2).align_offset(4), 2);
assert_eq!(raw.wrapping_offset(2).align_offset(8), usize::MAX); // requested alignment higher than allocation alignment

let p = ptr::invalid::<()>(1);
assert_eq!(p.align_offset(1), 0);
}

fn test_align_to() {
Expand Down

0 comments on commit 94ddca1

Please sign in to comment.