Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jan 30, 2021
1 parent bcb87a7 commit 6b878ed
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0e190206e2ff0c13d64701d9b4145bf89a2d0cab
7ce1b3b24491cbe10669cbe2b5733c2fe7cfe5b7
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Make sure we find these even with many checks disabled.
// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
#![feature(raw_ref_macros)]
use std::ptr;

fn main() {
let p = {
let b = Box::new(42);
&*b as *const i32
};
let x = unsafe { ptr::raw_const!(*p) }; //~ ERROR dereferenced after this allocation got freed
let x = unsafe { ptr::addr_of!(*p) }; //~ ERROR dereferenced after this allocation got freed
panic!("this should never print: {:?}", x);
}
1 change: 0 additions & 1 deletion tests/compile-fail/extern_static.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(raw_ref_op)]
//! Even referencing an unknown `extern static` already triggers an error.

extern "C" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This should fail even without validation or Stacked Borrows.
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
#![feature(raw_ref_macros)]
use std::ptr;

fn main() {
Expand All @@ -9,6 +8,6 @@ fn main() {
let x = &x[0] as *const _ as *const u32;
// This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
// The deref is UB even if we just put the result into a raw pointer.
let _x = unsafe { ptr::raw_const!(*x) }; //~ ERROR memory with alignment 2, but alignment 4 is required
let _x = unsafe { ptr::addr_of!(*x) }; //~ ERROR memory with alignment 2, but alignment 4 is required
}
}
6 changes: 3 additions & 3 deletions tests/run-pass/packed_struct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(unsize, coerce_unsized, raw_ref_op, raw_ref_macros)]
#![feature(unsize, coerce_unsized)]

use std::collections::hash_map::DefaultHasher;
use std::hash::Hash;
Expand Down Expand Up @@ -46,9 +46,9 @@ fn test_basic() {
assert_eq!({x.b}, 99);
// but we *can* take a raw pointer!
assert_eq!(unsafe { (&raw const x.a).read_unaligned() }, 42);
assert_eq!(unsafe { ptr::raw_const!(x.a).read_unaligned() }, 42);
assert_eq!(unsafe { ptr::addr_of!(x.a).read_unaligned() }, 42);
assert_eq!(unsafe { (&raw const x.b).read_unaligned() }, 99);
assert_eq!(unsafe { ptr::raw_const!(x.b).read_unaligned() }, 99);
assert_eq!(unsafe { ptr::addr_of!(x.b).read_unaligned() }, 99);

x.b = 77;
assert_eq!({x.b}, 77);
Expand Down
5 changes: 2 additions & 3 deletions tests/run-pass/stacked-borrows/stacked-borrows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// compile-flags: -Zmiri-track-raw-pointers
#![feature(raw_ref_macros)]
use std::ptr;

// Test various stacked-borrows-related things.
Expand Down Expand Up @@ -169,8 +168,8 @@ fn raw_ref_to_part() {
}

let it = Box::new(Whole { part: Part { _lame: 0 }, extra: 42 });
let whole = ptr::raw_mut!(*Box::leak(it));
let part = unsafe { ptr::raw_mut!((*whole).part) };
let whole = ptr::addr_of_mut!(*Box::leak(it));
let part = unsafe { ptr::addr_of_mut!((*whole).part) };
let typed = unsafe { &mut *(part as *mut Whole) };
assert!(typed.extra == 42);
drop(unsafe { Box::from_raw(whole) });
Expand Down

0 comments on commit 6b878ed

Please sign in to comment.