Skip to content

Commit 6a16f1a

Browse files
authored
[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.
1 parent 5cbaf55 commit 6a16f1a

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,16 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
5151

5252
EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD, const Expr *Init,
5353
bool CheckFullyInitialized) {
54+
assert(VD);
55+
assert(Init);
5456
this->CheckFullyInitialized = CheckFullyInitialized;
5557
S.EvaluatingDecl = VD;
5658
S.setEvalLocation(VD->getLocation());
5759
EvalResult.setSource(VD);
5860

59-
// FIXME: I think Init is never null.
60-
if (Init) {
61-
QualType T = VD->getType();
62-
this->ConvertResultToRValue = !Init->isGLValue() && !T->isPointerType() &&
63-
!T->isObjCObjectPointerType();
64-
} else
65-
this->ConvertResultToRValue = false;
66-
61+
QualType T = VD->getType();
62+
this->ConvertResultToRValue = !Init->isGLValue() && !T->isPointerType() &&
63+
!T->isObjCObjectPointerType();
6764
EvalResult.setSource(VD);
6865

6966
if (!this->visitDeclAndReturn(VD, Init, S.inConstantContext()))

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17761,6 +17761,7 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
1776117761
bool IsConstantInitialization) const {
1776217762
assert(!isValueDependent() &&
1776317763
"Expression evaluator can't be called on a dependent expression.");
17764+
assert(VD && "Need a valid VarDecl");
1776417765

1776517766
llvm::TimeTraceScope TimeScope("EvaluateAsInitializer", [&] {
1776617767
std::string Name;

0 commit comments

Comments
 (0)