]> granicus.if.org Git - clang/commitdiff
[PCH] Fix crash with valid code, related to anonymous field initializers.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 30 May 2013 23:59:46 +0000 (23:59 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 30 May 2013 23:59:46 +0000 (23:59 +0000)
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

lib/Serialization/ASTReader.cpp
test/PCH/cxx-member-init.cpp

index a4c8c353077cdb73265332570342cd4e379bee21..e7d17dede8b0cd399e849cb79ea7c2e531c8431c 100644 (file)
@@ -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)
index 20594d532e3370945c3b49d4375fd10e8a8e9f51..78fd74425b84d00caf3bd215e807f4b3808bbfce 100644 (file)
@@ -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