Skip to content

Commit

Permalink
Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit
Browse files Browse the repository at this point in the history
VarDecl::isNull() doesn't tell whether the VarDecl has an initializer as
methods like ensureEvaluatedStmt can create an EvaluatedStmt even when
there isn't an initializer.

Revert e1c3e16 as the change isn't
needed anymore with this change.

See the discussion in llvm#93749.
  • Loading branch information
ahatanak committed Jun 5, 2024
1 parent 461dcd4 commit 22a8fa0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,9 @@ bool VarDecl::hasInit() const {
if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg())
return false;

if (auto *Eval = getEvaluatedStmt())
return Eval->Value.isValid();

return !Init.isNull();
}

Expand All @@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() {

auto *Eval = getEvaluatedStmt();

return cast_if_present<Expr>(
Eval->Value.isOffset()
? Eval->Value.get(getASTContext().getExternalSource())
: Eval->Value.get(nullptr));
return cast<Expr>(Eval->Value.isOffset()
? Eval->Value.get(getASTContext().getExternalSource())
: Eval->Value.get(nullptr));
}

Stmt **VarDecl::getInitAddress() {
Expand Down

0 comments on commit 22a8fa0

Please sign in to comment.