[clang] [clang][ExprConst] Assert that EvaluateAsInitializer has non-null VD (PR #159274)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 17 00:46:51 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Both the expression (the initializer) as well as the VarDecl can't be null here. Assert that.
---
Full diff: https://github.com/llvm/llvm-project/pull/159274.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+5-8)
- (modified) clang/lib/AST/ExprConstant.cpp (+1)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/159274
More information about the cfe-commits
mailing list