[clang] [clang] Implement constexpr support for __builtin_{clzg, ctzg} (PR #86577)

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 14:38:02 PDT 2024


================
@@ -12367,8 +12368,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
                            BuiltinOp != Builtin::BI__lzcnt &&
                            BuiltinOp != Builtin::BI__lzcnt64;
 
-    if (ZeroIsUndefined && !Val)
-      return Error(E);
+    if (!Val) {
----------------
overmighty wrote:

`!Val` checks if the first argument is zero: https://github.com/llvm/llvm-project/blob/59bb4f259d78c7a1916462a1f6d12cf335523db1/llvm/include/llvm/ADT/APInt.h#L587

We always need to evaluate the first argument and check if it's zero, as the second argument is a fallback return value that's only used in that case.

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


More information about the cfe-commits mailing list