[clang] [CIR] Add support for non-compile-time memory order (PR #168892)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 21 15:53:07 PST 2025


================
@@ -844,9 +869,63 @@ RValue CIRGenFunction::emitAtomicExpr(AtomicExpr *e) {
       emitAtomicOp(*this, e, dest, ptr, val1, val2, isWeakExpr, orderFailExpr,
                    size, static_cast<cir::MemOrder>(ord));
   } else {
-    assert(!cir::MissingFeatures::atomicExpr());
-    cgm.errorNYI(e->getSourceRange(), "emitAtomicExpr: dynamic memory order");
-    return RValue::get(nullptr);
+    // The memory order is not known at compile-time.  The atomic operations
+    // can't handle runtime memory orders; the memory order must be hard coded.
+    // Generate a "switch" statement that converts a runtime value into a
+    // compile-time value.
+    cir::SwitchOp::create(
----------------
bcardosolopes wrote:

Please move the logic for this whole section to a new function

https://github.com/llvm/llvm-project/pull/168892


More information about the cfe-commits mailing list