aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-16 05:44:38 +0000
committerChris Lattner <sabre@nondot.org>2009-04-16 05:44:38 +0000
commitd51d74a3e89c5e5fc9bfd2814996a5feab6dc932 (patch)
tree92eabb712d4f05637e4fc598b8322c5db87f0837
parent3cbc3cf55059f50ade9d47a4b222bfbe047638d2 (diff)
implement framework for -fdiagnostics-show-option, but tblgen isn't
passing down the right info yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69268 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Diagnostic.h4
-rw-r--r--include/clang/Frontend/TextDiagnosticPrinter.h7
-rw-r--r--lib/Basic/Diagnostic.cpp7
-rw-r--r--lib/Frontend/TextDiagnosticPrinter.cpp5
-rw-r--r--tools/clang-cc/Warnings.cpp1
-rw-r--r--tools/clang-cc/clang-cc.cpp6
6 files changed, 26 insertions, 4 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index b877366520..4359bf9dfd 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -302,6 +302,10 @@ public:
///
static bool isBuiltinExtensionDiag(unsigned DiagID);
+ /// getWarningOptionForDiag - Return the lowest-level warning option that
+ /// enables the specified diagnostic. If there is no -Wfoo flag that controls
+ /// the diagnostic, this returns null.
+ static const char *getWarningOptionForDiag(unsigned DiagID);
/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
/// object, classify the specified diagnostic ID into a Level, consumable by
diff --git a/include/clang/Frontend/TextDiagnosticPrinter.h b/include/clang/Frontend/TextDiagnosticPrinter.h
index f0cc4a0ca0..9341b89f56 100644
--- a/include/clang/Frontend/TextDiagnosticPrinter.h
+++ b/include/clang/Frontend/TextDiagnosticPrinter.h
@@ -37,15 +37,18 @@ class TextDiagnosticPrinter : public DiagnosticClient {
bool CaretDiagnostics;
bool ShowLocation;
bool PrintRangeInfo;
+ bool PrintDiagnosticOption;
public:
TextDiagnosticPrinter(llvm::raw_ostream &os,
bool showColumn = true,
bool caretDiagnistics = true, bool showLocation = true,
- bool printRangeInfo = true)
+ bool printRangeInfo = true,
+ bool printDiagnosticOption = true)
: OS(os), LangOpts(0),
LastCaretDiagnosticWasNote(false), ShowColumn(showColumn),
CaretDiagnostics(caretDiagnistics), ShowLocation(showLocation),
- PrintRangeInfo(printRangeInfo) {}
+ PrintRangeInfo(printRangeInfo),
+ PrintDiagnosticOption(printDiagnosticOption) {}
void SetLangOpts(const LangOptions &LO) {
LangOpts = &LO;
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 31f56e99bf..16cb111e2c 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -65,6 +65,13 @@ static unsigned GetDefaultDiagMapping(unsigned DiagID) {
return diag::MAP_FATAL;
}
+/// getWarningOptionForDiag - Return the lowest-level warning option that
+/// enables the specified diagnostic. If there is no -Wfoo flag that controls
+/// the diagnostic, this returns null.
+const char *Diagnostic::getWarningOptionForDiag(unsigned DiagID) {
+ return 0; //"Wfoo";
+}
+
// Diagnostic classes.
enum {
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp
index c472a140cb..24f66dac7f 100644
--- a/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -308,6 +308,11 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
llvm::SmallString<100> OutStr;
Info.FormatDiagnostic(OutStr);
OS.write(OutStr.begin(), OutStr.size());
+
+ if (PrintDiagnosticOption)
+ if (const char *Option = Diagnostic::getWarningOptionForDiag(Info.getID()))
+ OS << " [-" << Option << ']';
+
OS << '\n';
// If caret diagnostics are enabled and we have location, we want to
diff --git a/tools/clang-cc/Warnings.cpp b/tools/clang-cc/Warnings.cpp
index bab2ab7a14..62bf467f0d 100644
--- a/tools/clang-cc/Warnings.cpp
+++ b/tools/clang-cc/Warnings.cpp
@@ -93,7 +93,6 @@ bool clang::ProcessWarningOptions(Diagnostic &Diags) {
else
Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
- // FIXME: -fdiagnostics-show-option
// FIXME: -Wfatal-errors / -Wfatal-errors=foo
for (unsigned i = 0, e = OptWarnings.size(); i != e; ++i) {
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 345a421585..7d1ce40135 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -303,6 +303,9 @@ static llvm::cl::opt<bool>
PrintSourceRangeInfo("fprint-source-range-info",
llvm::cl::desc("Print source range spans in numeric form"));
+static llvm::cl::opt<bool>
+PrintDiagnosticOption("fdiagnostics-show-option",
+ llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
//===----------------------------------------------------------------------===//
// C++ Visualization.
@@ -2227,7 +2230,8 @@ int main(int argc, char **argv) {
!NoShowColumn,
!NoCaretDiagnostics,
!NoShowLocation,
- PrintSourceRangeInfo);
+ PrintSourceRangeInfo,
+ PrintDiagnosticOption);
} else {
// When checking diagnostics, just buffer them up.
TextDiagClient = new TextDiagnosticBuffer();