Import GCC-8 to a new vendor branch
[dragonfly.git] / contrib / gcc-8.0 / gcc / c-family / c-attribs.c
blobe0630885cca3610d6cc5453819355425c175e9e1
1 /* C-family attributes handling.
2 Copyright (C) 1992-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "target.h"
24 #include "function.h"
25 #include "tree.h"
26 #include "memmodel.h"
27 #include "c-common.h"
28 #include "gimple-expr.h"
29 #include "tm_p.h"
30 #include "stringpool.h"
31 #include "cgraph.h"
32 #include "diagnostic.h"
33 #include "intl.h"
34 #include "stor-layout.h"
35 #include "calls.h"
36 #include "attribs.h"
37 #include "varasm.h"
38 #include "trans-mem.h"
39 #include "c-objc.h"
40 #include "common/common-target.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
43 #include "toplev.h"
44 #include "tree-iterator.h"
45 #include "opts.h"
46 #include "gimplify.h"
48 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_common_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
52 static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_no_sanitize_address_attribute (tree *, tree, tree,
56 int, bool *);
57 static tree handle_no_sanitize_thread_attribute (tree *, tree, tree,
58 int, bool *);
59 static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree,
60 int, bool *);
61 static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int,
62 bool *);
63 static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int,
64 bool *);
65 static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *);
66 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
67 static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
68 static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *);
69 static tree handle_noicf_attribute (tree *, tree, tree, int, bool *);
70 static tree handle_noipa_attribute (tree *, tree, tree, int, bool *);
71 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
72 static tree handle_always_inline_attribute (tree *, tree, tree, int,
73 bool *);
74 static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *);
75 static tree handle_artificial_attribute (tree *, tree, tree, int, bool *);
76 static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
77 static tree handle_error_attribute (tree *, tree, tree, int, bool *);
78 static tree handle_used_attribute (tree *, tree, tree, int, bool *);
79 static tree handle_externally_visible_attribute (tree *, tree, tree, int,
80 bool *);
81 static tree handle_no_reorder_attribute (tree *, tree, tree, int,
82 bool *);
83 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
84 static tree handle_transparent_union_attribute (tree *, tree, tree,
85 int, bool *);
86 static tree handle_scalar_storage_order_attribute (tree *, tree, tree,
87 int, bool *);
88 static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
89 static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
90 static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
91 static tree handle_section_attribute (tree *, tree, tree, int, bool *);
92 static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
93 static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree,
94 int, bool *);
95 static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
96 static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
97 static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *);
98 static tree handle_ifunc_attribute (tree *, tree, tree, int, bool *);
99 static tree handle_alias_attribute (tree *, tree, tree, int, bool *);
100 static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ;
101 static tree handle_visibility_attribute (tree *, tree, tree, int,
102 bool *);
103 static tree handle_tls_model_attribute (tree *, tree, tree, int,
104 bool *);
105 static tree handle_no_instrument_function_attribute (tree *, tree,
106 tree, int, bool *);
107 static tree handle_no_profile_instrument_function_attribute (tree *, tree,
108 tree, int, bool *);
109 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
110 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
111 static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
112 bool *);
113 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
114 static tree handle_tm_attribute (tree *, tree, tree, int, bool *);
115 static tree handle_tm_wrap_attribute (tree *, tree, tree, int, bool *);
116 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
117 static tree handle_deprecated_attribute (tree *, tree, tree, int,
118 bool *);
119 static tree handle_vector_size_attribute (tree *, tree, tree, int,
120 bool *);
121 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
122 static tree handle_nonstring_attribute (tree *, tree, tree, int, bool *);
123 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
124 static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
125 static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
126 bool *);
127 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
128 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
129 static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
130 static tree handle_alloc_align_attribute (tree *, tree, tree, int, bool *);
131 static tree handle_assume_aligned_attribute (tree *, tree, tree, int, bool *);
132 static tree handle_target_attribute (tree *, tree, tree, int, bool *);
133 static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *);
134 static tree handle_optimize_attribute (tree *, tree, tree, int, bool *);
135 static tree ignore_attribute (tree *, tree, tree, int, bool *);
136 static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *);
137 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
138 static tree handle_warn_unused_attribute (tree *, tree, tree, int, bool *);
139 static tree handle_returns_nonnull_attribute (tree *, tree, tree, int, bool *);
140 static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int,
141 bool *);
142 static tree handle_simd_attribute (tree *, tree, tree, int, bool *);
143 static tree handle_omp_declare_target_attribute (tree *, tree, tree, int,
144 bool *);
145 static tree handle_designated_init_attribute (tree *, tree, tree, int, bool *);
146 static tree handle_bnd_variable_size_attribute (tree *, tree, tree, int, bool *);
147 static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
148 static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
149 static tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *);
150 static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
151 int, bool *);
153 /* Helper to define attribute exclusions. */
154 #define ATTR_EXCL(name, function, type, variable) \
155 { name, function, type, variable }
157 /* Define attributes that are mutually exclusive with one another. */
158 static const struct attribute_spec::exclusions attr_aligned_exclusions[] =
160 /* Attribute name exclusion applies to:
161 function, type, variable */
162 ATTR_EXCL ("aligned", true, false, false),
163 ATTR_EXCL ("packed", true, false, false),
164 ATTR_EXCL (NULL, false, false, false)
167 static const struct attribute_spec::exclusions attr_cold_hot_exclusions[] =
169 ATTR_EXCL ("cold", true, true, true),
170 ATTR_EXCL ("hot", true, true, true),
171 ATTR_EXCL (NULL, false, false, false)
174 static const struct attribute_spec::exclusions attr_common_exclusions[] =
176 ATTR_EXCL ("common", true, true, true),
177 ATTR_EXCL ("nocommon", true, true, true),
178 ATTR_EXCL (NULL, false, false, false),
181 static const struct attribute_spec::exclusions attr_inline_exclusions[] =
183 ATTR_EXCL ("noinline", true, true, true),
184 ATTR_EXCL (NULL, false, false, false),
187 static const struct attribute_spec::exclusions attr_noinline_exclusions[] =
189 ATTR_EXCL ("always_inline", true, true, true),
190 ATTR_EXCL ("gnu_inline", true, true, true),
191 ATTR_EXCL (NULL, false, false, false),
194 static const struct attribute_spec::exclusions attr_noreturn_exclusions[] =
196 ATTR_EXCL ("alloc_align", true, true, true),
197 ATTR_EXCL ("alloc_size", true, true, true),
198 ATTR_EXCL ("const", true, true, true),
199 ATTR_EXCL ("malloc", true, true, true),
200 ATTR_EXCL ("pure", true, true, true),
201 ATTR_EXCL ("returns_twice", true, true, true),
202 ATTR_EXCL ("warn_unused_result", true, true, true),
203 ATTR_EXCL (NULL, false, false, false),
206 static const struct attribute_spec::exclusions
207 attr_warn_unused_result_exclusions[] =
209 ATTR_EXCL ("noreturn", true, true, true),
210 ATTR_EXCL ("warn_unused_result", true, true, true),
211 ATTR_EXCL (NULL, false, false, false),
214 static const struct attribute_spec::exclusions attr_returns_twice_exclusions[] =
216 ATTR_EXCL ("noreturn", true, true, true),
217 ATTR_EXCL (NULL, false, false, false),
220 /* Exclusions that apply to attribute alloc_align, alloc_size, and malloc. */
221 static const struct attribute_spec::exclusions attr_alloc_exclusions[] =
223 ATTR_EXCL ("const", true, true, true),
224 ATTR_EXCL ("noreturn", true, true, true),
225 ATTR_EXCL ("pure", true, true, true),
226 ATTR_EXCL (NULL, false, false, false),
229 static const struct attribute_spec::exclusions attr_const_pure_exclusions[] =
231 ATTR_EXCL ("const", true, true, true),
232 ATTR_EXCL ("alloc_align", true, true, true),
233 ATTR_EXCL ("alloc_size", true, true, true),
234 ATTR_EXCL ("malloc", true, true, true),
235 ATTR_EXCL ("noreturn", true, true, true),
236 ATTR_EXCL ("pure", true, true, true),
237 ATTR_EXCL (NULL, false, false, false)
240 /* Table of machine-independent attributes common to all C-like languages.
242 All attributes referencing arguments should be additionally processed
243 in chkp_copy_function_type_adding_bounds for correct instrumentation
244 by Pointer Bounds Checker.
245 Current list of processed common attributes: nonnull. */
246 const struct attribute_spec c_common_attribute_table[] =
248 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
249 affects_type_identity, handler, exclude } */
250 { "packed", 0, 0, false, false, false, false,
251 handle_packed_attribute,
252 attr_aligned_exclusions },
253 { "nocommon", 0, 0, true, false, false, false,
254 handle_nocommon_attribute,
255 attr_common_exclusions },
256 { "common", 0, 0, true, false, false, false,
257 handle_common_attribute,
258 attr_common_exclusions },
259 /* FIXME: logically, noreturn attributes should be listed as
260 "false, true, true" and apply to function types. But implementing this
261 would require all the places in the compiler that use TREE_THIS_VOLATILE
262 on a decl to identify non-returning functions to be located and fixed
263 to check the function type instead. */
264 { "noreturn", 0, 0, true, false, false, false,
265 handle_noreturn_attribute,
266 attr_noreturn_exclusions },
267 { "volatile", 0, 0, true, false, false, false,
268 handle_noreturn_attribute, NULL },
269 { "stack_protect", 0, 0, true, false, false, false,
270 handle_stack_protect_attribute, NULL },
271 { "noinline", 0, 0, true, false, false, false,
272 handle_noinline_attribute,
273 attr_noinline_exclusions },
274 { "noclone", 0, 0, true, false, false, false,
275 handle_noclone_attribute, NULL },
276 { "no_icf", 0, 0, true, false, false, false,
277 handle_noicf_attribute, NULL },
278 { "noipa", 0, 0, true, false, false, false,
279 handle_noipa_attribute, NULL },
280 { "leaf", 0, 0, true, false, false, false,
281 handle_leaf_attribute, NULL },
282 { "always_inline", 0, 0, true, false, false, false,
283 handle_always_inline_attribute,
284 attr_inline_exclusions },
285 { "gnu_inline", 0, 0, true, false, false, false,
286 handle_gnu_inline_attribute,
287 attr_inline_exclusions },
288 { "artificial", 0, 0, true, false, false, false,
289 handle_artificial_attribute, NULL },
290 { "flatten", 0, 0, true, false, false, false,
291 handle_flatten_attribute, NULL },
292 { "used", 0, 0, true, false, false, false,
293 handle_used_attribute, NULL },
294 { "unused", 0, 0, false, false, false, false,
295 handle_unused_attribute, NULL },
296 { "externally_visible", 0, 0, true, false, false, false,
297 handle_externally_visible_attribute, NULL },
298 { "no_reorder", 0, 0, true, false, false, false,
299 handle_no_reorder_attribute, NULL },
300 /* The same comments as for noreturn attributes apply to const ones. */
301 { "const", 0, 0, true, false, false, false,
302 handle_const_attribute,
303 attr_const_pure_exclusions },
304 { "scalar_storage_order", 1, 1, false, false, false, false,
305 handle_scalar_storage_order_attribute, NULL },
306 { "transparent_union", 0, 0, false, false, false, false,
307 handle_transparent_union_attribute, NULL },
308 { "constructor", 0, 1, true, false, false, false,
309 handle_constructor_attribute, NULL },
310 { "destructor", 0, 1, true, false, false, false,
311 handle_destructor_attribute, NULL },
312 { "mode", 1, 1, false, true, false, false,
313 handle_mode_attribute, NULL },
314 { "section", 1, 1, true, false, false, false,
315 handle_section_attribute, NULL },
316 { "aligned", 0, 1, false, false, false, false,
317 handle_aligned_attribute,
318 attr_aligned_exclusions },
319 { "warn_if_not_aligned", 0, 1, false, false, false, false,
320 handle_warn_if_not_aligned_attribute, NULL },
321 { "weak", 0, 0, true, false, false, false,
322 handle_weak_attribute, NULL },
323 { "noplt", 0, 0, true, false, false, false,
324 handle_noplt_attribute, NULL },
325 { "ifunc", 1, 1, true, false, false, false,
326 handle_ifunc_attribute, NULL },
327 { "alias", 1, 1, true, false, false, false,
328 handle_alias_attribute, NULL },
329 { "weakref", 0, 1, true, false, false, false,
330 handle_weakref_attribute, NULL },
331 { "no_instrument_function", 0, 0, true, false, false, false,
332 handle_no_instrument_function_attribute,
333 NULL },
334 { "no_profile_instrument_function", 0, 0, true, false, false, false,
335 handle_no_profile_instrument_function_attribute,
336 NULL },
337 { "malloc", 0, 0, true, false, false, false,
338 handle_malloc_attribute, attr_alloc_exclusions },
339 { "returns_twice", 0, 0, true, false, false, false,
340 handle_returns_twice_attribute,
341 attr_returns_twice_exclusions },
342 { "no_stack_limit", 0, 0, true, false, false, false,
343 handle_no_limit_stack_attribute, NULL },
344 { "pure", 0, 0, true, false, false, false,
345 handle_pure_attribute,
346 attr_const_pure_exclusions },
347 { "transaction_callable", 0, 0, false, true, false, false,
348 handle_tm_attribute, NULL },
349 { "transaction_unsafe", 0, 0, false, true, false, true,
350 handle_tm_attribute, NULL },
351 { "transaction_safe", 0, 0, false, true, false, true,
352 handle_tm_attribute, NULL },
353 { "transaction_safe_dynamic", 0, 0, true, false, false, false,
354 handle_tm_attribute, NULL },
355 { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
356 handle_tm_attribute, NULL },
357 /* ??? These two attributes didn't make the transition from the
358 Intel language document to the multi-vendor language document. */
359 { "transaction_pure", 0, 0, false, true, false, false,
360 handle_tm_attribute, NULL },
361 { "transaction_wrap", 1, 1, true, false, false, false,
362 handle_tm_wrap_attribute, NULL },
363 /* For internal use (marking of builtins) only. The name contains space
364 to prevent its usage in source code. */
365 { "no vops", 0, 0, true, false, false, false,
366 handle_novops_attribute, NULL },
367 { "deprecated", 0, 1, false, false, false, false,
368 handle_deprecated_attribute, NULL },
369 { "vector_size", 1, 1, false, true, false, true,
370 handle_vector_size_attribute, NULL },
371 { "visibility", 1, 1, false, false, false, false,
372 handle_visibility_attribute, NULL },
373 { "tls_model", 1, 1, true, false, false, false,
374 handle_tls_model_attribute, NULL },
375 { "nonnull", 0, -1, false, true, true, false,
376 handle_nonnull_attribute, NULL },
377 { "nonstring", 0, 0, true, false, false, false,
378 handle_nonstring_attribute, NULL },
379 { "nothrow", 0, 0, true, false, false, false,
380 handle_nothrow_attribute, NULL },
381 { "may_alias", 0, 0, false, true, false, false, NULL, NULL },
382 { "cleanup", 1, 1, true, false, false, false,
383 handle_cleanup_attribute, NULL },
384 { "warn_unused_result", 0, 0, false, true, true, false,
385 handle_warn_unused_result_attribute,
386 attr_warn_unused_result_exclusions },
387 { "sentinel", 0, 1, false, true, true, false,
388 handle_sentinel_attribute, NULL },
389 /* For internal use (marking of builtins) only. The name contains space
390 to prevent its usage in source code. */
391 { "type generic", 0, 0, false, true, true, false,
392 handle_type_generic_attribute, NULL },
393 { "alloc_size", 1, 2, false, true, true, false,
394 handle_alloc_size_attribute,
395 attr_alloc_exclusions },
396 { "cold", 0, 0, true, false, false, false,
397 handle_cold_attribute,
398 attr_cold_hot_exclusions },
399 { "hot", 0, 0, true, false, false, false,
400 handle_hot_attribute,
401 attr_cold_hot_exclusions },
402 { "no_address_safety_analysis",
403 0, 0, true, false, false, false,
404 handle_no_address_safety_analysis_attribute,
405 NULL },
406 { "no_sanitize", 1, 1, true, false, false, false,
407 handle_no_sanitize_attribute, NULL },
408 { "no_sanitize_address", 0, 0, true, false, false, false,
409 handle_no_sanitize_address_attribute, NULL },
410 { "no_sanitize_thread", 0, 0, true, false, false, false,
411 handle_no_sanitize_thread_attribute, NULL },
412 { "no_sanitize_undefined", 0, 0, true, false, false, false,
413 handle_no_sanitize_undefined_attribute, NULL },
414 { "asan odr indicator", 0, 0, true, false, false, false,
415 handle_asan_odr_indicator_attribute, NULL },
416 { "warning", 1, 1, true, false, false, false,
417 handle_error_attribute, NULL },
418 { "error", 1, 1, true, false, false, false,
419 handle_error_attribute, NULL },
420 { "target", 1, -1, true, false, false, false,
421 handle_target_attribute, NULL },
422 { "target_clones", 1, -1, true, false, false, false,
423 handle_target_clones_attribute, NULL },
424 { "optimize", 1, -1, true, false, false, false,
425 handle_optimize_attribute, NULL },
426 /* For internal use only. The leading '*' both prevents its usage in
427 source code and signals that it may be overridden by machine tables. */
428 { "*tm regparm", 0, 0, false, true, true, false,
429 ignore_attribute, NULL },
430 { "no_split_stack", 0, 0, true, false, false, false,
431 handle_no_split_stack_attribute, NULL },
432 /* For internal use (marking of builtins and runtime functions) only.
433 The name contains space to prevent its usage in source code. */
434 { "fn spec", 1, 1, false, true, true, false,
435 handle_fnspec_attribute, NULL },
436 { "warn_unused", 0, 0, false, false, false, false,
437 handle_warn_unused_attribute, NULL },
438 { "returns_nonnull", 0, 0, false, true, true, false,
439 handle_returns_nonnull_attribute, NULL },
440 { "omp declare simd", 0, -1, true, false, false, false,
441 handle_omp_declare_simd_attribute, NULL },
442 { "simd", 0, 1, true, false, false, false,
443 handle_simd_attribute, NULL },
444 { "omp declare target", 0, 0, true, false, false, false,
445 handle_omp_declare_target_attribute, NULL },
446 { "omp declare target link", 0, 0, true, false, false, false,
447 handle_omp_declare_target_attribute, NULL },
448 { "alloc_align", 1, 1, false, true, true, false,
449 handle_alloc_align_attribute,
450 attr_alloc_exclusions },
451 { "assume_aligned", 1, 2, false, true, true, false,
452 handle_assume_aligned_attribute, NULL },
453 { "designated_init", 0, 0, false, true, false, false,
454 handle_designated_init_attribute, NULL },
455 { "bnd_variable_size", 0, 0, true, false, false, false,
456 handle_bnd_variable_size_attribute, NULL },
457 { "bnd_legacy", 0, 0, true, false, false, false,
458 handle_bnd_legacy, NULL },
459 { "bnd_instrument", 0, 0, true, false, false, false,
460 handle_bnd_instrument, NULL },
461 { "fallthrough", 0, 0, false, false, false, false,
462 handle_fallthrough_attribute, NULL },
463 { "patchable_function_entry", 1, 2, true, false, false, false,
464 handle_patchable_function_entry_attribute,
465 NULL },
466 { "nocf_check", 0, 0, false, true, true, true,
467 handle_nocf_check_attribute, NULL },
468 { NULL, 0, 0, false, false, false, false, NULL, NULL }
471 /* Give the specifications for the format attributes, used by C and all
472 descendants.
474 All attributes referencing arguments should be additionally processed
475 in chkp_copy_function_type_adding_bounds for correct instrumentation
476 by Pointer Bounds Checker.
477 Current list of processed format attributes: format, format_arg. */
478 const struct attribute_spec c_common_format_attribute_table[] =
480 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
481 affects_type_identity, handler, exclude } */
482 { "format", 3, 3, false, true, true, false,
483 handle_format_attribute, NULL },
484 { "format_arg", 1, 1, false, true, true, false,
485 handle_format_arg_attribute, NULL },
486 { NULL, 0, 0, false, false, false, false, NULL, NULL }
489 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
490 identifier as an argument, so the front end shouldn't look it up. */
492 bool
493 attribute_takes_identifier_p (const_tree attr_id)
495 const struct attribute_spec *spec = lookup_attribute_spec (attr_id);
496 if (spec == NULL)
497 /* Unknown attribute that we'll end up ignoring, return true so we
498 don't complain about an identifier argument. */
499 return true;
500 else if (!strcmp ("mode", spec->name)
501 || !strcmp ("format", spec->name)
502 || !strcmp ("cleanup", spec->name))
503 return true;
504 else
505 return targetm.attribute_takes_identifier_p (attr_id);
508 /* Attribute handlers common to C front ends. */
510 /* Handle a "packed" attribute; arguments as in
511 struct attribute_spec.handler. */
513 static tree
514 handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
515 int flags, bool *no_add_attrs)
517 if (TYPE_P (*node))
519 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
520 *node = build_variant_type_copy (*node);
521 TYPE_PACKED (*node) = 1;
523 else if (TREE_CODE (*node) == FIELD_DECL)
525 if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
526 /* Still pack bitfields. */
527 && ! DECL_C_BIT_FIELD (*node))
528 warning (OPT_Wattributes,
529 "%qE attribute ignored for field of type %qT",
530 name, TREE_TYPE (*node));
531 else
532 DECL_PACKED (*node) = 1;
534 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
535 used for DECL_REGISTER. It wouldn't mean anything anyway.
536 We can't set DECL_PACKED on the type of a TYPE_DECL, because
537 that changes what the typedef is typing. */
538 else
540 warning (OPT_Wattributes, "%qE attribute ignored", name);
541 *no_add_attrs = true;
544 return NULL_TREE;
547 /* Handle a "nocommon" attribute; arguments as in
548 struct attribute_spec.handler. */
550 static tree
551 handle_nocommon_attribute (tree *node, tree name,
552 tree ARG_UNUSED (args),
553 int ARG_UNUSED (flags), bool *no_add_attrs)
555 if (VAR_P (*node))
556 DECL_COMMON (*node) = 0;
557 else
559 warning (OPT_Wattributes, "%qE attribute ignored", name);
560 *no_add_attrs = true;
563 return NULL_TREE;
566 /* Handle a "common" attribute; arguments as in
567 struct attribute_spec.handler. */
569 static tree
570 handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
571 int ARG_UNUSED (flags), bool *no_add_attrs)
573 if (VAR_P (*node))
574 DECL_COMMON (*node) = 1;
575 else
577 warning (OPT_Wattributes, "%qE attribute ignored", name);
578 *no_add_attrs = true;
581 return NULL_TREE;
584 /* Handle a "noreturn" attribute; arguments as in
585 struct attribute_spec.handler. */
587 static tree
588 handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
589 int ARG_UNUSED (flags), bool *no_add_attrs)
591 tree type = TREE_TYPE (*node);
593 /* See FIXME comment in c_common_attribute_table. */
594 if (TREE_CODE (*node) == FUNCTION_DECL
595 || objc_method_decl (TREE_CODE (*node)))
596 TREE_THIS_VOLATILE (*node) = 1;
597 else if (TREE_CODE (type) == POINTER_TYPE
598 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
599 TREE_TYPE (*node)
600 = (build_qualified_type
601 (build_pointer_type
602 (build_type_variant (TREE_TYPE (type),
603 TYPE_READONLY (TREE_TYPE (type)), 1)),
604 TYPE_QUALS (type)));
605 else
607 warning (OPT_Wattributes, "%qE attribute ignored", name);
608 *no_add_attrs = true;
611 return NULL_TREE;
614 /* Handle a "hot" and attribute; arguments as in
615 struct attribute_spec.handler. */
617 static tree
618 handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
619 int ARG_UNUSED (flags), bool *no_add_attrs)
621 if (TREE_CODE (*node) == FUNCTION_DECL
622 || TREE_CODE (*node) == LABEL_DECL)
624 /* Attribute hot processing is done later with lookup_attribute. */
626 else
628 warning (OPT_Wattributes, "%qE attribute ignored", name);
629 *no_add_attrs = true;
632 return NULL_TREE;
635 /* Handle a "cold" and attribute; arguments as in
636 struct attribute_spec.handler. */
638 static tree
639 handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args),
640 int ARG_UNUSED (flags), bool *no_add_attrs)
642 if (TREE_CODE (*node) == FUNCTION_DECL
643 || TREE_CODE (*node) == LABEL_DECL)
645 /* Attribute cold processing is done later with lookup_attribute. */
647 else
649 warning (OPT_Wattributes, "%qE attribute ignored", name);
650 *no_add_attrs = true;
653 return NULL_TREE;
656 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
658 void
659 add_no_sanitize_value (tree node, unsigned int flags)
661 tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node));
662 if (attr)
664 unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
665 flags |= old_value;
667 if (flags == old_value)
668 return;
670 TREE_VALUE (attr) = build_int_cst (unsigned_type_node, flags);
672 else
673 DECL_ATTRIBUTES (node)
674 = tree_cons (get_identifier ("no_sanitize"),
675 build_int_cst (unsigned_type_node, flags),
676 DECL_ATTRIBUTES (node));
679 /* Handle a "no_sanitize" attribute; arguments as in
680 struct attribute_spec.handler. */
682 static tree
683 handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
684 bool *no_add_attrs)
686 *no_add_attrs = true;
687 tree id = TREE_VALUE (args);
688 if (TREE_CODE (*node) != FUNCTION_DECL)
690 warning (OPT_Wattributes, "%qE attribute ignored", name);
691 return NULL_TREE;
694 if (TREE_CODE (id) != STRING_CST)
696 error ("no_sanitize argument not a string");
697 return NULL_TREE;
700 char *string = ASTRDUP (TREE_STRING_POINTER (id));
701 unsigned int flags = parse_no_sanitize_attribute (string);
703 add_no_sanitize_value (*node, flags);
705 return NULL_TREE;
708 /* Handle a "no_sanitize_address" attribute; arguments as in
709 struct attribute_spec.handler. */
711 static tree
712 handle_no_sanitize_address_attribute (tree *node, tree name, tree, int,
713 bool *no_add_attrs)
715 *no_add_attrs = true;
716 if (TREE_CODE (*node) != FUNCTION_DECL)
717 warning (OPT_Wattributes, "%qE attribute ignored", name);
718 else
719 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
721 return NULL_TREE;
724 /* Handle a "no_sanitize_thread" attribute; arguments as in
725 struct attribute_spec.handler. */
727 static tree
728 handle_no_sanitize_thread_attribute (tree *node, tree name, tree, int,
729 bool *no_add_attrs)
731 *no_add_attrs = true;
732 if (TREE_CODE (*node) != FUNCTION_DECL)
733 warning (OPT_Wattributes, "%qE attribute ignored", name);
734 else
735 add_no_sanitize_value (*node, SANITIZE_THREAD);
737 return NULL_TREE;
741 /* Handle a "no_address_safety_analysis" attribute; arguments as in
742 struct attribute_spec.handler. */
744 static tree
745 handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int,
746 bool *no_add_attrs)
748 *no_add_attrs = true;
749 if (TREE_CODE (*node) != FUNCTION_DECL)
750 warning (OPT_Wattributes, "%qE attribute ignored", name);
751 else
752 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
754 return NULL_TREE;
757 /* Handle a "no_sanitize_undefined" attribute; arguments as in
758 struct attribute_spec.handler. */
760 static tree
761 handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int,
762 bool *no_add_attrs)
764 *no_add_attrs = true;
765 if (TREE_CODE (*node) != FUNCTION_DECL)
766 warning (OPT_Wattributes, "%qE attribute ignored", name);
767 else
768 add_no_sanitize_value (*node,
769 SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
771 return NULL_TREE;
774 /* Handle an "asan odr indicator" attribute; arguments as in
775 struct attribute_spec.handler. */
777 static tree
778 handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *)
780 return NULL_TREE;
783 /* Handle a "stack_protect" attribute; arguments as in
784 struct attribute_spec.handler. */
786 static tree
787 handle_stack_protect_attribute (tree *node, tree name, tree, int,
788 bool *no_add_attrs)
790 if (TREE_CODE (*node) != FUNCTION_DECL)
792 warning (OPT_Wattributes, "%qE attribute ignored", name);
793 *no_add_attrs = true;
796 return NULL_TREE;
799 /* Handle a "noipa" attribute; arguments as in
800 struct attribute_spec.handler. */
802 static tree
803 handle_noipa_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
805 if (TREE_CODE (*node) != FUNCTION_DECL)
807 warning (OPT_Wattributes, "%qE attribute ignored", name);
808 *no_add_attrs = true;
811 return NULL_TREE;
814 /* Handle a "noinline" attribute; arguments as in
815 struct attribute_spec.handler. */
817 static tree
818 handle_noinline_attribute (tree *node, tree name,
819 tree ARG_UNUSED (args),
820 int ARG_UNUSED (flags), bool *no_add_attrs)
822 if (TREE_CODE (*node) == FUNCTION_DECL)
824 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
826 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
827 "with attribute %qs", name, "always_inline");
828 *no_add_attrs = true;
830 else
831 DECL_UNINLINABLE (*node) = 1;
833 else
835 warning (OPT_Wattributes, "%qE attribute ignored", name);
836 *no_add_attrs = true;
839 return NULL_TREE;
842 /* Handle a "noclone" attribute; arguments as in
843 struct attribute_spec.handler. */
845 static tree
846 handle_noclone_attribute (tree *node, tree name,
847 tree ARG_UNUSED (args),
848 int ARG_UNUSED (flags), bool *no_add_attrs)
850 if (TREE_CODE (*node) != FUNCTION_DECL)
852 warning (OPT_Wattributes, "%qE attribute ignored", name);
853 *no_add_attrs = true;
856 return NULL_TREE;
859 /* Handle a "nocf_check" attribute; arguments as in
860 struct attribute_spec.handler. */
862 static tree
863 handle_nocf_check_attribute (tree *node, tree name,
864 tree ARG_UNUSED (args),
865 int ARG_UNUSED (flags), bool *no_add_attrs)
867 if (TREE_CODE (*node) != FUNCTION_TYPE
868 && TREE_CODE (*node) != METHOD_TYPE)
870 warning (OPT_Wattributes, "%qE attribute ignored", name);
871 *no_add_attrs = true;
873 else if (!(flag_cf_protection & CF_BRANCH))
875 warning (OPT_Wattributes, "%qE attribute ignored. Use "
876 "-fcf-protection option to enable it", name);
877 *no_add_attrs = true;
880 return NULL_TREE;
883 /* Handle a "no_icf" attribute; arguments as in
884 struct attribute_spec.handler. */
886 static tree
887 handle_noicf_attribute (tree *node, tree name,
888 tree ARG_UNUSED (args),
889 int ARG_UNUSED (flags), bool *no_add_attrs)
891 if (TREE_CODE (*node) != FUNCTION_DECL)
893 warning (OPT_Wattributes, "%qE attribute ignored", name);
894 *no_add_attrs = true;
897 return NULL_TREE;
901 /* Handle a "always_inline" attribute; arguments as in
902 struct attribute_spec.handler. */
904 static tree
905 handle_always_inline_attribute (tree *node, tree name,
906 tree ARG_UNUSED (args),
907 int ARG_UNUSED (flags),
908 bool *no_add_attrs)
910 if (TREE_CODE (*node) == FUNCTION_DECL)
912 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node)))
914 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
915 "with %qs attribute", name, "noinline");
916 *no_add_attrs = true;
918 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
920 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
921 "with %qs attribute", name, "target_clones");
922 *no_add_attrs = true;
924 else
925 /* Set the attribute and mark it for disregarding inline
926 limits. */
927 DECL_DISREGARD_INLINE_LIMITS (*node) = 1;
929 else
931 warning (OPT_Wattributes, "%qE attribute ignored", name);
932 *no_add_attrs = true;
935 return NULL_TREE;
938 /* Handle a "gnu_inline" attribute; arguments as in
939 struct attribute_spec.handler. */
941 static tree
942 handle_gnu_inline_attribute (tree *node, tree name,
943 tree ARG_UNUSED (args),
944 int ARG_UNUSED (flags),
945 bool *no_add_attrs)
947 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
949 /* Do nothing else, just set the attribute. We'll get at
950 it later with lookup_attribute. */
952 else
954 warning (OPT_Wattributes, "%qE attribute ignored", name);
955 *no_add_attrs = true;
958 return NULL_TREE;
961 /* Handle a "leaf" attribute; arguments as in
962 struct attribute_spec.handler. */
964 static tree
965 handle_leaf_attribute (tree *node, tree name,
966 tree ARG_UNUSED (args),
967 int ARG_UNUSED (flags), bool *no_add_attrs)
969 if (TREE_CODE (*node) != FUNCTION_DECL)
971 warning (OPT_Wattributes, "%qE attribute ignored", name);
972 *no_add_attrs = true;
974 if (!TREE_PUBLIC (*node))
976 warning (OPT_Wattributes, "%qE attribute has no effect on unit local "
977 "functions", name);
978 *no_add_attrs = true;
981 return NULL_TREE;
984 /* Handle an "artificial" attribute; arguments as in
985 struct attribute_spec.handler. */
987 static tree
988 handle_artificial_attribute (tree *node, tree name,
989 tree ARG_UNUSED (args),
990 int ARG_UNUSED (flags),
991 bool *no_add_attrs)
993 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
995 /* Do nothing else, just set the attribute. We'll get at
996 it later with lookup_attribute. */
998 else
1000 warning (OPT_Wattributes, "%qE attribute ignored", name);
1001 *no_add_attrs = true;
1004 return NULL_TREE;
1007 /* Handle a "flatten" attribute; arguments as in
1008 struct attribute_spec.handler. */
1010 static tree
1011 handle_flatten_attribute (tree *node, tree name,
1012 tree args ATTRIBUTE_UNUSED,
1013 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
1015 if (TREE_CODE (*node) == FUNCTION_DECL)
1016 /* Do nothing else, just set the attribute. We'll get at
1017 it later with lookup_attribute. */
1019 else
1021 warning (OPT_Wattributes, "%qE attribute ignored", name);
1022 *no_add_attrs = true;
1025 return NULL_TREE;
1028 /* Handle a "warning" or "error" attribute; arguments as in
1029 struct attribute_spec.handler. */
1031 static tree
1032 handle_error_attribute (tree *node, tree name, tree args,
1033 int ARG_UNUSED (flags), bool *no_add_attrs)
1035 if (TREE_CODE (*node) == FUNCTION_DECL
1036 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
1037 /* Do nothing else, just set the attribute. We'll get at
1038 it later with lookup_attribute. */
1040 else
1042 warning (OPT_Wattributes, "%qE attribute ignored", name);
1043 *no_add_attrs = true;
1046 return NULL_TREE;
1049 /* Handle a "used" attribute; arguments as in
1050 struct attribute_spec.handler. */
1052 static tree
1053 handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
1054 int ARG_UNUSED (flags), bool *no_add_attrs)
1056 tree node = *pnode;
1058 if (TREE_CODE (node) == FUNCTION_DECL
1059 || (VAR_P (node) && TREE_STATIC (node))
1060 || (TREE_CODE (node) == TYPE_DECL))
1062 TREE_USED (node) = 1;
1063 DECL_PRESERVE_P (node) = 1;
1064 if (VAR_P (node))
1065 DECL_READ_P (node) = 1;
1067 else
1069 warning (OPT_Wattributes, "%qE attribute ignored", name);
1070 *no_add_attrs = true;
1073 return NULL_TREE;
1076 /* Handle a "unused" attribute; arguments as in
1077 struct attribute_spec.handler. */
1079 tree
1080 handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1081 int flags, bool *no_add_attrs)
1083 if (DECL_P (*node))
1085 tree decl = *node;
1087 if (TREE_CODE (decl) == PARM_DECL
1088 || VAR_OR_FUNCTION_DECL_P (decl)
1089 || TREE_CODE (decl) == LABEL_DECL
1090 || TREE_CODE (decl) == CONST_DECL
1091 || TREE_CODE (decl) == TYPE_DECL)
1093 TREE_USED (decl) = 1;
1094 if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
1095 DECL_READ_P (decl) = 1;
1097 else
1099 warning (OPT_Wattributes, "%qE attribute ignored", name);
1100 *no_add_attrs = true;
1103 else
1105 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1106 *node = build_variant_type_copy (*node);
1107 TREE_USED (*node) = 1;
1110 return NULL_TREE;
1113 /* Handle a "externally_visible" attribute; arguments as in
1114 struct attribute_spec.handler. */
1116 static tree
1117 handle_externally_visible_attribute (tree *pnode, tree name,
1118 tree ARG_UNUSED (args),
1119 int ARG_UNUSED (flags),
1120 bool *no_add_attrs)
1122 tree node = *pnode;
1124 if (VAR_OR_FUNCTION_DECL_P (node))
1126 if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
1127 && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
1129 warning (OPT_Wattributes,
1130 "%qE attribute have effect only on public objects", name);
1131 *no_add_attrs = true;
1134 else
1136 warning (OPT_Wattributes, "%qE attribute ignored", name);
1137 *no_add_attrs = true;
1140 return NULL_TREE;
1143 /* Handle the "no_reorder" attribute. Arguments as in
1144 struct attribute_spec.handler. */
1146 static tree
1147 handle_no_reorder_attribute (tree *pnode,
1148 tree name,
1149 tree,
1150 int,
1151 bool *no_add_attrs)
1153 tree node = *pnode;
1155 if (!VAR_OR_FUNCTION_DECL_P (node)
1156 && !(TREE_STATIC (node) || DECL_EXTERNAL (node)))
1158 warning (OPT_Wattributes,
1159 "%qE attribute only affects top level objects",
1160 name);
1161 *no_add_attrs = true;
1164 return NULL_TREE;
1167 /* Handle a "const" attribute; arguments as in
1168 struct attribute_spec.handler. */
1170 static tree
1171 handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1172 int flags, bool *no_add_attrs)
1174 tree type = TREE_TYPE (*node);
1176 /* See FIXME comment on noreturn in c_common_attribute_table. */
1177 if (TREE_CODE (*node) == FUNCTION_DECL)
1178 TREE_READONLY (*node) = 1;
1179 else if (TREE_CODE (type) == POINTER_TYPE
1180 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1181 TREE_TYPE (*node)
1182 = (build_qualified_type
1183 (build_pointer_type
1184 (build_type_variant (TREE_TYPE (type), 1,
1185 TREE_THIS_VOLATILE (TREE_TYPE (type)))),
1186 TYPE_QUALS (type)));
1187 else
1189 warning (OPT_Wattributes, "%qE attribute ignored", name);
1190 *no_add_attrs = true;
1193 /* void __builtin_unreachable(void) is const. Accept other such
1194 built-ins but warn on user-defined functions that return void. */
1195 if (!(flags & ATTR_FLAG_BUILT_IN)
1196 && TREE_CODE (*node) == FUNCTION_DECL
1197 && VOID_TYPE_P (TREE_TYPE (type)))
1198 warning (OPT_Wattributes, "%qE attribute on function "
1199 "returning %<void%>", name);
1201 return NULL_TREE;
1204 /* Handle a "scalar_storage_order" attribute; arguments as in
1205 struct attribute_spec.handler. */
1207 static tree
1208 handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
1209 int flags, bool *no_add_attrs)
1211 tree id = TREE_VALUE (args);
1212 tree type;
1214 if (TREE_CODE (*node) == TYPE_DECL
1215 && ! (flags & ATTR_FLAG_CXX11))
1216 node = &TREE_TYPE (*node);
1217 type = *node;
1219 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
1221 error ("scalar_storage_order is not supported because endianness "
1222 "is not uniform");
1223 return NULL_TREE;
1226 if (RECORD_OR_UNION_TYPE_P (type) && !c_dialect_cxx ())
1228 bool reverse = false;
1230 if (TREE_CODE (id) == STRING_CST
1231 && strcmp (TREE_STRING_POINTER (id), "big-endian") == 0)
1232 reverse = !BYTES_BIG_ENDIAN;
1233 else if (TREE_CODE (id) == STRING_CST
1234 && strcmp (TREE_STRING_POINTER (id), "little-endian") == 0)
1235 reverse = BYTES_BIG_ENDIAN;
1236 else
1238 error ("scalar_storage_order argument must be one of \"big-endian\""
1239 " or \"little-endian\"");
1240 return NULL_TREE;
1243 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1245 if (reverse)
1246 /* A type variant isn't good enough, since we don't want a cast
1247 to such a type to be removed as a no-op. */
1248 *node = type = build_duplicate_type (type);
1251 TYPE_REVERSE_STORAGE_ORDER (type) = reverse;
1252 return NULL_TREE;
1255 warning (OPT_Wattributes, "%qE attribute ignored", name);
1256 *no_add_attrs = true;
1257 return NULL_TREE;
1260 /* Handle a "transparent_union" attribute; arguments as in
1261 struct attribute_spec.handler. */
1263 static tree
1264 handle_transparent_union_attribute (tree *node, tree name,
1265 tree ARG_UNUSED (args), int flags,
1266 bool *no_add_attrs)
1268 tree type;
1270 *no_add_attrs = true;
1272 if (TREE_CODE (*node) == TYPE_DECL
1273 && ! (flags & ATTR_FLAG_CXX11))
1274 node = &TREE_TYPE (*node);
1275 type = *node;
1277 if (TREE_CODE (type) == UNION_TYPE)
1279 /* Make sure that the first field will work for a transparent union.
1280 If the type isn't complete yet, leave the check to the code in
1281 finish_struct. */
1282 if (TYPE_SIZE (type))
1284 tree first = first_field (type);
1285 if (first == NULL_TREE
1286 || DECL_ARTIFICIAL (first)
1287 || TYPE_MODE (type) != DECL_MODE (first))
1288 goto ignored;
1291 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1293 /* If the type isn't complete yet, setting the flag
1294 on a variant wouldn't ever be checked. */
1295 if (!TYPE_SIZE (type))
1296 goto ignored;
1298 /* build_duplicate_type doesn't work for C++. */
1299 if (c_dialect_cxx ())
1300 goto ignored;
1302 /* A type variant isn't good enough, since we don't want a cast
1303 to such a type to be removed as a no-op. */
1304 *node = type = build_duplicate_type (type);
1307 for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1308 TYPE_TRANSPARENT_AGGR (t) = 1;
1309 return NULL_TREE;
1312 ignored:
1313 warning (OPT_Wattributes, "%qE attribute ignored", name);
1314 return NULL_TREE;
1317 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1318 get the requested priority for a constructor or destructor,
1319 possibly issuing diagnostics for invalid or reserved
1320 priorities. */
1322 static priority_type
1323 get_priority (tree args, bool is_destructor)
1325 HOST_WIDE_INT pri;
1326 tree arg;
1328 if (!args)
1329 return DEFAULT_INIT_PRIORITY;
1331 if (!SUPPORTS_INIT_PRIORITY)
1333 if (is_destructor)
1334 error ("destructor priorities are not supported");
1335 else
1336 error ("constructor priorities are not supported");
1337 return DEFAULT_INIT_PRIORITY;
1340 arg = TREE_VALUE (args);
1341 if (TREE_CODE (arg) == IDENTIFIER_NODE)
1342 goto invalid;
1343 if (arg == error_mark_node)
1344 return DEFAULT_INIT_PRIORITY;
1345 arg = default_conversion (arg);
1346 if (!tree_fits_shwi_p (arg)
1347 || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
1348 goto invalid;
1350 pri = tree_to_shwi (arg);
1351 if (pri < 0 || pri > MAX_INIT_PRIORITY)
1352 goto invalid;
1354 if (pri <= MAX_RESERVED_INIT_PRIORITY)
1356 if (is_destructor)
1357 warning (0,
1358 "destructor priorities from 0 to %d are reserved "
1359 "for the implementation",
1360 MAX_RESERVED_INIT_PRIORITY);
1361 else
1362 warning (0,
1363 "constructor priorities from 0 to %d are reserved "
1364 "for the implementation",
1365 MAX_RESERVED_INIT_PRIORITY);
1367 return pri;
1369 invalid:
1370 if (is_destructor)
1371 error ("destructor priorities must be integers from 0 to %d inclusive",
1372 MAX_INIT_PRIORITY);
1373 else
1374 error ("constructor priorities must be integers from 0 to %d inclusive",
1375 MAX_INIT_PRIORITY);
1376 return DEFAULT_INIT_PRIORITY;
1379 /* Handle a "constructor" attribute; arguments as in
1380 struct attribute_spec.handler. */
1382 static tree
1383 handle_constructor_attribute (tree *node, tree name, tree args,
1384 int ARG_UNUSED (flags),
1385 bool *no_add_attrs)
1387 tree decl = *node;
1388 tree type = TREE_TYPE (decl);
1390 if (TREE_CODE (decl) == FUNCTION_DECL
1391 && TREE_CODE (type) == FUNCTION_TYPE
1392 && decl_function_context (decl) == 0)
1394 priority_type priority;
1395 DECL_STATIC_CONSTRUCTOR (decl) = 1;
1396 priority = get_priority (args, /*is_destructor=*/false);
1397 SET_DECL_INIT_PRIORITY (decl, priority);
1398 TREE_USED (decl) = 1;
1400 else
1402 warning (OPT_Wattributes, "%qE attribute ignored", name);
1403 *no_add_attrs = true;
1406 return NULL_TREE;
1409 /* Handle a "destructor" attribute; arguments as in
1410 struct attribute_spec.handler. */
1412 static tree
1413 handle_destructor_attribute (tree *node, tree name, tree args,
1414 int ARG_UNUSED (flags),
1415 bool *no_add_attrs)
1417 tree decl = *node;
1418 tree type = TREE_TYPE (decl);
1420 if (TREE_CODE (decl) == FUNCTION_DECL
1421 && TREE_CODE (type) == FUNCTION_TYPE
1422 && decl_function_context (decl) == 0)
1424 priority_type priority;
1425 DECL_STATIC_DESTRUCTOR (decl) = 1;
1426 priority = get_priority (args, /*is_destructor=*/true);
1427 SET_DECL_FINI_PRIORITY (decl, priority);
1428 TREE_USED (decl) = 1;
1430 else
1432 warning (OPT_Wattributes, "%qE attribute ignored", name);
1433 *no_add_attrs = true;
1436 return NULL_TREE;
1439 /* Nonzero if the mode is a valid vector mode for this architecture.
1440 This returns nonzero even if there is no hardware support for the
1441 vector mode, but we can emulate with narrower modes. */
1443 static bool
1444 vector_mode_valid_p (machine_mode mode)
1446 enum mode_class mclass = GET_MODE_CLASS (mode);
1448 /* Doh! What's going on? */
1449 if (mclass != MODE_VECTOR_INT
1450 && mclass != MODE_VECTOR_FLOAT
1451 && mclass != MODE_VECTOR_FRACT
1452 && mclass != MODE_VECTOR_UFRACT
1453 && mclass != MODE_VECTOR_ACCUM
1454 && mclass != MODE_VECTOR_UACCUM)
1455 return false;
1457 /* Hardware support. Woo hoo! */
1458 if (targetm.vector_mode_supported_p (mode))
1459 return true;
1461 /* We should probably return 1 if requesting V4DI and we have no DI,
1462 but we have V2DI, but this is probably very unlikely. */
1464 /* If we have support for the inner mode, we can safely emulate it.
1465 We may not have V2DI, but me can emulate with a pair of DIs. */
1466 return targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1470 /* Handle a "mode" attribute; arguments as in
1471 struct attribute_spec.handler. */
1473 static tree
1474 handle_mode_attribute (tree *node, tree name, tree args,
1475 int ARG_UNUSED (flags), bool *no_add_attrs)
1477 tree type = *node;
1478 tree ident = TREE_VALUE (args);
1480 *no_add_attrs = true;
1482 if (TREE_CODE (ident) != IDENTIFIER_NODE)
1483 warning (OPT_Wattributes, "%qE attribute ignored", name);
1484 else
1486 int j;
1487 const char *p = IDENTIFIER_POINTER (ident);
1488 int len = strlen (p);
1489 machine_mode mode = VOIDmode;
1490 tree typefm;
1491 bool valid_mode;
1493 if (len > 4 && p[0] == '_' && p[1] == '_'
1494 && p[len - 1] == '_' && p[len - 2] == '_')
1496 char *newp = (char *) alloca (len - 1);
1498 strcpy (newp, &p[2]);
1499 newp[len - 4] = '\0';
1500 p = newp;
1503 /* Change this type to have a type with the specified mode.
1504 First check for the special modes. */
1505 if (!strcmp (p, "byte"))
1506 mode = byte_mode;
1507 else if (!strcmp (p, "word"))
1508 mode = word_mode;
1509 else if (!strcmp (p, "pointer"))
1510 mode = ptr_mode;
1511 else if (!strcmp (p, "libgcc_cmp_return"))
1512 mode = targetm.libgcc_cmp_return_mode ();
1513 else if (!strcmp (p, "libgcc_shift_count"))
1514 mode = targetm.libgcc_shift_count_mode ();
1515 else if (!strcmp (p, "unwind_word"))
1516 mode = targetm.unwind_word_mode ();
1517 else
1518 for (j = 0; j < NUM_MACHINE_MODES; j++)
1519 if (!strcmp (p, GET_MODE_NAME (j)))
1521 mode = (machine_mode) j;
1522 break;
1525 if (mode == VOIDmode)
1527 error ("unknown machine mode %qE", ident);
1528 return NULL_TREE;
1531 valid_mode = false;
1532 switch (GET_MODE_CLASS (mode))
1534 case MODE_INT:
1535 case MODE_PARTIAL_INT:
1536 case MODE_FLOAT:
1537 case MODE_DECIMAL_FLOAT:
1538 case MODE_FRACT:
1539 case MODE_UFRACT:
1540 case MODE_ACCUM:
1541 case MODE_UACCUM:
1542 valid_mode
1543 = targetm.scalar_mode_supported_p (as_a <scalar_mode> (mode));
1544 break;
1546 case MODE_COMPLEX_INT:
1547 case MODE_COMPLEX_FLOAT:
1548 valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1549 break;
1551 case MODE_VECTOR_INT:
1552 case MODE_VECTOR_FLOAT:
1553 case MODE_VECTOR_FRACT:
1554 case MODE_VECTOR_UFRACT:
1555 case MODE_VECTOR_ACCUM:
1556 case MODE_VECTOR_UACCUM:
1557 warning (OPT_Wattributes, "specifying vector types with "
1558 "__attribute__ ((mode)) is deprecated");
1559 warning (OPT_Wattributes,
1560 "use __attribute__ ((vector_size)) instead");
1561 valid_mode = vector_mode_valid_p (mode);
1562 break;
1564 default:
1565 break;
1567 if (!valid_mode)
1569 error ("unable to emulate %qs", p);
1570 return NULL_TREE;
1573 if (POINTER_TYPE_P (type))
1575 scalar_int_mode addr_mode;
1576 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
1577 tree (*fn)(tree, machine_mode, bool);
1579 if (!is_a <scalar_int_mode> (mode, &addr_mode)
1580 || !targetm.addr_space.valid_pointer_mode (addr_mode, as))
1582 error ("invalid pointer mode %qs", p);
1583 return NULL_TREE;
1586 if (TREE_CODE (type) == POINTER_TYPE)
1587 fn = build_pointer_type_for_mode;
1588 else
1589 fn = build_reference_type_for_mode;
1590 typefm = fn (TREE_TYPE (type), addr_mode, false);
1592 else
1594 /* For fixed-point modes, we need to test if the signness of type
1595 and the machine mode are consistent. */
1596 if (ALL_FIXED_POINT_MODE_P (mode)
1597 && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
1599 error ("signedness of type and machine mode %qs don%'t match", p);
1600 return NULL_TREE;
1602 /* For fixed-point modes, we need to pass saturating info. */
1603 typefm = lang_hooks.types.type_for_mode (mode,
1604 ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
1605 : TYPE_UNSIGNED (type));
1608 if (typefm == NULL_TREE)
1610 error ("no data type for mode %qs", p);
1611 return NULL_TREE;
1613 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1615 /* For enumeral types, copy the precision from the integer
1616 type returned above. If not an INTEGER_TYPE, we can't use
1617 this mode for this type. */
1618 if (TREE_CODE (typefm) != INTEGER_TYPE)
1620 error ("cannot use mode %qs for enumeral types", p);
1621 return NULL_TREE;
1624 if (flags & ATTR_FLAG_TYPE_IN_PLACE)
1626 TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
1627 typefm = type;
1629 else
1631 /* We cannot build a type variant, as there's code that assumes
1632 that TYPE_MAIN_VARIANT has the same mode. This includes the
1633 debug generators. Instead, create a subrange type. This
1634 results in all of the enumeral values being emitted only once
1635 in the original, and the subtype gets them by reference. */
1636 if (TYPE_UNSIGNED (type))
1637 typefm = make_unsigned_type (TYPE_PRECISION (typefm));
1638 else
1639 typefm = make_signed_type (TYPE_PRECISION (typefm));
1640 TREE_TYPE (typefm) = type;
1643 else if (VECTOR_MODE_P (mode)
1644 ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
1645 : TREE_CODE (type) != TREE_CODE (typefm))
1647 error ("mode %qs applied to inappropriate type", p);
1648 return NULL_TREE;
1651 *node = build_qualified_type (typefm, TYPE_QUALS (type));
1654 return NULL_TREE;
1657 /* Handle a "section" attribute; arguments as in
1658 struct attribute_spec.handler. */
1660 static tree
1661 handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
1662 int ARG_UNUSED (flags), bool *no_add_attrs)
1664 tree decl = *node;
1666 if (!targetm_common.have_named_sections)
1668 error_at (DECL_SOURCE_LOCATION (*node),
1669 "section attributes are not supported for this target");
1670 goto fail;
1673 if (!VAR_OR_FUNCTION_DECL_P (decl))
1675 error ("section attribute not allowed for %q+D", *node);
1676 goto fail;
1679 if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
1681 error ("section attribute argument not a string constant");
1682 goto fail;
1685 if (VAR_P (decl)
1686 && current_function_decl != NULL_TREE
1687 && !TREE_STATIC (decl))
1689 error_at (DECL_SOURCE_LOCATION (decl),
1690 "section attribute cannot be specified for local variables");
1691 goto fail;
1694 /* The decl may have already been given a section attribute
1695 from a previous declaration. Ensure they match. */
1696 if (DECL_SECTION_NAME (decl) != NULL
1697 && strcmp (DECL_SECTION_NAME (decl),
1698 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
1700 error ("section of %q+D conflicts with previous declaration", *node);
1701 goto fail;
1704 if (VAR_P (decl)
1705 && !targetm.have_tls && targetm.emutls.tmpl_section
1706 && DECL_THREAD_LOCAL_P (decl))
1708 error ("section of %q+D cannot be overridden", *node);
1709 goto fail;
1712 set_decl_section_name (decl, TREE_STRING_POINTER (TREE_VALUE (args)));
1713 return NULL_TREE;
1715 fail:
1716 *no_add_attrs = true;
1717 return NULL_TREE;
1720 /* If in c++-11, check if the c++-11 alignment constraint with respect
1721 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1722 c++-11 mode, does nothing.
1724 [dcl.align]2/ says:
1726 [* if the constant expression evaluates to a fundamental alignment,
1727 the alignment requirement of the declared entity shall be the
1728 specified fundamental alignment.
1730 * if the constant expression evaluates to an extended alignment
1731 and the implementation supports that alignment in the context
1732 of the declaration, the alignment of the declared entity shall
1733 be that alignment
1735 * if the constant expression evaluates to an extended alignment
1736 and the implementation does not support that alignment in the
1737 context of the declaration, the program is ill-formed]. */
1739 static bool
1740 check_cxx_fundamental_alignment_constraints (tree node,
1741 unsigned align_log,
1742 int flags)
1744 bool alignment_too_large_p = false;
1745 unsigned requested_alignment = (1U << align_log) * BITS_PER_UNIT;
1746 unsigned max_align = 0;
1748 if ((!(flags & ATTR_FLAG_CXX11) && !warn_cxx_compat)
1749 || (node == NULL_TREE || node == error_mark_node))
1750 return true;
1752 if (cxx_fundamental_alignment_p (requested_alignment))
1753 return true;
1755 if (VAR_P (node))
1757 if (TREE_STATIC (node) || DECL_EXTERNAL (node))
1758 /* For file scope variables and static members, the target supports
1759 alignments that are at most MAX_OFILE_ALIGNMENT. */
1760 max_align = MAX_OFILE_ALIGNMENT;
1761 else
1762 /* For stack variables, the target supports at most
1763 MAX_STACK_ALIGNMENT. */
1764 max_align = MAX_STACK_ALIGNMENT;
1765 if (requested_alignment > max_align)
1766 alignment_too_large_p = true;
1768 /* Let's be liberal for types and fields; don't limit their alignment any
1769 more than check_user_alignment already did. */
1771 if (alignment_too_large_p)
1772 pedwarn (input_location, OPT_Wattributes,
1773 "requested alignment %d is larger than %d",
1774 requested_alignment / BITS_PER_UNIT, max_align / BITS_PER_UNIT);
1776 return !alignment_too_large_p;
1779 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1780 handle_aligned_attribute. */
1782 static tree
1783 common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
1784 bool *no_add_attrs,
1785 bool warn_if_not_aligned_p)
1787 tree decl = NULL_TREE;
1788 tree *type = NULL;
1789 bool is_type = false;
1790 tree align_expr;
1792 /* The last (already pushed) declaration with all validated attributes
1793 merged in or the current about-to-be-pushed one if one hasn't been
1794 yet. */
1795 tree last_decl = node[1] ? node[1] : *node;
1797 if (args)
1799 align_expr = TREE_VALUE (args);
1800 if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE
1801 && TREE_CODE (align_expr) != FUNCTION_DECL)
1802 align_expr = default_conversion (align_expr);
1804 else
1805 align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT);
1807 if (DECL_P (*node))
1809 decl = *node;
1810 type = &TREE_TYPE (decl);
1811 is_type = TREE_CODE (*node) == TYPE_DECL;
1813 else if (TYPE_P (*node))
1814 type = node, is_type = true;
1816 /* Log2 of specified alignment. */
1817 int pow2align = check_user_alignment (align_expr, true);
1818 if (pow2align == -1
1819 || !check_cxx_fundamental_alignment_constraints (*node, pow2align, flags))
1821 *no_add_attrs = true;
1822 return NULL_TREE;
1825 /* The alignment in bits corresponding to the specified alignment. */
1826 unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
1828 /* The alignment of the current declaration and that of the last
1829 pushed declaration, determined on demand below. */
1830 unsigned curalign = 0;
1831 unsigned lastalign = 0;
1833 if (is_type)
1835 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1836 /* OK, modify the type in place. */;
1837 /* If we have a TYPE_DECL, then copy the type, so that we
1838 don't accidentally modify a builtin type. See pushdecl. */
1839 else if (decl && TREE_TYPE (decl) != error_mark_node
1840 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
1842 tree tt = TREE_TYPE (decl);
1843 *type = build_variant_type_copy (*type);
1844 DECL_ORIGINAL_TYPE (decl) = tt;
1845 TYPE_NAME (*type) = decl;
1846 TREE_USED (*type) = TREE_USED (decl);
1847 TREE_TYPE (decl) = *type;
1849 else
1850 *type = build_variant_type_copy (*type);
1852 if (warn_if_not_aligned_p)
1854 SET_TYPE_WARN_IF_NOT_ALIGN (*type, bitalign);
1855 warn_if_not_aligned_p = false;
1857 else
1859 SET_TYPE_ALIGN (*type, bitalign);
1860 TYPE_USER_ALIGN (*type) = 1;
1863 else if (! VAR_OR_FUNCTION_DECL_P (decl)
1864 && TREE_CODE (decl) != FIELD_DECL)
1866 error ("alignment may not be specified for %q+D", decl);
1867 *no_add_attrs = true;
1869 else if (TREE_CODE (decl) == FUNCTION_DECL
1870 && ((curalign = DECL_ALIGN (decl)) > bitalign
1871 || ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
1873 /* Either a prior attribute on the same declaration or one
1874 on a prior declaration of the same function specifies
1875 stricter alignment than this attribute. */
1876 bool note = lastalign != 0;
1877 if (lastalign)
1878 curalign = lastalign;
1880 curalign /= BITS_PER_UNIT;
1881 bitalign /= BITS_PER_UNIT;
1883 bool diagd = true;
1884 if (DECL_USER_ALIGN (decl) || DECL_USER_ALIGN (last_decl))
1885 diagd = warning (OPT_Wattributes,
1886 "ignoring attribute %<%E (%u)%> because it conflicts "
1887 "with attribute %<%E (%u)%>",
1888 name, bitalign, name, curalign);
1889 else if (!warn_if_not_aligned_p)
1890 /* Do not error out for attribute warn_if_not_aligned. */
1891 error ("alignment for %q+D must be at least %d", decl, curalign);
1893 if (diagd && note)
1894 inform (DECL_SOURCE_LOCATION (last_decl), "previous declaration here");
1896 *no_add_attrs = true;
1898 else if (DECL_USER_ALIGN (decl)
1899 && DECL_ALIGN (decl) > bitalign)
1900 /* C++-11 [dcl.align/4]:
1902 When multiple alignment-specifiers are specified for an
1903 entity, the alignment requirement shall be set to the
1904 strictest specified alignment.
1906 This formally comes from the c++11 specification but we are
1907 doing it for the GNU attribute syntax as well. */
1908 *no_add_attrs = true;
1909 else if (!warn_if_not_aligned_p
1910 && TREE_CODE (decl) == FUNCTION_DECL
1911 && DECL_ALIGN (decl) > bitalign)
1913 /* Don't warn function alignment here if warn_if_not_aligned_p is
1914 true. It will be warned later. */
1915 if (DECL_USER_ALIGN (decl))
1916 error ("alignment for %q+D was previously specified as %d "
1917 "and may not be decreased", decl,
1918 DECL_ALIGN (decl) / BITS_PER_UNIT);
1919 else
1920 error ("alignment for %q+D must be at least %d", decl,
1921 DECL_ALIGN (decl) / BITS_PER_UNIT);
1922 *no_add_attrs = true;
1924 else
1926 if (warn_if_not_aligned_p)
1928 if (TREE_CODE (decl) == FIELD_DECL && !DECL_C_BIT_FIELD (decl))
1930 SET_DECL_WARN_IF_NOT_ALIGN (decl, bitalign);
1931 warn_if_not_aligned_p = false;
1934 else
1936 SET_DECL_ALIGN (decl, bitalign);
1937 DECL_USER_ALIGN (decl) = 1;
1941 if (warn_if_not_aligned_p)
1943 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1944 decl);
1945 *no_add_attrs = true;
1948 return NULL_TREE;
1951 /* Handle a "aligned" attribute; arguments as in
1952 struct attribute_spec.handler. */
1954 static tree
1955 handle_aligned_attribute (tree *node, tree name, tree args,
1956 int flags, bool *no_add_attrs)
1958 return common_handle_aligned_attribute (node, name, args, flags,
1959 no_add_attrs, false);
1962 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1963 struct attribute_spec.handler. */
1965 static tree
1966 handle_warn_if_not_aligned_attribute (tree *node, tree name,
1967 tree args, int flags,
1968 bool *no_add_attrs)
1970 return common_handle_aligned_attribute (node, name, args, flags,
1971 no_add_attrs, true);
1974 /* Handle a "weak" attribute; arguments as in
1975 struct attribute_spec.handler. */
1977 static tree
1978 handle_weak_attribute (tree *node, tree name,
1979 tree ARG_UNUSED (args),
1980 int ARG_UNUSED (flags),
1981 bool * ARG_UNUSED (no_add_attrs))
1983 if (TREE_CODE (*node) == FUNCTION_DECL
1984 && DECL_DECLARED_INLINE_P (*node))
1986 warning (OPT_Wattributes, "inline function %q+D declared weak", *node);
1987 *no_add_attrs = true;
1989 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
1991 error ("indirect function %q+D cannot be declared weak", *node);
1992 *no_add_attrs = true;
1993 return NULL_TREE;
1995 else if (VAR_OR_FUNCTION_DECL_P (*node))
1996 declare_weak (*node);
1997 else
1998 warning (OPT_Wattributes, "%qE attribute ignored", name);
2000 return NULL_TREE;
2003 /* Handle a "noplt" attribute; arguments as in
2004 struct attribute_spec.handler. */
2006 static tree
2007 handle_noplt_attribute (tree *node, tree name,
2008 tree ARG_UNUSED (args),
2009 int ARG_UNUSED (flags),
2010 bool * ARG_UNUSED (no_add_attrs))
2012 if (TREE_CODE (*node) != FUNCTION_DECL)
2014 warning (OPT_Wattributes,
2015 "%qE attribute is only applicable on functions", name);
2016 *no_add_attrs = true;
2017 return NULL_TREE;
2019 return NULL_TREE;
2022 /* Handle an "alias" or "ifunc" attribute; arguments as in
2023 struct attribute_spec.handler, except that IS_ALIAS tells us
2024 whether this is an alias as opposed to ifunc attribute. */
2026 static tree
2027 handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args,
2028 bool *no_add_attrs)
2030 tree decl = *node;
2032 if (TREE_CODE (decl) != FUNCTION_DECL
2033 && (!is_alias || !VAR_P (decl)))
2035 warning (OPT_Wattributes, "%qE attribute ignored", name);
2036 *no_add_attrs = true;
2038 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
2039 || (TREE_CODE (decl) != FUNCTION_DECL
2040 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
2041 /* A static variable declaration is always a tentative definition,
2042 but the alias is a non-tentative definition which overrides. */
2043 || (TREE_CODE (decl) != FUNCTION_DECL
2044 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
2046 error ("%q+D defined both normally and as %qE attribute", decl, name);
2047 *no_add_attrs = true;
2048 return NULL_TREE;
2050 else if (!is_alias
2051 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2052 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))))
2054 error ("weak %q+D cannot be defined %qE", decl, name);
2055 *no_add_attrs = true;
2056 return NULL_TREE;
2059 /* Note that the very first time we process a nested declaration,
2060 decl_function_context will not be set. Indeed, *would* never
2061 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2062 we do below. After such frobbery, pushdecl would set the context.
2063 In any case, this is never what we want. */
2064 else if (decl_function_context (decl) == 0 && current_function_decl == NULL)
2066 tree id;
2068 id = TREE_VALUE (args);
2069 if (TREE_CODE (id) != STRING_CST)
2071 error ("attribute %qE argument not a string", name);
2072 *no_add_attrs = true;
2073 return NULL_TREE;
2075 id = get_identifier (TREE_STRING_POINTER (id));
2076 /* This counts as a use of the object pointed to. */
2077 TREE_USED (id) = 1;
2079 if (TREE_CODE (decl) == FUNCTION_DECL)
2080 DECL_INITIAL (decl) = error_mark_node;
2081 else
2082 TREE_STATIC (decl) = 1;
2084 if (!is_alias)
2086 /* ifuncs are also aliases, so set that attribute too. */
2087 DECL_ATTRIBUTES (decl)
2088 = tree_cons (get_identifier ("alias"), args,
2089 DECL_ATTRIBUTES (decl));
2090 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("ifunc"),
2091 NULL, DECL_ATTRIBUTES (decl));
2094 else
2096 warning (OPT_Wattributes, "%qE attribute ignored", name);
2097 *no_add_attrs = true;
2100 if (decl_in_symtab_p (*node))
2102 struct symtab_node *n = symtab_node::get (decl);
2103 if (n && n->refuse_visibility_changes)
2105 if (is_alias)
2106 error ("%+qD declared alias after being used", decl);
2107 else
2108 error ("%+qD declared ifunc after being used", decl);
2113 return NULL_TREE;
2116 /* Handle an "alias" or "ifunc" attribute; arguments as in
2117 struct attribute_spec.handler. */
2119 static tree
2120 handle_ifunc_attribute (tree *node, tree name, tree args,
2121 int ARG_UNUSED (flags), bool *no_add_attrs)
2123 return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs);
2126 /* Handle an "alias" or "ifunc" attribute; arguments as in
2127 struct attribute_spec.handler. */
2129 static tree
2130 handle_alias_attribute (tree *node, tree name, tree args,
2131 int ARG_UNUSED (flags), bool *no_add_attrs)
2133 return handle_alias_ifunc_attribute (true, node, name, args, no_add_attrs);
2136 /* Handle a "weakref" attribute; arguments as in struct
2137 attribute_spec.handler. */
2139 static tree
2140 handle_weakref_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2141 int flags, bool *no_add_attrs)
2143 tree attr = NULL_TREE;
2145 /* We must ignore the attribute when it is associated with
2146 local-scoped decls, since attribute alias is ignored and many
2147 such symbols do not even have a DECL_WEAK field. */
2148 if (decl_function_context (*node)
2149 || current_function_decl
2150 || !VAR_OR_FUNCTION_DECL_P (*node))
2152 warning (OPT_Wattributes, "%qE attribute ignored", name);
2153 *no_add_attrs = true;
2154 return NULL_TREE;
2157 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
2159 error ("indirect function %q+D cannot be declared weakref", *node);
2160 *no_add_attrs = true;
2161 return NULL_TREE;
2164 /* The idea here is that `weakref("name")' mutates into `weakref,
2165 alias("name")', and weakref without arguments, in turn,
2166 implicitly adds weak. */
2168 if (args)
2170 attr = tree_cons (get_identifier ("alias"), args, attr);
2171 attr = tree_cons (get_identifier ("weakref"), NULL_TREE, attr);
2173 *no_add_attrs = true;
2175 decl_attributes (node, attr, flags);
2177 else
2179 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node)))
2180 error_at (DECL_SOURCE_LOCATION (*node),
2181 "weakref attribute must appear before alias attribute");
2183 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2184 and that isn't supported; and because it wants to add it to
2185 the list of weak decls, which isn't helpful. */
2186 DECL_WEAK (*node) = 1;
2189 if (decl_in_symtab_p (*node))
2191 struct symtab_node *n = symtab_node::get (*node);
2192 if (n && n->refuse_visibility_changes)
2193 error ("%+qD declared weakref after being used", *node);
2196 return NULL_TREE;
2199 /* Handle an "visibility" attribute; arguments as in
2200 struct attribute_spec.handler. */
2202 static tree
2203 handle_visibility_attribute (tree *node, tree name, tree args,
2204 int ARG_UNUSED (flags),
2205 bool *ARG_UNUSED (no_add_attrs))
2207 tree decl = *node;
2208 tree id = TREE_VALUE (args);
2209 enum symbol_visibility vis;
2211 if (TYPE_P (*node))
2213 if (TREE_CODE (*node) == ENUMERAL_TYPE)
2214 /* OK */;
2215 else if (!RECORD_OR_UNION_TYPE_P (*node))
2217 warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
2218 name);
2219 return NULL_TREE;
2221 else if (TYPE_FIELDS (*node))
2223 error ("%qE attribute ignored because %qT is already defined",
2224 name, *node);
2225 return NULL_TREE;
2228 else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
2230 warning (OPT_Wattributes, "%qE attribute ignored", name);
2231 return NULL_TREE;
2234 if (TREE_CODE (id) != STRING_CST)
2236 error ("visibility argument not a string");
2237 return NULL_TREE;
2240 /* If this is a type, set the visibility on the type decl. */
2241 if (TYPE_P (decl))
2243 decl = TYPE_NAME (decl);
2244 if (!decl)
2245 return NULL_TREE;
2246 if (TREE_CODE (decl) == IDENTIFIER_NODE)
2248 warning (OPT_Wattributes, "%qE attribute ignored on types",
2249 name);
2250 return NULL_TREE;
2254 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
2255 vis = VISIBILITY_DEFAULT;
2256 else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
2257 vis = VISIBILITY_INTERNAL;
2258 else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
2259 vis = VISIBILITY_HIDDEN;
2260 else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
2261 vis = VISIBILITY_PROTECTED;
2262 else
2264 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2265 vis = VISIBILITY_DEFAULT;
2268 if (DECL_VISIBILITY_SPECIFIED (decl)
2269 && vis != DECL_VISIBILITY (decl))
2271 tree attributes = (TYPE_P (*node)
2272 ? TYPE_ATTRIBUTES (*node)
2273 : DECL_ATTRIBUTES (decl));
2274 if (lookup_attribute ("visibility", attributes))
2275 error ("%qD redeclared with different visibility", decl);
2276 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2277 && lookup_attribute ("dllimport", attributes))
2278 error ("%qD was declared %qs which implies default visibility",
2279 decl, "dllimport");
2280 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2281 && lookup_attribute ("dllexport", attributes))
2282 error ("%qD was declared %qs which implies default visibility",
2283 decl, "dllexport");
2286 DECL_VISIBILITY (decl) = vis;
2287 DECL_VISIBILITY_SPECIFIED (decl) = 1;
2289 /* Go ahead and attach the attribute to the node as well. This is needed
2290 so we can determine whether we have VISIBILITY_DEFAULT because the
2291 visibility was not specified, or because it was explicitly overridden
2292 from the containing scope. */
2294 return NULL_TREE;
2297 /* Handle an "tls_model" attribute; arguments as in
2298 struct attribute_spec.handler. */
2300 static tree
2301 handle_tls_model_attribute (tree *node, tree name, tree args,
2302 int ARG_UNUSED (flags), bool *no_add_attrs)
2304 tree id;
2305 tree decl = *node;
2306 enum tls_model kind;
2308 *no_add_attrs = true;
2310 if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
2312 warning (OPT_Wattributes, "%qE attribute ignored", name);
2313 return NULL_TREE;
2316 kind = DECL_TLS_MODEL (decl);
2317 id = TREE_VALUE (args);
2318 if (TREE_CODE (id) != STRING_CST)
2320 error ("tls_model argument not a string");
2321 return NULL_TREE;
2324 if (!strcmp (TREE_STRING_POINTER (id), "local-exec"))
2325 kind = TLS_MODEL_LOCAL_EXEC;
2326 else if (!strcmp (TREE_STRING_POINTER (id), "initial-exec"))
2327 kind = TLS_MODEL_INITIAL_EXEC;
2328 else if (!strcmp (TREE_STRING_POINTER (id), "local-dynamic"))
2329 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
2330 else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
2331 kind = TLS_MODEL_GLOBAL_DYNAMIC;
2332 else
2333 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2335 set_decl_tls_model (decl, kind);
2336 return NULL_TREE;
2339 /* Handle a "no_instrument_function" attribute; arguments as in
2340 struct attribute_spec.handler. */
2342 static tree
2343 handle_no_instrument_function_attribute (tree *node, tree name,
2344 tree ARG_UNUSED (args),
2345 int ARG_UNUSED (flags),
2346 bool *no_add_attrs)
2348 tree decl = *node;
2350 if (TREE_CODE (decl) != FUNCTION_DECL)
2352 error_at (DECL_SOURCE_LOCATION (decl),
2353 "%qE attribute applies only to functions", name);
2354 *no_add_attrs = true;
2356 else
2357 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
2359 return NULL_TREE;
2362 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2363 struct attribute_spec.handler. */
2365 static tree
2366 handle_no_profile_instrument_function_attribute (tree *node, tree name, tree,
2367 int, bool *no_add_attrs)
2369 if (TREE_CODE (*node) != FUNCTION_DECL)
2371 warning (OPT_Wattributes, "%qE attribute ignored", name);
2372 *no_add_attrs = true;
2375 return NULL_TREE;
2378 /* Handle a "malloc" attribute; arguments as in
2379 struct attribute_spec.handler. */
2381 static tree
2382 handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2383 int ARG_UNUSED (flags), bool *no_add_attrs)
2385 if (TREE_CODE (*node) == FUNCTION_DECL
2386 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
2387 DECL_IS_MALLOC (*node) = 1;
2388 else
2390 warning (OPT_Wattributes, "%qE attribute ignored", name);
2391 *no_add_attrs = true;
2394 return NULL_TREE;
2397 /* Handle a "alloc_size" attribute; arguments as in
2398 struct attribute_spec.handler. */
2400 static tree
2401 handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2402 int ARG_UNUSED (flags), bool *no_add_attrs)
2404 unsigned arg_count = type_num_arguments (*node);
2405 for (; args; args = TREE_CHAIN (args))
2407 tree position = TREE_VALUE (args);
2408 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2409 && TREE_CODE (position) != FUNCTION_DECL)
2410 position = default_conversion (position);
2412 if (!tree_fits_uhwi_p (position)
2413 || !arg_count
2414 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2416 warning (OPT_Wattributes,
2417 "alloc_size parameter outside range");
2418 *no_add_attrs = true;
2419 return NULL_TREE;
2422 return NULL_TREE;
2425 /* Handle a "alloc_align" attribute; arguments as in
2426 struct attribute_spec.handler. */
2428 static tree
2429 handle_alloc_align_attribute (tree *node, tree, tree args, int,
2430 bool *no_add_attrs)
2432 unsigned arg_count = type_num_arguments (*node);
2433 tree position = TREE_VALUE (args);
2434 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2435 && TREE_CODE (position) != FUNCTION_DECL)
2436 position = default_conversion (position);
2438 if (!tree_fits_uhwi_p (position)
2439 || !arg_count
2440 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2442 warning (OPT_Wattributes,
2443 "alloc_align parameter outside range");
2444 *no_add_attrs = true;
2445 return NULL_TREE;
2447 return NULL_TREE;
2450 /* Handle a "assume_aligned" attribute; arguments as in
2451 struct attribute_spec.handler. */
2453 static tree
2454 handle_assume_aligned_attribute (tree *, tree, tree args, int,
2455 bool *no_add_attrs)
2457 for (; args; args = TREE_CHAIN (args))
2459 tree position = TREE_VALUE (args);
2460 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2461 && TREE_CODE (position) != FUNCTION_DECL)
2462 position = default_conversion (position);
2464 if (TREE_CODE (position) != INTEGER_CST)
2466 warning (OPT_Wattributes,
2467 "assume_aligned parameter not integer constant");
2468 *no_add_attrs = true;
2469 return NULL_TREE;
2472 return NULL_TREE;
2475 /* Handle a "fn spec" attribute; arguments as in
2476 struct attribute_spec.handler. */
2478 static tree
2479 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
2480 tree args, int ARG_UNUSED (flags),
2481 bool *no_add_attrs ATTRIBUTE_UNUSED)
2483 gcc_assert (args
2484 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
2485 && !TREE_CHAIN (args));
2486 return NULL_TREE;
2489 /* Handle a "bnd_variable_size" attribute; arguments as in
2490 struct attribute_spec.handler. */
2492 static tree
2493 handle_bnd_variable_size_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2494 int ARG_UNUSED (flags), bool *no_add_attrs)
2496 if (TREE_CODE (*node) != FIELD_DECL)
2498 warning (OPT_Wattributes, "%qE attribute ignored", name);
2499 *no_add_attrs = true;
2502 return NULL_TREE;
2505 /* Handle a "bnd_legacy" attribute; arguments as in
2506 struct attribute_spec.handler. */
2508 static tree
2509 handle_bnd_legacy (tree *node, tree name, tree ARG_UNUSED (args),
2510 int ARG_UNUSED (flags), bool *no_add_attrs)
2512 if (TREE_CODE (*node) != FUNCTION_DECL)
2514 warning (OPT_Wattributes, "%qE attribute ignored", name);
2515 *no_add_attrs = true;
2518 return NULL_TREE;
2521 /* Handle a "bnd_instrument" attribute; arguments as in
2522 struct attribute_spec.handler. */
2524 static tree
2525 handle_bnd_instrument (tree *node, tree name, tree ARG_UNUSED (args),
2526 int ARG_UNUSED (flags), bool *no_add_attrs)
2528 if (TREE_CODE (*node) != FUNCTION_DECL)
2530 warning (OPT_Wattributes, "%qE attribute ignored", name);
2531 *no_add_attrs = true;
2534 return NULL_TREE;
2537 /* Handle a "warn_unused" attribute; arguments as in
2538 struct attribute_spec.handler. */
2540 static tree
2541 handle_warn_unused_attribute (tree *node, tree name,
2542 tree args ATTRIBUTE_UNUSED,
2543 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2545 if (TYPE_P (*node))
2546 /* Do nothing else, just set the attribute. We'll get at
2547 it later with lookup_attribute. */
2549 else
2551 warning (OPT_Wattributes, "%qE attribute ignored", name);
2552 *no_add_attrs = true;
2555 return NULL_TREE;
2558 /* Handle an "omp declare simd" attribute; arguments as in
2559 struct attribute_spec.handler. */
2561 static tree
2562 handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *)
2564 return NULL_TREE;
2567 /* Handle a "simd" attribute. */
2569 static tree
2570 handle_simd_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs)
2572 if (TREE_CODE (*node) == FUNCTION_DECL)
2574 tree t = get_identifier ("omp declare simd");
2575 tree attr = NULL_TREE;
2576 if (args)
2578 tree id = TREE_VALUE (args);
2580 if (TREE_CODE (id) != STRING_CST)
2582 error ("attribute %qE argument not a string", name);
2583 *no_add_attrs = true;
2584 return NULL_TREE;
2587 if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
2588 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2589 OMP_CLAUSE_NOTINBRANCH);
2590 else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
2591 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2592 OMP_CLAUSE_INBRANCH);
2593 else
2595 error ("only %<inbranch%> and %<notinbranch%> flags are "
2596 "allowed for %<__simd__%> attribute");
2597 *no_add_attrs = true;
2598 return NULL_TREE;
2602 DECL_ATTRIBUTES (*node)
2603 = tree_cons (t, build_tree_list (NULL_TREE, attr),
2604 DECL_ATTRIBUTES (*node));
2606 else
2608 warning (OPT_Wattributes, "%qE attribute ignored", name);
2609 *no_add_attrs = true;
2612 return NULL_TREE;
2615 /* Handle an "omp declare target" attribute; arguments as in
2616 struct attribute_spec.handler. */
2618 static tree
2619 handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
2621 return NULL_TREE;
2624 /* Handle a "returns_twice" attribute; arguments as in
2625 struct attribute_spec.handler. */
2627 static tree
2628 handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2629 int ARG_UNUSED (flags), bool *no_add_attrs)
2631 if (TREE_CODE (*node) == FUNCTION_DECL)
2632 DECL_IS_RETURNS_TWICE (*node) = 1;
2633 else
2635 warning (OPT_Wattributes, "%qE attribute ignored", name);
2636 *no_add_attrs = true;
2639 return NULL_TREE;
2642 /* Handle a "no_limit_stack" attribute; arguments as in
2643 struct attribute_spec.handler. */
2645 static tree
2646 handle_no_limit_stack_attribute (tree *node, tree name,
2647 tree ARG_UNUSED (args),
2648 int ARG_UNUSED (flags),
2649 bool *no_add_attrs)
2651 tree decl = *node;
2653 if (TREE_CODE (decl) != FUNCTION_DECL)
2655 error_at (DECL_SOURCE_LOCATION (decl),
2656 "%qE attribute applies only to functions", name);
2657 *no_add_attrs = true;
2659 else if (DECL_INITIAL (decl))
2661 error_at (DECL_SOURCE_LOCATION (decl),
2662 "can%'t set %qE attribute after definition", name);
2663 *no_add_attrs = true;
2665 else
2666 DECL_NO_LIMIT_STACK (decl) = 1;
2668 return NULL_TREE;
2671 /* Handle a "pure" attribute; arguments as in
2672 struct attribute_spec.handler. */
2674 static tree
2675 handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2676 int ARG_UNUSED (flags), bool *no_add_attrs)
2678 if (TREE_CODE (*node) == FUNCTION_DECL)
2680 tree type = TREE_TYPE (*node);
2681 if (VOID_TYPE_P (TREE_TYPE (type)))
2682 warning (OPT_Wattributes, "%qE attribute on function "
2683 "returning %<void%>", name);
2685 DECL_PURE_P (*node) = 1;
2686 /* ??? TODO: Support types. */
2688 else
2690 warning (OPT_Wattributes, "%qE attribute ignored", name);
2691 *no_add_attrs = true;
2694 return NULL_TREE;
2697 /* Digest an attribute list destined for a transactional memory statement.
2698 ALLOWED is the set of attributes that are allowed for this statement;
2699 return the attribute we parsed. Multiple attributes are never allowed. */
2702 parse_tm_stmt_attr (tree attrs, int allowed)
2704 tree a_seen = NULL;
2705 int m_seen = 0;
2707 for ( ; attrs ; attrs = TREE_CHAIN (attrs))
2709 tree a = TREE_PURPOSE (attrs);
2710 int m = 0;
2712 if (is_attribute_p ("outer", a))
2713 m = TM_STMT_ATTR_OUTER;
2715 if ((m & allowed) == 0)
2717 warning (OPT_Wattributes, "%qE attribute directive ignored", a);
2718 continue;
2721 if (m_seen == 0)
2723 a_seen = a;
2724 m_seen = m;
2726 else if (m_seen == m)
2727 warning (OPT_Wattributes, "%qE attribute duplicated", a);
2728 else
2729 warning (OPT_Wattributes, "%qE attribute follows %qE", a, a_seen);
2732 return m_seen;
2735 /* Transform a TM attribute name into a maskable integer and back.
2736 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2737 to how the lack of an attribute is treated. */
2740 tm_attr_to_mask (tree attr)
2742 if (attr == NULL)
2743 return 0;
2744 if (is_attribute_p ("transaction_safe", attr))
2745 return TM_ATTR_SAFE;
2746 if (is_attribute_p ("transaction_callable", attr))
2747 return TM_ATTR_CALLABLE;
2748 if (is_attribute_p ("transaction_pure", attr))
2749 return TM_ATTR_PURE;
2750 if (is_attribute_p ("transaction_unsafe", attr))
2751 return TM_ATTR_IRREVOCABLE;
2752 if (is_attribute_p ("transaction_may_cancel_outer", attr))
2753 return TM_ATTR_MAY_CANCEL_OUTER;
2754 return 0;
2757 tree
2758 tm_mask_to_attr (int mask)
2760 const char *str;
2761 switch (mask)
2763 case TM_ATTR_SAFE:
2764 str = "transaction_safe";
2765 break;
2766 case TM_ATTR_CALLABLE:
2767 str = "transaction_callable";
2768 break;
2769 case TM_ATTR_PURE:
2770 str = "transaction_pure";
2771 break;
2772 case TM_ATTR_IRREVOCABLE:
2773 str = "transaction_unsafe";
2774 break;
2775 case TM_ATTR_MAY_CANCEL_OUTER:
2776 str = "transaction_may_cancel_outer";
2777 break;
2778 default:
2779 gcc_unreachable ();
2781 return get_identifier (str);
2784 /* Return the first TM attribute seen in LIST. */
2786 tree
2787 find_tm_attribute (tree list)
2789 for (; list ; list = TREE_CHAIN (list))
2791 tree name = TREE_PURPOSE (list);
2792 if (tm_attr_to_mask (name) != 0)
2793 return name;
2795 return NULL_TREE;
2798 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2799 Here we accept only function types, and verify that none of the other
2800 function TM attributes are also applied. */
2801 /* ??? We need to accept class types for C++, but not C. This greatly
2802 complicates this function, since we can no longer rely on the extra
2803 processing given by function_type_required. */
2805 static tree
2806 handle_tm_attribute (tree *node, tree name, tree args,
2807 int flags, bool *no_add_attrs)
2809 /* Only one path adds the attribute; others don't. */
2810 *no_add_attrs = true;
2812 switch (TREE_CODE (*node))
2814 case RECORD_TYPE:
2815 case UNION_TYPE:
2816 /* Only tm_callable and tm_safe apply to classes. */
2817 if (tm_attr_to_mask (name) & ~(TM_ATTR_SAFE | TM_ATTR_CALLABLE))
2818 goto ignored;
2819 /* FALLTHRU */
2821 case FUNCTION_TYPE:
2822 case METHOD_TYPE:
2824 tree old_name = find_tm_attribute (TYPE_ATTRIBUTES (*node));
2825 if (old_name == name)
2827 else if (old_name != NULL_TREE)
2828 error ("type was previously declared %qE", old_name);
2829 else
2830 *no_add_attrs = false;
2832 break;
2834 case FUNCTION_DECL:
2836 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2837 want to set transaction_safe on the type. */
2838 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name));
2839 if (!TYPE_P (DECL_CONTEXT (*node)))
2840 error_at (DECL_SOURCE_LOCATION (*node),
2841 "%<transaction_safe_dynamic%> may only be specified for "
2842 "a virtual function");
2843 *no_add_attrs = false;
2844 decl_attributes (&TREE_TYPE (*node),
2845 build_tree_list (get_identifier ("transaction_safe"),
2846 NULL_TREE),
2848 break;
2851 case POINTER_TYPE:
2853 enum tree_code subcode = TREE_CODE (TREE_TYPE (*node));
2854 if (subcode == FUNCTION_TYPE || subcode == METHOD_TYPE)
2856 tree fn_tmp = TREE_TYPE (*node);
2857 decl_attributes (&fn_tmp, tree_cons (name, args, NULL), 0);
2858 *node = build_pointer_type (fn_tmp);
2859 break;
2862 /* FALLTHRU */
2864 default:
2865 /* If a function is next, pass it on to be tried next. */
2866 if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
2867 return tree_cons (name, args, NULL);
2869 ignored:
2870 warning (OPT_Wattributes, "%qE attribute ignored", name);
2871 break;
2874 return NULL_TREE;
2877 /* Handle the TM_WRAP attribute; arguments as in
2878 struct attribute_spec.handler. */
2880 static tree
2881 handle_tm_wrap_attribute (tree *node, tree name, tree args,
2882 int ARG_UNUSED (flags), bool *no_add_attrs)
2884 tree decl = *node;
2886 /* We don't need the attribute even on success, since we
2887 record the entry in an external table. */
2888 *no_add_attrs = true;
2890 if (TREE_CODE (decl) != FUNCTION_DECL)
2891 warning (OPT_Wattributes, "%qE attribute ignored", name);
2892 else
2894 tree wrap_decl = TREE_VALUE (args);
2895 if (error_operand_p (wrap_decl))
2897 else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
2898 && !VAR_OR_FUNCTION_DECL_P (wrap_decl))
2899 error ("%qE argument not an identifier", name);
2900 else
2902 if (TREE_CODE (wrap_decl) == IDENTIFIER_NODE)
2903 wrap_decl = lookup_name (wrap_decl);
2904 if (wrap_decl && TREE_CODE (wrap_decl) == FUNCTION_DECL)
2906 if (lang_hooks.types_compatible_p (TREE_TYPE (decl),
2907 TREE_TYPE (wrap_decl)))
2908 record_tm_replacement (wrap_decl, decl);
2909 else
2910 error ("%qD is not compatible with %qD", wrap_decl, decl);
2912 else
2913 error ("%qE argument is not a function", name);
2917 return NULL_TREE;
2920 /* Ignore the given attribute. Used when this attribute may be usefully
2921 overridden by the target, but is not used generically. */
2923 static tree
2924 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
2925 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2926 bool *no_add_attrs)
2928 *no_add_attrs = true;
2929 return NULL_TREE;
2932 /* Handle a "no vops" attribute; arguments as in
2933 struct attribute_spec.handler. */
2935 static tree
2936 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
2937 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2938 bool *ARG_UNUSED (no_add_attrs))
2940 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
2941 DECL_IS_NOVOPS (*node) = 1;
2942 return NULL_TREE;
2945 /* Handle a "deprecated" attribute; arguments as in
2946 struct attribute_spec.handler. */
2948 static tree
2949 handle_deprecated_attribute (tree *node, tree name,
2950 tree args, int flags,
2951 bool *no_add_attrs)
2953 tree type = NULL_TREE;
2954 int warn = 0;
2955 tree what = NULL_TREE;
2957 if (!args)
2958 *no_add_attrs = true;
2959 else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
2961 error ("deprecated message is not a string");
2962 *no_add_attrs = true;
2965 if (DECL_P (*node))
2967 tree decl = *node;
2968 type = TREE_TYPE (decl);
2970 if (TREE_CODE (decl) == TYPE_DECL
2971 || TREE_CODE (decl) == PARM_DECL
2972 || VAR_OR_FUNCTION_DECL_P (decl)
2973 || TREE_CODE (decl) == FIELD_DECL
2974 || TREE_CODE (decl) == CONST_DECL
2975 || objc_method_decl (TREE_CODE (decl)))
2976 TREE_DEPRECATED (decl) = 1;
2977 else
2978 warn = 1;
2980 else if (TYPE_P (*node))
2982 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
2983 *node = build_variant_type_copy (*node);
2984 TREE_DEPRECATED (*node) = 1;
2985 type = *node;
2987 else
2988 warn = 1;
2990 if (warn)
2992 *no_add_attrs = true;
2993 if (type && TYPE_NAME (type))
2995 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2996 what = TYPE_NAME (*node);
2997 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2998 && DECL_NAME (TYPE_NAME (type)))
2999 what = DECL_NAME (TYPE_NAME (type));
3001 if (what)
3002 warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
3003 else
3004 warning (OPT_Wattributes, "%qE attribute ignored", name);
3007 return NULL_TREE;
3010 /* Handle a "vector_size" attribute; arguments as in
3011 struct attribute_spec.handler. */
3013 static tree
3014 handle_vector_size_attribute (tree *node, tree name, tree args,
3015 int ARG_UNUSED (flags),
3016 bool *no_add_attrs)
3018 unsigned HOST_WIDE_INT vecsize, nunits;
3019 machine_mode orig_mode;
3020 tree type = *node, new_type, size;
3022 *no_add_attrs = true;
3024 size = TREE_VALUE (args);
3025 if (size && TREE_CODE (size) != IDENTIFIER_NODE
3026 && TREE_CODE (size) != FUNCTION_DECL)
3027 size = default_conversion (size);
3029 if (!tree_fits_uhwi_p (size))
3031 warning (OPT_Wattributes, "%qE attribute ignored", name);
3032 return NULL_TREE;
3035 /* Get the vector size (in bytes). */
3036 vecsize = tree_to_uhwi (size);
3038 /* We need to provide for vector pointers, vector arrays, and
3039 functions returning vectors. For example:
3041 __attribute__((vector_size(16))) short *foo;
3043 In this case, the mode is SI, but the type being modified is
3044 HI, so we need to look further. */
3046 while (POINTER_TYPE_P (type)
3047 || TREE_CODE (type) == FUNCTION_TYPE
3048 || TREE_CODE (type) == METHOD_TYPE
3049 || TREE_CODE (type) == ARRAY_TYPE
3050 || TREE_CODE (type) == OFFSET_TYPE)
3051 type = TREE_TYPE (type);
3053 /* Get the mode of the type being modified. */
3054 orig_mode = TYPE_MODE (type);
3056 if ((!INTEGRAL_TYPE_P (type)
3057 && !SCALAR_FLOAT_TYPE_P (type)
3058 && !FIXED_POINT_TYPE_P (type))
3059 || (!SCALAR_FLOAT_MODE_P (orig_mode)
3060 && GET_MODE_CLASS (orig_mode) != MODE_INT
3061 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
3062 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
3063 || TREE_CODE (type) == BOOLEAN_TYPE)
3065 error ("invalid vector type for attribute %qE", name);
3066 return NULL_TREE;
3069 if (vecsize % tree_to_uhwi (TYPE_SIZE_UNIT (type)))
3071 error ("vector size not an integral multiple of component size");
3072 return NULL;
3075 if (vecsize == 0)
3077 error ("zero vector size");
3078 return NULL;
3081 /* Calculate how many units fit in the vector. */
3082 nunits = vecsize / tree_to_uhwi (TYPE_SIZE_UNIT (type));
3083 if (nunits & (nunits - 1))
3085 error ("number of components of the vector not a power of two");
3086 return NULL_TREE;
3089 new_type = build_vector_type (type, nunits);
3091 /* Build back pointers if needed. */
3092 *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
3094 return NULL_TREE;
3097 /* Handle the "nonnull" attribute. */
3099 static tree
3100 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
3101 tree args, int ARG_UNUSED (flags),
3102 bool *no_add_attrs)
3104 tree type = *node;
3105 unsigned HOST_WIDE_INT attr_arg_num;
3107 /* If no arguments are specified, all pointer arguments should be
3108 non-null. Verify a full prototype is given so that the arguments
3109 will have the correct types when we actually check them later.
3110 Avoid diagnosing type-generic built-ins since those have no
3111 prototype. */
3112 if (!args)
3114 if (!prototype_p (type)
3115 && (!TYPE_ATTRIBUTES (type)
3116 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type))))
3118 error ("nonnull attribute without arguments on a non-prototype");
3119 *no_add_attrs = true;
3121 return NULL_TREE;
3124 /* Argument list specified. Verify that each argument number references
3125 a pointer argument. */
3126 for (attr_arg_num = 1; args; attr_arg_num++, args = TREE_CHAIN (args))
3128 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
3130 tree arg = TREE_VALUE (args);
3131 if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
3132 && TREE_CODE (arg) != FUNCTION_DECL)
3133 TREE_VALUE (args) = arg = default_conversion (arg);
3135 if (!get_nonnull_operand (arg, &arg_num))
3137 error ("nonnull argument has invalid operand number (argument %lu)",
3138 (unsigned long) attr_arg_num);
3139 *no_add_attrs = true;
3140 return NULL_TREE;
3143 if (prototype_p (type))
3145 function_args_iterator iter;
3146 tree argument;
3148 function_args_iter_init (&iter, type);
3149 for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter))
3151 argument = function_args_iter_cond (&iter);
3152 if (argument == NULL_TREE || ck_num == arg_num)
3153 break;
3156 if (!argument
3157 || TREE_CODE (argument) == VOID_TYPE)
3159 error ("nonnull argument with out-of-range operand number "
3160 "(argument %lu, operand %lu)",
3161 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3162 *no_add_attrs = true;
3163 return NULL_TREE;
3166 if (TREE_CODE (argument) != POINTER_TYPE)
3168 error ("nonnull argument references non-pointer operand "
3169 "(argument %lu, operand %lu)",
3170 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3171 *no_add_attrs = true;
3172 return NULL_TREE;
3177 return NULL_TREE;
3180 /* Handle the "nonstring" variable attribute. */
3182 static tree
3183 handle_nonstring_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3184 int ARG_UNUSED (flags), bool *no_add_attrs)
3186 gcc_assert (!args);
3187 tree_code code = TREE_CODE (*node);
3189 if (VAR_P (*node)
3190 || code == FIELD_DECL
3191 || code == PARM_DECL)
3193 tree type = TREE_TYPE (*node);
3195 if (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
3197 /* Accept the attribute on arrays and pointers to all three
3198 narrow character types. */
3199 tree eltype = TREE_TYPE (type);
3200 eltype = TYPE_MAIN_VARIANT (eltype);
3201 if (eltype == char_type_node
3202 || eltype == signed_char_type_node
3203 || eltype == unsigned_char_type_node)
3204 return NULL_TREE;
3207 warning (OPT_Wattributes,
3208 "%qE attribute ignored on objects of type %qT",
3209 name, type);
3210 *no_add_attrs = true;
3211 return NULL_TREE;
3214 if (code == FUNCTION_DECL)
3215 warning (OPT_Wattributes,
3216 "%qE attribute does not apply to functions", name);
3217 else if (code == TYPE_DECL)
3218 warning (OPT_Wattributes,
3219 "%qE attribute does not apply to types", name);
3220 else
3221 warning (OPT_Wattributes, "%qE attribute ignored", name);
3223 *no_add_attrs = true;
3224 return NULL_TREE;
3227 /* Handle a "nothrow" attribute; arguments as in
3228 struct attribute_spec.handler. */
3230 static tree
3231 handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3232 int ARG_UNUSED (flags), bool *no_add_attrs)
3234 if (TREE_CODE (*node) == FUNCTION_DECL)
3235 TREE_NOTHROW (*node) = 1;
3236 /* ??? TODO: Support types. */
3237 else
3239 warning (OPT_Wattributes, "%qE attribute ignored", name);
3240 *no_add_attrs = true;
3243 return NULL_TREE;
3246 /* Handle a "cleanup" attribute; arguments as in
3247 struct attribute_spec.handler. */
3249 static tree
3250 handle_cleanup_attribute (tree *node, tree name, tree args,
3251 int ARG_UNUSED (flags), bool *no_add_attrs)
3253 tree decl = *node;
3254 tree cleanup_id, cleanup_decl;
3256 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3257 for global destructors in C++. This requires infrastructure that
3258 we don't have generically at the moment. It's also not a feature
3259 we'd be missing too much, since we do have attribute constructor. */
3260 if (!VAR_P (decl) || TREE_STATIC (decl))
3262 warning (OPT_Wattributes, "%qE attribute ignored", name);
3263 *no_add_attrs = true;
3264 return NULL_TREE;
3267 /* Verify that the argument is a function in scope. */
3268 /* ??? We could support pointers to functions here as well, if
3269 that was considered desirable. */
3270 cleanup_id = TREE_VALUE (args);
3271 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
3273 error ("cleanup argument not an identifier");
3274 *no_add_attrs = true;
3275 return NULL_TREE;
3277 cleanup_decl = lookup_name (cleanup_id);
3278 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
3280 error ("cleanup argument not a function");
3281 *no_add_attrs = true;
3282 return NULL_TREE;
3285 /* That the function has proper type is checked with the
3286 eventual call to build_function_call. */
3288 return NULL_TREE;
3291 /* Handle a "warn_unused_result" attribute. No special handling. */
3293 static tree
3294 handle_warn_unused_result_attribute (tree *node, tree name,
3295 tree ARG_UNUSED (args),
3296 int ARG_UNUSED (flags), bool *no_add_attrs)
3298 /* Ignore the attribute for functions not returning any value. */
3299 if (VOID_TYPE_P (TREE_TYPE (*node)))
3301 warning (OPT_Wattributes, "%qE attribute ignored", name);
3302 *no_add_attrs = true;
3305 return NULL_TREE;
3308 /* Handle a "sentinel" attribute. */
3310 static tree
3311 handle_sentinel_attribute (tree *node, tree name, tree args,
3312 int ARG_UNUSED (flags), bool *no_add_attrs)
3314 if (!prototype_p (*node))
3316 warning (OPT_Wattributes,
3317 "%qE attribute requires prototypes with named arguments", name);
3318 *no_add_attrs = true;
3320 else
3322 if (!stdarg_p (*node))
3324 warning (OPT_Wattributes,
3325 "%qE attribute only applies to variadic functions", name);
3326 *no_add_attrs = true;
3330 if (args)
3332 tree position = TREE_VALUE (args);
3333 if (position && TREE_CODE (position) != IDENTIFIER_NODE
3334 && TREE_CODE (position) != FUNCTION_DECL)
3335 position = default_conversion (position);
3337 if (TREE_CODE (position) != INTEGER_CST
3338 || !INTEGRAL_TYPE_P (TREE_TYPE (position)))
3340 warning (OPT_Wattributes,
3341 "requested position is not an integer constant");
3342 *no_add_attrs = true;
3344 else
3346 if (tree_int_cst_lt (position, integer_zero_node))
3348 warning (OPT_Wattributes,
3349 "requested position is less than zero");
3350 *no_add_attrs = true;
3355 return NULL_TREE;
3358 /* Handle a "type_generic" attribute. */
3360 static tree
3361 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
3362 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
3363 bool * ARG_UNUSED (no_add_attrs))
3365 /* Ensure we have a function type. */
3366 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
3368 /* Ensure we have a variadic function. */
3369 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
3371 return NULL_TREE;
3374 /* Handle a "target" attribute. */
3376 static tree
3377 handle_target_attribute (tree *node, tree name, tree args, int flags,
3378 bool *no_add_attrs)
3380 /* Ensure we have a function type. */
3381 if (TREE_CODE (*node) != FUNCTION_DECL)
3383 warning (OPT_Wattributes, "%qE attribute ignored", name);
3384 *no_add_attrs = true;
3386 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
3388 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3389 "with %qs attribute", name, "target_clones");
3390 *no_add_attrs = true;
3392 else if (! targetm.target_option.valid_attribute_p (*node, name, args,
3393 flags))
3394 *no_add_attrs = true;
3396 /* Check that there's no empty string in values of the attribute. */
3397 for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
3399 tree value = TREE_VALUE (t);
3400 if (TREE_CODE (value) == STRING_CST
3401 && TREE_STRING_LENGTH (value) == 1
3402 && TREE_STRING_POINTER (value)[0] == '\0')
3404 warning (OPT_Wattributes, "empty string in attribute %<target%>");
3405 *no_add_attrs = true;
3409 return NULL_TREE;
3412 /* Handle a "target_clones" attribute. */
3414 static tree
3415 handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3416 int ARG_UNUSED (flags), bool *no_add_attrs)
3418 /* Ensure we have a function type. */
3419 if (TREE_CODE (*node) == FUNCTION_DECL)
3421 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
3423 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3424 "with %qs attribute", name, "always_inline");
3425 *no_add_attrs = true;
3427 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node)))
3429 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3430 "with %qs attribute", name, "target");
3431 *no_add_attrs = true;
3433 else
3434 /* Do not inline functions with multiple clone targets. */
3435 DECL_UNINLINABLE (*node) = 1;
3437 else
3439 warning (OPT_Wattributes, "%qE attribute ignored", name);
3440 *no_add_attrs = true;
3442 return NULL_TREE;
3445 /* For handling "optimize" attribute. arguments as in
3446 struct attribute_spec.handler. */
3448 static tree
3449 handle_optimize_attribute (tree *node, tree name, tree args,
3450 int ARG_UNUSED (flags), bool *no_add_attrs)
3452 /* Ensure we have a function type. */
3453 if (TREE_CODE (*node) != FUNCTION_DECL)
3455 warning (OPT_Wattributes, "%qE attribute ignored", name);
3456 *no_add_attrs = true;
3458 else
3460 struct cl_optimization cur_opts;
3461 tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
3463 /* Save current options. */
3464 cl_optimization_save (&cur_opts, &global_options);
3466 /* If we previously had some optimization options, use them as the
3467 default. */
3468 if (old_opts)
3469 cl_optimization_restore (&global_options,
3470 TREE_OPTIMIZATION (old_opts));
3472 /* Parse options, and update the vector. */
3473 parse_optimize_options (args, true);
3474 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
3475 = build_optimization_node (&global_options);
3477 /* Restore current options. */
3478 cl_optimization_restore (&global_options, &cur_opts);
3481 return NULL_TREE;
3484 /* Handle a "no_split_stack" attribute. */
3486 static tree
3487 handle_no_split_stack_attribute (tree *node, tree name,
3488 tree ARG_UNUSED (args),
3489 int ARG_UNUSED (flags),
3490 bool *no_add_attrs)
3492 tree decl = *node;
3494 if (TREE_CODE (decl) != FUNCTION_DECL)
3496 error_at (DECL_SOURCE_LOCATION (decl),
3497 "%qE attribute applies only to functions", name);
3498 *no_add_attrs = true;
3500 else if (DECL_INITIAL (decl))
3502 error_at (DECL_SOURCE_LOCATION (decl),
3503 "can%'t set %qE attribute after definition", name);
3504 *no_add_attrs = true;
3507 return NULL_TREE;
3510 /* Handle a "returns_nonnull" attribute; arguments as in
3511 struct attribute_spec.handler. */
3513 static tree
3514 handle_returns_nonnull_attribute (tree *node, tree, tree, int,
3515 bool *no_add_attrs)
3517 // Even without a prototype we still have a return type we can check.
3518 if (TREE_CODE (TREE_TYPE (*node)) != POINTER_TYPE)
3520 error ("returns_nonnull attribute on a function not returning a pointer");
3521 *no_add_attrs = true;
3523 return NULL_TREE;
3526 /* Handle a "designated_init" attribute; arguments as in
3527 struct attribute_spec.handler. */
3529 static tree
3530 handle_designated_init_attribute (tree *node, tree name, tree, int,
3531 bool *no_add_attrs)
3533 if (TREE_CODE (*node) != RECORD_TYPE)
3535 error ("%qE attribute is only valid on %<struct%> type", name);
3536 *no_add_attrs = true;
3538 return NULL_TREE;
3542 /* Handle a "fallthrough" attribute; arguments as in struct
3543 attribute_spec.handler. */
3545 static tree
3546 handle_fallthrough_attribute (tree *, tree name, tree, int,
3547 bool *no_add_attrs)
3549 warning (OPT_Wattributes, "%qE attribute ignored", name);
3550 *no_add_attrs = true;
3551 return NULL_TREE;
3554 static tree
3555 handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
3557 /* Nothing to be done here. */
3558 return NULL_TREE;