DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: alexfh, gribozavr2.
DmitryPolukhin added projects: clang-tools-extra, clang.
Herald added a subscriber: xazax.hun.

Also added BuildDirectory for completness and removed unused `Fix`.

Test Plan: check-all


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79285

Files:
  clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
  clang/include/clang/Tooling/DiagnosticsYaml.h
  clang/unittests/Tooling/DiagnosticsYamlTest.cpp

Index: clang/unittests/Tooling/DiagnosticsYamlTest.cpp
===================================================================
--- clang/unittests/Tooling/DiagnosticsYamlTest.cpp
+++ clang/unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -65,6 +65,8 @@
     "          Offset:          100\n"
     "          Length:          12\n"
     "          ReplacementText: 'replacement #1'\n"
+    "    Level:           Warning\n"
+    "    BuildDirectory:  'path/to/build/directory'\n"
     "  - DiagnosticName:  'diagnostic#2'\n"
     "    DiagnosticMessage:\n"
     "      Message:         'message #2'\n"
@@ -75,6 +77,8 @@
     "          Offset:          62\n"
     "          Length:          2\n"
     "          ReplacementText: 'replacement #2'\n"
+    "    Level:           Warning\n"
+    "    BuildDirectory:  'path/to/build/directory'\n"
     "    Ranges:\n"
     "      - FilePath:        'path/to/source.cpp'\n"
     "        FileOffset:      10\n"
@@ -94,6 +98,8 @@
     "        FilePath:        'path/to/note2.cpp'\n"
     "        FileOffset:      99\n"
     "        Replacements:    []\n"
+    "    Level:           Warning\n"
+    "    BuildDirectory:  'path/to/build/directory'\n"
     "...\n";
 
 TEST(DiagnosticsYamlTest, serializesDiagnostics) {
Index: clang/include/clang/Tooling/DiagnosticsYaml.h
===================================================================
--- clang/include/clang/Tooling/DiagnosticsYaml.h
+++ clang/include/clang/Tooling/DiagnosticsYaml.h
@@ -77,7 +77,6 @@
 
     std::string DiagnosticName;
     clang::tooling::DiagnosticMessage Message;
-    llvm::StringMap<clang::tooling::Replacements> Fix;
     SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
     clang::tooling::Diagnostic::Level DiagLevel;
     std::string BuildDirectory;
@@ -90,9 +89,9 @@
     Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
     Io.mapRequired("DiagnosticMessage", Keys->Message);
     Io.mapOptional("Notes", Keys->Notes);
+    Io.mapOptional("Level", Keys->DiagLevel);
+    Io.mapOptional("BuildDirectory", Keys->BuildDirectory);
     Io.mapOptional("Ranges", Keys->Ranges);
-
-    // FIXME: Export properly all the different fields.
   }
 };
 
@@ -104,6 +103,14 @@
     Io.mapRequired("Diagnostics", Doc.Diagnostics);
   }
 };
+
+template <> struct ScalarEnumerationTraits<clang::tooling::Diagnostic::Level> {
+  static void enumeration(IO &IO, clang::tooling::Diagnostic::Level &Value) {
+    IO.enumCase(Value, "Warning", clang::tooling::Diagnostic::Warning);
+    IO.enumCase(Value, "Error", clang::tooling::Diagnostic::Error);
+  }
+};
+
 } // end namespace yaml
 } // end namespace llvm
 
Index: clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
@@ -1,15 +1,17 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
-// RUN: clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
+// RUN: not clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
 // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s -implicit-check-not='{{warning|error|note}}:'
 // RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
 #define X(n) void n ## n() {}
 X(f)
+int a[-1];
 
 // CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes]
 // CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
 // CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
 // CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
 // CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
+// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-diagnostic-error]
 
 // CHECK-YAML: ---
 // CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
@@ -42,4 +44,18 @@
 // CHECK-YAML-NEXT:         FilePath:        '{{.*}}-input.cpp'
 // CHECK-YAML-NEXT:         FileOffset:      13
 // CHECK-YAML-NEXT:         Replacements:    []
+// CHECK-YAML-NEXT:     Level:           Warning
+// CHECK-YAML-NEXT:     BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT:     DiagnosticMessage:
+// CHECK-YAML-NEXT:       Message:         '''a'' declared as an array with a negative size'
+// CHECK-YAML-NEXT:       FilePath:        '{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:       FileOffset:      41
+// CHECK-YAML-NEXT:       Replacements:    []
+// CHECK-YAML-NEXT:     Level:           Error
+// CHECK-YAML-NEXT:     BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:     Ranges:
+// CHECK-YAML-NEXT:      - FilePath:        '{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:         FileOffset:      41
+// CHECK-YAML-NEXT:         Length:          1
 // CHECK-YAML-NEXT: ...
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D79285: [clang-tid... Dmitry Polukhin via Phabricator via cfe-commits

Reply via email to