Serialization: Hoist the check for in-flight diagnostics in ASTReader::getInputFile, NFC

This logic seems easier to follow without the `Error()` helper, and
checking `DiagnosticsEngine::isDiagnosticInFlight` just once up front.

Differential Revision: https://reviews.llvm.org/D91366
This commit is contained in:
Duncan P. N. Exon Smith 2020-11-12 13:05:07 -05:00
parent 9a8bfe3835
commit d87fd096ac
2 changed files with 9 additions and 18 deletions

View File

@ -1450,8 +1450,6 @@ private:
void Error(StringRef Msg) const;
void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
unsigned Select) const;
void Error(llvm::Error &&Err) const;
public:

View File

@ -1246,12 +1246,6 @@ void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
Diag(DiagID) << Arg1 << Arg2 << Arg3;
}
void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
unsigned Select) const {
if (!Diags.isDiagnosticInFlight())
Diag(DiagID) << Arg1 << Arg2 << Select;
}
void ASTReader::Error(llvm::Error &&Err) const {
Error(toString(std::move(Err)));
}
@ -2395,7 +2389,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
auto FileChange = HasInputFileChanged();
// For an overridden file, there is nothing to validate.
if (!Overridden && FileChange != ModificationType::None) {
if (Complain) {
if (Complain && !Diags.isDiagnosticInFlight()) {
// Build a list of the PCH imports that got us here (in reverse).
SmallVector<ModuleFile *, 4> ImportStack(1, &F);
while (!ImportStack.back()->ImportedBy.empty())
@ -2406,17 +2400,17 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
unsigned DiagnosticKind =
moduleKindForDiagnostic(ImportStack.back()->Kind);
if (DiagnosticKind == 0)
Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName,
(unsigned)FileChange);
Diag(diag::err_fe_pch_file_modified)
<< Filename << TopLevelPCHName << FileChange;
else if (DiagnosticKind == 1)
Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName,
(unsigned)FileChange);
Diag(diag::err_fe_module_file_modified)
<< Filename << TopLevelPCHName << FileChange;
else
Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName,
(unsigned)FileChange);
Diag(diag::err_fe_ast_file_modified)
<< Filename << TopLevelPCHName << FileChange;
// Print the import stack.
if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
if (ImportStack.size() > 1) {
Diag(diag::note_pch_required_by)
<< Filename << ImportStack[0]->FileName;
for (unsigned I = 1; I < ImportStack.size(); ++I)
@ -2424,8 +2418,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
<< ImportStack[I-1]->FileName << ImportStack[I]->FileName;
}
if (!Diags.isDiagnosticInFlight())
Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
}
IsOutOfDate = true;