mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
make align_offset always work on no-provenance pointers
This commit is contained in:
parent
0a9e5e8e81
commit
c8c82a0bca
@ -89,6 +89,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ptr = this.read_pointer(ptr_op)?;
|
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) {
|
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.
|
// Only do anything if we can identify the allocation this goes to.
|
||||||
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);
|
let (_size, cur_align, _kind) = this.get_alloc_info(alloc_id);
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
//@compile-flags: -Zmiri-symbolic-alignment-check
|
//@compile-flags: -Zmiri-symbolic-alignment-check
|
||||||
|
#![feature(strict_provenance)]
|
||||||
|
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
fn test_align_offset() {
|
fn test_align_offset() {
|
||||||
let d = Box::new([0u32; 4]);
|
let d = Box::new([0u32; 4]);
|
||||||
@ -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(2), 0);
|
||||||
assert_eq!(raw.wrapping_offset(2).align_offset(4), 2);
|
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
|
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() {
|
fn test_align_to() {
|
||||||
|
Loading…
Reference in New Issue
Block a user