@@ -1153,7 +1153,8 @@ static Language getLanguageFromOptions(const LangOptions &LangOpts) {
11531153std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl (
11541154 SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input,
11551155 StringRef OriginalModuleMapFile, StringRef ModuleFileName,
1156- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
1156+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1157+ DiagnosticConsumer *DiagConsumer) {
11571158 // Construct a compiler invocation for creating this module.
11581159 auto Invocation = std::make_shared<CompilerInvocation>(getInvocation ());
11591160
@@ -1221,10 +1222,15 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12211222 Instance.createFileManager (&getVirtualFileSystem ());
12221223 }
12231224
1224- Instance.createDiagnostics (
1225- Instance.getVirtualFileSystem (),
1226- new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1227- /* ShouldOwnClient=*/ true );
1225+ if (DiagConsumer) {
1226+ Instance.createDiagnostics (Instance.getVirtualFileSystem (), DiagConsumer,
1227+ /* ShouldOwnClient=*/ false );
1228+ } else {
1229+ Instance.createDiagnostics (
1230+ Instance.getVirtualFileSystem (),
1231+ new ForwardingDiagnosticConsumer (getDiagnosticClient ()),
1232+ /* ShouldOwnClient=*/ true );
1233+ }
12281234 if (llvm::is_contained (DiagOpts.SystemHeaderWarningsModules , ModuleName))
12291235 Instance.getDiagnostics ().setSuppressSystemWarnings (false );
12301236
@@ -1322,7 +1328,8 @@ static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
13221328
13231329std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile (
13241330 SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName,
1325- IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
1331+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
1332+ DiagnosticConsumer *DiagConsumer) {
13261333 StringRef ModuleName = Module->getTopLevelModuleName ();
13271334
13281335 InputKind IK (getLanguageFromOptions (getLangOpts ()), InputKind::ModuleMap);
@@ -1368,7 +1375,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13681375 ImportLoc, ModuleName,
13691376 FrontendInputFile (ModuleMapFilePath, IK, IsSystem),
13701377 ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName,
1371- std::move (VFS));
1378+ std::move (VFS), DiagConsumer );
13721379 }
13731380
13741381 // FIXME: We only need to fake up an input file here as a way of
@@ -1386,7 +1393,7 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
13861393 ImportLoc, ModuleName,
13871394 FrontendInputFile (FakeModuleMapFile, IK, +Module->IsSystem ),
13881395 ModMap.getModuleMapFileForUniquing (Module)->getName (), ModuleFileName,
1389- std::move (VFS));
1396+ std::move (VFS), DiagConsumer );
13901397
13911398 std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =
13921399 llvm::MemoryBuffer::getMemBufferCopy (InferredModuleMapContent);
0 commit comments