Merge pull request #503 from RalfJung/atomic-arith

Reject atomic arithmetic on non-integer types
This commit is contained in:
Ralf Jung 2018-10-31 13:02:37 +01:00 committed by GitHub
commit 2833b54100
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -126,6 +126,9 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
"atomic_xsub_acqrel" |
"atomic_xsub_relaxed" => {
let ptr = self.ref_to_mplace(self.read_value(args[0])?)?;
if !ptr.layout.ty.is_integral() {
return err!(Unimplemented(format!("Atomic arithmetic operations only work on integer types")));
}
let rhs = self.read_value(args[1])?;
let old = self.read_value(ptr.into())?;
self.write_value(*old, dest)?; // old value is returned

View file

@ -0,0 +1,9 @@
#![feature(core_intrinsics)]
pub fn main() {
let mut z: f64 = 1.0;
unsafe {
::std::intrinsics::atomic_xadd(&mut z, 2.0);
//~^ ERROR: Atomic arithmetic operations only work on integer types
}
}