aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2022-08-04 12:53:06 +0200
committerTimm Bäder <tbaeder@redhat.com>2022-08-05 06:47:49 +0200
commitd1942855c4317c61f9fae173afa2cbe1076c3c4c (patch)
treebb976027831a06f9c330a179a07a3e5d76045dad
parent8b74074731eeb3ff673bd7da4cd963efe78f8db6 (diff)
[clang] Consider array filler in MaybeElementDependentArrayfiller()
Any InitListExpr may have an array filler and since we may be evaluating the array filler as well, we need to take into account that the array filler expression might make the InitListExpr element dependent. Fixes https://github.com/llvm/llvm-project/issues/56016 Differential Revision: https://reviews.llvm.org/D131155
-rw-r--r--clang/docs/ReleaseNotes.rst4
-rw-r--r--clang/lib/AST/ExprConstant.cpp5
-rw-r--r--clang/test/SemaCXX/constexpr-array-init.cpp24
3 files changed, 33 insertions, 0 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c9f65b271413..a2d7526bb770 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -62,6 +62,10 @@ Bug Fixes
already properly diagnosing this case).
- Fix clang not properly diagnosing the failing subexpression when chained
binary operators are used in a ``static_assert`` expression.
+- Fix a crash when evaluating a multi-dimensional array's array filler
+ expression is element-dependent. This fixes
+ `Issue 50601 <https://github.com/llvm/llvm-project/issues/56016>`_.
+
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6f3539a4b2c1..36f957711316 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10695,6 +10695,11 @@ static bool MaybeElementDependentArrayFiller(const Expr *FillerExpr) {
if (MaybeElementDependentArrayFiller(ILE->getInit(I)))
return true;
}
+
+ if (ILE->hasArrayFiller() &&
+ MaybeElementDependentArrayFiller(ILE->getArrayFiller()))
+ return true;
+
return false;
}
return true;
diff --git a/clang/test/SemaCXX/constexpr-array-init.cpp b/clang/test/SemaCXX/constexpr-array-init.cpp
new file mode 100644
index 000000000000..cb11f47fb3cb
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-array-init.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+/// This test case used to crash in constant evaluation
+/// because of the two-dimensional array with an array
+/// filler expression.
+
+/// expected-no-diagnostics
+struct Foo {
+ int a;
+ constexpr Foo()
+ : a(get_int()) {
+ }
+
+ constexpr int get_int() const {
+ return 5;
+ }
+};
+
+static constexpr Foo bar[2][1] = {
+ {{}},
+};
+static_assert(bar[0][0].a == 5);
+static_assert(bar[1][0].a == 5);
+