Skip to content

Commit 7416024

Browse files
committed
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. This patch provides the initial implementation of 'remarks'. It includes the actual definiton of the remark nodes, their printing as well as basic parameter handling. We are reusing the existing diagnostic parameters which means a remark can be enabled with normal '-Wdiagnostic-name' flags and can be upgraded to an error using '-Werror=diagnostic-name'. '-Werror' alone does not upgrade remarks. This patch is by intention minimal in terms of parameter handling. More experience and more discussions will most likely lead to further enhancements in the parameter handling. llvm-svn: 202475
1 parent e8d4c9a commit 7416024

18 files changed

+94
-21
lines changed

clang/docs/InternalsManual.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ start with ``err_``, ``warn_``, ``ext_`` to encode the severity into the name.
8787
Since the enum is referenced in the C++ code that produces the diagnostic, it
8888
is somewhat useful for it to be reasonably short.
8989

90-
The severity of the diagnostic comes from the set {``NOTE``, ``WARNING``,
90+
The severity of the diagnostic comes from the set {``NOTE``, ``REMARK``,
91+
``WARNING``,
9192
``EXTENSION``, ``EXTWARN``, ``ERROR``}. The ``ERROR`` severity is used for
9293
diagnostics indicating the program is never acceptable under any circumstances.
9394
When an error is emitted, the AST for the input code may not be fully built.
@@ -97,11 +98,13 @@ represent them in the AST, but we produce diagnostics to tell the user their
9798
code is non-portable. The difference is that the former are ignored by
9899
default, and the later warn by default. The ``WARNING`` severity is used for
99100
constructs that are valid in the currently selected source language but that
100-
are dubious in some way. The ``NOTE`` level is used to staple more information
101-
onto previous diagnostics.
101+
are dubious in some way. The ``REMARK`` severity provides generic information
102+
about the compilation that is not necessarily related to any dubious code. The
103+
``NOTE`` level is used to staple more information onto previous diagnostics.
102104

103105
These *severities* are mapped into a smaller set (the ``Diagnostic::Level``
104-
enum, {``Ignored``, ``Note``, ``Warning``, ``Error``, ``Fatal``}) of output
106+
enum, {``Ignored``, ``Note``, ``Remark``, ``Warning``, ``Error``, ``Fatal``}) of
107+
output
105108
*levels* by the diagnostics subsystem based on various configuration options.
106109
Clang internally supports a fully fine grained mapping mechanism that allows
107110
you to map almost any diagnostic to the output level that you want. The only

clang/docs/UsersManual.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ Options to Control Error and Warning Messages
112112

113113
.. option:: -w
114114

115-
Disable all warnings.
115+
Disable all diagnostics.
116116

117117
.. option:: -Weverything
118118

119-
:ref:`Enable all warnings. <diagnostics_enable_everything>`
119+
:ref:`Enable all diagnostics. <diagnostics_enable_everything>`
120120

121121
.. option:: -pedantic
122122

@@ -582,6 +582,7 @@ All diagnostics are mapped into one of these 5 classes:
582582

583583
- Ignored
584584
- Note
585+
- Remark
585586
- Warning
586587
- Error
587588
- Fatal
@@ -722,11 +723,12 @@ is treated as a system header.
722723

723724
.. _diagnostics_enable_everything:
724725

725-
Enabling All Warnings
726-
^^^^^^^^^^^^^^^^^^^^^
726+
Enabling All Diagnostics
727+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
727728

728729
In addition to the traditional ``-W`` flags, one can enable **all**
729-
warnings by passing :option:`-Weverything`. This works as expected with
730+
diagnostics by passing :option:`-Weverything`. This works as expected
731+
with
730732
:option:`-Werror`, and also includes the warnings from :option:`-pedantic`.
731733

732734
Note that when combined with :option:`-w` (which disables all warnings), that

