[PCH] Fix crash with valid code, related to anonymous field initializers.
In a certain code-path we were not deserializing an anonymous field initializer correctly,
leading to a crash when trying to IRGen it.
This is a simpler version of a patch by Yunzhong Gao!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182974 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index a4c8c35..e7d17de 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -6993,9 +6993,16 @@
MemberOrEllipsisLoc, LParenLoc,
Init, RParenLoc);
} else {
- BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc,
- LParenLoc, Init, RParenLoc,
- Indices.data(), Indices.size());
+ if (IndirectMember) {
+ assert(Indices.empty() && "Indirect field improperly initialized");
+ BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember,
+ MemberOrEllipsisLoc, LParenLoc,
+ Init, RParenLoc);
+ } else {
+ BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc,
+ LParenLoc, Init, RParenLoc,
+ Indices.data(), Indices.size());
+ }
}
if (IsWritten)
diff --git a/test/PCH/cxx-member-init.cpp b/test/PCH/cxx-member-init.cpp
index 20594d5..78fd744 100644
--- a/test/PCH/cxx-member-init.cpp
+++ b/test/PCH/cxx-member-init.cpp
@@ -13,6 +13,15 @@
S *that = this;
};
template<typename T> struct X { T t {0}; };
+
+struct v_t { };
+
+struct m_t
+{
+ struct { v_t v; };
+ m_t() { }
+};
+
#endif
#ifdef SOURCE
@@ -20,6 +29,11 @@
struct E { explicit E(int); };
X<E> x;
+
+m_t *test() {
+ return new m_t;
+}
+
#elif HEADER
#undef HEADER
#define SOURCE