Teach TextDiagnosticPrinter to print out '-Werror' in addition to the warning flag for a warning mapped to an error.

For example:

t.c:7:9: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]

llvm-svn: 126466
This commit is contained in:
Ted Kremenek 2011-02-25 01:28:26 +00:00
parent 4c82cd21ed
commit b6f9ab6378
5 changed files with 32 additions and 8 deletions

View File

@ -474,8 +474,9 @@ public:
///
/// \param Loc The source location we are interested in finding out the
/// diagnostic state. Can be null in order to query the latest state.
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const {
return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this);
Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
diag::Mapping *mapping = 0) const {
return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this, mapping);
}
/// Report - Issue the message to the client. @c DiagID is a member of the

View File

@ -188,14 +188,16 @@ private:
/// \param Loc The source location we are interested in finding out the
/// diagnostic state. Can be null in order to query the latest state.
DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
const Diagnostic &Diag) const;
const Diagnostic &Diag,
diag::Mapping *mapping = 0) const;
/// getDiagnosticLevel - This is an internal implementation helper used when
/// DiagClass is already known.
DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID,
unsigned DiagClass,
SourceLocation Loc,
const Diagnostic &Diag) const;
const Diagnostic &Diag,
diag::Mapping *mapping = 0) const;
/// ProcessDiag - This is the method used to report a diagnostic that is
/// finally fully formed.

View File

@ -288,14 +288,15 @@ const char *DiagnosticIDs::getDescription(unsigned DiagID) const {
/// the DiagnosticClient.
DiagnosticIDs::Level
DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
const Diagnostic &Diag) const {
const Diagnostic &Diag,
diag::Mapping *mapping) const {
// Handle custom diagnostics, which cannot be mapped.
if (DiagID >= diag::DIAG_UPPER_LIMIT)
return CustomDiagInfo->getLevel(DiagID);
unsigned DiagClass = getBuiltinDiagClass(DiagID);
assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag);
return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag, mapping);
}
/// \brief Based on the way the client configured the Diagnostic
@ -307,7 +308,8 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
DiagnosticIDs::Level
DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
SourceLocation Loc,
const Diagnostic &Diag) const {
const Diagnostic &Diag,
diag::Mapping *mapping) const {
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error. Errors can only be mapped to fatal.
DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
@ -324,6 +326,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
Diag.setDiagnosticMappingInternal(DiagID, MappingInfo, State, false, false);
}
if (mapping)
*mapping = (diag::Mapping) (MappingInfo & 7);
switch (MappingInfo & 7) {
default: assert(0 && "Unknown mapping!");
case diag::MAP_IGNORE:

View File

@ -905,9 +905,21 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
std::string OptionName;
if (DiagOpts->ShowOptionNames) {
// Was this a warning mapped to an error using -Werror or pragma?
if (Level == Diagnostic::Error &&
DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
diag::Mapping mapping = diag::MAP_IGNORE;
Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(),
&mapping);
if (mapping == diag::MAP_WARNING)
OptionName += "-Werror";
}
if (const char *
Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID())) {
OptionName = "-W";
if (!OptionName.empty())
OptionName += ',';
OptionName += "-W";
OptionName += Opt;
} else if (Info.getID() == diag::fatal_too_many_errors) {
OptionName = "-ferror-limit=";

View File

@ -37,3 +37,7 @@ void bitwise_rel(unsigned i) {
(void)(i && i || 0); // no warning.
(void)(0 || i && i); // no warning.
}
// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s
// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]