1 /* Functions to enable and disable individual warnings on an expression
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
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"
29 #include "diagnostic-spec.h"
31 /* Return the no-warning bit for EXPR. */
34 get_no_warning_bit (const_tree expr
)
36 fprintf(stderr
, "incomplete %s\n", __func__
);
39 // sdcpp return expr->base.nowarning_flag;
42 /* Return the no-warning bit for statement STMT. */
45 get_no_warning_bit (const gimple
*stmt
)
47 fprintf(stderr
, "incomplete %s\n", __func__
);
50 // sdcpp return stmt->no_warning;
53 /* Set the no-warning bit for EXPR to VALUE. */
56 set_no_warning_bit (tree expr
, bool value
)
58 fprintf(stderr
, "incomplete %s\n", __func__
);
61 // expr->base.nowarning_flag = value;
64 /* Set the no-warning bit for statement STMT to VALUE. */
67 set_no_warning_bit (gimple
*stmt
, bool value
)
69 fprintf(stderr
, "incomplete %s\n", __func__
);
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__
);
85 return DECL_SOURCE_LOCATION (expr
);
87 return EXPR_LOCATION (expr
);
88 return UNKNOWN_LOCATION
;
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__
);
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
))
113 if (!get_no_warning_bit (expr
))
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__
);
128 const location_t loc
= get_location (stmt
);
130 if (RESERVED_LOCATION_P (loc
))
133 if (!get_no_warning_bit (stmt
))
136 return nowarn_map
? nowarn_map
->get (loc
) : NULL
;
140 /* Return true if warning OPT is suppressed for decl/expression EXPR.
141 By default tests the disposition for any warning. */
144 warning_suppressed_p (const_tree expr
, opt_code opt
/* = all_warnings */)
146 const nowarn_spec_t
*spec
= get_nowarn_spec (expr
);
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
);
157 /* Return true if warning OPT is suppressed for statement STMT.
158 By default tests the disposition for any warning. */
161 warning_suppressed_p (const gimple
*stmt
, opt_code opt
/* = all_warnings */)
163 fprintf(stderr
, "incomplete %s\n", __func__
);
168 const nowarn_spec_t
*spec
= get_nowarn_spec (stmt
);
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
);
181 /* Enable, or by default disable, a warning for the expression.
182 The wildcard OPT of -1 controls all warnings. */
185 suppress_warning (tree expr
, opt_code opt
/* = all_warnings */,
186 bool supp
/* = true */)
188 if (opt
== no_warning
)
191 fprintf(stderr
, "incomplete %s\n", __func__
);
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
);
203 /* Enable, or by default disable, a warning for the statement STMT.
204 The wildcard OPT of -1 controls all warnings. */
207 suppress_warning (gimple
*stmt
, opt_code opt
/* = all_warnings */,
208 bool supp
/* = true */)
210 if (opt
== no_warning
)
213 fprintf(stderr
, "incomplete %s\n", __func__
);
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
);
226 /* Copy the warning disposition mapping between an expression and/or
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'. */
245 /* If there's an entry in the map the no-warning bit must be set. */
248 gcc_checking_assert (nowarn_map
);
249 nowarn_spec_t tem
= *from_spec
;
250 nowarn_map
->put (to_loc
, tem
);
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. */
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. */
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. */
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. */
291 copy_warning (gimple
*to
, const gimple
*from
)
293 copy_warning
<gimple
*, const gimple
*>(to
, from
);