Skip to content

Commit 433e494

Browse files
authored
Merge pull request #646 from rchaser53/issue-58645
use copy_op directly insteadof write_scalar
2 parents 5566aec + b1c0cf2 commit 433e494

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/intrinsic.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,30 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
5050

5151
"atomic_load" |
5252
"atomic_load_relaxed" |
53-
"atomic_load_acq" |
54-
"volatile_load" => {
53+
"atomic_load_acq" => {
5554
let ptr = this.deref_operand(args[0])?;
5655
let val = this.read_scalar(ptr.into())?; // make sure it fits into a scalar; otherwise it cannot be atomic
5756
this.write_scalar(val, dest)?;
5857
}
5958

59+
"volatile_load" => {
60+
let ptr = this.deref_operand(args[0])?;
61+
this.copy_op(ptr.into(), dest)?;
62+
}
63+
6064
"atomic_store" |
6165
"atomic_store_relaxed" |
62-
"atomic_store_rel" |
63-
"volatile_store" => {
66+
"atomic_store_rel" => {
6467
let ptr = this.deref_operand(args[0])?;
6568
let val = this.read_scalar(args[1])?; // make sure it fits into a scalar; otherwise it cannot be atomic
6669
this.write_scalar(val, ptr.into())?;
6770
}
6871

72+
"volatile_store" => {
73+
let ptr = this.deref_operand(args[0])?;
74+
this.copy_op(args[1], ptr.into())?;
75+
}
76+
6977
"atomic_fence_acq" => {
7078
// we are inherently singlethreaded and singlecored, this is a nop
7179
}

tests/run-pass/volatile.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// related: #58645
2+
#![feature(core_intrinsics)]
3+
use std::intrinsics::{volatile_load, volatile_store};
4+
5+
pub fn main() {
6+
unsafe {
7+
let i: &mut (isize, isize) = &mut (0, 0);
8+
volatile_store(i, (1, 2));
9+
assert_eq!(volatile_load(i), (1, 2));
10+
assert_eq!(i, &mut (1, 2));
11+
}
12+
}

0 commit comments

Comments
 (0)