[PATCH] D40372: [ExprConstant] Fix assert when initializing constexpr array
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 22 11:22:22 PST 2017
erik.pilkington created this revision.
Previously, clang would assert on the following:
struct S {
constexpr S (const int& ir = 0) {}
};
constexpr S foo[2];
The problem was that while initializing foo, CallStackFrame::createTemporary() was called twice for the MaterializeTemporaryExpr for `0` in the default constructor (once for each array element) without ending the lifetime of the first. This caused createTemporary() to assert. This patch fixes this problem by separating the lifetime of temporaries created for successive calls to the ctor when initializing arrays.
https://bugs.llvm.org/show_bug.cgi?id=34858
Thanks for taking a look!
Erik
https://reviews.llvm.org/D40372
Files:
lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx1y.cpp
Index: test/SemaCXX/constant-expression-cxx1y.cpp
===================================================================
--- test/SemaCXX/constant-expression-cxx1y.cpp
+++ test/SemaCXX/constant-expression-cxx1y.cpp
@@ -1021,3 +1021,10 @@
}
static_assert(evalNested(), "");
} // namespace PR19741
+
+namespace PR34858 {
+struct S {
+ constexpr S(const int & = 0) {}
+};
+constexpr S s[2];
+}
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -6912,12 +6912,14 @@
// Initialize the elements.
LValue ArrayElt = Subobject;
ArrayElt.addArray(Info, E, CAT);
- for (unsigned I = 0; I != N; ++I)
+ for (unsigned I = 0; I != N; ++I) {
+ BlockScopeRAII Scope(Info);
if (!VisitCXXConstructExpr(E, ArrayElt, &Value->getArrayInitializedElt(I),
CAT->getElementType()) ||
!HandleLValueArrayAdjustment(Info, E, ArrayElt,
CAT->getElementType(), 1))
return false;
+ }
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40372.123987.patch
Type: text/x-patch
Size: 1117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171122/eb017fd0/attachment.bin>
More information about the cfe-commits
mailing list