libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / diagnostic-spec.h
blob0b155a5cde3faca70692754c086accdee76c6351
1 /* Language-independent APIs to enable/disable per-location warnings.
3 Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 Contributed by Martin Sebor <msebor@redhat.com>
6 This file is part of GCC.
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.
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.
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/>. */
22 #ifndef DIAGNOSTIC_SPEC_H_INCLUDED
23 #define DIAGNOSTIC_SPEC_H_INCLUDED
25 #include "hash-map.h"
27 /* A "bitset" of warning groups. */
29 class nowarn_spec_t
31 public:
32 enum
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. */
51 NW_ALL = (NW_ACCESS | NW_LEXICAL | NW_NONNULL
52 | NW_UNINIT | NW_VFLOW | NW_DANGLING | NW_REDUNDANT | NW_OTHER)
55 nowarn_spec_t (): m_bits () { }
57 nowarn_spec_t (opt_code);
59 static nowarn_spec_t from_bits (unsigned bits)
61 nowarn_spec_t spec;
62 spec.m_bits = bits;
63 return spec;
66 /* Return the raw bitset. */
67 operator unsigned() const
69 return m_bits;
72 /* Return true if the bitset is clear. */
73 bool operator!() const
75 return !m_bits;
78 /* Return the inverse of the bitset. */
79 nowarn_spec_t operator~() const
81 nowarn_spec_t res (*this);
82 res.m_bits &= ~NW_ALL;
83 return res;
86 /* Set *THIS to the bitwise OR of *THIS and RHS. */
87 nowarn_spec_t& operator|= (const nowarn_spec_t &rhs)
89 m_bits |= rhs.m_bits;
90 return *this;
93 /* Set *THIS to the bitwise AND of *THIS and RHS. */
94 nowarn_spec_t& operator&= (const nowarn_spec_t &rhs)
96 m_bits &= rhs.m_bits;
97 return *this;
100 /* Set *THIS to the bitwise exclusive OR of *THIS and RHS. */
101 nowarn_spec_t& operator^= (const nowarn_spec_t &rhs)
103 m_bits ^= rhs.m_bits;
104 return *this;
107 private:
108 /* Bitset of warning groups. */
109 unsigned m_bits;
112 /* Return the bitwise OR of LHS and RHS. */
114 inline nowarn_spec_t
115 operator| (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
117 return nowarn_spec_t (lhs) |= rhs;
120 /* Return the bitwise AND of LHS and RHS. */
122 inline nowarn_spec_t
123 operator& (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
125 return nowarn_spec_t (lhs) &= rhs;
128 /* Return true if LHS is equal RHS. */
130 inline bool
131 operator== (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
133 return static_cast<unsigned>(lhs) == static_cast<unsigned>(rhs);
136 /* Return true if LHS is not equal RHS. */
138 inline bool
139 operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
141 return !(lhs == rhs);
144 typedef hash_map<location_hash, nowarn_spec_t> nowarn_map_t;
146 /* A mapping from a 'location_t' to the warning spec set for it. */
147 extern GTY(()) nowarn_map_t *nowarn_map;
149 #endif // DIAGNOSTIC_SPEC_H_INCLUDED