From: Argyrios Kyrtzidis Date: Thu, 30 May 2013 23:59:46 +0000 (+0000) Subject: [PCH] Fix crash with valid code, related to anonymous field initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8f480ff1cba08ce7e93160546168f729c95804c;p=clang [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 a4c8c35307..e7d17dede8 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -6993,9 +6993,16 @@ ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, 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 20594d532e..78fd74425b 100644 --- a/test/PCH/cxx-member-init.cpp +++ b/test/PCH/cxx-member-init.cpp @@ -13,6 +13,15 @@ struct S { S *that = this; }; template struct X { T t {0}; }; + +struct v_t { }; + +struct m_t +{ + struct { v_t v; }; + m_t() { } +}; + #endif #ifdef SOURCE @@ -20,6 +29,11 @@ S s; struct E { explicit E(int); }; X x; + +m_t *test() { + return new m_t; +} + #elif HEADER #undef HEADER #define SOURCE