]> git.lizzy.rs Git - rust.git/commitdiff
get rid of some uses of core_intrinsics
authorRalf Jung <post@ralfj.de>
Sun, 24 Jul 2022 12:48:58 +0000 (08:48 -0400)
committerRalf Jung <post@ralfj.de>
Sun, 24 Jul 2022 13:26:11 +0000 (09:26 -0400)
tests/fail/data_race/atomic_read_na_write_race1.rs
tests/fail/data_race/atomic_read_na_write_race1.stderr
tests/fail/data_race/atomic_write_na_read_race2.rs
tests/fail/data_race/atomic_write_na_read_race2.stderr
tests/fail/data_race/atomic_write_na_write_race1.rs
tests/fail/data_race/atomic_write_na_write_race1.stderr
tests/fail/weak_memory/racing_mixed_size_read.rs
tests/fail/weak_memory/racing_mixed_size_read.stderr
tests/pass/weak_memory/extra_cpp.rs
tests/pass/weak_memory/extra_cpp_unsafe.rs

index 1ef021edc8cc723ec4a745fa23ed806fc44a76be..30900a85d003f53d3e35404da071613b5383bfd1 100644 (file)
@@ -1,10 +1,8 @@
 // We want to control preemption here.
 //@compile-flags: -Zmiri-preemption-rate=0
 //@ignore-target-windows: Concurrency on Windows is not supported yet.
-#![feature(core_intrinsics)]
 
-use std::intrinsics;
-use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::{AtomicUsize, Ordering};
 use std::thread::spawn;
 
 #[derive(Copy, Clone)]
@@ -23,8 +21,7 @@ pub fn main() {
         });
 
         let j2 = spawn(move || {
-            //Equivalent to: (&*c.0).load(Ordering::SeqCst)
-            intrinsics::atomic_load_seqcst(c.0 as *mut usize) //~ ERROR: Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>`
+            (&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>`
         });
 
         j1.join().unwrap();
index 2a0ca9260782c79f4a64b03e9bcb1266ed040ca5..e7a219e1235269a6dc170b8c267c47a364becb1b 100644 (file)
@@ -1,8 +1,8 @@
 error: Undefined Behavior: Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>` at ALLOC
   --> $DIR/atomic_read_na_write_race1.rs:LL:CC
    |
-LL |             intrinsics::atomic_load_seqcst(c.0 as *mut usize)
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>` at ALLOC
+LL |             (&*c.0).load(Ordering::SeqCst)
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>` at ALLOC
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
index 77b2945f7371544d59e705e63496f94923089758..1a79dde0b08ac3a54efa26a33d441069aaed01e2 100644 (file)
@@ -1,10 +1,8 @@
 // We want to control preemption here.
 //@compile-flags: -Zmiri-preemption-rate=0
 //@ignore-target-windows: Concurrency on Windows is not supported yet.
-#![feature(core_intrinsics)]
 
-use std::intrinsics::atomic_store;
-use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::{AtomicUsize, Ordering};
 use std::thread::spawn;
 
 #[derive(Copy, Clone)]
@@ -23,8 +21,7 @@ pub fn main() {
         });
 
         let j2 = spawn(move || {
-            //Equivalent to: (&*c.0).store(32, Ordering::SeqCst)
-            atomic_store(c.0 as *mut usize, 32); //~ ERROR: Data race detected between Atomic Store on thread `<unnamed>` and Read on thread `<unnamed>`
+            (&*c.0).store(32, Ordering::SeqCst); //~ ERROR: Data race detected between Atomic Store on thread `<unnamed>` and Read on thread `<unnamed>`
         });
 
         j1.join().unwrap();
index 69bf6c5f37425caf1fd4c2d15d2131f54dca7f73..e9c6005f27e6bd3178553464257cd0e588bc14cc 100644 (file)
@@ -1,7 +1,7 @@
 error: Undefined Behavior: Data race detected between Atomic Store on thread `<unnamed>` and Read on thread `<unnamed>` at ALLOC
   --> $DIR/atomic_write_na_read_race2.rs:LL:CC
    |
-LL |             atomic_store(c.0 as *mut usize, 32);
+LL |             (&*c.0).store(32, Ordering::SeqCst);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Store on thread `<unnamed>` and Read on thread `<unnamed>` at ALLOC
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
index 34922dd595ed638c347b9c585f0d33a5b87d21a6..04015c2d14205c6715aae577ea49a5faa52e8058 100644 (file)
@@ -1,10 +1,8 @@
 // We want to control preemption here.
 //@compile-flags: -Zmiri-preemption-rate=0
 //@ignore-target-windows: Concurrency on Windows is not supported yet.
-#![feature(core_intrinsics)]
 
-use std::intrinsics::atomic_store;
-use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::{AtomicUsize, Ordering};
 use std::thread::spawn;
 
 #[derive(Copy, Clone)]
@@ -23,8 +21,7 @@ pub fn main() {
         });
 
         let j2 = spawn(move || {
-            //Equivalent to: (&*c.0).store(64, Ordering::SeqCst)
-            atomic_store(c.0 as *mut usize, 64); //~ ERROR: Data race detected between Atomic Store on thread `<unnamed>` and Write on thread `<unnamed>`
+            (&*c.0).store(64, Ordering::SeqCst); //~ ERROR: Data race detected between Atomic Store on thread `<unnamed>` and Write on thread `<unnamed>`
         });
 
         j1.join().unwrap();
index 6abcf4fe3d12b77df9cb7a1284ce1ae9a4482809..5ecc4ca04026320337e88348b1c71e91edfce256 100644 (file)
@@ -1,7 +1,7 @@
 error: Undefined Behavior: Data race detected between Atomic Store on thread `<unnamed>` and Write on thread `<unnamed>` at ALLOC
   --> $DIR/atomic_write_na_write_race1.rs:LL:CC
    |
-LL |             atomic_store(c.0 as *mut usize, 64);
+LL |             (&*c.0).store(64, Ordering::SeqCst);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Store on thread `<unnamed>` and Write on thread `<unnamed>` at ALLOC
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
index aeaa6b68f6c8c46c4090bfc41b10d757720f6440..1c0b1c2be8fdaaac7c1df61db8cd478cdc12accf 100644 (file)
@@ -2,10 +2,8 @@
 //@compile-flags: -Zmiri-preemption-rate=0
 //@ignore-target-windows: Concurrency on Windows is not supported yet.
 
-#![feature(core_intrinsics)]
-
-use std::sync::atomic::AtomicU32;
 use std::sync::atomic::Ordering::*;
+use std::sync::atomic::{AtomicU16, AtomicU32};
 use std::thread::spawn;
 
 fn static_atomic(val: u32) -> &'static AtomicU32 {
@@ -31,8 +29,8 @@ pub fn main() {
         let x_ptr = x as *const AtomicU32 as *const u32;
         let x_split = split_u32_ptr(x_ptr);
         unsafe {
-            let hi = &(*x_split)[0] as *const u16;
-            std::intrinsics::atomic_load_relaxed(hi); //~ ERROR: imperfectly overlapping
+            let hi = x_split as *const u16 as *const AtomicU16;
+            (*hi).load(Relaxed); //~ ERROR: imperfectly overlapping
         }
     });
 
