-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit #94515
Conversation
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.
@llvm/pr-subscribers-clang Author: Akira Hatanaka (ahatanak) ChangesVarDecl::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. Full diff: https://github.com/llvm/llvm-project/pull/94515.diff 1 Files Affected:
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 1f19dadafa44e..fc04f877b2268 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -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();
}
@@ -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() {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much better, thanks!
LGTM
clang/lib/AST/Decl.cpp
Outdated
return cast<Expr>(Eval->Value.isOffset() | ||
? Eval->Value.get(getASTContext().getExternalSource()) | ||
: Eval->Value.get(nullptr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: It seems this could move the conditional into the argument for Eval->Value.get
.
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.