[clang-tools-extra] 7f2f024 - Remark was added to clang tooling Diagnostic
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon May 24 08:22:52 PDT 2021
Author: Ivan Murashko
Date: 2021-05-24T11:21:44-04:00
New Revision: 7f2f0247f855b143c12cd33d1f53d14bc63f3e82
URL: https://github.com/llvm/llvm-project/commit/7f2f0247f855b143c12cd33d1f53d14bc63f3e82
DIFF: https://github.com/llvm/llvm-project/commit/7f2f0247f855b143c12cd33d1f53d14bc63f3e82.diff
LOG: Remark was added to clang tooling Diagnostic
The diff adds Remark to Diagnostic::Level for clang tooling. That makes
Remark diagnostic level ready to use in clang-tidy checks: the
clang-diagnostic-module-import becomes visible as a part of the change.
Added:
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/A.h
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/module.modulemap
clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
Modified:
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang/include/clang/Tooling/Core/Diagnostic.h
clang/include/clang/Tooling/DiagnosticsYaml.h
clang/unittests/Tooling/DiagnosticsYamlTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 08d5c0d6704ba..1457f145f552c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -446,6 +446,9 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
case DiagnosticsEngine::Warning:
CheckName = "clang-diagnostic-warning";
break;
+ case DiagnosticsEngine::Remark:
+ CheckName = "clang-diagnostic-remark";
+ break;
default:
CheckName = "clang-diagnostic-unknown";
break;
@@ -460,7 +463,10 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
Level = ClangTidyError::Error;
LastErrorRelatesToUserCode = true;
LastErrorPassesLineFilter = true;
+ } else if (DiagLevel == DiagnosticsEngine::Remark) {
+ Level = ClangTidyError::Remark;
}
+
bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
Context.treatAsError(CheckName);
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/A.h b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/A.h
new file mode 100644
index 0000000000000..b7c2ac02d8d2f
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/A.h
@@ -0,0 +1 @@
+// A
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/module.modulemap b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/module.modulemap
new file mode 100644
index 0000000000000..37a855090ec8a
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/remarks/module.modulemap
@@ -0,0 +1 @@
+module A { header "A.h" }
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
new file mode 100644
index 0000000000000..0e9fb46e3e1cb
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: cp -r %S/Inputs/remarks %t
+// RUN: cp %s %t/t.cpp
+
+// RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-module-import' t.cpp -- \
+// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN: -fsyntax-only \
+// RUN: -I%S/Inputs/remarks \
+// RUN: -working-directory=%t \
+// RUN: -Rmodule-build -Rmodule-import t.cpp 2>&1 |\
+// RUN: FileCheck %s -implicit-check-not "remark:"
+
+#include "A.h"
+// CHECK: remark: importing module 'A' from {{.*}} [clang-diagnostic-module-import]
+
diff --git a/clang/include/clang/Tooling/Core/Diagnostic.h b/clang/include/clang/Tooling/Core/Diagnostic.h
index f68e0a682cd21..4553380bcf00e 100644
--- a/clang/include/clang/Tooling/Core/Diagnostic.h
+++ b/clang/include/clang/Tooling/Core/Diagnostic.h
@@ -67,6 +67,7 @@ struct DiagnosticMessage {
/// fixes to be applied.
struct Diagnostic {
enum Level {
+ Remark = DiagnosticsEngine::Remark,
Warning = DiagnosticsEngine::Warning,
Error = DiagnosticsEngine::Error
};
diff --git a/clang/include/clang/Tooling/DiagnosticsYaml.h b/clang/include/clang/Tooling/DiagnosticsYaml.h
index 31bc2989b883e..3f257d84f8136 100644
--- a/clang/include/clang/Tooling/DiagnosticsYaml.h
+++ b/clang/include/clang/Tooling/DiagnosticsYaml.h
@@ -106,6 +106,7 @@ 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);
+ IO.enumCase(Value, "Remark", clang::tooling::Diagnostic::Remark);
}
};
diff --git a/clang/unittests/Tooling/DiagnosticsYamlTest.cpp b/clang/unittests/Tooling/DiagnosticsYamlTest.cpp
index 0686b22691251..6d3b4b9939f0d 100644
--- a/clang/unittests/Tooling/DiagnosticsYamlTest.cpp
+++ b/clang/unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -47,10 +47,11 @@ static Diagnostic makeDiagnostic(StringRef DiagnosticName,
const std::string &Message, int FileOffset,
const std::string &FilePath,
const StringMap<Replacements> &Fix,
- const SmallVector<FileByteRange, 1> &Ranges) {
+ const SmallVector<FileByteRange, 1> &Ranges,
+ Diagnostic::Level DiagnosticLevel) {
return Diagnostic(DiagnosticName,
makeMessage(Message, FileOffset, FilePath, Fix, Ranges), {},
- Diagnostic::Warning, "path/to/build/directory");
+ DiagnosticLevel, "path/to/build/directory");
}
static const char *YAMLContent =
@@ -102,6 +103,14 @@ static const char *YAMLContent =
" Replacements: []\n"
" Level: Warning\n"
" BuildDirectory: 'path/to/build/directory'\n"
+ " - DiagnosticName: 'diagnostic#4'\n"
+ " DiagnosticMessage:\n"
+ " Message: 'message #4'\n"
+ " FilePath: 'path/to/source3.cpp'\n"
+ " FileOffset: 72\n"
+ " Replacements: []\n"
+ " Level: Remark\n"
+ " BuildDirectory: 'path/to/build/directory'\n"
"...\n";
TEST(DiagnosticsYamlTest, serializesDiagnostics) {
@@ -112,7 +121,8 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
{"path/to/source.cpp",
Replacements({"path/to/source.cpp", 100, 12, "replacement #1"})}};
TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55,
- "path/to/source.cpp", Fix1, {}));
+ "path/to/source.cpp", Fix1, {},
+ Diagnostic::Warning));
StringMap<Replacements> Fix2 = {
{"path/to/header.h",
@@ -120,15 +130,21 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
SmallVector<FileByteRange, 1> Ranges2 =
{makeByteRange(10, 10, "path/to/source.cpp")};
TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#2", "message #2", 60,
- "path/to/header.h", Fix2, Ranges2));
+ "path/to/header.h", Fix2, Ranges2,
+ Diagnostic::Warning));
TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72,
- "path/to/source2.cpp", {}, {}));
+ "path/to/source2.cpp", {}, {},
+ Diagnostic::Warning));
TUD.Diagnostics.back().Notes.push_back(
makeMessage("Note1", 88, "path/to/note1.cpp", {}, {}));
TUD.Diagnostics.back().Notes.push_back(
makeMessage("Note2", 99, "path/to/note2.cpp", {}, {}));
+ TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#4", "message #4", 72,
+ "path/to/source3.cpp", {}, {},
+ Diagnostic::Remark));
+
std::string YamlContent;
raw_string_ostream YamlContentStream(YamlContent);
@@ -144,7 +160,7 @@ TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
YAML >> TUDActual;
ASSERT_FALSE(YAML.error());
- ASSERT_EQ(3u, TUDActual.Diagnostics.size());
+ ASSERT_EQ(4u, TUDActual.Diagnostics.size());
EXPECT_EQ("path/to/source.cpp", TUDActual.MainSourceFile);
auto getFixes = [](const StringMap<Replacements> &Fix) {
More information about the cfe-commits
mailing list