Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -374,7 +374,14 @@ // The module manager holds a reference to the old preprocessor (if any). ModuleManager.reset(); - // Create the Preprocessor. + // Create the Preprocessor. If this instance is replacing the existing + // preprocessor and that existing one is going away, we have to remove + // the Module* pointers it owns from KnownModules since they will be + // dangling. FIXME: Should this only remove pointers owned by the + // preprocessor that is going away or clear the entire map (or can + // the map even own any other Module* pointers)? + if (PP.unique()) + KnownModules.clear(); HeaderSearch *HeaderInfo = new HeaderSearch(getHeaderSearchOptsPtr(), getSourceManager(), getDiagnostics(), getLangOpts(), &getTarget());