Index: include/clang/Basic/SourceManager.h
===================================================================
--- include/clang/Basic/SourceManager.h	(revision 146901)
+++ include/clang/Basic/SourceManager.h	(working copy)
@@ -613,6 +613,12 @@
   /// getMainFileID - Returns the FileID of the main source file.
   FileID getMainFileID() const { return MainFileID; }
 
+  /// setMainFileID - Set the FileID of the main source file.
+  void setMainFileID(FileID ID) {
+    assert(MainFileID.isInvalid() && "MainFileID already set!");
+    MainFileID = ID;
+  }
+
   /// createMainFileID - Create the FileID for the main source file.
   FileID createMainFileID(const FileEntry *SourceFile) {
     assert(MainFileID.isInvalid() && "MainFileID already set!");
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp	(revision 146901)
+++ lib/Serialization/ASTReader.cpp	(working copy)
@@ -896,6 +896,7 @@
   }
 
   static internal_key_type GetInternalKey(const char *path) { return path; }
+  static external_key_type GetExternalKey(internal_key_type key) { return key; }
 
   static bool EqualKey(internal_key_type a, internal_key_type b) {
     return strcmp(a, b) == 0;
@@ -2654,6 +2655,12 @@
                                         + OriginalFileID.getOpaqueValue() - 1);
       SourceMgr.setPreambleFileID(OriginalFileID);
     }
+  } else if (Type == MK_MainFile) {
+    if (!OriginalFileID.isInvalid()) {
+      OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID
+                                        + OriginalFileID.getOpaqueValue() - 1);
+      SourceMgr.setMainFileID(OriginalFileID);
+    }
   }
   
   return Success;
