[cfe-commits] r109554 - in /cfe/trunk: include/clang/Lex/MacroInfo.h include/clang/Lex/Preprocessor.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Lex/MacroInfo.cpp test/PCH/Inputs/chain-macro1.h test/PCH/Inputs/chain-macro2.h test/PCH/chain-macro.c

Sebastian Redl sebastian.redl at getdesigned.at
Tue Jul 27 16:01:29 PDT 2010


Author: cornedbee
Date: Tue Jul 27 18:01:28 2010
New Revision: 109554

URL: http://llvm.org/viewvc/llvm-project?rev=109554&view=rev
Log:
Record macros in dependent PCHs. Also add various info tables to dependent PCHs; tests for this to follow.

Added:
    cfe/trunk/test/PCH/Inputs/chain-macro1.h
    cfe/trunk/test/PCH/Inputs/chain-macro2.h
    cfe/trunk/test/PCH/chain-macro.c
Modified:
    cfe/trunk/include/clang/Lex/MacroInfo.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Lex/MacroInfo.cpp

Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=109554&r1=109553&r2=109554&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Tue Jul 27 18:01:28 2010
@@ -62,6 +62,9 @@
   /// it has not yet been redefined or undefined.
   bool IsBuiltinMacro : 1;
 
+  /// IsFromPCH - True if this macro was loaded from a PCH file.
+  bool IsFromPCH : 1;
+
 private:
   //===--------------------------------------------------------------------===//
   // State that changes as the macro is used.
@@ -172,6 +175,12 @@
   /// __LINE__, which requires processing before expansion.
   bool isBuiltinMacro() const { return IsBuiltinMacro; }
 
+  /// isFromPCH - Return true if this macro was loaded from a PCH file.
+  bool isFromPCH() const { return IsFromPCH; }
+
+  /// setIsFromPCH - Set whether this macro was loaded from a PCH file.
+  void setIsFromPCH(bool FromPCH = true) { IsFromPCH = FromPCH; }
+
   /// isUsed - Return false if this macro is defined in the main file and has
   /// not yet been used.
   bool isUsed() const { return IsUsed; }

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=109554&r1=109553&r2=109554&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Jul 27 18:01:28 2010
@@ -117,7 +117,7 @@
   /// conceptually similar the IdentifierTable. In addition, the current control
   /// flow (in clang::ParseAST()), make it convenient to put here.
   /// FIXME: Make sure the lifetime of Identifiers/Selectors *isn't* tied to
-  /// the lifetime fo the preprocessor.
+  /// the lifetime of the preprocessor.
   SelectorTable Selectors;
 
   /// BuiltinInfo - Information about builtins.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=109554&r1=109553&r2=109554&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Jul 27 18:01:28 2010
@@ -633,7 +633,7 @@
     ID = ID >> 1;
 
     if (!IsInteresting) {
-      // For unintersting identifiers, just build the IdentifierInfo
+      // For uninteresting identifiers, just build the IdentifierInfo
       // and associate it with the persistent ID.
       IdentifierInfo *II = KnownII;
       if (!II)
@@ -1176,6 +1176,7 @@
 
       MacroInfo *MI = PP->AllocateMacroInfo(Loc);
       MI->setIsUsed(isUsed);
+      MI->setIsFromPCH();
 
       unsigned NextIndex = 3;
       if (RecType == pch::PP_MACRO_FUNCTION_LIKE) {

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=109554&r1=109553&r2=109554&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Jul 27 18:01:28 2010
@@ -1262,7 +1262,8 @@
 
     // Don't emit builtin macros like __LINE__ to the PCH file unless they have
     // been redefined by the header (in which case they are not isBuiltinMacro).
-    if (MI->isBuiltinMacro())
+    // Also skip macros from a PCH file if we're chaining.
+    if (MI->isBuiltinMacro() || (Chain && MI->isFromPCH()))
       continue;
 
     AddIdentifierRef(I->first, Record);
@@ -2372,6 +2373,42 @@
                           reinterpret_cast<const char*>(NewGlobalDecls.data()),
                           NewGlobalDecls.size() * sizeof(pch::DeclID));
 
+  // Build a record containing all of the new tentative definitions in this
+  // file, in TentativeDefinitions order.
+  RecordData TentativeDefinitions;
+  for (unsigned i = 0, e = SemaRef.TentativeDefinitions.size(); i != e; ++i) {
+    if (SemaRef.TentativeDefinitions[i]->getPCHLevel() == 0)
+      AddDeclRef(SemaRef.TentativeDefinitions[i], TentativeDefinitions);
+  }
+
+  // Build a record containing all of the static unused functions in this file.
+  RecordData UnusedStaticFuncs;
+  for (unsigned i=0, e = SemaRef.UnusedStaticFuncs.size(); i !=e; ++i) {
+    if (SemaRef.UnusedStaticFuncs[i]->getPCHLevel() == 0)
+      AddDeclRef(SemaRef.UnusedStaticFuncs[i], UnusedStaticFuncs);
+  }
+
+  // Build a record containing all of the locally-scoped external
+  // declarations in this header file. Generally, this record will be
+  // empty.
+  RecordData LocallyScopedExternalDecls;
+  // FIXME: This is filling in the PCH file in densemap order which is
+  // nondeterminstic!
+  for (llvm::DenseMap<DeclarationName, NamedDecl *>::iterator
+         TD = SemaRef.LocallyScopedExternalDecls.begin(),
+         TDEnd = SemaRef.LocallyScopedExternalDecls.end();
+       TD != TDEnd; ++TD) {
+    if (TD->second->getPCHLevel() == 0)
+      AddDeclRef(TD->second, LocallyScopedExternalDecls);
+  }
+
+  // Build a record containing all of the ext_vector declarations.
+  RecordData ExtVectorDecls;
+  for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I) {
+    if (SemaRef.ExtVectorDecls[I]->getPCHLevel() == 0)
+      AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls);
+  }
+
   Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3);
   WriteDeclsBlockAbbrevs();
   while (!DeclTypesToEmit.empty()) {
@@ -2384,17 +2421,41 @@
   }
   Stream.ExitBlock();
 
