Author: Akira Hatanaka
Date: 2024-06-14T11:22:09-07:00
New Revision: 46c8f25b0a7d664d4ef3b8d6376815a877788463

URL: 
https://github.com/llvm/llvm-project/commit/46c8f25b0a7d664d4ef3b8d6376815a877788463
DIFF: 
https://github.com/llvm/llvm-project/commit/46c8f25b0a7d664d4ef3b8d6376815a877788463.diff

LOG: Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (#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 e1c3e16d24b5cc097ff08e9283f53319acd3f245 as the change isn't
needed anymore with this change.

See the discussion in https://github.com/llvm/llvm-project/pull/93749.

Added: 
    

Modified: 
    clang/lib/AST/Decl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 1f19dadafa44e..9d0a835a12c45 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,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() {


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to