ClangImporter: Share a module cache between CompilerInstances

Share an in-memory module cache between Clang compiler instances to
maintain a consistent view of the implicitly-generated PCMs, protecting
against filesystem races.  This cache is more robust after r355778.

Note that there are still potential races for PCHs; I'll fix that in a
follow-up.

rdar://problem/48545366
(cherry picked from commit bf0e9a70c6)
This commit is contained in:
Duncan P. N. Exon Smith
2019-03-09 10:00:00 -08:00
parent 9eed34235b
commit a42bc62397

View File

@@ -1383,7 +1383,8 @@ std::string ClangImporter::getBridgingHeaderContents(StringRef headerPath,
invocation->getPreprocessorOpts().resetNonModularOptions(); invocation->getPreprocessorOpts().resetNonModularOptions();
clang::CompilerInstance rewriteInstance( clang::CompilerInstance rewriteInstance(
Impl.Instance->getPCHContainerOperations()); Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
rewriteInstance.setInvocation(invocation); rewriteInstance.setInvocation(invocation);
rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer); rewriteInstance.createDiagnostics(new clang::IgnoringDiagConsumer);
@@ -1441,7 +1442,8 @@ ClangImporter::emitBridgingPCH(StringRef headerPath,
invocation->getLangOpts()->NeededByPCHOrCompilationUsesPCH = true; invocation->getLangOpts()->NeededByPCHOrCompilationUsesPCH = true;
clang::CompilerInstance emitInstance( clang::CompilerInstance emitInstance(
Impl.Instance->getPCHContainerOperations()); Impl.Instance->getPCHContainerOperations(),
&Impl.Instance->getModuleCache());
emitInstance.setInvocation(std::move(invocation)); emitInstance.setInvocation(std::move(invocation));
emitInstance.createDiagnostics(&Impl.Instance->getDiagnosticClient(), emitInstance.createDiagnostics(&Impl.Instance->getDiagnosticClient(),
/*ShouldOwnClient=*/false); /*ShouldOwnClient=*/false);