[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-14 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak closed 
https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-13 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/94515

>From 22a8fa09e81337f45c2ed94e229f06e9aaa32c0e Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 5 Jun 2024 11:02:31 -0700
Subject: [PATCH 1/2] Check whether EvaluatedStmt::Value is valid in
 VarDecl::hasInit

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.
---
 clang/lib/AST/Decl.cpp | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

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(
-  Eval->Value.isOffset()
-  ? Eval->Value.get(getASTContext().getExternalSource())
-  : Eval->Value.get(nullptr));
+  return cast(Eval->Value.isOffset()
+? Eval->Value.get(getASTContext().getExternalSource())
+: Eval->Value.get(nullptr));
 }
 
 Stmt **VarDecl::getInitAddress() {

>From a54e9ac892aa7bbbcf73256e7ac5eaec187578fe Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Thu, 13 Jun 2024 18:21:38 -0700
Subject: [PATCH 2/2] Move the conditional into the argument

---
 clang/lib/AST/Decl.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index fc04f877b2268..9d0a835a12c45 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2405,9 +2405,8 @@ Expr *VarDecl::getInit() {
 
   auto *Eval = getEvaluatedStmt();
 
-  return cast(Eval->Value.isOffset()
-? Eval->Value.get(getASTContext().getExternalSource())
-: Eval->Value.get(nullptr));
+  return cast(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


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-12 Thread Matheus Izvekov via cfe-commits


@@ -2402,10 +2405,9 @@ Expr *VarDecl::getInit() {
 
   auto *Eval = getEvaluatedStmt();
 
-  return cast_if_present(
-  Eval->Value.isOffset()
-  ? Eval->Value.get(getASTContext().getExternalSource())
-  : Eval->Value.get(nullptr));
+  return cast(Eval->Value.isOffset()
+? Eval->Value.get(getASTContext().getExternalSource())
+: Eval->Value.get(nullptr));

mizvekov wrote:

Small nit: It seems this could move the conditional into the argument for 
`Eval->Value.get`.

https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

This is much better, thanks!

LGTM

https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Akira Hatanaka (ahatanak)


Changes

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/94515.diff


1 Files Affected:

- (modified) clang/lib/AST/Decl.cpp (+6-4) 


``diff
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(
-  Eval->Value.isOffset()
-  ? Eval->Value.get(getASTContext().getExternalSource())
-  : Eval->Value.get(nullptr));
+  return cast(Eval->Value.isOffset()
+? Eval->Value.get(getASTContext().getExternalSource())
+: Eval->Value.get(nullptr));
 }
 
 Stmt **VarDecl::getInitAddress() {

``




https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-05 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak ready_for_review 
https://github.com/llvm/llvm-project/pull/94515
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-05 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/94515

>From 22a8fa09e81337f45c2ed94e229f06e9aaa32c0e Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 5 Jun 2024 11:02:31 -0700
Subject: [PATCH] Check whether EvaluatedStmt::Value is valid in
 VarDecl::hasInit

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.
---
 clang/lib/AST/Decl.cpp | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

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(
-  Eval->Value.isOffset()
-  ? Eval->Value.get(getASTContext().getExternalSource())
-  : Eval->Value.get(nullptr));
+  return cast(Eval->Value.isOffset()
+? Eval->Value.get(getASTContext().getExternalSource())
+: Eval->Value.get(nullptr));
 }
 
 Stmt **VarDecl::getInitAddress() {

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


[clang] Check whether EvaluatedStmt::Value is valid in VarDecl::hasInit (PR #94515)

2024-06-05 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak created 
https://github.com/llvm/llvm-project/pull/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.

>From 91751f09a1ca73f75c892c89ef7c312ad4df2c64 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 5 Jun 2024 11:02:31 -0700
Subject: [PATCH] Check whether EvaluatedStmt::Value is valid in
 VarDecl::hasInit

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.
---
 clang/lib/AST/Decl.cpp | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

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(
-  Eval->Value.isOffset()
-  ? Eval->Value.get(getASTContext().getExternalSource())
-  : Eval->Value.get(nullptr));
+  return cast(Eval->Value.isOffset()
+? Eval->Value.get(getASTContext().getExternalSource())
+: Eval->Value.get(nullptr));
 }
 
 Stmt **VarDecl::getInitAddress() {

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