https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/159274
>From 36b5fee1993d350a22b63171a363654df4c76b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 17 Sep 2025 09:44:14 +0200 Subject: [PATCH] [clang][ExprConst] Assert that EvaluateAsInitializer has non-null VD Both the expression (the initializer) as well as the VarDecl can't be null here. Assert that. --- clang/lib/AST/ByteCode/EvalEmitter.cpp | 13 +++++-------- clang/lib/AST/ExprConstant.cpp | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) 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