-  // FIXME: Preprocessor
+  WritePreprocessor(PP);
   // FIXME: Method pool
   WriteIdentifierTable(PP);
   WriteTypeDeclOffsets();
-  // FIXME: External unnamed definitions
-  // FIXME: Tentative definitions
-  // FIXME: Unused static functions
-  // FIXME: Locally-scoped external definitions
-  // FIXME: ext_vector type names
+
+  // Write the record containing external, unnamed definitions.
+  if (!ExternalDefinitions.empty())
+    Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
+
+  // Write the record containing tentative definitions.
+  if (!TentativeDefinitions.empty())
+    Stream.EmitRecord(pch::TENTATIVE_DEFINITIONS, TentativeDefinitions);
+
+  // Write the record containing unused static functions.
+  if (!UnusedStaticFuncs.empty())
+    Stream.EmitRecord(pch::UNUSED_STATIC_FUNCS, UnusedStaticFuncs);
+
+  // Write the record containing locally-scoped external definitions.
+  if (!LocallyScopedExternalDecls.empty())
+    Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS,
+                      LocallyScopedExternalDecls);
+
+  // Write the record containing ext_vector type names.
+  if (!ExtVectorDecls.empty())
+    Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls);
+
+  // FIXME: Vtable uses
   // FIXME: Dynamic classes declarations
-  // FIXME: Statistics
+
+  Record.clear();
+  Record.push_back(NumStatements);
+  Record.push_back(NumMacros);
+  Record.push_back(NumLexicalDeclContexts);
+  Record.push_back(NumVisibleDeclContexts);
+  Stream.EmitRecord(pch::STATISTICS, Record);
   Stream.ExitBlock();
 }
 

Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=109554&r1=109553&r2=109554&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Tue Jul 27 18:01:28 2010
@@ -20,6 +20,7 @@
   IsC99Varargs = false;
   IsGNUVarargs = false;
   IsBuiltinMacro = false;
+  IsFromPCH = false;
   IsDisabled = false;
   IsUsed = true;
 

Added: cfe/trunk/test/PCH/Inputs/chain-macro1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-macro1.h?rev=109554&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-macro1.h (added)
+++ cfe/trunk/test/PCH/Inputs/chain-macro1.h Tue Jul 27 18:01:28 2010
@@ -0,0 +1 @@
+#define FOOBAR void f();

Added: cfe/trunk/test/PCH/Inputs/chain-macro2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-macro2.h?rev=109554&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-macro2.h (added)
+++ cfe/trunk/test/PCH/Inputs/chain-macro2.h Tue Jul 27 18:01:28 2010
@@ -0,0 +1 @@
+#define BARFOO void g();

Added: cfe/trunk/test/PCH/chain-macro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-macro.c?rev=109554&view=auto
==============================================================================
--- cfe/trunk/test/PCH/chain-macro.c (added)
+++ cfe/trunk/test/PCH/chain-macro.c Tue Jul 27 18:01:28 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-macro1.h
+// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-macro2.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();
+FOOBAR
+// CHECK: void g();
+BARFOO





More information about the cfe-commits mailing list