Skip to content

Commit

Permalink
Merge pull request #503 from RalfJung/atomic-arith
Browse files Browse the repository at this point in the history
Reject atomic arithmetic on non-integer types
  • Loading branch information
RalfJung authored Oct 31, 2018
2 parents 75f667e + 1fe925e commit 2833b54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/compile-fail/atomic_non_integer_arithmetic.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 2833b54

Please sign in to comment.