@@ -899,10 +899,12 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
899899 std::make_shared<clang::CompilerInvocation>(*Impl.Invocation );
900900 invocation->getPreprocessorOpts ().DisablePCHOrModuleValidation =
901901 clang::DisableValidationForModuleKind::None;
902- invocation->getPreprocessorOpts ().AllowPCHWithCompilerErrors = false ;
903902 invocation->getHeaderSearchOpts ().ModulesValidateSystemHeaders = true ;
904903 invocation->getLangOpts ()->NeededByPCHOrCompilationUsesPCH = true ;
905904 invocation->getLangOpts ()->CacheGeneratedPCH = true ;
905+ // If the underlying invocation is allowing PCH errors, then it "can be read",
906+ // even if it has its error bit set. Thus, don't override
907+ // `AllowPCHWithCompilerErrors`.
906908
907909 // ClangImporter::create adds a remapped MemoryBuffer that we don't need
908910 // here. Moreover, it's a raw pointer owned by the preprocessor options; if
@@ -1408,7 +1410,8 @@ bool ClangImporter::Implementation::importHeader(
14081410 // Don't even try to load the bridging header if the Clang AST is in a bad
14091411 // state. It could cause a crash.
14101412 auto &clangDiags = getClangASTContext ().getDiagnostics ();
1411- if (clangDiags.hasUnrecoverableErrorOccurred ())
1413+ if (clangDiags.hasUnrecoverableErrorOccurred () &&
1414+ !getClangInstance ()->getPreprocessorOpts ().AllowPCHWithCompilerErrors )
14121415 return true ;
14131416
14141417 assert (adapter);
@@ -1508,7 +1511,8 @@ bool ClangImporter::Implementation::importHeader(
15081511 getBufferImporterForDiagnostics ());
15091512
15101513 // FIXME: What do we do if there was already an error?
1511- if (!hadError && clangDiags.hasErrorOccurred ()) {
1514+ if (!hadError && clangDiags.hasErrorOccurred () &&
1515+ !getClangInstance ()->getPreprocessorOpts ().AllowPCHWithCompilerErrors ) {
15121516 diagnose (diagLoc, diag::bridging_header_error, headerName);
15131517 return true ;
15141518 }
@@ -1711,7 +1715,8 @@ ClangImporter::emitBridgingPCH(StringRef headerPath,
17111715 FrontendOpts, std::make_unique<clang::GeneratePCHAction>());
17121716 emitInstance->ExecuteAction (*action);
17131717
1714- if (emitInstance->getDiagnostics ().hasErrorOccurred ()) {
1718+ if (emitInstance->getDiagnostics ().hasErrorOccurred () &&
1719+ !emitInstance->getPreprocessorOpts ().AllowPCHWithCompilerErrors ) {
17151720 Impl.diagnose ({}, diag::bridging_header_pch_error,
17161721 outputPCHPath, headerPath);
17171722 return true ;
@@ -1771,7 +1776,8 @@ bool ClangImporter::emitPrecompiledModule(StringRef moduleMapPath,
17711776 std::make_unique<clang::GenerateModuleFromModuleMapAction>());
17721777 emitInstance->ExecuteAction (*action);
17731778
1774- if (emitInstance->getDiagnostics ().hasErrorOccurred ()) {
1779+ if (emitInstance->getDiagnostics ().hasErrorOccurred () &&
1780+ !FrontendOpts.AllowPCMWithCompilerErrors ) {
17751781 Impl.diagnose ({}, diag::emit_pcm_error, outputPath, moduleMapPath);
17761782 return true ;
17771783 }
0 commit comments