Merge pull request #646 from rchaser53/issue-58645

use copy_op directly insteadof write_scalar
This commit is contained in:
Ralf Jung 2019-02-26 12:28:14 +01:00 committed by GitHub
commit 433e494d79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -50,22 +50,30 @@ fn call_intrinsic(
"atomic_load" |
"atomic_load_relaxed" |
"atomic_load_acq" |
"volatile_load" => {
"atomic_load_acq" => {
let ptr = this.deref_operand(args[0])?;
let val = this.read_scalar(ptr.into())?; // make sure it fits into a scalar; otherwise it cannot be atomic
this.write_scalar(val, dest)?;
}
"volatile_load" => {
let ptr = this.deref_operand(args[0])?;
this.copy_op(ptr.into(), dest)?;
}
"atomic_store" |
"atomic_store_relaxed" |
"atomic_store_rel" |
"volatile_store" => {
"atomic_store_rel" => {
let ptr = this.deref_operand(args[0])?;
let val = this.read_scalar(args[1])?; // make sure it fits into a scalar; otherwise it cannot be atomic
this.write_scalar(val, ptr.into())?;
}
"volatile_store" => {
let ptr = this.deref_operand(args[0])?;
this.copy_op(args[1], ptr.into())?;
}
"atomic_fence_acq" => {
// we are inherently singlethreaded and singlecored, this is a nop
}

View File

@ -0,0 +1,12 @@
// related: #58645
#![feature(core_intrinsics)]
use std::intrinsics::{volatile_load, volatile_store};
pub fn main() {
unsafe {
let i: &mut (isize, isize) = &mut (0, 0);
volatile_store(i, (1, 2));
assert_eq!(volatile_load(i), (1, 2));
assert_eq!(i, &mut (1, 2));
}
}