[PATCH] Adding ID and Warning Option to Diagnostic Log

Steven Wu stevenwu at apple.com
Wed Oct 15 18:08:00 PDT 2014


Hi

This patch adds two more fields to diagnostic log (not serialize-diagnostic). The two new fields are DiagnosticID and Warning Option. I find them very handy in detecting and categorizing diagnostics.
The added fields are in a dict type in a plist so it is unlikely to break any existing tools that read diagnostic logs. 

Steven

--
 include/clang/Frontend/LogDiagnosticPrinter.h |  3 +++
 lib/Frontend/LogDiagnosticPrinter.cpp         | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/clang/Frontend/LogDiagnosticPrinter.h b/include/clang/Frontend/LogDiagnosticPrinter.h
index 8d60e9b..98adf65 100644
--- a/include/clang/Frontend/LogDiagnosticPrinter.h
+++ b/include/clang/Frontend/LogDiagnosticPrinter.h
@@ -35,6 +35,9 @@ class LogDiagnosticPrinter : public DiagnosticConsumer {
   
     /// The ID of the diagnostic.
     unsigned DiagnosticID;
+
+    /// The Option Flag for the diagnostic
+    std::string WarningOption;
   
     /// The level of the diagnostic.
     DiagnosticsEngine::Level DiagnosticLevel;
diff --git a/lib/Frontend/LogDiagnosticPrinter.cpp b/lib/Frontend/LogDiagnosticPrinter.cpp
index c2dcd1b..19a4660 100644
--- a/lib/Frontend/LogDiagnosticPrinter.cpp
+++ b/lib/Frontend/LogDiagnosticPrinter.cpp
@@ -63,6 +63,14 @@ LogDiagnosticPrinter::EmitDiagEntry(llvm::raw_ostream &OS,
        << "      ";
     EmitString(OS, DE.Message) << '\n';
   }
+  OS << "      <key>ID</key>\n"
+     << "      ";
+  EmitInteger(OS, DE.DiagnosticID) << '\n';
+  if (!DE.WarningOption.empty()) {
+    OS << "      <key>WarningOption</key>\n"
+       << "      ";
+    EmitString(OS, DE.WarningOption) << '\n';
+  }
   OS << "    </dict>\n";
 }
 
@@ -122,6 +130,12 @@ void LogDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
   DE.DiagnosticID = Info.getID();
   DE.DiagnosticLevel = Level;
 
+  DE.WarningOption = "";
+  StringRef WarningOption = DiagnosticIDs::getWarningOptionForDiag(DE.DiagnosticID);
+  if (!WarningOption.empty()) {
+    DE.WarningOption = WarningOption.str();
+  }
+
   // Format the message.
   SmallString<100> MessageStr;
   Info.FormatDiagnostic(MessageStr);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Diaglog.patch
Type: application/octet-stream
Size: 1645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141015/58321a1b/attachment.obj>


More information about the cfe-commits mailing list