[cfe-commits] r144510 - in /cfe/trunk: include/clang/Lex/HeaderSearch.h include/clang/Serialization/ASTWriter.h lib/Serialization/ASTWriter.cpp test/Index/preamble-reparse-import.m test/Index/preamble-reparse-import.m-1.h test/Index/preamble-reparse-import.m-2.h test/Index/preamble-reparse-import.m-3.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Nov 13 14:08:39 PST 2011


Author: akirtzidis
Date: Sun Nov 13 16:08:39 2011
New Revision: 144510

URL: http://llvm.org/viewvc/llvm-project?rev=144510&view=rev
Log:
[PCH] When chaining a PCH and serializing HeaderSearch, make sure the HeaderFileInfos
from the primary PCH is deserialized, otherwise we lose info that headers were
already #imported/#included.

Added:
    cfe/trunk/test/Index/preamble-reparse-import.m
    cfe/trunk/test/Index/preamble-reparse-import.m-1.h
    cfe/trunk/test/Index/preamble-reparse-import.m-2.h
    cfe/trunk/test/Index/preamble-reparse-import.m-3.h
Modified:
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/include/clang/Serialization/ASTWriter.h
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=144510&r1=144509&r2=144510&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Sun Nov 13 16:08:39 2011
@@ -367,14 +367,17 @@
   /// FIXME: This will need to be generalized for submodules.
   StringRef findModuleForHeader(const FileEntry *File);
   
-  typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator;
-  header_file_iterator header_file_begin() const { return FileInfo.begin(); }
-  header_file_iterator header_file_end() const { return FileInfo.end(); }
   unsigned header_file_size() const { return FileInfo.size(); }
 
   // Used by ASTReader.
   void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID);
 
+  /// getFileInfo - Return the HeaderFileInfo structure for the specified
+  /// FileEntry.
+  const HeaderFileInfo &getFileInfo(const FileEntry *FE) const {
+    return const_cast<HeaderSearch*>(this)->getFileInfo(FE);
+  }
+
   // Used by external tools
   typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator;
   search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=144510&r1=144509&r2=144510&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Sun Nov 13 16:08:39 2011
@@ -377,7 +377,7 @@
                                const Preprocessor &PP,
                                StringRef isysroot);
   void WritePreprocessor(const Preprocessor &PP, bool IsModule);
-  void WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot);
+  void WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot);
   void WritePreprocessorDetail(PreprocessingRecord &PPRec);
   void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag);
   void WriteCXXBaseSpecifiersOffsets();

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=144510&r1=144509&r2=144510&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Nov 13 16:08:39 2011
@@ -1220,14 +1220,14 @@
   // Trait used for the on-disk hash table of header search information.
   class HeaderFileInfoTrait {
     ASTWriter &Writer;
-    HeaderSearch &HS;
+    const HeaderSearch &HS;
     
     // Keep track of the framework names we've used during serialization.
     SmallVector<char, 128> FrameworkStringData;
     llvm::StringMap<unsigned> FrameworkNameOffset;
     
   public:
-    HeaderFileInfoTrait(ASTWriter &Writer, HeaderSearch &HS) 
+    HeaderFileInfoTrait(ASTWriter &Writer, const HeaderSearch &HS) 
       : Writer(Writer), HS(HS) { }
     
     typedef const char *key_type;
@@ -1306,7 +1306,7 @@
 /// \param HS The header search structure to save.
 ///
 /// \param Chain Whether we're creating a chained AST file.
-void ASTWriter::WriteHeaderSearch(HeaderSearch &HS, StringRef isysroot) {
+void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot) {
   SmallVector<const FileEntry *, 16> FilesByUID;
   HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
   
@@ -1322,7 +1322,9 @@
     if (!File)
       continue;
 
-    const HeaderFileInfo &HFI = HS.header_file_begin()[UID];
+    // Use HeaderSearch's getFileInfo to make sure we get the HeaderFileInfo
+    // from the external source if it was not provided already.
+    const HeaderFileInfo &HFI = HS.getFileInfo(File);
     if (HFI.External && Chain)
       continue;
 

Added: cfe/trunk/test/Index/preamble-reparse-import.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-import.m?rev=144510&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-import.m (added)
+++ cfe/trunk/test/Index/preamble-reparse-import.m Sun Nov 13 16:08:39 2011
@@ -0,0 +1,12 @@
+// RUN: c-index-test -write-pch %t.h.pch -x objective-c %s-2.h
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 \
+// RUN:   c-index-test -test-load-source-reparse 3 local %s -include %t.h
+// RUN: c-index-test -write-pch %t.h.pch -x objective-c %s-3.h
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 \
+// RUN:   c-index-test -test-load-source-reparse 3 local %s -include %t.h
+
+#import "preamble-reparse-import.m-1.h"
+
+void foo();
+#import "preamble-reparse-import.m-2.h"
+#import "preamble-reparse-import.m-1.h"

Added: cfe/trunk/test/Index/preamble-reparse-import.m-1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-import.m-1.h?rev=144510&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-import.m-1.h (added)
+++ cfe/trunk/test/Index/preamble-reparse-import.m-1.h Sun Nov 13 16:08:39 2011
@@ -0,0 +1,5 @@
+#ifdef PARSED2
+#error parsed twice
+#endif
+
+#define PARSED2 1

Added: cfe/trunk/test/Index/preamble-reparse-import.m-2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-import.m-2.h?rev=144510&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-import.m-2.h (added)
+++ cfe/trunk/test/Index/preamble-reparse-import.m-2.h Sun Nov 13 16:08:39 2011
@@ -0,0 +1,5 @@
+#ifdef PARSED
+#error parsed twice
+#endif
+
+#define PARSED 1

Added: cfe/trunk/test/Index/preamble-reparse-import.m-3.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble-reparse-import.m-3.h?rev=144510&view=auto
==============================================================================
--- cfe/trunk/test/Index/preamble-reparse-import.m-3.h (added)
+++ cfe/trunk/test/Index/preamble-reparse-import.m-3.h Sun Nov 13 16:08:39 2011
@@ -0,0 +1 @@
+#import "preamble-reparse-import.m-2.h"





More information about the cfe-commits mailing list