[clang] [-Wunsafe-buffer-usage] Improve null-termination analysis on conditionals (PR #176262)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 16 11:58:27 PST 2026
================
@@ -758,7 +758,19 @@ static bool isNullTermPointer(const Expr *Ptr, ASTContext &Ctx) {
// Strip CXXDefaultArgExpr before check:
if (const auto *DefaultArgE = dyn_cast<CXXDefaultArgExpr>(Ptr))
Ptr = DefaultArgE->getExpr();
- Ptr = tryConstantFoldConditionalExpr(Ptr, Ctx);
+ // Try to perform constant fold recursively:
+ if (const auto *NewPtr =
+ tryConstantFoldConditionalExpr(Ptr->IgnoreParenImpCasts(), Ctx);
+ NewPtr != Ptr)
+ return isNullTermPointer(NewPtr, Ctx);
----------------
ziqingluo-90 wrote:
You are right, it's bad! Though it works, because in the second recursion`Ptr->IgnoreParenImpCasts()` will do nothing. But it is bad, I will fix it.
https://github.com/llvm/llvm-project/pull/176262
More information about the cfe-commits
mailing list