[cfe-commits] r129983 - in /cfe/trunk/lib/Serialization: ASTReaderStmt.cpp ASTWriterStmt.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Apr 21 22:29:31 PDT 2011


Author: akirtzidis
Date: Fri Apr 22 00:29:30 2011
New Revision: 129983

URL: http://llvm.org/viewvc/llvm-project?rev=129983&view=rev
Log:
For

 double data[20000000] = { [19999999] = 1 };

Don't serialize the filler multiple times.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
    cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=129983&r1=129982&r2=129983&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Fri Apr 22 00:29:30 2011
@@ -683,19 +683,29 @@
 
 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
   VisitExpr(E);
-  unsigned NumInits = Record[Idx++];
-  E->reserveInits(*Reader.getContext(), NumInits);
-  for (unsigned I = 0; I != NumInits; ++I)
-    E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr());
   E->setSyntacticForm(cast_or_null<InitListExpr>(Reader.ReadSubStmt()));
   E->setLBraceLoc(ReadSourceLocation(Record, Idx));
   E->setRBraceLoc(ReadSourceLocation(Record, Idx));
-  if (Record[Idx++]) // isArrayFiller
-    E->ArrayFillerOrUnionFieldInit = Reader.ReadSubExpr();
-  else
+  bool isArrayFiller = Record[Idx++];
+  Expr *filler = 0;
+  if (isArrayFiller) {
+    filler = Reader.ReadSubExpr();
+    E->ArrayFillerOrUnionFieldInit = filler;
+  } else
     E->ArrayFillerOrUnionFieldInit
         = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
   E->sawArrayRangeDesignator(Record[Idx++]);
+  unsigned NumInits = Record[Idx++];
+  E->reserveInits(*Reader.getContext(), NumInits);
+  if (isArrayFiller) {
+    for (unsigned I = 0; I != NumInits; ++I) {
+      Expr *init = Reader.ReadSubExpr();
+      E->updateInit(*Reader.getContext(), I, init ? init : filler);
+    }
+  } else {
+    for (unsigned I = 0; I != NumInits; ++I)
+      E->updateInit(*Reader.getContext(), I, Reader.ReadSubExpr());
+  }
 }
 
 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {

Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=129983&r1=129982&r2=129983&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Fri Apr 22 00:29:30 2011
@@ -667,9 +667,6 @@
 
 void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
   VisitExpr(E);
-  Record.push_back(E->getNumInits());
-  for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
-    Writer.AddStmt(E->getInit(I));
   Writer.AddStmt(E->getSyntacticForm());
   Writer.AddSourceLocation(E->getLBraceLoc(), Record);
   Writer.AddSourceLocation(E->getRBraceLoc(), Record);
@@ -680,6 +677,17 @@
   else
     Writer.AddDeclRef(E->getInitializedFieldInUnion(), Record);
   Record.push_back(E->hadArrayRangeDesignator());
+  Record.push_back(E->getNumInits());
+  if (isArrayFiller) {
+    // ArrayFiller may have filled "holes" due to designated initializer.
+    // Replace them by 0 to indicate that the filler goes in that place.
+    Expr *filler = E->getArrayFiller();
+    for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
+      Writer.AddStmt(E->getInit(I) != filler ? E->getInit(I) : 0);
+  } else {
+    for (unsigned I = 0, N = E->getNumInits(); I != N; ++I)
+      Writer.AddStmt(E->getInit(I));
+  }
   Code = serialization::EXPR_INIT_LIST;
 }
 





More information about the cfe-commits mailing list