Skip to content

Commit 46c8f25

Browse files
authored
Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (llvm#94515)
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.
1 parent b6fd6d4 commit 46c8f25

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,9 @@ bool VarDecl::hasInit() const {
23902390
if (P->hasUnparsedDefaultArg() || P->hasUninstantiatedDefaultArg())
23912391
return false;
23922392

2393+
if (auto *Eval = getEvaluatedStmt())
2394+
return Eval->Value.isValid();
2395+
23932396
return !Init.isNull();
23942397
}
23952398

@@ -2402,10 +2405,8 @@ Expr *VarDecl::getInit() {
24022405

24032406
auto *Eval = getEvaluatedStmt();
24042407

2405-
return cast_if_present<Expr>(
2406-
Eval->Value.isOffset()
2407-
? Eval->Value.get(getASTContext().getExternalSource())
2408-
: Eval->Value.get(nullptr));
2408+
return cast<Expr>(Eval->Value.get(
2409+
Eval->Value.isOffset() ? getASTContext().getExternalSource() : nullptr));
24092410
}
24102411

24112412
Stmt **VarDecl::getInitAddress() {

0 commit comments

Comments
 (0)