Add 'remark' diagnostic type in clang
Tobias Grosser
tobias at grosser.es
Tue Feb 25 02:20:10 PST 2014
Hi,
I would like to add the following patch. (I submitted a corresponding
patch to LLVM).
--------------
Add 'remark' diagnostic type in clang
A 'remark' is information that is not an error or a warning, but rather
some additional information provided to the user. In contrast to a
'note' a 'remark' is an independent diagnostic, whereas a 'note' always
depends on another diagnostic.
A typical use case for remark nodes is information provided to the user,
e.g. information provided by the vectorizer about loops that have been
vectorized.
--------------
A review would be highly appreciated.
Tobias
-------------- next part --------------
>From a18752f95c7768c0b7592c053fbaccaaf038a5a9 Mon Sep 17 00:00:00 2001
From: Tobias Grosser <tobias at grosser.es>
Date: Tue, 25 Feb 2014 09:37:24 +0100
Subject: [PATCH] Add 'remark' diagnostic type in 'clang'
A 'remark' is information that is not an error or a warning, but rather some
additional information provided to the user. In contrast to a 'note' a 'remark'
is an independent diagnostic, whereas a 'note' always depends on another
diagnostic.
A typical use case for remark nodes is information provided to the user, e.g.
information provided by the vectorizer about loops that have been vectorized.
---
include/clang-c/Index.h | 8 ++++++++
include/clang/Basic/Diagnostic.h | 1 +
include/clang/Basic/Diagnostic.td | 3 +++
include/clang/Basic/DiagnosticFrontendKinds.td | 3 +++
include/clang/Basic/DiagnosticIDs.h | 13 +++++++------
lib/Basic/DiagnosticIDs.cpp | 10 +++++++---
lib/CodeGen/CodeGenAction.cpp | 3 +++
lib/Frontend/LogDiagnosticPrinter.cpp | 3 ++-
lib/Frontend/PrintPreprocessedOutput.cpp | 3 +++
lib/Frontend/TextDiagnostic.cpp | 4 ++++
tools/c-index-test/c-index-test.c | 1 +
tools/diagtool/ShowEnabledWarnings.cpp | 1 +
tools/libclang/CIndexDiagnostic.cpp | 1 +
tools/libclang/CXStoredDiagnostic.cpp | 1 +
14 files changed, 45 insertions(+), 10 deletions(-)
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 9c37ac7..d6b0f79 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -653,6 +653,12 @@ enum CXDiagnosticSeverity {
CXDiagnostic_Note = 1,
/**
+ * \brief This diagnostic is a remark that provides additional information
+ * for the user.
+ */
+ CXDiagnostic_Remark = 5,
+
+ /**
* \brief This diagnostic indicates suspicious code that may not be
* wrong.
*/
@@ -669,6 +675,8 @@ enum CXDiagnosticSeverity {
* results.
*/
CXDiagnostic_Fatal = 4
+
+
};
/**
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 6782964..d83c4c0 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -142,6 +142,7 @@ public:
enum Level {
Ignored = DiagnosticIDs::Ignored,
Note = DiagnosticIDs::Note,
+ Remark = DiagnosticIDs::Remark,
Warning = DiagnosticIDs::Warning,
Error = DiagnosticIDs::Error,
Fatal = DiagnosticIDs::Fatal
diff --git a/include/clang/Basic/Diagnostic.td b/include/clang/Basic/Diagnostic.td
index 2616548..01cc0d1 100644
--- a/include/clang/Basic/Diagnostic.td
+++ b/include/clang/Basic/Diagnostic.td
@@ -15,6 +15,7 @@
// Define the diagnostic mappings.
class DiagMapping;
def MAP_IGNORE : DiagMapping;
+def MAP_REMARK : DiagMapping;
def MAP_WARNING : DiagMapping;
def MAP_ERROR : DiagMapping;
def MAP_FATAL : DiagMapping;
@@ -22,6 +23,7 @@ def MAP_FATAL : DiagMapping;
// Define the diagnostic classes.
class DiagClass;
def CLASS_NOTE : DiagClass;
+def CLASS_REMARK : DiagClass;
def CLASS_WARNING : DiagClass;
def CLASS_EXTENSION : DiagClass;
def CLASS_ERROR : DiagClass;
@@ -84,6 +86,7 @@ class AccessControl {
// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
class Error<string str> : Diagnostic<str, CLASS_ERROR, MAP_ERROR>, SFINAEFailure;
class Warning<string str> : Diagnostic<str, CLASS_WARNING, MAP_WARNING>;
+class Remark<string str> : Diagnostic<str, CLASS_REMARK, MAP_REMARK>;
class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>;
class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>;
class Note<string str> : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>;
diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td
index 21809ad..99cdf74 100644
--- a/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -17,6 +17,7 @@ def err_fe_error_backend : Error<"error in backend: %0">, DefaultFatal;
// Error generated by the backend.
def err_fe_inline_asm : Error<"%0">, CatInlineAsm;
def warn_fe_inline_asm : Warning<"%0">, CatInlineAsm, InGroup<BackendInlineAsm>;
+def remark_fe_inline_asm : Remark<"%0">, CatInlineAsm;
def note_fe_inline_asm : Note<"%0">, CatInlineAsm;
def note_fe_inline_asm_here : Note<"instantiated into assembly here">;
def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
@@ -25,10 +26,12 @@ def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
def warn_fe_backend_frame_larger_than: Warning<"stack size exceeded (%0) in %1">,
CatBackend, InGroup<BackendFrameLargerThan>;
def err_fe_backend_frame_larger_than: Error<"%0">, CatBackend;
+def remark_fe_backend_frame_larger_than: Remark<"%0">, CatBackend;
def note_fe_backend_frame_larger_than: Note<"%0">, CatBackend;
def warn_fe_backend_plugin: Warning<"%0">, CatBackend, InGroup<BackendPlugin>;
def err_fe_backend_plugin: Error<"%0">, CatBackend;
+def remark_fe_backend_plugin: Remark<"%0">, CatBackend;
def note_fe_backend_plugin: Note<"%0">, CatBackend;
def err_fe_invalid_code_complete_file : Error<
diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h
index 0152f25..737a3bb 100644
--- a/include/clang/Basic/DiagnosticIDs.h
+++ b/include/clang/Basic/DiagnosticIDs.h
@@ -56,16 +56,17 @@ namespace clang {
};
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
- /// to either MAP_IGNORE (nothing), MAP_WARNING (emit a warning), MAP_ERROR
- /// (emit as an error). It allows clients to map errors to
- /// MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop emitting diagnostics after this
- /// one).
+ /// to either MAP_IGNORE (nothing), MAP_WARNING (emit a warning), MAP_REMARK
+ /// (emit a remark), MAP_ERROR (emit as an error). It allows clients to map
+ /// errors to MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop emitting diagnostics
+ /// after this one).
enum Mapping {
// NOTE: 0 means "uncomputed".
MAP_IGNORE = 1, ///< Map this diagnostic to nothing, ignore it.
MAP_WARNING = 2, ///< Map this diagnostic to a warning.
MAP_ERROR = 3, ///< Map this diagnostic to an error.
- MAP_FATAL = 4 ///< Map this diagnostic to a fatal error.
+ MAP_REMARK = 4, ///< Map this diagnostic to a remark.
+ MAP_FATAL = 5 ///< Map this diagnostic to a fatal error.
};
}
@@ -113,7 +114,7 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
public:
/// \brief The level of the diagnostic, after it has been through mapping.
enum Level {
- Ignored, Note, Warning, Error, Fatal
+ Ignored, Note, Remark, Warning, Error, Fatal
};
private:
diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp
index c8cd03e..1a34da2 100644
--- a/lib/Basic/DiagnosticIDs.cpp
+++ b/lib/Basic/DiagnosticIDs.cpp
@@ -30,9 +30,10 @@ namespace {
// Diagnostic classes.
enum {
CLASS_NOTE = 0x01,
- CLASS_WARNING = 0x02,
- CLASS_EXTENSION = 0x03,
- CLASS_ERROR = 0x04
+ CLASS_REMARK = 0x02,
+ CLASS_WARNING = 0x03,
+ CLASS_EXTENSION = 0x04,
+ CLASS_ERROR = 0x05
};
struct StaticDiagInfoRec {
@@ -409,6 +410,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
case diag::MAP_IGNORE:
Result = DiagnosticIDs::Ignored;
break;
+ case diag::MAP_REMARK:
+ Result = DiagnosticIDs::Remark;
+ break;
case diag::MAP_WARNING:
Result = DiagnosticIDs::Warning;
break;
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp
index d7c03e8..ce5d0d0 100644
--- a/lib/CodeGen/CodeGenAction.cpp
+++ b/lib/CodeGen/CodeGenAction.cpp
@@ -307,6 +307,9 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
case llvm::DS_Warning: \
DiagID = diag::warn_fe_##GroupName; \
break; \
+ case llvm::DS_Remark: \
+ DiagID = diag::remark_fe_##GroupName; \
+ break; \
case llvm::DS_Note: \
DiagID = diag::note_fe_##GroupName; \
break; \
diff --git a/lib/Frontend/LogDiagnosticPrinter.cpp b/lib/Frontend/LogDiagnosticPrinter.cpp
index 2189b86..bb39929 100644
--- a/lib/Frontend/LogDiagnosticPrinter.cpp
+++ b/lib/Frontend/LogDiagnosticPrinter.cpp
@@ -31,7 +31,8 @@ LogDiagnosticPrinter::~LogDiagnosticPrinter() {
static StringRef getLevelName(DiagnosticsEngine::Level Level) {
switch (Level) {
case DiagnosticsEngine::Ignored: return "ignored";
- case DiagnosticsEngine::Note: return "note";
+ case DiagnosticsEngine::Remark: return "note";
+ case DiagnosticsEngine::Note: return "remark";
case DiagnosticsEngine::Warning: return "warning";
case DiagnosticsEngine::Error: return "error";
case DiagnosticsEngine::Fatal: return "fatal error";
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp
index 489227d..20d7cd3 100644
--- a/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -459,6 +459,9 @@ PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
MoveToLine(Loc);
OS << "#pragma " << Namespace << " diagnostic ";
switch (Map) {
+ case diag::MAP_REMARK:
+ OS << "remark";
+ break;
case diag::MAP_WARNING:
OS << "warning";
break;
diff --git a/lib/Frontend/TextDiagnostic.cpp b/lib/Frontend/TextDiagnostic.cpp
index a2dc953..17c926b 100644
--- a/lib/Frontend/TextDiagnostic.cpp
+++ b/lib/Frontend/TextDiagnostic.cpp
@@ -26,6 +26,8 @@ using namespace clang;
static const enum raw_ostream::Colors noteColor =
raw_ostream::BLACK;
+static const enum raw_ostream::Colors remarkColor =
+ raw_ostream::BLUE;
static const enum raw_ostream::Colors fixitColor =
raw_ostream::GREEN;
static const enum raw_ostream::Colors caretColor =
@@ -711,6 +713,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
case DiagnosticsEngine::Ignored:
llvm_unreachable("Invalid diagnostic type");
case DiagnosticsEngine::Note: OS.changeColor(noteColor, true); break;
+ case DiagnosticsEngine::Remark: OS.changeColor(remarkColor, true); break;
case DiagnosticsEngine::Warning: OS.changeColor(warningColor, true); break;
case DiagnosticsEngine::Error: OS.changeColor(errorColor, true); break;
case DiagnosticsEngine::Fatal: OS.changeColor(fatalColor, true); break;
@@ -721,6 +724,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
case DiagnosticsEngine::Ignored:
llvm_unreachable("Invalid diagnostic type");
case DiagnosticsEngine::Note: OS << "note"; break;
+ case DiagnosticsEngine::Remark: OS << "remark"; break;
case DiagnosticsEngine::Warning: OS << "warning"; break;
case DiagnosticsEngine::Error: OS << "error"; break;
case DiagnosticsEngine::Fatal: OS << "fatal error"; break;
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 3a47ae4..8c22366 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -3721,6 +3721,7 @@ static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) {
static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
switch (severity) {
case CXDiagnostic_Note: return "note";
+ case CXDiagnostic_Remark: return "remark";
case CXDiagnostic_Error: return "error";
case CXDiagnostic_Fatal: return "fatal";
case CXDiagnostic_Ignored: return "ignored";
diff --git a/tools/diagtool/ShowEnabledWarnings.cpp b/tools/diagtool/ShowEnabledWarnings.cpp
index bcc7520..234b18e 100644
--- a/tools/diagtool/ShowEnabledWarnings.cpp
+++ b/tools/diagtool/ShowEnabledWarnings.cpp
@@ -44,6 +44,7 @@ static char getCharForLevel(DiagnosticsEngine::Level Level) {
switch (Level) {
case DiagnosticsEngine::Ignored: return ' ';
case DiagnosticsEngine::Note: return '-';
+ case DiagnosticsEngine::Remark: return 'R';
case DiagnosticsEngine::Warning: return 'W';
case DiagnosticsEngine::Error: return 'E';
case DiagnosticsEngine::Fatal: return 'F';
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index d3450d5..a5440b4 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -305,6 +305,7 @@ CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) {
switch (Severity) {
case CXDiagnostic_Ignored: llvm_unreachable("impossible");
case CXDiagnostic_Note: Out << "note: "; break;
+ case CXDiagnostic_Remark: Out << "remark: "; break;
case CXDiagnostic_Warning: Out << "warning: "; break;
case CXDiagnostic_Error: Out << "error: "; break;
case CXDiagnostic_Fatal: Out << "fatal error: "; break;
diff --git a/tools/libclang/CXStoredDiagnostic.cpp b/tools/libclang/CXStoredDiagnostic.cpp
index 9731616..45ce39b 100644
--- a/tools/libclang/CXStoredDiagnostic.cpp
+++ b/tools/libclang/CXStoredDiagnostic.cpp
@@ -31,6 +31,7 @@ CXDiagnosticSeverity CXStoredDiagnostic::getSeverity() const {
switch (Diag.getLevel()) {
case DiagnosticsEngine::Ignored: return CXDiagnostic_Ignored;
case DiagnosticsEngine::Note: return CXDiagnostic_Note;
+ case DiagnosticsEngine::Remark: return CXDiagnostic_Remark;
case DiagnosticsEngine::Warning: return CXDiagnostic_Warning;
case DiagnosticsEngine::Error: return CXDiagnostic_Error;
case DiagnosticsEngine::Fatal: return CXDiagnostic_Fatal;
--
1.8.1.2
More information about the cfe-commits
mailing list