Skip to content

Conversation

@tbaederr
Copy link
Contributor

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

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Sep 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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 --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; 
@tbaederr
Copy link
Contributor Author

CI failure is a timed-out LLDB test.

Both the expression (the initializer) as well as the VarDecl can't be null here. Assert that.
@tbaederr tbaederr merged commit 6a16f1a into llvm:main Sep 17, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

3 participants