PR rtl-optimization/83496
[official-gcc.git] / gcc / c-family / c-attribs.c
blob0261a45ec980739e482af2dcc27f2be51070d778
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 { "cilk simd function", 0, -1, true, false, false, false,
443 handle_omp_declare_simd_attribute, NULL },
444 { "simd", 0, 1, true, false, false, false,
445 handle_simd_attribute, NULL },
446 { "omp declare target", 0, 0, true, false, false, false,
447 handle_omp_declare_target_attribute, NULL },
448 { "omp declare target link", 0, 0, true, false, false, false,
449 handle_omp_declare_target_attribute, NULL },
450 { "alloc_align", 1, 1, false, true, true, false,
451 handle_alloc_align_attribute,
452 attr_alloc_exclusions },
453 { "assume_aligned", 1, 2, false, true, true, false,
454 handle_assume_aligned_attribute, NULL },
455 { "designated_init", 0, 0, false, true, false, false,
456 handle_designated_init_attribute, NULL },
457 { "bnd_variable_size", 0, 0, true, false, false, false,
458 handle_bnd_variable_size_attribute, NULL },
459 { "bnd_legacy", 0, 0, true, false, false, false,
460 handle_bnd_legacy, NULL },
461 { "bnd_instrument", 0, 0, true, false, false, false,
462 handle_bnd_instrument, NULL },
463 { "fallthrough", 0, 0, false, false, false, false,
464 handle_fallthrough_attribute, NULL },
465 { "patchable_function_entry", 1, 2, true, false, false, false,
466 handle_patchable_function_entry_attribute,
467 NULL },
468 { "nocf_check", 0, 0, false, true, true, true,
469 handle_nocf_check_attribute, NULL },
470 { NULL, 0, 0, false, false, false, false, NULL, NULL }
473 /* Give the specifications for the format attributes, used by C and all
474 descendants.
476 All attributes referencing arguments should be additionally processed
477 in chkp_copy_function_type_adding_bounds for correct instrumentation
478 by Pointer Bounds Checker.
479 Current list of processed format attributes: format, format_arg. */
480 const struct attribute_spec c_common_format_attribute_table[] =
482 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
483 affects_type_identity, handler, exclude } */
484 { "format", 3, 3, false, true, true, false,
485 handle_format_attribute, NULL },
486 { "format_arg", 1, 1, false, true, true, false,
487 handle_format_arg_attribute, NULL },
488 { NULL, 0, 0, false, false, false, false, NULL, NULL }
491 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
492 identifier as an argument, so the front end shouldn't look it up. */
494 bool
495 attribute_takes_identifier_p (const_tree attr_id)
497 const struct attribute_spec *spec = lookup_attribute_spec (attr_id);
498 if (spec == NULL)
499 /* Unknown attribute that we'll end up ignoring, return true so we
500 don't complain about an identifier argument. */
501 return true;
502 else if (!strcmp ("mode", spec->name)
503 || !strcmp ("format", spec->name)
504 || !strcmp ("cleanup", spec->name))
505 return true;
506 else
507 return targetm.attribute_takes_identifier_p (attr_id);
510 /* Attribute handlers common to C front ends. */
512 /* Handle a "packed" attribute; arguments as in
513 struct attribute_spec.handler. */
515 static tree
516 handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
517 int flags, bool *no_add_attrs)
519 if (TYPE_P (*node))
521 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
522 *node = build_variant_type_copy (*node);
523 TYPE_PACKED (*node) = 1;
525 else if (TREE_CODE (*node) == FIELD_DECL)
527 if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
528 /* Still pack bitfields. */
529 && ! DECL_C_BIT_FIELD (*node))
530 warning (OPT_Wattributes,
531 "%qE attribute ignored for field of type %qT",
532 name, TREE_TYPE (*node));
533 else
534 DECL_PACKED (*node) = 1;
536 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
537 used for DECL_REGISTER. It wouldn't mean anything anyway.
538 We can't set DECL_PACKED on the type of a TYPE_DECL, because
539 that changes what the typedef is typing. */
540 else
542 warning (OPT_Wattributes, "%qE attribute ignored", name);
543 *no_add_attrs = true;
546 return NULL_TREE;
549 /* Handle a "nocommon" attribute; arguments as in
550 struct attribute_spec.handler. */
552 static tree
553 handle_nocommon_attribute (tree *node, tree name,
554 tree ARG_UNUSED (args),
555 int ARG_UNUSED (flags), bool *no_add_attrs)
557 if (VAR_P (*node))
558 DECL_COMMON (*node) = 0;
559 else
561 warning (OPT_Wattributes, "%qE attribute ignored", name);
562 *no_add_attrs = true;
565 return NULL_TREE;
568 /* Handle a "common" attribute; arguments as in
569 struct attribute_spec.handler. */
571 static tree
572 handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
573 int ARG_UNUSED (flags), bool *no_add_attrs)
575 if (VAR_P (*node))
576 DECL_COMMON (*node) = 1;
577 else
579 warning (OPT_Wattributes, "%qE attribute ignored", name);
580 *no_add_attrs = true;
583 return NULL_TREE;
586 /* Handle a "noreturn" attribute; arguments as in
587 struct attribute_spec.handler. */
589 static tree
590 handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
591 int ARG_UNUSED (flags), bool *no_add_attrs)
593 tree type = TREE_TYPE (*node);
595 /* See FIXME comment in c_common_attribute_table. */
596 if (TREE_CODE (*node) == FUNCTION_DECL
597 || objc_method_decl (TREE_CODE (*node)))
598 TREE_THIS_VOLATILE (*node) = 1;
599 else if (TREE_CODE (type) == POINTER_TYPE
600 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
601 TREE_TYPE (*node)
602 = (build_qualified_type
603 (build_pointer_type
604 (build_type_variant (TREE_TYPE (type),
605 TYPE_READONLY (TREE_TYPE (type)), 1)),
606 TYPE_QUALS (type)));
607 else
609 warning (OPT_Wattributes, "%qE attribute ignored", name);
610 *no_add_attrs = true;
613 return NULL_TREE;
616 /* Handle a "hot" and attribute; arguments as in
617 struct attribute_spec.handler. */
619 static tree
620 handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
621 int ARG_UNUSED (flags), bool *no_add_attrs)
623 if (TREE_CODE (*node) == FUNCTION_DECL
624 || TREE_CODE (*node) == LABEL_DECL)
626 /* Attribute hot processing is done later with lookup_attribute. */
628 else
630 warning (OPT_Wattributes, "%qE attribute ignored", name);
631 *no_add_attrs = true;
634 return NULL_TREE;
637 /* Handle a "cold" and attribute; arguments as in
638 struct attribute_spec.handler. */
640 static tree
641 handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args),
642 int ARG_UNUSED (flags), bool *no_add_attrs)
644 if (TREE_CODE (*node) == FUNCTION_DECL
645 || TREE_CODE (*node) == LABEL_DECL)
647 /* Attribute cold processing is done later with lookup_attribute. */
649 else
651 warning (OPT_Wattributes, "%qE attribute ignored", name);
652 *no_add_attrs = true;
655 return NULL_TREE;
658 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
660 void
661 add_no_sanitize_value (tree node, unsigned int flags)
663 tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node));
664 if (attr)
666 unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
667 flags |= old_value;
669 if (flags == old_value)
670 return;
672 TREE_VALUE (attr) = build_int_cst (unsigned_type_node, flags);
674 else
675 DECL_ATTRIBUTES (node)
676 = tree_cons (get_identifier ("no_sanitize"),
677 build_int_cst (unsigned_type_node, flags),
678 DECL_ATTRIBUTES (node));
681 /* Handle a "no_sanitize" attribute; arguments as in
682 struct attribute_spec.handler. */
684 static tree
685 handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
686 bool *no_add_attrs)
688 *no_add_attrs = true;
689 tree id = TREE_VALUE (args);
690 if (TREE_CODE (*node) != FUNCTION_DECL)
692 warning (OPT_Wattributes, "%qE attribute ignored", name);
693 return NULL_TREE;
696 if (TREE_CODE (id) != STRING_CST)
698 error ("no_sanitize argument not a string");
699 return NULL_TREE;
702 char *string = ASTRDUP (TREE_STRING_POINTER (id));
703 unsigned int flags = parse_no_sanitize_attribute (string);
705 add_no_sanitize_value (*node, flags);
707 return NULL_TREE;
710 /* Handle a "no_sanitize_address" attribute; arguments as in
711 struct attribute_spec.handler. */
713 static tree
714 handle_no_sanitize_address_attribute (tree *node, tree name, tree, int,
715 bool *no_add_attrs)
717 *no_add_attrs = true;
718 if (TREE_CODE (*node) != FUNCTION_DECL)
719 warning (OPT_Wattributes, "%qE attribute ignored", name);
720 else
721 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
723 return NULL_TREE;
726 /* Handle a "no_sanitize_thread" attribute; arguments as in
727 struct attribute_spec.handler. */
729 static tree
730 handle_no_sanitize_thread_attribute (tree *node, tree name, tree, int,
731 bool *no_add_attrs)
733 *no_add_attrs = true;
734 if (TREE_CODE (*node) != FUNCTION_DECL)
735 warning (OPT_Wattributes, "%qE attribute ignored", name);
736 else
737 add_no_sanitize_value (*node, SANITIZE_THREAD);
739 return NULL_TREE;
743 /* Handle a "no_address_safety_analysis" attribute; arguments as in
744 struct attribute_spec.handler. */
746 static tree
747 handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int,
748 bool *no_add_attrs)
750 *no_add_attrs = true;
751 if (TREE_CODE (*node) != FUNCTION_DECL)
752 warning (OPT_Wattributes, "%qE attribute ignored", name);
753 else
754 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
756 return NULL_TREE;
759 /* Handle a "no_sanitize_undefined" attribute; arguments as in
760 struct attribute_spec.handler. */
762 static tree
763 handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int,
764 bool *no_add_attrs)
766 *no_add_attrs = true;
767 if (TREE_CODE (*node) != FUNCTION_DECL)
768 warning (OPT_Wattributes, "%qE attribute ignored", name);
769 else
770 add_no_sanitize_value (*node,
771 SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
773 return NULL_TREE;
776 /* Handle an "asan odr indicator" attribute; arguments as in
777 struct attribute_spec.handler. */
779 static tree
780 handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *)
782 return NULL_TREE;
785 /* Handle a "stack_protect" attribute; arguments as in
786 struct attribute_spec.handler. */
788 static tree
789 handle_stack_protect_attribute (tree *node, tree name, tree, int,
790 bool *no_add_attrs)
792 if (TREE_CODE (*node) != FUNCTION_DECL)
794 warning (OPT_Wattributes, "%qE attribute ignored", name);
795 *no_add_attrs = true;
798 return NULL_TREE;
801 /* Handle a "noipa" attribute; arguments as in
802 struct attribute_spec.handler. */
804 static tree
805 handle_noipa_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
807 if (TREE_CODE (*node) != FUNCTION_DECL)
809 warning (OPT_Wattributes, "%qE attribute ignored", name);
810 *no_add_attrs = true;
813 return NULL_TREE;
816 /* Handle a "noinline" attribute; arguments as in
817 struct attribute_spec.handler. */
819 static tree
820 handle_noinline_attribute (tree *node, tree name,
821 tree ARG_UNUSED (args),
822 int ARG_UNUSED (flags), bool *no_add_attrs)
824 if (TREE_CODE (*node) == FUNCTION_DECL)
826 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
828 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
829 "with attribute %qs", name, "always_inline");
830 *no_add_attrs = true;
832 else
833 DECL_UNINLINABLE (*node) = 1;
835 else
837 warning (OPT_Wattributes, "%qE attribute ignored", name);
838 *no_add_attrs = true;
841 return NULL_TREE;
844 /* Handle a "noclone" attribute; arguments as in
845 struct attribute_spec.handler. */
847 static tree
848 handle_noclone_attribute (tree *node, tree name,
849 tree ARG_UNUSED (args),
850 int ARG_UNUSED (flags), bool *no_add_attrs)
852 if (TREE_CODE (*node) != FUNCTION_DECL)
854 warning (OPT_Wattributes, "%qE attribute ignored", name);
855 *no_add_attrs = true;
858 return NULL_TREE;
861 /* Handle a "nocf_check" attribute; arguments as in
862 struct attribute_spec.handler. */
864 static tree
865 handle_nocf_check_attribute (tree *node, tree name,
866 tree ARG_UNUSED (args),
867 int ARG_UNUSED (flags), bool *no_add_attrs)
869 if (TREE_CODE (*node) != FUNCTION_TYPE
870 && TREE_CODE (*node) != METHOD_TYPE)
872 warning (OPT_Wattributes, "%qE attribute ignored", name);
873 *no_add_attrs = true;
875 else if (!(flag_cf_protection & CF_BRANCH))
877 warning (OPT_Wattributes, "%qE attribute ignored. Use "
878 "-fcf-protection option to enable it", name);
879 *no_add_attrs = true;
882 return NULL_TREE;
885 /* Handle a "no_icf" attribute; arguments as in
886 struct attribute_spec.handler. */
888 static tree
889 handle_noicf_attribute (tree *node, tree name,
890 tree ARG_UNUSED (args),
891 int ARG_UNUSED (flags), bool *no_add_attrs)
893 if (TREE_CODE (*node) != FUNCTION_DECL)
895 warning (OPT_Wattributes, "%qE attribute ignored", name);
896 *no_add_attrs = true;
899 return NULL_TREE;
903 /* Handle a "always_inline" attribute; arguments as in
904 struct attribute_spec.handler. */
906 static tree
907 handle_always_inline_attribute (tree *node, tree name,
908 tree ARG_UNUSED (args),
909 int ARG_UNUSED (flags),
910 bool *no_add_attrs)
912 if (TREE_CODE (*node) == FUNCTION_DECL)
914 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node)))
916 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
917 "with %qs attribute", name, "noinline");
918 *no_add_attrs = true;
920 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
922 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
923 "with %qs attribute", name, "target_clones");
924 *no_add_attrs = true;
926 else
927 /* Set the attribute and mark it for disregarding inline
928 limits. */
929 DECL_DISREGARD_INLINE_LIMITS (*node) = 1;
931 else
933 warning (OPT_Wattributes, "%qE attribute ignored", name);
934 *no_add_attrs = true;
937 return NULL_TREE;
940 /* Handle a "gnu_inline" attribute; arguments as in
941 struct attribute_spec.handler. */
943 static tree
944 handle_gnu_inline_attribute (tree *node, tree name,
945 tree ARG_UNUSED (args),
946 int ARG_UNUSED (flags),
947 bool *no_add_attrs)
949 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
951 /* Do nothing else, just set the attribute. We'll get at
952 it later with lookup_attribute. */
954 else
956 warning (OPT_Wattributes, "%qE attribute ignored", name);
957 *no_add_attrs = true;
960 return NULL_TREE;
963 /* Handle a "leaf" attribute; arguments as in
964 struct attribute_spec.handler. */
966 static tree
967 handle_leaf_attribute (tree *node, tree name,
968 tree ARG_UNUSED (args),
969 int ARG_UNUSED (flags), bool *no_add_attrs)
971 if (TREE_CODE (*node) != FUNCTION_DECL)
973 warning (OPT_Wattributes, "%qE attribute ignored", name);
974 *no_add_attrs = true;
976 if (!TREE_PUBLIC (*node))
978 warning (OPT_Wattributes, "%qE attribute has no effect on unit local "
979 "functions", name);
980 *no_add_attrs = true;
983 return NULL_TREE;
986 /* Handle an "artificial" attribute; arguments as in
987 struct attribute_spec.handler. */
989 static tree
990 handle_artificial_attribute (tree *node, tree name,
991 tree ARG_UNUSED (args),
992 int ARG_UNUSED (flags),
993 bool *no_add_attrs)
995 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
997 /* Do nothing else, just set the attribute. We'll get at
998 it later with lookup_attribute. */
1000 else
1002 warning (OPT_Wattributes, "%qE attribute ignored", name);
1003 *no_add_attrs = true;
1006 return NULL_TREE;
1009 /* Handle a "flatten" attribute; arguments as in
1010 struct attribute_spec.handler. */
1012 static tree
1013 handle_flatten_attribute (tree *node, tree name,
1014 tree args ATTRIBUTE_UNUSED,
1015 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
1017 if (TREE_CODE (*node) == FUNCTION_DECL)
1018 /* Do nothing else, just set the attribute. We'll get at
1019 it later with lookup_attribute. */
1021 else
1023 warning (OPT_Wattributes, "%qE attribute ignored", name);
1024 *no_add_attrs = true;
1027 return NULL_TREE;
1030 /* Handle a "warning" or "error" attribute; arguments as in
1031 struct attribute_spec.handler. */
1033 static tree
1034 handle_error_attribute (tree *node, tree name, tree args,
1035 int ARG_UNUSED (flags), bool *no_add_attrs)
1037 if (TREE_CODE (*node) == FUNCTION_DECL
1038 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
1039 /* Do nothing else, just set the attribute. We'll get at
1040 it later with lookup_attribute. */
1042 else
1044 warning (OPT_Wattributes, "%qE attribute ignored", name);
1045 *no_add_attrs = true;
1048 return NULL_TREE;
1051 /* Handle a "used" attribute; arguments as in
1052 struct attribute_spec.handler. */
1054 static tree
1055 handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
1056 int ARG_UNUSED (flags), bool *no_add_attrs)
1058 tree node = *pnode;
1060 if (TREE_CODE (node) == FUNCTION_DECL
1061 || (VAR_P (node) && TREE_STATIC (node))
1062 || (TREE_CODE (node) == TYPE_DECL))
1064 TREE_USED (node) = 1;
1065 DECL_PRESERVE_P (node) = 1;
1066 if (VAR_P (node))
1067 DECL_READ_P (node) = 1;
1069 else
1071 warning (OPT_Wattributes, "%qE attribute ignored", name);
1072 *no_add_attrs = true;
1075 return NULL_TREE;
1078 /* Handle a "unused" attribute; arguments as in
1079 struct attribute_spec.handler. */
1081 tree
1082 handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1083 int flags, bool *no_add_attrs)
1085 if (DECL_P (*node))
1087 tree decl = *node;
1089 if (TREE_CODE (decl) == PARM_DECL
1090 || VAR_OR_FUNCTION_DECL_P (decl)
1091 || TREE_CODE (decl) == LABEL_DECL
1092 || TREE_CODE (decl) == CONST_DECL
1093 || TREE_CODE (decl) == TYPE_DECL)
1095 TREE_USED (decl) = 1;
1096 if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
1097 DECL_READ_P (decl) = 1;
1099 else
1101 warning (OPT_Wattributes, "%qE attribute ignored", name);
1102 *no_add_attrs = true;
1105 else
1107 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1108 *node = build_variant_type_copy (*node);
1109 TREE_USED (*node) = 1;
1112 return NULL_TREE;
1115 /* Handle a "externally_visible" attribute; arguments as in
1116 struct attribute_spec.handler. */
1118 static tree
1119 handle_externally_visible_attribute (tree *pnode, tree name,
1120 tree ARG_UNUSED (args),
1121 int ARG_UNUSED (flags),
1122 bool *no_add_attrs)
1124 tree node = *pnode;
1126 if (VAR_OR_FUNCTION_DECL_P (node))
1128 if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
1129 && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
1131 warning (OPT_Wattributes,
1132 "%qE attribute have effect only on public objects", name);
1133 *no_add_attrs = true;
1136 else
1138 warning (OPT_Wattributes, "%qE attribute ignored", name);
1139 *no_add_attrs = true;
1142 return NULL_TREE;
1145 /* Handle the "no_reorder" attribute. Arguments as in
1146 struct attribute_spec.handler. */
1148 static tree
1149 handle_no_reorder_attribute (tree *pnode,
1150 tree name,
1151 tree,
1152 int,
1153 bool *no_add_attrs)
1155 tree node = *pnode;
1157 if (!VAR_OR_FUNCTION_DECL_P (node)
1158 && !(TREE_STATIC (node) || DECL_EXTERNAL (node)))
1160 warning (OPT_Wattributes,
1161 "%qE attribute only affects top level objects",
1162 name);
1163 *no_add_attrs = true;
1166 return NULL_TREE;
1169 /* Handle a "const" attribute; arguments as in
1170 struct attribute_spec.handler. */
1172 static tree
1173 handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1174 int flags, bool *no_add_attrs)
1176 tree type = TREE_TYPE (*node);
1178 /* See FIXME comment on noreturn in c_common_attribute_table. */
1179 if (TREE_CODE (*node) == FUNCTION_DECL)
1180 TREE_READONLY (*node) = 1;
1181 else if (TREE_CODE (type) == POINTER_TYPE
1182 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1183 TREE_TYPE (*node)
1184 = (build_qualified_type
1185 (build_pointer_type
1186 (build_type_variant (TREE_TYPE (type), 1,
1187 TREE_THIS_VOLATILE (TREE_TYPE (type)))),
1188 TYPE_QUALS (type)));
1189 else
1191 warning (OPT_Wattributes, "%qE attribute ignored", name);
1192 *no_add_attrs = true;
1195 /* void __builtin_unreachable(void) is const. Accept other such
1196 built-ins but warn on user-defined functions that return void. */
1197 if (!(flags & ATTR_FLAG_BUILT_IN)
1198 && TREE_CODE (*node) == FUNCTION_DECL
1199 && VOID_TYPE_P (TREE_TYPE (type)))
1200 warning (OPT_Wattributes, "%qE attribute on function "
1201 "returning %<void%>", name);
1203 return NULL_TREE;
1206 /* Handle a "scalar_storage_order" attribute; arguments as in
1207 struct attribute_spec.handler. */
1209 static tree
1210 handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
1211 int flags, bool *no_add_attrs)
1213 tree id = TREE_VALUE (args);
1214 tree type;
1216 if (TREE_CODE (*node) == TYPE_DECL
1217 && ! (flags & ATTR_FLAG_CXX11))
1218 node = &TREE_TYPE (*node);
1219 type = *node;
1221 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
1223 error ("scalar_storage_order is not supported because endianness "
1224 "is not uniform");
1225 return NULL_TREE;
1228 if (RECORD_OR_UNION_TYPE_P (type) && !c_dialect_cxx ())
1230 bool reverse = false;
1232 if (TREE_CODE (id) == STRING_CST
1233 && strcmp (TREE_STRING_POINTER (id), "big-endian") == 0)
1234 reverse = !BYTES_BIG_ENDIAN;
1235 else if (TREE_CODE (id) == STRING_CST
1236 && strcmp (TREE_STRING_POINTER (id), "little-endian") == 0)
1237 reverse = BYTES_BIG_ENDIAN;
1238 else
1240 error ("scalar_storage_order argument must be one of \"big-endian\""
1241 " or \"little-endian\"");
1242 return NULL_TREE;
1245 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1247 if (reverse)
1248 /* A type variant isn't good enough, since we don't want a cast
1249 to such a type to be removed as a no-op. */
1250 *node = type = build_duplicate_type (type);
1253 TYPE_REVERSE_STORAGE_ORDER (type) = reverse;
1254 return NULL_TREE;
1257 warning (OPT_Wattributes, "%qE attribute ignored", name);
1258 *no_add_attrs = true;
1259 return NULL_TREE;
1262 /* Handle a "transparent_union" attribute; arguments as in
1263 struct attribute_spec.handler. */
1265 static tree
1266 handle_transparent_union_attribute (tree *node, tree name,
1267 tree ARG_UNUSED (args), int flags,
1268 bool *no_add_attrs)
1270 tree type;
1272 *no_add_attrs = true;
1274 if (TREE_CODE (*node) == TYPE_DECL
1275 && ! (flags & ATTR_FLAG_CXX11))
1276 node = &TREE_TYPE (*node);
1277 type = *node;
1279 if (TREE_CODE (type) == UNION_TYPE)
1281 /* Make sure that the first field will work for a transparent union.
1282 If the type isn't complete yet, leave the check to the code in
1283 finish_struct. */
1284 if (TYPE_SIZE (type))
1286 tree first = first_field (type);
1287 if (first == NULL_TREE
1288 || DECL_ARTIFICIAL (first)
1289 || TYPE_MODE (type) != DECL_MODE (first))
1290 goto ignored;
1293 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1295 /* If the type isn't complete yet, setting the flag
1296 on a variant wouldn't ever be checked. */
1297 if (!TYPE_SIZE (type))
1298 goto ignored;
1300 /* build_duplicate_type doesn't work for C++. */
1301 if (c_dialect_cxx ())
1302 goto ignored;
1304 /* A type variant isn't good enough, since we don't want a cast
1305 to such a type to be removed as a no-op. */
1306 *node = type = build_duplicate_type (type);
1309 for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1310 TYPE_TRANSPARENT_AGGR (t) = 1;
1311 return NULL_TREE;
1314 ignored:
1315 warning (OPT_Wattributes, "%qE attribute ignored", name);
1316 return NULL_TREE;
1319 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1320 get the requested priority for a constructor or destructor,
1321 possibly issuing diagnostics for invalid or reserved
1322 priorities. */
1324 static priority_type
1325 get_priority (tree args, bool is_destructor)
1327 HOST_WIDE_INT pri;
1328 tree arg;
1330 if (!args)
1331 return DEFAULT_INIT_PRIORITY;
1333 if (!SUPPORTS_INIT_PRIORITY)
1335 if (is_destructor)
1336 error ("destructor priorities are not supported");
1337 else
1338 error ("constructor priorities are not supported");
1339 return DEFAULT_INIT_PRIORITY;
1342 arg = TREE_VALUE (args);
1343 if (TREE_CODE (arg) == IDENTIFIER_NODE)
1344 goto invalid;
1345 if (arg == error_mark_node)
1346 return DEFAULT_INIT_PRIORITY;
1347 arg = default_conversion (arg);
1348 if (!tree_fits_shwi_p (arg)
1349 || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
1350 goto invalid;
1352 pri = tree_to_shwi (arg);
1353 if (pri < 0 || pri > MAX_INIT_PRIORITY)
1354 goto invalid;
1356 if (pri <= MAX_RESERVED_INIT_PRIORITY)
1358 if (is_destructor)
1359 warning (0,
1360 "destructor priorities from 0 to %d are reserved "
1361 "for the implementation",
1362 MAX_RESERVED_INIT_PRIORITY);
1363 else
1364 warning (0,
1365 "constructor priorities from 0 to %d are reserved "
1366 "for the implementation",
1367 MAX_RESERVED_INIT_PRIORITY);
1369 return pri;
1371 invalid:
1372 if (is_destructor)
1373 error ("destructor priorities must be integers from 0 to %d inclusive",
1374 MAX_INIT_PRIORITY);
1375 else
1376 error ("constructor priorities must be integers from 0 to %d inclusive",
1377 MAX_INIT_PRIORITY);
1378 return DEFAULT_INIT_PRIORITY;
1381 /* Handle a "constructor" attribute; arguments as in
1382 struct attribute_spec.handler. */
1384 static tree
1385 handle_constructor_attribute (tree *node, tree name, tree args,
1386 int ARG_UNUSED (flags),
1387 bool *no_add_attrs)
1389 tree decl = *node;
1390 tree type = TREE_TYPE (decl);
1392 if (TREE_CODE (decl) == FUNCTION_DECL
1393 && TREE_CODE (type) == FUNCTION_TYPE
1394 && decl_function_context (decl) == 0)
1396 priority_type priority;
1397 DECL_STATIC_CONSTRUCTOR (decl) = 1;
1398 priority = get_priority (args, /*is_destructor=*/false);
1399 SET_DECL_INIT_PRIORITY (decl, priority);
1400 TREE_USED (decl) = 1;
1402 else
1404 warning (OPT_Wattributes, "%qE attribute ignored", name);
1405 *no_add_attrs = true;
1408 return NULL_TREE;
1411 /* Handle a "destructor" attribute; arguments as in
1412 struct attribute_spec.handler. */
1414 static tree
1415 handle_destructor_attribute (tree *node, tree name, tree args,
1416 int ARG_UNUSED (flags),
1417 bool *no_add_attrs)
1419 tree decl = *node;
1420 tree type = TREE_TYPE (decl);
1422 if (TREE_CODE (decl) == FUNCTION_DECL
1423 && TREE_CODE (type) == FUNCTION_TYPE
1424 && decl_function_context (decl) == 0)
1426 priority_type priority;
1427 DECL_STATIC_DESTRUCTOR (decl) = 1;
1428 priority = get_priority (args, /*is_destructor=*/true);
1429 SET_DECL_FINI_PRIORITY (decl, priority);
1430 TREE_USED (decl) = 1;
1432 else
1434 warning (OPT_Wattributes, "%qE attribute ignored", name);
1435 *no_add_attrs = true;
1438 return NULL_TREE;
1441 /* Nonzero if the mode is a valid vector mode for this architecture.
1442 This returns nonzero even if there is no hardware support for the
1443 vector mode, but we can emulate with narrower modes. */
1445 static bool
1446 vector_mode_valid_p (machine_mode mode)
1448 enum mode_class mclass = GET_MODE_CLASS (mode);
1450 /* Doh! What's going on? */
1451 if (mclass != MODE_VECTOR_INT
1452 && mclass != MODE_VECTOR_FLOAT
1453 && mclass != MODE_VECTOR_FRACT
1454 && mclass != MODE_VECTOR_UFRACT
1455 && mclass != MODE_VECTOR_ACCUM
1456 && mclass != MODE_VECTOR_UACCUM)
1457 return false;
1459 /* Hardware support. Woo hoo! */
1460 if (targetm.vector_mode_supported_p (mode))
1461 return true;
1463 /* We should probably return 1 if requesting V4DI and we have no DI,
1464 but we have V2DI, but this is probably very unlikely. */
1466 /* If we have support for the inner mode, we can safely emulate it.
1467 We may not have V2DI, but me can emulate with a pair of DIs. */
1468 return targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1472 /* Handle a "mode" attribute; arguments as in
1473 struct attribute_spec.handler. */
1475 static tree
1476 handle_mode_attribute (tree *node, tree name, tree args,
1477 int ARG_UNUSED (flags), bool *no_add_attrs)
1479 tree type = *node;
1480 tree ident = TREE_VALUE (args);
1482 *no_add_attrs = true;
1484 if (TREE_CODE (ident) != IDENTIFIER_NODE)
1485 warning (OPT_Wattributes, "%qE attribute ignored", name);
1486 else
1488 int j;
1489 const char *p = IDENTIFIER_POINTER (ident);
1490 int len = strlen (p);
1491 machine_mode mode = VOIDmode;
1492 tree typefm;
1493 bool valid_mode;
1495 if (len > 4 && p[0] == '_' && p[1] == '_'
1496 && p[len - 1] == '_' && p[len - 2] == '_')
1498 char *newp = (char *) alloca (len - 1);
1500 strcpy (newp, &p[2]);
1501 newp[len - 4] = '\0';
1502 p = newp;
1505 /* Change this type to have a type with the specified mode.
1506 First check for the special modes. */
1507 if (!strcmp (p, "byte"))
1508 mode = byte_mode;
1509 else if (!strcmp (p, "word"))
1510 mode = word_mode;
1511 else if (!strcmp (p, "pointer"))
1512 mode = ptr_mode;
1513 else if (!strcmp (p, "libgcc_cmp_return"))
1514 mode = targetm.libgcc_cmp_return_mode ();
1515 else if (!strcmp (p, "libgcc_shift_count"))
1516 mode = targetm.libgcc_shift_count_mode ();
1517 else if (!strcmp (p, "unwind_word"))
1518 mode = targetm.unwind_word_mode ();
1519 else
1520 for (j = 0; j < NUM_MACHINE_MODES; j++)
1521 if (!strcmp (p, GET_MODE_NAME (j)))
1523 mode = (machine_mode) j;
1524 break;
1527 if (mode == VOIDmode)
1529 error ("unknown machine mode %qE", ident);
1530 return NULL_TREE;
1533 valid_mode = false;
1534 switch (GET_MODE_CLASS (mode))
1536 case MODE_INT:
1537 case MODE_PARTIAL_INT:
1538 case MODE_FLOAT:
1539 case MODE_DECIMAL_FLOAT:
1540 case MODE_FRACT:
1541 case MODE_UFRACT:
1542 case MODE_ACCUM:
1543 case MODE_UACCUM:
1544 valid_mode
1545 = targetm.scalar_mode_supported_p (as_a <scalar_mode> (mode));
1546 break;
1548 case MODE_COMPLEX_INT:
1549 case MODE_COMPLEX_FLOAT:
1550 valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1551 break;
1553 case MODE_VECTOR_INT:
1554 case MODE_VECTOR_FLOAT:
1555 case MODE_VECTOR_FRACT:
1556 case MODE_VECTOR_UFRACT:
1557 case MODE_VECTOR_ACCUM:
1558 case MODE_VECTOR_UACCUM:
1559 warning (OPT_Wattributes, "specifying vector types with "
1560 "__attribute__ ((mode)) is deprecated");
1561 warning (OPT_Wattributes,
1562 "use __attribute__ ((vector_size)) instead");
1563 valid_mode = vector_mode_valid_p (mode);
1564 break;
1566 default:
1567 break;
1569 if (!valid_mode)
1571 error ("unable to emulate %qs", p);
1572 return NULL_TREE;
1575 if (POINTER_TYPE_P (type))
1577 scalar_int_mode addr_mode;
1578 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
1579 tree (*fn)(tree, machine_mode, bool);
1581 if (!is_a <scalar_int_mode> (mode, &addr_mode)
1582 || !targetm.addr_space.valid_pointer_mode (addr_mode, as))
1584 error ("invalid pointer mode %qs", p);
1585 return NULL_TREE;
1588 if (TREE_CODE (type) == POINTER_TYPE)
1589 fn = build_pointer_type_for_mode;
1590 else
1591 fn = build_reference_type_for_mode;
1592 typefm = fn (TREE_TYPE (type), addr_mode, false);
1594 else
1596 /* For fixed-point modes, we need to test if the signness of type
1597 and the machine mode are consistent. */
1598 if (ALL_FIXED_POINT_MODE_P (mode)
1599 && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
1601 error ("signedness of type and machine mode %qs don%'t match", p);
1602 return NULL_TREE;
1604 /* For fixed-point modes, we need to pass saturating info. */
1605 typefm = lang_hooks.types.type_for_mode (mode,
1606 ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
1607 : TYPE_UNSIGNED (type));
1610 if (typefm == NULL_TREE)
1612 error ("no data type for mode %qs", p);
1613 return NULL_TREE;
1615 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1617 /* For enumeral types, copy the precision from the integer
1618 type returned above. If not an INTEGER_TYPE, we can't use
1619 this mode for this type. */
1620 if (TREE_CODE (typefm) != INTEGER_TYPE)
1622 error ("cannot use mode %qs for enumeral types", p);
1623 return NULL_TREE;
1626 if (flags & ATTR_FLAG_TYPE_IN_PLACE)
1628 TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
1629 typefm = type;
1631 else
1633 /* We cannot build a type variant, as there's code that assumes
1634 that TYPE_MAIN_VARIANT has the same mode. This includes the
1635 debug generators. Instead, create a subrange type. This
1636 results in all of the enumeral values being emitted only once
1637 in the original, and the subtype gets them by reference. */
1638 if (TYPE_UNSIGNED (type))
1639 typefm = make_unsigned_type (TYPE_PRECISION (typefm));
1640 else
1641 typefm = make_signed_type (TYPE_PRECISION (typefm));
1642 TREE_TYPE (typefm) = type;
1645 else if (VECTOR_MODE_P (mode)
1646 ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
1647 : TREE_CODE (type) != TREE_CODE (typefm))
1649 error ("mode %qs applied to inappropriate type", p);
1650 return NULL_TREE;
1653 *node = build_qualified_type (typefm, TYPE_QUALS (type));
1656 return NULL_TREE;
1659 /* Handle a "section" attribute; arguments as in
1660 struct attribute_spec.handler. */
1662 static tree
1663 handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
1664 int ARG_UNUSED (flags), bool *no_add_attrs)
1666 tree decl = *node;
1668 if (!targetm_common.have_named_sections)
1670 error_at (DECL_SOURCE_LOCATION (*node),
1671 "section attributes are not supported for this target");
1672 goto fail;
1675 if (!VAR_OR_FUNCTION_DECL_P (decl))
1677 error ("section attribute not allowed for %q+D", *node);
1678 goto fail;
1681 if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
1683 error ("section attribute argument not a string constant");
1684 goto fail;
1687 if (VAR_P (decl)
1688 && current_function_decl != NULL_TREE
1689 && !TREE_STATIC (decl))
1691 error_at (DECL_SOURCE_LOCATION (decl),
1692 "section attribute cannot be specified for local variables");
1693 goto fail;
1696 /* The decl may have already been given a section attribute
1697 from a previous declaration. Ensure they match. */
1698 if (DECL_SECTION_NAME (decl) != NULL
1699 && strcmp (DECL_SECTION_NAME (decl),
1700 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
1702 error ("section of %q+D conflicts with previous declaration", *node);
1703 goto fail;
1706 if (VAR_P (decl)
1707 && !targetm.have_tls && targetm.emutls.tmpl_section
1708 && DECL_THREAD_LOCAL_P (decl))
1710 error ("section of %q+D cannot be overridden", *node);
1711 goto fail;
1714 set_decl_section_name (decl, TREE_STRING_POINTER (TREE_VALUE (args)));
1715 return NULL_TREE;
1717 fail:
1718 *no_add_attrs = true;
1719 return NULL_TREE;
1722 /* If in c++-11, check if the c++-11 alignment constraint with respect
1723 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1724 c++-11 mode, does nothing.
1726 [dcl.align]2/ says:
1728 [* if the constant expression evaluates to a fundamental alignment,
1729 the alignment requirement of the declared entity shall be the
1730 specified fundamental alignment.
1732 * if the constant expression evaluates to an extended alignment
1733 and the implementation supports that alignment in the context
1734 of the declaration, the alignment of the declared entity shall
1735 be that alignment
1737 * if the constant expression evaluates to an extended alignment
1738 and the implementation does not support that alignment in the
1739 context of the declaration, the program is ill-formed]. */
1741 static bool
1742 check_cxx_fundamental_alignment_constraints (tree node,
1743 unsigned align_log,
1744 int flags)
1746 bool alignment_too_large_p = false;
1747 unsigned requested_alignment = (1U << align_log) * BITS_PER_UNIT;
1748 unsigned max_align = 0;
1750 if ((!(flags & ATTR_FLAG_CXX11) && !warn_cxx_compat)
1751 || (node == NULL_TREE || node == error_mark_node))
1752 return true;
1754 if (cxx_fundamental_alignment_p (requested_alignment))
1755 return true;
1757 if (VAR_P (node))
1759 if (TREE_STATIC (node) || DECL_EXTERNAL (node))
1760 /* For file scope variables and static members, the target supports
1761 alignments that are at most MAX_OFILE_ALIGNMENT. */
1762 max_align = MAX_OFILE_ALIGNMENT;
1763 else
1764 /* For stack variables, the target supports at most
1765 MAX_STACK_ALIGNMENT. */
1766 max_align = MAX_STACK_ALIGNMENT;
1767 if (requested_alignment > max_align)
1768 alignment_too_large_p = true;
1770 /* Let's be liberal for types and fields; don't limit their alignment any
1771 more than check_user_alignment already did. */
1773 if (alignment_too_large_p)
1774 pedwarn (input_location, OPT_Wattributes,
1775 "requested alignment %d is larger than %d",
1776 requested_alignment / BITS_PER_UNIT, max_align / BITS_PER_UNIT);
1778 return !alignment_too_large_p;
1781 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1782 handle_aligned_attribute. */
1784 static tree
1785 common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
1786 bool *no_add_attrs,
1787 bool warn_if_not_aligned_p)
1789 tree decl = NULL_TREE;
1790 tree *type = NULL;
1791 bool is_type = false;
1792 tree align_expr;
1794 /* The last (already pushed) declaration with all validated attributes
1795 merged in or the current about-to-be-pushed one if one hasn't been
1796 yet. */
1797 tree last_decl = node[1] ? node[1] : *node;
1799 if (args)
1801 align_expr = TREE_VALUE (args);
1802 if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE
1803 && TREE_CODE (align_expr) != FUNCTION_DECL)
1804 align_expr = default_conversion (align_expr);
1806 else
1807 align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT);
1809 if (DECL_P (*node))
1811 decl = *node;
1812 type = &TREE_TYPE (decl);
1813 is_type = TREE_CODE (*node) == TYPE_DECL;
1815 else if (TYPE_P (*node))
1816 type = node, is_type = true;
1818 /* Log2 of specified alignment. */
1819 int pow2align = check_user_alignment (align_expr, true);
1821 /* The alignment in bits corresponding to the specified alignment. */
1822 unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
1824 /* The alignment of the current declaration and that of the last
1825 pushed declaration, determined on demand below. */
1826 unsigned curalign = 0;
1827 unsigned lastalign = 0;
1829 if (pow2align == -1
1830 || !check_cxx_fundamental_alignment_constraints (*node, pow2align, flags))
1831 *no_add_attrs = true;
1832 else if (is_type)
1834 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1835 /* OK, modify the type in place. */;
1836 /* If we have a TYPE_DECL, then copy the type, so that we
1837 don't accidentally modify a builtin type. See pushdecl. */
1838 else if (decl && TREE_TYPE (decl) != error_mark_node
1839 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
1841 tree tt = TREE_TYPE (decl);
1842 *type = build_variant_type_copy (*type);
1843 DECL_ORIGINAL_TYPE (decl) = tt;
1844 TYPE_NAME (*type) = decl;
1845 TREE_USED (*type) = TREE_USED (decl);
1846 TREE_TYPE (decl) = *type;
1848 else
1849 *type = build_variant_type_copy (*type);
1851 if (warn_if_not_aligned_p)
1853 SET_TYPE_WARN_IF_NOT_ALIGN (*type, bitalign);
1854 warn_if_not_aligned_p = false;
1856 else
1858 SET_TYPE_ALIGN (*type, bitalign);
1859 TYPE_USER_ALIGN (*type) = 1;
1862 else if (! VAR_OR_FUNCTION_DECL_P (decl)
1863 && TREE_CODE (decl) != FIELD_DECL)
1865 error ("alignment may not be specified for %q+D", decl);
1866 *no_add_attrs = true;
1868 else if (TREE_CODE (decl) == FUNCTION_DECL
1869 && ((curalign = DECL_ALIGN (decl)) > bitalign
1870 || ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
1872 /* Either a prior attribute on the same declaration or one
1873 on a prior declaration of the same function specifies
1874 stricter alignment than this attribute. */
1875 bool note = lastalign != 0;
1876 if (lastalign)
1877 curalign = lastalign;
1879 curalign /= BITS_PER_UNIT;
1880 bitalign /= BITS_PER_UNIT;
1882 bool diagd = true;
1883 if (DECL_USER_ALIGN (decl) || DECL_USER_ALIGN (last_decl))
1884 diagd = warning (OPT_Wattributes,
1885 "ignoring attribute %<%E (%u)%> because it conflicts "
1886 "with attribute %<%E (%u)%>",
1887 name, bitalign, name, curalign);
1888 else if (!warn_if_not_aligned_p)
1889 /* Do not error out for attribute warn_if_not_aligned. */
1890 error ("alignment for %q+D must be at least %d", decl, curalign);
1892 if (diagd && note)
1893 inform (DECL_SOURCE_LOCATION (last_decl), "previous declaration here");
1895 *no_add_attrs = true;
1897 else if (DECL_USER_ALIGN (decl)
1898 && DECL_ALIGN (decl) > bitalign)
1899 /* C++-11 [dcl.align/4]:
1901 When multiple alignment-specifiers are specified for an
1902 entity, the alignment requirement shall be set to the
1903 strictest specified alignment.
1905 This formally comes from the c++11 specification but we are
1906 doing it for the GNU attribute syntax as well. */
1907 *no_add_attrs = true;
1908 else if (!warn_if_not_aligned_p
1909 && TREE_CODE (decl) == FUNCTION_DECL
1910 && DECL_ALIGN (decl) > bitalign)
1912 /* Don't warn function alignment here if warn_if_not_aligned_p is
1913 true. It will be warned later. */
1914 if (DECL_USER_ALIGN (decl))
1915 error ("alignment for %q+D was previously specified as %d "
1916 "and may not be decreased", decl,
1917 DECL_ALIGN (decl) / BITS_PER_UNIT);
1918 else
1919 error ("alignment for %q+D must be at least %d", decl,
1920 DECL_ALIGN (decl) / BITS_PER_UNIT);
1921 *no_add_attrs = true;
1923 else
1925 if (warn_if_not_aligned_p)
1927 if (TREE_CODE (decl) == FIELD_DECL && !DECL_C_BIT_FIELD (decl))
1929 SET_DECL_WARN_IF_NOT_ALIGN (decl, bitalign);
1930 warn_if_not_aligned_p = false;
1933 else
1935 SET_DECL_ALIGN (decl, bitalign);
1936 DECL_USER_ALIGN (decl) = 1;
1940 if (warn_if_not_aligned_p)
1942 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1943 decl);
1944 *no_add_attrs = true;
1947 return NULL_TREE;
1950 /* Handle a "aligned" attribute; arguments as in
1951 struct attribute_spec.handler. */
1953 static tree
1954 handle_aligned_attribute (tree *node, tree name, tree args,
1955 int flags, bool *no_add_attrs)
1957 return common_handle_aligned_attribute (node, name, args, flags,
1958 no_add_attrs, false);
1961 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1962 struct attribute_spec.handler. */
1964 static tree
1965 handle_warn_if_not_aligned_attribute (tree *node, tree name,
1966 tree args, int flags,
1967 bool *no_add_attrs)
1969 return common_handle_aligned_attribute (node, name, args, flags,
1970 no_add_attrs, true);
1973 /* Handle a "weak" attribute; arguments as in
1974 struct attribute_spec.handler. */
1976 static tree
1977 handle_weak_attribute (tree *node, tree name,
1978 tree ARG_UNUSED (args),
1979 int ARG_UNUSED (flags),
1980 bool * ARG_UNUSED (no_add_attrs))
1982 if (TREE_CODE (*node) == FUNCTION_DECL
1983 && DECL_DECLARED_INLINE_P (*node))
1985 warning (OPT_Wattributes, "inline function %q+D declared weak", *node);
1986 *no_add_attrs = true;
1988 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
1990 error ("indirect function %q+D cannot be declared weak", *node);
1991 *no_add_attrs = true;
1992 return NULL_TREE;
1994 else if (VAR_OR_FUNCTION_DECL_P (*node))
1995 declare_weak (*node);
1996 else
1997 warning (OPT_Wattributes, "%qE attribute ignored", name);
1999 return NULL_TREE;
2002 /* Handle a "noplt" attribute; arguments as in
2003 struct attribute_spec.handler. */
2005 static tree
2006 handle_noplt_attribute (tree *node, tree name,
2007 tree ARG_UNUSED (args),
2008 int ARG_UNUSED (flags),
2009 bool * ARG_UNUSED (no_add_attrs))
2011 if (TREE_CODE (*node) != FUNCTION_DECL)
2013 warning (OPT_Wattributes,
2014 "%qE attribute is only applicable on functions", name);
2015 *no_add_attrs = true;
2016 return NULL_TREE;
2018 return NULL_TREE;
2021 /* Handle an "alias" or "ifunc" attribute; arguments as in
2022 struct attribute_spec.handler, except that IS_ALIAS tells us
2023 whether this is an alias as opposed to ifunc attribute. */
2025 static tree
2026 handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args,
2027 bool *no_add_attrs)
2029 tree decl = *node;
2031 if (TREE_CODE (decl) != FUNCTION_DECL
2032 && (!is_alias || !VAR_P (decl)))
2034 warning (OPT_Wattributes, "%qE attribute ignored", name);
2035 *no_add_attrs = true;
2037 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
2038 || (TREE_CODE (decl) != FUNCTION_DECL
2039 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
2040 /* A static variable declaration is always a tentative definition,
2041 but the alias is a non-tentative definition which overrides. */
2042 || (TREE_CODE (decl) != FUNCTION_DECL
2043 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
2045 error ("%q+D defined both normally and as %qE attribute", decl, name);
2046 *no_add_attrs = true;
2047 return NULL_TREE;
2049 else if (!is_alias
2050 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2051 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))))
2053 error ("weak %q+D cannot be defined %qE", decl, name);
2054 *no_add_attrs = true;
2055 return NULL_TREE;
2058 /* Note that the very first time we process a nested declaration,
2059 decl_function_context will not be set. Indeed, *would* never
2060 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2061 we do below. After such frobbery, pushdecl would set the context.
2062 In any case, this is never what we want. */
2063 else if (decl_function_context (decl) == 0 && current_function_decl == NULL)
2065 tree id;
2067 id = TREE_VALUE (args);
2068 if (TREE_CODE (id) != STRING_CST)
2070 error ("attribute %qE argument not a string", name);
2071 *no_add_attrs = true;
2072 return NULL_TREE;
2074 id = get_identifier (TREE_STRING_POINTER (id));
2075 /* This counts as a use of the object pointed to. */
2076 TREE_USED (id) = 1;
2078 if (TREE_CODE (decl) == FUNCTION_DECL)
2079 DECL_INITIAL (decl) = error_mark_node;
2080 else
2081 TREE_STATIC (decl) = 1;
2083 if (!is_alias)
2085 /* ifuncs are also aliases, so set that attribute too. */
2086 DECL_ATTRIBUTES (decl)
2087 = tree_cons (get_identifier ("alias"), args,
2088 DECL_ATTRIBUTES (decl));
2089 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("ifunc"),
2090 NULL, DECL_ATTRIBUTES (decl));
2093 else
2095 warning (OPT_Wattributes, "%qE attribute ignored", name);
2096 *no_add_attrs = true;
2099 if (decl_in_symtab_p (*node))
2101 struct symtab_node *n = symtab_node::get (decl);
2102 if (n && n->refuse_visibility_changes)
2104 if (is_alias)
2105 error ("%+qD declared alias after being used", decl);
2106 else
2107 error ("%+qD declared ifunc after being used", decl);
2112 return NULL_TREE;
2115 /* Handle an "alias" or "ifunc" attribute; arguments as in
2116 struct attribute_spec.handler. */
2118 static tree
2119 handle_ifunc_attribute (tree *node, tree name, tree args,
2120 int ARG_UNUSED (flags), bool *no_add_attrs)
2122 return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs);
2125 /* Handle an "alias" or "ifunc" attribute; arguments as in
2126 struct attribute_spec.handler. */
2128 static tree
2129 handle_alias_attribute (tree *node, tree name, tree args,
2130 int ARG_UNUSED (flags), bool *no_add_attrs)
2132 return handle_alias_ifunc_attribute (true, node, name, args, no_add_attrs);
2135 /* Handle a "weakref" attribute; arguments as in struct
2136 attribute_spec.handler. */
2138 static tree
2139 handle_weakref_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2140 int flags, bool *no_add_attrs)
2142 tree attr = NULL_TREE;
2144 /* We must ignore the attribute when it is associated with
2145 local-scoped decls, since attribute alias is ignored and many
2146 such symbols do not even have a DECL_WEAK field. */
2147 if (decl_function_context (*node)
2148 || current_function_decl
2149 || !VAR_OR_FUNCTION_DECL_P (*node))
2151 warning (OPT_Wattributes, "%qE attribute ignored", name);
2152 *no_add_attrs = true;
2153 return NULL_TREE;
2156 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
2158 error ("indirect function %q+D cannot be declared weakref", *node);
2159 *no_add_attrs = true;
2160 return NULL_TREE;
2163 /* The idea here is that `weakref("name")' mutates into `weakref,
2164 alias("name")', and weakref without arguments, in turn,
2165 implicitly adds weak. */
2167 if (args)
2169 attr = tree_cons (get_identifier ("alias"), args, attr);
2170 attr = tree_cons (get_identifier ("weakref"), NULL_TREE, attr);
2172 *no_add_attrs = true;
2174 decl_attributes (node, attr, flags);
2176 else
2178 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node)))
2179 error_at (DECL_SOURCE_LOCATION (*node),
2180 "weakref attribute must appear before alias attribute");
2182 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2183 and that isn't supported; and because it wants to add it to
2184 the list of weak decls, which isn't helpful. */
2185 DECL_WEAK (*node) = 1;
2188 if (decl_in_symtab_p (*node))
2190 struct symtab_node *n = symtab_node::get (*node);
2191 if (n && n->refuse_visibility_changes)
2192 error ("%+qD declared weakref after being used", *node);
2195 return NULL_TREE;
2198 /* Handle an "visibility" attribute; arguments as in
2199 struct attribute_spec.handler. */
2201 static tree
2202 handle_visibility_attribute (tree *node, tree name, tree args,
2203 int ARG_UNUSED (flags),
2204 bool *ARG_UNUSED (no_add_attrs))
2206 tree decl = *node;
2207 tree id = TREE_VALUE (args);
2208 enum symbol_visibility vis;
2210 if (TYPE_P (*node))
2212 if (TREE_CODE (*node) == ENUMERAL_TYPE)
2213 /* OK */;
2214 else if (!RECORD_OR_UNION_TYPE_P (*node))
2216 warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
2217 name);
2218 return NULL_TREE;
2220 else if (TYPE_FIELDS (*node))
2222 error ("%qE attribute ignored because %qT is already defined",
2223 name, *node);
2224 return NULL_TREE;
2227 else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
2229 warning (OPT_Wattributes, "%qE attribute ignored", name);
2230 return NULL_TREE;
2233 if (TREE_CODE (id) != STRING_CST)
2235 error ("visibility argument not a string");
2236 return NULL_TREE;
2239 /* If this is a type, set the visibility on the type decl. */
2240 if (TYPE_P (decl))
2242 decl = TYPE_NAME (decl);
2243 if (!decl)
2244 return NULL_TREE;
2245 if (TREE_CODE (decl) == IDENTIFIER_NODE)
2247 warning (OPT_Wattributes, "%qE attribute ignored on types",
2248 name);
2249 return NULL_TREE;
2253 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
2254 vis = VISIBILITY_DEFAULT;
2255 else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
2256 vis = VISIBILITY_INTERNAL;
2257 else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
2258 vis = VISIBILITY_HIDDEN;
2259 else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
2260 vis = VISIBILITY_PROTECTED;
2261 else
2263 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2264 vis = VISIBILITY_DEFAULT;
2267 if (DECL_VISIBILITY_SPECIFIED (decl)
2268 && vis != DECL_VISIBILITY (decl))
2270 tree attributes = (TYPE_P (*node)
2271 ? TYPE_ATTRIBUTES (*node)
2272 : DECL_ATTRIBUTES (decl));
2273 if (lookup_attribute ("visibility", attributes))
2274 error ("%qD redeclared with different visibility", decl);
2275 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2276 && lookup_attribute ("dllimport", attributes))
2277 error ("%qD was declared %qs which implies default visibility",
2278 decl, "dllimport");
2279 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2280 && lookup_attribute ("dllexport", attributes))
2281 error ("%qD was declared %qs which implies default visibility",
2282 decl, "dllexport");
2285 DECL_VISIBILITY (decl) = vis;
2286 DECL_VISIBILITY_SPECIFIED (decl) = 1;
2288 /* Go ahead and attach the attribute to the node as well. This is needed
2289 so we can determine whether we have VISIBILITY_DEFAULT because the
2290 visibility was not specified, or because it was explicitly overridden
2291 from the containing scope. */
2293 return NULL_TREE;
2296 /* Handle an "tls_model" attribute; arguments as in
2297 struct attribute_spec.handler. */
2299 static tree
2300 handle_tls_model_attribute (tree *node, tree name, tree args,
2301 int ARG_UNUSED (flags), bool *no_add_attrs)
2303 tree id;
2304 tree decl = *node;
2305 enum tls_model kind;
2307 *no_add_attrs = true;
2309 if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
2311 warning (OPT_Wattributes, "%qE attribute ignored", name);
2312 return NULL_TREE;
2315 kind = DECL_TLS_MODEL (decl);
2316 id = TREE_VALUE (args);
2317 if (TREE_CODE (id) != STRING_CST)
2319 error ("tls_model argument not a string");
2320 return NULL_TREE;
2323 if (!strcmp (TREE_STRING_POINTER (id), "local-exec"))
2324 kind = TLS_MODEL_LOCAL_EXEC;
2325 else if (!strcmp (TREE_STRING_POINTER (id), "initial-exec"))
2326 kind = TLS_MODEL_INITIAL_EXEC;
2327 else if (!strcmp (TREE_STRING_POINTER (id), "local-dynamic"))
2328 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
2329 else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
2330 kind = TLS_MODEL_GLOBAL_DYNAMIC;
2331 else
2332 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2334 set_decl_tls_model (decl, kind);
2335 return NULL_TREE;
2338 /* Handle a "no_instrument_function" attribute; arguments as in
2339 struct attribute_spec.handler. */
2341 static tree
2342 handle_no_instrument_function_attribute (tree *node, tree name,
2343 tree ARG_UNUSED (args),
2344 int ARG_UNUSED (flags),
2345 bool *no_add_attrs)
2347 tree decl = *node;
2349 if (TREE_CODE (decl) != FUNCTION_DECL)
2351 error_at (DECL_SOURCE_LOCATION (decl),
2352 "%qE attribute applies only to functions", name);
2353 *no_add_attrs = true;
2355 else
2356 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
2358 return NULL_TREE;
2361 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2362 struct attribute_spec.handler. */
2364 static tree
2365 handle_no_profile_instrument_function_attribute (tree *node, tree name, tree,
2366 int, bool *no_add_attrs)
2368 if (TREE_CODE (*node) != FUNCTION_DECL)
2370 warning (OPT_Wattributes, "%qE attribute ignored", name);
2371 *no_add_attrs = true;
2374 return NULL_TREE;
2377 /* Handle a "malloc" attribute; arguments as in
2378 struct attribute_spec.handler. */
2380 static tree
2381 handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2382 int ARG_UNUSED (flags), bool *no_add_attrs)
2384 if (TREE_CODE (*node) == FUNCTION_DECL
2385 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
2386 DECL_IS_MALLOC (*node) = 1;
2387 else
2389 warning (OPT_Wattributes, "%qE attribute ignored", name);
2390 *no_add_attrs = true;
2393 return NULL_TREE;
2396 /* Handle a "alloc_size" attribute; arguments as in
2397 struct attribute_spec.handler. */
2399 static tree
2400 handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2401 int ARG_UNUSED (flags), bool *no_add_attrs)
2403 unsigned arg_count = type_num_arguments (*node);
2404 for (; args; args = TREE_CHAIN (args))
2406 tree position = TREE_VALUE (args);
2407 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2408 && TREE_CODE (position) != FUNCTION_DECL)
2409 position = default_conversion (position);
2411 if (!tree_fits_uhwi_p (position)
2412 || !arg_count
2413 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2415 warning (OPT_Wattributes,
2416 "alloc_size parameter outside range");
2417 *no_add_attrs = true;
2418 return NULL_TREE;
2421 return NULL_TREE;
2424 /* Handle a "alloc_align" attribute; arguments as in
2425 struct attribute_spec.handler. */
2427 static tree
2428 handle_alloc_align_attribute (tree *node, tree, tree args, int,
2429 bool *no_add_attrs)
2431 unsigned arg_count = type_num_arguments (*node);
2432 tree position = TREE_VALUE (args);
2433 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2434 && TREE_CODE (position) != FUNCTION_DECL)
2435 position = default_conversion (position);
2437 if (!tree_fits_uhwi_p (position)
2438 || !arg_count
2439 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2441 warning (OPT_Wattributes,
2442 "alloc_align parameter outside range");
2443 *no_add_attrs = true;
2444 return NULL_TREE;
2446 return NULL_TREE;
2449 /* Handle a "assume_aligned" attribute; arguments as in
2450 struct attribute_spec.handler. */
2452 static tree
2453 handle_assume_aligned_attribute (tree *, tree, tree args, int,
2454 bool *no_add_attrs)
2456 for (; args; args = TREE_CHAIN (args))
2458 tree position = TREE_VALUE (args);
2459 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2460 && TREE_CODE (position) != FUNCTION_DECL)
2461 position = default_conversion (position);
2463 if (TREE_CODE (position) != INTEGER_CST)
2465 warning (OPT_Wattributes,
2466 "assume_aligned parameter not integer constant");
2467 *no_add_attrs = true;
2468 return NULL_TREE;
2471 return NULL_TREE;
2474 /* Handle a "fn spec" attribute; arguments as in
2475 struct attribute_spec.handler. */
2477 static tree
2478 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
2479 tree args, int ARG_UNUSED (flags),
2480 bool *no_add_attrs ATTRIBUTE_UNUSED)
2482 gcc_assert (args
2483 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
2484 && !TREE_CHAIN (args));
2485 return NULL_TREE;
2488 /* Handle a "bnd_variable_size" attribute; arguments as in
2489 struct attribute_spec.handler. */
2491 static tree
2492 handle_bnd_variable_size_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2493 int ARG_UNUSED (flags), bool *no_add_attrs)
2495 if (TREE_CODE (*node) != FIELD_DECL)
2497 warning (OPT_Wattributes, "%qE attribute ignored", name);
2498 *no_add_attrs = true;
2501 return NULL_TREE;
2504 /* Handle a "bnd_legacy" attribute; arguments as in
2505 struct attribute_spec.handler. */
2507 static tree
2508 handle_bnd_legacy (tree *node, tree name, tree ARG_UNUSED (args),
2509 int ARG_UNUSED (flags), bool *no_add_attrs)
2511 if (TREE_CODE (*node) != FUNCTION_DECL)
2513 warning (OPT_Wattributes, "%qE attribute ignored", name);
2514 *no_add_attrs = true;
2517 return NULL_TREE;
2520 /* Handle a "bnd_instrument" attribute; arguments as in
2521 struct attribute_spec.handler. */
2523 static tree
2524 handle_bnd_instrument (tree *node, tree name, tree ARG_UNUSED (args),
2525 int ARG_UNUSED (flags), bool *no_add_attrs)
2527 if (TREE_CODE (*node) != FUNCTION_DECL)
2529 warning (OPT_Wattributes, "%qE attribute ignored", name);
2530 *no_add_attrs = true;
2533 return NULL_TREE;
2536 /* Handle a "warn_unused" attribute; arguments as in
2537 struct attribute_spec.handler. */
2539 static tree
2540 handle_warn_unused_attribute (tree *node, tree name,
2541 tree args ATTRIBUTE_UNUSED,
2542 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2544 if (TYPE_P (*node))
2545 /* Do nothing else, just set the attribute. We'll get at
2546 it later with lookup_attribute. */
2548 else
2550 warning (OPT_Wattributes, "%qE attribute ignored", name);
2551 *no_add_attrs = true;
2554 return NULL_TREE;
2557 /* Handle an "omp declare simd" attribute; arguments as in
2558 struct attribute_spec.handler. */
2560 static tree
2561 handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *)
2563 return NULL_TREE;
2566 /* Handle a "simd" attribute. */
2568 static tree
2569 handle_simd_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs)
2571 if (TREE_CODE (*node) == FUNCTION_DECL)
2573 tree t = get_identifier ("omp declare simd");
2574 tree attr = NULL_TREE;
2575 if (args)
2577 tree id = TREE_VALUE (args);
2579 if (TREE_CODE (id) != STRING_CST)
2581 error ("attribute %qE argument not a string", name);
2582 *no_add_attrs = true;
2583 return NULL_TREE;
2586 if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
2587 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2588 OMP_CLAUSE_NOTINBRANCH);
2589 else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
2590 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2591 OMP_CLAUSE_INBRANCH);
2592 else
2594 error ("only %<inbranch%> and %<notinbranch%> flags are "
2595 "allowed for %<__simd__%> attribute");
2596 *no_add_attrs = true;
2597 return NULL_TREE;
2601 DECL_ATTRIBUTES (*node)
2602 = tree_cons (t, build_tree_list (NULL_TREE, attr),
2603 DECL_ATTRIBUTES (*node));
2605 else
2607 warning (OPT_Wattributes, "%qE attribute ignored", name);
2608 *no_add_attrs = true;
2611 return NULL_TREE;
2614 /* Handle an "omp declare target" attribute; arguments as in
2615 struct attribute_spec.handler. */
2617 static tree
2618 handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
2620 return NULL_TREE;
2623 /* Handle a "returns_twice" attribute; arguments as in
2624 struct attribute_spec.handler. */
2626 static tree
2627 handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2628 int ARG_UNUSED (flags), bool *no_add_attrs)
2630 if (TREE_CODE (*node) == FUNCTION_DECL)
2631 DECL_IS_RETURNS_TWICE (*node) = 1;
2632 else
2634 warning (OPT_Wattributes, "%qE attribute ignored", name);
2635 *no_add_attrs = true;
2638 return NULL_TREE;
2641 /* Handle a "no_limit_stack" attribute; arguments as in
2642 struct attribute_spec.handler. */
2644 static tree
2645 handle_no_limit_stack_attribute (tree *node, tree name,
2646 tree ARG_UNUSED (args),
2647 int ARG_UNUSED (flags),
2648 bool *no_add_attrs)
2650 tree decl = *node;
2652 if (TREE_CODE (decl) != FUNCTION_DECL)
2654 error_at (DECL_SOURCE_LOCATION (decl),
2655 "%qE attribute applies only to functions", name);
2656 *no_add_attrs = true;
2658 else if (DECL_INITIAL (decl))
2660 error_at (DECL_SOURCE_LOCATION (decl),
2661 "can%'t set %qE attribute after definition", name);
2662 *no_add_attrs = true;
2664 else
2665 DECL_NO_LIMIT_STACK (decl) = 1;
2667 return NULL_TREE;
2670 /* Handle a "pure" attribute; arguments as in
2671 struct attribute_spec.handler. */
2673 static tree
2674 handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2675 int ARG_UNUSED (flags), bool *no_add_attrs)
2677 if (TREE_CODE (*node) == FUNCTION_DECL)
2679 tree type = TREE_TYPE (*node);
2680 if (VOID_TYPE_P (TREE_TYPE (type)))
2681 warning (OPT_Wattributes, "%qE attribute on function "
2682 "returning %<void%>", name);
2684 DECL_PURE_P (*node) = 1;
2685 /* ??? TODO: Support types. */
2687 else
2689 warning (OPT_Wattributes, "%qE attribute ignored", name);
2690 *no_add_attrs = true;
2693 return NULL_TREE;
2696 /* Digest an attribute list destined for a transactional memory statement.
2697 ALLOWED is the set of attributes that are allowed for this statement;
2698 return the attribute we parsed. Multiple attributes are never allowed. */
2701 parse_tm_stmt_attr (tree attrs, int allowed)
2703 tree a_seen = NULL;
2704 int m_seen = 0;
2706 for ( ; attrs ; attrs = TREE_CHAIN (attrs))
2708 tree a = TREE_PURPOSE (attrs);
2709 int m = 0;
2711 if (is_attribute_p ("outer", a))
2712 m = TM_STMT_ATTR_OUTER;
2714 if ((m & allowed) == 0)
2716 warning (OPT_Wattributes, "%qE attribute directive ignored", a);
2717 continue;
2720 if (m_seen == 0)
2722 a_seen = a;
2723 m_seen = m;
2725 else if (m_seen == m)
2726 warning (OPT_Wattributes, "%qE attribute duplicated", a);
2727 else
2728 warning (OPT_Wattributes, "%qE attribute follows %qE", a, a_seen);
2731 return m_seen;
2734 /* Transform a TM attribute name into a maskable integer and back.
2735 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2736 to how the lack of an attribute is treated. */
2739 tm_attr_to_mask (tree attr)
2741 if (attr == NULL)
2742 return 0;
2743 if (is_attribute_p ("transaction_safe", attr))
2744 return TM_ATTR_SAFE;
2745 if (is_attribute_p ("transaction_callable", attr))
2746 return TM_ATTR_CALLABLE;
2747 if (is_attribute_p ("transaction_pure", attr))
2748 return TM_ATTR_PURE;
2749 if (is_attribute_p ("transaction_unsafe", attr))
2750 return TM_ATTR_IRREVOCABLE;
2751 if (is_attribute_p ("transaction_may_cancel_outer", attr))
2752 return TM_ATTR_MAY_CANCEL_OUTER;
2753 return 0;
2756 tree
2757 tm_mask_to_attr (int mask)
2759 const char *str;
2760 switch (mask)
2762 case TM_ATTR_SAFE:
2763 str = "transaction_safe";
2764 break;
2765 case TM_ATTR_CALLABLE:
2766 str = "transaction_callable";
2767 break;
2768 case TM_ATTR_PURE:
2769 str = "transaction_pure";
2770 break;
2771 case TM_ATTR_IRREVOCABLE:
2772 str = "transaction_unsafe";
2773 break;
2774 case TM_ATTR_MAY_CANCEL_OUTER:
2775 str = "transaction_may_cancel_outer";
2776 break;
2777 default:
2778 gcc_unreachable ();
2780 return get_identifier (str);
2783 /* Return the first TM attribute seen in LIST. */
2785 tree
2786 find_tm_attribute (tree list)
2788 for (; list ; list = TREE_CHAIN (list))
2790 tree name = TREE_PURPOSE (list);
2791 if (tm_attr_to_mask (name) != 0)
2792 return name;
2794 return NULL_TREE;
2797 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2798 Here we accept only function types, and verify that none of the other
2799 function TM attributes are also applied. */
2800 /* ??? We need to accept class types for C++, but not C. This greatly
2801 complicates this function, since we can no longer rely on the extra
2802 processing given by function_type_required. */
2804 static tree
2805 handle_tm_attribute (tree *node, tree name, tree args,
2806 int flags, bool *no_add_attrs)
2808 /* Only one path adds the attribute; others don't. */
2809 *no_add_attrs = true;
2811 switch (TREE_CODE (*node))
2813 case RECORD_TYPE:
2814 case UNION_TYPE:
2815 /* Only tm_callable and tm_safe apply to classes. */
2816 if (tm_attr_to_mask (name) & ~(TM_ATTR_SAFE | TM_ATTR_CALLABLE))
2817 goto ignored;
2818 /* FALLTHRU */
2820 case FUNCTION_TYPE:
2821 case METHOD_TYPE:
2823 tree old_name = find_tm_attribute (TYPE_ATTRIBUTES (*node));
2824 if (old_name == name)
2826 else if (old_name != NULL_TREE)
2827 error ("type was previously declared %qE", old_name);
2828 else
2829 *no_add_attrs = false;
2831 break;
2833 case FUNCTION_DECL:
2835 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2836 want to set transaction_safe on the type. */
2837 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name));
2838 if (!TYPE_P (DECL_CONTEXT (*node)))
2839 error_at (DECL_SOURCE_LOCATION (*node),
2840 "%<transaction_safe_dynamic%> may only be specified for "
2841 "a virtual function");
2842 *no_add_attrs = false;
2843 decl_attributes (&TREE_TYPE (*node),
2844 build_tree_list (get_identifier ("transaction_safe"),
2845 NULL_TREE),
2847 break;
2850 case POINTER_TYPE:
2852 enum tree_code subcode = TREE_CODE (TREE_TYPE (*node));
2853 if (subcode == FUNCTION_TYPE || subcode == METHOD_TYPE)
2855 tree fn_tmp = TREE_TYPE (*node);
2856 decl_attributes (&fn_tmp, tree_cons (name, args, NULL), 0);
2857 *node = build_pointer_type (fn_tmp);
2858 break;
2861 /* FALLTHRU */
2863 default:
2864 /* If a function is next, pass it on to be tried next. */
2865 if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
2866 return tree_cons (name, args, NULL);
2868 ignored:
2869 warning (OPT_Wattributes, "%qE attribute ignored", name);
2870 break;
2873 return NULL_TREE;
2876 /* Handle the TM_WRAP attribute; arguments as in
2877 struct attribute_spec.handler. */
2879 static tree
2880 handle_tm_wrap_attribute (tree *node, tree name, tree args,
2881 int ARG_UNUSED (flags), bool *no_add_attrs)
2883 tree decl = *node;
2885 /* We don't need the attribute even on success, since we
2886 record the entry in an external table. */
2887 *no_add_attrs = true;
2889 if (TREE_CODE (decl) != FUNCTION_DECL)
2890 warning (OPT_Wattributes, "%qE attribute ignored", name);
2891 else
2893 tree wrap_decl = TREE_VALUE (args);
2894 if (error_operand_p (wrap_decl))
2896 else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
2897 && !VAR_OR_FUNCTION_DECL_P (wrap_decl))
2898 error ("%qE argument not an identifier", name);
2899 else
2901 if (TREE_CODE (wrap_decl) == IDENTIFIER_NODE)
2902 wrap_decl = lookup_name (wrap_decl);
2903 if (wrap_decl && TREE_CODE (wrap_decl) == FUNCTION_DECL)
2905 if (lang_hooks.types_compatible_p (TREE_TYPE (decl),
2906 TREE_TYPE (wrap_decl)))
2907 record_tm_replacement (wrap_decl, decl);
2908 else
2909 error ("%qD is not compatible with %qD", wrap_decl, decl);
2911 else
2912 error ("%qE argument is not a function", name);
2916 return NULL_TREE;
2919 /* Ignore the given attribute. Used when this attribute may be usefully
2920 overridden by the target, but is not used generically. */
2922 static tree
2923 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
2924 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2925 bool *no_add_attrs)
2927 *no_add_attrs = true;
2928 return NULL_TREE;
2931 /* Handle a "no vops" attribute; arguments as in
2932 struct attribute_spec.handler. */
2934 static tree
2935 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
2936 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2937 bool *ARG_UNUSED (no_add_attrs))
2939 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
2940 DECL_IS_NOVOPS (*node) = 1;
2941 return NULL_TREE;
2944 /* Handle a "deprecated" attribute; arguments as in
2945 struct attribute_spec.handler. */
2947 static tree
2948 handle_deprecated_attribute (tree *node, tree name,
2949 tree args, int flags,
2950 bool *no_add_attrs)
2952 tree type = NULL_TREE;
2953 int warn = 0;
2954 tree what = NULL_TREE;
2956 if (!args)
2957 *no_add_attrs = true;
2958 else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
2960 error ("deprecated message is not a string");
2961 *no_add_attrs = true;
2964 if (DECL_P (*node))
2966 tree decl = *node;
2967 type = TREE_TYPE (decl);
2969 if (TREE_CODE (decl) == TYPE_DECL
2970 || TREE_CODE (decl) == PARM_DECL
2971 || VAR_OR_FUNCTION_DECL_P (decl)
2972 || TREE_CODE (decl) == FIELD_DECL
2973 || TREE_CODE (decl) == CONST_DECL
2974 || objc_method_decl (TREE_CODE (decl)))
2975 TREE_DEPRECATED (decl) = 1;
2976 else
2977 warn = 1;
2979 else if (TYPE_P (*node))
2981 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
2982 *node = build_variant_type_copy (*node);
2983 TREE_DEPRECATED (*node) = 1;
2984 type = *node;
2986 else
2987 warn = 1;
2989 if (warn)
2991 *no_add_attrs = true;
2992 if (type && TYPE_NAME (type))
2994 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2995 what = TYPE_NAME (*node);
2996 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
2997 && DECL_NAME (TYPE_NAME (type)))
2998 what = DECL_NAME (TYPE_NAME (type));
3000 if (what)
3001 warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
3002 else
3003 warning (OPT_Wattributes, "%qE attribute ignored", name);
3006 return NULL_TREE;
3009 /* Handle a "vector_size" attribute; arguments as in
3010 struct attribute_spec.handler. */
3012 static tree
3013 handle_vector_size_attribute (tree *node, tree name, tree args,
3014 int ARG_UNUSED (flags),
3015 bool *no_add_attrs)
3017 unsigned HOST_WIDE_INT vecsize, nunits;
3018 machine_mode orig_mode;
3019 tree type = *node, new_type, size;
3021 *no_add_attrs = true;
3023 size = TREE_VALUE (args);
3024 if (size && TREE_CODE (size) != IDENTIFIER_NODE
3025 && TREE_CODE (size) != FUNCTION_DECL)
3026 size = default_conversion (size);
3028 if (!tree_fits_uhwi_p (size))
3030 warning (OPT_Wattributes, "%qE attribute ignored", name);
3031 return NULL_TREE;
3034 /* Get the vector size (in bytes). */
3035 vecsize = tree_to_uhwi (size);
3037 /* We need to provide for vector pointers, vector arrays, and
3038 functions returning vectors. For example:
3040 __attribute__((vector_size(16))) short *foo;
3042 In this case, the mode is SI, but the type being modified is
3043 HI, so we need to look further. */
3045 while (POINTER_TYPE_P (type)
3046 || TREE_CODE (type) == FUNCTION_TYPE
3047 || TREE_CODE (type) == METHOD_TYPE
3048 || TREE_CODE (type) == ARRAY_TYPE
3049 || TREE_CODE (type) == OFFSET_TYPE)
3050 type = TREE_TYPE (type);
3052 /* Get the mode of the type being modified. */
3053 orig_mode = TYPE_MODE (type);
3055 if ((!INTEGRAL_TYPE_P (type)
3056 && !SCALAR_FLOAT_TYPE_P (type)
3057 && !FIXED_POINT_TYPE_P (type))
3058 || (!SCALAR_FLOAT_MODE_P (orig_mode)
3059 && GET_MODE_CLASS (orig_mode) != MODE_INT
3060 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
3061 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
3062 || TREE_CODE (type) == BOOLEAN_TYPE)
3064 error ("invalid vector type for attribute %qE", name);
3065 return NULL_TREE;
3068 if (vecsize % tree_to_uhwi (TYPE_SIZE_UNIT (type)))
3070 error ("vector size not an integral multiple of component size");
3071 return NULL;
3074 if (vecsize == 0)
3076 error ("zero vector size");
3077 return NULL;
3080 /* Calculate how many units fit in the vector. */
3081 nunits = vecsize / tree_to_uhwi (TYPE_SIZE_UNIT (type));
3082 if (nunits & (nunits - 1))
3084 error ("number of components of the vector not a power of two");
3085 return NULL_TREE;
3088 new_type = build_vector_type (type, nunits);
3090 /* Build back pointers if needed. */
3091 *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
3093 return NULL_TREE;
3096 /* Handle the "nonnull" attribute. */
3098 static tree
3099 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
3100 tree args, int ARG_UNUSED (flags),
3101 bool *no_add_attrs)
3103 tree type = *node;
3104 unsigned HOST_WIDE_INT attr_arg_num;
3106 /* If no arguments are specified, all pointer arguments should be
3107 non-null. Verify a full prototype is given so that the arguments
3108 will have the correct types when we actually check them later.
3109 Avoid diagnosing type-generic built-ins since those have no
3110 prototype. */
3111 if (!args)
3113 if (!prototype_p (type)
3114 && (!TYPE_ATTRIBUTES (type)
3115 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type))))
3117 error ("nonnull attribute without arguments on a non-prototype");
3118 *no_add_attrs = true;
3120 return NULL_TREE;
3123 /* Argument list specified. Verify that each argument number references
3124 a pointer argument. */
3125 for (attr_arg_num = 1; args; attr_arg_num++, args = TREE_CHAIN (args))
3127 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
3129 tree arg = TREE_VALUE (args);
3130 if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
3131 && TREE_CODE (arg) != FUNCTION_DECL)
3132 TREE_VALUE (args) = arg = default_conversion (arg);
3134 if (!get_nonnull_operand (arg, &arg_num))
3136 error ("nonnull argument has invalid operand number (argument %lu)",
3137 (unsigned long) attr_arg_num);
3138 *no_add_attrs = true;
3139 return NULL_TREE;
3142 if (prototype_p (type))
3144 function_args_iterator iter;
3145 tree argument;
3147 function_args_iter_init (&iter, type);
3148 for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter))
3150 argument = function_args_iter_cond (&iter);
3151 if (argument == NULL_TREE || ck_num == arg_num)
3152 break;
3155 if (!argument
3156 || TREE_CODE (argument) == VOID_TYPE)
3158 error ("nonnull argument with out-of-range operand number "
3159 "(argument %lu, operand %lu)",
3160 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3161 *no_add_attrs = true;
3162 return NULL_TREE;
3165 if (TREE_CODE (argument) != POINTER_TYPE)
3167 error ("nonnull argument references non-pointer operand "
3168 "(argument %lu, operand %lu)",
3169 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3170 *no_add_attrs = true;
3171 return NULL_TREE;
3176 return NULL_TREE;
3179 /* Handle the "nonstring" variable attribute. */
3181 static tree
3182 handle_nonstring_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3183 int ARG_UNUSED (flags), bool *no_add_attrs)
3185 gcc_assert (!args);
3186 tree_code code = TREE_CODE (*node);
3188 if (VAR_P (*node)
3189 || code == FIELD_DECL
3190 || code == PARM_DECL)
3192 tree type = TREE_TYPE (*node);
3194 if (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
3196 tree eltype = TREE_TYPE (type);
3197 if (eltype == char_type_node)
3198 return NULL_TREE;
3201 warning (OPT_Wattributes,
3202 "%qE attribute ignored on objects of type %qT",
3203 name, type);
3204 *no_add_attrs = true;
3205 return NULL_TREE;
3208 if (code == FUNCTION_DECL)
3209 warning (OPT_Wattributes,
3210 "%qE attribute does not apply to functions", name);
3211 else if (code == TYPE_DECL)
3212 warning (OPT_Wattributes,
3213 "%qE attribute does not apply to types", name);
3214 else
3215 warning (OPT_Wattributes, "%qE attribute ignored", name);
3217 *no_add_attrs = true;
3218 return NULL_TREE;
3221 /* Handle a "nothrow" attribute; arguments as in
3222 struct attribute_spec.handler. */
3224 static tree
3225 handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3226 int ARG_UNUSED (flags), bool *no_add_attrs)
3228 if (TREE_CODE (*node) == FUNCTION_DECL)
3229 TREE_NOTHROW (*node) = 1;
3230 /* ??? TODO: Support types. */
3231 else
3233 warning (OPT_Wattributes, "%qE attribute ignored", name);
3234 *no_add_attrs = true;
3237 return NULL_TREE;
3240 /* Handle a "cleanup" attribute; arguments as in
3241 struct attribute_spec.handler. */
3243 static tree
3244 handle_cleanup_attribute (tree *node, tree name, tree args,
3245 int ARG_UNUSED (flags), bool *no_add_attrs)
3247 tree decl = *node;
3248 tree cleanup_id, cleanup_decl;
3250 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3251 for global destructors in C++. This requires infrastructure that
3252 we don't have generically at the moment. It's also not a feature
3253 we'd be missing too much, since we do have attribute constructor. */
3254 if (!VAR_P (decl) || TREE_STATIC (decl))
3256 warning (OPT_Wattributes, "%qE attribute ignored", name);
3257 *no_add_attrs = true;
3258 return NULL_TREE;
3261 /* Verify that the argument is a function in scope. */
3262 /* ??? We could support pointers to functions here as well, if
3263 that was considered desirable. */
3264 cleanup_id = TREE_VALUE (args);
3265 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
3267 error ("cleanup argument not an identifier");
3268 *no_add_attrs = true;
3269 return NULL_TREE;
3271 cleanup_decl = lookup_name (cleanup_id);
3272 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
3274 error ("cleanup argument not a function");
3275 *no_add_attrs = true;
3276 return NULL_TREE;
3279 /* That the function has proper type is checked with the
3280 eventual call to build_function_call. */
3282 return NULL_TREE;
3285 /* Handle a "warn_unused_result" attribute. No special handling. */
3287 static tree
3288 handle_warn_unused_result_attribute (tree *node, tree name,
3289 tree ARG_UNUSED (args),
3290 int ARG_UNUSED (flags), bool *no_add_attrs)
3292 /* Ignore the attribute for functions not returning any value. */
3293 if (VOID_TYPE_P (TREE_TYPE (*node)))
3295 warning (OPT_Wattributes, "%qE attribute ignored", name);
3296 *no_add_attrs = true;
3299 return NULL_TREE;
3302 /* Handle a "sentinel" attribute. */
3304 static tree
3305 handle_sentinel_attribute (tree *node, tree name, tree args,
3306 int ARG_UNUSED (flags), bool *no_add_attrs)
3308 if (!prototype_p (*node))
3310 warning (OPT_Wattributes,
3311 "%qE attribute requires prototypes with named arguments", name);
3312 *no_add_attrs = true;
3314 else
3316 if (!stdarg_p (*node))
3318 warning (OPT_Wattributes,
3319 "%qE attribute only applies to variadic functions", name);
3320 *no_add_attrs = true;
3324 if (args)
3326 tree position = TREE_VALUE (args);
3327 if (position && TREE_CODE (position) != IDENTIFIER_NODE
3328 && TREE_CODE (position) != FUNCTION_DECL)
3329 position = default_conversion (position);
3331 if (TREE_CODE (position) != INTEGER_CST
3332 || !INTEGRAL_TYPE_P (TREE_TYPE (position)))
3334 warning (OPT_Wattributes,
3335 "requested position is not an integer constant");
3336 *no_add_attrs = true;
3338 else
3340 if (tree_int_cst_lt (position, integer_zero_node))
3342 warning (OPT_Wattributes,
3343 "requested position is less than zero");
3344 *no_add_attrs = true;
3349 return NULL_TREE;
3352 /* Handle a "type_generic" attribute. */
3354 static tree
3355 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
3356 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
3357 bool * ARG_UNUSED (no_add_attrs))
3359 /* Ensure we have a function type. */
3360 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
3362 /* Ensure we have a variadic function. */
3363 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
3365 return NULL_TREE;
3368 /* Handle a "target" attribute. */
3370 static tree
3371 handle_target_attribute (tree *node, tree name, tree args, int flags,
3372 bool *no_add_attrs)
3374 /* Ensure we have a function type. */
3375 if (TREE_CODE (*node) != FUNCTION_DECL)
3377 warning (OPT_Wattributes, "%qE attribute ignored", name);
3378 *no_add_attrs = true;
3380 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
3382 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3383 "with %qs attribute", name, "target_clones");
3384 *no_add_attrs = true;
3386 else if (! targetm.target_option.valid_attribute_p (*node, name, args,
3387 flags))
3388 *no_add_attrs = true;
3390 /* Check that there's no empty string in values of the attribute. */
3391 for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
3393 tree value = TREE_VALUE (t);
3394 if (TREE_CODE (value) == STRING_CST
3395 && TREE_STRING_LENGTH (value) == 1
3396 && TREE_STRING_POINTER (value)[0] == '\0')
3398 warning (OPT_Wattributes, "empty string in attribute %<target%>");
3399 *no_add_attrs = true;
3403 return NULL_TREE;
3406 /* Handle a "target_clones" attribute. */
3408 static tree
3409 handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3410 int ARG_UNUSED (flags), bool *no_add_attrs)
3412 /* Ensure we have a function type. */
3413 if (TREE_CODE (*node) == FUNCTION_DECL)
3415 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
3417 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3418 "with %qs attribute", name, "always_inline");
3419 *no_add_attrs = true;
3421 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node)))
3423 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3424 "with %qs attribute", name, "target");
3425 *no_add_attrs = true;
3427 else
3428 /* Do not inline functions with multiple clone targets. */
3429 DECL_UNINLINABLE (*node) = 1;
3431 else
3433 warning (OPT_Wattributes, "%qE attribute ignored", name);
3434 *no_add_attrs = true;
3436 return NULL_TREE;
3439 /* For handling "optimize" attribute. arguments as in
3440 struct attribute_spec.handler. */
3442 static tree
3443 handle_optimize_attribute (tree *node, tree name, tree args,
3444 int ARG_UNUSED (flags), bool *no_add_attrs)
3446 /* Ensure we have a function type. */
3447 if (TREE_CODE (*node) != FUNCTION_DECL)
3449 warning (OPT_Wattributes, "%qE attribute ignored", name);
3450 *no_add_attrs = true;
3452 else
3454 struct cl_optimization cur_opts;
3455 tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
3457 /* Save current options. */
3458 cl_optimization_save (&cur_opts, &global_options);
3460 /* If we previously had some optimization options, use them as the
3461 default. */
3462 if (old_opts)
3463 cl_optimization_restore (&global_options,
3464 TREE_OPTIMIZATION (old_opts));
3466 /* Parse options, and update the vector. */
3467 parse_optimize_options (args, true);
3468 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
3469 = build_optimization_node (&global_options);
3471 /* Restore current options. */
3472 cl_optimization_restore (&global_options, &cur_opts);
3475 return NULL_TREE;
3478 /* Handle a "no_split_stack" attribute. */
3480 static tree
3481 handle_no_split_stack_attribute (tree *node, tree name,
3482 tree ARG_UNUSED (args),
3483 int ARG_UNUSED (flags),
3484 bool *no_add_attrs)
3486 tree decl = *node;
3488 if (TREE_CODE (decl) != FUNCTION_DECL)
3490 error_at (DECL_SOURCE_LOCATION (decl),
3491 "%qE attribute applies only to functions", name);
3492 *no_add_attrs = true;
3494 else if (DECL_INITIAL (decl))
3496 error_at (DECL_SOURCE_LOCATION (decl),
3497 "can%'t set %qE attribute after definition", name);
3498 *no_add_attrs = true;
3501 return NULL_TREE;
3504 /* Handle a "returns_nonnull" attribute; arguments as in
3505 struct attribute_spec.handler. */
3507 static tree
3508 handle_returns_nonnull_attribute (tree *node, tree, tree, int,
3509 bool *no_add_attrs)
3511 // Even without a prototype we still have a return type we can check.
3512 if (TREE_CODE (TREE_TYPE (*node)) != POINTER_TYPE)
3514 error ("returns_nonnull attribute on a function not returning a pointer");
3515 *no_add_attrs = true;
3517 return NULL_TREE;
3520 /* Handle a "designated_init" attribute; arguments as in
3521 struct attribute_spec.handler. */
3523 static tree
3524 handle_designated_init_attribute (tree *node, tree name, tree, int,
3525 bool *no_add_attrs)
3527 if (TREE_CODE (*node) != RECORD_TYPE)
3529 error ("%qE attribute is only valid on %<struct%> type", name);
3530 *no_add_attrs = true;
3532 return NULL_TREE;
3536 /* Handle a "fallthrough" attribute; arguments as in struct
3537 attribute_spec.handler. */
3539 static tree
3540 handle_fallthrough_attribute (tree *, tree name, tree, int,
3541 bool *no_add_attrs)
3543 warning (OPT_Wattributes, "%qE attribute ignored", name);
3544 *no_add_attrs = true;
3545 return NULL_TREE;
3548 static tree
3549 handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
3551 /* Nothing to be done here. */
3552 return NULL_TREE;