pa-linux.h (NEED_INDICATE_EXEC_STACK): Define to 0.
[official-gcc.git] / gcc / c-family / c-attribs.c
blobd302b4f22c7863c4a04aa828b73d8f63543b91da
1 /* C-family attributes handling.
2 Copyright (C) 1992-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "target.h"
24 #include "function.h"
25 #include "tree.h"
26 #include "memmodel.h"
27 #include "c-common.h"
28 #include "gimple-expr.h"
29 #include "tm_p.h"
30 #include "stringpool.h"
31 #include "cgraph.h"
32 #include "diagnostic.h"
33 #include "intl.h"
34 #include "stor-layout.h"
35 #include "calls.h"
36 #include "attribs.h"
37 #include "varasm.h"
38 #include "trans-mem.h"
39 #include "c-objc.h"
40 #include "common/common-target.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
43 #include "toplev.h"
44 #include "tree-iterator.h"
45 #include "opts.h"
46 #include "gimplify.h"
48 static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
49 static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
50 static tree handle_common_attribute (tree *, tree, tree, int, bool *);
51 static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *);
52 static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
53 static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
54 static tree handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
55 static tree handle_no_sanitize_address_attribute (tree *, tree, tree,
56 int, bool *);
57 static tree handle_no_sanitize_thread_attribute (tree *, tree, tree,
58 int, bool *);
59 static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree,
60 int, bool *);
61 static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int,
62 bool *);
63 static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int,
64 bool *);
65 static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *);
66 static tree handle_noinline_attribute (tree *, tree, tree, int, bool *);
67 static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
68 static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *);
69 static tree handle_noicf_attribute (tree *, tree, tree, int, bool *);
70 static tree handle_noipa_attribute (tree *, tree, tree, int, bool *);
71 static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
72 static tree handle_always_inline_attribute (tree *, tree, tree, int,
73 bool *);
74 static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *);
75 static tree handle_artificial_attribute (tree *, tree, tree, int, bool *);
76 static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
77 static tree handle_error_attribute (tree *, tree, tree, int, bool *);
78 static tree handle_used_attribute (tree *, tree, tree, int, bool *);
79 static tree handle_externally_visible_attribute (tree *, tree, tree, int,
80 bool *);
81 static tree handle_no_reorder_attribute (tree *, tree, tree, int,
82 bool *);
83 static tree handle_const_attribute (tree *, tree, tree, int, bool *);
84 static tree handle_transparent_union_attribute (tree *, tree, tree,
85 int, bool *);
86 static tree handle_scalar_storage_order_attribute (tree *, tree, tree,
87 int, bool *);
88 static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
89 static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
90 static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
91 static tree handle_section_attribute (tree *, tree, tree, int, bool *);
92 static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
93 static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree,
94 int, bool *);
95 static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
96 static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
97 static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *);
98 static tree handle_ifunc_attribute (tree *, tree, tree, int, bool *);
99 static tree handle_alias_attribute (tree *, tree, tree, int, bool *);
100 static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ;
101 static tree handle_visibility_attribute (tree *, tree, tree, int,
102 bool *);
103 static tree handle_tls_model_attribute (tree *, tree, tree, int,
104 bool *);
105 static tree handle_no_instrument_function_attribute (tree *, tree,
106 tree, int, bool *);
107 static tree handle_no_profile_instrument_function_attribute (tree *, tree,
108 tree, int, bool *);
109 static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
110 static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *);
111 static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
112 bool *);
113 static tree handle_pure_attribute (tree *, tree, tree, int, bool *);
114 static tree handle_tm_attribute (tree *, tree, tree, int, bool *);
115 static tree handle_tm_wrap_attribute (tree *, tree, tree, int, bool *);
116 static tree handle_novops_attribute (tree *, tree, tree, int, bool *);
117 static tree handle_deprecated_attribute (tree *, tree, tree, int,
118 bool *);
119 static tree handle_vector_size_attribute (tree *, tree, tree, int,
120 bool *);
121 static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
122 static tree handle_nonstring_attribute (tree *, tree, tree, int, bool *);
123 static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *);
124 static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
125 static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
126 bool *);
127 static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
128 static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *);
129 static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
130 static tree handle_alloc_align_attribute (tree *, tree, tree, int, bool *);
131 static tree handle_assume_aligned_attribute (tree *, tree, tree, int, bool *);
132 static tree handle_target_attribute (tree *, tree, tree, int, bool *);
133 static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *);
134 static tree handle_optimize_attribute (tree *, tree, tree, int, bool *);
135 static tree ignore_attribute (tree *, tree, tree, int, bool *);
136 static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *);
137 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
138 static tree handle_warn_unused_attribute (tree *, tree, tree, int, bool *);
139 static tree handle_returns_nonnull_attribute (tree *, tree, tree, int, bool *);
140 static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int,
141 bool *);
142 static tree handle_simd_attribute (tree *, tree, tree, int, bool *);
143 static tree handle_omp_declare_target_attribute (tree *, tree, tree, int,
144 bool *);
145 static tree handle_designated_init_attribute (tree *, tree, tree, int, bool *);
146 static tree handle_bnd_variable_size_attribute (tree *, tree, tree, int, bool *);
147 static tree handle_bnd_legacy (tree *, tree, tree, int, bool *);
148 static tree handle_bnd_instrument (tree *, tree, tree, int, bool *);
149 static tree handle_fallthrough_attribute (tree *, tree, tree, int, bool *);
150 static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
151 int, bool *);
153 /* Helper to define attribute exclusions. */
154 #define ATTR_EXCL(name, function, type, variable) \
155 { name, function, type, variable }
157 /* Define attributes that are mutually exclusive with one another. */
158 static const struct attribute_spec::exclusions attr_aligned_exclusions[] =
160 /* Attribute name exclusion applies to:
161 function, type, variable */
162 ATTR_EXCL ("aligned", true, false, false),
163 ATTR_EXCL ("packed", true, false, false),
164 ATTR_EXCL (NULL, false, false, false)
167 static const struct attribute_spec::exclusions attr_cold_hot_exclusions[] =
169 ATTR_EXCL ("cold", true, true, true),
170 ATTR_EXCL ("hot", true, true, true),
171 ATTR_EXCL (NULL, false, false, false)
174 static const struct attribute_spec::exclusions attr_common_exclusions[] =
176 ATTR_EXCL ("common", true, true, true),
177 ATTR_EXCL ("nocommon", true, true, true),
178 ATTR_EXCL (NULL, false, false, false),
181 static const struct attribute_spec::exclusions attr_inline_exclusions[] =
183 ATTR_EXCL ("noinline", true, true, true),
184 ATTR_EXCL (NULL, false, false, false),
187 static const struct attribute_spec::exclusions attr_noinline_exclusions[] =
189 ATTR_EXCL ("always_inline", true, true, true),
190 ATTR_EXCL ("gnu_inline", true, true, true),
191 ATTR_EXCL (NULL, false, false, false),
194 static const struct attribute_spec::exclusions attr_noreturn_exclusions[] =
196 ATTR_EXCL ("alloc_align", true, true, true),
197 ATTR_EXCL ("alloc_size", true, true, true),
198 ATTR_EXCL ("const", true, true, true),
199 ATTR_EXCL ("malloc", true, true, true),
200 ATTR_EXCL ("pure", true, true, true),
201 ATTR_EXCL ("returns_twice", true, true, true),
202 ATTR_EXCL ("warn_unused_result", true, true, true),
203 ATTR_EXCL (NULL, false, false, false),
206 static const struct attribute_spec::exclusions
207 attr_warn_unused_result_exclusions[] =
209 ATTR_EXCL ("noreturn", true, true, true),
210 ATTR_EXCL ("warn_unused_result", true, true, true),
211 ATTR_EXCL (NULL, false, false, false),
214 static const struct attribute_spec::exclusions attr_returns_twice_exclusions[] =
216 ATTR_EXCL ("noreturn", true, true, true),
217 ATTR_EXCL (NULL, false, false, false),
220 /* Exclusions that apply to attribute alloc_align, alloc_size, and malloc. */
221 static const struct attribute_spec::exclusions attr_alloc_exclusions[] =
223 ATTR_EXCL ("const", true, true, true),
224 ATTR_EXCL ("noreturn", true, true, true),
225 ATTR_EXCL ("pure", true, true, true),
226 ATTR_EXCL (NULL, false, false, false),
229 static const struct attribute_spec::exclusions attr_const_pure_exclusions[] =
231 ATTR_EXCL ("const", true, true, true),
232 ATTR_EXCL ("alloc_align", true, true, true),
233 ATTR_EXCL ("alloc_size", true, true, true),
234 ATTR_EXCL ("malloc", true, true, true),
235 ATTR_EXCL ("noreturn", true, true, true),
236 ATTR_EXCL ("pure", true, true, true),
237 ATTR_EXCL (NULL, false, false, false)
240 /* Table of machine-independent attributes common to all C-like languages.
242 All attributes referencing arguments should be additionally processed
243 in chkp_copy_function_type_adding_bounds for correct instrumentation
244 by Pointer Bounds Checker.
245 Current list of processed common attributes: nonnull. */
246 const struct attribute_spec c_common_attribute_table[] =
248 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
249 affects_type_identity, handler, exclude } */
250 { "packed", 0, 0, false, false, false, false,
251 handle_packed_attribute,
252 attr_aligned_exclusions },
253 { "nocommon", 0, 0, true, false, false, false,
254 handle_nocommon_attribute,
255 attr_common_exclusions },
256 { "common", 0, 0, true, false, false, false,
257 handle_common_attribute,
258 attr_common_exclusions },
259 /* FIXME: logically, noreturn attributes should be listed as
260 "false, true, true" and apply to function types. But implementing this
261 would require all the places in the compiler that use TREE_THIS_VOLATILE
262 on a decl to identify non-returning functions to be located and fixed
263 to check the function type instead. */
264 { "noreturn", 0, 0, true, false, false, false,
265 handle_noreturn_attribute,
266 attr_noreturn_exclusions },
267 { "volatile", 0, 0, true, false, false, false,
268 handle_noreturn_attribute, NULL },
269 { "stack_protect", 0, 0, true, false, false, false,
270 handle_stack_protect_attribute, NULL },
271 { "noinline", 0, 0, true, false, false, false,
272 handle_noinline_attribute,
273 attr_noinline_exclusions },
274 { "noclone", 0, 0, true, false, false, false,
275 handle_noclone_attribute, NULL },
276 { "no_icf", 0, 0, true, false, false, false,
277 handle_noicf_attribute, NULL },
278 { "noipa", 0, 0, true, false, false, false,
279 handle_noipa_attribute, NULL },
280 { "leaf", 0, 0, true, false, false, false,
281 handle_leaf_attribute, NULL },
282 { "always_inline", 0, 0, true, false, false, false,
283 handle_always_inline_attribute,
284 attr_inline_exclusions },
285 { "gnu_inline", 0, 0, true, false, false, false,
286 handle_gnu_inline_attribute,
287 attr_inline_exclusions },
288 { "artificial", 0, 0, true, false, false, false,
289 handle_artificial_attribute, NULL },
290 { "flatten", 0, 0, true, false, false, false,
291 handle_flatten_attribute, NULL },
292 { "used", 0, 0, true, false, false, false,
293 handle_used_attribute, NULL },
294 { "unused", 0, 0, false, false, false, false,
295 handle_unused_attribute, NULL },
296 { "externally_visible", 0, 0, true, false, false, false,
297 handle_externally_visible_attribute, NULL },
298 { "no_reorder", 0, 0, true, false, false, false,
299 handle_no_reorder_attribute, NULL },
300 /* The same comments as for noreturn attributes apply to const ones. */
301 { "const", 0, 0, true, false, false, false,
302 handle_const_attribute,
303 attr_const_pure_exclusions },
304 { "scalar_storage_order", 1, 1, false, false, false, false,
305 handle_scalar_storage_order_attribute, NULL },
306 { "transparent_union", 0, 0, false, false, false, false,
307 handle_transparent_union_attribute, NULL },
308 { "constructor", 0, 1, true, false, false, false,
309 handle_constructor_attribute, NULL },
310 { "destructor", 0, 1, true, false, false, false,
311 handle_destructor_attribute, NULL },
312 { "mode", 1, 1, false, true, false, false,
313 handle_mode_attribute, NULL },
314 { "section", 1, 1, true, false, false, false,
315 handle_section_attribute, NULL },
316 { "aligned", 0, 1, false, false, false, false,
317 handle_aligned_attribute,
318 attr_aligned_exclusions },
319 { "warn_if_not_aligned", 0, 1, false, false, false, false,
320 handle_warn_if_not_aligned_attribute, NULL },
321 { "weak", 0, 0, true, false, false, false,
322 handle_weak_attribute, NULL },
323 { "noplt", 0, 0, true, false, false, false,
324 handle_noplt_attribute, NULL },
325 { "ifunc", 1, 1, true, false, false, false,
326 handle_ifunc_attribute, NULL },
327 { "alias", 1, 1, true, false, false, false,
328 handle_alias_attribute, NULL },
329 { "weakref", 0, 1, true, false, false, false,
330 handle_weakref_attribute, NULL },
331 { "no_instrument_function", 0, 0, true, false, false, false,
332 handle_no_instrument_function_attribute,
333 NULL },
334 { "no_profile_instrument_function", 0, 0, true, false, false, false,
335 handle_no_profile_instrument_function_attribute,
336 NULL },
337 { "malloc", 0, 0, true, false, false, false,
338 handle_malloc_attribute, attr_alloc_exclusions },
339 { "returns_twice", 0, 0, true, false, false, false,
340 handle_returns_twice_attribute,
341 attr_returns_twice_exclusions },
342 { "no_stack_limit", 0, 0, true, false, false, false,
343 handle_no_limit_stack_attribute, NULL },
344 { "pure", 0, 0, true, false, false, false,
345 handle_pure_attribute,
346 attr_const_pure_exclusions },
347 { "transaction_callable", 0, 0, false, true, false, false,
348 handle_tm_attribute, NULL },
349 { "transaction_unsafe", 0, 0, false, true, false, true,
350 handle_tm_attribute, NULL },
351 { "transaction_safe", 0, 0, false, true, false, true,
352 handle_tm_attribute, NULL },
353 { "transaction_safe_dynamic", 0, 0, true, false, false, false,
354 handle_tm_attribute, NULL },
355 { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
356 handle_tm_attribute, NULL },
357 /* ??? These two attributes didn't make the transition from the
358 Intel language document to the multi-vendor language document. */
359 { "transaction_pure", 0, 0, false, true, false, false,
360 handle_tm_attribute, NULL },
361 { "transaction_wrap", 1, 1, true, false, false, false,
362 handle_tm_wrap_attribute, NULL },
363 /* For internal use (marking of builtins) only. The name contains space
364 to prevent its usage in source code. */
365 { "no vops", 0, 0, true, false, false, false,
366 handle_novops_attribute, NULL },
367 { "deprecated", 0, 1, false, false, false, false,
368 handle_deprecated_attribute, NULL },
369 { "vector_size", 1, 1, false, true, false, true,
370 handle_vector_size_attribute, NULL },
371 { "visibility", 1, 1, false, false, false, false,
372 handle_visibility_attribute, NULL },
373 { "tls_model", 1, 1, true, false, false, false,
374 handle_tls_model_attribute, NULL },
375 { "nonnull", 0, -1, false, true, true, false,
376 handle_nonnull_attribute, NULL },
377 { "nonstring", 0, 0, true, false, false, false,
378 handle_nonstring_attribute, NULL },
379 { "nothrow", 0, 0, true, false, false, false,
380 handle_nothrow_attribute, NULL },
381 { "may_alias", 0, 0, false, true, false, false, NULL, NULL },
382 { "cleanup", 1, 1, true, false, false, false,
383 handle_cleanup_attribute, NULL },
384 { "warn_unused_result", 0, 0, false, true, true, false,
385 handle_warn_unused_result_attribute,
386 attr_warn_unused_result_exclusions },
387 { "sentinel", 0, 1, false, true, true, false,
388 handle_sentinel_attribute, NULL },
389 /* For internal use (marking of builtins) only. The name contains space
390 to prevent its usage in source code. */
391 { "type generic", 0, 0, false, true, true, false,
392 handle_type_generic_attribute, NULL },
393 { "alloc_size", 1, 2, false, true, true, false,
394 handle_alloc_size_attribute,
395 attr_alloc_exclusions },
396 { "cold", 0, 0, true, false, false, false,
397 handle_cold_attribute,
398 attr_cold_hot_exclusions },
399 { "hot", 0, 0, true, false, false, false,
400 handle_hot_attribute,
401 attr_cold_hot_exclusions },
402 { "no_address_safety_analysis",
403 0, 0, true, false, false, false,
404 handle_no_address_safety_analysis_attribute,
405 NULL },
406 { "no_sanitize", 1, -1, true, false, false, false,
407 handle_no_sanitize_attribute, NULL },
408 { "no_sanitize_address", 0, 0, true, false, false, false,
409 handle_no_sanitize_address_attribute, NULL },
410 { "no_sanitize_thread", 0, 0, true, false, false, false,
411 handle_no_sanitize_thread_attribute, NULL },
412 { "no_sanitize_undefined", 0, 0, true, false, false, false,
413 handle_no_sanitize_undefined_attribute, NULL },
414 { "asan odr indicator", 0, 0, true, false, false, false,
415 handle_asan_odr_indicator_attribute, NULL },
416 { "warning", 1, 1, true, false, false, false,
417 handle_error_attribute, NULL },
418 { "error", 1, 1, true, false, false, false,
419 handle_error_attribute, NULL },
420 { "target", 1, -1, true, false, false, false,
421 handle_target_attribute, NULL },
422 { "target_clones", 1, -1, true, false, false, false,
423 handle_target_clones_attribute, NULL },
424 { "optimize", 1, -1, true, false, false, false,
425 handle_optimize_attribute, NULL },
426 /* For internal use only. The leading '*' both prevents its usage in
427 source code and signals that it may be overridden by machine tables. */
428 { "*tm regparm", 0, 0, false, true, true, false,
429 ignore_attribute, NULL },
430 { "no_split_stack", 0, 0, true, false, false, false,
431 handle_no_split_stack_attribute, NULL },
432 /* For internal use (marking of builtins and runtime functions) only.
433 The name contains space to prevent its usage in source code. */
434 { "fn spec", 1, 1, false, true, true, false,
435 handle_fnspec_attribute, NULL },
436 { "warn_unused", 0, 0, false, false, false, false,
437 handle_warn_unused_attribute, NULL },
438 { "returns_nonnull", 0, 0, false, true, true, false,
439 handle_returns_nonnull_attribute, NULL },
440 { "omp declare simd", 0, -1, true, false, false, false,
441 handle_omp_declare_simd_attribute, NULL },
442 { "simd", 0, 1, true, false, false, false,
443 handle_simd_attribute, NULL },
444 { "omp declare target", 0, 0, true, false, false, false,
445 handle_omp_declare_target_attribute, NULL },
446 { "omp declare target link", 0, 0, true, false, false, false,
447 handle_omp_declare_target_attribute, NULL },
448 { "alloc_align", 1, 1, false, true, true, false,
449 handle_alloc_align_attribute,
450 attr_alloc_exclusions },
451 { "assume_aligned", 1, 2, false, true, true, false,
452 handle_assume_aligned_attribute, NULL },
453 { "designated_init", 0, 0, false, true, false, false,
454 handle_designated_init_attribute, NULL },
455 { "bnd_variable_size", 0, 0, true, false, false, false,
456 handle_bnd_variable_size_attribute, NULL },
457 { "bnd_legacy", 0, 0, true, false, false, false,
458 handle_bnd_legacy, NULL },
459 { "bnd_instrument", 0, 0, true, false, false, false,
460 handle_bnd_instrument, NULL },
461 { "fallthrough", 0, 0, false, false, false, false,
462 handle_fallthrough_attribute, NULL },
463 { "patchable_function_entry", 1, 2, true, false, false, false,
464 handle_patchable_function_entry_attribute,
465 NULL },
466 { "nocf_check", 0, 0, false, true, true, true,
467 handle_nocf_check_attribute, NULL },
468 { NULL, 0, 0, false, false, false, false, NULL, NULL }
471 /* Give the specifications for the format attributes, used by C and all
472 descendants.
474 All attributes referencing arguments should be additionally processed
475 in chkp_copy_function_type_adding_bounds for correct instrumentation
476 by Pointer Bounds Checker.
477 Current list of processed format attributes: format, format_arg. */
478 const struct attribute_spec c_common_format_attribute_table[] =
480 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
481 affects_type_identity, handler, exclude } */
482 { "format", 3, 3, false, true, true, false,
483 handle_format_attribute, NULL },
484 { "format_arg", 1, 1, false, true, true, false,
485 handle_format_arg_attribute, NULL },
486 { NULL, 0, 0, false, false, false, false, NULL, NULL }
489 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
490 identifier as an argument, so the front end shouldn't look it up. */
492 bool
493 attribute_takes_identifier_p (const_tree attr_id)
495 const struct attribute_spec *spec = lookup_attribute_spec (attr_id);
496 if (spec == NULL)
497 /* Unknown attribute that we'll end up ignoring, return true so we
498 don't complain about an identifier argument. */
499 return true;
500 else if (!strcmp ("mode", spec->name)
501 || !strcmp ("format", spec->name)
502 || !strcmp ("cleanup", spec->name))
503 return true;
504 else
505 return targetm.attribute_takes_identifier_p (attr_id);
508 /* Attribute handlers common to C front ends. */
510 /* Handle a "packed" attribute; arguments as in
511 struct attribute_spec.handler. */
513 static tree
514 handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
515 int flags, bool *no_add_attrs)
517 if (TYPE_P (*node))
519 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
520 *node = build_variant_type_copy (*node);
521 TYPE_PACKED (*node) = 1;
523 else if (TREE_CODE (*node) == FIELD_DECL)
525 if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
526 /* Still pack bitfields. */
527 && ! DECL_C_BIT_FIELD (*node))
528 warning (OPT_Wattributes,
529 "%qE attribute ignored for field of type %qT",
530 name, TREE_TYPE (*node));
531 else
532 DECL_PACKED (*node) = 1;
534 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
535 used for DECL_REGISTER. It wouldn't mean anything anyway.
536 We can't set DECL_PACKED on the type of a TYPE_DECL, because
537 that changes what the typedef is typing. */
538 else
540 warning (OPT_Wattributes, "%qE attribute ignored", name);
541 *no_add_attrs = true;
544 return NULL_TREE;
547 /* Handle a "nocommon" attribute; arguments as in
548 struct attribute_spec.handler. */
550 static tree
551 handle_nocommon_attribute (tree *node, tree name,
552 tree ARG_UNUSED (args),
553 int ARG_UNUSED (flags), bool *no_add_attrs)
555 if (VAR_P (*node))
556 DECL_COMMON (*node) = 0;
557 else
559 warning (OPT_Wattributes, "%qE attribute ignored", name);
560 *no_add_attrs = true;
563 return NULL_TREE;
566 /* Handle a "common" attribute; arguments as in
567 struct attribute_spec.handler. */
569 static tree
570 handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
571 int ARG_UNUSED (flags), bool *no_add_attrs)
573 if (VAR_P (*node))
574 DECL_COMMON (*node) = 1;
575 else
577 warning (OPT_Wattributes, "%qE attribute ignored", name);
578 *no_add_attrs = true;
581 return NULL_TREE;
584 /* Handle a "noreturn" attribute; arguments as in
585 struct attribute_spec.handler. */
587 static tree
588 handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
589 int ARG_UNUSED (flags), bool *no_add_attrs)
591 tree type = TREE_TYPE (*node);
593 /* See FIXME comment in c_common_attribute_table. */
594 if (TREE_CODE (*node) == FUNCTION_DECL
595 || objc_method_decl (TREE_CODE (*node)))
596 TREE_THIS_VOLATILE (*node) = 1;
597 else if (TREE_CODE (type) == POINTER_TYPE
598 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
599 TREE_TYPE (*node)
600 = (build_qualified_type
601 (build_pointer_type
602 (build_type_variant (TREE_TYPE (type),
603 TYPE_READONLY (TREE_TYPE (type)), 1)),
604 TYPE_QUALS (type)));
605 else
607 warning (OPT_Wattributes, "%qE attribute ignored", name);
608 *no_add_attrs = true;
611 return NULL_TREE;
614 /* Handle a "hot" and attribute; arguments as in
615 struct attribute_spec.handler. */
617 static tree
618 handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
619 int ARG_UNUSED (flags), bool *no_add_attrs)
621 if (TREE_CODE (*node) == FUNCTION_DECL
622 || TREE_CODE (*node) == LABEL_DECL)
624 /* Attribute hot processing is done later with lookup_attribute. */
626 else
628 warning (OPT_Wattributes, "%qE attribute ignored", name);
629 *no_add_attrs = true;
632 return NULL_TREE;
635 /* Handle a "cold" and attribute; arguments as in
636 struct attribute_spec.handler. */
638 static tree
639 handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args),
640 int ARG_UNUSED (flags), bool *no_add_attrs)
642 if (TREE_CODE (*node) == FUNCTION_DECL
643 || TREE_CODE (*node) == LABEL_DECL)
645 /* Attribute cold processing is done later with lookup_attribute. */
647 else
649 warning (OPT_Wattributes, "%qE attribute ignored", name);
650 *no_add_attrs = true;
653 return NULL_TREE;
656 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
658 void
659 add_no_sanitize_value (tree node, unsigned int flags)
661 tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node));
662 if (attr)
664 unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr));
665 flags |= old_value;
667 if (flags == old_value)
668 return;
670 TREE_VALUE (attr) = build_int_cst (unsigned_type_node, flags);
672 else
673 DECL_ATTRIBUTES (node)
674 = tree_cons (get_identifier ("no_sanitize"),
675 build_int_cst (unsigned_type_node, flags),
676 DECL_ATTRIBUTES (node));
679 /* Handle a "no_sanitize" attribute; arguments as in
680 struct attribute_spec.handler. */
682 static tree
683 handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
684 bool *no_add_attrs)
686 unsigned int flags = 0;
687 *no_add_attrs = true;
688 if (TREE_CODE (*node) != FUNCTION_DECL)
690 warning (OPT_Wattributes, "%qE attribute ignored", name);
691 return NULL_TREE;
694 for (; args; args = TREE_CHAIN (args))
696 tree id = TREE_VALUE (args);
697 if (TREE_CODE (id) != STRING_CST)
699 error ("no_sanitize argument not a string");
700 return NULL_TREE;
703 char *string = ASTRDUP (TREE_STRING_POINTER (id));
704 flags |= parse_no_sanitize_attribute (string);
707 add_no_sanitize_value (*node, flags);
709 return NULL_TREE;
712 /* Handle a "no_sanitize_address" attribute; arguments as in
713 struct attribute_spec.handler. */
715 static tree
716 handle_no_sanitize_address_attribute (tree *node, tree name, tree, int,
717 bool *no_add_attrs)
719 *no_add_attrs = true;
720 if (TREE_CODE (*node) != FUNCTION_DECL)
721 warning (OPT_Wattributes, "%qE attribute ignored", name);
722 else
723 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
725 return NULL_TREE;
728 /* Handle a "no_sanitize_thread" attribute; arguments as in
729 struct attribute_spec.handler. */
731 static tree
732 handle_no_sanitize_thread_attribute (tree *node, tree name, tree, int,
733 bool *no_add_attrs)
735 *no_add_attrs = true;
736 if (TREE_CODE (*node) != FUNCTION_DECL)
737 warning (OPT_Wattributes, "%qE attribute ignored", name);
738 else
739 add_no_sanitize_value (*node, SANITIZE_THREAD);
741 return NULL_TREE;
745 /* Handle a "no_address_safety_analysis" attribute; arguments as in
746 struct attribute_spec.handler. */
748 static tree
749 handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int,
750 bool *no_add_attrs)
752 *no_add_attrs = true;
753 if (TREE_CODE (*node) != FUNCTION_DECL)
754 warning (OPT_Wattributes, "%qE attribute ignored", name);
755 else
756 add_no_sanitize_value (*node, SANITIZE_ADDRESS);
758 return NULL_TREE;
761 /* Handle a "no_sanitize_undefined" attribute; arguments as in
762 struct attribute_spec.handler. */
764 static tree
765 handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int,
766 bool *no_add_attrs)
768 *no_add_attrs = true;
769 if (TREE_CODE (*node) != FUNCTION_DECL)
770 warning (OPT_Wattributes, "%qE attribute ignored", name);
771 else
772 add_no_sanitize_value (*node,
773 SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
775 return NULL_TREE;
778 /* Handle an "asan odr indicator" attribute; arguments as in
779 struct attribute_spec.handler. */
781 static tree
782 handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *)
784 return NULL_TREE;
787 /* Handle a "stack_protect" attribute; arguments as in
788 struct attribute_spec.handler. */
790 static tree
791 handle_stack_protect_attribute (tree *node, tree name, tree, int,
792 bool *no_add_attrs)
794 if (TREE_CODE (*node) != FUNCTION_DECL)
796 warning (OPT_Wattributes, "%qE attribute ignored", name);
797 *no_add_attrs = true;
800 return NULL_TREE;
803 /* Handle a "noipa" attribute; arguments as in
804 struct attribute_spec.handler. */
806 static tree
807 handle_noipa_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
809 if (TREE_CODE (*node) != FUNCTION_DECL)
811 warning (OPT_Wattributes, "%qE attribute ignored", name);
812 *no_add_attrs = true;
815 return NULL_TREE;
818 /* Handle a "noinline" attribute; arguments as in
819 struct attribute_spec.handler. */
821 static tree
822 handle_noinline_attribute (tree *node, tree name,
823 tree ARG_UNUSED (args),
824 int ARG_UNUSED (flags), bool *no_add_attrs)
826 if (TREE_CODE (*node) == FUNCTION_DECL)
828 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
830 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
831 "with attribute %qs", name, "always_inline");
832 *no_add_attrs = true;
834 else
835 DECL_UNINLINABLE (*node) = 1;
837 else
839 warning (OPT_Wattributes, "%qE attribute ignored", name);
840 *no_add_attrs = true;
843 return NULL_TREE;
846 /* Handle a "noclone" attribute; arguments as in
847 struct attribute_spec.handler. */
849 static tree
850 handle_noclone_attribute (tree *node, tree name,
851 tree ARG_UNUSED (args),
852 int ARG_UNUSED (flags), bool *no_add_attrs)
854 if (TREE_CODE (*node) != FUNCTION_DECL)
856 warning (OPT_Wattributes, "%qE attribute ignored", name);
857 *no_add_attrs = true;
860 return NULL_TREE;
863 /* Handle a "nocf_check" attribute; arguments as in
864 struct attribute_spec.handler. */
866 static tree
867 handle_nocf_check_attribute (tree *node, tree name,
868 tree ARG_UNUSED (args),
869 int ARG_UNUSED (flags), bool *no_add_attrs)
871 if (TREE_CODE (*node) != FUNCTION_TYPE
872 && TREE_CODE (*node) != METHOD_TYPE)
874 warning (OPT_Wattributes, "%qE attribute ignored", name);
875 *no_add_attrs = true;
877 else if (!(flag_cf_protection & CF_BRANCH))
879 warning (OPT_Wattributes, "%qE attribute ignored. Use "
880 "-fcf-protection option to enable it", name);
881 *no_add_attrs = true;
884 return NULL_TREE;
887 /* Handle a "no_icf" attribute; arguments as in
888 struct attribute_spec.handler. */
890 static tree
891 handle_noicf_attribute (tree *node, tree name,
892 tree ARG_UNUSED (args),
893 int ARG_UNUSED (flags), bool *no_add_attrs)
895 if (TREE_CODE (*node) != FUNCTION_DECL)
897 warning (OPT_Wattributes, "%qE attribute ignored", name);
898 *no_add_attrs = true;
901 return NULL_TREE;
905 /* Handle a "always_inline" attribute; arguments as in
906 struct attribute_spec.handler. */
908 static tree
909 handle_always_inline_attribute (tree *node, tree name,
910 tree ARG_UNUSED (args),
911 int ARG_UNUSED (flags),
912 bool *no_add_attrs)
914 if (TREE_CODE (*node) == FUNCTION_DECL)
916 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node)))
918 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
919 "with %qs attribute", name, "noinline");
920 *no_add_attrs = true;
922 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
924 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
925 "with %qs attribute", name, "target_clones");
926 *no_add_attrs = true;
928 else
929 /* Set the attribute and mark it for disregarding inline
930 limits. */
931 DECL_DISREGARD_INLINE_LIMITS (*node) = 1;
933 else
935 warning (OPT_Wattributes, "%qE attribute ignored", name);
936 *no_add_attrs = true;
939 return NULL_TREE;
942 /* Handle a "gnu_inline" attribute; arguments as in
943 struct attribute_spec.handler. */
945 static tree
946 handle_gnu_inline_attribute (tree *node, tree name,
947 tree ARG_UNUSED (args),
948 int ARG_UNUSED (flags),
949 bool *no_add_attrs)
951 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
953 /* Do nothing else, just set the attribute. We'll get at
954 it later with lookup_attribute. */
956 else
958 warning (OPT_Wattributes, "%qE attribute ignored", name);
959 *no_add_attrs = true;
962 return NULL_TREE;
965 /* Handle a "leaf" attribute; arguments as in
966 struct attribute_spec.handler. */
968 static tree
969 handle_leaf_attribute (tree *node, tree name,
970 tree ARG_UNUSED (args),
971 int ARG_UNUSED (flags), bool *no_add_attrs)
973 if (TREE_CODE (*node) != FUNCTION_DECL)
975 warning (OPT_Wattributes, "%qE attribute ignored", name);
976 *no_add_attrs = true;
978 if (!TREE_PUBLIC (*node))
980 warning (OPT_Wattributes, "%qE attribute has no effect on unit local "
981 "functions", name);
982 *no_add_attrs = true;
985 return NULL_TREE;
988 /* Handle an "artificial" attribute; arguments as in
989 struct attribute_spec.handler. */
991 static tree
992 handle_artificial_attribute (tree *node, tree name,
993 tree ARG_UNUSED (args),
994 int ARG_UNUSED (flags),
995 bool *no_add_attrs)
997 if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
999 /* Do nothing else, just set the attribute. We'll get at
1000 it later with lookup_attribute. */
1002 else
1004 warning (OPT_Wattributes, "%qE attribute ignored", name);
1005 *no_add_attrs = true;
1008 return NULL_TREE;
1011 /* Handle a "flatten" attribute; arguments as in
1012 struct attribute_spec.handler. */
1014 static tree
1015 handle_flatten_attribute (tree *node, tree name,
1016 tree args ATTRIBUTE_UNUSED,
1017 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
1019 if (TREE_CODE (*node) == FUNCTION_DECL)
1020 /* Do nothing else, just set the attribute. We'll get at
1021 it later with lookup_attribute. */
1023 else
1025 warning (OPT_Wattributes, "%qE attribute ignored", name);
1026 *no_add_attrs = true;
1029 return NULL_TREE;
1032 /* Handle a "warning" or "error" attribute; arguments as in
1033 struct attribute_spec.handler. */
1035 static tree
1036 handle_error_attribute (tree *node, tree name, tree args,
1037 int ARG_UNUSED (flags), bool *no_add_attrs)
1039 if (TREE_CODE (*node) == FUNCTION_DECL
1040 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
1041 /* Do nothing else, just set the attribute. We'll get at
1042 it later with lookup_attribute. */
1044 else
1046 warning (OPT_Wattributes, "%qE attribute ignored", name);
1047 *no_add_attrs = true;
1050 return NULL_TREE;
1053 /* Handle a "used" attribute; arguments as in
1054 struct attribute_spec.handler. */
1056 static tree
1057 handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
1058 int ARG_UNUSED (flags), bool *no_add_attrs)
1060 tree node = *pnode;
1062 if (TREE_CODE (node) == FUNCTION_DECL
1063 || (VAR_P (node) && TREE_STATIC (node))
1064 || (TREE_CODE (node) == TYPE_DECL))
1066 TREE_USED (node) = 1;
1067 DECL_PRESERVE_P (node) = 1;
1068 if (VAR_P (node))
1069 DECL_READ_P (node) = 1;
1071 else
1073 warning (OPT_Wattributes, "%qE attribute ignored", name);
1074 *no_add_attrs = true;
1077 return NULL_TREE;
1080 /* Handle a "unused" attribute; arguments as in
1081 struct attribute_spec.handler. */
1083 tree
1084 handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1085 int flags, bool *no_add_attrs)
1087 if (DECL_P (*node))
1089 tree decl = *node;
1091 if (TREE_CODE (decl) == PARM_DECL
1092 || VAR_OR_FUNCTION_DECL_P (decl)
1093 || TREE_CODE (decl) == LABEL_DECL
1094 || TREE_CODE (decl) == CONST_DECL
1095 || TREE_CODE (decl) == TYPE_DECL)
1097 TREE_USED (decl) = 1;
1098 if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
1099 DECL_READ_P (decl) = 1;
1101 else
1103 warning (OPT_Wattributes, "%qE attribute ignored", name);
1104 *no_add_attrs = true;
1107 else
1109 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1110 *node = build_variant_type_copy (*node);
1111 TREE_USED (*node) = 1;
1114 return NULL_TREE;
1117 /* Handle a "externally_visible" attribute; arguments as in
1118 struct attribute_spec.handler. */
1120 static tree
1121 handle_externally_visible_attribute (tree *pnode, tree name,
1122 tree ARG_UNUSED (args),
1123 int ARG_UNUSED (flags),
1124 bool *no_add_attrs)
1126 tree node = *pnode;
1128 if (VAR_OR_FUNCTION_DECL_P (node))
1130 if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
1131 && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
1133 warning (OPT_Wattributes,
1134 "%qE attribute have effect only on public objects", name);
1135 *no_add_attrs = true;
1138 else
1140 warning (OPT_Wattributes, "%qE attribute ignored", name);
1141 *no_add_attrs = true;
1144 return NULL_TREE;
1147 /* Handle the "no_reorder" attribute. Arguments as in
1148 struct attribute_spec.handler. */
1150 static tree
1151 handle_no_reorder_attribute (tree *pnode,
1152 tree name,
1153 tree,
1154 int,
1155 bool *no_add_attrs)
1157 tree node = *pnode;
1159 if (!VAR_OR_FUNCTION_DECL_P (node)
1160 && !(TREE_STATIC (node) || DECL_EXTERNAL (node)))
1162 warning (OPT_Wattributes,
1163 "%qE attribute only affects top level objects",
1164 name);
1165 *no_add_attrs = true;
1168 return NULL_TREE;
1171 /* Handle a "const" attribute; arguments as in
1172 struct attribute_spec.handler. */
1174 static tree
1175 handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
1176 int flags, bool *no_add_attrs)
1178 tree type = TREE_TYPE (*node);
1180 /* See FIXME comment on noreturn in c_common_attribute_table. */
1181 if (TREE_CODE (*node) == FUNCTION_DECL)
1182 TREE_READONLY (*node) = 1;
1183 else if (TREE_CODE (type) == POINTER_TYPE
1184 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1185 TREE_TYPE (*node)
1186 = (build_qualified_type
1187 (build_pointer_type
1188 (build_type_variant (TREE_TYPE (type), 1,
1189 TREE_THIS_VOLATILE (TREE_TYPE (type)))),
1190 TYPE_QUALS (type)));
1191 else
1193 warning (OPT_Wattributes, "%qE attribute ignored", name);
1194 *no_add_attrs = true;
1197 /* void __builtin_unreachable(void) is const. Accept other such
1198 built-ins but warn on user-defined functions that return void. */
1199 if (!(flags & ATTR_FLAG_BUILT_IN)
1200 && TREE_CODE (*node) == FUNCTION_DECL
1201 && VOID_TYPE_P (TREE_TYPE (type)))
1202 warning (OPT_Wattributes, "%qE attribute on function "
1203 "returning %<void%>", name);
1205 return NULL_TREE;
1208 /* Handle a "scalar_storage_order" attribute; arguments as in
1209 struct attribute_spec.handler. */
1211 static tree
1212 handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
1213 int flags, bool *no_add_attrs)
1215 tree id = TREE_VALUE (args);
1216 tree type;
1218 if (TREE_CODE (*node) == TYPE_DECL
1219 && ! (flags & ATTR_FLAG_CXX11))
1220 node = &TREE_TYPE (*node);
1221 type = *node;
1223 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
1225 error ("scalar_storage_order is not supported because endianness "
1226 "is not uniform");
1227 return NULL_TREE;
1230 if (RECORD_OR_UNION_TYPE_P (type) && !c_dialect_cxx ())
1232 bool reverse = false;
1234 if (TREE_CODE (id) == STRING_CST
1235 && strcmp (TREE_STRING_POINTER (id), "big-endian") == 0)
1236 reverse = !BYTES_BIG_ENDIAN;
1237 else if (TREE_CODE (id) == STRING_CST
1238 && strcmp (TREE_STRING_POINTER (id), "little-endian") == 0)
1239 reverse = BYTES_BIG_ENDIAN;
1240 else
1242 error ("scalar_storage_order argument must be one of \"big-endian\""
1243 " or \"little-endian\"");
1244 return NULL_TREE;
1247 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1249 if (reverse)
1250 /* A type variant isn't good enough, since we don't want a cast
1251 to such a type to be removed as a no-op. */
1252 *node = type = build_duplicate_type (type);
1255 TYPE_REVERSE_STORAGE_ORDER (type) = reverse;
1256 return NULL_TREE;
1259 warning (OPT_Wattributes, "%qE attribute ignored", name);
1260 *no_add_attrs = true;
1261 return NULL_TREE;
1264 /* Handle a "transparent_union" attribute; arguments as in
1265 struct attribute_spec.handler. */
1267 static tree
1268 handle_transparent_union_attribute (tree *node, tree name,
1269 tree ARG_UNUSED (args), int flags,
1270 bool *no_add_attrs)
1272 tree type;
1274 *no_add_attrs = true;
1276 if (TREE_CODE (*node) == TYPE_DECL
1277 && ! (flags & ATTR_FLAG_CXX11))
1278 node = &TREE_TYPE (*node);
1279 type = *node;
1281 if (TREE_CODE (type) == UNION_TYPE)
1283 /* Make sure that the first field will work for a transparent union.
1284 If the type isn't complete yet, leave the check to the code in
1285 finish_struct. */
1286 if (TYPE_SIZE (type))
1288 tree first = first_field (type);
1289 if (first == NULL_TREE
1290 || DECL_ARTIFICIAL (first)
1291 || TYPE_MODE (type) != DECL_MODE (first))
1292 goto ignored;
1295 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1297 /* If the type isn't complete yet, setting the flag
1298 on a variant wouldn't ever be checked. */
1299 if (!TYPE_SIZE (type))
1300 goto ignored;
1302 /* build_duplicate_type doesn't work for C++. */
1303 if (c_dialect_cxx ())
1304 goto ignored;
1306 /* A type variant isn't good enough, since we don't want a cast
1307 to such a type to be removed as a no-op. */
1308 *node = type = build_duplicate_type (type);
1311 for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
1312 TYPE_TRANSPARENT_AGGR (t) = 1;
1313 return NULL_TREE;
1316 ignored:
1317 warning (OPT_Wattributes, "%qE attribute ignored", name);
1318 return NULL_TREE;
1321 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1322 get the requested priority for a constructor or destructor,
1323 possibly issuing diagnostics for invalid or reserved
1324 priorities. */
1326 static priority_type
1327 get_priority (tree args, bool is_destructor)
1329 HOST_WIDE_INT pri;
1330 tree arg;
1332 if (!args)
1333 return DEFAULT_INIT_PRIORITY;
1335 if (!SUPPORTS_INIT_PRIORITY)
1337 if (is_destructor)
1338 error ("destructor priorities are not supported");
1339 else
1340 error ("constructor priorities are not supported");
1341 return DEFAULT_INIT_PRIORITY;
1344 arg = TREE_VALUE (args);
1345 if (TREE_CODE (arg) == IDENTIFIER_NODE)
1346 goto invalid;
1347 if (arg == error_mark_node)
1348 return DEFAULT_INIT_PRIORITY;
1349 arg = default_conversion (arg);
1350 if (!tree_fits_shwi_p (arg)
1351 || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
1352 goto invalid;
1354 pri = tree_to_shwi (arg);
1355 if (pri < 0 || pri > MAX_INIT_PRIORITY)
1356 goto invalid;
1358 if (pri <= MAX_RESERVED_INIT_PRIORITY)
1360 if (is_destructor)
1361 warning (0,
1362 "destructor priorities from 0 to %d are reserved "
1363 "for the implementation",
1364 MAX_RESERVED_INIT_PRIORITY);
1365 else
1366 warning (0,
1367 "constructor priorities from 0 to %d are reserved "
1368 "for the implementation",
1369 MAX_RESERVED_INIT_PRIORITY);
1371 return pri;
1373 invalid:
1374 if (is_destructor)
1375 error ("destructor priorities must be integers from 0 to %d inclusive",
1376 MAX_INIT_PRIORITY);
1377 else
1378 error ("constructor priorities must be integers from 0 to %d inclusive",
1379 MAX_INIT_PRIORITY);
1380 return DEFAULT_INIT_PRIORITY;
1383 /* Handle a "constructor" attribute; arguments as in
1384 struct attribute_spec.handler. */
1386 static tree
1387 handle_constructor_attribute (tree *node, tree name, tree args,
1388 int ARG_UNUSED (flags),
1389 bool *no_add_attrs)
1391 tree decl = *node;
1392 tree type = TREE_TYPE (decl);
1394 if (TREE_CODE (decl) == FUNCTION_DECL
1395 && TREE_CODE (type) == FUNCTION_TYPE
1396 && decl_function_context (decl) == 0)
1398 priority_type priority;
1399 DECL_STATIC_CONSTRUCTOR (decl) = 1;
1400 priority = get_priority (args, /*is_destructor=*/false);
1401 SET_DECL_INIT_PRIORITY (decl, priority);
1402 TREE_USED (decl) = 1;
1404 else
1406 warning (OPT_Wattributes, "%qE attribute ignored", name);
1407 *no_add_attrs = true;
1410 return NULL_TREE;
1413 /* Handle a "destructor" attribute; arguments as in
1414 struct attribute_spec.handler. */
1416 static tree
1417 handle_destructor_attribute (tree *node, tree name, tree args,
1418 int ARG_UNUSED (flags),
1419 bool *no_add_attrs)
1421 tree decl = *node;
1422 tree type = TREE_TYPE (decl);
1424 if (TREE_CODE (decl) == FUNCTION_DECL
1425 && TREE_CODE (type) == FUNCTION_TYPE
1426 && decl_function_context (decl) == 0)
1428 priority_type priority;
1429 DECL_STATIC_DESTRUCTOR (decl) = 1;
1430 priority = get_priority (args, /*is_destructor=*/true);
1431 SET_DECL_FINI_PRIORITY (decl, priority);
1432 TREE_USED (decl) = 1;
1434 else
1436 warning (OPT_Wattributes, "%qE attribute ignored", name);
1437 *no_add_attrs = true;
1440 return NULL_TREE;
1443 /* Nonzero if the mode is a valid vector mode for this architecture.
1444 This returns nonzero even if there is no hardware support for the
1445 vector mode, but we can emulate with narrower modes. */
1447 static bool
1448 vector_mode_valid_p (machine_mode mode)
1450 enum mode_class mclass = GET_MODE_CLASS (mode);
1452 /* Doh! What's going on? */
1453 if (mclass != MODE_VECTOR_INT
1454 && mclass != MODE_VECTOR_FLOAT
1455 && mclass != MODE_VECTOR_FRACT
1456 && mclass != MODE_VECTOR_UFRACT
1457 && mclass != MODE_VECTOR_ACCUM
1458 && mclass != MODE_VECTOR_UACCUM)
1459 return false;
1461 /* Hardware support. Woo hoo! */
1462 if (targetm.vector_mode_supported_p (mode))
1463 return true;
1465 /* We should probably return 1 if requesting V4DI and we have no DI,
1466 but we have V2DI, but this is probably very unlikely. */
1468 /* If we have support for the inner mode, we can safely emulate it.
1469 We may not have V2DI, but me can emulate with a pair of DIs. */
1470 return targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1474 /* Handle a "mode" attribute; arguments as in
1475 struct attribute_spec.handler. */
1477 static tree
1478 handle_mode_attribute (tree *node, tree name, tree args,
1479 int ARG_UNUSED (flags), bool *no_add_attrs)
1481 tree type = *node;
1482 tree ident = TREE_VALUE (args);
1484 *no_add_attrs = true;
1486 if (TREE_CODE (ident) != IDENTIFIER_NODE)
1487 warning (OPT_Wattributes, "%qE attribute ignored", name);
1488 else
1490 int j;
1491 const char *p = IDENTIFIER_POINTER (ident);
1492 int len = strlen (p);
1493 machine_mode mode = VOIDmode;
1494 tree typefm;
1495 bool valid_mode;
1497 if (len > 4 && p[0] == '_' && p[1] == '_'
1498 && p[len - 1] == '_' && p[len - 2] == '_')
1500 char *newp = (char *) alloca (len - 1);
1502 strcpy (newp, &p[2]);
1503 newp[len - 4] = '\0';
1504 p = newp;
1507 /* Change this type to have a type with the specified mode.
1508 First check for the special modes. */
1509 if (!strcmp (p, "byte"))
1510 mode = byte_mode;
1511 else if (!strcmp (p, "word"))
1512 mode = word_mode;
1513 else if (!strcmp (p, "pointer"))
1514 mode = ptr_mode;
1515 else if (!strcmp (p, "libgcc_cmp_return"))
1516 mode = targetm.libgcc_cmp_return_mode ();
1517 else if (!strcmp (p, "libgcc_shift_count"))
1518 mode = targetm.libgcc_shift_count_mode ();
1519 else if (!strcmp (p, "unwind_word"))
1520 mode = targetm.unwind_word_mode ();
1521 else
1522 for (j = 0; j < NUM_MACHINE_MODES; j++)
1523 if (!strcmp (p, GET_MODE_NAME (j)))
1525 mode = (machine_mode) j;
1526 break;
1529 if (mode == VOIDmode)
1531 error ("unknown machine mode %qE", ident);
1532 return NULL_TREE;
1535 valid_mode = false;
1536 switch (GET_MODE_CLASS (mode))
1538 case MODE_INT:
1539 case MODE_PARTIAL_INT:
1540 case MODE_FLOAT:
1541 case MODE_DECIMAL_FLOAT:
1542 case MODE_FRACT:
1543 case MODE_UFRACT:
1544 case MODE_ACCUM:
1545 case MODE_UACCUM:
1546 valid_mode
1547 = targetm.scalar_mode_supported_p (as_a <scalar_mode> (mode));
1548 break;
1550 case MODE_COMPLEX_INT:
1551 case MODE_COMPLEX_FLOAT:
1552 valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
1553 break;
1555 case MODE_VECTOR_INT:
1556 case MODE_VECTOR_FLOAT:
1557 case MODE_VECTOR_FRACT:
1558 case MODE_VECTOR_UFRACT:
1559 case MODE_VECTOR_ACCUM:
1560 case MODE_VECTOR_UACCUM:
1561 warning (OPT_Wattributes, "specifying vector types with "
1562 "__attribute__ ((mode)) is deprecated");
1563 warning (OPT_Wattributes,
1564 "use __attribute__ ((vector_size)) instead");
1565 valid_mode = vector_mode_valid_p (mode);
1566 break;
1568 default:
1569 break;
1571 if (!valid_mode)
1573 error ("unable to emulate %qs", p);
1574 return NULL_TREE;
1577 if (POINTER_TYPE_P (type))
1579 scalar_int_mode addr_mode;
1580 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
1581 tree (*fn)(tree, machine_mode, bool);
1583 if (!is_a <scalar_int_mode> (mode, &addr_mode)
1584 || !targetm.addr_space.valid_pointer_mode (addr_mode, as))
1586 error ("invalid pointer mode %qs", p);
1587 return NULL_TREE;
1590 if (TREE_CODE (type) == POINTER_TYPE)
1591 fn = build_pointer_type_for_mode;
1592 else
1593 fn = build_reference_type_for_mode;
1594 typefm = fn (TREE_TYPE (type), addr_mode, false);
1596 else
1598 /* For fixed-point modes, we need to test if the signness of type
1599 and the machine mode are consistent. */
1600 if (ALL_FIXED_POINT_MODE_P (mode)
1601 && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
1603 error ("signedness of type and machine mode %qs don%'t match", p);
1604 return NULL_TREE;
1606 /* For fixed-point modes, we need to pass saturating info. */
1607 typefm = lang_hooks.types.type_for_mode (mode,
1608 ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
1609 : TYPE_UNSIGNED (type));
1612 if (typefm == NULL_TREE)
1614 error ("no data type for mode %qs", p);
1615 return NULL_TREE;
1617 else if (TREE_CODE (type) == ENUMERAL_TYPE)
1619 /* For enumeral types, copy the precision from the integer
1620 type returned above. If not an INTEGER_TYPE, we can't use
1621 this mode for this type. */
1622 if (TREE_CODE (typefm) != INTEGER_TYPE)
1624 error ("cannot use mode %qs for enumeral types", p);
1625 return NULL_TREE;
1628 if (flags & ATTR_FLAG_TYPE_IN_PLACE)
1630 TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
1631 typefm = type;
1633 else
1635 /* We cannot build a type variant, as there's code that assumes
1636 that TYPE_MAIN_VARIANT has the same mode. This includes the
1637 debug generators. Instead, create a subrange type. This
1638 results in all of the enumeral values being emitted only once
1639 in the original, and the subtype gets them by reference. */
1640 if (TYPE_UNSIGNED (type))
1641 typefm = make_unsigned_type (TYPE_PRECISION (typefm));
1642 else
1643 typefm = make_signed_type (TYPE_PRECISION (typefm));
1644 TREE_TYPE (typefm) = type;
1647 else if (VECTOR_MODE_P (mode)
1648 ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
1649 : TREE_CODE (type) != TREE_CODE (typefm))
1651 error ("mode %qs applied to inappropriate type", p);
1652 return NULL_TREE;
1655 *node = build_qualified_type (typefm, TYPE_QUALS (type));
1658 return NULL_TREE;
1661 /* Handle a "section" attribute; arguments as in
1662 struct attribute_spec.handler. */
1664 static tree
1665 handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
1666 int ARG_UNUSED (flags), bool *no_add_attrs)
1668 tree decl = *node;
1670 if (!targetm_common.have_named_sections)
1672 error_at (DECL_SOURCE_LOCATION (*node),
1673 "section attributes are not supported for this target");
1674 goto fail;
1677 if (!VAR_OR_FUNCTION_DECL_P (decl))
1679 error ("section attribute not allowed for %q+D", *node);
1680 goto fail;
1683 if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
1685 error ("section attribute argument not a string constant");
1686 goto fail;
1689 if (VAR_P (decl)
1690 && current_function_decl != NULL_TREE
1691 && !TREE_STATIC (decl))
1693 error_at (DECL_SOURCE_LOCATION (decl),
1694 "section attribute cannot be specified for local variables");
1695 goto fail;
1698 /* The decl may have already been given a section attribute
1699 from a previous declaration. Ensure they match. */
1700 if (DECL_SECTION_NAME (decl) != NULL
1701 && strcmp (DECL_SECTION_NAME (decl),
1702 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
1704 error ("section of %q+D conflicts with previous declaration", *node);
1705 goto fail;
1708 if (VAR_P (decl)
1709 && !targetm.have_tls && targetm.emutls.tmpl_section
1710 && DECL_THREAD_LOCAL_P (decl))
1712 error ("section of %q+D cannot be overridden", *node);
1713 goto fail;
1716 set_decl_section_name (decl, TREE_STRING_POINTER (TREE_VALUE (args)));
1717 return NULL_TREE;
1719 fail:
1720 *no_add_attrs = true;
1721 return NULL_TREE;
1724 /* If in c++-11, check if the c++-11 alignment constraint with respect
1725 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1726 c++-11 mode, does nothing.
1728 [dcl.align]2/ says:
1730 [* if the constant expression evaluates to a fundamental alignment,
1731 the alignment requirement of the declared entity shall be the
1732 specified fundamental alignment.
1734 * if the constant expression evaluates to an extended alignment
1735 and the implementation supports that alignment in the context
1736 of the declaration, the alignment of the declared entity shall
1737 be that alignment
1739 * if the constant expression evaluates to an extended alignment
1740 and the implementation does not support that alignment in the
1741 context of the declaration, the program is ill-formed]. */
1743 static bool
1744 check_cxx_fundamental_alignment_constraints (tree node,
1745 unsigned align_log,
1746 int flags)
1748 bool alignment_too_large_p = false;
1749 unsigned requested_alignment = (1U << align_log) * BITS_PER_UNIT;
1750 unsigned max_align = 0;
1752 if ((!(flags & ATTR_FLAG_CXX11) && !warn_cxx_compat)
1753 || (node == NULL_TREE || node == error_mark_node))
1754 return true;
1756 if (cxx_fundamental_alignment_p (requested_alignment))
1757 return true;
1759 if (VAR_P (node))
1761 if (TREE_STATIC (node) || DECL_EXTERNAL (node))
1762 /* For file scope variables and static members, the target supports
1763 alignments that are at most MAX_OFILE_ALIGNMENT. */
1764 max_align = MAX_OFILE_ALIGNMENT;
1765 else
1766 /* For stack variables, the target supports at most
1767 MAX_STACK_ALIGNMENT. */
1768 max_align = MAX_STACK_ALIGNMENT;
1769 if (requested_alignment > max_align)
1770 alignment_too_large_p = true;
1772 /* Let's be liberal for types and fields; don't limit their alignment any
1773 more than check_user_alignment already did. */
1775 if (alignment_too_large_p)
1776 pedwarn (input_location, OPT_Wattributes,
1777 "requested alignment %d is larger than %d",
1778 requested_alignment / BITS_PER_UNIT, max_align / BITS_PER_UNIT);
1780 return !alignment_too_large_p;
1783 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1784 handle_aligned_attribute. */
1786 static tree
1787 common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
1788 bool *no_add_attrs,
1789 bool warn_if_not_aligned_p)
1791 tree decl = NULL_TREE;
1792 tree *type = NULL;
1793 bool is_type = false;
1794 tree align_expr;
1796 /* The last (already pushed) declaration with all validated attributes
1797 merged in or the current about-to-be-pushed one if one hasn't been
1798 yet. */
1799 tree last_decl = node[1] ? node[1] : *node;
1801 if (args)
1803 align_expr = TREE_VALUE (args);
1804 if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE
1805 && TREE_CODE (align_expr) != FUNCTION_DECL)
1806 align_expr = default_conversion (align_expr);
1808 else
1809 align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT);
1811 if (DECL_P (*node))
1813 decl = *node;
1814 type = &TREE_TYPE (decl);
1815 is_type = TREE_CODE (*node) == TYPE_DECL;
1817 else if (TYPE_P (*node))
1818 type = node, is_type = true;
1820 /* Log2 of specified alignment. */
1821 int pow2align = check_user_alignment (align_expr, true);
1822 if (pow2align == -1
1823 || !check_cxx_fundamental_alignment_constraints (*node, pow2align, flags))
1825 *no_add_attrs = true;
1826 return NULL_TREE;
1829 /* The alignment in bits corresponding to the specified alignment. */
1830 unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
1832 /* The alignment of the current declaration and that of the last
1833 pushed declaration, determined on demand below. */
1834 unsigned curalign = 0;
1835 unsigned lastalign = 0;
1837 if (is_type)
1839 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
1840 /* OK, modify the type in place. */;
1841 /* If we have a TYPE_DECL, then copy the type, so that we
1842 don't accidentally modify a builtin type. See pushdecl. */
1843 else if (decl && TREE_TYPE (decl) != error_mark_node
1844 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
1846 tree tt = TREE_TYPE (decl);
1847 *type = build_variant_type_copy (*type);
1848 DECL_ORIGINAL_TYPE (decl) = tt;
1849 TYPE_NAME (*type) = decl;
1850 TREE_USED (*type) = TREE_USED (decl);
1851 TREE_TYPE (decl) = *type;
1853 else
1854 *type = build_variant_type_copy (*type);
1856 if (warn_if_not_aligned_p)
1858 SET_TYPE_WARN_IF_NOT_ALIGN (*type, bitalign);
1859 warn_if_not_aligned_p = false;
1861 else
1863 SET_TYPE_ALIGN (*type, bitalign);
1864 TYPE_USER_ALIGN (*type) = 1;
1867 else if (! VAR_OR_FUNCTION_DECL_P (decl)
1868 && TREE_CODE (decl) != FIELD_DECL)
1870 error ("alignment may not be specified for %q+D", decl);
1871 *no_add_attrs = true;
1873 else if (TREE_CODE (decl) == FUNCTION_DECL
1874 && ((curalign = DECL_ALIGN (decl)) > bitalign
1875 || ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
1877 /* Either a prior attribute on the same declaration or one
1878 on a prior declaration of the same function specifies
1879 stricter alignment than this attribute. */
1880 bool note = lastalign != 0;
1881 if (lastalign)
1882 curalign = lastalign;
1884 curalign /= BITS_PER_UNIT;
1885 bitalign /= BITS_PER_UNIT;
1887 bool diagd = true;
1888 if (DECL_USER_ALIGN (decl) || DECL_USER_ALIGN (last_decl))
1889 diagd = warning (OPT_Wattributes,
1890 "ignoring attribute %<%E (%u)%> because it conflicts "
1891 "with attribute %<%E (%u)%>",
1892 name, bitalign, name, curalign);
1893 else if (!warn_if_not_aligned_p)
1894 /* Do not error out for attribute warn_if_not_aligned. */
1895 error ("alignment for %q+D must be at least %d", decl, curalign);
1897 if (diagd && note)
1898 inform (DECL_SOURCE_LOCATION (last_decl), "previous declaration here");
1900 *no_add_attrs = true;
1902 else if (DECL_USER_ALIGN (decl)
1903 && DECL_ALIGN (decl) > bitalign)
1904 /* C++-11 [dcl.align/4]:
1906 When multiple alignment-specifiers are specified for an
1907 entity, the alignment requirement shall be set to the
1908 strictest specified alignment.
1910 This formally comes from the c++11 specification but we are
1911 doing it for the GNU attribute syntax as well. */
1912 *no_add_attrs = true;
1913 else if (!warn_if_not_aligned_p
1914 && TREE_CODE (decl) == FUNCTION_DECL
1915 && DECL_ALIGN (decl) > bitalign)
1917 /* Don't warn function alignment here if warn_if_not_aligned_p is
1918 true. It will be warned later. */
1919 if (DECL_USER_ALIGN (decl))
1920 error ("alignment for %q+D was previously specified as %d "
1921 "and may not be decreased", decl,
1922 DECL_ALIGN (decl) / BITS_PER_UNIT);
1923 else
1924 error ("alignment for %q+D must be at least %d", decl,
1925 DECL_ALIGN (decl) / BITS_PER_UNIT);
1926 *no_add_attrs = true;
1928 else
1930 if (warn_if_not_aligned_p)
1932 if (TREE_CODE (decl) == FIELD_DECL && !DECL_C_BIT_FIELD (decl))
1934 SET_DECL_WARN_IF_NOT_ALIGN (decl, bitalign);
1935 warn_if_not_aligned_p = false;
1938 else
1940 SET_DECL_ALIGN (decl, bitalign);
1941 DECL_USER_ALIGN (decl) = 1;
1945 if (warn_if_not_aligned_p)
1947 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1948 decl);
1949 *no_add_attrs = true;
1952 return NULL_TREE;
1955 /* Handle a "aligned" attribute; arguments as in
1956 struct attribute_spec.handler. */
1958 static tree
1959 handle_aligned_attribute (tree *node, tree name, tree args,
1960 int flags, bool *no_add_attrs)
1962 return common_handle_aligned_attribute (node, name, args, flags,
1963 no_add_attrs, false);
1966 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1967 struct attribute_spec.handler. */
1969 static tree
1970 handle_warn_if_not_aligned_attribute (tree *node, tree name,
1971 tree args, int flags,
1972 bool *no_add_attrs)
1974 return common_handle_aligned_attribute (node, name, args, flags,
1975 no_add_attrs, true);
1978 /* Handle a "weak" attribute; arguments as in
1979 struct attribute_spec.handler. */
1981 static tree
1982 handle_weak_attribute (tree *node, tree name,
1983 tree ARG_UNUSED (args),
1984 int ARG_UNUSED (flags),
1985 bool * ARG_UNUSED (no_add_attrs))
1987 if (TREE_CODE (*node) == FUNCTION_DECL
1988 && DECL_DECLARED_INLINE_P (*node))
1990 warning (OPT_Wattributes, "inline function %q+D declared weak", *node);
1991 *no_add_attrs = true;
1993 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
1995 error ("indirect function %q+D cannot be declared weak", *node);
1996 *no_add_attrs = true;
1997 return NULL_TREE;
1999 else if (VAR_OR_FUNCTION_DECL_P (*node))
2000 declare_weak (*node);
2001 else
2002 warning (OPT_Wattributes, "%qE attribute ignored", name);
2004 return NULL_TREE;
2007 /* Handle a "noplt" attribute; arguments as in
2008 struct attribute_spec.handler. */
2010 static tree
2011 handle_noplt_attribute (tree *node, tree name,
2012 tree ARG_UNUSED (args),
2013 int ARG_UNUSED (flags),
2014 bool * ARG_UNUSED (no_add_attrs))
2016 if (TREE_CODE (*node) != FUNCTION_DECL)
2018 warning (OPT_Wattributes,
2019 "%qE attribute is only applicable on functions", name);
2020 *no_add_attrs = true;
2021 return NULL_TREE;
2023 return NULL_TREE;
2026 /* Handle an "alias" or "ifunc" attribute; arguments as in
2027 struct attribute_spec.handler, except that IS_ALIAS tells us
2028 whether this is an alias as opposed to ifunc attribute. */
2030 static tree
2031 handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args,
2032 bool *no_add_attrs)
2034 tree decl = *node;
2036 if (TREE_CODE (decl) != FUNCTION_DECL
2037 && (!is_alias || !VAR_P (decl)))
2039 warning (OPT_Wattributes, "%qE attribute ignored", name);
2040 *no_add_attrs = true;
2042 else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
2043 || (TREE_CODE (decl) != FUNCTION_DECL
2044 && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
2045 /* A static variable declaration is always a tentative definition,
2046 but the alias is a non-tentative definition which overrides. */
2047 || (TREE_CODE (decl) != FUNCTION_DECL
2048 && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl)))
2050 error ("%q+D defined both normally and as %qE attribute", decl, name);
2051 *no_add_attrs = true;
2052 return NULL_TREE;
2054 else if (!is_alias
2055 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2056 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))))
2058 error ("weak %q+D cannot be defined %qE", decl, name);
2059 *no_add_attrs = true;
2060 return NULL_TREE;
2063 /* Note that the very first time we process a nested declaration,
2064 decl_function_context will not be set. Indeed, *would* never
2065 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2066 we do below. After such frobbery, pushdecl would set the context.
2067 In any case, this is never what we want. */
2068 else if (decl_function_context (decl) == 0 && current_function_decl == NULL)
2070 tree id;
2072 id = TREE_VALUE (args);
2073 if (TREE_CODE (id) != STRING_CST)
2075 error ("attribute %qE argument not a string", name);
2076 *no_add_attrs = true;
2077 return NULL_TREE;
2079 id = get_identifier (TREE_STRING_POINTER (id));
2080 /* This counts as a use of the object pointed to. */
2081 TREE_USED (id) = 1;
2083 if (TREE_CODE (decl) == FUNCTION_DECL)
2084 DECL_INITIAL (decl) = error_mark_node;
2085 else
2086 TREE_STATIC (decl) = 1;
2088 if (!is_alias)
2090 /* ifuncs are also aliases, so set that attribute too. */
2091 DECL_ATTRIBUTES (decl)
2092 = tree_cons (get_identifier ("alias"), args,
2093 DECL_ATTRIBUTES (decl));
2094 DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("ifunc"),
2095 NULL, DECL_ATTRIBUTES (decl));
2098 else
2100 warning (OPT_Wattributes, "%qE attribute ignored", name);
2101 *no_add_attrs = true;
2104 if (decl_in_symtab_p (*node))
2106 struct symtab_node *n = symtab_node::get (decl);
2107 if (n && n->refuse_visibility_changes)
2109 if (is_alias)
2110 error ("%+qD declared alias after being used", decl);
2111 else
2112 error ("%+qD declared ifunc after being used", decl);
2117 return NULL_TREE;
2120 /* Handle an "alias" or "ifunc" attribute; arguments as in
2121 struct attribute_spec.handler. */
2123 static tree
2124 handle_ifunc_attribute (tree *node, tree name, tree args,
2125 int ARG_UNUSED (flags), bool *no_add_attrs)
2127 return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs);
2130 /* Handle an "alias" or "ifunc" attribute; arguments as in
2131 struct attribute_spec.handler. */
2133 static tree
2134 handle_alias_attribute (tree *node, tree name, tree args,
2135 int ARG_UNUSED (flags), bool *no_add_attrs)
2137 return handle_alias_ifunc_attribute (true, node, name, args, no_add_attrs);
2140 /* Handle a "weakref" attribute; arguments as in struct
2141 attribute_spec.handler. */
2143 static tree
2144 handle_weakref_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2145 int flags, bool *no_add_attrs)
2147 tree attr = NULL_TREE;
2149 /* We must ignore the attribute when it is associated with
2150 local-scoped decls, since attribute alias is ignored and many
2151 such symbols do not even have a DECL_WEAK field. */
2152 if (decl_function_context (*node)
2153 || current_function_decl
2154 || !VAR_OR_FUNCTION_DECL_P (*node))
2156 warning (OPT_Wattributes, "%qE attribute ignored", name);
2157 *no_add_attrs = true;
2158 return NULL_TREE;
2161 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
2163 error ("indirect function %q+D cannot be declared weakref", *node);
2164 *no_add_attrs = true;
2165 return NULL_TREE;
2168 /* The idea here is that `weakref("name")' mutates into `weakref,
2169 alias("name")', and weakref without arguments, in turn,
2170 implicitly adds weak. */
2172 if (args)
2174 attr = tree_cons (get_identifier ("alias"), args, attr);
2175 attr = tree_cons (get_identifier ("weakref"), NULL_TREE, attr);
2177 *no_add_attrs = true;
2179 decl_attributes (node, attr, flags);
2181 else
2183 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node)))
2184 error_at (DECL_SOURCE_LOCATION (*node),
2185 "weakref attribute must appear before alias attribute");
2187 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2188 and that isn't supported; and because it wants to add it to
2189 the list of weak decls, which isn't helpful. */
2190 DECL_WEAK (*node) = 1;
2193 if (decl_in_symtab_p (*node))
2195 struct symtab_node *n = symtab_node::get (*node);
2196 if (n && n->refuse_visibility_changes)
2197 error ("%+qD declared weakref after being used", *node);
2200 return NULL_TREE;
2203 /* Handle an "visibility" attribute; arguments as in
2204 struct attribute_spec.handler. */
2206 static tree
2207 handle_visibility_attribute (tree *node, tree name, tree args,
2208 int ARG_UNUSED (flags),
2209 bool *ARG_UNUSED (no_add_attrs))
2211 tree decl = *node;
2212 tree id = TREE_VALUE (args);
2213 enum symbol_visibility vis;
2215 if (TYPE_P (*node))
2217 if (TREE_CODE (*node) == ENUMERAL_TYPE)
2218 /* OK */;
2219 else if (!RECORD_OR_UNION_TYPE_P (*node))
2221 warning (OPT_Wattributes, "%qE attribute ignored on non-class types",
2222 name);
2223 return NULL_TREE;
2225 else if (TYPE_FIELDS (*node))
2227 error ("%qE attribute ignored because %qT is already defined",
2228 name, *node);
2229 return NULL_TREE;
2232 else if (decl_function_context (decl) != 0 || !TREE_PUBLIC (decl))
2234 warning (OPT_Wattributes, "%qE attribute ignored", name);
2235 return NULL_TREE;
2238 if (TREE_CODE (id) != STRING_CST)
2240 error ("visibility argument not a string");
2241 return NULL_TREE;
2244 /* If this is a type, set the visibility on the type decl. */
2245 if (TYPE_P (decl))
2247 decl = TYPE_NAME (decl);
2248 if (!decl)
2249 return NULL_TREE;
2250 if (TREE_CODE (decl) == IDENTIFIER_NODE)
2252 warning (OPT_Wattributes, "%qE attribute ignored on types",
2253 name);
2254 return NULL_TREE;
2258 if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
2259 vis = VISIBILITY_DEFAULT;
2260 else if (strcmp (TREE_STRING_POINTER (id), "internal") == 0)
2261 vis = VISIBILITY_INTERNAL;
2262 else if (strcmp (TREE_STRING_POINTER (id), "hidden") == 0)
2263 vis = VISIBILITY_HIDDEN;
2264 else if (strcmp (TREE_STRING_POINTER (id), "protected") == 0)
2265 vis = VISIBILITY_PROTECTED;
2266 else
2268 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2269 vis = VISIBILITY_DEFAULT;
2272 if (DECL_VISIBILITY_SPECIFIED (decl)
2273 && vis != DECL_VISIBILITY (decl))
2275 tree attributes = (TYPE_P (*node)
2276 ? TYPE_ATTRIBUTES (*node)
2277 : DECL_ATTRIBUTES (decl));
2278 if (lookup_attribute ("visibility", attributes))
2279 error ("%qD redeclared with different visibility", decl);
2280 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2281 && lookup_attribute ("dllimport", attributes))
2282 error ("%qD was declared %qs which implies default visibility",
2283 decl, "dllimport");
2284 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2285 && lookup_attribute ("dllexport", attributes))
2286 error ("%qD was declared %qs which implies default visibility",
2287 decl, "dllexport");
2290 DECL_VISIBILITY (decl) = vis;
2291 DECL_VISIBILITY_SPECIFIED (decl) = 1;
2293 /* Go ahead and attach the attribute to the node as well. This is needed
2294 so we can determine whether we have VISIBILITY_DEFAULT because the
2295 visibility was not specified, or because it was explicitly overridden
2296 from the containing scope. */
2298 return NULL_TREE;
2301 /* Handle an "tls_model" attribute; arguments as in
2302 struct attribute_spec.handler. */
2304 static tree
2305 handle_tls_model_attribute (tree *node, tree name, tree args,
2306 int ARG_UNUSED (flags),
2307 bool *ARG_UNUSED (no_add_attrs))
2309 tree id;
2310 tree decl = *node;
2311 enum tls_model kind;
2313 if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
2315 warning (OPT_Wattributes, "%qE attribute ignored", name);
2316 return NULL_TREE;
2319 kind = DECL_TLS_MODEL (decl);
2320 id = TREE_VALUE (args);
2321 if (TREE_CODE (id) != STRING_CST)
2323 error ("tls_model argument not a string");
2324 return NULL_TREE;
2327 if (!strcmp (TREE_STRING_POINTER (id), "local-exec"))
2328 kind = TLS_MODEL_LOCAL_EXEC;
2329 else if (!strcmp (TREE_STRING_POINTER (id), "initial-exec"))
2330 kind = TLS_MODEL_INITIAL_EXEC;
2331 else if (!strcmp (TREE_STRING_POINTER (id), "local-dynamic"))
2332 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
2333 else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
2334 kind = TLS_MODEL_GLOBAL_DYNAMIC;
2335 else
2336 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2338 set_decl_tls_model (decl, kind);
2339 return NULL_TREE;
2342 /* Handle a "no_instrument_function" attribute; arguments as in
2343 struct attribute_spec.handler. */
2345 static tree
2346 handle_no_instrument_function_attribute (tree *node, tree name,
2347 tree ARG_UNUSED (args),
2348 int ARG_UNUSED (flags),
2349 bool *no_add_attrs)
2351 tree decl = *node;
2353 if (TREE_CODE (decl) != FUNCTION_DECL)
2355 error_at (DECL_SOURCE_LOCATION (decl),
2356 "%qE attribute applies only to functions", name);
2357 *no_add_attrs = true;
2359 else
2360 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
2362 return NULL_TREE;
2365 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2366 struct attribute_spec.handler. */
2368 static tree
2369 handle_no_profile_instrument_function_attribute (tree *node, tree name, tree,
2370 int, bool *no_add_attrs)
2372 if (TREE_CODE (*node) != FUNCTION_DECL)
2374 warning (OPT_Wattributes, "%qE attribute ignored", name);
2375 *no_add_attrs = true;
2378 return NULL_TREE;
2381 /* Handle a "malloc" attribute; arguments as in
2382 struct attribute_spec.handler. */
2384 static tree
2385 handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2386 int ARG_UNUSED (flags), bool *no_add_attrs)
2388 if (TREE_CODE (*node) == FUNCTION_DECL
2389 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node))))
2390 DECL_IS_MALLOC (*node) = 1;
2391 else
2393 warning (OPT_Wattributes, "%qE attribute ignored", name);
2394 *no_add_attrs = true;
2397 return NULL_TREE;
2400 /* Handle a "alloc_size" attribute; arguments as in
2401 struct attribute_spec.handler. */
2403 static tree
2404 handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args,
2405 int ARG_UNUSED (flags), bool *no_add_attrs)
2407 unsigned arg_count = type_num_arguments (*node);
2408 for (; args; args = TREE_CHAIN (args))
2410 tree position = TREE_VALUE (args);
2411 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2412 && TREE_CODE (position) != FUNCTION_DECL)
2413 position = default_conversion (position);
2415 if (!tree_fits_uhwi_p (position)
2416 || !arg_count
2417 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2419 warning (OPT_Wattributes,
2420 "alloc_size parameter outside range");
2421 *no_add_attrs = true;
2422 return NULL_TREE;
2425 return NULL_TREE;
2428 /* Handle a "alloc_align" attribute; arguments as in
2429 struct attribute_spec.handler. */
2431 static tree
2432 handle_alloc_align_attribute (tree *node, tree, tree args, int,
2433 bool *no_add_attrs)
2435 unsigned arg_count = type_num_arguments (*node);
2436 tree position = TREE_VALUE (args);
2437 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2438 && TREE_CODE (position) != FUNCTION_DECL)
2439 position = default_conversion (position);
2441 if (!tree_fits_uhwi_p (position)
2442 || !arg_count
2443 || !IN_RANGE (tree_to_uhwi (position), 1, arg_count))
2445 warning (OPT_Wattributes,
2446 "alloc_align parameter outside range");
2447 *no_add_attrs = true;
2448 return NULL_TREE;
2450 return NULL_TREE;
2453 /* Handle a "assume_aligned" attribute; arguments as in
2454 struct attribute_spec.handler. */
2456 static tree
2457 handle_assume_aligned_attribute (tree *, tree, tree args, int,
2458 bool *no_add_attrs)
2460 for (; args; args = TREE_CHAIN (args))
2462 tree position = TREE_VALUE (args);
2463 if (position && TREE_CODE (position) != IDENTIFIER_NODE
2464 && TREE_CODE (position) != FUNCTION_DECL)
2465 position = default_conversion (position);
2467 if (TREE_CODE (position) != INTEGER_CST)
2469 warning (OPT_Wattributes,
2470 "assume_aligned parameter not integer constant");
2471 *no_add_attrs = true;
2472 return NULL_TREE;
2475 return NULL_TREE;
2478 /* Handle a "fn spec" attribute; arguments as in
2479 struct attribute_spec.handler. */
2481 static tree
2482 handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name),
2483 tree args, int ARG_UNUSED (flags),
2484 bool *no_add_attrs ATTRIBUTE_UNUSED)
2486 gcc_assert (args
2487 && TREE_CODE (TREE_VALUE (args)) == STRING_CST
2488 && !TREE_CHAIN (args));
2489 return NULL_TREE;
2492 /* Handle a "bnd_variable_size" attribute; arguments as in
2493 struct attribute_spec.handler. */
2495 static tree
2496 handle_bnd_variable_size_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2497 int ARG_UNUSED (flags), bool *no_add_attrs)
2499 if (TREE_CODE (*node) != FIELD_DECL)
2501 warning (OPT_Wattributes, "%qE attribute ignored", name);
2502 *no_add_attrs = true;
2505 return NULL_TREE;
2508 /* Handle a "bnd_legacy" attribute; arguments as in
2509 struct attribute_spec.handler. */
2511 static tree
2512 handle_bnd_legacy (tree *node, tree name, tree ARG_UNUSED (args),
2513 int ARG_UNUSED (flags), bool *no_add_attrs)
2515 if (TREE_CODE (*node) != FUNCTION_DECL)
2517 warning (OPT_Wattributes, "%qE attribute ignored", name);
2518 *no_add_attrs = true;
2521 return NULL_TREE;
2524 /* Handle a "bnd_instrument" attribute; arguments as in
2525 struct attribute_spec.handler. */
2527 static tree
2528 handle_bnd_instrument (tree *node, tree name, tree ARG_UNUSED (args),
2529 int ARG_UNUSED (flags), bool *no_add_attrs)
2531 if (TREE_CODE (*node) != FUNCTION_DECL)
2533 warning (OPT_Wattributes, "%qE attribute ignored", name);
2534 *no_add_attrs = true;
2537 return NULL_TREE;
2540 /* Handle a "warn_unused" attribute; arguments as in
2541 struct attribute_spec.handler. */
2543 static tree
2544 handle_warn_unused_attribute (tree *node, tree name,
2545 tree args ATTRIBUTE_UNUSED,
2546 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
2548 if (TYPE_P (*node))
2549 /* Do nothing else, just set the attribute. We'll get at
2550 it later with lookup_attribute. */
2552 else
2554 warning (OPT_Wattributes, "%qE attribute ignored", name);
2555 *no_add_attrs = true;
2558 return NULL_TREE;
2561 /* Handle an "omp declare simd" attribute; arguments as in
2562 struct attribute_spec.handler. */
2564 static tree
2565 handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *)
2567 return NULL_TREE;
2570 /* Handle a "simd" attribute. */
2572 static tree
2573 handle_simd_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs)
2575 if (TREE_CODE (*node) == FUNCTION_DECL)
2577 tree t = get_identifier ("omp declare simd");
2578 tree attr = NULL_TREE;
2579 if (args)
2581 tree id = TREE_VALUE (args);
2583 if (TREE_CODE (id) != STRING_CST)
2585 error ("attribute %qE argument not a string", name);
2586 *no_add_attrs = true;
2587 return NULL_TREE;
2590 if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
2591 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2592 OMP_CLAUSE_NOTINBRANCH);
2593 else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
2594 attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
2595 OMP_CLAUSE_INBRANCH);
2596 else
2598 error ("only %<inbranch%> and %<notinbranch%> flags are "
2599 "allowed for %<__simd__%> attribute");
2600 *no_add_attrs = true;
2601 return NULL_TREE;
2605 DECL_ATTRIBUTES (*node)
2606 = tree_cons (t, build_tree_list (NULL_TREE, attr),
2607 DECL_ATTRIBUTES (*node));
2609 else
2611 warning (OPT_Wattributes, "%qE attribute ignored", name);
2612 *no_add_attrs = true;
2615 return NULL_TREE;
2618 /* Handle an "omp declare target" attribute; arguments as in
2619 struct attribute_spec.handler. */
2621 static tree
2622 handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
2624 return NULL_TREE;
2627 /* Handle a "returns_twice" attribute; arguments as in
2628 struct attribute_spec.handler. */
2630 static tree
2631 handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2632 int ARG_UNUSED (flags), bool *no_add_attrs)
2634 if (TREE_CODE (*node) == FUNCTION_DECL)
2635 DECL_IS_RETURNS_TWICE (*node) = 1;
2636 else
2638 warning (OPT_Wattributes, "%qE attribute ignored", name);
2639 *no_add_attrs = true;
2642 return NULL_TREE;
2645 /* Handle a "no_limit_stack" attribute; arguments as in
2646 struct attribute_spec.handler. */
2648 static tree
2649 handle_no_limit_stack_attribute (tree *node, tree name,
2650 tree ARG_UNUSED (args),
2651 int ARG_UNUSED (flags),
2652 bool *no_add_attrs)
2654 tree decl = *node;
2656 if (TREE_CODE (decl) != FUNCTION_DECL)
2658 error_at (DECL_SOURCE_LOCATION (decl),
2659 "%qE attribute applies only to functions", name);
2660 *no_add_attrs = true;
2662 else if (DECL_INITIAL (decl))
2664 error_at (DECL_SOURCE_LOCATION (decl),
2665 "can%'t set %qE attribute after definition", name);
2666 *no_add_attrs = true;
2668 else
2669 DECL_NO_LIMIT_STACK (decl) = 1;
2671 return NULL_TREE;
2674 /* Handle a "pure" attribute; arguments as in
2675 struct attribute_spec.handler. */
2677 static tree
2678 handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args),
2679 int ARG_UNUSED (flags), bool *no_add_attrs)
2681 if (TREE_CODE (*node) == FUNCTION_DECL)
2683 tree type = TREE_TYPE (*node);
2684 if (VOID_TYPE_P (TREE_TYPE (type)))
2685 warning (OPT_Wattributes, "%qE attribute on function "
2686 "returning %<void%>", name);
2688 DECL_PURE_P (*node) = 1;
2689 /* ??? TODO: Support types. */
2691 else
2693 warning (OPT_Wattributes, "%qE attribute ignored", name);
2694 *no_add_attrs = true;
2697 return NULL_TREE;
2700 /* Digest an attribute list destined for a transactional memory statement.
2701 ALLOWED is the set of attributes that are allowed for this statement;
2702 return the attribute we parsed. Multiple attributes are never allowed. */
2705 parse_tm_stmt_attr (tree attrs, int allowed)
2707 tree a_seen = NULL;
2708 int m_seen = 0;
2710 for ( ; attrs ; attrs = TREE_CHAIN (attrs))
2712 tree a = TREE_PURPOSE (attrs);
2713 int m = 0;
2715 if (is_attribute_p ("outer", a))
2716 m = TM_STMT_ATTR_OUTER;
2718 if ((m & allowed) == 0)
2720 warning (OPT_Wattributes, "%qE attribute directive ignored", a);
2721 continue;
2724 if (m_seen == 0)
2726 a_seen = a;
2727 m_seen = m;
2729 else if (m_seen == m)
2730 warning (OPT_Wattributes, "%qE attribute duplicated", a);
2731 else
2732 warning (OPT_Wattributes, "%qE attribute follows %qE", a, a_seen);
2735 return m_seen;
2738 /* Transform a TM attribute name into a maskable integer and back.
2739 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2740 to how the lack of an attribute is treated. */
2743 tm_attr_to_mask (tree attr)
2745 if (attr == NULL)
2746 return 0;
2747 if (is_attribute_p ("transaction_safe", attr))
2748 return TM_ATTR_SAFE;
2749 if (is_attribute_p ("transaction_callable", attr))
2750 return TM_ATTR_CALLABLE;
2751 if (is_attribute_p ("transaction_pure", attr))
2752 return TM_ATTR_PURE;
2753 if (is_attribute_p ("transaction_unsafe", attr))
2754 return TM_ATTR_IRREVOCABLE;
2755 if (is_attribute_p ("transaction_may_cancel_outer", attr))
2756 return TM_ATTR_MAY_CANCEL_OUTER;
2757 return 0;
2760 tree
2761 tm_mask_to_attr (int mask)
2763 const char *str;
2764 switch (mask)
2766 case TM_ATTR_SAFE:
2767 str = "transaction_safe";
2768 break;
2769 case TM_ATTR_CALLABLE:
2770 str = "transaction_callable";
2771 break;
2772 case TM_ATTR_PURE:
2773 str = "transaction_pure";
2774 break;
2775 case TM_ATTR_IRREVOCABLE:
2776 str = "transaction_unsafe";
2777 break;
2778 case TM_ATTR_MAY_CANCEL_OUTER:
2779 str = "transaction_may_cancel_outer";
2780 break;
2781 default:
2782 gcc_unreachable ();
2784 return get_identifier (str);
2787 /* Return the first TM attribute seen in LIST. */
2789 tree
2790 find_tm_attribute (tree list)
2792 for (; list ; list = TREE_CHAIN (list))
2794 tree name = TREE_PURPOSE (list);
2795 if (tm_attr_to_mask (name) != 0)
2796 return name;
2798 return NULL_TREE;
2801 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2802 Here we accept only function types, and verify that none of the other
2803 function TM attributes are also applied. */
2804 /* ??? We need to accept class types for C++, but not C. This greatly
2805 complicates this function, since we can no longer rely on the extra
2806 processing given by function_type_required. */
2808 static tree
2809 handle_tm_attribute (tree *node, tree name, tree args,
2810 int flags, bool *no_add_attrs)
2812 /* Only one path adds the attribute; others don't. */
2813 *no_add_attrs = true;
2815 switch (TREE_CODE (*node))
2817 case RECORD_TYPE:
2818 case UNION_TYPE:
2819 /* Only tm_callable and tm_safe apply to classes. */
2820 if (tm_attr_to_mask (name) & ~(TM_ATTR_SAFE | TM_ATTR_CALLABLE))
2821 goto ignored;
2822 /* FALLTHRU */
2824 case FUNCTION_TYPE:
2825 case METHOD_TYPE:
2827 tree old_name = find_tm_attribute (TYPE_ATTRIBUTES (*node));
2828 if (old_name == name)
2830 else if (old_name != NULL_TREE)
2831 error ("type was previously declared %qE", old_name);
2832 else
2833 *no_add_attrs = false;
2835 break;
2837 case FUNCTION_DECL:
2839 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2840 want to set transaction_safe on the type. */
2841 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name));
2842 if (!TYPE_P (DECL_CONTEXT (*node)))
2843 error_at (DECL_SOURCE_LOCATION (*node),
2844 "%<transaction_safe_dynamic%> may only be specified for "
2845 "a virtual function");
2846 *no_add_attrs = false;
2847 decl_attributes (&TREE_TYPE (*node),
2848 build_tree_list (get_identifier ("transaction_safe"),
2849 NULL_TREE),
2851 break;
2854 case POINTER_TYPE:
2856 enum tree_code subcode = TREE_CODE (TREE_TYPE (*node));
2857 if (subcode == FUNCTION_TYPE || subcode == METHOD_TYPE)
2859 tree fn_tmp = TREE_TYPE (*node);
2860 decl_attributes (&fn_tmp, tree_cons (name, args, NULL), 0);
2861 *node = build_pointer_type (fn_tmp);
2862 break;
2865 /* FALLTHRU */
2867 default:
2868 /* If a function is next, pass it on to be tried next. */
2869 if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
2870 return tree_cons (name, args, NULL);
2872 ignored:
2873 warning (OPT_Wattributes, "%qE attribute ignored", name);
2874 break;
2877 return NULL_TREE;
2880 /* Handle the TM_WRAP attribute; arguments as in
2881 struct attribute_spec.handler. */
2883 static tree
2884 handle_tm_wrap_attribute (tree *node, tree name, tree args,
2885 int ARG_UNUSED (flags), bool *no_add_attrs)
2887 tree decl = *node;
2889 /* We don't need the attribute even on success, since we
2890 record the entry in an external table. */
2891 *no_add_attrs = true;
2893 if (TREE_CODE (decl) != FUNCTION_DECL)
2894 warning (OPT_Wattributes, "%qE attribute ignored", name);
2895 else
2897 tree wrap_decl = TREE_VALUE (args);
2898 if (error_operand_p (wrap_decl))
2900 else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
2901 && !VAR_OR_FUNCTION_DECL_P (wrap_decl))
2902 error ("%qE argument not an identifier", name);
2903 else
2905 if (TREE_CODE (wrap_decl) == IDENTIFIER_NODE)
2906 wrap_decl = lookup_name (wrap_decl);
2907 if (wrap_decl && TREE_CODE (wrap_decl) == FUNCTION_DECL)
2909 if (lang_hooks.types_compatible_p (TREE_TYPE (decl),
2910 TREE_TYPE (wrap_decl)))
2911 record_tm_replacement (wrap_decl, decl);
2912 else
2913 error ("%qD is not compatible with %qD", wrap_decl, decl);
2915 else
2916 error ("%qE argument is not a function", name);
2920 return NULL_TREE;
2923 /* Ignore the given attribute. Used when this attribute may be usefully
2924 overridden by the target, but is not used generically. */
2926 static tree
2927 ignore_attribute (tree * ARG_UNUSED (node), tree ARG_UNUSED (name),
2928 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2929 bool *no_add_attrs)
2931 *no_add_attrs = true;
2932 return NULL_TREE;
2935 /* Handle a "no vops" attribute; arguments as in
2936 struct attribute_spec.handler. */
2938 static tree
2939 handle_novops_attribute (tree *node, tree ARG_UNUSED (name),
2940 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
2941 bool *ARG_UNUSED (no_add_attrs))
2943 gcc_assert (TREE_CODE (*node) == FUNCTION_DECL);
2944 DECL_IS_NOVOPS (*node) = 1;
2945 return NULL_TREE;
2948 /* Handle a "deprecated" attribute; arguments as in
2949 struct attribute_spec.handler. */
2951 static tree
2952 handle_deprecated_attribute (tree *node, tree name,
2953 tree args, int flags,
2954 bool *no_add_attrs)
2956 tree type = NULL_TREE;
2957 int warn = 0;
2958 tree what = NULL_TREE;
2960 if (!args)
2961 *no_add_attrs = true;
2962 else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
2964 error ("deprecated message is not a string");
2965 *no_add_attrs = true;
2968 if (DECL_P (*node))
2970 tree decl = *node;
2971 type = TREE_TYPE (decl);
2973 if (TREE_CODE (decl) == TYPE_DECL
2974 || TREE_CODE (decl) == PARM_DECL
2975 || VAR_OR_FUNCTION_DECL_P (decl)
2976 || TREE_CODE (decl) == FIELD_DECL
2977 || TREE_CODE (decl) == CONST_DECL
2978 || objc_method_decl (TREE_CODE (decl)))
2979 TREE_DEPRECATED (decl) = 1;
2980 else
2981 warn = 1;
2983 else if (TYPE_P (*node))
2985 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
2986 *node = build_variant_type_copy (*node);
2987 TREE_DEPRECATED (*node) = 1;
2988 type = *node;
2990 else
2991 warn = 1;
2993 if (warn)
2995 *no_add_attrs = true;
2996 if (type && TYPE_NAME (type))
2998 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2999 what = TYPE_NAME (*node);
3000 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
3001 && DECL_NAME (TYPE_NAME (type)))
3002 what = DECL_NAME (TYPE_NAME (type));
3004 if (what)
3005 warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
3006 else
3007 warning (OPT_Wattributes, "%qE attribute ignored", name);
3010 return NULL_TREE;
3013 /* Handle a "vector_size" attribute; arguments as in
3014 struct attribute_spec.handler. */
3016 static tree
3017 handle_vector_size_attribute (tree *node, tree name, tree args,
3018 int ARG_UNUSED (flags),
3019 bool *no_add_attrs)
3021 unsigned HOST_WIDE_INT vecsize, nunits;
3022 machine_mode orig_mode;
3023 tree type = *node, new_type, size;
3025 *no_add_attrs = true;
3027 size = TREE_VALUE (args);
3028 if (size && TREE_CODE (size) != IDENTIFIER_NODE
3029 && TREE_CODE (size) != FUNCTION_DECL)
3030 size = default_conversion (size);
3032 if (!tree_fits_uhwi_p (size))
3034 warning (OPT_Wattributes, "%qE attribute ignored", name);
3035 return NULL_TREE;
3038 /* Get the vector size (in bytes). */
3039 vecsize = tree_to_uhwi (size);
3041 /* We need to provide for vector pointers, vector arrays, and
3042 functions returning vectors. For example:
3044 __attribute__((vector_size(16))) short *foo;
3046 In this case, the mode is SI, but the type being modified is
3047 HI, so we need to look further. */
3049 while (POINTER_TYPE_P (type)
3050 || TREE_CODE (type) == FUNCTION_TYPE
3051 || TREE_CODE (type) == METHOD_TYPE
3052 || TREE_CODE (type) == ARRAY_TYPE
3053 || TREE_CODE (type) == OFFSET_TYPE)
3054 type = TREE_TYPE (type);
3056 /* Get the mode of the type being modified. */
3057 orig_mode = TYPE_MODE (type);
3059 if ((!INTEGRAL_TYPE_P (type)
3060 && !SCALAR_FLOAT_TYPE_P (type)
3061 && !FIXED_POINT_TYPE_P (type))
3062 || (!SCALAR_FLOAT_MODE_P (orig_mode)
3063 && GET_MODE_CLASS (orig_mode) != MODE_INT
3064 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
3065 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
3066 || TREE_CODE (type) == BOOLEAN_TYPE)
3068 error ("invalid vector type for attribute %qE", name);
3069 return NULL_TREE;
3072 if (vecsize % tree_to_uhwi (TYPE_SIZE_UNIT (type)))
3074 error ("vector size not an integral multiple of component size");
3075 return NULL;
3078 if (vecsize == 0)
3080 error ("zero vector size");
3081 return NULL;
3084 /* Calculate how many units fit in the vector. */
3085 nunits = vecsize / tree_to_uhwi (TYPE_SIZE_UNIT (type));
3086 if (nunits & (nunits - 1))
3088 error ("number of components of the vector not a power of two");
3089 return NULL_TREE;
3092 new_type = build_vector_type (type, nunits);
3094 /* Build back pointers if needed. */
3095 *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
3097 return NULL_TREE;
3100 /* Handle the "nonnull" attribute. */
3102 static tree
3103 handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name),
3104 tree args, int ARG_UNUSED (flags),
3105 bool *no_add_attrs)
3107 tree type = *node;
3108 unsigned HOST_WIDE_INT attr_arg_num;
3110 /* If no arguments are specified, all pointer arguments should be
3111 non-null. Verify a full prototype is given so that the arguments
3112 will have the correct types when we actually check them later.
3113 Avoid diagnosing type-generic built-ins since those have no
3114 prototype. */
3115 if (!args)
3117 if (!prototype_p (type)
3118 && (!TYPE_ATTRIBUTES (type)
3119 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type))))
3121 error ("nonnull attribute without arguments on a non-prototype");
3122 *no_add_attrs = true;
3124 return NULL_TREE;
3127 /* Argument list specified. Verify that each argument number references
3128 a pointer argument. */
3129 for (attr_arg_num = 1; args; attr_arg_num++, args = TREE_CHAIN (args))
3131 unsigned HOST_WIDE_INT arg_num = 0, ck_num;
3133 tree arg = TREE_VALUE (args);
3134 if (arg && TREE_CODE (arg) != IDENTIFIER_NODE
3135 && TREE_CODE (arg) != FUNCTION_DECL)
3136 TREE_VALUE (args) = arg = default_conversion (arg);
3138 if (!get_nonnull_operand (arg, &arg_num))
3140 error ("nonnull argument has invalid operand number (argument %lu)",
3141 (unsigned long) attr_arg_num);
3142 *no_add_attrs = true;
3143 return NULL_TREE;
3146 if (prototype_p (type))
3148 function_args_iterator iter;
3149 tree argument;
3151 function_args_iter_init (&iter, type);
3152 for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter))
3154 argument = function_args_iter_cond (&iter);
3155 if (argument == NULL_TREE || ck_num == arg_num)
3156 break;
3159 if (!argument
3160 || TREE_CODE (argument) == VOID_TYPE)
3162 error ("nonnull argument with out-of-range operand number "
3163 "(argument %lu, operand %lu)",
3164 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3165 *no_add_attrs = true;
3166 return NULL_TREE;
3169 if (TREE_CODE (argument) != POINTER_TYPE)
3171 error ("nonnull argument references non-pointer operand "
3172 "(argument %lu, operand %lu)",
3173 (unsigned long) attr_arg_num, (unsigned long) arg_num);
3174 *no_add_attrs = true;
3175 return NULL_TREE;
3180 return NULL_TREE;
3183 /* Handle the "nonstring" variable attribute. */
3185 static tree
3186 handle_nonstring_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3187 int ARG_UNUSED (flags), bool *no_add_attrs)
3189 gcc_assert (!args);
3190 tree_code code = TREE_CODE (*node);
3192 if (VAR_P (*node)
3193 || code == FIELD_DECL
3194 || code == PARM_DECL)
3196 tree type = TREE_TYPE (*node);
3198 if (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
3200 /* Accept the attribute on arrays and pointers to all three
3201 narrow character types. */
3202 tree eltype = TREE_TYPE (type);
3203 eltype = TYPE_MAIN_VARIANT (eltype);
3204 if (eltype == char_type_node
3205 || eltype == signed_char_type_node
3206 || eltype == unsigned_char_type_node)
3207 return NULL_TREE;
3210 warning (OPT_Wattributes,
3211 "%qE attribute ignored on objects of type %qT",
3212 name, type);
3213 *no_add_attrs = true;
3214 return NULL_TREE;
3217 if (code == FUNCTION_DECL)
3218 warning (OPT_Wattributes,
3219 "%qE attribute does not apply to functions", name);
3220 else if (code == TYPE_DECL)
3221 warning (OPT_Wattributes,
3222 "%qE attribute does not apply to types", name);
3223 else
3224 warning (OPT_Wattributes, "%qE attribute ignored", name);
3226 *no_add_attrs = true;
3227 return NULL_TREE;
3230 /* Handle a "nothrow" attribute; arguments as in
3231 struct attribute_spec.handler. */
3233 static tree
3234 handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3235 int ARG_UNUSED (flags), bool *no_add_attrs)
3237 if (TREE_CODE (*node) == FUNCTION_DECL)
3238 TREE_NOTHROW (*node) = 1;
3239 /* ??? TODO: Support types. */
3240 else
3242 warning (OPT_Wattributes, "%qE attribute ignored", name);
3243 *no_add_attrs = true;
3246 return NULL_TREE;
3249 /* Handle a "cleanup" attribute; arguments as in
3250 struct attribute_spec.handler. */
3252 static tree
3253 handle_cleanup_attribute (tree *node, tree name, tree args,
3254 int ARG_UNUSED (flags), bool *no_add_attrs)
3256 tree decl = *node;
3257 tree cleanup_id, cleanup_decl;
3259 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3260 for global destructors in C++. This requires infrastructure that
3261 we don't have generically at the moment. It's also not a feature
3262 we'd be missing too much, since we do have attribute constructor. */
3263 if (!VAR_P (decl) || TREE_STATIC (decl))
3265 warning (OPT_Wattributes, "%qE attribute ignored", name);
3266 *no_add_attrs = true;
3267 return NULL_TREE;
3270 /* Verify that the argument is a function in scope. */
3271 /* ??? We could support pointers to functions here as well, if
3272 that was considered desirable. */
3273 cleanup_id = TREE_VALUE (args);
3274 if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
3276 error ("cleanup argument not an identifier");
3277 *no_add_attrs = true;
3278 return NULL_TREE;
3280 cleanup_decl = lookup_name (cleanup_id);
3281 if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
3283 error ("cleanup argument not a function");
3284 *no_add_attrs = true;
3285 return NULL_TREE;
3288 /* That the function has proper type is checked with the
3289 eventual call to build_function_call. */
3291 return NULL_TREE;
3294 /* Handle a "warn_unused_result" attribute. No special handling. */
3296 static tree
3297 handle_warn_unused_result_attribute (tree *node, tree name,
3298 tree ARG_UNUSED (args),
3299 int ARG_UNUSED (flags), bool *no_add_attrs)
3301 /* Ignore the attribute for functions not returning any value. */
3302 if (VOID_TYPE_P (TREE_TYPE (*node)))
3304 warning (OPT_Wattributes, "%qE attribute ignored", name);
3305 *no_add_attrs = true;
3308 return NULL_TREE;
3311 /* Handle a "sentinel" attribute. */
3313 static tree
3314 handle_sentinel_attribute (tree *node, tree name, tree args,
3315 int ARG_UNUSED (flags), bool *no_add_attrs)
3317 if (!prototype_p (*node))
3319 warning (OPT_Wattributes,
3320 "%qE attribute requires prototypes with named arguments", name);
3321 *no_add_attrs = true;
3323 else
3325 if (!stdarg_p (*node))
3327 warning (OPT_Wattributes,
3328 "%qE attribute only applies to variadic functions", name);
3329 *no_add_attrs = true;
3333 if (args)
3335 tree position = TREE_VALUE (args);
3336 if (position && TREE_CODE (position) != IDENTIFIER_NODE
3337 && TREE_CODE (position) != FUNCTION_DECL)
3338 position = default_conversion (position);
3340 if (TREE_CODE (position) != INTEGER_CST
3341 || !INTEGRAL_TYPE_P (TREE_TYPE (position)))
3343 warning (OPT_Wattributes,
3344 "requested position is not an integer constant");
3345 *no_add_attrs = true;
3347 else
3349 if (tree_int_cst_lt (position, integer_zero_node))
3351 warning (OPT_Wattributes,
3352 "requested position is less than zero");
3353 *no_add_attrs = true;
3358 return NULL_TREE;
3361 /* Handle a "type_generic" attribute. */
3363 static tree
3364 handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name),
3365 tree ARG_UNUSED (args), int ARG_UNUSED (flags),
3366 bool * ARG_UNUSED (no_add_attrs))
3368 /* Ensure we have a function type. */
3369 gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE);
3371 /* Ensure we have a variadic function. */
3372 gcc_assert (!prototype_p (*node) || stdarg_p (*node));
3374 return NULL_TREE;
3377 /* Handle a "target" attribute. */
3379 static tree
3380 handle_target_attribute (tree *node, tree name, tree args, int flags,
3381 bool *no_add_attrs)
3383 /* Ensure we have a function type. */
3384 if (TREE_CODE (*node) != FUNCTION_DECL)
3386 warning (OPT_Wattributes, "%qE attribute ignored", name);
3387 *no_add_attrs = true;
3389 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
3391 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3392 "with %qs attribute", name, "target_clones");
3393 *no_add_attrs = true;
3395 else if (! targetm.target_option.valid_attribute_p (*node, name, args,
3396 flags))
3397 *no_add_attrs = true;
3399 /* Check that there's no empty string in values of the attribute. */
3400 for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
3402 tree value = TREE_VALUE (t);
3403 if (TREE_CODE (value) == STRING_CST
3404 && TREE_STRING_LENGTH (value) == 1
3405 && TREE_STRING_POINTER (value)[0] == '\0')
3407 warning (OPT_Wattributes, "empty string in attribute %<target%>");
3408 *no_add_attrs = true;
3412 return NULL_TREE;
3415 /* Handle a "target_clones" attribute. */
3417 static tree
3418 handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
3419 int ARG_UNUSED (flags), bool *no_add_attrs)
3421 /* Ensure we have a function type. */
3422 if (TREE_CODE (*node) == FUNCTION_DECL)
3424 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node)))
3426 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3427 "with %qs attribute", name, "always_inline");
3428 *no_add_attrs = true;
3430 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node)))
3432 warning (OPT_Wattributes, "%qE attribute ignored due to conflict "
3433 "with %qs attribute", name, "target");
3434 *no_add_attrs = true;
3436 else
3437 /* Do not inline functions with multiple clone targets. */
3438 DECL_UNINLINABLE (*node) = 1;
3440 else
3442 warning (OPT_Wattributes, "%qE attribute ignored", name);
3443 *no_add_attrs = true;
3445 return NULL_TREE;
3448 /* For handling "optimize" attribute. arguments as in
3449 struct attribute_spec.handler. */
3451 static tree
3452 handle_optimize_attribute (tree *node, tree name, tree args,
3453 int ARG_UNUSED (flags), bool *no_add_attrs)
3455 /* Ensure we have a function type. */
3456 if (TREE_CODE (*node) != FUNCTION_DECL)
3458 warning (OPT_Wattributes, "%qE attribute ignored", name);
3459 *no_add_attrs = true;
3461 else
3463 struct cl_optimization cur_opts;
3464 tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
3466 /* Save current options. */
3467 cl_optimization_save (&cur_opts, &global_options);
3469 /* If we previously had some optimization options, use them as the
3470 default. */
3471 if (old_opts)
3472 cl_optimization_restore (&global_options,
3473 TREE_OPTIMIZATION (old_opts));
3475 /* Parse options, and update the vector. */
3476 parse_optimize_options (args, true);
3477 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
3478 = build_optimization_node (&global_options);
3480 /* Restore current options. */
3481 cl_optimization_restore (&global_options, &cur_opts);
3484 return NULL_TREE;
3487 /* Handle a "no_split_stack" attribute. */
3489 static tree
3490 handle_no_split_stack_attribute (tree *node, tree name,
3491 tree ARG_UNUSED (args),
3492 int ARG_UNUSED (flags),
3493 bool *no_add_attrs)
3495 tree decl = *node;
3497 if (TREE_CODE (decl) != FUNCTION_DECL)
3499 error_at (DECL_SOURCE_LOCATION (decl),
3500 "%qE attribute applies only to functions", name);
3501 *no_add_attrs = true;
3503 else if (DECL_INITIAL (decl))
3505 error_at (DECL_SOURCE_LOCATION (decl),
3506 "can%'t set %qE attribute after definition", name);
3507 *no_add_attrs = true;
3510 return NULL_TREE;
3513 /* Handle a "returns_nonnull" attribute; arguments as in
3514 struct attribute_spec.handler. */
3516 static tree
3517 handle_returns_nonnull_attribute (tree *node, tree, tree, int,
3518 bool *no_add_attrs)
3520 // Even without a prototype we still have a return type we can check.
3521 if (TREE_CODE (TREE_TYPE (*node)) != POINTER_TYPE)
3523 error ("returns_nonnull attribute on a function not returning a pointer");
3524 *no_add_attrs = true;
3526 return NULL_TREE;
3529 /* Handle a "designated_init" attribute; arguments as in
3530 struct attribute_spec.handler. */
3532 static tree
3533 handle_designated_init_attribute (tree *node, tree name, tree, int,
3534 bool *no_add_attrs)
3536 if (TREE_CODE (*node) != RECORD_TYPE)
3538 error ("%qE attribute is only valid on %<struct%> type", name);
3539 *no_add_attrs = true;
3541 return NULL_TREE;
3545 /* Handle a "fallthrough" attribute; arguments as in struct
3546 attribute_spec.handler. */
3548 static tree
3549 handle_fallthrough_attribute (tree *, tree name, tree, int,
3550 bool *no_add_attrs)
3552 warning (OPT_Wattributes, "%qE attribute ignored", name);
3553 *no_add_attrs = true;
3554 return NULL_TREE;
3557 static tree
3558 handle_patchable_function_entry_attribute (tree *, tree, tree, int, bool *)
3560 /* Nothing to be done here. */
3561 return NULL_TREE;