[clang] [Clang] Fix crash when visting a fold expression in a default argument (PR #67514)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 26 19:04:38 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
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<struct X>(1, 2, 3);
N::S test_h4 = h<struct X>(N::S(), N::S(), N::S()); // expected-note {{instantiation of}}
}
+
+namespace GH67395 {
+template <typename>
+bool f();
+
+template <typename... T>
+void g(bool = (f<T>() || ...));
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/67514
More information about the cfe-commits
mailing list