Author: Timm Baeder
Date: 2025-09-17T13:23:02+02:00
New Revision: 6a16f1a6f4aca8957c9c1f672f2572c662ddf562

URL: 
https://github.com/llvm/llvm-project/commit/6a16f1a6f4aca8957c9c1f672f2572c662ddf562
DIFF: 
https://github.com/llvm/llvm-project/commit/6a16f1a6f4aca8957c9c1f672f2572c662ddf562.diff

LOG: [clang][ExprConst] Assert that EvaluateAsInitializer has non-null VD 
(#159274)

Both the expression (the initializer) as well as the VarDecl can't be
null here. Assert that.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/EvalEmitter.cpp
    clang/lib/AST/ExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 1d73f0e247aa2..c7287999dd9c0 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -51,19 +51,16 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
 
 EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD, const Expr 
*Init,
                                             bool CheckFullyInitialized) {
+  assert(VD);
+  assert(Init);
   this->CheckFullyInitialized = CheckFullyInitialized;
   S.EvaluatingDecl = VD;
   S.setEvalLocation(VD->getLocation());
   EvalResult.setSource(VD);
 
-  // FIXME: I think Init is never null.
-  if (Init) {
-    QualType T = VD->getType();
-    this->ConvertResultToRValue = !Init->isGLValue() && !T->isPointerType() &&
-                                  !T->isObjCObjectPointerType();
-  } else
-    this->ConvertResultToRValue = false;
-
+  QualType T = VD->getType();
+  this->ConvertResultToRValue = !Init->isGLValue() && !T->isPointerType() &&
+                                !T->isObjCObjectPointerType();
   EvalResult.setSource(VD);
 
   if (!this->visitDeclAndReturn(VD, Init, S.inConstantContext()))

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 12e4e25bd29c4..d0c0c7f3ed120 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -17761,6 +17761,7 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
                                  bool IsConstantInitialization) const {
   assert(!isValueDependent() &&
          "Expression evaluator can't be called on a dependent expression.");
+  assert(VD && "Need a valid VarDecl");
 
   llvm::TimeTraceScope TimeScope("EvaluateAsInitializer", [&] {
     std::string Name;


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

Reply via email to