[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:45 PST 2025
Hana =?utf-8?q?Dusíková?= <hanicka at hanicka.net>,
Hana =?utf-8?q?Dusíková?= <hanicka at hanicka.net>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/98756 at github.com>
================
@@ -17893,4 +18005,425 @@ std::optional<bool> EvaluateBuiltinIsWithinLifetime(IntExprEvaluator &IEE,
IsWithinLifetimeHandler handler{Info};
return findSubobject(Info, E, CO, Val.getLValueDesignator(), handler);
}
+
} // namespace
+
+static bool EvaluateAtomicOrder(const AtomicExpr *E, EvalInfo &Info) {
+ // We need to evaluate Order argument(s), but we ignore it as constant
+ // evaluation is single threaded.
----------------
AaronBallman wrote:
Is this actually correct though? My reading of https://eel.is/c++draft/atomics keeps hitting preconditions that say "order is memory_order::relaxed, memory_order::consume, memory_order::ac-
quire, or memory_order::seq_cst", which means we should reject code like this, shouldn't we?
```
#include <atomic>
constexpr int foo(std::atomic<int> i) {
return i.load(static_cast<std::memory_order>(1001));
}
```
and while we don't have to catch UB in the library functions, it seems more user-friendly to do so.
https://github.com/llvm/llvm-project/pull/98756
More information about the cfe-commits
mailing list