@@ -856,10 +856,12 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
856
856
std::make_shared<clang::CompilerInvocation>(*Impl.Invocation );
857
857
invocation->getPreprocessorOpts ().DisablePCHOrModuleValidation =
858
858
clang::DisableValidationForModuleKind::None;
859
- invocation->getPreprocessorOpts ().AllowPCHWithCompilerErrors = false ;
860
859
invocation->getHeaderSearchOpts ().ModulesValidateSystemHeaders = true ;
861
860
invocation->getLangOpts ()->NeededByPCHOrCompilationUsesPCH = true ;
862
861
invocation->getLangOpts ()->CacheGeneratedPCH = true ;
862
+ // If the underlying invocation is allowing PCH errors, then it "can be read",
863
+ // even if it has its error bit set. Thus, don't override
864
+ // `AllowPCHWithCompilerErrors`.
863
865
864
866
// ClangImporter::create adds a remapped MemoryBuffer that we don't need
865
867
// here. Moreover, it's a raw pointer owned by the preprocessor options; if
@@ -1365,7 +1367,8 @@ bool ClangImporter::Implementation::importHeader(
1365
1367
// Don't even try to load the bridging header if the Clang AST is in a bad
1366
1368
// state. It could cause a crash.
1367
1369
auto &clangDiags = getClangASTContext ().getDiagnostics ();
1368
- if (clangDiags.hasUnrecoverableErrorOccurred ())
1370
+ if (clangDiags.hasUnrecoverableErrorOccurred () &&
1371
+ !getClangInstance ()->getPreprocessorOpts ().AllowPCHWithCompilerErrors )
1369
1372
return true ;
1370
1373
1371
1374
assert (adapter);
@@ -1465,7 +1468,8 @@ bool ClangImporter::Implementation::importHeader(
1465
1468
getBufferImporterForDiagnostics ());
1466
1469
1467
1470
// FIXME: What do we do if there was already an error?
1468
- if (!hadError && clangDiags.hasErrorOccurred ()) {
1471
+ if (!hadError && clangDiags.hasErrorOccurred () &&
1472
+ !getClangInstance ()->getPreprocessorOpts ().AllowPCHWithCompilerErrors ) {
1469
1473
diagnose (diagLoc, diag::bridging_header_error, headerName);
1470
1474
return true ;
1471
1475
}
@@ -1668,7 +1672,8 @@ ClangImporter::emitBridgingPCH(StringRef headerPath,
1668
1672
FrontendOpts, std::make_unique<clang::GeneratePCHAction>());
1669
1673
emitInstance->ExecuteAction (*action);
1670
1674
1671
- if (emitInstance->getDiagnostics ().hasErrorOccurred ()) {
1675
+ if (emitInstance->getDiagnostics ().hasErrorOccurred () &&
1676
+ !emitInstance->getPreprocessorOpts ().AllowPCHWithCompilerErrors ) {
1672
1677
Impl.diagnose ({}, diag::bridging_header_pch_error,
1673
1678
outputPCHPath, headerPath);
1674
1679
return true ;
@@ -1728,7 +1733,8 @@ bool ClangImporter::emitPrecompiledModule(StringRef moduleMapPath,
1728
1733
std::make_unique<clang::GenerateModuleFromModuleMapAction>());
1729
1734
emitInstance->ExecuteAction (*action);
1730
1735
1731
- if (emitInstance->getDiagnostics ().hasErrorOccurred ()) {
1736
+ if (emitInstance->getDiagnostics ().hasErrorOccurred () &&
1737
+ !FrontendOpts.AllowPCMWithCompilerErrors ) {
1732
1738
Impl.diagnose ({}, diag::emit_pcm_error, outputPath, moduleMapPath);
1733
1739
return true ;
1734
1740
}
0 commit comments