[clang] d194285 - [clang] Consider array filler in MaybeElementDependentArrayfiller()
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 4 22:44:43 PDT 2022
Author: Timm Bäder
Date: 2022-08-05T06:47:49+02:00
New Revision: d1942855c4317c61f9fae173afa2cbe1076c3c4c
URL: https://github.com/llvm/llvm-project/commit/d1942855c4317c61f9fae173afa2cbe1076c3c4c
DIFF: https://github.com/llvm/llvm-project/commit/d1942855c4317c61f9fae173afa2cbe1076c3c4c.diff
LOG: [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
Added:
clang/test/SemaCXX/constexpr-array-init.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
Removed:
################################################################################
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);
+
More information about the cfe-commits
mailing list