Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make align_offset always work on no-provenance pointers #2683

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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