clang/Modules: Delay err_module_file_conflict if a diagnostic is in flight

As part of an audit of whether all errors are being reported from the
ASTReader, delay err_module_file_conflict if a diagnostic is already in
flight when it is hit.  This required plumbing an extra argument through
the delayed diagnostic mechanics in DiagnosticsEngine.
This commit is contained in:
Duncan P. N. Exon Smith 2019-11-10 11:17:42 -08:00
parent 0cf86da174
commit eef6902160
4 changed files with 19 additions and 14 deletions

View File

@ -473,6 +473,9 @@ private:
/// Second string argument for the delayed diagnostic.
std::string DelayedDiagArg2;
/// Third string argument for the delayed diagnostic.
std::string DelayedDiagArg3;
/// Optional flag value.
///
/// Some flags accept values, for instance: -Wframe-larger-than=<value> and
@ -874,8 +877,12 @@ public:
/// \param Arg2 A string argument that will be provided to the
/// diagnostic. A copy of this string will be stored in the
/// DiagnosticsEngine object itself.
///
/// \param Arg3 A string argument that will be provided to the
/// diagnostic. A copy of this string will be stored in the
/// DiagnosticsEngine object itself.
void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "",
StringRef Arg2 = "");
StringRef Arg2 = "", StringRef Arg3 = "");
/// Clear out the current diagnostic.
void Clear() { CurDiagID = std::numeric_limits<unsigned>::max(); }

View File

@ -1440,7 +1440,7 @@ private:
/// do with non-routine failures (e.g., corrupted AST file).
void Error(StringRef Msg) const;
void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
StringRef Arg2 = StringRef()) const;
StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
unsigned Select) const;
void Error(llvm::Error &&Err) const;

View File

@ -145,19 +145,20 @@ void DiagnosticsEngine::Reset() {
}
void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,
StringRef Arg2) {
StringRef Arg2, StringRef Arg3) {
if (DelayedDiagID)
return;
DelayedDiagID = DiagID;
DelayedDiagArg1 = Arg1.str();
DelayedDiagArg2 = Arg2.str();
DelayedDiagArg3 = Arg3.str();
}
void DiagnosticsEngine::ReportDelayed() {
unsigned ID = DelayedDiagID;
DelayedDiagID = 0;
Report(ID) << DelayedDiagArg1 << DelayedDiagArg2;
Report(ID) << DelayedDiagArg1 << DelayedDiagArg2 << DelayedDiagArg3;
}
void DiagnosticsEngine::DiagStateMap::appendFirst(DiagState *State) {

View File

@ -1239,12 +1239,12 @@ void ASTReader::Error(StringRef Msg) const {
}
}
void ASTReader::Error(unsigned DiagID,
StringRef Arg1, StringRef Arg2) const {
void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
StringRef Arg3) const {
if (Diags.isDiagnosticInFlight())
Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2);
Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2, Arg3);
else
Diag(DiagID) << Arg1 << Arg2;
Diag(DiagID) << Arg1 << Arg2 << Arg3;
}
void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
@ -5472,12 +5472,9 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
// Don't emit module relocation error if we have -fno-validate-pch
if (!PP.getPreprocessorOpts().DisablePCHValidation &&
CurFile != F.File) {
if (!Diags.isDiagnosticInFlight()) {
Diag(diag::err_module_file_conflict)
<< CurrentModule->getTopLevelModuleName()
<< CurFile->getName()
<< F.File->getName();
}
Error(diag::err_module_file_conflict,
CurrentModule->getTopLevelModuleName(), CurFile->getName(),
F.File->getName());
return Failure;
}
}