[llvm-branch-commits] [cfe-branch] r120668 - in /cfe/branches/Apple/whitney: include/clang/Basic/SourceManager.h lib/Frontend/CompilerInstance.cpp lib/Serialization/ASTReader.cpp

Daniel Dunbar daniel at zuster.org
Wed Dec 1 18:52:24 PST 2010


Author: ddunbar
Date: Wed Dec  1 20:52:24 2010
New Revision: 120668

URL: http://llvm.org/viewvc/llvm-project?rev=120668&view=rev
Log:
Merge r120390:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Tue Nov 30 05:23:00 2010 +0000

    When loading a precompiled preamble, use the file ID of the
    precompiled preamble as the "main" source file's file ID within the
    source manager. This makes compiling with a precompiled preamble
    produce the same source locations as when compiling without the
    precompiled preamble; prior to this change, we ended up with different
    file IDs for source locations within the precompiled preamble
    vs. those after the precompiled preamble, even for entities (e.g.,
    preprocessing entities) in the same file.

*** MANUAL MERGE ***

Modified:
    cfe/branches/Apple/whitney/include/clang/Basic/SourceManager.h
    cfe/branches/Apple/whitney/lib/Frontend/CompilerInstance.cpp
    cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp

Modified: cfe/branches/Apple/whitney/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/include/clang/Basic/SourceManager.h?rev=120668&r1=120667&r2=120668&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/include/clang/Basic/SourceManager.h (original)
+++ cfe/branches/Apple/whitney/include/clang/Basic/SourceManager.h Wed Dec  1 20:52:24 2010
@@ -461,6 +461,13 @@
     return MainFileID;
   }
 
+  /// \brief Set the file ID for the precompiled preamble, which is also the
+  /// main file.
+  void SetPreambleFileID(FileID Preamble) {
+    assert(MainFileID.isInvalid() && "MainFileID already set!");
+    MainFileID = Preamble;
+  }
+  
   //===--------------------------------------------------------------------===//
   // Methods to create new FileID's and instantiations.
   //===--------------------------------------------------------------------===//

Modified: cfe/branches/Apple/whitney/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Frontend/CompilerInstance.cpp?rev=120668&r1=120667&r2=120668&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Frontend/CompilerInstance.cpp Wed Dec  1 20:52:24 2010
@@ -478,8 +478,11 @@
                                                const FileSystemOptions &FSOpts,
                                                SourceManager &SourceMgr,
                                                const FrontendOptions &Opts) {
-  // Figure out where to get and map in the main file.
-  if (InputFile != "-") {
+  // Figure out where to get and map in the main file, unless it's already
+  // been created (e.g., by a precompiled preamble).
+  if (!SourceMgr.getMainFileID().isInvalid()) {
+    // Do nothing: the main file has already been set.
+  } else if (InputFile != "-") {
     const FileEntry *File = FileMgr.getFile(InputFile, FSOpts);
     if (!File) {
       Diags.Report(diag::err_fe_error_reading) << InputFile;

Modified: cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp?rev=120668&r1=120667&r2=120668&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Serialization/ASTReader.cpp Wed Dec  1 20:52:24 2010
@@ -2249,6 +2249,19 @@
   if (DeserializationListener)
     DeserializationListener->ReaderInitialized(this);
 
+  // If this AST file is a precompiled preamble, then set the main file ID of 
+  // 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(),
+                                              FileSystemOpts), 1, 1);
+    if (Loc.isValid()) {
+      std::pair<FileID, unsigned> Decomposed = SourceMgr.getDecomposedLoc(Loc);
+      SourceMgr.SetPreambleFileID(Decomposed.first);
+    }
+  }
+  
   return Success;
 }
 





More information about the llvm-branch-commits mailing list