From 7df41a77b821946e2f187d938e4bc9ef49e03f79 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 13 Aug 2022 08:22:19 -0400 Subject: [PATCH 1/2] rustup --- rust-version | 2 +- src/lib.rs | 1 + tests/fail/const-ub-checks.rs | 11 +++++++++++ tests/fail/const-ub-checks.stderr | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/fail/const-ub-checks.rs create mode 100644 tests/fail/const-ub-checks.stderr diff --git a/rust-version b/rust-version index 0bcadc0a366..fdd18704d18 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -20ffea6938b5839c390252e07940b99e3b6a889a +75b7e52e92c3b00fc891b47f5b2efdff0a2be55a diff --git a/src/lib.rs b/src/lib.rs index 94958b2ff5f..ba337f28311 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,4 +116,5 @@ "-Zmir-opt-level=0", "--cfg=miri", "-Cdebug-assertions=on", + "-Zextra-const-ub-checks", ]; diff --git a/tests/fail/const-ub-checks.rs b/tests/fail/const-ub-checks.rs new file mode 100644 index 00000000000..fa522c30cbd --- /dev/null +++ b/tests/fail/const-ub-checks.rs @@ -0,0 +1,11 @@ +#![feature(const_ptr_read)] + +const UNALIGNED_READ: () = unsafe { + let x = &[0u8; 4]; + let ptr = x.as_ptr().cast::(); + ptr.read(); //~ERROR: evaluation of constant value failed +}; + +fn main() { + let _x = UNALIGNED_READ; +} diff --git a/tests/fail/const-ub-checks.stderr b/tests/fail/const-ub-checks.stderr new file mode 100644 index 00000000000..a8b7ea242b9 --- /dev/null +++ b/tests/fail/const-ub-checks.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const-ub-checks.rs:LL:CC + | +LL | ptr.read(); + | ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. From d59bad95fdd0157df3bfcbfb878bc7c451d0bee2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 13 Aug 2022 09:03:30 -0400 Subject: [PATCH 2/2] fix data_race test --- tests/pass/concurrency/data_race.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/pass/concurrency/data_race.rs b/tests/pass/concurrency/data_race.rs index 5d1e1bb266c..9c7030db3db 100644 --- a/tests/pass/concurrency/data_race.rs +++ b/tests/pass/concurrency/data_race.rs @@ -1,5 +1,5 @@ //@ignore-target-windows: Concurrency on Windows is not supported yet. -//@compile-flags: -Zmiri-disable-weak-memory-emulation +//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0 use std::sync::atomic::{fence, AtomicUsize, Ordering}; use std::thread::spawn; @@ -10,9 +10,9 @@ unsafe impl Send for EvilSend {} unsafe impl Sync for EvilSend {} -static SYNC: AtomicUsize = AtomicUsize::new(0); - fn test_fence_sync() { + static SYNC: AtomicUsize = AtomicUsize::new(0); + let mut var = 0u32; let ptr = &mut var as *mut u32; let evil_ptr = EvilSend(ptr); @@ -28,7 +28,7 @@ fn test_fence_sync() { fence(Ordering::Acquire); unsafe { *evil_ptr.0 } } else { - 0 + panic!(); // relies on thread 2 going last } }); @@ -56,6 +56,8 @@ fn test_multiple_reads() { } pub fn test_rmw_no_block() { + static SYNC: AtomicUsize = AtomicUsize::new(0); + let mut a = 0u32; let b = &mut a as *mut u32; let c = EvilSend(b); @@ -77,11 +79,13 @@ pub fn test_rmw_no_block() { j1.join().unwrap(); j2.join().unwrap(); let v = j3.join().unwrap(); - assert!(v == 1 || v == 2); + assert!(v == 1 || v == 2); // relies on thread 3 going last } } pub fn test_simple_release() { + static SYNC: AtomicUsize = AtomicUsize::new(0); + let mut a = 0u32; let b = &mut a as *mut u32; let c = EvilSend(b); @@ -95,7 +99,7 @@ pub fn test_simple_release() { let j2 = spawn(move || if SYNC.load(Ordering::Acquire) == 1 { *c.0 } else { 0 }); j1.join().unwrap(); - assert_eq!(j2.join().unwrap(), 1); + assert_eq!(j2.join().unwrap(), 1); // relies on thread 2 going last } }