index 9988f4a86d426172363436e1f47e5b7c0dde4735..8dbf9e6948bd7975a7a0ca4a153e3b7a305abe9d 100644 (file)
@@ -1,8 +1,8 @@
 error: unsupported operation: racy imperfectly overlapping atomic access is not possible in the C++20 memory model, and not supported by Miri's weak memory emulation
   --> $DIR/racing_mixed_size_read.rs:LL:CC
    |
-LL |             std::intrinsics::atomic_load_relaxed(hi);
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ racy imperfectly overlapping atomic access is not possible in the C++20 memory model, and not supported by Miri's weak memory emulation
+LL |             (*hi).load(Relaxed);
+   |             ^^^^^^^^^^^^^^^^^^^ racy imperfectly overlapping atomic access is not possible in the C++20 memory model, and not supported by Miri's weak memory emulation
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
    = note: backtrace:
index 52c13cbdced37a4b977aa561f98513a22cd38353..d98fba26ffa80df251a754bab2a2da99241b26bf 100644 (file)
@@ -5,7 +5,6 @@
 // but doable in safe (at least sound) Rust.
 
 #![feature(atomic_from_mut)]
-#![feature(core_intrinsics)]
 
 use std::sync::atomic::Ordering::*;
 use std::sync::atomic::{AtomicU16, AtomicU32};
index 1c6c370ced3b1a309a3b730b39fe888b2ee686ab..f5c6021a4a85b5b5668e2b3f950333c177320b86 100644 (file)
@@ -7,7 +7,6 @@
 // memory model in the future.
 
 #![feature(atomic_from_mut)]
-#![feature(core_intrinsics)]
 
 use std::sync::atomic::AtomicU32;
 use std::sync::atomic::Ordering::*;
@@ -27,7 +26,7 @@ fn racing_mixed_atomicity_read() {
 
     let j2 = spawn(move || {
         let x_ptr = x as *const AtomicU32 as *const u32;
-        unsafe { std::intrinsics::atomic_load_relaxed(x_ptr) }
+        unsafe { x_ptr.read() }
     });
 
     let r1 = j1.join().unwrap();