Skip to content

Commit

Permalink
Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (#94515)
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 #93749.
  • Loading branch information
ahatanak committed Jun 14, 2024
1 parent b6fd6d4 commit 46c8f25
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 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,8 @@ 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.get(
Eval->Value.isOffset() ? getASTContext().getExternalSource() : nullptr));
}

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

0 comments on commit 46c8f25

Please sign in to comment.