1 /* C-family attributes handling.
2 Copyright (C) 1992-2017 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
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
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/>. */
22 #include "coretypes.h"
28 #include "gimple-expr.h"
30 #include "stringpool.h"
32 #include "diagnostic.h"
34 #include "stor-layout.h"
38 #include "trans-mem.h"
40 #include "common/common-target.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
44 #include "tree-iterator.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
,
57 static tree
handle_no_sanitize_thread_attribute (tree
*, tree
, tree
,
59 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
61 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
63 static tree
handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int,
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,
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,
81 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
83 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
84 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
86 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
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
,
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,
103 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
105 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
107 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
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,
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,
119 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
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,
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,
142 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
143 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
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
,
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, handler,
249 affects_type_identity } */
250 { "packed", 0, 0, false, false, false,
251 handle_packed_attribute
, false,
252 attr_aligned_exclusions
},
253 { "nocommon", 0, 0, true, false, false,
254 handle_nocommon_attribute
, false,
255 attr_common_exclusions
},
256 { "common", 0, 0, true, false, false,
257 handle_common_attribute
, false,
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,
265 handle_noreturn_attribute
, false,
266 attr_noreturn_exclusions
},
267 { "volatile", 0, 0, true, false, false,
268 handle_noreturn_attribute
, false, NULL
},
269 { "stack_protect", 0, 0, true, false, false,
270 handle_stack_protect_attribute
, false, NULL
},
271 { "noinline", 0, 0, true, false, false,
272 handle_noinline_attribute
, false,
273 attr_noinline_exclusions
},
274 { "noclone", 0, 0, true, false, false,
275 handle_noclone_attribute
, false, NULL
},
276 { "no_icf", 0, 0, true, false, false,
277 handle_noicf_attribute
, false, NULL
},
278 { "noipa", 0, 0, true, false, false,
279 handle_noipa_attribute
, false, NULL
},
280 { "leaf", 0, 0, true, false, false,
281 handle_leaf_attribute
, false, NULL
},
282 { "always_inline", 0, 0, true, false, false,
283 handle_always_inline_attribute
, false,
284 attr_inline_exclusions
},
285 { "gnu_inline", 0, 0, true, false, false,
286 handle_gnu_inline_attribute
, false,
287 attr_inline_exclusions
},
288 { "artificial", 0, 0, true, false, false,
289 handle_artificial_attribute
, false, NULL
},
290 { "flatten", 0, 0, true, false, false,
291 handle_flatten_attribute
, false, NULL
},
292 { "used", 0, 0, true, false, false,
293 handle_used_attribute
, false, NULL
},
294 { "unused", 0, 0, false, false, false,
295 handle_unused_attribute
, false, NULL
},
296 { "externally_visible", 0, 0, true, false, false,
297 handle_externally_visible_attribute
, false, NULL
},
298 { "no_reorder", 0, 0, true, false, false,
299 handle_no_reorder_attribute
, false, NULL
},
300 /* The same comments as for noreturn attributes apply to const ones. */
301 { "const", 0, 0, true, false, false,
302 handle_const_attribute
, false,
303 attr_const_pure_exclusions
},
304 { "scalar_storage_order", 1, 1, false, false, false,
305 handle_scalar_storage_order_attribute
, false, NULL
},
306 { "transparent_union", 0, 0, false, false, false,
307 handle_transparent_union_attribute
, false, NULL
},
308 { "constructor", 0, 1, true, false, false,
309 handle_constructor_attribute
, false, NULL
},
310 { "destructor", 0, 1, true, false, false,
311 handle_destructor_attribute
, false, NULL
},
312 { "mode", 1, 1, false, true, false,
313 handle_mode_attribute
, false, NULL
},
314 { "section", 1, 1, true, false, false,
315 handle_section_attribute
, false, NULL
},
316 { "aligned", 0, 1, false, false, false,
317 handle_aligned_attribute
, false,
318 attr_aligned_exclusions
},
319 { "warn_if_not_aligned", 0, 1, false, false, false,
320 handle_warn_if_not_aligned_attribute
,
322 { "weak", 0, 0, true, false, false,
323 handle_weak_attribute
, false, NULL
},
324 { "noplt", 0, 0, true, false, false,
325 handle_noplt_attribute
, false, NULL
},
326 { "ifunc", 1, 1, true, false, false,
327 handle_ifunc_attribute
, false, NULL
},
328 { "alias", 1, 1, true, false, false,
329 handle_alias_attribute
, false, NULL
},
330 { "weakref", 0, 1, true, false, false,
331 handle_weakref_attribute
, false, NULL
},
332 { "no_instrument_function", 0, 0, true, false, false,
333 handle_no_instrument_function_attribute
,
335 { "no_profile_instrument_function", 0, 0, true, false, false,
336 handle_no_profile_instrument_function_attribute
,
338 { "malloc", 0, 0, true, false, false,
339 handle_malloc_attribute
, false,
340 attr_alloc_exclusions
},
341 { "returns_twice", 0, 0, true, false, false,
342 handle_returns_twice_attribute
, false,
343 attr_returns_twice_exclusions
},
344 { "no_stack_limit", 0, 0, true, false, false,
345 handle_no_limit_stack_attribute
, false, NULL
},
346 { "pure", 0, 0, true, false, false,
347 handle_pure_attribute
, false,
348 attr_const_pure_exclusions
},
349 { "transaction_callable", 0, 0, false, true, false,
350 handle_tm_attribute
, false, NULL
},
351 { "transaction_unsafe", 0, 0, false, true, false,
352 handle_tm_attribute
, true, NULL
},
353 { "transaction_safe", 0, 0, false, true, false,
354 handle_tm_attribute
, true, NULL
},
355 { "transaction_safe_dynamic", 0, 0, true, false, false,
356 handle_tm_attribute
, false, NULL
},
357 { "transaction_may_cancel_outer", 0, 0, false, true, false,
358 handle_tm_attribute
, false, NULL
},
359 /* ??? These two attributes didn't make the transition from the
360 Intel language document to the multi-vendor language document. */
361 { "transaction_pure", 0, 0, false, true, false,
362 handle_tm_attribute
, false, NULL
},
363 { "transaction_wrap", 1, 1, true, false, false,
364 handle_tm_wrap_attribute
, false, NULL
},
365 /* For internal use (marking of builtins) only. The name contains space
366 to prevent its usage in source code. */
367 { "no vops", 0, 0, true, false, false,
368 handle_novops_attribute
, false, NULL
},
369 { "deprecated", 0, 1, false, false, false,
370 handle_deprecated_attribute
, false, NULL
},
371 { "vector_size", 1, 1, false, true, false,
372 handle_vector_size_attribute
, true, NULL
},
373 { "visibility", 1, 1, false, false, false,
374 handle_visibility_attribute
, false, NULL
},
375 { "tls_model", 1, 1, true, false, false,
376 handle_tls_model_attribute
, false, NULL
},
377 { "nonnull", 0, -1, false, true, true,
378 handle_nonnull_attribute
, false, NULL
},
379 { "nonstring", 0, 0, true, false, false,
380 handle_nonstring_attribute
, false, NULL
},
381 { "nothrow", 0, 0, true, false, false,
382 handle_nothrow_attribute
, false, NULL
},
383 { "may_alias", 0, 0, false, true, false, NULL
, false, NULL
},
384 { "cleanup", 1, 1, true, false, false,
385 handle_cleanup_attribute
, false, NULL
},
386 { "warn_unused_result", 0, 0, false, true, true,
387 handle_warn_unused_result_attribute
, false,
388 attr_warn_unused_result_exclusions
},
389 { "sentinel", 0, 1, false, true, true,
390 handle_sentinel_attribute
, false, NULL
},
391 /* For internal use (marking of builtins) only. The name contains space
392 to prevent its usage in source code. */
393 { "type generic", 0, 0, false, true, true,
394 handle_type_generic_attribute
, false, NULL
},
395 { "alloc_size", 1, 2, false, true, true,
396 handle_alloc_size_attribute
, false,
397 attr_alloc_exclusions
},
398 { "cold", 0, 0, true, false, false,
399 handle_cold_attribute
, false,
400 attr_cold_hot_exclusions
},
401 { "hot", 0, 0, true, false, false,
402 handle_hot_attribute
, false,
403 attr_cold_hot_exclusions
},
404 { "no_address_safety_analysis",
405 0, 0, true, false, false,
406 handle_no_address_safety_analysis_attribute
,
408 { "no_sanitize", 1, 1, true, false, false,
409 handle_no_sanitize_attribute
,
411 { "no_sanitize_address", 0, 0, true, false, false,
412 handle_no_sanitize_address_attribute
,
414 { "no_sanitize_thread", 0, 0, true, false, false,
415 handle_no_sanitize_thread_attribute
,
417 { "no_sanitize_undefined", 0, 0, true, false, false,
418 handle_no_sanitize_undefined_attribute
,
420 { "asan odr indicator", 0, 0, true, false, false,
421 handle_asan_odr_indicator_attribute
,
423 { "warning", 1, 1, true, false, false,
424 handle_error_attribute
, false, NULL
},
425 { "error", 1, 1, true, false, false,
426 handle_error_attribute
, false, NULL
},
427 { "target", 1, -1, true, false, false,
428 handle_target_attribute
, false, NULL
},
429 { "target_clones", 1, -1, true, false, false,
430 handle_target_clones_attribute
, false, NULL
},
431 { "optimize", 1, -1, true, false, false,
432 handle_optimize_attribute
, false, NULL
},
433 /* For internal use only. The leading '*' both prevents its usage in
434 source code and signals that it may be overridden by machine tables. */
435 { "*tm regparm", 0, 0, false, true, true,
436 ignore_attribute
, false, NULL
},
437 { "no_split_stack", 0, 0, true, false, false,
438 handle_no_split_stack_attribute
, false, NULL
},
439 /* For internal use (marking of builtins and runtime functions) only.
440 The name contains space to prevent its usage in source code. */
441 { "fn spec", 1, 1, false, true, true,
442 handle_fnspec_attribute
, false, NULL
},
443 { "warn_unused", 0, 0, false, false, false,
444 handle_warn_unused_attribute
, false, NULL
},
445 { "returns_nonnull", 0, 0, false, true, true,
446 handle_returns_nonnull_attribute
, false, NULL
},
447 { "omp declare simd", 0, -1, true, false, false,
448 handle_omp_declare_simd_attribute
, false, NULL
},
449 { "cilk simd function", 0, -1, true, false, false,
450 handle_omp_declare_simd_attribute
, false, NULL
},
451 { "simd", 0, 1, true, false, false,
452 handle_simd_attribute
, false, NULL
},
453 { "omp declare target", 0, 0, true, false, false,
454 handle_omp_declare_target_attribute
, false, NULL
},
455 { "omp declare target link", 0, 0, true, false, false,
456 handle_omp_declare_target_attribute
, false, NULL
},
457 { "alloc_align", 1, 1, false, true, true,
458 handle_alloc_align_attribute
, false,
459 attr_alloc_exclusions
},
460 { "assume_aligned", 1, 2, false, true, true,
461 handle_assume_aligned_attribute
, false, NULL
},
462 { "designated_init", 0, 0, false, true, false,
463 handle_designated_init_attribute
, false, NULL
},
464 { "bnd_variable_size", 0, 0, true, false, false,
465 handle_bnd_variable_size_attribute
, false, NULL
},
466 { "bnd_legacy", 0, 0, true, false, false,
467 handle_bnd_legacy
, false, NULL
},
468 { "bnd_instrument", 0, 0, true, false, false,
469 handle_bnd_instrument
, false, NULL
},
470 { "fallthrough", 0, 0, false, false, false,
471 handle_fallthrough_attribute
, false, NULL
},
472 { "patchable_function_entry", 1, 2, true, false, false,
473 handle_patchable_function_entry_attribute
,
475 { "nocf_check", 0, 0, false, true, true,
476 handle_nocf_check_attribute
, true, NULL
},
477 { NULL
, 0, 0, false, false, false, NULL
, false, NULL
}
480 /* Give the specifications for the format attributes, used by C and all
483 All attributes referencing arguments should be additionally processed
484 in chkp_copy_function_type_adding_bounds for correct instrumentation
485 by Pointer Bounds Checker.
486 Current list of processed format attributes: format, format_arg. */
487 const struct attribute_spec c_common_format_attribute_table
[] =
489 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
490 affects_type_identity } */
491 { "format", 3, 3, false, true, true,
492 handle_format_attribute
, false, NULL
},
493 { "format_arg", 1, 1, false, true, true,
494 handle_format_arg_attribute
, false, NULL
},
495 { NULL
, 0, 0, false, false, false, NULL
, false, NULL
}
498 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
499 identifier as an argument, so the front end shouldn't look it up. */
502 attribute_takes_identifier_p (const_tree attr_id
)
504 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
506 /* Unknown attribute that we'll end up ignoring, return true so we
507 don't complain about an identifier argument. */
509 else if (!strcmp ("mode", spec
->name
)
510 || !strcmp ("format", spec
->name
)
511 || !strcmp ("cleanup", spec
->name
))
514 return targetm
.attribute_takes_identifier_p (attr_id
);
517 /* Attribute handlers common to C front ends. */
519 /* Handle a "packed" attribute; arguments as in
520 struct attribute_spec.handler. */
523 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
524 int flags
, bool *no_add_attrs
)
528 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
529 *node
= build_variant_type_copy (*node
);
530 TYPE_PACKED (*node
) = 1;
532 else if (TREE_CODE (*node
) == FIELD_DECL
)
534 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
535 /* Still pack bitfields. */
536 && ! DECL_C_BIT_FIELD (*node
))
537 warning (OPT_Wattributes
,
538 "%qE attribute ignored for field of type %qT",
539 name
, TREE_TYPE (*node
));
541 DECL_PACKED (*node
) = 1;
543 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
544 used for DECL_REGISTER. It wouldn't mean anything anyway.
545 We can't set DECL_PACKED on the type of a TYPE_DECL, because
546 that changes what the typedef is typing. */
549 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
550 *no_add_attrs
= true;
556 /* Handle a "nocommon" attribute; arguments as in
557 struct attribute_spec.handler. */
560 handle_nocommon_attribute (tree
*node
, tree name
,
561 tree
ARG_UNUSED (args
),
562 int ARG_UNUSED (flags
), bool *no_add_attrs
)
565 DECL_COMMON (*node
) = 0;
568 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
569 *no_add_attrs
= true;
575 /* Handle a "common" attribute; arguments as in
576 struct attribute_spec.handler. */
579 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
580 int ARG_UNUSED (flags
), bool *no_add_attrs
)
583 DECL_COMMON (*node
) = 1;
586 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
587 *no_add_attrs
= true;
593 /* Handle a "noreturn" attribute; arguments as in
594 struct attribute_spec.handler. */
597 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
598 int ARG_UNUSED (flags
), bool *no_add_attrs
)
600 tree type
= TREE_TYPE (*node
);
602 /* See FIXME comment in c_common_attribute_table. */
603 if (TREE_CODE (*node
) == FUNCTION_DECL
604 || objc_method_decl (TREE_CODE (*node
)))
605 TREE_THIS_VOLATILE (*node
) = 1;
606 else if (TREE_CODE (type
) == POINTER_TYPE
607 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
609 = (build_qualified_type
611 (build_type_variant (TREE_TYPE (type
),
612 TYPE_READONLY (TREE_TYPE (type
)), 1)),
616 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
617 *no_add_attrs
= true;
623 /* Handle a "hot" and attribute; arguments as in
624 struct attribute_spec.handler. */
627 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
628 int ARG_UNUSED (flags
), bool *no_add_attrs
)
630 if (TREE_CODE (*node
) == FUNCTION_DECL
631 || TREE_CODE (*node
) == LABEL_DECL
)
633 /* Attribute hot processing is done later with lookup_attribute. */
637 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
638 *no_add_attrs
= true;
644 /* Handle a "cold" and attribute; arguments as in
645 struct attribute_spec.handler. */
648 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
649 int ARG_UNUSED (flags
), bool *no_add_attrs
)
651 if (TREE_CODE (*node
) == FUNCTION_DECL
652 || TREE_CODE (*node
) == LABEL_DECL
)
654 /* Attribute cold processing is done later with lookup_attribute. */
658 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
659 *no_add_attrs
= true;
665 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
668 add_no_sanitize_value (tree node
, unsigned int flags
)
670 tree attr
= lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node
));
673 unsigned int old_value
= tree_to_uhwi (TREE_VALUE (attr
));
676 if (flags
== old_value
)
679 TREE_VALUE (attr
) = build_int_cst (unsigned_type_node
, flags
);
682 DECL_ATTRIBUTES (node
)
683 = tree_cons (get_identifier ("no_sanitize"),
684 build_int_cst (unsigned_type_node
, flags
),
685 DECL_ATTRIBUTES (node
));
688 /* Handle a "no_sanitize" attribute; arguments as in
689 struct attribute_spec.handler. */
692 handle_no_sanitize_attribute (tree
*node
, tree name
, tree args
, int,
695 *no_add_attrs
= true;
696 tree id
= TREE_VALUE (args
);
697 if (TREE_CODE (*node
) != FUNCTION_DECL
)
699 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
703 if (TREE_CODE (id
) != STRING_CST
)
705 error ("no_sanitize argument not a string");
709 char *string
= ASTRDUP (TREE_STRING_POINTER (id
));
710 unsigned int flags
= parse_no_sanitize_attribute (string
);
712 add_no_sanitize_value (*node
, flags
);
717 /* Handle a "no_sanitize_address" attribute; arguments as in
718 struct attribute_spec.handler. */
721 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
724 *no_add_attrs
= true;
725 if (TREE_CODE (*node
) != FUNCTION_DECL
)
726 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
728 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
733 /* Handle a "no_sanitize_thread" attribute; arguments as in
734 struct attribute_spec.handler. */
737 handle_no_sanitize_thread_attribute (tree
*node
, tree name
, tree
, int,
740 *no_add_attrs
= true;
741 if (TREE_CODE (*node
) != FUNCTION_DECL
)
742 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
744 add_no_sanitize_value (*node
, SANITIZE_THREAD
);
750 /* Handle a "no_address_safety_analysis" attribute; arguments as in
751 struct attribute_spec.handler. */
754 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
757 *no_add_attrs
= true;
758 if (TREE_CODE (*node
) != FUNCTION_DECL
)
759 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
761 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
766 /* Handle a "no_sanitize_undefined" attribute; arguments as in
767 struct attribute_spec.handler. */
770 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
773 *no_add_attrs
= true;
774 if (TREE_CODE (*node
) != FUNCTION_DECL
)
775 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
777 add_no_sanitize_value (*node
,
778 SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
783 /* Handle an "asan odr indicator" attribute; arguments as in
784 struct attribute_spec.handler. */
787 handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int, bool *)
792 /* Handle a "stack_protect" attribute; arguments as in
793 struct attribute_spec.handler. */
796 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
799 if (TREE_CODE (*node
) != FUNCTION_DECL
)
801 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
802 *no_add_attrs
= true;
808 /* Handle a "noipa" attribute; arguments as in
809 struct attribute_spec.handler. */
812 handle_noipa_attribute (tree
*node
, tree name
, tree
, int, bool *no_add_attrs
)
814 if (TREE_CODE (*node
) != FUNCTION_DECL
)
816 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
817 *no_add_attrs
= true;
823 /* Handle a "noinline" attribute; arguments as in
824 struct attribute_spec.handler. */
827 handle_noinline_attribute (tree
*node
, tree name
,
828 tree
ARG_UNUSED (args
),
829 int ARG_UNUSED (flags
), bool *no_add_attrs
)
831 if (TREE_CODE (*node
) == FUNCTION_DECL
)
833 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
835 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
836 "with attribute %qs", name
, "always_inline");
837 *no_add_attrs
= true;
840 DECL_UNINLINABLE (*node
) = 1;
844 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
845 *no_add_attrs
= true;
851 /* Handle a "noclone" attribute; arguments as in
852 struct attribute_spec.handler. */
855 handle_noclone_attribute (tree
*node
, tree name
,
856 tree
ARG_UNUSED (args
),
857 int ARG_UNUSED (flags
), bool *no_add_attrs
)
859 if (TREE_CODE (*node
) != FUNCTION_DECL
)
861 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
862 *no_add_attrs
= true;
868 /* Handle a "nocf_check" attribute; arguments as in
869 struct attribute_spec.handler. */
872 handle_nocf_check_attribute (tree
*node
, tree name
,
873 tree
ARG_UNUSED (args
),
874 int ARG_UNUSED (flags
), bool *no_add_attrs
)
876 if (TREE_CODE (*node
) != FUNCTION_TYPE
877 && TREE_CODE (*node
) != METHOD_TYPE
)
879 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
880 *no_add_attrs
= true;
882 else if (!(flag_cf_protection
& CF_BRANCH
))
884 warning (OPT_Wattributes
, "%qE attribute ignored. Use "
885 "-fcf-protection option to enable it", name
);
886 *no_add_attrs
= true;
892 /* Handle a "no_icf" attribute; arguments as in
893 struct attribute_spec.handler. */
896 handle_noicf_attribute (tree
*node
, tree name
,
897 tree
ARG_UNUSED (args
),
898 int ARG_UNUSED (flags
), bool *no_add_attrs
)
900 if (TREE_CODE (*node
) != FUNCTION_DECL
)
902 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
903 *no_add_attrs
= true;
910 /* Handle a "always_inline" attribute; arguments as in
911 struct attribute_spec.handler. */
914 handle_always_inline_attribute (tree
*node
, tree name
,
915 tree
ARG_UNUSED (args
),
916 int ARG_UNUSED (flags
),
919 if (TREE_CODE (*node
) == FUNCTION_DECL
)
921 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
923 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
924 "with %qs attribute", name
, "noinline");
925 *no_add_attrs
= true;
927 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
929 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
930 "with %qs attribute", name
, "target_clones");
931 *no_add_attrs
= true;
934 /* Set the attribute and mark it for disregarding inline
936 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
940 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
941 *no_add_attrs
= true;
947 /* Handle a "gnu_inline" attribute; arguments as in
948 struct attribute_spec.handler. */
951 handle_gnu_inline_attribute (tree
*node
, tree name
,
952 tree
ARG_UNUSED (args
),
953 int ARG_UNUSED (flags
),
956 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
958 /* Do nothing else, just set the attribute. We'll get at
959 it later with lookup_attribute. */
963 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
964 *no_add_attrs
= true;
970 /* Handle a "leaf" attribute; arguments as in
971 struct attribute_spec.handler. */
974 handle_leaf_attribute (tree
*node
, tree name
,
975 tree
ARG_UNUSED (args
),
976 int ARG_UNUSED (flags
), bool *no_add_attrs
)
978 if (TREE_CODE (*node
) != FUNCTION_DECL
)
980 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
981 *no_add_attrs
= true;
983 if (!TREE_PUBLIC (*node
))
985 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
987 *no_add_attrs
= true;
993 /* Handle an "artificial" attribute; arguments as in
994 struct attribute_spec.handler. */
997 handle_artificial_attribute (tree
*node
, tree name
,
998 tree
ARG_UNUSED (args
),
999 int ARG_UNUSED (flags
),
1002 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
1004 /* Do nothing else, just set the attribute. We'll get at
1005 it later with lookup_attribute. */
1009 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1010 *no_add_attrs
= true;
1016 /* Handle a "flatten" attribute; arguments as in
1017 struct attribute_spec.handler. */
1020 handle_flatten_attribute (tree
*node
, tree name
,
1021 tree args ATTRIBUTE_UNUSED
,
1022 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1024 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1025 /* Do nothing else, just set the attribute. We'll get at
1026 it later with lookup_attribute. */
1030 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1031 *no_add_attrs
= true;
1037 /* Handle a "warning" or "error" attribute; arguments as in
1038 struct attribute_spec.handler. */
1041 handle_error_attribute (tree
*node
, tree name
, tree args
,
1042 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1044 if (TREE_CODE (*node
) == FUNCTION_DECL
1045 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
1046 /* Do nothing else, just set the attribute. We'll get at
1047 it later with lookup_attribute. */
1051 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1052 *no_add_attrs
= true;
1058 /* Handle a "used" attribute; arguments as in
1059 struct attribute_spec.handler. */
1062 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
1063 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1067 if (TREE_CODE (node
) == FUNCTION_DECL
1068 || (VAR_P (node
) && TREE_STATIC (node
))
1069 || (TREE_CODE (node
) == TYPE_DECL
))
1071 TREE_USED (node
) = 1;
1072 DECL_PRESERVE_P (node
) = 1;
1074 DECL_READ_P (node
) = 1;
1078 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1079 *no_add_attrs
= true;
1085 /* Handle a "unused" attribute; arguments as in
1086 struct attribute_spec.handler. */
1089 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1090 int flags
, bool *no_add_attrs
)
1096 if (TREE_CODE (decl
) == PARM_DECL
1097 || VAR_OR_FUNCTION_DECL_P (decl
)
1098 || TREE_CODE (decl
) == LABEL_DECL
1099 || TREE_CODE (decl
) == CONST_DECL
1100 || TREE_CODE (decl
) == TYPE_DECL
)
1102 TREE_USED (decl
) = 1;
1103 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
1104 DECL_READ_P (decl
) = 1;
1108 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1109 *no_add_attrs
= true;
1114 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1115 *node
= build_variant_type_copy (*node
);
1116 TREE_USED (*node
) = 1;
1122 /* Handle a "externally_visible" attribute; arguments as in
1123 struct attribute_spec.handler. */
1126 handle_externally_visible_attribute (tree
*pnode
, tree name
,
1127 tree
ARG_UNUSED (args
),
1128 int ARG_UNUSED (flags
),
1133 if (VAR_OR_FUNCTION_DECL_P (node
))
1135 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
1136 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
1138 warning (OPT_Wattributes
,
1139 "%qE attribute have effect only on public objects", name
);
1140 *no_add_attrs
= true;
1145 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1146 *no_add_attrs
= true;
1152 /* Handle the "no_reorder" attribute. Arguments as in
1153 struct attribute_spec.handler. */
1156 handle_no_reorder_attribute (tree
*pnode
,
1164 if (!VAR_OR_FUNCTION_DECL_P (node
)
1165 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
1167 warning (OPT_Wattributes
,
1168 "%qE attribute only affects top level objects",
1170 *no_add_attrs
= true;
1176 /* Handle a "const" attribute; arguments as in
1177 struct attribute_spec.handler. */
1180 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1181 int flags
, bool *no_add_attrs
)
1183 tree type
= TREE_TYPE (*node
);
1185 /* See FIXME comment on noreturn in c_common_attribute_table. */
1186 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1187 TREE_READONLY (*node
) = 1;
1188 else if (TREE_CODE (type
) == POINTER_TYPE
1189 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1191 = (build_qualified_type
1193 (build_type_variant (TREE_TYPE (type
), 1,
1194 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
1195 TYPE_QUALS (type
)));
1198 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1199 *no_add_attrs
= true;
1202 /* void __builtin_unreachable(void) is const. Accept other such
1203 built-ins but warn on user-defined functions that return void. */
1204 if (!(flags
& ATTR_FLAG_BUILT_IN
)
1205 && TREE_CODE (*node
) == FUNCTION_DECL
1206 && VOID_TYPE_P (TREE_TYPE (type
)))
1207 warning (OPT_Wattributes
, "%qE attribute on function "
1208 "returning %<void%>", name
);
1213 /* Handle a "scalar_storage_order" attribute; arguments as in
1214 struct attribute_spec.handler. */
1217 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
1218 int flags
, bool *no_add_attrs
)
1220 tree id
= TREE_VALUE (args
);
1223 if (TREE_CODE (*node
) == TYPE_DECL
1224 && ! (flags
& ATTR_FLAG_CXX11
))
1225 node
= &TREE_TYPE (*node
);
1228 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
1230 error ("scalar_storage_order is not supported because endianness "
1235 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
1237 bool reverse
= false;
1239 if (TREE_CODE (id
) == STRING_CST
1240 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1241 reverse
= !BYTES_BIG_ENDIAN
;
1242 else if (TREE_CODE (id
) == STRING_CST
1243 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1244 reverse
= BYTES_BIG_ENDIAN
;
1247 error ("scalar_storage_order argument must be one of \"big-endian\""
1248 " or \"little-endian\"");
1252 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1255 /* A type variant isn't good enough, since we don't want a cast
1256 to such a type to be removed as a no-op. */
1257 *node
= type
= build_duplicate_type (type
);
1260 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1264 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1265 *no_add_attrs
= true;
1269 /* Handle a "transparent_union" attribute; arguments as in
1270 struct attribute_spec.handler. */
1273 handle_transparent_union_attribute (tree
*node
, tree name
,
1274 tree
ARG_UNUSED (args
), int flags
,
1279 *no_add_attrs
= true;
1281 if (TREE_CODE (*node
) == TYPE_DECL
1282 && ! (flags
& ATTR_FLAG_CXX11
))
1283 node
= &TREE_TYPE (*node
);
1286 if (TREE_CODE (type
) == UNION_TYPE
)
1288 /* Make sure that the first field will work for a transparent union.
1289 If the type isn't complete yet, leave the check to the code in
1291 if (TYPE_SIZE (type
))
1293 tree first
= first_field (type
);
1294 if (first
== NULL_TREE
1295 || DECL_ARTIFICIAL (first
)
1296 || TYPE_MODE (type
) != DECL_MODE (first
))
1300 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1302 /* If the type isn't complete yet, setting the flag
1303 on a variant wouldn't ever be checked. */
1304 if (!TYPE_SIZE (type
))
1307 /* build_duplicate_type doesn't work for C++. */
1308 if (c_dialect_cxx ())
1311 /* A type variant isn't good enough, since we don't want a cast
1312 to such a type to be removed as a no-op. */
1313 *node
= type
= build_duplicate_type (type
);
1316 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1317 TYPE_TRANSPARENT_AGGR (t
) = 1;
1322 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1326 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1327 get the requested priority for a constructor or destructor,
1328 possibly issuing diagnostics for invalid or reserved
1331 static priority_type
1332 get_priority (tree args
, bool is_destructor
)
1338 return DEFAULT_INIT_PRIORITY
;
1340 if (!SUPPORTS_INIT_PRIORITY
)
1343 error ("destructor priorities are not supported");
1345 error ("constructor priorities are not supported");
1346 return DEFAULT_INIT_PRIORITY
;
1349 arg
= TREE_VALUE (args
);
1350 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1352 if (arg
== error_mark_node
)
1353 return DEFAULT_INIT_PRIORITY
;
1354 arg
= default_conversion (arg
);
1355 if (!tree_fits_shwi_p (arg
)
1356 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1359 pri
= tree_to_shwi (arg
);
1360 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1363 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1367 "destructor priorities from 0 to %d are reserved "
1368 "for the implementation",
1369 MAX_RESERVED_INIT_PRIORITY
);
1372 "constructor priorities from 0 to %d are reserved "
1373 "for the implementation",
1374 MAX_RESERVED_INIT_PRIORITY
);
1380 error ("destructor priorities must be integers from 0 to %d inclusive",
1383 error ("constructor priorities must be integers from 0 to %d inclusive",
1385 return DEFAULT_INIT_PRIORITY
;
1388 /* Handle a "constructor" attribute; arguments as in
1389 struct attribute_spec.handler. */
1392 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1393 int ARG_UNUSED (flags
),
1397 tree type
= TREE_TYPE (decl
);
1399 if (TREE_CODE (decl
) == FUNCTION_DECL
1400 && TREE_CODE (type
) == FUNCTION_TYPE
1401 && decl_function_context (decl
) == 0)
1403 priority_type priority
;
1404 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1405 priority
= get_priority (args
, /*is_destructor=*/false);
1406 SET_DECL_INIT_PRIORITY (decl
, priority
);
1407 TREE_USED (decl
) = 1;
1411 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1412 *no_add_attrs
= true;
1418 /* Handle a "destructor" attribute; arguments as in
1419 struct attribute_spec.handler. */
1422 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1423 int ARG_UNUSED (flags
),
1427 tree type
= TREE_TYPE (decl
);
1429 if (TREE_CODE (decl
) == FUNCTION_DECL
1430 && TREE_CODE (type
) == FUNCTION_TYPE
1431 && decl_function_context (decl
) == 0)
1433 priority_type priority
;
1434 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1435 priority
= get_priority (args
, /*is_destructor=*/true);
1436 SET_DECL_FINI_PRIORITY (decl
, priority
);
1437 TREE_USED (decl
) = 1;
1441 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1442 *no_add_attrs
= true;
1448 /* Nonzero if the mode is a valid vector mode for this architecture.
1449 This returns nonzero even if there is no hardware support for the
1450 vector mode, but we can emulate with narrower modes. */
1453 vector_mode_valid_p (machine_mode mode
)
1455 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1457 /* Doh! What's going on? */
1458 if (mclass
!= MODE_VECTOR_INT
1459 && mclass
!= MODE_VECTOR_FLOAT
1460 && mclass
!= MODE_VECTOR_FRACT
1461 && mclass
!= MODE_VECTOR_UFRACT
1462 && mclass
!= MODE_VECTOR_ACCUM
1463 && mclass
!= MODE_VECTOR_UACCUM
)
1466 /* Hardware support. Woo hoo! */
1467 if (targetm
.vector_mode_supported_p (mode
))
1470 /* We should probably return 1 if requesting V4DI and we have no DI,
1471 but we have V2DI, but this is probably very unlikely. */
1473 /* If we have support for the inner mode, we can safely emulate it.
1474 We may not have V2DI, but me can emulate with a pair of DIs. */
1475 return targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1479 /* Handle a "mode" attribute; arguments as in
1480 struct attribute_spec.handler. */
1483 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1484 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1487 tree ident
= TREE_VALUE (args
);
1489 *no_add_attrs
= true;
1491 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1492 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1496 const char *p
= IDENTIFIER_POINTER (ident
);
1497 int len
= strlen (p
);
1498 machine_mode mode
= VOIDmode
;
1502 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1503 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1505 char *newp
= (char *) alloca (len
- 1);
1507 strcpy (newp
, &p
[2]);
1508 newp
[len
- 4] = '\0';
1512 /* Change this type to have a type with the specified mode.
1513 First check for the special modes. */
1514 if (!strcmp (p
, "byte"))
1516 else if (!strcmp (p
, "word"))
1518 else if (!strcmp (p
, "pointer"))
1520 else if (!strcmp (p
, "libgcc_cmp_return"))
1521 mode
= targetm
.libgcc_cmp_return_mode ();
1522 else if (!strcmp (p
, "libgcc_shift_count"))
1523 mode
= targetm
.libgcc_shift_count_mode ();
1524 else if (!strcmp (p
, "unwind_word"))
1525 mode
= targetm
.unwind_word_mode ();
1527 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1528 if (!strcmp (p
, GET_MODE_NAME (j
)))
1530 mode
= (machine_mode
) j
;
1534 if (mode
== VOIDmode
)
1536 error ("unknown machine mode %qE", ident
);
1541 switch (GET_MODE_CLASS (mode
))
1544 case MODE_PARTIAL_INT
:
1546 case MODE_DECIMAL_FLOAT
:
1552 = targetm
.scalar_mode_supported_p (as_a
<scalar_mode
> (mode
));
1555 case MODE_COMPLEX_INT
:
1556 case MODE_COMPLEX_FLOAT
:
1557 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1560 case MODE_VECTOR_INT
:
1561 case MODE_VECTOR_FLOAT
:
1562 case MODE_VECTOR_FRACT
:
1563 case MODE_VECTOR_UFRACT
:
1564 case MODE_VECTOR_ACCUM
:
1565 case MODE_VECTOR_UACCUM
:
1566 warning (OPT_Wattributes
, "specifying vector types with "
1567 "__attribute__ ((mode)) is deprecated");
1568 warning (OPT_Wattributes
,
1569 "use __attribute__ ((vector_size)) instead");
1570 valid_mode
= vector_mode_valid_p (mode
);
1578 error ("unable to emulate %qs", p
);
1582 if (POINTER_TYPE_P (type
))
1584 scalar_int_mode addr_mode
;
1585 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1586 tree (*fn
)(tree
, machine_mode
, bool);
1588 if (!is_a
<scalar_int_mode
> (mode
, &addr_mode
)
1589 || !targetm
.addr_space
.valid_pointer_mode (addr_mode
, as
))
1591 error ("invalid pointer mode %qs", p
);
1595 if (TREE_CODE (type
) == POINTER_TYPE
)
1596 fn
= build_pointer_type_for_mode
;
1598 fn
= build_reference_type_for_mode
;
1599 typefm
= fn (TREE_TYPE (type
), addr_mode
, false);
1603 /* For fixed-point modes, we need to test if the signness of type
1604 and the machine mode are consistent. */
1605 if (ALL_FIXED_POINT_MODE_P (mode
)
1606 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1608 error ("signedness of type and machine mode %qs don%'t match", p
);
1611 /* For fixed-point modes, we need to pass saturating info. */
1612 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1613 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1614 : TYPE_UNSIGNED (type
));
1617 if (typefm
== NULL_TREE
)
1619 error ("no data type for mode %qs", p
);
1622 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1624 /* For enumeral types, copy the precision from the integer
1625 type returned above. If not an INTEGER_TYPE, we can't use
1626 this mode for this type. */
1627 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1629 error ("cannot use mode %qs for enumeral types", p
);
1633 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1635 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1640 /* We cannot build a type variant, as there's code that assumes
1641 that TYPE_MAIN_VARIANT has the same mode. This includes the
1642 debug generators. Instead, create a subrange type. This
1643 results in all of the enumeral values being emitted only once
1644 in the original, and the subtype gets them by reference. */
1645 if (TYPE_UNSIGNED (type
))
1646 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1648 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1649 TREE_TYPE (typefm
) = type
;
1652 else if (VECTOR_MODE_P (mode
)
1653 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1654 : TREE_CODE (type
) != TREE_CODE (typefm
))
1656 error ("mode %qs applied to inappropriate type", p
);
1660 *node
= build_qualified_type (typefm
, TYPE_QUALS (type
));
1666 /* Handle a "section" attribute; arguments as in
1667 struct attribute_spec.handler. */
1670 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1671 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1675 if (!targetm_common
.have_named_sections
)
1677 error_at (DECL_SOURCE_LOCATION (*node
),
1678 "section attributes are not supported for this target");
1682 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1684 error ("section attribute not allowed for %q+D", *node
);
1688 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1690 error ("section attribute argument not a string constant");
1695 && current_function_decl
!= NULL_TREE
1696 && !TREE_STATIC (decl
))
1698 error_at (DECL_SOURCE_LOCATION (decl
),
1699 "section attribute cannot be specified for local variables");
1703 /* The decl may have already been given a section attribute
1704 from a previous declaration. Ensure they match. */
1705 if (DECL_SECTION_NAME (decl
) != NULL
1706 && strcmp (DECL_SECTION_NAME (decl
),
1707 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1709 error ("section of %q+D conflicts with previous declaration", *node
);
1714 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1715 && DECL_THREAD_LOCAL_P (decl
))
1717 error ("section of %q+D cannot be overridden", *node
);
1721 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1725 *no_add_attrs
= true;
1729 /* If in c++-11, check if the c++-11 alignment constraint with respect
1730 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1731 c++-11 mode, does nothing.
1735 [* if the constant expression evaluates to a fundamental alignment,
1736 the alignment requirement of the declared entity shall be the
1737 specified fundamental alignment.
1739 * if the constant expression evaluates to an extended alignment
1740 and the implementation supports that alignment in the context
1741 of the declaration, the alignment of the declared entity shall
1744 * if the constant expression evaluates to an extended alignment
1745 and the implementation does not support that alignment in the
1746 context of the declaration, the program is ill-formed]. */
1749 check_cxx_fundamental_alignment_constraints (tree node
,
1753 bool alignment_too_large_p
= false;
1754 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1755 unsigned max_align
= 0;
1757 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1758 || (node
== NULL_TREE
|| node
== error_mark_node
))
1761 if (cxx_fundamental_alignment_p (requested_alignment
))
1766 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1767 /* For file scope variables and static members, the target supports
1768 alignments that are at most MAX_OFILE_ALIGNMENT. */
1769 max_align
= MAX_OFILE_ALIGNMENT
;
1771 /* For stack variables, the target supports at most
1772 MAX_STACK_ALIGNMENT. */
1773 max_align
= MAX_STACK_ALIGNMENT
;
1774 if (requested_alignment
> max_align
)
1775 alignment_too_large_p
= true;
1777 /* Let's be liberal for types and fields; don't limit their alignment any
1778 more than check_user_alignment already did. */
1780 if (alignment_too_large_p
)
1781 pedwarn (input_location
, OPT_Wattributes
,
1782 "requested alignment %d is larger than %d",
1783 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1785 return !alignment_too_large_p
;
1788 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1789 handle_aligned_attribute. */
1792 common_handle_aligned_attribute (tree
*node
, tree name
, tree args
, int flags
,
1794 bool warn_if_not_aligned_p
)
1796 tree decl
= NULL_TREE
;
1798 bool is_type
= false;
1801 /* The last (already pushed) declaration with all validated attributes
1802 merged in or the current about-to-be-pushed one if one hasn't been
1804 tree last_decl
= node
[1] ? node
[1] : *node
;
1808 align_expr
= TREE_VALUE (args
);
1809 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1810 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1811 align_expr
= default_conversion (align_expr
);
1814 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1819 type
= &TREE_TYPE (decl
);
1820 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1822 else if (TYPE_P (*node
))
1823 type
= node
, is_type
= true;
1825 /* Log2 of specified alignment. */
1826 int pow2align
= check_user_alignment (align_expr
, true);
1828 /* The alignment in bits corresponding to the specified alignment. */
1829 unsigned bitalign
= (1U << pow2align
) * BITS_PER_UNIT
;
1831 /* The alignment of the current declaration and that of the last
1832 pushed declaration, determined on demand below. */
1833 unsigned curalign
= 0;
1834 unsigned lastalign
= 0;
1837 || !check_cxx_fundamental_alignment_constraints (*node
, pow2align
, flags
))
1838 *no_add_attrs
= true;
1841 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1842 /* OK, modify the type in place. */;
1843 /* If we have a TYPE_DECL, then copy the type, so that we
1844 don't accidentally modify a builtin type. See pushdecl. */
1845 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1846 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1848 tree tt
= TREE_TYPE (decl
);
1849 *type
= build_variant_type_copy (*type
);
1850 DECL_ORIGINAL_TYPE (decl
) = tt
;
1851 TYPE_NAME (*type
) = decl
;
1852 TREE_USED (*type
) = TREE_USED (decl
);
1853 TREE_TYPE (decl
) = *type
;
1856 *type
= build_variant_type_copy (*type
);
1858 if (warn_if_not_aligned_p
)
1860 SET_TYPE_WARN_IF_NOT_ALIGN (*type
, bitalign
);
1861 warn_if_not_aligned_p
= false;
1865 SET_TYPE_ALIGN (*type
, bitalign
);
1866 TYPE_USER_ALIGN (*type
) = 1;
1869 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1870 && TREE_CODE (decl
) != FIELD_DECL
)
1872 error ("alignment may not be specified for %q+D", decl
);
1873 *no_add_attrs
= true;
1875 else if (TREE_CODE (decl
) == FUNCTION_DECL
1876 && ((curalign
= DECL_ALIGN (decl
)) > bitalign
1877 || ((lastalign
= DECL_ALIGN (last_decl
)) > bitalign
)))
1879 /* Either a prior attribute on the same declaration or one
1880 on a prior declaration of the same function specifies
1881 stricter alignment than this attribute. */
1882 bool note
= lastalign
!= 0;
1884 curalign
= lastalign
;
1886 curalign
/= BITS_PER_UNIT
;
1887 bitalign
/= BITS_PER_UNIT
;
1889 if (DECL_USER_ALIGN (decl
) || DECL_USER_ALIGN (last_decl
))
1890 warning (OPT_Wattributes
,
1891 "ignoring attribute %<%E (%u)%> because it conflicts with "
1892 "attribute %<%E (%u)%>", name
, bitalign
, name
, curalign
);
1894 error ("alignment for %q+D must be at least %d", decl
, curalign
);
1897 inform (DECL_SOURCE_LOCATION (last_decl
), "previous declaration here");
1899 *no_add_attrs
= true;
1901 else if (DECL_USER_ALIGN (decl
)
1902 && DECL_ALIGN (decl
) > bitalign
)
1903 /* C++-11 [dcl.align/4]:
1905 When multiple alignment-specifiers are specified for an
1906 entity, the alignment requirement shall be set to the
1907 strictest specified alignment.
1909 This formally comes from the c++11 specification but we are
1910 doing it for the GNU attribute syntax as well. */
1911 *no_add_attrs
= true;
1912 else if (!warn_if_not_aligned_p
1913 && TREE_CODE (decl
) == FUNCTION_DECL
1914 && DECL_ALIGN (decl
) > bitalign
)
1916 /* Don't warn function alignment here if warn_if_not_aligned_p is
1917 true. It will be warned later. */
1918 if (DECL_USER_ALIGN (decl
))
1919 error ("alignment for %q+D was previously specified as %d "
1920 "and may not be decreased", decl
,
1921 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1923 error ("alignment for %q+D must be at least %d", decl
,
1924 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1925 *no_add_attrs
= true;
1929 if (warn_if_not_aligned_p
)
1931 if (TREE_CODE (decl
) == FIELD_DECL
&& !DECL_C_BIT_FIELD (decl
))
1933 SET_DECL_WARN_IF_NOT_ALIGN (decl
, bitalign
);
1934 warn_if_not_aligned_p
= false;
1939 SET_DECL_ALIGN (decl
, bitalign
);
1940 DECL_USER_ALIGN (decl
) = 1;
1944 if (warn_if_not_aligned_p
)
1946 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1948 *no_add_attrs
= true;
1954 /* Handle a "aligned" attribute; arguments as in
1955 struct attribute_spec.handler. */
1958 handle_aligned_attribute (tree
*node
, tree name
, tree args
,
1959 int flags
, bool *no_add_attrs
)
1961 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1962 no_add_attrs
, false);
1965 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1966 struct attribute_spec.handler. */
1969 handle_warn_if_not_aligned_attribute (tree
*node
, tree name
,
1970 tree args
, int flags
,
1973 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1974 no_add_attrs
, true);
1977 /* Handle a "weak" attribute; arguments as in
1978 struct attribute_spec.handler. */
1981 handle_weak_attribute (tree
*node
, tree name
,
1982 tree
ARG_UNUSED (args
),
1983 int ARG_UNUSED (flags
),
1984 bool * ARG_UNUSED (no_add_attrs
))
1986 if (TREE_CODE (*node
) == FUNCTION_DECL
1987 && DECL_DECLARED_INLINE_P (*node
))
1989 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1990 *no_add_attrs
= true;
1992 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1994 error ("indirect function %q+D cannot be declared weak", *node
);
1995 *no_add_attrs
= true;
1998 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1999 declare_weak (*node
);
2001 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2006 /* Handle a "noplt" attribute; arguments as in
2007 struct attribute_spec.handler. */
2010 handle_noplt_attribute (tree
*node
, tree name
,
2011 tree
ARG_UNUSED (args
),
2012 int ARG_UNUSED (flags
),
2013 bool * ARG_UNUSED (no_add_attrs
))
2015 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2017 warning (OPT_Wattributes
,
2018 "%qE attribute is only applicable on functions", name
);
2019 *no_add_attrs
= true;
2025 /* Handle an "alias" or "ifunc" attribute; arguments as in
2026 struct attribute_spec.handler, except that IS_ALIAS tells us
2027 whether this is an alias as opposed to ifunc attribute. */
2030 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
2035 if (TREE_CODE (decl
) != FUNCTION_DECL
2036 && (!is_alias
|| !VAR_P (decl
)))
2038 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2039 *no_add_attrs
= true;
2041 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
2042 || (TREE_CODE (decl
) != FUNCTION_DECL
2043 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
2044 /* A static variable declaration is always a tentative definition,
2045 but the alias is a non-tentative definition which overrides. */
2046 || (TREE_CODE (decl
) != FUNCTION_DECL
2047 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
2049 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
2050 *no_add_attrs
= true;
2054 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2055 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
2057 error ("weak %q+D cannot be defined %qE", decl
, name
);
2058 *no_add_attrs
= true;
2062 /* Note that the very first time we process a nested declaration,
2063 decl_function_context will not be set. Indeed, *would* never
2064 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2065 we do below. After such frobbery, pushdecl would set the context.
2066 In any case, this is never what we want. */
2067 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
2071 id
= TREE_VALUE (args
);
2072 if (TREE_CODE (id
) != STRING_CST
)
2074 error ("attribute %qE argument not a string", name
);
2075 *no_add_attrs
= true;
2078 id
= get_identifier (TREE_STRING_POINTER (id
));
2079 /* This counts as a use of the object pointed to. */
2082 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2083 DECL_INITIAL (decl
) = error_mark_node
;
2085 TREE_STATIC (decl
) = 1;
2089 /* ifuncs are also aliases, so set that attribute too. */
2090 DECL_ATTRIBUTES (decl
)
2091 = tree_cons (get_identifier ("alias"), args
,
2092 DECL_ATTRIBUTES (decl
));
2093 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("ifunc"),
2094 NULL
, DECL_ATTRIBUTES (decl
));
2099 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2100 *no_add_attrs
= true;
2103 if (decl_in_symtab_p (*node
))
2105 struct symtab_node
*n
= symtab_node::get (decl
);
2106 if (n
&& n
->refuse_visibility_changes
)
2109 error ("%+qD declared alias after being used", decl
);
2111 error ("%+qD declared ifunc after being used", decl
);
2119 /* Handle an "alias" or "ifunc" attribute; arguments as in
2120 struct attribute_spec.handler. */
2123 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
2124 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2126 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
2129 /* Handle an "alias" or "ifunc" attribute; arguments as in
2130 struct attribute_spec.handler. */
2133 handle_alias_attribute (tree
*node
, tree name
, tree args
,
2134 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2136 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
2139 /* Handle a "weakref" attribute; arguments as in struct
2140 attribute_spec.handler. */
2143 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2144 int flags
, bool *no_add_attrs
)
2146 tree attr
= NULL_TREE
;
2148 /* We must ignore the attribute when it is associated with
2149 local-scoped decls, since attribute alias is ignored and many
2150 such symbols do not even have a DECL_WEAK field. */
2151 if (decl_function_context (*node
)
2152 || current_function_decl
2153 || !VAR_OR_FUNCTION_DECL_P (*node
))
2155 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2156 *no_add_attrs
= true;
2160 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
2162 error ("indirect function %q+D cannot be declared weakref", *node
);
2163 *no_add_attrs
= true;
2167 /* The idea here is that `weakref("name")' mutates into `weakref,
2168 alias("name")', and weakref without arguments, in turn,
2169 implicitly adds weak. */
2173 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
2174 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
2176 *no_add_attrs
= true;
2178 decl_attributes (node
, attr
, flags
);
2182 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
2183 error_at (DECL_SOURCE_LOCATION (*node
),
2184 "weakref attribute must appear before alias attribute");
2186 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2187 and that isn't supported; and because it wants to add it to
2188 the list of weak decls, which isn't helpful. */
2189 DECL_WEAK (*node
) = 1;
2192 if (decl_in_symtab_p (*node
))
2194 struct symtab_node
*n
= symtab_node::get (*node
);
2195 if (n
&& n
->refuse_visibility_changes
)
2196 error ("%+qD declared weakref after being used", *node
);
2202 /* Handle an "visibility" attribute; arguments as in
2203 struct attribute_spec.handler. */
2206 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
2207 int ARG_UNUSED (flags
),
2208 bool *ARG_UNUSED (no_add_attrs
))
2211 tree id
= TREE_VALUE (args
);
2212 enum symbol_visibility vis
;
2216 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
2218 else if (!RECORD_OR_UNION_TYPE_P (*node
))
2220 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
2224 else if (TYPE_FIELDS (*node
))
2226 error ("%qE attribute ignored because %qT is already defined",
2231 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
2233 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2237 if (TREE_CODE (id
) != STRING_CST
)
2239 error ("visibility argument not a string");
2243 /* If this is a type, set the visibility on the type decl. */
2246 decl
= TYPE_NAME (decl
);
2249 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
2251 warning (OPT_Wattributes
, "%qE attribute ignored on types",
2257 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
2258 vis
= VISIBILITY_DEFAULT
;
2259 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
2260 vis
= VISIBILITY_INTERNAL
;
2261 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
2262 vis
= VISIBILITY_HIDDEN
;
2263 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
2264 vis
= VISIBILITY_PROTECTED
;
2267 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2268 vis
= VISIBILITY_DEFAULT
;
2271 if (DECL_VISIBILITY_SPECIFIED (decl
)
2272 && vis
!= DECL_VISIBILITY (decl
))
2274 tree attributes
= (TYPE_P (*node
)
2275 ? TYPE_ATTRIBUTES (*node
)
2276 : DECL_ATTRIBUTES (decl
));
2277 if (lookup_attribute ("visibility", attributes
))
2278 error ("%qD redeclared with different visibility", decl
);
2279 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2280 && lookup_attribute ("dllimport", attributes
))
2281 error ("%qD was declared %qs which implies default visibility",
2283 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2284 && lookup_attribute ("dllexport", attributes
))
2285 error ("%qD was declared %qs which implies default visibility",
2289 DECL_VISIBILITY (decl
) = vis
;
2290 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
2292 /* Go ahead and attach the attribute to the node as well. This is needed
2293 so we can determine whether we have VISIBILITY_DEFAULT because the
2294 visibility was not specified, or because it was explicitly overridden
2295 from the containing scope. */
2300 /* Handle an "tls_model" attribute; arguments as in
2301 struct attribute_spec.handler. */
2304 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
2305 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2309 enum tls_model kind
;
2311 *no_add_attrs
= true;
2313 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
2315 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
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");
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
;
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
);
2342 /* Handle a "no_instrument_function" attribute; arguments as in
2343 struct attribute_spec.handler. */
2346 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2347 tree
ARG_UNUSED (args
),
2348 int ARG_UNUSED (flags
),
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;
2360 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2365 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2366 struct attribute_spec.handler. */
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;
2381 /* Handle a "malloc" attribute; arguments as in
2382 struct attribute_spec.handler. */
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;
2393 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2394 *no_add_attrs
= true;
2400 /* Handle a "alloc_size" attribute; arguments as in
2401 struct attribute_spec.handler. */
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
)
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;
2428 /* Handle a "alloc_align" attribute; arguments as in
2429 struct attribute_spec.handler. */
2432 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
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
)
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;
2453 /* Handle a "assume_aligned" attribute; arguments as in
2454 struct attribute_spec.handler. */
2457 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
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;
2478 /* Handle a "fn spec" attribute; arguments as in
2479 struct attribute_spec.handler. */
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
)
2487 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2488 && !TREE_CHAIN (args
));
2492 /* Handle a "bnd_variable_size" attribute; arguments as in
2493 struct attribute_spec.handler. */
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;
2508 /* Handle a "bnd_legacy" attribute; arguments as in
2509 struct attribute_spec.handler. */
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;
2524 /* Handle a "bnd_instrument" attribute; arguments as in
2525 struct attribute_spec.handler. */
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;
2540 /* Handle a "warn_unused" attribute; arguments as in
2541 struct attribute_spec.handler. */
2544 handle_warn_unused_attribute (tree
*node
, tree name
,
2545 tree args ATTRIBUTE_UNUSED
,
2546 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2549 /* Do nothing else, just set the attribute. We'll get at
2550 it later with lookup_attribute. */
2554 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2555 *no_add_attrs
= true;
2561 /* Handle an "omp declare simd" attribute; arguments as in
2562 struct attribute_spec.handler. */
2565 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2570 /* Handle a "simd" attribute. */
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
;
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;
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
);
2598 error ("only %<inbranch%> and %<notinbranch%> flags are "
2599 "allowed for %<__simd__%> attribute");
2600 *no_add_attrs
= true;
2605 DECL_ATTRIBUTES (*node
)
2606 = tree_cons (t
, build_tree_list (NULL_TREE
, attr
),
2607 DECL_ATTRIBUTES (*node
));
2611 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2612 *no_add_attrs
= true;
2618 /* Handle an "omp declare target" attribute; arguments as in
2619 struct attribute_spec.handler. */
2622 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2627 /* Handle a "returns_twice" attribute; arguments as in
2628 struct attribute_spec.handler. */
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;
2638 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2639 *no_add_attrs
= true;
2645 /* Handle a "no_limit_stack" attribute; arguments as in
2646 struct attribute_spec.handler. */
2649 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2650 tree
ARG_UNUSED (args
),
2651 int ARG_UNUSED (flags
),
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;
2669 DECL_NO_LIMIT_STACK (decl
) = 1;
2674 /* Handle a "pure" attribute; arguments as in
2675 struct attribute_spec.handler. */
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. */
2693 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2694 *no_add_attrs
= true;
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
)
2710 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2712 tree a
= TREE_PURPOSE (attrs
);
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
);
2729 else if (m_seen
== m
)
2730 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2732 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_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
)
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
;
2761 tm_mask_to_attr (int mask
)
2767 str
= "transaction_safe";
2769 case TM_ATTR_CALLABLE
:
2770 str
= "transaction_callable";
2773 str
= "transaction_pure";
2775 case TM_ATTR_IRREVOCABLE
:
2776 str
= "transaction_unsafe";
2778 case TM_ATTR_MAY_CANCEL_OUTER
:
2779 str
= "transaction_may_cancel_outer";
2784 return get_identifier (str
);
2787 /* Return the first TM attribute seen in LIST. */
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)
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. */
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
))
2819 /* Only tm_callable and tm_safe apply to classes. */
2820 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
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
);
2833 *no_add_attrs
= false;
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"),
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
);
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
);
2873 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2880 /* Handle the TM_WRAP attribute; arguments as in
2881 struct attribute_spec.handler. */
2884 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2885 int ARG_UNUSED (flags
), bool *no_add_attrs
)
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
);
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
);
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
);
2913 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2916 error ("%qE argument is not a function", name
);
2923 /* Ignore the given attribute. Used when this attribute may be usefully
2924 overridden by the target, but is not used generically. */
2927 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2928 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2931 *no_add_attrs
= true;
2935 /* Handle a "no vops" attribute; arguments as in
2936 struct attribute_spec.handler. */
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;
2948 /* Handle a "deprecated" attribute; arguments as in
2949 struct attribute_spec.handler. */
2952 handle_deprecated_attribute (tree
*node
, tree name
,
2953 tree args
, int flags
,
2956 tree type
= NULL_TREE
;
2958 tree what
= NULL_TREE
;
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;
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;
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;
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
));
3005 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
3007 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3013 /* Handle a "vector_size" attribute; arguments as in
3014 struct attribute_spec.handler. */
3017 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
3018 int ARG_UNUSED (flags
),
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
);
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
);
3072 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
3074 error ("vector size not an integral multiple of component size");
3080 error ("zero vector size");
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");
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
);
3100 /* Handle the "nonnull" attribute. */
3103 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3104 tree args
, int ARG_UNUSED (flags
),
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
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;
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;
3146 if (prototype_p (type
))
3148 function_args_iterator iter
;
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
)
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;
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;
3183 /* Handle the "nonstring" variable attribute. */
3186 handle_nonstring_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3187 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3190 tree_code code
= TREE_CODE (*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 tree eltype
= TREE_TYPE (type
);
3201 if (eltype
== char_type_node
)
3205 warning (OPT_Wattributes
,
3206 "%qE attribute ignored on objects of type %qT",
3208 *no_add_attrs
= true;
3212 if (code
== FUNCTION_DECL
)
3213 warning (OPT_Wattributes
,
3214 "%qE attribute does not apply to functions", name
);
3215 else if (code
== TYPE_DECL
)
3216 warning (OPT_Wattributes
,
3217 "%qE attribute does not apply to types", name
);
3219 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3221 *no_add_attrs
= true;
3225 /* Handle a "nothrow" attribute; arguments as in
3226 struct attribute_spec.handler. */
3229 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3230 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3232 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3233 TREE_NOTHROW (*node
) = 1;
3234 /* ??? TODO: Support types. */
3237 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3238 *no_add_attrs
= true;
3244 /* Handle a "cleanup" attribute; arguments as in
3245 struct attribute_spec.handler. */
3248 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
3249 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3252 tree cleanup_id
, cleanup_decl
;
3254 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3255 for global destructors in C++. This requires infrastructure that
3256 we don't have generically at the moment. It's also not a feature
3257 we'd be missing too much, since we do have attribute constructor. */
3258 if (!VAR_P (decl
) || TREE_STATIC (decl
))
3260 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3261 *no_add_attrs
= true;
3265 /* Verify that the argument is a function in scope. */
3266 /* ??? We could support pointers to functions here as well, if
3267 that was considered desirable. */
3268 cleanup_id
= TREE_VALUE (args
);
3269 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
3271 error ("cleanup argument not an identifier");
3272 *no_add_attrs
= true;
3275 cleanup_decl
= lookup_name (cleanup_id
);
3276 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
3278 error ("cleanup argument not a function");
3279 *no_add_attrs
= true;
3283 /* That the function has proper type is checked with the
3284 eventual call to build_function_call. */
3289 /* Handle a "warn_unused_result" attribute. No special handling. */
3292 handle_warn_unused_result_attribute (tree
*node
, tree name
,
3293 tree
ARG_UNUSED (args
),
3294 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3296 /* Ignore the attribute for functions not returning any value. */
3297 if (VOID_TYPE_P (TREE_TYPE (*node
)))
3299 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3300 *no_add_attrs
= true;
3306 /* Handle a "sentinel" attribute. */
3309 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
3310 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3312 if (!prototype_p (*node
))
3314 warning (OPT_Wattributes
,
3315 "%qE attribute requires prototypes with named arguments", name
);
3316 *no_add_attrs
= true;
3320 if (!stdarg_p (*node
))
3322 warning (OPT_Wattributes
,
3323 "%qE attribute only applies to variadic functions", name
);
3324 *no_add_attrs
= true;
3330 tree position
= TREE_VALUE (args
);
3331 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
3332 && TREE_CODE (position
) != FUNCTION_DECL
)
3333 position
= default_conversion (position
);
3335 if (TREE_CODE (position
) != INTEGER_CST
3336 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
3338 warning (OPT_Wattributes
,
3339 "requested position is not an integer constant");
3340 *no_add_attrs
= true;
3344 if (tree_int_cst_lt (position
, integer_zero_node
))
3346 warning (OPT_Wattributes
,
3347 "requested position is less than zero");
3348 *no_add_attrs
= true;
3356 /* Handle a "type_generic" attribute. */
3359 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3360 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
3361 bool * ARG_UNUSED (no_add_attrs
))
3363 /* Ensure we have a function type. */
3364 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
3366 /* Ensure we have a variadic function. */
3367 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
3372 /* Handle a "target" attribute. */
3375 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3378 /* Ensure we have a function type. */
3379 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3381 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3382 *no_add_attrs
= true;
3384 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3386 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3387 "with %qs attribute", name
, "target_clones");
3388 *no_add_attrs
= true;
3390 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3392 *no_add_attrs
= true;
3394 /* Check that there's no empty string in values of the attribute. */
3395 for (tree t
= args
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
3397 tree value
= TREE_VALUE (t
);
3398 if (TREE_CODE (value
) == STRING_CST
3399 && TREE_STRING_LENGTH (value
) == 1
3400 && TREE_STRING_POINTER (value
)[0] == '\0')
3402 warning (OPT_Wattributes
, "empty string in attribute %<target%>");
3403 *no_add_attrs
= true;
3410 /* Handle a "target_clones" attribute. */
3413 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3414 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3416 /* Ensure we have a function type. */
3417 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3419 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3421 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3422 "with %qs attribute", name
, "always_inline");
3423 *no_add_attrs
= true;
3425 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3427 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3428 "with %qs attribute", name
, "target");
3429 *no_add_attrs
= true;
3432 /* Do not inline functions with multiple clone targets. */
3433 DECL_UNINLINABLE (*node
) = 1;
3437 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3438 *no_add_attrs
= true;
3443 /* For handling "optimize" attribute. arguments as in
3444 struct attribute_spec.handler. */
3447 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3448 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3450 /* Ensure we have a function type. */
3451 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3453 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3454 *no_add_attrs
= true;
3458 struct cl_optimization cur_opts
;
3459 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3461 /* Save current options. */
3462 cl_optimization_save (&cur_opts
, &global_options
);
3464 /* If we previously had some optimization options, use them as the
3467 cl_optimization_restore (&global_options
,
3468 TREE_OPTIMIZATION (old_opts
));
3470 /* Parse options, and update the vector. */
3471 parse_optimize_options (args
, true);
3472 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3473 = build_optimization_node (&global_options
);
3475 /* Restore current options. */
3476 cl_optimization_restore (&global_options
, &cur_opts
);
3482 /* Handle a "no_split_stack" attribute. */
3485 handle_no_split_stack_attribute (tree
*node
, tree name
,
3486 tree
ARG_UNUSED (args
),
3487 int ARG_UNUSED (flags
),
3492 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3494 error_at (DECL_SOURCE_LOCATION (decl
),
3495 "%qE attribute applies only to functions", name
);
3496 *no_add_attrs
= true;
3498 else if (DECL_INITIAL (decl
))
3500 error_at (DECL_SOURCE_LOCATION (decl
),
3501 "can%'t set %qE attribute after definition", name
);
3502 *no_add_attrs
= true;
3508 /* Handle a "returns_nonnull" attribute; arguments as in
3509 struct attribute_spec.handler. */
3512 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3515 // Even without a prototype we still have a return type we can check.
3516 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3518 error ("returns_nonnull attribute on a function not returning a pointer");
3519 *no_add_attrs
= true;
3524 /* Handle a "designated_init" attribute; arguments as in
3525 struct attribute_spec.handler. */
3528 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3531 if (TREE_CODE (*node
) != RECORD_TYPE
)
3533 error ("%qE attribute is only valid on %<struct%> type", name
);
3534 *no_add_attrs
= true;
3540 /* Handle a "fallthrough" attribute; arguments as in struct
3541 attribute_spec.handler. */
3544 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3547 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3548 *no_add_attrs
= true;
3553 handle_patchable_function_entry_attribute (tree
*, tree
, tree
, int, bool *)
3555 /* Nothing to be done here. */