r182974 - [PCH] Fix crash with valid code, related to anonymous field initializers.

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu May 30 16:59:46 PDT 2013


Author: akirtzidis
Date: Thu May 30 18:59:46 2013
New Revision: 182974

URL: http://llvm.org/viewvc/llvm-project?rev=182974&view=rev
Log:
[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!

Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/test/PCH/cxx-member-init.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=182974&r1=182973&r2=182974&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu May 30 18:59:46 2013
@@ -6993,9 +6993,16 @@ ASTReader::ReadCXXCtorInitializers(Modul
                                                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)

Modified: cfe/trunk/test/PCH/cxx-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-member-init.cpp?rev=182974&r1=182973&r2=182974&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx-member-init.cpp (original)
+++ cfe/trunk/test/PCH/cxx-member-init.cpp Thu May 30 18:59:46 2013
@@ -13,6 +13,15 @@ struct S {
   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 @@ S s;
 
 struct E { explicit E(int); };
 X<E> x;
+
+m_t *test() {
+  return new m_t;
+}
+
 #elif HEADER
 #undef HEADER
 #define SOURCE





More information about the cfe-commits mailing list