Skip to content

rustup #1697

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

Merged
merged 1 commit into from
Jan 31, 2021
Merged

rustup #1697

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
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0e190206e2ff0c13d64701d9b4145bf89a2d0cab
9b3242982202707be2485b1e4cf5f3b34466a38d
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);
}
3 changes: 1 addition & 2 deletions tests/compile-fail/extern_static.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![feature(raw_ref_op)]
//! Even referencing an unknown `extern static` already triggers an error.

extern "C" {
static mut FOO: i32;
}

fn main() {
let _val = unsafe { &raw const FOO }; //~ ERROR is not supported by Miri
let _val = unsafe { std::ptr::addr_of!(FOO) }; //~ ERROR is not supported by Miri
}
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
}
}
1 change: 1 addition & 0 deletions tests/run-pass/issue-73223.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn main() {
assert_eq!(state.rest(path), "some/more");
}

#[allow(unused)]
struct State {
prev: Option<usize>,
next: Option<usize>,
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/many_shr_bor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Make sure validation can handle many overlapping shared borrows for different parts of a data structure
use std::cell::RefCell;

#[allow(unused)]
struct Test {
a: u32,
b: u32,
Expand Down
8 changes: 3 additions & 5 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 @@ -45,10 +45,8 @@ fn test_basic() {
assert_eq!({x.a}, 42);
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 { (&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.a).read_unaligned() }, 42);
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