Index: lib/Interpreter/CIFactory.cpp
===================================================================
--- lib/Interpreter/CIFactory.cpp	(revision 45565)
+++ lib/Interpreter/CIFactory.cpp	(working copy)
@@ -220,8 +220,14 @@
     CI->createSourceManager(CI->getFileManager());
 
     // Set up the memory buffer
-    if (buffer)
-      CI->getSourceManager().createMainFileIDForMemBuffer(buffer);
+    if (buffer) {
+      const FileEntry *File =
+        CI->getFileManager().getVirtualFile(buffer->getBufferIdentifier(),
+                                            buffer->getBufferSize(), 0);
+      SourceManager &SM = CI->getSourceManager();
+      SM.createMainFileID(File);
+      SM.overrideFileContents(File, buffer, true);
+    }
 
     // Set up the preprocessor
     CI->createPreprocessor();
Index: lib/Interpreter/IncrementalParser.cpp
===================================================================
--- lib/Interpreter/IncrementalParser.cpp	(revision 45565)
+++ lib/Interpreter/IncrementalParser.cpp	(working copy)
@@ -228,14 +228,15 @@
       getCodeGenerator()->Initialize(getCI()->getASTContext());
     }
 
+    // Check for errors coming from our custom consumers.
+    DiagnosticConsumer& DClient = m_CI->getDiagnosticClient();
+    DClient.BeginSourceFile(getCI()->getLangOpts(),
+                            &getCI()->getPreprocessor());
+
     beginTransaction(Opts);
     EParseResult Result = ParseInternal(input);
     endTransaction();
 
-    // Check for errors coming from our custom consumers.
-    DiagnosticConsumer& DClient = m_CI->getDiagnosticClient();
-    DClient.BeginSourceFile(getCI()->getLangOpts(),
-                            &getCI()->getPreprocessor());
     commitCurrentTransaction();
 
     DClient.EndSourceFile();
@@ -295,15 +296,18 @@
     m_MemoryBuffers.push_back(MB);
     SourceManager& SM = getCI()->getSourceManager();
 
+    const FileEntry *File =
+      getCI()->getFileManager().getVirtualFile(MB->getBufferIdentifier(),
+                                               MB->getBufferSize(), 0);
+    SM.overrideFileContents(File, MB, true);
+
     // Create SourceLocation, which will allow clang to order the overload
     // candidates for example
     SourceLocation NewLoc = SM.getLocForStartOfFile(m_VirtualFileID);
     NewLoc = NewLoc.getLocWithOffset(m_MemoryBuffers.size() + 1);
 
     // Create FileID for the current buffer
-    FileID FID = SM.createFileIDForMemBuffer(m_MemoryBuffers.back(),
-                                             /*LoadedID*/0,
-                                             /*LoadedOffset*/0, NewLoc);
+    FileID FID = SM.createFileID(File, NewLoc, SrcMgr::C_User);
 
     PP.EnterSourceFile(FID, 0, NewLoc);
 
