forked from OSchip/llvm-project
Fix PR1966 by ignoring non-error diagnostics from system headers even if they are
*mapped* onto errors. llvm-svn: 46686
This commit is contained in:
parent
15e4ad81c3
commit
3ac9699c44
|
@ -200,6 +200,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
|
||||||
void Diagnostic::Report(FullSourceLoc Pos, unsigned DiagID,
|
void Diagnostic::Report(FullSourceLoc Pos, unsigned DiagID,
|
||||||
const std::string *Strs, unsigned NumStrs,
|
const std::string *Strs, unsigned NumStrs,
|
||||||
const SourceRange *Ranges, unsigned NumRanges) {
|
const SourceRange *Ranges, unsigned NumRanges) {
|
||||||
|
|
||||||
// Figure out the diagnostic level of this message.
|
// Figure out the diagnostic level of this message.
|
||||||
Diagnostic::Level DiagLevel = getDiagnosticLevel(DiagID);
|
Diagnostic::Level DiagLevel = getDiagnosticLevel(DiagID);
|
||||||
|
|
||||||
|
@ -207,15 +208,20 @@ void Diagnostic::Report(FullSourceLoc Pos, unsigned DiagID,
|
||||||
if (DiagLevel == Diagnostic::Ignored)
|
if (DiagLevel == Diagnostic::Ignored)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// If this is not an error and we are in a system header, ignore it. We have
|
||||||
|
// to check on the original class here, because we also want to ignore
|
||||||
|
// extensions and warnings in -Werror and -pedantic-errors modes, which *map*
|
||||||
|
// warnings/extensions to errors.
|
||||||
|
if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
|
||||||
|
getBuiltinDiagClass(DiagID) != ERROR &&
|
||||||
|
Client.isInSystemHeader(Pos))
|
||||||
|
return;
|
||||||
|
|
||||||
if (DiagLevel >= Diagnostic::Error) {
|
if (DiagLevel >= Diagnostic::Error) {
|
||||||
ErrorOccurred = true;
|
ErrorOccurred = true;
|
||||||
++NumErrors;
|
++NumErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we going to ignore this diagnosic?
|
|
||||||
if (Client.IgnoreDiagnostic(DiagLevel, Pos))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Finally, report it.
|
// Finally, report it.
|
||||||
Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
|
Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
|
||||||
Strs, NumStrs, Ranges, NumRanges);
|
Strs, NumStrs, Ranges, NumRanges);
|
||||||
|
|
|
@ -39,20 +39,15 @@ std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
|
||||||
return Msg;
|
return Msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
|
bool TextDiagnostics::isInSystemHeader(FullSourceLoc Pos) const {
|
||||||
FullSourceLoc Pos) {
|
if (!Pos.isValid()) return false;
|
||||||
if (Pos.isValid()) {
|
|
||||||
// If this is a warning or note, and if it a system header, suppress the
|
|
||||||
// diagnostic.
|
|
||||||
if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
|
|
||||||
if (const FileEntry *F = Pos.getFileEntryForLoc()) {
|
if (const FileEntry *F = Pos.getFileEntryForLoc()) {
|
||||||
DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
|
DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
|
||||||
if (DirInfo == DirectoryLookup::SystemHeaderDir ||
|
if (DirInfo == DirectoryLookup::SystemHeaderDir ||
|
||||||
DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
|
DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,7 @@ public:
|
||||||
|
|
||||||
void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
|
void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
|
||||||
|
|
||||||
virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
|
virtual bool isInSystemHeader(FullSourceLoc Pos) const;
|
||||||
FullSourceLoc Pos);
|
|
||||||
|
|
||||||
virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
|
virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
|
||||||
FullSourceLoc Pos,
|
FullSourceLoc Pos,
|
||||||
|
|
|
@ -166,10 +166,9 @@ class DiagnosticClient {
|
||||||
public:
|
public:
|
||||||
virtual ~DiagnosticClient();
|
virtual ~DiagnosticClient();
|
||||||
|
|
||||||
/// IgnoreDiagnostic - If the client wants to ignore this diagnostic, then
|
/// isInSystemHeader - If the client can tell that this is a system header,
|
||||||
/// return true.
|
/// return true.
|
||||||
virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel,
|
virtual bool isInSystemHeader(FullSourceLoc Pos) const { return false; }
|
||||||
FullSourceLoc Pos) = 0;
|
|
||||||
|
|
||||||
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
|
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
|
||||||
/// capturing it to a log as needed.
|
/// capturing it to a log as needed.
|
||||||
|
|
Loading…
Reference in New Issue