[PATCH] IRGen: __c11/__atomic compare-and-exchange should respect the standard

Richard Smith richard at metafoo.co.uk
Mon Mar 3 12:36:22 PST 2014



================
Comment at: lib/CodeGen/CGAtomic.cpp:234
@@ +233,3 @@
+    // Update the memory at Expected with Old's value.
+    llvm::StoreInst *StoreExpected = CGF.Builder.CreateStore(Old, Val1);
+    StoreExpected->setAlignment(Align);
----------------
This is still not correct, as far as I can see.

According to the C++ standard, the value at `Val1` is replaced as part of the atomic operation of `atomic_compare_exchange_{weak|strong}{_explicit}`, and that update has the memory order given by the second memory order argument to the function.

The first half of this requirement seems highly problematic, and is probably a bug in the standard. The second half of this requirement seems to require that `Val1` is updated by an atomic store, using the 'failure' ordering for the atomic compare exchange operation.


http://llvm-reviews.chandlerc.com/D2922



More information about the cfe-commits mailing list