[PATCH] D135367: [clang-tidy] Dump effective diagnostics level in YAML output
Dmitry Polukhin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 6 08:02:03 PDT 2022
DmitryPolukhin created this revision.
DmitryPolukhin added reviewers: njames93, klimek.
DmitryPolukhin added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
DmitryPolukhin requested review of this revision.
Herald added a subscriber: cfe-commits.
Before this patch YAML output had default diagnostic level instead of effective level reported to the user on stdout. Wrapper scripts for clang-tidy usually use YAML output and they pick wrong diagnostics level without this patch.
Test Plan: check-clang-tools
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135367
Files:
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
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,5 +1,5 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
-// RUN: not clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes,clang-diagnostic-zero-length-array' -export-fixes=%t.yaml -- -Wmissing-prototypes -Wzero-length-array > %t.msg 2>&1
+// RUN: not clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes,clang-diagnostic-zero-length-array' --warnings-as-errors='clang-diagnostic-missing-prototypes' -export-fixes=%t.yaml -- -Wmissing-prototypes -Wzero-length-array > %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() {}
@@ -12,7 +12,7 @@
member;
};
-// CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes]
+// CHECK-MESSAGES: -input.cpp:2:1: error: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes,-warnings-as-errors]
// 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
@@ -52,7 +52,7 @@
// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
// CHECK-YAML-NEXT: FileOffset: 13
// CHECK-YAML-NEXT: Replacements: []
-// CHECK-YAML-NEXT: Level: Warning
+// CHECK-YAML-NEXT: Level: Error
// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error
// CHECK-YAML-NEXT: DiagnosticMessage:
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -403,6 +403,8 @@
bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
Context.treatAsError(CheckName);
+ if (IsWarningAsError)
+ Level = ClangTidyError::Error;
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
IsWarningAsError);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135367.465743.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221006/434a0ac2/attachment-0001.bin>
More information about the cfe-commits
mailing list