clang/include/clang-c/Index.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ enum CXDiagnosticSeverity {
652652
*/
653653
CXDiagnostic_Note = 1,
654654

655+
/**
656+
* \brief This diagnostic is a remark that provides additional information
657+
* for the user.
658+
*/
659+
CXDiagnostic_Remark = 5,
660+
655661
/**
656662
* \brief This diagnostic indicates suspicious code that may not be
657663
* wrong.

clang/include/clang/Basic/Diagnostic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
142142
enum Level {
143143
Ignored = DiagnosticIDs::Ignored,
144144
Note = DiagnosticIDs::Note,
145+
Remark = DiagnosticIDs::Remark,
145146
Warning = DiagnosticIDs::Warning,
146147
Error = DiagnosticIDs::Error,
147148
Fatal = DiagnosticIDs::Fatal

clang/include/clang/Basic/Diagnostic.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
// Define the diagnostic mappings.
1616
class DiagMapping;
1717
def MAP_IGNORE : DiagMapping;
18+
def MAP_REMARK : DiagMapping;
1819
def MAP_WARNING : DiagMapping;
1920
def MAP_ERROR : DiagMapping;
2021
def MAP_FATAL : DiagMapping;
2122

2223
// Define the diagnostic classes.
2324
class DiagClass;
2425
def CLASS_NOTE : DiagClass;
26+
def CLASS_REMARK : DiagClass;
2527
def CLASS_WARNING : DiagClass;
2628
def CLASS_EXTENSION : DiagClass;
2729
def CLASS_ERROR : DiagClass;
@@ -84,6 +86,7 @@ class AccessControl {
8486
// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
8587
class Error<string str> : Diagnostic<str, CLASS_ERROR, MAP_ERROR>, SFINAEFailure;
8688
class Warning<string str> : Diagnostic<str, CLASS_WARNING, MAP_WARNING>;
89+
class Remark<string str> : Diagnostic<str, CLASS_REMARK, MAP_IGNORE>;
8790
class Extension<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_IGNORE>;
8891
class ExtWarn<string str> : Diagnostic<str, CLASS_EXTENSION, MAP_WARNING>;
8992
class Note<string str> : Diagnostic<str, CLASS_NOTE, MAP_FATAL/*ignored*/>;

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def note_fe_backend_frame_larger_than: Note<"%0">, CatBackend;
2929

3030
def warn_fe_backend_plugin: Warning<"%0">, CatBackend, InGroup<BackendPlugin>;
3131
def err_fe_backend_plugin: Error<"%0">, CatBackend;
32+
def remark_fe_backend_plugin: Remark<"%0">, CatBackend, InGroup<RemarkBackendPlugin>;
3233
def note_fe_backend_plugin: Note<"%0">, CatBackend;
3334

3435
def err_fe_invalid_code_complete_file : Error<

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,4 @@ def SourceUsesOpenMP : DiagGroup<"source-uses-openmp">;
637637
def BackendInlineAsm : DiagGroup<"inline-asm">;
638638
def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;
639639
def BackendPlugin : DiagGroup<"backend-plugin">;
640+
def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">;

clang/include/clang/Basic/DiagnosticIDs.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ namespace clang {
5656
};
5757

5858
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
59-
/// to either MAP_IGNORE (nothing), MAP_WARNING (emit a warning), MAP_ERROR
60-
/// (emit as an error). It allows clients to map errors to
61-
/// MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop emitting diagnostics after this
62-
/// one).
59+
/// to either MAP_IGNORE (nothing), MAP_REMARK (emit a remark), MAP_WARNING
60+
/// (emit a warning), MAP_ERROR (emit as an error). It allows clients to
61+
/// map errors to MAP_ERROR/MAP_DEFAULT or MAP_FATAL (stop emitting
62+
/// diagnostics after this one).
6363
enum Mapping {
6464
// NOTE: 0 means "uncomputed".
6565
MAP_IGNORE = 1, ///< Map this diagnostic to nothing, ignore it.
66-
MAP_WARNING = 2, ///< Map this diagnostic to a warning.
67-
MAP_ERROR = 3, ///< Map this diagnostic to an error.
68-
MAP_FATAL = 4 ///< Map this diagnostic to a fatal error.
66+
MAP_REMARK = 2, ///< Map this diagnostic to a remark.
67+
MAP_WARNING = 3, ///< Map this diagnostic to a warning.
68+
MAP_ERROR = 4, ///< Map this diagnostic to an error.
69+
MAP_FATAL = 5 ///< Map this diagnostic to a fatal error.
6970
};
7071
}
7172

@@ -113,7 +114,7 @@ class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
113114
public:
114115
/// \brief The level of the diagnostic, after it has been through mapping.
115116
enum Level {
116-
Ignored, Note, Warning, Error, Fatal
117+
Ignored, Note, Remark, Warning, Error, Fatal
117118
};
118119

