[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-27 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/67514

>From e2e0e10e13748ba9369b73c7547c035ee75dfffa Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Tue, 26 Sep 2023 18:55:44 -0700
Subject: [PATCH] [Clang] Fix crash when visting a fold expression in a default
 argument

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr
the children can be NULL and this causes a crash.

Fixes: https://github.com/llvm/llvm-project/issues/67395
---
 clang/docs/ReleaseNotes.rst| 4 
 clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
 clang/test/SemaTemplate/cxx1z-fold-expressions.cpp | 8 
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8a136aae5489a8c..3a65e40b7274f5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,10 @@ Bug Fixes to C++ Support
   reference. Fixes:
   (`#64162 `_)
 
+- Fix crash when fold expression was used in the initialization of default
+  argument. Fixes:
+  (`#67395 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0091e0ecf6f3986..302e944d5d74f1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,7 +86,8 @@ class CheckDefaultArgumentVisitor
 bool CheckDefaultArgumentVisitor::VisitExpr(const Expr *Node) {
   bool IsInvalid = false;
   for (const Stmt *SubStmt : Node->children())
-IsInvalid |= Visit(SubStmt);
+if (SubStmt)
+  IsInvalid |= Visit(SubStmt);
   return IsInvalid;
 }
 
diff --git a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp 
b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
index 518eaf0e05239e0..47a252eb335f6e5 100644
--- a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -124,3 +124,11 @@ namespace PR30738 {
   int test_h3 = h(1, 2, 3);
   N::S test_h4 = h(N::S(), N::S(), N::S()); // expected-note 
{{instantiation of}}
 }
+
+namespace GH67395 {
+template 
+bool f();
+
+template 
+void g(bool = (f() || ...));
+}

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


[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-27 Thread via cfe-commits

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

Can you add a release note mentioning the issue? Otherwise, LGTM

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


[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will 
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr the 
children can be NULL and this causes a crash.

Fixes: https://github.com/llvm/llvm-project/issues/67395

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-1) 
- (modified) clang/test/SemaTemplate/cxx1z-fold-expressions.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0091e0ecf6f3986..302e944d5d74f1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,7 +86,8 @@ class CheckDefaultArgumentVisitor
 bool CheckDefaultArgumentVisitor::VisitExpr(const Expr *Node) {
   bool IsInvalid = false;
   for (const Stmt *SubStmt : Node->children())
-IsInvalid |= Visit(SubStmt);
+if (SubStmt)
+  IsInvalid |= Visit(SubStmt);
   return IsInvalid;
 }
 
diff --git a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp 
b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
index 518eaf0e05239e0..47a252eb335f6e5 100644
--- a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -124,3 +124,11 @@ namespace PR30738 {
   int test_h3 = h(1, 2, 3);
   N::S test_h4 = h(N::S(), N::S(), N::S()); // expected-note 
{{instantiation of}}
 }
+
+namespace GH67395 {
+template 
+bool f();
+
+template 
+void g(bool = (f() || ...));
+}

``




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


[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)

2023-09-26 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik created 
https://github.com/llvm/llvm-project/pull/67514

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will 
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr the 
children can be NULL and this causes a crash.

Fixes: https://github.com/llvm/llvm-project/issues/67395

>From 2c8147f4f781ad8eaef188b294ce3588069f1c01 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Tue, 26 Sep 2023 18:55:44 -0700
Subject: [PATCH] [Clang] Fix crash when visting a fold expression in a default
 argument

CheckDefaultArgumentVisitor::Visit(...) assumes that the children of Expr will
not be NULL. This is not a valid assumption and when we have a CXXFoldExpr
the children can be NULL and this causes a crash.

Fixes: https://github.com/llvm/llvm-project/issues/67395
---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
 clang/test/SemaTemplate/cxx1z-fold-expressions.cpp | 8 
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 0091e0ecf6f3986..302e944d5d74f1c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -86,7 +86,8 @@ class CheckDefaultArgumentVisitor
 bool CheckDefaultArgumentVisitor::VisitExpr(const Expr *Node) {
   bool IsInvalid = false;
   for (const Stmt *SubStmt : Node->children())
-IsInvalid |= Visit(SubStmt);
+if (SubStmt)
+  IsInvalid |= Visit(SubStmt);
   return IsInvalid;
 }
 
diff --git a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp 
b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
index 518eaf0e05239e0..47a252eb335f6e5 100644
--- a/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ b/clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -124,3 +124,11 @@ namespace PR30738 {
   int test_h3 = h(1, 2, 3);
   N::S test_h4 = h(N::S(), N::S(), N::S()); // expected-note 
{{instantiation of}}
 }
+
+namespace GH67395 {
+template 
+bool f();
+
+template 
+void g(bool = (f() || ...));
+}

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