aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/TextDiagnosticPrinter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-05-04 21:13:21 +0000
committerChris Lattner <sabre@nondot.org>2010-05-04 21:13:21 +0000
commitc9b889044c8e1e2d6ab194e34e8b74f6998094fa (patch)
treec762cf1573b3a81683ebe2ea6dc475e485402c9f /lib/Frontend/TextDiagnosticPrinter.cpp
parentfe67f3bfc09caa66ab1398c03418c35bea77caf4 (diff)
When -fdiagnostics-print-source-range-info is specified,
print the diagnostic category number in the [] at the end of the line. For example: $ cat t.c #include <stdio.h> void foo() { printf("%s", 4); } $ clang t.c -fsyntax-only -fdiagnostics-print-source-range-info t.c:3:11:{3:10-3:12}{3:15-3:16}: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,1] printf("%s", 4); ~^ ~ 1 warning generated. Clients that want category information can now pick the number out of the output, rdar://7928231. More coming. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103053 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index 66ed956a22..46bdd75a0e 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
#include <algorithm>
using namespace clang;
@@ -819,21 +820,45 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
llvm::SmallString<100> OutStr;
Info.FormatDiagnostic(OutStr);
+ std::string OptionName;
if (DiagOpts->ShowOptionNames) {
if (const char *Opt = Diagnostic::getWarningOptionForDiag(Info.getID())) {
- OutStr += " [-W";
- OutStr += Opt;
- OutStr += ']';
+ OptionName = "-W";
+ OptionName += Opt;
} else {
// If the diagnostic is an extension diagnostic and not enabled by default
// then it must have been turned on with -pedantic.
bool EnabledByDefault;
if (Diagnostic::isBuiltinExtensionDiag(Info.getID(), EnabledByDefault) &&
!EnabledByDefault)
- OutStr += " [-pedantic]";
+ OptionName = "-pedantic";
}
}
+
+ // If the user wants to see category information, include it too.
+ unsigned DiagCategory = 0;
+ if (DiagOpts->ShowSourceRanges)
+ DiagCategory = Diagnostic::getCategoryNumberForDiag(Info.getID());
+
+ // If there is any categorization information, include it.
+ if (!OptionName.empty() || DiagCategory != 0) {
+ bool NeedsComma = false;
+ OutStr += " [";
+
+ if (!OptionName.empty()) {
+ OutStr += OptionName;
+ NeedsComma = true;
+ }
+
+ if (DiagCategory) {
+ if (NeedsComma) OutStr += ',';
+ OutStr += llvm::utostr(DiagCategory);
+ }
+
+ OutStr += "]";
+ }
+
if (DiagOpts->ShowColors) {
// Print warnings, errors and fatal errors in bold, no color
switch (Level) {