119120
private:

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ namespace {
3030
// Diagnostic classes.
3131
enum {
3232
CLASS_NOTE = 0x01,
33-
CLASS_WARNING = 0x02,
34-
CLASS_EXTENSION = 0x03,
35-
CLASS_ERROR = 0x04
33+
CLASS_REMARK = 0x02,
34+
CLASS_WARNING = 0x03,
35+
CLASS_EXTENSION = 0x04,
36+
CLASS_ERROR = 0x05
3637
};
3738

3839
struct StaticDiagInfoRec {
@@ -409,6 +410,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
409410
case diag::MAP_IGNORE:
410411
Result = DiagnosticIDs::Ignored;
411412
break;
413+
case diag::MAP_REMARK:
414+
Result = DiagnosticIDs::Remark;
415+
break;
412416
case diag::MAP_WARNING:
413417
Result = DiagnosticIDs::Warning;
414418
break;
@@ -425,6 +429,11 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
425429
!MappingInfo.isUser())
426430
Result = DiagnosticIDs::Warning;
427431

432+
// Diagnostics of class REMARK are either printed as remarks or in case they
433+
// have been added to -Werror they are printed as errors.
434+
if (DiagClass == CLASS_REMARK && Result == DiagnosticIDs::Warning)
435+
Result = DiagnosticIDs::Remark;
436+
428437
// Ignore -pedantic diagnostics inside __extension__ blocks.
429438
// (The diagnostics controlled by -pedantic are the extension diagnostics
430439
// that are not enabled by default.)

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,27 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
307307
case llvm::DS_Warning: \
308308
DiagID = diag::warn_fe_##GroupName; \
309309
break; \
310+
case llvm::DS_Remark: \
311+
llvm_unreachable("'remark' severity not expected"); \
312+
break; \
313+
case llvm::DS_Note: \
314+
DiagID = diag::note_fe_##GroupName; \
315+
break; \
316+
} \
317+
} while (false)
318+
319+
#define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
320+
do { \
321+
switch (Severity) { \
322+
case llvm::DS_Error: \
323+
DiagID = diag::err_fe_##GroupName; \
324+
break; \
325+
case llvm::DS_Warning: \
326+
DiagID = diag::warn_fe_##GroupName; \
327+
break; \
328+
case llvm::DS_Remark: \
329+
DiagID = diag::remark_fe_##GroupName; \
330+
break; \
310331
case llvm::DS_Note: \
311332
DiagID = diag::note_fe_##GroupName; \
312333
break; \
@@ -372,7 +393,7 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
372393
break;
373394
default:
374395
// Plugin IDs are not bound to any value as they are set dynamically.
375-
ComputeDiagID(Severity, backend_plugin, DiagID);
396+
ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
376397
break;
377398
}
378399
std::string MsgStorage;

clang/lib/Frontend/LogDiagnosticPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ LogDiagnosticPrinter::~LogDiagnosticPrinter() {
3131
static StringRef getLevelName(DiagnosticsEngine::Level Level) {
3232
switch (Level) {
3333
case DiagnosticsEngine::Ignored: return "ignored";
34+
case DiagnosticsEngine::Remark: return "remark";
3435
case DiagnosticsEngine::Note: return "note";
3536
case DiagnosticsEngine::Warning: return "warning";
3637
case DiagnosticsEngine::Error: return "error";

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
459459
MoveToLine(Loc);
460460
OS << "#pragma " << Namespace << " diagnostic ";
461461
switch (Map) {
462+
case diag::MAP_REMARK:
463+
OS << "remark";
464+
break;
462465
case diag::MAP_WARNING:
463466
OS << "warning";
464467
break;

clang/lib/Frontend/TextDiagnostic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ using namespace clang;
2626

2727
static const enum raw_ostream::Colors noteColor =
2828
raw_ostream::BLACK;
29+
static const enum raw_ostream::Colors remarkColor =
30+
raw_ostream::BLUE;
2931
static const enum raw_ostream::Colors fixitColor =
3032
raw_ostream::GREEN;
3133
static const enum raw_ostream::Colors caretColor =
@@ -711,6 +713,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
711713
case DiagnosticsEngine::Ignored:
712714
llvm_unreachable("Invalid diagnostic type");
713715
case DiagnosticsEngine::Note: OS.changeColor(noteColor, true); break;
716+
case DiagnosticsEngine::Remark: OS.changeColor(remarkColor, true); break;
714717
case DiagnosticsEngine::Warning: OS.changeColor(warningColor, true); break;
715718
case DiagnosticsEngine::Error: OS.changeColor(errorColor, true); break;
716719
case DiagnosticsEngine::Fatal: OS.changeColor(fatalColor, true); break;
@@ -721,6 +724,7 @@ TextDiagnostic::printDiagnosticLevel(raw_ostream &OS,
721724
case DiagnosticsEngine::Ignored:
722725
llvm_unreachable("Invalid diagnostic type");
723726
case DiagnosticsEngine::Note: OS << "note"; break;
727+
case DiagnosticsEngine::Remark: OS << "remark"; break;
724728
case DiagnosticsEngine::Warning: OS << "warning"; break;
725729
case DiagnosticsEngine::Error: OS << "error"; break;
726730
case DiagnosticsEngine::Fatal: OS << "fatal error"; break;

clang/tools/c-index-test/c-index-test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,6 +3736,7 @@ static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) {
37363736
static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
37373737
switch (severity) {
37383738
case CXDiagnostic_Note: return "note";
3739+
case CXDiagnostic_Remark: return "remark";
37393740
case CXDiagnostic_Error: return "error";
37403741
case CXDiagnostic_Fatal: return "fatal";
37413742
case CXDiagnostic_Ignored: return "ignored";

clang/tools/diagtool/ShowEnabledWarnings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static char getCharForLevel(DiagnosticsEngine::Level Level) {
4444
switch (Level) {
4545
case DiagnosticsEngine::Ignored: return ' ';
4646
case DiagnosticsEngine::Note: return '-';
47+
case DiagnosticsEngine::Remark: return 'R';
4748
case DiagnosticsEngine::Warning: return 'W';
4849
case DiagnosticsEngine::Error: return 'E';
4950
case DiagnosticsEngine::Fatal: return 'F';

clang/tools/libclang/CIndexDiagnostic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) {
305305
switch (Severity) {
306306
case CXDiagnostic_Ignored: llvm_unreachable("impossible");
307307
case CXDiagnostic_Note: Out << "note: "; break;
308+
case CXDiagnostic_Remark: Out << "remark: "; break;
308309
case CXDiagnostic_Warning: Out << "warning: "; break;
309310
case CXDiagnostic_Error: Out << "error: "; break;
310311
case CXDiagnostic_Fatal: Out << "fatal error: "; break;

clang/tools/libclang/CXStoredDiagnostic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CXDiagnosticSeverity CXStoredDiagnostic::getSeverity() const {
3131
switch (Diag.getLevel()) {
3232
case DiagnosticsEngine::Ignored: return CXDiagnostic_Ignored;
3333
case DiagnosticsEngine::Note: return CXDiagnostic_Note;
34+
case DiagnosticsEngine::Remark: return CXDiagnostic_Remark;
3435
case DiagnosticsEngine::Warning: return CXDiagnostic_Warning;
3536
case DiagnosticsEngine::Error: return CXDiagnostic_Error;
3637
case DiagnosticsEngine::Fatal: return CXDiagnostic_Fatal;

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ static bool isError(const Record &Diag) {
472472
return ClsName == "CLASS_ERROR";
473473
}
474474

475+
static bool isRemark(const Record &Diag) {
476+
const std::string &ClsName = Diag.getValueAsDef("Class")->getName();
477+
return ClsName == "CLASS_REMARK";
478+
}
479+
475480
/// ClangDiagsDefsEmitter - The top-level class emits .def files containing
476481
/// declarations of Clang diagnostics.
477482
namespace clang {
@@ -518,6 +523,14 @@ void EmitClangDiagsDefs(RecordKeeper &Records, raw_ostream &OS,
518523
}
519524
}
520525

526+
// Check that all remarks have an associated diagnostic group.
527+
if (isRemark(R)) {
528+
if (!isa<DefInit>(R.getValueInit("Group"))) {
529+
PrintFatalError(R.getLoc(), "Error " + R.getName() +
530+
" not in any diagnostic group");
531+
}
532+
}
533+
521534
// Filter by component.
522535
if (!Component.empty() && Component != R.getValueAsString("Component"))
523536
continue;

0 commit comments

Comments
 (0)