Skip to content

Commit 50ef22a

Browse files
committed
Auto merge of #2484 - RalfJung:rustup, r=RalfJung
rustup; enable extra const UB checks
2 parents 4e1bc7e + d59bad9 commit 50ef22a

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20ffea6938b5839c390252e07940b99e3b6a889a
1+
75b7e52e92c3b00fc891b47f5b2efdff0a2be55a

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,5 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
116116
"-Zmir-opt-level=0",
117117
"--cfg=miri",
118118
"-Cdebug-assertions=on",
119+
"-Zextra-const-ub-checks",
119120
];

tests/fail/const-ub-checks.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_ptr_read)]
2+
3+
const UNALIGNED_READ: () = unsafe {
4+
let x = &[0u8; 4];
5+
let ptr = x.as_ptr().cast::<u32>();
6+
ptr.read(); //~ERROR: evaluation of constant value failed
7+
};
8+
9+
fn main() {
10+
let _x = UNALIGNED_READ;
11+
}

tests/fail/const-ub-checks.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/const-ub-checks.rs:LL:CC
3+
|
4+
LL | ptr.read();
5+
| ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0080`.

tests/pass/concurrency/data_race.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ignore-target-windows: Concurrency on Windows is not supported yet.
2-
//@compile-flags: -Zmiri-disable-weak-memory-emulation
2+
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
33

44
use std::sync::atomic::{fence, AtomicUsize, Ordering};
55
use std::thread::spawn;
@@ -10,9 +10,9 @@ struct EvilSend<T>(pub T);
1010
unsafe impl<T> Send for EvilSend<T> {}
1111
unsafe impl<T> Sync for EvilSend<T> {}
1212

13-
static SYNC: AtomicUsize = AtomicUsize::new(0);
14-
1513
fn test_fence_sync() {
14+
static SYNC: AtomicUsize = AtomicUsize::new(0);
15+
1616
let mut var = 0u32;
1717
let ptr = &mut var as *mut u32;
1818
let evil_ptr = EvilSend(ptr);
@@ -28,7 +28,7 @@ fn test_fence_sync() {
2828
fence(Ordering::Acquire);
2929
unsafe { *evil_ptr.0 }
3030
} else {
31-
0
31+
panic!(); // relies on thread 2 going last
3232
}
3333
});
3434

@@ -56,6 +56,8 @@ fn test_multiple_reads() {
5656
}
5757

5858
pub fn test_rmw_no_block() {
59+
static SYNC: AtomicUsize = AtomicUsize::new(0);
60+
5961
let mut a = 0u32;
6062
let b = &mut a as *mut u32;
6163
let c = EvilSend(b);
@@ -77,11 +79,13 @@ pub fn test_rmw_no_block() {
7779
j1.join().unwrap();
7880
j2.join().unwrap();
7981
let v = j3.join().unwrap();
80-
assert!(v == 1 || v == 2);
82+
assert!(v == 1 || v == 2); // relies on thread 3 going last
8183
}
8284
}
8385

8486
pub fn test_simple_release() {
87+
static SYNC: AtomicUsize = AtomicUsize::new(0);
88+
8589
let mut a = 0u32;
8690
let b = &mut a as *mut u32;
8791
let c = EvilSend(b);
@@ -95,7 +99,7 @@ pub fn test_simple_release() {
9599
let j2 = spawn(move || if SYNC.load(Ordering::Acquire) == 1 { *c.0 } else { 0 });
96100

97101
j1.join().unwrap();
98-
assert_eq!(j2.join().unwrap(), 1);
102+
assert_eq!(j2.join().unwrap(), 1); // relies on thread 2 going last
99103
}
100104
}
101105

0 commit comments

Comments
 (0)