https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/152593

>From d7c1848b87a9f33d29acd3c526ea19b7ddaa7be7 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghm...@intel.com>
Date: Thu, 7 Aug 2025 13:31:03 -0700
Subject: [PATCH 1/2] [Clang][AST][NFC] Add assertion on Init to
 CompoundLiteralExpr

Static analysis complained that:

  child_range(&Init, &Init+1);

in the children member function was potentially out of bounds. This is false b/c
it is forming an iterator range but it would be invalid if Init was a nullptr.

I add an assertion in the constructor for this and remove to FIXME checks that
are related to this. I checked the various usages and we always valid the
argument is not nullptr.
---
 clang/include/clang/AST/Expr.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 237b3b2cf7444..a5116a72264b9 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3548,6 +3548,7 @@ class CompoundLiteralExpr : public Expr {
                       QualType T, ExprValueKind VK, Expr *init, bool fileScope)
       : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary),
         LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {
+    assert(Init && "Init is a nullptr");
     setDependence(computeDependence(this));
   }
 
@@ -3577,17 +3578,11 @@ class CompoundLiteralExpr : public Expr {
   APValue &getStaticValue() const;
 
   SourceLocation getBeginLoc() const LLVM_READONLY {
-    // FIXME: Init should never be null.
-    if (!Init)
-      return SourceLocation();
     if (LParenLoc.isInvalid())
       return Init->getBeginLoc();
     return LParenLoc;
   }
   SourceLocation getEndLoc() const LLVM_READONLY {
-    // FIXME: Init should never be null.
-    if (!Init)
-      return SourceLocation();
     return Init->getEndLoc();
   }
 

>From cf07239bdca7e93a83cf12d100ed0f378ecfb1aa Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghm...@intel.com>
Date: Thu, 7 Aug 2025 16:15:45 -0700
Subject: [PATCH 2/2] Address clang-format issue.

---
 clang/include/clang/AST/Expr.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a5116a72264b9..5653b2549ac3c 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3582,9 +3582,7 @@ class CompoundLiteralExpr : public Expr {
       return Init->getBeginLoc();
     return LParenLoc;
   }
-  SourceLocation getEndLoc() const LLVM_READONLY {
-    return Init->getEndLoc();
-  }
+  SourceLocation getEndLoc() const LLVM_READONLY { return Init->getEndLoc(); }
 
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CompoundLiteralExprClass;

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to