[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 11 08:21:56 PDT 2024
================
@@ -179,13 +180,85 @@ class DiagnosticMapping {
class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
public:
/// The level of the diagnostic, after it has been through mapping.
- enum Level {
- Ignored, Note, Remark, Warning, Error, Fatal
+ enum Level : uint8_t { Ignored, Note, Remark, Warning, Error, Fatal };
+
+ // Diagnostic classes.
+ enum Class {
+ CLASS_NOTE = 0x01,
+ CLASS_REMARK = 0x02,
+ CLASS_WARNING = 0x03,
+ CLASS_EXTENSION = 0x04,
+ CLASS_ERROR = 0x05
+ };
+
+ static bool IsCustomDiag(diag::kind Diag) {
+ return Diag >= diag::DIAG_UPPER_LIMIT;
+ }
+
+ class CustomDiagDesc {
+ diag::Severity DefaultSeverity : 3;
+ unsigned Class : 3;
+ unsigned ShowInSystemHeader : 1;
+ unsigned ShowInSystemMacro : 1;
+ unsigned HasGroup : 1;
+ diag::Group Group;
+ std::string Description;
+
+ auto get_as_tuple() const {
+ return std::tuple(DefaultSeverity, Class, ShowInSystemHeader,
+ ShowInSystemMacro, HasGroup, Group,
+ std::string_view{Description});
+ }
+
+ public:
+ CustomDiagDesc(diag::Severity DefaultSeverity, std::string Description,
+ unsigned Class = CLASS_WARNING,
+ bool ShowInSystemHeader = false,
+ bool ShowInSystemMacro = false,
+ std::optional<diag::Group> Group = std::nullopt)
+ : DefaultSeverity(DefaultSeverity), Class(Class),
+ ShowInSystemHeader(ShowInSystemHeader),
+ ShowInSystemMacro(ShowInSystemMacro), HasGroup(Group != std::nullopt),
+ Group(Group.value_or(diag::Group{})),
+ Description(std::move(Description)) {}
+
+ std::optional<diag::Group> GetGroup() const {
+ if (HasGroup)
+ return Group;
+ return std::nullopt;
+ }
+
+ diag::Severity GetDefaultSeverity() const { return DefaultSeverity; }
+ unsigned GetClass() const { return Class; }
+ std::string_view GetDescription() const { return Description; }
+ bool ShouldShowInSystemHeader() const { return ShowInSystemHeader; }
+
+ friend bool operator==(const CustomDiagDesc &lhs,
+ const CustomDiagDesc &rhs) {
+ return lhs.get_as_tuple() == rhs.get_as_tuple();
+ }
+
+ friend bool operator<(const CustomDiagDesc &lhs,
+ const CustomDiagDesc &rhs) {
+ return lhs.get_as_tuple() < rhs.get_as_tuple();
+ }
+ };
+
+ struct GroupInfo {
+ diag::Severity Severity : 3;
+ bool HasNoWarningAsError : 1;
----------------
AaronBallman wrote:
`unsigned` and `LLVM_PREFERRED_TYPE` here as well.
https://github.com/llvm/llvm-project/pull/70976
More information about the cfe-commits
mailing list