Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h	(revision 167370)
+++ include/clang/Frontend/ASTUnit.h	(working copy)
@@ -62,7 +62,7 @@
 
 /// \brief Utility class for loading a ASTContext from an AST file.
 ///
-class ASTUnit : public ModuleLoader {
+class ASTUnit {
 private:
   IntrusiveRefCntPtr<LangOptions>         LangOpts;
   IntrusiveRefCntPtr<DiagnosticsEngine>   Diagnostics;
@@ -829,13 +829,6 @@
   ///
   /// \returns True if an error occurred, false otherwise.
   bool serialize(raw_ostream &OS);
-  
-  virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
-                             Module::NameVisibilityKind Visibility,
-                             bool IsInclusionDirective) {
-    // ASTUnit doesn't know how to load modules (not that this matters).
-    return 0;
-  }
 };
 
 } // namespace clang
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h	(revision 167370)
+++ include/clang/Lex/Preprocessor.h	(working copy)
@@ -92,7 +92,7 @@
   SourceManager     &SourceMgr;
   ScratchBuffer     *ScratchBuf;
   HeaderSearch      &HeaderInfo;
-  ModuleLoader      &TheModuleLoader;
+  ModuleLoader      *TheModuleLoader;
 
   /// \brief External source of macros.
   ExternalPreprocessorSource *ExternalSource;
@@ -144,6 +144,9 @@
   /// Whether the preprocessor owns the header search object.
   bool OwnsHeaderSearch : 1;
 
+  /// Whether the preprocessor owns the module loader object.
+  bool OwnsModuleLoader: 1;
+
   /// DisableMacroExpansion - True if macro expansion is disabled.
   bool DisableMacroExpansion : 1;
 
@@ -400,7 +403,7 @@
                DiagnosticsEngine &diags, LangOptions &opts,
                const TargetInfo *target,
                SourceManager &SM, HeaderSearch &Headers,
-               ModuleLoader &TheModuleLoader,
+               ModuleLoader *TheModuleLoader,
                IdentifierInfoLookup *IILookup = 0,
                bool OwnsHeaderSearch = false,
                bool DelayInitialization = false,
@@ -445,7 +448,7 @@
   }
 
   /// \brief Retrieve the module loader associated with this preprocessor.
-  ModuleLoader &getModuleLoader() const { return TheModuleLoader; }
+  ModuleLoader &getModuleLoader() const { return *TheModuleLoader; }
 
   /// SetCommentRetentionState - Control whether or not the preprocessor retains
   /// comments in output.
Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp	(revision 167370)
+++ lib/Frontend/ASTUnit.cpp	(working copy)
@@ -757,7 +757,7 @@
   AST->PP = new Preprocessor(new PreprocessorOptions(),
                              AST->getDiagnostics(), AST->ASTFileLangOpts,
                              /*Target=*/0, AST->getSourceManager(), HeaderInfo, 
-                             *AST, 
+                             /*TheModuleLoader=*/0, 
                              /*IILookup=*/0,
                              /*OwnsHeaderSearch=*/false,
                              /*DelayInitialization=*/true);
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp	(revision 167370)
+++ lib/Frontend/CompilerInstance.cpp	(working copy)
@@ -248,7 +248,7 @@
                                               &getTarget());
   PP = new Preprocessor(&getPreprocessorOpts(),
                         getDiagnostics(), getLangOpts(), &getTarget(),
-                        getSourceManager(), *HeaderInfo, *this, PTHMgr,
+                        getSourceManager(), *HeaderInfo, this, PTHMgr,
                         /*OwnsHeaderSearch=*/true);
 
   // Note that this is different then passing PTHMgr to Preprocessor's ctor.
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp	(revision 167370)
+++ lib/Lex/PPDirectives.cpp	(working copy)
@@ -1484,7 +1484,7 @@
     Module::NameVisibilityKind Visibility 
       = (IncludeKind == 3)? Module::MacrosVisible : Module::AllVisible;
     Module *Imported
-      = TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility,
+      = TheModuleLoader->loadModule(IncludeTok.getLocation(), Path, Visibility,
                                    /*IsIncludeDirective=*/true);
     assert((Imported == 0 || Imported == SuggestedModule) &&
            "the imported module is different than the suggested one");
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp	(revision 167370)
+++ lib/Lex/Preprocessor.cpp	(working copy)
@@ -47,6 +47,16 @@
 #include "llvm/Support/Capacity.h"
 using namespace clang;
 
