struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / cpp / gcc / warning-control.cc
blob081c966d918dd85faba07a5f984cb96365bb2519
1 /* Functions to enable and disable individual warnings on an expression
2 and statement basis.
4 Copyright (C) 2021-2022 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 "bitmap.h"
26 #include "tree.h"
27 #include "cgraph.h"
28 #include "hash-map.h"
29 #include "diagnostic-spec.h"
31 /* Return the no-warning bit for EXPR. */
33 static inline bool
34 get_no_warning_bit (const_tree expr)
36 fprintf(stderr, "incomplete %s\n", __func__);
37 (void) expr;
38 return true;
39 // sdcpp return expr->base.nowarning_flag;
42 /* Return the no-warning bit for statement STMT. */
44 static inline bool
45 get_no_warning_bit (const gimple *stmt)
47 fprintf(stderr, "incomplete %s\n", __func__);
48 (void) stmt;
49 return true;
50 // sdcpp return stmt->no_warning;
53 /* Set the no-warning bit for EXPR to VALUE. */
55 static inline void
56 set_no_warning_bit (tree expr, bool value)
58 fprintf(stderr, "incomplete %s\n", __func__);
59 (void) expr;
60 (void) value;
61 // expr->base.nowarning_flag = value;
64 /* Set the no-warning bit for statement STMT to VALUE. */
66 static inline void
67 set_no_warning_bit (gimple *stmt, bool value)
69 fprintf(stderr, "incomplete %s\n", __func__);
70 (void) stmt;
71 (void) value;
72 // sdcpp stmt->no_warning = value;
75 /* Return EXPR location or 'UNKNOWN_LOCATION'. */
77 static inline location_t
78 get_location (const_tree expr)
80 fprintf(stderr, "incomplete %s\n", __func__);
81 (void) expr;
82 return location_t();
83 #if 0 // sdcpp
84 if (DECL_P (expr))
85 return DECL_SOURCE_LOCATION (expr);
86 if (EXPR_P (expr))
87 return EXPR_LOCATION (expr);
88 return UNKNOWN_LOCATION;
89 #endif
92 /* Return STMT location (may be 'UNKNOWN_LOCATION'). */
94 static inline location_t
95 get_location (const gimple *stmt)
97 fprintf(stderr, "incomplete %s\n", __func__);
98 (void) stmt;
99 return location_t();
100 // sdcpp return gimple_location (stmt);
103 /* Return the no-warning bitmap for decl/expression EXPR. */
105 static nowarn_spec_t *
106 get_nowarn_spec (const_tree expr)
108 const location_t loc = get_location (expr);
110 if (RESERVED_LOCATION_P (loc))
111 return NULL;
113 if (!get_no_warning_bit (expr))
114 return NULL;
116 return nowarn_map ? nowarn_map->get (loc) : NULL;
119 /* Return the no-warning bitmap for statement STMT. */
121 static nowarn_spec_t *
122 get_nowarn_spec (const gimple *stmt)
124 fprintf(stderr, "incomplete %s\n", __func__);
125 (void) stmt;
126 return 0;
127 #if 0 //sdcpp
128 const location_t loc = get_location (stmt);
130 if (RESERVED_LOCATION_P (loc))
131 return NULL;
133 if (!get_no_warning_bit (stmt))
134 return NULL;
136 return nowarn_map ? nowarn_map->get (loc) : NULL;
137 #endif
140 /* Return true if warning OPT is suppressed for decl/expression EXPR.
141 By default tests the disposition for any warning. */
143 bool
144 warning_suppressed_p (const_tree expr, opt_code opt /* = all_warnings */)
146 const nowarn_spec_t *spec = get_nowarn_spec (expr);
148 if (!spec)
149 return get_no_warning_bit (expr);
151 const nowarn_spec_t optspec (opt);
152 bool dis = *spec & optspec;
153 gcc_assert (get_no_warning_bit (expr) || !dis);
154 return dis;
157 /* Return true if warning OPT is suppressed for statement STMT.
158 By default tests the disposition for any warning. */
160 bool
161 warning_suppressed_p (const gimple *stmt, opt_code opt /* = all_warnings */)
163 fprintf(stderr, "incomplete %s\n", __func__);
164 (void) stmt;
165 (void) opt;
166 return true;
167 #if 0
168 const nowarn_spec_t *spec = get_nowarn_spec (stmt);
170 if (!spec)
171 /* Fall back on the single no-warning bit. */
172 return get_no_warning_bit (stmt);
174 const nowarn_spec_t optspec (opt);
175 bool dis = *spec & optspec;
176 gcc_assert (get_no_warning_bit (stmt) || !dis);
177 return dis;
178 #endif
181 /* Enable, or by default disable, a warning for the expression.
182 The wildcard OPT of -1 controls all warnings. */
184 void
185 suppress_warning (tree expr, opt_code opt /* = all_warnings */,
186 bool supp /* = true */)
188 if (opt == no_warning)
189 return;
191 fprintf(stderr, "incomplete %s\n", __func__);
192 (void) expr;
193 (void) supp;
194 #if 0 // sdcpp
195 const location_t loc = get_location (expr);
197 if (!RESERVED_LOCATION_P (loc))
198 supp = suppress_warning_at (loc, opt, supp) || supp;
199 set_no_warning_bit (expr, supp);
200 #endif // sdcpp
203 /* Enable, or by default disable, a warning for the statement STMT.
204 The wildcard OPT of -1 controls all warnings. */
206 void
207 suppress_warning (gimple *stmt, opt_code opt /* = all_warnings */,
208 bool supp /* = true */)
210 if (opt == no_warning)
211 return;
213 fprintf(stderr, "incomplete %s\n", __func__);
214 (void) stmt;
215 (void) supp;
216 #if 0 // sdcpp
218 const location_t loc = get_location (stmt);
220 if (!RESERVED_LOCATION_P (loc))
221 supp = suppress_warning_at (loc, opt, supp) || supp;
222 set_no_warning_bit (stmt, supp);
223 #endif // sdcpp
226 /* Copy the warning disposition mapping between an expression and/or
227 a statement. */
229 template <class ToType, class FromType>
230 void copy_warning (ToType to, FromType from)
232 const location_t to_loc = get_location (to);
234 bool supp = get_no_warning_bit (from);
236 nowarn_spec_t *from_spec = get_nowarn_spec (from);
237 if (RESERVED_LOCATION_P (to_loc))
238 /* We cannot set no-warning dispositions for 'to', so we have no chance but
239 lose those potentially set for 'from'. */
241 else
243 if (from_spec)
245 /* If there's an entry in the map the no-warning bit must be set. */
246 gcc_assert (supp);
248 gcc_checking_assert (nowarn_map);
249 nowarn_spec_t tem = *from_spec;
250 nowarn_map->put (to_loc, tem);
252 else
254 if (nowarn_map)
255 nowarn_map->remove (to_loc);
259 /* The no-warning bit might be set even if the map has not been consulted, or
260 otherwise if there's no entry in the map. */
261 set_no_warning_bit (to, supp);
264 /* Copy the warning disposition mapping from one expression to another. */
266 void
267 copy_warning (tree to, const_tree from)
269 copy_warning<tree, const_tree>(to, from);
272 /* Copy the warning disposition mapping from a statement to an expression. */
274 void
275 copy_warning (tree to, const gimple *from)
277 copy_warning<tree, const gimple *>(to, from);
280 /* Copy the warning disposition mapping from an expression to a statement. */
282 void
283 copy_warning (gimple *to, const_tree from)
285 copy_warning<gimple *, const_tree>(to, from);
288 /* Copy the warning disposition mapping from one statement to another. */
290 void
291 copy_warning (gimple *to, const gimple *from)
293 copy_warning<gimple *, const gimple *>(to, from);