GCC Middle and Back End API Reference
diagnostic-spec.h
Go to the documentation of this file.
1/* Language-independent APIs to enable/disable per-location warnings.
2
3 Copyright (C) 2021-2025 Free Software Foundation, Inc.
4 Contributed by Martin Sebor <msebor@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22#ifndef DIAGNOSTIC_SPEC_H_INCLUDED
23#define DIAGNOSTIC_SPEC_H_INCLUDED
24
25#include "hash-map.h"
26
27/* A "bitset" of warning groups. */
28
30{
31public:
32 enum
33 {
34 /* Middle end warnings about invalid accesses. */
35 NW_ACCESS = 1 << 0,
36 /* Front end/lexical warnings. */
37 NW_LEXICAL = 1 << 1,
38 /* Warnings about null pointers. */
39 NW_NONNULL = 1 << 2,
40 /* Warnings about uninitialized reads. */
41 NW_UNINIT = 1 << 3,
42 /* Warnings about arithmetic overflow. */
43 NW_VFLOW = 1 << 4,
44 /* Warnings about dangling pointers. */
45 NW_DANGLING = 1 << 5,
46 /* All other unclassified warnings. */
47 NW_OTHER = 1 << 6,
48 /* Warnings about redundant calls. */
49 NW_REDUNDANT = 1 << 7,
50 /* All groups of warnings. */
53 };
54
56
57 nowarn_spec_t (opt_code);
58
59 static nowarn_spec_t from_bits (unsigned bits)
60 {
61 nowarn_spec_t spec;
62 spec.m_bits = bits;
63 return spec;
64 }
65
66 /* Return the raw bitset. */
67 operator unsigned() const
68 {
69 return m_bits;
70 }
71
72 /* Return true if the bitset is clear. */
73 bool operator!() const
74 {
75 return !m_bits;
76 }
77
78 /* Return the inverse of the bitset. */
80 {
81 nowarn_spec_t res (*this);
82 res.m_bits &= ~NW_ALL;
83 return res;
84 }
85
86 /* Set *THIS to the bitwise OR of *THIS and RHS. */
88 {
89 m_bits |= rhs.m_bits;
90 return *this;
91 }
92
93 /* Set *THIS to the bitwise AND of *THIS and RHS. */
95 {
96 m_bits &= rhs.m_bits;
97 return *this;
98 }
99
100 /* Set *THIS to the bitwise exclusive OR of *THIS and RHS. */
102 {
103 m_bits ^= rhs.m_bits;
104 return *this;
105 }
106
107private:
108 /* Bitset of warning groups. */
109 unsigned m_bits;
110};
111
112/* Return the bitwise OR of LHS and RHS. */
113
114inline nowarn_spec_t
116{
117 return nowarn_spec_t (lhs) |= rhs;
118}
119
120/* Return the bitwise AND of LHS and RHS. */
121
122inline nowarn_spec_t
124{
125 return nowarn_spec_t (lhs) &= rhs;
126}
127
128/* Return true if LHS is equal RHS. */
129
130inline bool
132{
133 return static_cast<unsigned>(lhs) == static_cast<unsigned>(rhs);
134}
135
136/* Return true if LHS is not equal RHS. */
137
138inline bool
140{
141 return !(lhs == rhs);
142}
143
145
146/* A mapping from a 'location_t' to the warning spec set for it. */
147extern GTY(()) nowarn_map_t *nowarn_map;
148
149#endif // DIAGNOSTIC_SPEC_H_INCLUDED
Definition hash-map.h:40
Definition diagnostic-spec.h:30
@ NW_ACCESS
Definition diagnostic-spec.h:35
@ NW_VFLOW
Definition diagnostic-spec.h:43
@ NW_OTHER
Definition diagnostic-spec.h:47
@ NW_REDUNDANT
Definition diagnostic-spec.h:49
@ NW_LEXICAL
Definition diagnostic-spec.h:37
@ NW_DANGLING
Definition diagnostic-spec.h:45
@ NW_NONNULL
Definition diagnostic-spec.h:39
@ NW_UNINIT
Definition diagnostic-spec.h:41
@ NW_ALL
Definition diagnostic-spec.h:51
static nowarn_spec_t from_bits(unsigned bits)
Definition diagnostic-spec.h:59
nowarn_spec_t & operator|=(const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:87
unsigned m_bits
Definition diagnostic-spec.h:109
nowarn_spec_t & operator^=(const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:101
nowarn_spec_t operator~() const
Definition diagnostic-spec.h:79
nowarn_spec_t()
Definition diagnostic-spec.h:55
nowarn_spec_t & operator&=(const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:94
bool operator!() const
Definition diagnostic-spec.h:73
#define GTY(x)
Definition coretypes.h:41
bool operator==(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:131
nowarn_map_t * nowarn_map
Definition diagnostic-spec.cc:120
bool operator!=(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:139
hash_map< location_hash, nowarn_spec_t > nowarn_map_t
Definition diagnostic-spec.h:144
nowarn_spec_t operator|(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:115
nowarn_spec_t operator&(const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
Definition diagnostic-spec.h:123