[clang] [CIR] Add support for dynamic atomic sync scope (PR #189699)

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 09:01:31 PDT 2026


================
@@ -754,8 +765,50 @@ static void emitAtomicOp(CIRGenFunction &cgf, AtomicExpr *expr, Address dest,
     return;
   }
 
-  assert(!cir::MissingFeatures::atomicSyncScopeID());
-  cgf.cgm.errorNYI(expr->getSourceRange(), "emitAtomicOp: dynamic sync scope");
+  // The sync scope is not a compile-time constant. Emit a switch statement to
+  // handle each possible value of the sync scope.
+  CIRGenBuilderTy &builder = cgf.getBuilder();
+  mlir::Location loc = cgf.getLoc(expr->getSourceRange());
+  llvm::ArrayRef<unsigned> allScopes = scopeModel->getRuntimeValues();
+  unsigned fallback = scopeModel->getFallBackValue();
+
+  cir::SwitchOp::create(
+      builder, loc, scopeValue,
+      [&](mlir::OpBuilder &, mlir::Location loc, mlir::OperationState &) {
+        mlir::Block *switchBlock = builder.getBlock();
+
+        // Default case -- use fallback scope
+        cir::SyncScopeKind fallbackScope = convertSyncScopeToCIR(
+            cgf, expr->getScope()->getSourceRange(), scopeModel->map(fallback));
+        emitMemOrderDefaultCaseLabel(builder, loc);
----------------
Lancern wrote:

I just happen to catch this which I missed when reviewing claude's changes before committing. We should rename this function to a more general name like `emitDefaultCaseLabel`.

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


More information about the cfe-commits mailing list