+namespace {
+  class VoidModuleLoader : public ModuleLoader {
+    virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path, 
+                               Module::NameVisibilityKind Visibility,
+                               bool IsInclusionDirective) {
+      return 0;
+    }
+  };
+}
+
 //===----------------------------------------------------------------------===//
 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }
 
@@ -55,7 +65,7 @@
 Preprocessor::Preprocessor(llvm::IntrusiveRefCntPtr<PreprocessorOptions> PPOpts,
                            DiagnosticsEngine &diags, LangOptions &opts,
                            const TargetInfo *target, SourceManager &SM,
-                           HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
+                           HeaderSearch &Headers, ModuleLoader *TheModuleLoader,
                            IdentifierInfoLookup* IILookup,
                            bool OwnsHeaders,
                            bool DelayInitialization,
@@ -68,9 +78,14 @@
     CodeCompletionFile(0), CodeCompletionOffset(0), CodeCompletionReached(0),
     SkipMainFilePreamble(0, true), CurPPLexer(0), 
     CurDirLookup(0), CurLexerKind(CLK_Lexer), Callbacks(0), Listener(0),
-    MacroArgCache(0), Record(0), MIChainHead(0), MICache(0) 
+    MacroArgCache(0), Record(0), MIChainHead(0), MICache(0),
+    OwnsModuleLoader(false)
 {
   OwnsHeaderSearch = OwnsHeaders;
+  if (TheModuleLoader == 0) {
+    TheModuleLoader = new VoidModuleLoader;
+    OwnsModuleLoader = true;
+  }
   
   ScratchBuf = new ScratchBuffer(SourceMgr);
   CounterValue = 0; // __COUNTER__ starts at 0.
@@ -168,6 +183,9 @@
     delete &HeaderInfo;
 
   delete Callbacks;
+
+  if (OwnsModuleLoader)
+    delete TheModuleLoader;
 }
 
 void Preprocessor::Initialize(const TargetInfo &Target) {
@@ -680,7 +698,7 @@
 
   // If we have a non-empty module path, load the named module.
   if (!ModuleImportPath.empty()) {
-    Module *Imported = TheModuleLoader.loadModule(ModuleImportLoc,
+    Module *Imported = TheModuleLoader->loadModule(ModuleImportLoc,
                                                   ModuleImportPath,
                                                   Module::MacrosVisible,
                                                   /*IsIncludeDirective=*/false);
Index: unittests/Basic/SourceManagerTest.cpp
===================================================================
--- unittests/Basic/SourceManagerTest.cpp	(revision 167370)
+++ unittests/Basic/SourceManagerTest.cpp	(working copy)
@@ -52,14 +52,6 @@
   IntrusiveRefCntPtr<TargetInfo> Target;
 };
 
-class VoidModuleLoader : public ModuleLoader {
-  virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
-                             Module::NameVisibilityKind Visibility,
-                             bool IsInclusionDirective) {
-    return 0;
-  }
-};
-
 TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
   const char *source =
     "#define M(x) [x]\n"
@@ -67,11 +59,10 @@
   MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
   FileID mainFileID = SourceMgr.createMainFileIDForMemBuffer(buf);
 
-  VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, FileMgr, Diags, LangOpts, 
                           &*Target);
   Preprocessor PP(new PreprocessorOptions(), Diags, LangOpts, Target.getPtr(),
-                  SourceMgr, HeaderInfo, ModLoader,
+                  SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
                   /*IILookup =*/ 0,
                   /*OwnsHeaderSearch =*/false,
                   /*DelayInitialization =*/ false);
@@ -182,11 +173,10 @@
                                                  headerBuf->getBufferSize(), 0);
   SourceMgr.overrideFileContents(headerFile, headerBuf);
 
-  VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, FileMgr, Diags, LangOpts, 
                           &*Target);
   Preprocessor PP(new PreprocessorOptions(), Diags, LangOpts, Target.getPtr(),
-                  SourceMgr, HeaderInfo, ModLoader,
+                  SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
                   /*IILookup =*/ 0,
                   /*OwnsHeaderSearch =*/false,
                   /*DelayInitialization =*/ false);
@@ -279,11 +269,10 @@
                                                  headerBuf->getBufferSize(), 0);
   SourceMgr.overrideFileContents(headerFile, headerBuf);
 
