[cfe-commits] r107477 - in /cfe/trunk/lib/Frontend: PCHReaderDecl.cpp PCHWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jul 2 04:55:41 PDT 2010


Author: akirtzidis
Date: Fri Jul  2 06:55:40 2010
New Revision: 107477

URL: http://llvm.org/viewvc/llvm-project?rev=107477&view=rev
Log:
Fix reading FunctionDecls from PCH.

Modified:
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Frontend/PCHWriterDecl.cpp

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107477&r1=107476&r2=107477&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri Jul  2 06:55:40 2010
@@ -206,22 +206,6 @@
 
 void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   VisitDeclaratorDecl(FD);
-  if (Record[Idx++])
-    FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
-  FD->setPreviousDeclaration(
-                   cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
-  FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
-  FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
-  FD->setInlineSpecified(Record[Idx++]);
-  FD->setVirtualAsWritten(Record[Idx++]);
-  FD->setPure(Record[Idx++]);
-  FD->setHasInheritedPrototype(Record[Idx++]);
-  FD->setHasWrittenPrototype(Record[Idx++]);
-  FD->setDeleted(Record[Idx++]);
-  FD->setTrivial(Record[Idx++]);
-  FD->setCopyAssignment(Record[Idx++]);
-  FD->setHasImplicitReturnZero(Record[Idx++]);
-  FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
 
   switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
   default: assert(false && "Unhandled TemplatedKind!");
@@ -250,22 +234,22 @@
     Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
     
     // Template args as written.
-    unsigned NumTemplateArgLocs = Record[Idx++];
     llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
-    TemplArgLocs.reserve(NumTemplateArgLocs);
-    for (unsigned i=0; i != NumTemplateArgLocs; ++i)
-      TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
-
     SourceLocation LAngleLoc, RAngleLoc;
-    if (NumTemplateArgLocs) {
+    if (Record[Idx++]) {  // TemplateArgumentsAsWritten != 0
+      unsigned NumTemplateArgLocs = Record[Idx++];
+      TemplArgLocs.reserve(NumTemplateArgLocs);
+      for (unsigned i=0; i != NumTemplateArgLocs; ++i)
+        TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
+  
       LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
       RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
     }
 
     FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
                                           TemplArgs.data(), TSK,
-                                          NumTemplateArgLocs,
-                                  NumTemplateArgLocs ? TemplArgLocs.data() : 0,
+                                          TemplArgLocs.size(),
+                                          TemplArgLocs.data(),
                                           LAngleLoc, RAngleLoc);
     break;
   }
@@ -287,7 +271,24 @@
     break;
   }
   }
-  
+
+  if (Record[Idx++])
+    FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
+  FD->setPreviousDeclaration(
+                   cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
+  FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
+  FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
+  FD->setInlineSpecified(Record[Idx++]);
+  FD->setVirtualAsWritten(Record[Idx++]);
+  FD->setPure(Record[Idx++]);
+  FD->setHasInheritedPrototype(Record[Idx++]);
+  FD->setHasWrittenPrototype(Record[Idx++]);
+  FD->setDeleted(Record[Idx++]);
+  FD->setTrivial(Record[Idx++]);
+  FD->setCopyAssignment(Record[Idx++]);
+  FD->setHasImplicitReturnZero(Record[Idx++]);
+  FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
+
   // Read in the parameters.
   unsigned NumParams = Record[Idx++];
   llvm::SmallVector<ParmVarDecl *, 16> Params;

Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=107477&r1=107476&r2=107477&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri Jul  2 06:55:40 2010
@@ -199,24 +199,6 @@
 void PCHDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
   VisitDeclaratorDecl(D);
 
-  Record.push_back(D->isThisDeclarationADefinition());
-  if (D->isThisDeclarationADefinition())
-    Writer.AddStmt(D->getBody());
-
-  Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
-  Record.push_back(D->getStorageClass()); // FIXME: stable encoding
-  Record.push_back(D->getStorageClassAsWritten());
-  Record.push_back(D->isInlineSpecified());
-  Record.push_back(D->isVirtualAsWritten());
-  Record.push_back(D->isPure());
-  Record.push_back(D->hasInheritedPrototype());
-  Record.push_back(D->hasWrittenPrototype());
-  Record.push_back(D->isDeleted());
-  Record.push_back(D->isTrivial());
-  Record.push_back(D->isCopyAssignment());
-  Record.push_back(D->hasImplicitReturnZero());
-  Writer.AddSourceLocation(D->getLocEnd(), Record);
-  
   Record.push_back(D->getTemplatedKind());
   switch (D->getTemplatedKind()) {
   default: assert(false && "Unhandled TemplatedKind!");
@@ -243,6 +225,7 @@
     Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
     
     // Template args as written.
+    Record.push_back(FTSInfo->TemplateArgumentsAsWritten != 0);
     if (FTSInfo->TemplateArgumentsAsWritten) {
       Record.push_back(FTSInfo->TemplateArgumentsAsWritten->size());
       for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->size(); i!=e; ++i)
@@ -252,8 +235,6 @@
                                Record);
       Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->getRAngleLoc(),
                                Record);
-    } else {
-      Record.push_back(0);
     }
     break;
   }
@@ -274,6 +255,26 @@
   }
   }
 
+  // Make sure no Exprs are emitted after the body, because when reading the
+  // function, the body doesn't get read so the cursor doesn't advance. 
+  Record.push_back(D->isThisDeclarationADefinition());
+  if (D->isThisDeclarationADefinition())
+    Writer.AddStmt(D->getBody());
+
+  Writer.AddDeclRef(D->getPreviousDeclaration(), Record);
+  Record.push_back(D->getStorageClass()); // FIXME: stable encoding
+  Record.push_back(D->getStorageClassAsWritten());
+  Record.push_back(D->isInlineSpecified());
+  Record.push_back(D->isVirtualAsWritten());
+  Record.push_back(D->isPure());
+  Record.push_back(D->hasInheritedPrototype());
+  Record.push_back(D->hasWrittenPrototype());
+  Record.push_back(D->isDeleted());
+  Record.push_back(D->isTrivial());
+  Record.push_back(D->isCopyAssignment());
+  Record.push_back(D->hasImplicitReturnZero());
+  Writer.AddSourceLocation(D->getLocEnd(), Record);
+
   Record.push_back(D->param_size());
   for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
        P != PEnd; ++P)





More information about the cfe-commits mailing list