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"
26class DiagnosticsEngine;
103#include "clang/Basic/DiagnosticCommonInterface.inc"
108 unsigned Severity : 3;
109 LLVM_PREFERRED_TYPE(
bool)
111 LLVM_PREFERRED_TYPE(
bool)
112 unsigned IsPragma : 1;
113 LLVM_PREFERRED_TYPE(
bool)
114 unsigned HasNoWarningAsError : 1;
115 LLVM_PREFERRED_TYPE(
bool)
116 unsigned HasNoErrorAsFatal : 1;
117 LLVM_PREFERRED_TYPE(
bool)
118 unsigned WasUpgradedFromWarning : 1;
126 Result.IsPragma = IsPragma;
127 Result.HasNoWarningAsError = 0;
128 Result.HasNoErrorAsFatal = 0;
129 Result.WasUpgradedFromWarning = 0;
158 return (IsUser << 7) | (IsPragma << 6) | (HasNoWarningAsError << 5) |
159 (HasNoErrorAsFatal << 4) | (WasUpgradedFromWarning << 3) | Severity;
164 Result.IsUser = (Bits >> 7) & 1;
165 Result.IsPragma = (Bits >> 6) & 1;
166 Result.HasNoWarningAsError = (Bits >> 5) & 1;
167 Result.HasNoErrorAsFatal = (Bits >> 4) & 1;
168 Result.WasUpgradedFromWarning = (Bits >> 3) & 1;
169 Result.Severity = Bits & 0x7;
204 unsigned DefaultSeverity : 3;
205 LLVM_PREFERRED_TYPE(
Class)
206 unsigned DiagClass : 3;
207 LLVM_PREFERRED_TYPE(
bool)
208 unsigned ShowInSystemHeader : 1;
209 LLVM_PREFERRED_TYPE(
bool)
210 unsigned ShowInSystemMacro : 1;
211 LLVM_PREFERRED_TYPE(
bool)
212 unsigned HasGroup : 1;
214 std::string Description;
216 auto get_as_tuple()
const {
217 return std::tuple(DefaultSeverity, DiagClass, ShowInSystemHeader,
218 ShowInSystemMacro, HasGroup, Group,
219 std::string_view{Description});
225 bool ShowInSystemHeader =
false,
226 bool ShowInSystemMacro =
false,
227 std::optional<diag::Group> Group = std::nullopt)
228 : DefaultSeverity(static_cast<
unsigned>(DefaultSeverity)),
229 DiagClass(
Class), ShowInSystemHeader(ShowInSystemHeader),
230 ShowInSystemMacro(ShowInSystemMacro), HasGroup(Group !=
std::nullopt),
231 Group(Group.value_or(diag::Group{})),
232 Description(
std::move(Description)) {}
250 return lhs.get_as_tuple() == rhs.get_as_tuple();
255 return lhs.get_as_tuple() < rhs.get_as_tuple();
262 LLVM_PREFERRED_TYPE(
bool)
268 std::unique_ptr<diag::CustomDiagInfo> CustomDiagInfo;
270 auto GIs = std::make_unique<GroupInfo[]>(
273 GIs[i] = {{},
false};
283 return llvm::makeIntrusiveRefCnt<DiagnosticIDs>();
324 llvm_unreachable(
"Fully covered switch above!");
351 bool isNote(
unsigned DiagID)
const;
474 std::vector<diag::kind> &Diags);
483 unsigned CompatDiagId);
502 Class getDiagClass(
unsigned DiagID)
const;
506 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.
Class to make it convenient to initialize TrapReason objects which can be used to attach the "trap re...
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.
static unsigned getCXXCompatDiagId(const LangOptions &LangOpts, unsigned CompatDiagId)
Get the appropriate diagnostic Id to use for issuing a compatibility diagnostic.
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)
bool isTrapDiag(unsigned DiagID) const
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 llvm::IntrusiveRefCntPtr< DiagnosticIDs > create()
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Encodes a location in the source.
@ DIAG_SIZE_SERIALIZATION
Flavor
Flavors of diagnostics we can emit.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
@ DIAG_START_SERIALIZATION
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