]> granicus.if.org Git - clang/commitdiff
Update the list of lexical decls in the TU for chained PCHs. This makes -ast-print...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 27 Jul 2010 18:24:41 +0000 (18:24 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 27 Jul 2010 18:24:41 +0000 (18:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109524 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHBitCodes.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHReaderDecl.cpp
lib/Frontend/PCHWriter.cpp
test/PCH/chain-function.c

index 76c4a7cb2ac9b5d7622379ac011b059a3651fd76..774a96becb98a85d77b17e96238010637b1123bc 100644 (file)
@@ -237,9 +237,13 @@ namespace clang {
       /// \brief Record code for the chained PCH metadata, including the
       /// PCH version and the name of the PCH this is chained to.
       CHAINED_METADATA = 26,
-      
+
       /// \brief Record code for referenced selector pool.
-      REFERENCED_SELECTOR_POOL = 27
+      REFERENCED_SELECTOR_POOL = 27,
+
+      /// \brief Record code for an update to the TU's lexically contained
+      /// declarations.
+      TU_UPDATE_LEXICAL = 28
     };
 
     /// \brief Record types used within a source manager block.
index 37e11249f88e9cc87a572f406883bb9a489b3003..a0e3148bc73e1141b3b2f0058d3b1152b46dced5 100644 (file)
@@ -1539,6 +1539,16 @@ PCHReader::ReadPCHBlock(PerFileData &F) {
       F.LocalNumDecls = Record[0];
       break;
 
+    case pch::TU_UPDATE_LEXICAL: {
+      DeclContextInfo Info = {
+        /* No visible information */ 0, 0,
+        reinterpret_cast<const pch::DeclID *>(BlobStart),
+        BlobLen / sizeof(pch::DeclID)
+      };
+      DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info);
+      break;
+    }
+
     case pch::LANGUAGE_OPTIONS:
       if (ParseLanguageOptions(Record) && !DisableValidation)
         return IgnorePCH;
index 6f6ed84df7753f060e5a43e3e230e01e2dea9534..fe2947d64f9b3ec357332c9ea54da90451e4a0af 100644 (file)
@@ -1520,7 +1520,11 @@ Decl *PCHReader::ReadDeclRecord(unsigned Index) {
       DeclContextInfo Info;
       if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
         return 0;
-      DeclContextOffsets[DC].push_back(Info);
+      DeclContextInfos &Infos = DeclContextOffsets[DC];
+      // Reading the TU will happen after reading its update blocks, so we need
+      // to make sure we insert in front. For all other contexts, the vector
+      // is empty here anyway, so there's no loss in efficiency.
+      Infos.insert(Infos.begin(), Info);
     }
   }
   assert(Idx == Record.size());
index 0ade10f7f86be080acc20f978713522aeb8ed7c3..96c64169cf3f992ca23519eb251fe948b04a767c 100644 (file)
@@ -2354,15 +2354,23 @@ void PCHWriter::WritePCHChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   // The TU was loaded before we managed to register ourselves as a listener.
   // Thus we need to add it manually.
   DeclIDs[TU] = 1;
-  Record.clear();
+  llvm::SmallVector<pch::DeclID, 64> NewGlobalDecls;
   for (DeclContext::decl_iterator I = TU->noload_decls_begin(),
                                   E = TU->noload_decls_end();
        I != E; ++I) {
-    if ((*I)->getPCHLevel() == 0) {
-      AddDeclRef(*I, Record);
-    }
+    if ((*I)->getPCHLevel() == 0)
+      NewGlobalDecls.push_back(GetDeclRef(*I));
   }
   // We also need to write a lexical updates block for the TU.
+  llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev();
+  Abv->Add(llvm::BitCodeAbbrevOp(pch::TU_UPDATE_LEXICAL));
+  Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
+  unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv);
+  Record.clear();
+  Record.push_back(pch::TU_UPDATE_LEXICAL);
+  Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record,
+                          reinterpret_cast<const char*>(NewGlobalDecls.data()),
+                          NewGlobalDecls.size() * sizeof(pch::DeclID));
 
   Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3);
   WriteDeclsBlockAbbrevs();
index 29bfdd4c3eac05ce4b94db141b29c4851f72ce86..0d766fbfc385225c85d46f70a96740dbd919832a 100644 (file)
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-function1.h
 // RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-function2.h -include-pch %t1 -chained-pch
 // RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s
+// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s
+
+// CHECK: void f();
+// CHECK: void g();
 
 void h() {
   f();