[clang] [clang] Implement constexpr support for __builtin_{clzg, ctzg} (PR #86577)
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 25 16:19:45 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) {
----------------
nickdesaulniers wrote:
In that case:
```c++
case Builtin::BI__builtin_clzg:
case Builtin::BI__builtin_ctzg: {
APSInt Val;
if (!EvaluateInteger(E->getArg(0), Val, Info))
return false;
if (E->getNumArgs() == 1) {
if (!Val)
return Error(E);
if (BuiltinOp == Builtin::BI__builtin_clzg)
return Success(Val.countl_zero(), E);
return Success(Val.countr_zero(), E);
}
if (!EvaluateInteger(E->getArg(1), Val, Info))
return false;
return Success(Val, E);
https://github.com/llvm/llvm-project/pull/86577
More information about the cfe-commits
mailing list