[clang] [clang] atomic fetch op misbehaves on atomic bool (PR #186940)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 5 07:22:49 PDT 2026


================
@@ -4880,6 +4884,14 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
   // For an arithmetic operation, the implied arithmetic must be well-formed.
   // For _n operations, the value type must also be a valid atomic type.
   if (Form == Arithmetic || IsN) {
+    // C23 ยง7.17.7.5p1: atomic arithmetic operations are not permitted on
+    // atomic_bool (_Bool). GCC similarly rejects this. Only applies to
+    // arithmetic forms; non-arithmetic _n ops (load, store, exchange) are fine.
+    if (Form == Arithmetic && ValType->isBooleanType()) {
----------------
AaronBallman wrote:

Also applicable are atomic enums with an underlying type of bool:
```
enum E : bool {
  False,
  True
};

_Atomic enum E e = False;
atomic_fetch_add(&e, 1); // Should also be diagnosed
```

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


More information about the cfe-commits mailing list