[clang] [clang] constexpr atomic builtins (__c11_atomic_OP and __atomic_OP) (PR #98756)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 06:47:44 PST 2025


Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= <hanicka at hanicka.net>,
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= <hanicka at hanicka.net>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/98756 at github.com>


================
@@ -16268,6 +16353,25 @@ class VoidExprEvaluator
     }
   }
 
+  bool VisitAtomicExpr(const AtomicExpr *E) {
+    if (!EvaluateAtomicOrder(E, Info))
+      return false;
+
+    switch (E->getOp()) {
+    default:
+      return Error(E);
----------------
AaronBallman wrote:

Does this do the correct thing for code like:
```
constexpr int foo(const int *ptr) {
  (void)__atomic_load_n(ptr, __ATOMIC_RELAXED);
  return 12;
}
constexpr int i = 12;
static_assert(foo(&i) == 12);
```
I would expect that to compile and pass the static assertion.

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


More information about the cfe-commits mailing list