[clang] [CIR][CIRGen] Add support for `__sync_val/bool_compare_and_swap` builtins (PR #186529)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 17 15:15:40 PDT 2026


================
@@ -172,6 +172,37 @@ static mlir::Value makeBinaryAtomicValue(
   return rmwi->getResult(0);
 }
 
+/// Utility to insert an atomic cmpxchg instruction.
+static mlir::Value makeAtomicCmpXchgValue(CIRGenFunction &cgf,
+                                          const CallExpr *expr,
+                                          bool returnBool) {
+  QualType typ = returnBool ? expr->getArg(1)->getType() : expr->getType();
+  Address destAddr = checkAtomicAlignment(cgf, expr);
+  clang::CIRGen::CIRGenBuilderTy &builder = cgf.getBuilder();
+
+  cir::IntType intType =
+      expr->getArg(0)->getType()->getPointeeType()->isUnsignedIntegerType()
----------------
andykaylor wrote:

I'm curious about this entire line.

First, it's not clear to me why you're using arg 0 to get the signedness. Won't it always point to the same type as arg 1 and arg 2? If so, you could use arg 1 and avoid the need to get the pointee type.

Second, why is it necessary to get an integer type using the width of the input types? Won't this always return the same type as `typ`?

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


More information about the cfe-commits mailing list