14#ifndef LLVM_CLANG_BASIC_DIAGNOSTICIDS_H
15#define LLVM_CLANG_BASIC_DIAGNOSTICIDS_H
19#include "llvm/ADT/IntrusiveRefCntPtr.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/ErrorHandling.h"
26 class DiagnosticsEngine;
27 class DiagnosticBuilder;
75#define DIAG(ENUM, FLAGS, DEFAULT_MAPPING, DESC, GROUP, SFINAE, CATEGORY, \
76 NOWERROR, SHOWINSYSHEADER, SHOWINSYSMACRO, DEFFERABLE) \
79#include "clang/Basic/DiagnosticCommonKinds.inc"
109 unsigned Severity : 3;
110 LLVM_PREFERRED_TYPE(
bool)
112 LLVM_PREFERRED_TYPE(
bool)
113 unsigned IsPragma : 1;
114 LLVM_PREFERRED_TYPE(
bool)
115 unsigned HasNoWarningAsError : 1;
116 LLVM_PREFERRED_TYPE(
bool)
117 unsigned HasNoErrorAsFatal : 1;
118 LLVM_PREFERRED_TYPE(
bool)
119 unsigned WasUpgradedFromWarning : 1;
127 Result.IsPragma = IsPragma;
128 Result.HasNoWarningAsError = 0;
129 Result.HasNoErrorAsFatal = 0;
130 Result.WasUpgradedFromWarning = 0;
159 return (IsUser << 7) | (IsPragma << 6) | (HasNoWarningAsError << 5) |
160 (HasNoErrorAsFatal << 4) | (WasUpgradedFromWarning << 3) | Severity;
165 Result.IsUser = (Bits >> 7) & 1;
166 Result.IsPragma = (Bits >> 6) & 1;
167 Result.HasNoWarningAsError = (Bits >> 5) & 1;
168 Result.HasNoErrorAsFatal = (Bits >> 4) & 1;
169 Result.WasUpgradedFromWarning = (Bits >> 3) & 1;
170 Result.Severity = Bits & 0x7;
203 unsigned DefaultSeverity : 3;
204 LLVM_PREFERRED_TYPE(
Class)
205 unsigned DiagClass : 3;
206 LLVM_PREFERRED_TYPE(
bool)
207 unsigned ShowInSystemHeader : 1;
208 LLVM_PREFERRED_TYPE(
bool)
209 unsigned ShowInSystemMacro : 1;
210 LLVM_PREFERRED_TYPE(
bool)
211 unsigned HasGroup : 1;
213 std::string Description;
215 auto get_as_tuple()
const {
216 return std::tuple(DefaultSeverity, DiagClass, ShowInSystemHeader,
217 ShowInSystemMacro, HasGroup, Group,
218 std::string_view{Description});
224 bool ShowInSystemHeader =
false,
225 bool ShowInSystemMacro =
false,
226 std::optional<diag::Group> Group = std::nullopt)
227 : DefaultSeverity(static_cast<
unsigned>(DefaultSeverity)),
228 DiagClass(
Class), ShowInSystemHeader(ShowInSystemHeader),
229 ShowInSystemMacro(ShowInSystemMacro), HasGroup(Group !=
std::nullopt),
230 Group(Group.value_or(diag::Group{})),
231 Description(
std::move(Description)) {}
249 return lhs.get_as_tuple() == rhs.get_as_tuple();
254 return lhs.get_as_tuple() < rhs.get_as_tuple();
261 LLVM_PREFERRED_TYPE(
bool)
267 std::unique_ptr<diag::CustomDiagInfo> CustomDiagInfo;
269 auto GIs = std::make_unique<GroupInfo[]>(
272 GIs[i] = {{},
false};
315 llvm_unreachable(
"Fully covered switch above!");
342 bool isNote(
unsigned DiagID)
const;
461 std::vector<diag::kind> &Diags);
484 Class getDiagClass(
unsigned DiagID)
const;
496 Level DiagLevel)
const;
500 bool isUnrecoverable(
unsigned DiagID)
const;
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
A little helper class used to produce diagnostics.
friend bool operator==(const CustomDiagDesc &lhs, const CustomDiagDesc &rhs)
bool ShouldShowInSystemHeader() const
friend bool operator<(const CustomDiagDesc &lhs, const CustomDiagDesc &rhs)
std::optional< diag::Group > GetGroup() const
diag::Severity GetDefaultSeverity() const
CustomDiagDesc(diag::Severity DefaultSeverity, std::string Description, unsigned Class=CLASS_WARNING, bool ShowInSystemHeader=false, bool ShowInSystemMacro=false, std::optional< diag::Group > Group=std::nullopt)
std::string_view GetDescription() const
Used for handling and querying diagnostic IDs.
void initCustomDiagMapping(DiagnosticMapping &, unsigned DiagID)
static StringRef getCategoryNameFromID(unsigned CategoryID)
Given a category ID, return the name of the category.
unsigned getCustomDiagID(Level Level, StringRef Message)
static unsigned getNumberOfCategories()
Return the number of diagnostic categories.
static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group)
Get the diagnostic option with the closest edit distance to the given group name.
bool getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group, SmallVectorImpl< diag::kind > &Diags) const
Get the set of all diagnostic IDs in the group with the given name.
static std::vector< std::string > getDiagnosticFlags()
Get the string of all diagnostic flags.
bool isWarningOrExtension(unsigned DiagID) const
Return true if the unmapped diagnostic levelof the specified diagnostic ID is a Warning or Extension.
void setGroupSeverity(StringRef Group, diag::Severity)
bool isExtensionDiag(unsigned DiagID) const
Determine whether the given diagnostic ID is for an extension of some sort.
DiagnosticMapping getDefaultMapping(unsigned DiagID) const
Get the default mapping for this diagnostic.
static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID)
Determines whether the given built-in diagnostic ID is for an error that is suppressed if it occurs d...
bool isDefaultMappingAsError(unsigned DiagID) const
Return true if the specified diagnostic is mapped to errors by default.
void setGroupNoWarningsAsError(StringRef Group, bool)
static bool isCodegenABICheckDiagnostic(unsigned DiagID)
Return true if a given diagnostic is a codegen-time ABI check.
StringRef getDescription(unsigned DiagID) const
Given a diagnostic ID, return a description of the issue.
SFINAEResponse
Enumeration describing how the emission of a diagnostic should be treated when it occurs during C++ t...
@ SFINAE_SubstitutionFailure
The diagnostic should not be reported, but it should cause template argument deduction to fail.
@ SFINAE_Suppress
The diagnostic should be suppressed entirely.
@ SFINAE_AccessControl
The diagnostic is an access-control diagnostic, which will be substitution failures in some contexts ...
@ SFINAE_Report
The diagnostic should be reported.
bool isNote(unsigned DiagID) const
Determine whether the given diagnostic ID is a Note.
StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
static StringRef getWarningOptionDocumentation(diag::Group GroupID)
Given a diagnostic group ID, return its documentation.
static std::optional< diag::Group > getGroupForWarningOption(StringRef)
Given a group ID, returns the flag that toggles the group.
static bool IsCustomDiag(diag::kind Diag)
unsigned getCustomDiagID(CustomDiagDesc Diag)
Return an ID for a diagnostic with the specified format string and level.
Level
The level of the diagnostic, after it has been through mapping.
static unsigned getCategoryNumberForDiag(unsigned DiagID)
Return the category number that a specified DiagID belongs to, or 0 if no category.
static StringRef getWarningOptionForGroup(diag::Group)
Given a group ID, returns the flag that toggles the group.
static bool isARCDiagnostic(unsigned DiagID)
Return true if a given diagnostic falls into an ARC diagnostic category.
static void getAllDiagnostics(diag::Flavor Flavor, std::vector< diag::kind > &Diags)
Get the set of all diagnostic IDs.
std::optional< diag::Group > getGroupForDiag(unsigned DiagID) const
Return the lowest-level group that contains the specified diagnostic.
static bool isDeferrable(unsigned DiagID)
Whether the diagnostic message can be deferred.
bool hasNoErrorAsFatal() const
bool wasUpgradedFromWarning() const
Whether this mapping attempted to map the diagnostic to a warning, but was overruled because the diag...
unsigned serialize() const
Serialize this mapping as a raw integer.
bool operator==(DiagnosticMapping Other) const
bool isErrorOrFatal() const
void setNoWarningAsError(bool Value)
void setSeverity(diag::Severity Value)
static DiagnosticMapping deserialize(unsigned Bits)
Deserialize a mapping.
diag::Severity getSeverity() const
void setUpgradedFromWarning(bool Value)
static DiagnosticMapping Make(diag::Severity Severity, bool IsUser, bool IsPragma)
void setNoErrorAsFatal(bool Value)
bool hasNoWarningAsError() const
Concrete class used by the front-end to report problems and issues.
Encodes a location in the source.
@ DIAG_SIZE_SERIALIZATION
@ DIAG_START_SERIALIZATION
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
@ NUM_BUILTIN_COMMON_DIAGNOSTICS
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
@ Warning
Present this diagnostic as a warning.
@ Fatal
Present this diagnostic as a fatal error.
@ Error
Present this diagnostic as an error.
@ Remark
Present this diagnostic as a remark.
@ Ignored
Do not present this diagnostic, ignore it.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
@ Other
Other implicit parameter.
unsigned HasNoWarningAsError