1 /* Functions to enable and disable individual warnings on an expression
3 Copyright (C) 2021-2023 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
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
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/>. */
24 #include "coretypes.h"
30 #include "diagnostic-spec.h"
31 #include "pretty-print.h"
34 /* Initialize *THIS from warning option OPT. */
36 nowarn_spec_t::nowarn_spec_t (opt_code opt
)
38 /* Create a very simple mapping based on testing and experience.
39 It should become more refined with time. */
50 /* Flow-sensitive warnings about pointer problems issued by both
51 front ends and the middle end. */
57 /* Flow-sensitive warnings about arithmetic overflow issued by both
58 front ends and the middle end. */
60 case OPT_Wshift_count_negative
:
61 case OPT_Wshift_count_overflow
:
62 case OPT_Wstrict_overflow
:
66 /* Lexical warnings issued by front ends. */
69 case OPT_Wparentheses
:
70 case OPT_Wreturn_type
:
71 case OPT_Wsizeof_array_div
:
72 case OPT_Wstrict_aliasing
:
74 case OPT_Wunused_function
:
75 case OPT_Wunused_but_set_variable
:
76 case OPT_Wunused_variable
:
77 case OPT_Wunused_but_set_parameter
:
81 /* Access warning group. */
82 case OPT_Warray_bounds_
:
83 case OPT_Wformat_overflow_
:
84 case OPT_Wformat_truncation_
:
86 case OPT_Wsizeof_pointer_memaccess
:
87 case OPT_Wstrict_aliasing_
:
88 case OPT_Wstringop_overflow_
:
89 case OPT_Wstringop_overread
:
90 case OPT_Wstringop_truncation
:
94 /* Initialization warning group. */
96 case OPT_Wuninitialized
:
97 case OPT_Wmaybe_uninitialized
:
101 case OPT_Wdangling_pointer_
:
102 case OPT_Wreturn_local_addr
:
103 case OPT_Wuse_after_free_
:
104 m_bits
= NW_DANGLING
;
107 case OPT_Wpessimizing_move
:
108 case OPT_Wredundant_move
:
109 m_bits
= NW_REDUNDANT
;
113 /* A catchall group for everything else. */
118 /* A mapping from a 'location_t' to the warning spec set for it. */
120 GTY(()) nowarn_map_t
*nowarn_map
;
122 /* Return the no-warning disposition for location LOC and option OPT
123 or for all/any otions by default. */
126 warning_suppressed_at (location_t loc
, opt_code opt
/* = all_warnings */)
128 gcc_checking_assert (!RESERVED_LOCATION_P (loc
));
133 if (const nowarn_spec_t
* const pspec
= nowarn_map
->get (loc
))
135 const nowarn_spec_t
optspec (opt
);
136 return *pspec
& optspec
;
142 /* Change the supression of warnings for location LOC.
143 OPT controls which warnings are affected.
144 The wildcard OPT of -1 controls all warnings.
145 If SUPP is true (the default), enable the suppression of the warnings.
146 If SUPP is false, disable the suppression of the warnings. */
149 suppress_warning_at (location_t loc
, opt_code opt
/* = all_warnings */,
150 bool supp
/* = true */)
152 gcc_checking_assert (!RESERVED_LOCATION_P (loc
));
154 const nowarn_spec_t
optspec (supp
? opt
: opt_code ());
156 if (nowarn_spec_t
*pspec
= nowarn_map
? nowarn_map
->get (loc
) : NULL
)
168 nowarn_map
->remove (loc
);
172 if (!supp
|| opt
== no_warning
)
176 nowarn_map
= nowarn_map_t::create_ggc (32);
178 nowarn_map
->put (loc
, optspec
);
182 /* Copy the no-warning disposition from one location to another. */
185 copy_warning (location_t to
, location_t from
)
190 nowarn_spec_t
*from_spec
;
191 if (RESERVED_LOCATION_P (from
))
194 from_spec
= nowarn_map
->get (from
);
195 if (RESERVED_LOCATION_P (to
))
196 /* We cannot set no-warning dispositions for 'to', so we have no chance but
197 lose those potentially set for 'from'. */
203 nowarn_spec_t tem
= *from_spec
;
204 nowarn_map
->put (to
, tem
);
207 nowarn_map
->remove (to
);