Don't warn when alignment of global common data exceeds maximum alignment.
[official-gcc.git] / gcc / warning-control.cc
blobec8ed232763054be945a3ca2d5bd18678b413cd8
1 /* Functions to enable and disable individual warnings on an expression
2 and statement basis.
4 Copyright (C) 2021 Free Software Foundation, Inc.
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 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "backend.h"
26 #include "bitmap.h"
27 #include "tree.h"
28 #include "gimple.h"
29 #include "cgraph.h"
30 #include "hash-map.h"
31 #include "diagnostic-spec.h"
33 /* Return the no-warning bit for EXPR. */
35 static inline bool
36 get_no_warning_bit (const_tree expr)
38 return expr->base.nowarning_flag;
41 /* Return the no-warning bit for statement STMT. */
43 static inline bool
44 get_no_warning_bit (const gimple *stmt)
46 return stmt->no_warning;
49 /* Set the no-warning bit for EXPR to VALUE. */
51 static inline void
52 set_no_warning_bit (tree expr, bool value)
54 expr->base.nowarning_flag = value;
57 /* Set the no-warning bit for statement STMT to VALUE. */
59 static inline void
60 set_no_warning_bit (gimple *stmt, bool value)
62 stmt->no_warning = value;
65 /* Return EXPR location or zero. */
67 static inline key_type_t
68 convert_to_key (const_tree expr)
70 if (DECL_P (expr))
71 return DECL_SOURCE_LOCATION (expr);
72 if (EXPR_P (expr))
73 return EXPR_LOCATION (expr);
74 return 0;
77 /* Return STMT location (may be zero). */
79 static inline key_type_t
80 convert_to_key (const gimple *stmt)
82 return gimple_location (stmt);
85 /* Return the no-warning bitmap for decl/expression EXPR. */
87 static nowarn_spec_t *
88 get_nowarn_spec (const_tree expr)
90 const key_type_t key = convert_to_key (expr);
92 if (!get_no_warning_bit (expr) || !key)
93 return NULL;
95 return nowarn_map ? nowarn_map->get (key) : NULL;
98 /* Return the no-warning bitmap for stateemt STMT. */
100 static nowarn_spec_t *
101 get_nowarn_spec (const gimple *stmt)
103 const key_type_t key = convert_to_key (stmt);
105 if (!get_no_warning_bit (stmt))
106 return NULL;
108 return nowarn_map ? nowarn_map->get (key) : NULL;
111 /* Return true if warning OPT is suppressed for decl/expression EXPR.
112 By default tests the disposition for any warning. */
114 bool
115 warning_suppressed_p (const_tree expr, opt_code opt /* = all_warnings */)
117 const nowarn_spec_t *spec = get_nowarn_spec (expr);
119 if (!spec)
120 return get_no_warning_bit (expr);
122 const nowarn_spec_t optspec (opt);
123 bool dis = *spec & optspec;
124 gcc_assert (get_no_warning_bit (expr) || !dis);
125 return dis;
128 /* Return true if warning OPT is suppressed for statement STMT.
129 By default tests the disposition for any warning. */
131 bool
132 warning_suppressed_p (const gimple *stmt, opt_code opt /* = all_warnings */)
134 const nowarn_spec_t *spec = get_nowarn_spec (stmt);
136 if (!spec)
137 /* Fall back on the single no-warning bit. */
138 return get_no_warning_bit (stmt);
140 const nowarn_spec_t optspec (opt);
141 bool dis = *spec & optspec;
142 gcc_assert (get_no_warning_bit (stmt) || !dis);
143 return dis;
146 /* Enable, or by default disable, a warning for the expression.
147 The wildcard OPT of -1 controls all warnings. */
149 void
150 suppress_warning (tree expr, opt_code opt /* = all_warnings */,
151 bool supp /* = true */)
153 if (opt == no_warning)
154 return;
156 const key_type_t key = convert_to_key (expr);
158 supp = suppress_warning_at (key, opt, supp) || supp;
159 set_no_warning_bit (expr, supp);
162 /* Enable, or by default disable, a warning for the statement STMT.
163 The wildcard OPT of -1 controls all warnings. */
165 void
166 suppress_warning (gimple *stmt, opt_code opt /* = all_warnings */,
167 bool supp /* = true */)
169 if (opt == no_warning)
170 return;
172 const key_type_t key = convert_to_key (stmt);
174 supp = suppress_warning_at (key, opt, supp) || supp;
175 set_no_warning_bit (stmt, supp);
178 /* Copy the warning disposition mapping between an expression and/or
179 a statement. */
181 template <class ToType, class FromType>
182 void copy_warning (ToType to, FromType from)
184 const key_type_t to_key = convert_to_key (to);
186 if (nowarn_spec_t *from_map = get_nowarn_spec (from))
188 /* If there's an entry in the map the no-warning bit must be set. */
189 gcc_assert (get_no_warning_bit (from));
191 if (!nowarn_map)
192 nowarn_map = xint_hash_map_t::create_ggc (32);
194 nowarn_map->put (to_key, *from_map);
195 set_no_warning_bit (to, true);
197 else
199 if (nowarn_map)
200 nowarn_map->remove (to_key);
202 /* The no-warning bit might be set even if there's no entry
203 in the map. */
204 set_no_warning_bit (to, get_no_warning_bit (from));
208 /* Copy the warning disposition mapping from one expression to another. */
210 void
211 copy_warning (tree to, const_tree from)
213 copy_warning<tree, const_tree>(to, from);
216 /* Copy the warning disposition mapping from a statement to an expression. */
218 void
219 copy_warning (tree to, const gimple *from)
221 copy_warning<tree, const gimple *>(to, from);
224 /* Copy the warning disposition mapping from an expression to a statement. */
226 void
227 copy_warning (gimple *to, const_tree from)
229 copy_warning<gimple *, const_tree>(to, from);
232 /* Copy the warning disposition mapping from one statement to another. */
234 void
235 copy_warning (gimple *to, const gimple *from)
237 copy_warning<gimple *, const gimple *>(to, from);