-  VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, FileMgr, Diags, LangOpts, 
                           &*Target);
   Preprocessor PP(new PreprocessorOptions(), Diags, LangOpts, Target.getPtr(),
-                  SourceMgr, HeaderInfo, ModLoader,
+                  SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
                   /*IILookup =*/ 0,
                   /*OwnsHeaderSearch =*/false,
                   /*DelayInitialization =*/ false);
Index: unittests/Lex/LexerTest.cpp
===================================================================
--- unittests/Lex/LexerTest.cpp	(revision 167370)
+++ unittests/Lex/LexerTest.cpp	(working copy)
@@ -52,14 +52,6 @@
   IntrusiveRefCntPtr<TargetInfo> Target;
 };
 
-class VoidModuleLoader : public ModuleLoader {
-  virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
-                             Module::NameVisibilityKind Visibility,
-                             bool IsInclusionDirective) {
-    return 0;
-  }
-};
-
 TEST_F(LexerTest, LexAPI) {
   const char *source =
     "#define M(x) [x]\n"
@@ -73,11 +65,10 @@
   MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
   (void)SourceMgr.createMainFileIDForMemBuffer(buf);
 
-  VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, FileMgr, Diags, LangOpts, 
                           Target.getPtr());
   Preprocessor PP(new PreprocessorOptions(), Diags, LangOpts, Target.getPtr(),
-                  SourceMgr, HeaderInfo, ModLoader,
+                  SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
                   /*IILookup =*/ 0,
                   /*OwnsHeaderSearch =*/false,
                   /*DelayInitialization =*/ false);
Index: unittests/Lex/PPCallbacksTest.cpp
===================================================================
--- unittests/Lex/PPCallbacksTest.cpp	(revision 167370)
+++ unittests/Lex/PPCallbacksTest.cpp	(working copy)
@@ -30,15 +30,6 @@
 
 namespace {
 
-// Stub out module loading.
-class VoidModuleLoader : public ModuleLoader {
-  virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
-    Module::NameVisibilityKind Visibility,
-    bool IsInclusionDirective) {
-      return 0;
-  }
-};
-
 // Stub to collect data from InclusionDirective callbacks.
 class InclusionDirectiveCallbacks : public PPCallbacks {
 public:
@@ -126,8 +117,6 @@
     MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(SourceText);
     (void)SourceMgr.createMainFileIDForMemBuffer(Buf);
 
-    VoidModuleLoader ModLoader;
-
     IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts = new HeaderSearchOptions();
     HeaderSearch HeaderInfo(HSOpts, FileMgr, Diags, LangOpts, Target.getPtr());
     AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
@@ -135,7 +124,7 @@
     IntrusiveRefCntPtr<PreprocessorOptions> PPOpts = new PreprocessorOptions();
     Preprocessor PP(PPOpts, Diags, LangOpts,
       Target.getPtr(),
-      SourceMgr, HeaderInfo, ModLoader,
+      SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
       /*IILookup =*/ 0,
       /*OwnsHeaderSearch =*/false,
       /*DelayInitialization =*/ false);
Index: unittests/Lex/PreprocessingRecordTest.cpp
===================================================================
--- unittests/Lex/PreprocessingRecordTest.cpp	(revision 167370)
+++ unittests/Lex/PreprocessingRecordTest.cpp	(working copy)
@@ -53,14 +53,6 @@
   IntrusiveRefCntPtr<TargetInfo> Target;
 };
 
-class VoidModuleLoader : public ModuleLoader {
-  virtual Module *loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
-                             Module::NameVisibilityKind Visibility,
-                             bool IsInclusionDirective) {
-    return 0;
-  }
-};
-
 TEST_F(PreprocessingRecordTest, PPRecAPI) {
   const char *source =
       "0 1\n"
@@ -84,11 +76,10 @@
   MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
   SourceMgr.createMainFileIDForMemBuffer(buf);
 
-  VoidModuleLoader ModLoader;
   HeaderSearch HeaderInfo(new HeaderSearchOptions, FileMgr, Diags, LangOpts, 
                           Target.getPtr());
   Preprocessor PP(new PreprocessorOptions(), Diags, LangOpts,Target.getPtr(),
-                  SourceMgr, HeaderInfo, ModLoader,
+                  SourceMgr, HeaderInfo, /*TheModuleLoader =*/ 0,
                   /*IILookup =*/ 0,
                   /*OwnsHeaderSearch =*/false,
                   /*DelayInitialization =*/ false);
