]> granicus.if.org Git - clang/commitdiff
Keep track of the file ID corresponding to the original file used to
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 May 2011 21:43:30 +0000 (21:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 May 2011 21:43:30 +0000 (21:43 +0000)
build a precompiled header. Use this information to eliminate the call
to SourceManager::getLocation() while loading a precompiled preamble,
since SourceManager::getLocation() itself causes unwanted
deserialization.

Fixed <rdar://problem/9399352>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131021 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceLocation.h
include/clang/Serialization/ASTBitCodes.h
include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index 14bb2b724fd455bd0fa5499e4b15dbf4fb81dd2b..ee5f96fe937a4381e9a0d30fe19dda8a55507b98 100644 (file)
@@ -54,6 +54,9 @@ public:
 
 private:
   friend class SourceManager;
+  friend class ASTWriter;
+  friend class ASTReader;
+  
   static FileID get(unsigned V) {
     FileID F;
     F.ID = V;
index 0b997563f93294a894f600a26142d03351b3b3da..ff0267589853136a71a7158070ac2a487ad2179b 100644 (file)
@@ -279,7 +279,9 @@ namespace clang {
       /// generate the AST file.
       ORIGINAL_FILE_NAME = 19,
 
-      /// Record #20 intentionally left blank.
+      /// \brief Record code for the file ID of the original file used to 
+      /// generate the AST file.
+      ORIGINAL_FILE_ID = 20,
       
       /// \brief Record code for the version control branch and revision
       /// information of the compiler used to build this AST file.
index fd073e29aa95439b5b0cdcbb3e7fb0fcbe64b2ab..244503a82aa4b7bde75c12b785b947ddbc53d4a5 100644 (file)
@@ -631,6 +631,10 @@ private:
   /// AST file.
   std::string ActualOriginalFileName;
 
+  /// \brief The file ID for the original file that was used to build the
+  /// primary AST file.
+  FileID OriginalFileID;
+  
   /// \brief The directory that the PCH was originally created in. Used to
   /// allow resolving headers even after headers+PCH was moved to a new path.
   std::string OriginalDir;
index bdc46f590fa1d0e37577d84ad148d2febd33d3fd..0ab1704b117de5dc1637df5e3d5084bb0c515182 100644 (file)
@@ -2237,6 +2237,10 @@ ASTReader::ReadASTBlock(PerFileData &F) {
       MaybeAddSystemRootToFilename(OriginalFileName);
       break;
 
+    case ORIGINAL_FILE_ID:
+      OriginalFileID = FileID::get(Record[0]);
+      break;
+        
     case ORIGINAL_PCH_DIR:
       // The primary AST will be the last to get here, so it will be the one
       // that's used.
@@ -2451,12 +2455,15 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
   // the source manager to the file source file from which the preamble was
   // built. This is the only valid way to use a precompiled preamble.
   if (Type == Preamble) {
-    SourceLocation Loc
-      = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1);
-    if (Loc.isValid()) {
-      std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc);
-      SourceMgr.SetPreambleFileID(Decomposed.first);
+    if (OriginalFileID.isInvalid()) {
+      SourceLocation Loc
+        = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1);
+      if (Loc.isValid())
+        OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first;
     }
+    
+    if (!OriginalFileID.isInvalid())
+      SourceMgr.SetPreambleFileID(OriginalFileID);
   }
   
   return Success;
index 1c62bfd72abcadbc1b84c26e9f244d6951260bec..720f203040bd022c6df86052974888a68e240396 100644 (file)
@@ -727,6 +727,7 @@ void ASTWriter::WriteBlockInfoBlock() {
   // AST Top-Level Block.
   BLOCK(AST_BLOCK);
   RECORD(ORIGINAL_FILE_NAME);
+  RECORD(ORIGINAL_FILE_ID);
   RECORD(TYPE_OFFSET);
   RECORD(DECL_OFFSET);
   RECORD(LANGUAGE_OPTIONS);
@@ -953,7 +954,7 @@ void ASTWriter::WriteMetadata(ASTContext &Context, const char *isysroot,
   const std::string &BlobStr = Chain ? Chain->getFileName() : Target.getTriple().getTriple();
   Stream.EmitRecordWithBlob(MetaAbbrevCode, Record, BlobStr);
 
-  // Original file name
+  // Original file name and file ID
   SourceManager &SM = Context.getSourceManager();
   if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
     BitCodeAbbrev *FileAbbrev = new BitCodeAbbrev();
@@ -971,6 +972,10 @@ void ASTWriter::WriteMetadata(ASTContext &Context, const char *isysroot,
     RecordData Record;
     Record.push_back(ORIGINAL_FILE_NAME);
     Stream.EmitRecordWithBlob(FileAbbrevCode, Record, MainFileNameStr);
+    
+    Record.clear();
+    Record.push_back(SM.getMainFileID().getOpaqueValue());
+    Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
   }
 
   // Original PCH directory