1 /* C-family attributes handling.
2 Copyright (C) 1992-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
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,
249 affects_type_identity, handler, exclude } */
250 { "packed", 0, 0, false, false, false, false,
251 handle_packed_attribute
,
252 attr_aligned_exclusions
},
253 { "nocommon", 0, 0, true, false, false, false,
254 handle_nocommon_attribute
,
255 attr_common_exclusions
},
256 { "common", 0, 0, true, false, false, false,
257 handle_common_attribute
,
258 attr_common_exclusions
},
259 /* FIXME: logically, noreturn attributes should be listed as
260 "false, true, true" and apply to function types. But implementing this
261 would require all the places in the compiler that use TREE_THIS_VOLATILE
262 on a decl to identify non-returning functions to be located and fixed
263 to check the function type instead. */
264 { "noreturn", 0, 0, true, false, false, false,
265 handle_noreturn_attribute
,
266 attr_noreturn_exclusions
},
267 { "volatile", 0, 0, true, false, false, false,
268 handle_noreturn_attribute
, NULL
},
269 { "stack_protect", 0, 0, true, false, false, false,
270 handle_stack_protect_attribute
, NULL
},
271 { "noinline", 0, 0, true, false, false, false,
272 handle_noinline_attribute
,
273 attr_noinline_exclusions
},
274 { "noclone", 0, 0, true, false, false, false,
275 handle_noclone_attribute
, NULL
},
276 { "no_icf", 0, 0, true, false, false, false,
277 handle_noicf_attribute
, NULL
},
278 { "noipa", 0, 0, true, false, false, false,
279 handle_noipa_attribute
, NULL
},
280 { "leaf", 0, 0, true, false, false, false,
281 handle_leaf_attribute
, NULL
},
282 { "always_inline", 0, 0, true, false, false, false,
283 handle_always_inline_attribute
,
284 attr_inline_exclusions
},
285 { "gnu_inline", 0, 0, true, false, false, false,
286 handle_gnu_inline_attribute
,
287 attr_inline_exclusions
},
288 { "artificial", 0, 0, true, false, false, false,
289 handle_artificial_attribute
, NULL
},
290 { "flatten", 0, 0, true, false, false, false,
291 handle_flatten_attribute
, NULL
},
292 { "used", 0, 0, true, false, false, false,
293 handle_used_attribute
, NULL
},
294 { "unused", 0, 0, false, false, false, false,
295 handle_unused_attribute
, NULL
},
296 { "externally_visible", 0, 0, true, false, false, false,
297 handle_externally_visible_attribute
, NULL
},
298 { "no_reorder", 0, 0, true, false, false, false,
299 handle_no_reorder_attribute
, NULL
},
300 /* The same comments as for noreturn attributes apply to const ones. */
301 { "const", 0, 0, true, false, false, false,
302 handle_const_attribute
,
303 attr_const_pure_exclusions
},
304 { "scalar_storage_order", 1, 1, false, false, false, false,
305 handle_scalar_storage_order_attribute
, NULL
},
306 { "transparent_union", 0, 0, false, false, false, false,
307 handle_transparent_union_attribute
, NULL
},
308 { "constructor", 0, 1, true, false, false, false,
309 handle_constructor_attribute
, NULL
},
310 { "destructor", 0, 1, true, false, false, false,
311 handle_destructor_attribute
, NULL
},
312 { "mode", 1, 1, false, true, false, false,
313 handle_mode_attribute
, NULL
},
314 { "section", 1, 1, true, false, false, false,
315 handle_section_attribute
, NULL
},
316 { "aligned", 0, 1, false, false, false, false,
317 handle_aligned_attribute
,
318 attr_aligned_exclusions
},
319 { "warn_if_not_aligned", 0, 1, false, false, false, false,
320 handle_warn_if_not_aligned_attribute
, NULL
},
321 { "weak", 0, 0, true, false, false, false,
322 handle_weak_attribute
, NULL
},
323 { "noplt", 0, 0, true, false, false, false,
324 handle_noplt_attribute
, NULL
},
325 { "ifunc", 1, 1, true, false, false, false,
326 handle_ifunc_attribute
, NULL
},
327 { "alias", 1, 1, true, false, false, false,
328 handle_alias_attribute
, NULL
},
329 { "weakref", 0, 1, true, false, false, false,
330 handle_weakref_attribute
, NULL
},
331 { "no_instrument_function", 0, 0, true, false, false, false,
332 handle_no_instrument_function_attribute
,
334 { "no_profile_instrument_function", 0, 0, true, false, false, false,
335 handle_no_profile_instrument_function_attribute
,
337 { "malloc", 0, 0, true, false, false, false,
338 handle_malloc_attribute
, attr_alloc_exclusions
},
339 { "returns_twice", 0, 0, true, false, false, false,
340 handle_returns_twice_attribute
,
341 attr_returns_twice_exclusions
},
342 { "no_stack_limit", 0, 0, true, false, false, false,
343 handle_no_limit_stack_attribute
, NULL
},
344 { "pure", 0, 0, true, false, false, false,
345 handle_pure_attribute
,
346 attr_const_pure_exclusions
},
347 { "transaction_callable", 0, 0, false, true, false, false,
348 handle_tm_attribute
, NULL
},
349 { "transaction_unsafe", 0, 0, false, true, false, true,
350 handle_tm_attribute
, NULL
},
351 { "transaction_safe", 0, 0, false, true, false, true,
352 handle_tm_attribute
, NULL
},
353 { "transaction_safe_dynamic", 0, 0, true, false, false, false,
354 handle_tm_attribute
, NULL
},
355 { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
356 handle_tm_attribute
, NULL
},
357 /* ??? These two attributes didn't make the transition from the
358 Intel language document to the multi-vendor language document. */
359 { "transaction_pure", 0, 0, false, true, false, false,
360 handle_tm_attribute
, NULL
},
361 { "transaction_wrap", 1, 1, true, false, false, false,
362 handle_tm_wrap_attribute
, NULL
},
363 /* For internal use (marking of builtins) only. The name contains space
364 to prevent its usage in source code. */
365 { "no vops", 0, 0, true, false, false, false,
366 handle_novops_attribute
, NULL
},
367 { "deprecated", 0, 1, false, false, false, false,
368 handle_deprecated_attribute
, NULL
},
369 { "vector_size", 1, 1, false, true, false, true,
370 handle_vector_size_attribute
, NULL
},
371 { "visibility", 1, 1, false, false, false, false,
372 handle_visibility_attribute
, NULL
},
373 { "tls_model", 1, 1, true, false, false, false,
374 handle_tls_model_attribute
, NULL
},
375 { "nonnull", 0, -1, false, true, true, false,
376 handle_nonnull_attribute
, NULL
},
377 { "nonstring", 0, 0, true, false, false, false,
378 handle_nonstring_attribute
, NULL
},
379 { "nothrow", 0, 0, true, false, false, false,
380 handle_nothrow_attribute
, NULL
},
381 { "may_alias", 0, 0, false, true, false, false, NULL
, NULL
},
382 { "cleanup", 1, 1, true, false, false, false,
383 handle_cleanup_attribute
, NULL
},
384 { "warn_unused_result", 0, 0, false, true, true, false,
385 handle_warn_unused_result_attribute
,
386 attr_warn_unused_result_exclusions
},
387 { "sentinel", 0, 1, false, true, true, false,
388 handle_sentinel_attribute
, NULL
},
389 /* For internal use (marking of builtins) only. The name contains space
390 to prevent its usage in source code. */
391 { "type generic", 0, 0, false, true, true, false,
392 handle_type_generic_attribute
, NULL
},
393 { "alloc_size", 1, 2, false, true, true, false,
394 handle_alloc_size_attribute
,
395 attr_alloc_exclusions
},
396 { "cold", 0, 0, true, false, false, false,
397 handle_cold_attribute
,
398 attr_cold_hot_exclusions
},
399 { "hot", 0, 0, true, false, false, false,
400 handle_hot_attribute
,
401 attr_cold_hot_exclusions
},
402 { "no_address_safety_analysis",
403 0, 0, true, false, false, false,
404 handle_no_address_safety_analysis_attribute
,
406 { "no_sanitize", 1, 1, true, false, false, false,
407 handle_no_sanitize_attribute
, NULL
},
408 { "no_sanitize_address", 0, 0, true, false, false, false,
409 handle_no_sanitize_address_attribute
, NULL
},
410 { "no_sanitize_thread", 0, 0, true, false, false, false,
411 handle_no_sanitize_thread_attribute
, NULL
},
412 { "no_sanitize_undefined", 0, 0, true, false, false, false,
413 handle_no_sanitize_undefined_attribute
, NULL
},
414 { "asan odr indicator", 0, 0, true, false, false, false,
415 handle_asan_odr_indicator_attribute
, NULL
},
416 { "warning", 1, 1, true, false, false, false,
417 handle_error_attribute
, NULL
},
418 { "error", 1, 1, true, false, false, false,
419 handle_error_attribute
, NULL
},
420 { "target", 1, -1, true, false, false, false,
421 handle_target_attribute
, NULL
},
422 { "target_clones", 1, -1, true, false, false, false,
423 handle_target_clones_attribute
, NULL
},
424 { "optimize", 1, -1, true, false, false, false,
425 handle_optimize_attribute
, NULL
},
426 /* For internal use only. The leading '*' both prevents its usage in
427 source code and signals that it may be overridden by machine tables. */
428 { "*tm regparm", 0, 0, false, true, true, false,
429 ignore_attribute
, NULL
},
430 { "no_split_stack", 0, 0, true, false, false, false,
431 handle_no_split_stack_attribute
, NULL
},
432 /* For internal use (marking of builtins and runtime functions) only.
433 The name contains space to prevent its usage in source code. */
434 { "fn spec", 1, 1, false, true, true, false,
435 handle_fnspec_attribute
, NULL
},
436 { "warn_unused", 0, 0, false, false, false, false,
437 handle_warn_unused_attribute
, NULL
},
438 { "returns_nonnull", 0, 0, false, true, true, false,
439 handle_returns_nonnull_attribute
, NULL
},
440 { "omp declare simd", 0, -1, true, false, false, false,
441 handle_omp_declare_simd_attribute
, NULL
},
442 { "cilk simd function", 0, -1, true, false, false, false,
443 handle_omp_declare_simd_attribute
, NULL
},
444 { "simd", 0, 1, true, false, false, false,
445 handle_simd_attribute
, NULL
},
446 { "omp declare target", 0, 0, true, false, false, false,
447 handle_omp_declare_target_attribute
, NULL
},
448 { "omp declare target link", 0, 0, true, false, false, false,
449 handle_omp_declare_target_attribute
, NULL
},
450 { "alloc_align", 1, 1, false, true, true, false,
451 handle_alloc_align_attribute
,
452 attr_alloc_exclusions
},
453 { "assume_aligned", 1, 2, false, true, true, false,
454 handle_assume_aligned_attribute
, NULL
},
455 { "designated_init", 0, 0, false, true, false, false,
456 handle_designated_init_attribute
, NULL
},
457 { "bnd_variable_size", 0, 0, true, false, false, false,
458 handle_bnd_variable_size_attribute
, NULL
},
459 { "bnd_legacy", 0, 0, true, false, false, false,
460 handle_bnd_legacy
, NULL
},
461 { "bnd_instrument", 0, 0, true, false, false, false,
462 handle_bnd_instrument
, NULL
},
463 { "fallthrough", 0, 0, false, false, false, false,
464 handle_fallthrough_attribute
, NULL
},
465 { "patchable_function_entry", 1, 2, true, false, false, false,
466 handle_patchable_function_entry_attribute
,
468 { "nocf_check", 0, 0, false, true, true, true,
469 handle_nocf_check_attribute
, NULL
},
470 { NULL
, 0, 0, false, false, false, false, NULL
, NULL
}
473 /* Give the specifications for the format attributes, used by C and all
476 All attributes referencing arguments should be additionally processed
477 in chkp_copy_function_type_adding_bounds for correct instrumentation
478 by Pointer Bounds Checker.
479 Current list of processed format attributes: format, format_arg. */
480 const struct attribute_spec c_common_format_attribute_table
[] =
482 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
483 affects_type_identity, handler, exclude } */
484 { "format", 3, 3, false, true, true, false,
485 handle_format_attribute
, NULL
},
486 { "format_arg", 1, 1, false, true, true, false,
487 handle_format_arg_attribute
, NULL
},
488 { NULL
, 0, 0, false, false, false, false, NULL
, NULL
}
491 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
492 identifier as an argument, so the front end shouldn't look it up. */
495 attribute_takes_identifier_p (const_tree attr_id
)
497 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
499 /* Unknown attribute that we'll end up ignoring, return true so we
500 don't complain about an identifier argument. */
502 else if (!strcmp ("mode", spec
->name
)
503 || !strcmp ("format", spec
->name
)
504 || !strcmp ("cleanup", spec
->name
))
507 return targetm
.attribute_takes_identifier_p (attr_id
);
510 /* Attribute handlers common to C front ends. */
512 /* Handle a "packed" attribute; arguments as in
513 struct attribute_spec.handler. */
516 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
517 int flags
, bool *no_add_attrs
)
521 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
522 *node
= build_variant_type_copy (*node
);
523 TYPE_PACKED (*node
) = 1;
525 else if (TREE_CODE (*node
) == FIELD_DECL
)
527 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
528 /* Still pack bitfields. */
529 && ! DECL_C_BIT_FIELD (*node
))
530 warning (OPT_Wattributes
,
531 "%qE attribute ignored for field of type %qT",
532 name
, TREE_TYPE (*node
));
534 DECL_PACKED (*node
) = 1;
536 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
537 used for DECL_REGISTER. It wouldn't mean anything anyway.
538 We can't set DECL_PACKED on the type of a TYPE_DECL, because
539 that changes what the typedef is typing. */
542 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
543 *no_add_attrs
= true;
549 /* Handle a "nocommon" attribute; arguments as in
550 struct attribute_spec.handler. */
553 handle_nocommon_attribute (tree
*node
, tree name
,
554 tree
ARG_UNUSED (args
),
555 int ARG_UNUSED (flags
), bool *no_add_attrs
)
558 DECL_COMMON (*node
) = 0;
561 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
562 *no_add_attrs
= true;
568 /* Handle a "common" attribute; arguments as in
569 struct attribute_spec.handler. */
572 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
573 int ARG_UNUSED (flags
), bool *no_add_attrs
)
576 DECL_COMMON (*node
) = 1;
579 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
580 *no_add_attrs
= true;
586 /* Handle a "noreturn" attribute; arguments as in
587 struct attribute_spec.handler. */
590 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
591 int ARG_UNUSED (flags
), bool *no_add_attrs
)
593 tree type
= TREE_TYPE (*node
);
595 /* See FIXME comment in c_common_attribute_table. */
596 if (TREE_CODE (*node
) == FUNCTION_DECL
597 || objc_method_decl (TREE_CODE (*node
)))
598 TREE_THIS_VOLATILE (*node
) = 1;
599 else if (TREE_CODE (type
) == POINTER_TYPE
600 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
602 = (build_qualified_type
604 (build_type_variant (TREE_TYPE (type
),
605 TYPE_READONLY (TREE_TYPE (type
)), 1)),
609 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
610 *no_add_attrs
= true;
616 /* Handle a "hot" and attribute; arguments as in
617 struct attribute_spec.handler. */
620 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
621 int ARG_UNUSED (flags
), bool *no_add_attrs
)
623 if (TREE_CODE (*node
) == FUNCTION_DECL
624 || TREE_CODE (*node
) == LABEL_DECL
)
626 /* Attribute hot processing is done later with lookup_attribute. */
630 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
631 *no_add_attrs
= true;
637 /* Handle a "cold" and attribute; arguments as in
638 struct attribute_spec.handler. */
641 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
642 int ARG_UNUSED (flags
), bool *no_add_attrs
)
644 if (TREE_CODE (*node
) == FUNCTION_DECL
645 || TREE_CODE (*node
) == LABEL_DECL
)
647 /* Attribute cold processing is done later with lookup_attribute. */
651 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
652 *no_add_attrs
= true;
658 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
661 add_no_sanitize_value (tree node
, unsigned int flags
)
663 tree attr
= lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node
));
666 unsigned int old_value
= tree_to_uhwi (TREE_VALUE (attr
));
669 if (flags
== old_value
)
672 TREE_VALUE (attr
) = build_int_cst (unsigned_type_node
, flags
);
675 DECL_ATTRIBUTES (node
)
676 = tree_cons (get_identifier ("no_sanitize"),
677 build_int_cst (unsigned_type_node
, flags
),
678 DECL_ATTRIBUTES (node
));
681 /* Handle a "no_sanitize" attribute; arguments as in
682 struct attribute_spec.handler. */
685 handle_no_sanitize_attribute (tree
*node
, tree name
, tree args
, int,
688 *no_add_attrs
= true;
689 tree id
= TREE_VALUE (args
);
690 if (TREE_CODE (*node
) != FUNCTION_DECL
)
692 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
696 if (TREE_CODE (id
) != STRING_CST
)
698 error ("no_sanitize argument not a string");
702 char *string
= ASTRDUP (TREE_STRING_POINTER (id
));
703 unsigned int flags
= parse_no_sanitize_attribute (string
);
705 add_no_sanitize_value (*node
, flags
);
710 /* Handle a "no_sanitize_address" attribute; arguments as in
711 struct attribute_spec.handler. */
714 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
717 *no_add_attrs
= true;
718 if (TREE_CODE (*node
) != FUNCTION_DECL
)
719 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
721 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
726 /* Handle a "no_sanitize_thread" attribute; arguments as in
727 struct attribute_spec.handler. */
730 handle_no_sanitize_thread_attribute (tree
*node
, tree name
, tree
, int,
733 *no_add_attrs
= true;
734 if (TREE_CODE (*node
) != FUNCTION_DECL
)
735 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
737 add_no_sanitize_value (*node
, SANITIZE_THREAD
);
743 /* Handle a "no_address_safety_analysis" attribute; arguments as in
744 struct attribute_spec.handler. */
747 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
750 *no_add_attrs
= true;
751 if (TREE_CODE (*node
) != FUNCTION_DECL
)
752 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
754 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
759 /* Handle a "no_sanitize_undefined" attribute; arguments as in
760 struct attribute_spec.handler. */
763 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
766 *no_add_attrs
= true;
767 if (TREE_CODE (*node
) != FUNCTION_DECL
)
768 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
770 add_no_sanitize_value (*node
,
771 SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
776 /* Handle an "asan odr indicator" attribute; arguments as in
777 struct attribute_spec.handler. */
780 handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int, bool *)
785 /* Handle a "stack_protect" attribute; arguments as in
786 struct attribute_spec.handler. */
789 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
792 if (TREE_CODE (*node
) != FUNCTION_DECL
)
794 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
795 *no_add_attrs
= true;
801 /* Handle a "noipa" attribute; arguments as in
802 struct attribute_spec.handler. */
805 handle_noipa_attribute (tree
*node
, tree name
, tree
, int, bool *no_add_attrs
)
807 if (TREE_CODE (*node
) != FUNCTION_DECL
)
809 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
810 *no_add_attrs
= true;
816 /* Handle a "noinline" attribute; arguments as in
817 struct attribute_spec.handler. */
820 handle_noinline_attribute (tree
*node
, tree name
,
821 tree
ARG_UNUSED (args
),
822 int ARG_UNUSED (flags
), bool *no_add_attrs
)
824 if (TREE_CODE (*node
) == FUNCTION_DECL
)
826 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
828 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
829 "with attribute %qs", name
, "always_inline");
830 *no_add_attrs
= true;
833 DECL_UNINLINABLE (*node
) = 1;
837 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
838 *no_add_attrs
= true;
844 /* Handle a "noclone" attribute; arguments as in
845 struct attribute_spec.handler. */
848 handle_noclone_attribute (tree
*node
, tree name
,
849 tree
ARG_UNUSED (args
),
850 int ARG_UNUSED (flags
), bool *no_add_attrs
)
852 if (TREE_CODE (*node
) != FUNCTION_DECL
)
854 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
855 *no_add_attrs
= true;
861 /* Handle a "nocf_check" attribute; arguments as in
862 struct attribute_spec.handler. */
865 handle_nocf_check_attribute (tree
*node
, tree name
,
866 tree
ARG_UNUSED (args
),
867 int ARG_UNUSED (flags
), bool *no_add_attrs
)
869 if (TREE_CODE (*node
) != FUNCTION_TYPE
870 && TREE_CODE (*node
) != METHOD_TYPE
)
872 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
873 *no_add_attrs
= true;
875 else if (!(flag_cf_protection
& CF_BRANCH
))
877 warning (OPT_Wattributes
, "%qE attribute ignored. Use "
878 "-fcf-protection option to enable it", name
);
879 *no_add_attrs
= true;
885 /* Handle a "no_icf" attribute; arguments as in
886 struct attribute_spec.handler. */
889 handle_noicf_attribute (tree
*node
, tree name
,
890 tree
ARG_UNUSED (args
),
891 int ARG_UNUSED (flags
), bool *no_add_attrs
)
893 if (TREE_CODE (*node
) != FUNCTION_DECL
)
895 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
896 *no_add_attrs
= true;
903 /* Handle a "always_inline" attribute; arguments as in
904 struct attribute_spec.handler. */
907 handle_always_inline_attribute (tree
*node
, tree name
,
908 tree
ARG_UNUSED (args
),
909 int ARG_UNUSED (flags
),
912 if (TREE_CODE (*node
) == FUNCTION_DECL
)
914 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
916 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
917 "with %qs attribute", name
, "noinline");
918 *no_add_attrs
= true;
920 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
922 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
923 "with %qs attribute", name
, "target_clones");
924 *no_add_attrs
= true;
927 /* Set the attribute and mark it for disregarding inline
929 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
933 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
934 *no_add_attrs
= true;
940 /* Handle a "gnu_inline" attribute; arguments as in
941 struct attribute_spec.handler. */
944 handle_gnu_inline_attribute (tree
*node
, tree name
,
945 tree
ARG_UNUSED (args
),
946 int ARG_UNUSED (flags
),
949 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
951 /* Do nothing else, just set the attribute. We'll get at
952 it later with lookup_attribute. */
956 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
957 *no_add_attrs
= true;
963 /* Handle a "leaf" attribute; arguments as in
964 struct attribute_spec.handler. */
967 handle_leaf_attribute (tree
*node
, tree name
,
968 tree
ARG_UNUSED (args
),
969 int ARG_UNUSED (flags
), bool *no_add_attrs
)
971 if (TREE_CODE (*node
) != FUNCTION_DECL
)
973 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
974 *no_add_attrs
= true;
976 if (!TREE_PUBLIC (*node
))
978 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
980 *no_add_attrs
= true;
986 /* Handle an "artificial" attribute; arguments as in
987 struct attribute_spec.handler. */
990 handle_artificial_attribute (tree
*node
, tree name
,
991 tree
ARG_UNUSED (args
),
992 int ARG_UNUSED (flags
),
995 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
997 /* Do nothing else, just set the attribute. We'll get at
998 it later with lookup_attribute. */
1002 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1003 *no_add_attrs
= true;
1009 /* Handle a "flatten" attribute; arguments as in
1010 struct attribute_spec.handler. */
1013 handle_flatten_attribute (tree
*node
, tree name
,
1014 tree args ATTRIBUTE_UNUSED
,
1015 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1017 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1018 /* Do nothing else, just set the attribute. We'll get at
1019 it later with lookup_attribute. */
1023 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1024 *no_add_attrs
= true;
1030 /* Handle a "warning" or "error" attribute; arguments as in
1031 struct attribute_spec.handler. */
1034 handle_error_attribute (tree
*node
, tree name
, tree args
,
1035 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1037 if (TREE_CODE (*node
) == FUNCTION_DECL
1038 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
1039 /* Do nothing else, just set the attribute. We'll get at
1040 it later with lookup_attribute. */
1044 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1045 *no_add_attrs
= true;
1051 /* Handle a "used" attribute; arguments as in
1052 struct attribute_spec.handler. */
1055 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
1056 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1060 if (TREE_CODE (node
) == FUNCTION_DECL
1061 || (VAR_P (node
) && TREE_STATIC (node
))
1062 || (TREE_CODE (node
) == TYPE_DECL
))
1064 TREE_USED (node
) = 1;
1065 DECL_PRESERVE_P (node
) = 1;
1067 DECL_READ_P (node
) = 1;
1071 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1072 *no_add_attrs
= true;
1078 /* Handle a "unused" attribute; arguments as in
1079 struct attribute_spec.handler. */
1082 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1083 int flags
, bool *no_add_attrs
)
1089 if (TREE_CODE (decl
) == PARM_DECL
1090 || VAR_OR_FUNCTION_DECL_P (decl
)
1091 || TREE_CODE (decl
) == LABEL_DECL
1092 || TREE_CODE (decl
) == CONST_DECL
1093 || TREE_CODE (decl
) == TYPE_DECL
)
1095 TREE_USED (decl
) = 1;
1096 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
1097 DECL_READ_P (decl
) = 1;
1101 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1102 *no_add_attrs
= true;
1107 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1108 *node
= build_variant_type_copy (*node
);
1109 TREE_USED (*node
) = 1;
1115 /* Handle a "externally_visible" attribute; arguments as in
1116 struct attribute_spec.handler. */
1119 handle_externally_visible_attribute (tree
*pnode
, tree name
,
1120 tree
ARG_UNUSED (args
),
1121 int ARG_UNUSED (flags
),
1126 if (VAR_OR_FUNCTION_DECL_P (node
))
1128 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
1129 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
1131 warning (OPT_Wattributes
,
1132 "%qE attribute have effect only on public objects", name
);
1133 *no_add_attrs
= true;
1138 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1139 *no_add_attrs
= true;
1145 /* Handle the "no_reorder" attribute. Arguments as in
1146 struct attribute_spec.handler. */
1149 handle_no_reorder_attribute (tree
*pnode
,
1157 if (!VAR_OR_FUNCTION_DECL_P (node
)
1158 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
1160 warning (OPT_Wattributes
,
1161 "%qE attribute only affects top level objects",
1163 *no_add_attrs
= true;
1169 /* Handle a "const" attribute; arguments as in
1170 struct attribute_spec.handler. */
1173 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1174 int flags
, bool *no_add_attrs
)
1176 tree type
= TREE_TYPE (*node
);
1178 /* See FIXME comment on noreturn in c_common_attribute_table. */
1179 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1180 TREE_READONLY (*node
) = 1;
1181 else if (TREE_CODE (type
) == POINTER_TYPE
1182 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1184 = (build_qualified_type
1186 (build_type_variant (TREE_TYPE (type
), 1,
1187 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
1188 TYPE_QUALS (type
)));
1191 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1192 *no_add_attrs
= true;
1195 /* void __builtin_unreachable(void) is const. Accept other such
1196 built-ins but warn on user-defined functions that return void. */
1197 if (!(flags
& ATTR_FLAG_BUILT_IN
)
1198 && TREE_CODE (*node
) == FUNCTION_DECL
1199 && VOID_TYPE_P (TREE_TYPE (type
)))
1200 warning (OPT_Wattributes
, "%qE attribute on function "
1201 "returning %<void%>", name
);
1206 /* Handle a "scalar_storage_order" attribute; arguments as in
1207 struct attribute_spec.handler. */
1210 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
1211 int flags
, bool *no_add_attrs
)
1213 tree id
= TREE_VALUE (args
);
1216 if (TREE_CODE (*node
) == TYPE_DECL
1217 && ! (flags
& ATTR_FLAG_CXX11
))
1218 node
= &TREE_TYPE (*node
);
1221 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
1223 error ("scalar_storage_order is not supported because endianness "
1228 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
1230 bool reverse
= false;
1232 if (TREE_CODE (id
) == STRING_CST
1233 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1234 reverse
= !BYTES_BIG_ENDIAN
;
1235 else if (TREE_CODE (id
) == STRING_CST
1236 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1237 reverse
= BYTES_BIG_ENDIAN
;
1240 error ("scalar_storage_order argument must be one of \"big-endian\""
1241 " or \"little-endian\"");
1245 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1248 /* A type variant isn't good enough, since we don't want a cast
1249 to such a type to be removed as a no-op. */
1250 *node
= type
= build_duplicate_type (type
);
1253 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1257 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1258 *no_add_attrs
= true;
1262 /* Handle a "transparent_union" attribute; arguments as in
1263 struct attribute_spec.handler. */
1266 handle_transparent_union_attribute (tree
*node
, tree name
,
1267 tree
ARG_UNUSED (args
), int flags
,
1272 *no_add_attrs
= true;
1274 if (TREE_CODE (*node
) == TYPE_DECL
1275 && ! (flags
& ATTR_FLAG_CXX11
))
1276 node
= &TREE_TYPE (*node
);
1279 if (TREE_CODE (type
) == UNION_TYPE
)
1281 /* Make sure that the first field will work for a transparent union.
1282 If the type isn't complete yet, leave the check to the code in
1284 if (TYPE_SIZE (type
))
1286 tree first
= first_field (type
);
1287 if (first
== NULL_TREE
1288 || DECL_ARTIFICIAL (first
)
1289 || TYPE_MODE (type
) != DECL_MODE (first
))
1293 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1295 /* If the type isn't complete yet, setting the flag
1296 on a variant wouldn't ever be checked. */
1297 if (!TYPE_SIZE (type
))
1300 /* build_duplicate_type doesn't work for C++. */
1301 if (c_dialect_cxx ())
1304 /* A type variant isn't good enough, since we don't want a cast
1305 to such a type to be removed as a no-op. */
1306 *node
= type
= build_duplicate_type (type
);
1309 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1310 TYPE_TRANSPARENT_AGGR (t
) = 1;
1315 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1319 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1320 get the requested priority for a constructor or destructor,
1321 possibly issuing diagnostics for invalid or reserved
1324 static priority_type
1325 get_priority (tree args
, bool is_destructor
)
1331 return DEFAULT_INIT_PRIORITY
;
1333 if (!SUPPORTS_INIT_PRIORITY
)
1336 error ("destructor priorities are not supported");
1338 error ("constructor priorities are not supported");
1339 return DEFAULT_INIT_PRIORITY
;
1342 arg
= TREE_VALUE (args
);
1343 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1345 if (arg
== error_mark_node
)
1346 return DEFAULT_INIT_PRIORITY
;
1347 arg
= default_conversion (arg
);
1348 if (!tree_fits_shwi_p (arg
)
1349 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1352 pri
= tree_to_shwi (arg
);
1353 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1356 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1360 "destructor priorities from 0 to %d are reserved "
1361 "for the implementation",
1362 MAX_RESERVED_INIT_PRIORITY
);
1365 "constructor priorities from 0 to %d are reserved "
1366 "for the implementation",
1367 MAX_RESERVED_INIT_PRIORITY
);
1373 error ("destructor priorities must be integers from 0 to %d inclusive",
1376 error ("constructor priorities must be integers from 0 to %d inclusive",
1378 return DEFAULT_INIT_PRIORITY
;
1381 /* Handle a "constructor" attribute; arguments as in
1382 struct attribute_spec.handler. */
1385 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1386 int ARG_UNUSED (flags
),
1390 tree type
= TREE_TYPE (decl
);
1392 if (TREE_CODE (decl
) == FUNCTION_DECL
1393 && TREE_CODE (type
) == FUNCTION_TYPE
1394 && decl_function_context (decl
) == 0)
1396 priority_type priority
;
1397 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1398 priority
= get_priority (args
, /*is_destructor=*/false);
1399 SET_DECL_INIT_PRIORITY (decl
, priority
);
1400 TREE_USED (decl
) = 1;
1404 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1405 *no_add_attrs
= true;
1411 /* Handle a "destructor" attribute; arguments as in
1412 struct attribute_spec.handler. */
1415 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1416 int ARG_UNUSED (flags
),
1420 tree type
= TREE_TYPE (decl
);
1422 if (TREE_CODE (decl
) == FUNCTION_DECL
1423 && TREE_CODE (type
) == FUNCTION_TYPE
1424 && decl_function_context (decl
) == 0)
1426 priority_type priority
;
1427 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1428 priority
= get_priority (args
, /*is_destructor=*/true);
1429 SET_DECL_FINI_PRIORITY (decl
, priority
);
1430 TREE_USED (decl
) = 1;
1434 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1435 *no_add_attrs
= true;
1441 /* Nonzero if the mode is a valid vector mode for this architecture.
1442 This returns nonzero even if there is no hardware support for the
1443 vector mode, but we can emulate with narrower modes. */
1446 vector_mode_valid_p (machine_mode mode
)
1448 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1450 /* Doh! What's going on? */
1451 if (mclass
!= MODE_VECTOR_INT
1452 && mclass
!= MODE_VECTOR_FLOAT
1453 && mclass
!= MODE_VECTOR_FRACT
1454 && mclass
!= MODE_VECTOR_UFRACT
1455 && mclass
!= MODE_VECTOR_ACCUM
1456 && mclass
!= MODE_VECTOR_UACCUM
)
1459 /* Hardware support. Woo hoo! */
1460 if (targetm
.vector_mode_supported_p (mode
))
1463 /* We should probably return 1 if requesting V4DI and we have no DI,
1464 but we have V2DI, but this is probably very unlikely. */
1466 /* If we have support for the inner mode, we can safely emulate it.
1467 We may not have V2DI, but me can emulate with a pair of DIs. */
1468 return targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1472 /* Handle a "mode" attribute; arguments as in
1473 struct attribute_spec.handler. */
1476 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1477 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1480 tree ident
= TREE_VALUE (args
);
1482 *no_add_attrs
= true;
1484 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1485 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1489 const char *p
= IDENTIFIER_POINTER (ident
);
1490 int len
= strlen (p
);
1491 machine_mode mode
= VOIDmode
;
1495 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1496 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1498 char *newp
= (char *) alloca (len
- 1);
1500 strcpy (newp
, &p
[2]);
1501 newp
[len
- 4] = '\0';
1505 /* Change this type to have a type with the specified mode.
1506 First check for the special modes. */
1507 if (!strcmp (p
, "byte"))
1509 else if (!strcmp (p
, "word"))
1511 else if (!strcmp (p
, "pointer"))
1513 else if (!strcmp (p
, "libgcc_cmp_return"))
1514 mode
= targetm
.libgcc_cmp_return_mode ();
1515 else if (!strcmp (p
, "libgcc_shift_count"))
1516 mode
= targetm
.libgcc_shift_count_mode ();
1517 else if (!strcmp (p
, "unwind_word"))
1518 mode
= targetm
.unwind_word_mode ();
1520 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1521 if (!strcmp (p
, GET_MODE_NAME (j
)))
1523 mode
= (machine_mode
) j
;
1527 if (mode
== VOIDmode
)
1529 error ("unknown machine mode %qE", ident
);
1534 switch (GET_MODE_CLASS (mode
))
1537 case MODE_PARTIAL_INT
:
1539 case MODE_DECIMAL_FLOAT
:
1545 = targetm
.scalar_mode_supported_p (as_a
<scalar_mode
> (mode
));
1548 case MODE_COMPLEX_INT
:
1549 case MODE_COMPLEX_FLOAT
:
1550 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1553 case MODE_VECTOR_INT
:
1554 case MODE_VECTOR_FLOAT
:
1555 case MODE_VECTOR_FRACT
:
1556 case MODE_VECTOR_UFRACT
:
1557 case MODE_VECTOR_ACCUM
:
1558 case MODE_VECTOR_UACCUM
:
1559 warning (OPT_Wattributes
, "specifying vector types with "
1560 "__attribute__ ((mode)) is deprecated");
1561 warning (OPT_Wattributes
,
1562 "use __attribute__ ((vector_size)) instead");
1563 valid_mode
= vector_mode_valid_p (mode
);
1571 error ("unable to emulate %qs", p
);
1575 if (POINTER_TYPE_P (type
))
1577 scalar_int_mode addr_mode
;
1578 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1579 tree (*fn
)(tree
, machine_mode
, bool);
1581 if (!is_a
<scalar_int_mode
> (mode
, &addr_mode
)
1582 || !targetm
.addr_space
.valid_pointer_mode (addr_mode
, as
))
1584 error ("invalid pointer mode %qs", p
);
1588 if (TREE_CODE (type
) == POINTER_TYPE
)
1589 fn
= build_pointer_type_for_mode
;
1591 fn
= build_reference_type_for_mode
;
1592 typefm
= fn (TREE_TYPE (type
), addr_mode
, false);
1596 /* For fixed-point modes, we need to test if the signness of type
1597 and the machine mode are consistent. */
1598 if (ALL_FIXED_POINT_MODE_P (mode
)
1599 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1601 error ("signedness of type and machine mode %qs don%'t match", p
);
1604 /* For fixed-point modes, we need to pass saturating info. */
1605 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1606 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1607 : TYPE_UNSIGNED (type
));
1610 if (typefm
== NULL_TREE
)
1612 error ("no data type for mode %qs", p
);
1615 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1617 /* For enumeral types, copy the precision from the integer
1618 type returned above. If not an INTEGER_TYPE, we can't use
1619 this mode for this type. */
1620 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1622 error ("cannot use mode %qs for enumeral types", p
);
1626 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1628 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1633 /* We cannot build a type variant, as there's code that assumes
1634 that TYPE_MAIN_VARIANT has the same mode. This includes the
1635 debug generators. Instead, create a subrange type. This
1636 results in all of the enumeral values being emitted only once
1637 in the original, and the subtype gets them by reference. */
1638 if (TYPE_UNSIGNED (type
))
1639 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1641 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1642 TREE_TYPE (typefm
) = type
;
1645 else if (VECTOR_MODE_P (mode
)
1646 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1647 : TREE_CODE (type
) != TREE_CODE (typefm
))
1649 error ("mode %qs applied to inappropriate type", p
);
1653 *node
= build_qualified_type (typefm
, TYPE_QUALS (type
));
1659 /* Handle a "section" attribute; arguments as in
1660 struct attribute_spec.handler. */
1663 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1664 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1668 if (!targetm_common
.have_named_sections
)
1670 error_at (DECL_SOURCE_LOCATION (*node
),
1671 "section attributes are not supported for this target");
1675 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1677 error ("section attribute not allowed for %q+D", *node
);
1681 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1683 error ("section attribute argument not a string constant");
1688 && current_function_decl
!= NULL_TREE
1689 && !TREE_STATIC (decl
))
1691 error_at (DECL_SOURCE_LOCATION (decl
),
1692 "section attribute cannot be specified for local variables");
1696 /* The decl may have already been given a section attribute
1697 from a previous declaration. Ensure they match. */
1698 if (DECL_SECTION_NAME (decl
) != NULL
1699 && strcmp (DECL_SECTION_NAME (decl
),
1700 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1702 error ("section of %q+D conflicts with previous declaration", *node
);
1707 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1708 && DECL_THREAD_LOCAL_P (decl
))
1710 error ("section of %q+D cannot be overridden", *node
);
1714 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1718 *no_add_attrs
= true;
1722 /* If in c++-11, check if the c++-11 alignment constraint with respect
1723 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1724 c++-11 mode, does nothing.
1728 [* if the constant expression evaluates to a fundamental alignment,
1729 the alignment requirement of the declared entity shall be the
1730 specified fundamental alignment.
1732 * if the constant expression evaluates to an extended alignment
1733 and the implementation supports that alignment in the context
1734 of the declaration, the alignment of the declared entity shall
1737 * if the constant expression evaluates to an extended alignment
1738 and the implementation does not support that alignment in the
1739 context of the declaration, the program is ill-formed]. */
1742 check_cxx_fundamental_alignment_constraints (tree node
,
1746 bool alignment_too_large_p
= false;
1747 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1748 unsigned max_align
= 0;
1750 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1751 || (node
== NULL_TREE
|| node
== error_mark_node
))
1754 if (cxx_fundamental_alignment_p (requested_alignment
))
1759 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1760 /* For file scope variables and static members, the target supports
1761 alignments that are at most MAX_OFILE_ALIGNMENT. */
1762 max_align
= MAX_OFILE_ALIGNMENT
;
1764 /* For stack variables, the target supports at most
1765 MAX_STACK_ALIGNMENT. */
1766 max_align
= MAX_STACK_ALIGNMENT
;
1767 if (requested_alignment
> max_align
)
1768 alignment_too_large_p
= true;
1770 /* Let's be liberal for types and fields; don't limit their alignment any
1771 more than check_user_alignment already did. */
1773 if (alignment_too_large_p
)
1774 pedwarn (input_location
, OPT_Wattributes
,
1775 "requested alignment %d is larger than %d",
1776 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1778 return !alignment_too_large_p
;
1781 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1782 handle_aligned_attribute. */
1785 common_handle_aligned_attribute (tree
*node
, tree name
, tree args
, int flags
,
1787 bool warn_if_not_aligned_p
)
1789 tree decl
= NULL_TREE
;
1791 bool is_type
= false;
1794 /* The last (already pushed) declaration with all validated attributes
1795 merged in or the current about-to-be-pushed one if one hasn't been
1797 tree last_decl
= node
[1] ? node
[1] : *node
;
1801 align_expr
= TREE_VALUE (args
);
1802 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1803 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1804 align_expr
= default_conversion (align_expr
);
1807 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1812 type
= &TREE_TYPE (decl
);
1813 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1815 else if (TYPE_P (*node
))
1816 type
= node
, is_type
= true;
1818 /* Log2 of specified alignment. */
1819 int pow2align
= check_user_alignment (align_expr
, true);
1821 /* The alignment in bits corresponding to the specified alignment. */
1822 unsigned bitalign
= (1U << pow2align
) * BITS_PER_UNIT
;
1824 /* The alignment of the current declaration and that of the last
1825 pushed declaration, determined on demand below. */
1826 unsigned curalign
= 0;
1827 unsigned lastalign
= 0;
1830 || !check_cxx_fundamental_alignment_constraints (*node
, pow2align
, flags
))
1831 *no_add_attrs
= true;
1834 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1835 /* OK, modify the type in place. */;
1836 /* If we have a TYPE_DECL, then copy the type, so that we
1837 don't accidentally modify a builtin type. See pushdecl. */
1838 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1839 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1841 tree tt
= TREE_TYPE (decl
);
1842 *type
= build_variant_type_copy (*type
);
1843 DECL_ORIGINAL_TYPE (decl
) = tt
;
1844 TYPE_NAME (*type
) = decl
;
1845 TREE_USED (*type
) = TREE_USED (decl
);
1846 TREE_TYPE (decl
) = *type
;
1849 *type
= build_variant_type_copy (*type
);
1851 if (warn_if_not_aligned_p
)
1853 SET_TYPE_WARN_IF_NOT_ALIGN (*type
, bitalign
);
1854 warn_if_not_aligned_p
= false;
1858 SET_TYPE_ALIGN (*type
, bitalign
);
1859 TYPE_USER_ALIGN (*type
) = 1;
1862 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1863 && TREE_CODE (decl
) != FIELD_DECL
)
1865 error ("alignment may not be specified for %q+D", decl
);
1866 *no_add_attrs
= true;
1868 else if (TREE_CODE (decl
) == FUNCTION_DECL
1869 && ((curalign
= DECL_ALIGN (decl
)) > bitalign
1870 || ((lastalign
= DECL_ALIGN (last_decl
)) > bitalign
)))
1872 /* Either a prior attribute on the same declaration or one
1873 on a prior declaration of the same function specifies
1874 stricter alignment than this attribute. */
1875 bool note
= lastalign
!= 0;
1877 curalign
= lastalign
;
1879 curalign
/= BITS_PER_UNIT
;
1880 bitalign
/= BITS_PER_UNIT
;
1883 if (DECL_USER_ALIGN (decl
) || DECL_USER_ALIGN (last_decl
))
1884 diagd
= warning (OPT_Wattributes
,
1885 "ignoring attribute %<%E (%u)%> because it conflicts "
1886 "with attribute %<%E (%u)%>",
1887 name
, bitalign
, name
, curalign
);
1888 else if (!warn_if_not_aligned_p
)
1889 /* Do not error out for attribute warn_if_not_aligned. */
1890 error ("alignment for %q+D must be at least %d", decl
, curalign
);
1893 inform (DECL_SOURCE_LOCATION (last_decl
), "previous declaration here");
1895 *no_add_attrs
= true;
1897 else if (DECL_USER_ALIGN (decl
)
1898 && DECL_ALIGN (decl
) > bitalign
)
1899 /* C++-11 [dcl.align/4]:
1901 When multiple alignment-specifiers are specified for an
1902 entity, the alignment requirement shall be set to the
1903 strictest specified alignment.
1905 This formally comes from the c++11 specification but we are
1906 doing it for the GNU attribute syntax as well. */
1907 *no_add_attrs
= true;
1908 else if (!warn_if_not_aligned_p
1909 && TREE_CODE (decl
) == FUNCTION_DECL
1910 && DECL_ALIGN (decl
) > bitalign
)
1912 /* Don't warn function alignment here if warn_if_not_aligned_p is
1913 true. It will be warned later. */
1914 if (DECL_USER_ALIGN (decl
))
1915 error ("alignment for %q+D was previously specified as %d "
1916 "and may not be decreased", decl
,
1917 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1919 error ("alignment for %q+D must be at least %d", decl
,
1920 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1921 *no_add_attrs
= true;
1925 if (warn_if_not_aligned_p
)
1927 if (TREE_CODE (decl
) == FIELD_DECL
&& !DECL_C_BIT_FIELD (decl
))
1929 SET_DECL_WARN_IF_NOT_ALIGN (decl
, bitalign
);
1930 warn_if_not_aligned_p
= false;
1935 SET_DECL_ALIGN (decl
, bitalign
);
1936 DECL_USER_ALIGN (decl
) = 1;
1940 if (warn_if_not_aligned_p
)
1942 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1944 *no_add_attrs
= true;
1950 /* Handle a "aligned" attribute; arguments as in
1951 struct attribute_spec.handler. */
1954 handle_aligned_attribute (tree
*node
, tree name
, tree args
,
1955 int flags
, bool *no_add_attrs
)
1957 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1958 no_add_attrs
, false);
1961 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1962 struct attribute_spec.handler. */
1965 handle_warn_if_not_aligned_attribute (tree
*node
, tree name
,
1966 tree args
, int flags
,
1969 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1970 no_add_attrs
, true);
1973 /* Handle a "weak" attribute; arguments as in
1974 struct attribute_spec.handler. */
1977 handle_weak_attribute (tree
*node
, tree name
,
1978 tree
ARG_UNUSED (args
),
1979 int ARG_UNUSED (flags
),
1980 bool * ARG_UNUSED (no_add_attrs
))
1982 if (TREE_CODE (*node
) == FUNCTION_DECL
1983 && DECL_DECLARED_INLINE_P (*node
))
1985 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1986 *no_add_attrs
= true;
1988 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1990 error ("indirect function %q+D cannot be declared weak", *node
);
1991 *no_add_attrs
= true;
1994 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1995 declare_weak (*node
);
1997 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2002 /* Handle a "noplt" attribute; arguments as in
2003 struct attribute_spec.handler. */
2006 handle_noplt_attribute (tree
*node
, tree name
,
2007 tree
ARG_UNUSED (args
),
2008 int ARG_UNUSED (flags
),
2009 bool * ARG_UNUSED (no_add_attrs
))
2011 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2013 warning (OPT_Wattributes
,
2014 "%qE attribute is only applicable on functions", name
);
2015 *no_add_attrs
= true;
2021 /* Handle an "alias" or "ifunc" attribute; arguments as in
2022 struct attribute_spec.handler, except that IS_ALIAS tells us
2023 whether this is an alias as opposed to ifunc attribute. */
2026 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
2031 if (TREE_CODE (decl
) != FUNCTION_DECL
2032 && (!is_alias
|| !VAR_P (decl
)))
2034 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2035 *no_add_attrs
= true;
2037 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
2038 || (TREE_CODE (decl
) != FUNCTION_DECL
2039 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
2040 /* A static variable declaration is always a tentative definition,
2041 but the alias is a non-tentative definition which overrides. */
2042 || (TREE_CODE (decl
) != FUNCTION_DECL
2043 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
2045 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
2046 *no_add_attrs
= true;
2050 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2051 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
2053 error ("weak %q+D cannot be defined %qE", decl
, name
);
2054 *no_add_attrs
= true;
2058 /* Note that the very first time we process a nested declaration,
2059 decl_function_context will not be set. Indeed, *would* never
2060 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2061 we do below. After such frobbery, pushdecl would set the context.
2062 In any case, this is never what we want. */
2063 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
2067 id
= TREE_VALUE (args
);
2068 if (TREE_CODE (id
) != STRING_CST
)
2070 error ("attribute %qE argument not a string", name
);
2071 *no_add_attrs
= true;
2074 id
= get_identifier (TREE_STRING_POINTER (id
));
2075 /* This counts as a use of the object pointed to. */
2078 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2079 DECL_INITIAL (decl
) = error_mark_node
;
2081 TREE_STATIC (decl
) = 1;
2085 /* ifuncs are also aliases, so set that attribute too. */
2086 DECL_ATTRIBUTES (decl
)
2087 = tree_cons (get_identifier ("alias"), args
,
2088 DECL_ATTRIBUTES (decl
));
2089 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("ifunc"),
2090 NULL
, DECL_ATTRIBUTES (decl
));
2095 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2096 *no_add_attrs
= true;
2099 if (decl_in_symtab_p (*node
))
2101 struct symtab_node
*n
= symtab_node::get (decl
);
2102 if (n
&& n
->refuse_visibility_changes
)
2105 error ("%+qD declared alias after being used", decl
);
2107 error ("%+qD declared ifunc after being used", decl
);
2115 /* Handle an "alias" or "ifunc" attribute; arguments as in
2116 struct attribute_spec.handler. */
2119 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
2120 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2122 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
2125 /* Handle an "alias" or "ifunc" attribute; arguments as in
2126 struct attribute_spec.handler. */
2129 handle_alias_attribute (tree
*node
, tree name
, tree args
,
2130 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2132 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
2135 /* Handle a "weakref" attribute; arguments as in struct
2136 attribute_spec.handler. */
2139 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2140 int flags
, bool *no_add_attrs
)
2142 tree attr
= NULL_TREE
;
2144 /* We must ignore the attribute when it is associated with
2145 local-scoped decls, since attribute alias is ignored and many
2146 such symbols do not even have a DECL_WEAK field. */
2147 if (decl_function_context (*node
)
2148 || current_function_decl
2149 || !VAR_OR_FUNCTION_DECL_P (*node
))
2151 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2152 *no_add_attrs
= true;
2156 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
2158 error ("indirect function %q+D cannot be declared weakref", *node
);
2159 *no_add_attrs
= true;
2163 /* The idea here is that `weakref("name")' mutates into `weakref,
2164 alias("name")', and weakref without arguments, in turn,
2165 implicitly adds weak. */
2169 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
2170 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
2172 *no_add_attrs
= true;
2174 decl_attributes (node
, attr
, flags
);
2178 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
2179 error_at (DECL_SOURCE_LOCATION (*node
),
2180 "weakref attribute must appear before alias attribute");
2182 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2183 and that isn't supported; and because it wants to add it to
2184 the list of weak decls, which isn't helpful. */
2185 DECL_WEAK (*node
) = 1;
2188 if (decl_in_symtab_p (*node
))
2190 struct symtab_node
*n
= symtab_node::get (*node
);
2191 if (n
&& n
->refuse_visibility_changes
)
2192 error ("%+qD declared weakref after being used", *node
);
2198 /* Handle an "visibility" attribute; arguments as in
2199 struct attribute_spec.handler. */
2202 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
2203 int ARG_UNUSED (flags
),
2204 bool *ARG_UNUSED (no_add_attrs
))
2207 tree id
= TREE_VALUE (args
);
2208 enum symbol_visibility vis
;
2212 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
2214 else if (!RECORD_OR_UNION_TYPE_P (*node
))
2216 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
2220 else if (TYPE_FIELDS (*node
))
2222 error ("%qE attribute ignored because %qT is already defined",
2227 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
2229 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2233 if (TREE_CODE (id
) != STRING_CST
)
2235 error ("visibility argument not a string");
2239 /* If this is a type, set the visibility on the type decl. */
2242 decl
= TYPE_NAME (decl
);
2245 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
2247 warning (OPT_Wattributes
, "%qE attribute ignored on types",
2253 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
2254 vis
= VISIBILITY_DEFAULT
;
2255 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
2256 vis
= VISIBILITY_INTERNAL
;
2257 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
2258 vis
= VISIBILITY_HIDDEN
;
2259 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
2260 vis
= VISIBILITY_PROTECTED
;
2263 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2264 vis
= VISIBILITY_DEFAULT
;
2267 if (DECL_VISIBILITY_SPECIFIED (decl
)
2268 && vis
!= DECL_VISIBILITY (decl
))
2270 tree attributes
= (TYPE_P (*node
)
2271 ? TYPE_ATTRIBUTES (*node
)
2272 : DECL_ATTRIBUTES (decl
));
2273 if (lookup_attribute ("visibility", attributes
))
2274 error ("%qD redeclared with different visibility", decl
);
2275 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2276 && lookup_attribute ("dllimport", attributes
))
2277 error ("%qD was declared %qs which implies default visibility",
2279 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2280 && lookup_attribute ("dllexport", attributes
))
2281 error ("%qD was declared %qs which implies default visibility",
2285 DECL_VISIBILITY (decl
) = vis
;
2286 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
2288 /* Go ahead and attach the attribute to the node as well. This is needed
2289 so we can determine whether we have VISIBILITY_DEFAULT because the
2290 visibility was not specified, or because it was explicitly overridden
2291 from the containing scope. */
2296 /* Handle an "tls_model" attribute; arguments as in
2297 struct attribute_spec.handler. */
2300 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
2301 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2305 enum tls_model kind
;
2307 *no_add_attrs
= true;
2309 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
2311 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2315 kind
= DECL_TLS_MODEL (decl
);
2316 id
= TREE_VALUE (args
);
2317 if (TREE_CODE (id
) != STRING_CST
)
2319 error ("tls_model argument not a string");
2323 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
2324 kind
= TLS_MODEL_LOCAL_EXEC
;
2325 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
2326 kind
= TLS_MODEL_INITIAL_EXEC
;
2327 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
2328 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
2329 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
2330 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
2332 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2334 set_decl_tls_model (decl
, kind
);
2338 /* Handle a "no_instrument_function" attribute; arguments as in
2339 struct attribute_spec.handler. */
2342 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2343 tree
ARG_UNUSED (args
),
2344 int ARG_UNUSED (flags
),
2349 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2351 error_at (DECL_SOURCE_LOCATION (decl
),
2352 "%qE attribute applies only to functions", name
);
2353 *no_add_attrs
= true;
2356 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2361 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2362 struct attribute_spec.handler. */
2365 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
2366 int, bool *no_add_attrs
)
2368 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2370 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2371 *no_add_attrs
= true;
2377 /* Handle a "malloc" attribute; arguments as in
2378 struct attribute_spec.handler. */
2381 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2382 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2384 if (TREE_CODE (*node
) == FUNCTION_DECL
2385 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
2386 DECL_IS_MALLOC (*node
) = 1;
2389 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2390 *no_add_attrs
= true;
2396 /* Handle a "alloc_size" attribute; arguments as in
2397 struct attribute_spec.handler. */
2400 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2401 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2403 unsigned arg_count
= type_num_arguments (*node
);
2404 for (; args
; args
= TREE_CHAIN (args
))
2406 tree position
= TREE_VALUE (args
);
2407 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2408 && TREE_CODE (position
) != FUNCTION_DECL
)
2409 position
= default_conversion (position
);
2411 if (!tree_fits_uhwi_p (position
)
2413 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2415 warning (OPT_Wattributes
,
2416 "alloc_size parameter outside range");
2417 *no_add_attrs
= true;
2424 /* Handle a "alloc_align" attribute; arguments as in
2425 struct attribute_spec.handler. */
2428 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
2431 unsigned arg_count
= type_num_arguments (*node
);
2432 tree position
= TREE_VALUE (args
);
2433 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2434 && TREE_CODE (position
) != FUNCTION_DECL
)
2435 position
= default_conversion (position
);
2437 if (!tree_fits_uhwi_p (position
)
2439 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2441 warning (OPT_Wattributes
,
2442 "alloc_align parameter outside range");
2443 *no_add_attrs
= true;
2449 /* Handle a "assume_aligned" attribute; arguments as in
2450 struct attribute_spec.handler. */
2453 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
2456 for (; args
; args
= TREE_CHAIN (args
))
2458 tree position
= TREE_VALUE (args
);
2459 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2460 && TREE_CODE (position
) != FUNCTION_DECL
)
2461 position
= default_conversion (position
);
2463 if (TREE_CODE (position
) != INTEGER_CST
)
2465 warning (OPT_Wattributes
,
2466 "assume_aligned parameter not integer constant");
2467 *no_add_attrs
= true;
2474 /* Handle a "fn spec" attribute; arguments as in
2475 struct attribute_spec.handler. */
2478 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
2479 tree args
, int ARG_UNUSED (flags
),
2480 bool *no_add_attrs ATTRIBUTE_UNUSED
)
2483 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2484 && !TREE_CHAIN (args
));
2488 /* Handle a "bnd_variable_size" attribute; arguments as in
2489 struct attribute_spec.handler. */
2492 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2493 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2495 if (TREE_CODE (*node
) != FIELD_DECL
)
2497 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2498 *no_add_attrs
= true;
2504 /* Handle a "bnd_legacy" attribute; arguments as in
2505 struct attribute_spec.handler. */
2508 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2509 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2511 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2513 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2514 *no_add_attrs
= true;
2520 /* Handle a "bnd_instrument" attribute; arguments as in
2521 struct attribute_spec.handler. */
2524 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2525 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2527 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2529 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2530 *no_add_attrs
= true;
2536 /* Handle a "warn_unused" attribute; arguments as in
2537 struct attribute_spec.handler. */
2540 handle_warn_unused_attribute (tree
*node
, tree name
,
2541 tree args ATTRIBUTE_UNUSED
,
2542 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2545 /* Do nothing else, just set the attribute. We'll get at
2546 it later with lookup_attribute. */
2550 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2551 *no_add_attrs
= true;
2557 /* Handle an "omp declare simd" attribute; arguments as in
2558 struct attribute_spec.handler. */
2561 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2566 /* Handle a "simd" attribute. */
2569 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
2571 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2573 tree t
= get_identifier ("omp declare simd");
2574 tree attr
= NULL_TREE
;
2577 tree id
= TREE_VALUE (args
);
2579 if (TREE_CODE (id
) != STRING_CST
)
2581 error ("attribute %qE argument not a string", name
);
2582 *no_add_attrs
= true;
2586 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
2587 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2588 OMP_CLAUSE_NOTINBRANCH
);
2589 else if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
2590 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2591 OMP_CLAUSE_INBRANCH
);
2594 error ("only %<inbranch%> and %<notinbranch%> flags are "
2595 "allowed for %<__simd__%> attribute");
2596 *no_add_attrs
= true;
2601 DECL_ATTRIBUTES (*node
)
2602 = tree_cons (t
, build_tree_list (NULL_TREE
, attr
),
2603 DECL_ATTRIBUTES (*node
));
2607 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2608 *no_add_attrs
= true;
2614 /* Handle an "omp declare target" attribute; arguments as in
2615 struct attribute_spec.handler. */
2618 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2623 /* Handle a "returns_twice" attribute; arguments as in
2624 struct attribute_spec.handler. */
2627 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2628 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2630 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2631 DECL_IS_RETURNS_TWICE (*node
) = 1;
2634 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2635 *no_add_attrs
= true;
2641 /* Handle a "no_limit_stack" attribute; arguments as in
2642 struct attribute_spec.handler. */
2645 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2646 tree
ARG_UNUSED (args
),
2647 int ARG_UNUSED (flags
),
2652 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2654 error_at (DECL_SOURCE_LOCATION (decl
),
2655 "%qE attribute applies only to functions", name
);
2656 *no_add_attrs
= true;
2658 else if (DECL_INITIAL (decl
))
2660 error_at (DECL_SOURCE_LOCATION (decl
),
2661 "can%'t set %qE attribute after definition", name
);
2662 *no_add_attrs
= true;
2665 DECL_NO_LIMIT_STACK (decl
) = 1;
2670 /* Handle a "pure" attribute; arguments as in
2671 struct attribute_spec.handler. */
2674 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2675 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2677 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2679 tree type
= TREE_TYPE (*node
);
2680 if (VOID_TYPE_P (TREE_TYPE (type
)))
2681 warning (OPT_Wattributes
, "%qE attribute on function "
2682 "returning %<void%>", name
);
2684 DECL_PURE_P (*node
) = 1;
2685 /* ??? TODO: Support types. */
2689 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2690 *no_add_attrs
= true;
2696 /* Digest an attribute list destined for a transactional memory statement.
2697 ALLOWED is the set of attributes that are allowed for this statement;
2698 return the attribute we parsed. Multiple attributes are never allowed. */
2701 parse_tm_stmt_attr (tree attrs
, int allowed
)
2706 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2708 tree a
= TREE_PURPOSE (attrs
);
2711 if (is_attribute_p ("outer", a
))
2712 m
= TM_STMT_ATTR_OUTER
;
2714 if ((m
& allowed
) == 0)
2716 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
2725 else if (m_seen
== m
)
2726 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2728 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
2734 /* Transform a TM attribute name into a maskable integer and back.
2735 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2736 to how the lack of an attribute is treated. */
2739 tm_attr_to_mask (tree attr
)
2743 if (is_attribute_p ("transaction_safe", attr
))
2744 return TM_ATTR_SAFE
;
2745 if (is_attribute_p ("transaction_callable", attr
))
2746 return TM_ATTR_CALLABLE
;
2747 if (is_attribute_p ("transaction_pure", attr
))
2748 return TM_ATTR_PURE
;
2749 if (is_attribute_p ("transaction_unsafe", attr
))
2750 return TM_ATTR_IRREVOCABLE
;
2751 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
2752 return TM_ATTR_MAY_CANCEL_OUTER
;
2757 tm_mask_to_attr (int mask
)
2763 str
= "transaction_safe";
2765 case TM_ATTR_CALLABLE
:
2766 str
= "transaction_callable";
2769 str
= "transaction_pure";
2771 case TM_ATTR_IRREVOCABLE
:
2772 str
= "transaction_unsafe";
2774 case TM_ATTR_MAY_CANCEL_OUTER
:
2775 str
= "transaction_may_cancel_outer";
2780 return get_identifier (str
);
2783 /* Return the first TM attribute seen in LIST. */
2786 find_tm_attribute (tree list
)
2788 for (; list
; list
= TREE_CHAIN (list
))
2790 tree name
= TREE_PURPOSE (list
);
2791 if (tm_attr_to_mask (name
) != 0)
2797 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2798 Here we accept only function types, and verify that none of the other
2799 function TM attributes are also applied. */
2800 /* ??? We need to accept class types for C++, but not C. This greatly
2801 complicates this function, since we can no longer rely on the extra
2802 processing given by function_type_required. */
2805 handle_tm_attribute (tree
*node
, tree name
, tree args
,
2806 int flags
, bool *no_add_attrs
)
2808 /* Only one path adds the attribute; others don't. */
2809 *no_add_attrs
= true;
2811 switch (TREE_CODE (*node
))
2815 /* Only tm_callable and tm_safe apply to classes. */
2816 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
2823 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
2824 if (old_name
== name
)
2826 else if (old_name
!= NULL_TREE
)
2827 error ("type was previously declared %qE", old_name
);
2829 *no_add_attrs
= false;
2835 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2836 want to set transaction_safe on the type. */
2837 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
2838 if (!TYPE_P (DECL_CONTEXT (*node
)))
2839 error_at (DECL_SOURCE_LOCATION (*node
),
2840 "%<transaction_safe_dynamic%> may only be specified for "
2841 "a virtual function");
2842 *no_add_attrs
= false;
2843 decl_attributes (&TREE_TYPE (*node
),
2844 build_tree_list (get_identifier ("transaction_safe"),
2852 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
2853 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
2855 tree fn_tmp
= TREE_TYPE (*node
);
2856 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
2857 *node
= build_pointer_type (fn_tmp
);
2864 /* If a function is next, pass it on to be tried next. */
2865 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
2866 return tree_cons (name
, args
, NULL
);
2869 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2876 /* Handle the TM_WRAP attribute; arguments as in
2877 struct attribute_spec.handler. */
2880 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2881 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2885 /* We don't need the attribute even on success, since we
2886 record the entry in an external table. */
2887 *no_add_attrs
= true;
2889 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2890 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2893 tree wrap_decl
= TREE_VALUE (args
);
2894 if (error_operand_p (wrap_decl
))
2896 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
2897 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
2898 error ("%qE argument not an identifier", name
);
2901 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
2902 wrap_decl
= lookup_name (wrap_decl
);
2903 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
2905 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
2906 TREE_TYPE (wrap_decl
)))
2907 record_tm_replacement (wrap_decl
, decl
);
2909 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2912 error ("%qE argument is not a function", name
);
2919 /* Ignore the given attribute. Used when this attribute may be usefully
2920 overridden by the target, but is not used generically. */
2923 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2924 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2927 *no_add_attrs
= true;
2931 /* Handle a "no vops" attribute; arguments as in
2932 struct attribute_spec.handler. */
2935 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2936 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2937 bool *ARG_UNUSED (no_add_attrs
))
2939 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
2940 DECL_IS_NOVOPS (*node
) = 1;
2944 /* Handle a "deprecated" attribute; arguments as in
2945 struct attribute_spec.handler. */
2948 handle_deprecated_attribute (tree
*node
, tree name
,
2949 tree args
, int flags
,
2952 tree type
= NULL_TREE
;
2954 tree what
= NULL_TREE
;
2957 *no_add_attrs
= true;
2958 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
2960 error ("deprecated message is not a string");
2961 *no_add_attrs
= true;
2967 type
= TREE_TYPE (decl
);
2969 if (TREE_CODE (decl
) == TYPE_DECL
2970 || TREE_CODE (decl
) == PARM_DECL
2971 || VAR_OR_FUNCTION_DECL_P (decl
)
2972 || TREE_CODE (decl
) == FIELD_DECL
2973 || TREE_CODE (decl
) == CONST_DECL
2974 || objc_method_decl (TREE_CODE (decl
)))
2975 TREE_DEPRECATED (decl
) = 1;
2979 else if (TYPE_P (*node
))
2981 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2982 *node
= build_variant_type_copy (*node
);
2983 TREE_DEPRECATED (*node
) = 1;
2991 *no_add_attrs
= true;
2992 if (type
&& TYPE_NAME (type
))
2994 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
2995 what
= TYPE_NAME (*node
);
2996 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
2997 && DECL_NAME (TYPE_NAME (type
)))
2998 what
= DECL_NAME (TYPE_NAME (type
));
3001 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
3003 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3009 /* Handle a "vector_size" attribute; arguments as in
3010 struct attribute_spec.handler. */
3013 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
3014 int ARG_UNUSED (flags
),
3017 unsigned HOST_WIDE_INT vecsize
, nunits
;
3018 machine_mode orig_mode
;
3019 tree type
= *node
, new_type
, size
;
3021 *no_add_attrs
= true;
3023 size
= TREE_VALUE (args
);
3024 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
3025 && TREE_CODE (size
) != FUNCTION_DECL
)
3026 size
= default_conversion (size
);
3028 if (!tree_fits_uhwi_p (size
))
3030 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3034 /* Get the vector size (in bytes). */
3035 vecsize
= tree_to_uhwi (size
);
3037 /* We need to provide for vector pointers, vector arrays, and
3038 functions returning vectors. For example:
3040 __attribute__((vector_size(16))) short *foo;
3042 In this case, the mode is SI, but the type being modified is
3043 HI, so we need to look further. */
3045 while (POINTER_TYPE_P (type
)
3046 || TREE_CODE (type
) == FUNCTION_TYPE
3047 || TREE_CODE (type
) == METHOD_TYPE
3048 || TREE_CODE (type
) == ARRAY_TYPE
3049 || TREE_CODE (type
) == OFFSET_TYPE
)
3050 type
= TREE_TYPE (type
);
3052 /* Get the mode of the type being modified. */
3053 orig_mode
= TYPE_MODE (type
);
3055 if ((!INTEGRAL_TYPE_P (type
)
3056 && !SCALAR_FLOAT_TYPE_P (type
)
3057 && !FIXED_POINT_TYPE_P (type
))
3058 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
3059 && GET_MODE_CLASS (orig_mode
) != MODE_INT
3060 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
3061 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
3062 || TREE_CODE (type
) == BOOLEAN_TYPE
)
3064 error ("invalid vector type for attribute %qE", name
);
3068 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
3070 error ("vector size not an integral multiple of component size");
3076 error ("zero vector size");
3080 /* Calculate how many units fit in the vector. */
3081 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
3082 if (nunits
& (nunits
- 1))
3084 error ("number of components of the vector not a power of two");
3088 new_type
= build_vector_type (type
, nunits
);
3090 /* Build back pointers if needed. */
3091 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
3096 /* Handle the "nonnull" attribute. */
3099 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3100 tree args
, int ARG_UNUSED (flags
),
3104 unsigned HOST_WIDE_INT attr_arg_num
;
3106 /* If no arguments are specified, all pointer arguments should be
3107 non-null. Verify a full prototype is given so that the arguments
3108 will have the correct types when we actually check them later.
3109 Avoid diagnosing type-generic built-ins since those have no
3113 if (!prototype_p (type
)
3114 && (!TYPE_ATTRIBUTES (type
)
3115 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
3117 error ("nonnull attribute without arguments on a non-prototype");
3118 *no_add_attrs
= true;
3123 /* Argument list specified. Verify that each argument number references
3124 a pointer argument. */
3125 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
3127 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
3129 tree arg
= TREE_VALUE (args
);
3130 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
3131 && TREE_CODE (arg
) != FUNCTION_DECL
)
3132 TREE_VALUE (args
) = arg
= default_conversion (arg
);
3134 if (!get_nonnull_operand (arg
, &arg_num
))
3136 error ("nonnull argument has invalid operand number (argument %lu)",
3137 (unsigned long) attr_arg_num
);
3138 *no_add_attrs
= true;
3142 if (prototype_p (type
))
3144 function_args_iterator iter
;
3147 function_args_iter_init (&iter
, type
);
3148 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
3150 argument
= function_args_iter_cond (&iter
);
3151 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
3156 || TREE_CODE (argument
) == VOID_TYPE
)
3158 error ("nonnull argument with out-of-range operand number "
3159 "(argument %lu, operand %lu)",
3160 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3161 *no_add_attrs
= true;
3165 if (TREE_CODE (argument
) != POINTER_TYPE
)
3167 error ("nonnull argument references non-pointer operand "
3168 "(argument %lu, operand %lu)",
3169 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3170 *no_add_attrs
= true;
3179 /* Handle the "nonstring" variable attribute. */
3182 handle_nonstring_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3183 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3186 tree_code code
= TREE_CODE (*node
);
3189 || code
== FIELD_DECL
3190 || code
== PARM_DECL
)
3192 tree type
= TREE_TYPE (*node
);
3194 if (POINTER_TYPE_P (type
) || TREE_CODE (type
) == ARRAY_TYPE
)
3196 tree eltype
= TREE_TYPE (type
);
3197 if (eltype
== char_type_node
)
3201 warning (OPT_Wattributes
,
3202 "%qE attribute ignored on objects of type %qT",
3204 *no_add_attrs
= true;
3208 if (code
== FUNCTION_DECL
)
3209 warning (OPT_Wattributes
,
3210 "%qE attribute does not apply to functions", name
);
3211 else if (code
== TYPE_DECL
)
3212 warning (OPT_Wattributes
,
3213 "%qE attribute does not apply to types", name
);
3215 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3217 *no_add_attrs
= true;
3221 /* Handle a "nothrow" attribute; arguments as in
3222 struct attribute_spec.handler. */
3225 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3226 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3228 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3229 TREE_NOTHROW (*node
) = 1;
3230 /* ??? TODO: Support types. */
3233 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3234 *no_add_attrs
= true;
3240 /* Handle a "cleanup" attribute; arguments as in
3241 struct attribute_spec.handler. */
3244 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
3245 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3248 tree cleanup_id
, cleanup_decl
;
3250 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3251 for global destructors in C++. This requires infrastructure that
3252 we don't have generically at the moment. It's also not a feature
3253 we'd be missing too much, since we do have attribute constructor. */
3254 if (!VAR_P (decl
) || TREE_STATIC (decl
))
3256 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3257 *no_add_attrs
= true;
3261 /* Verify that the argument is a function in scope. */
3262 /* ??? We could support pointers to functions here as well, if
3263 that was considered desirable. */
3264 cleanup_id
= TREE_VALUE (args
);
3265 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
3267 error ("cleanup argument not an identifier");
3268 *no_add_attrs
= true;
3271 cleanup_decl
= lookup_name (cleanup_id
);
3272 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
3274 error ("cleanup argument not a function");
3275 *no_add_attrs
= true;
3279 /* That the function has proper type is checked with the
3280 eventual call to build_function_call. */
3285 /* Handle a "warn_unused_result" attribute. No special handling. */
3288 handle_warn_unused_result_attribute (tree
*node
, tree name
,
3289 tree
ARG_UNUSED (args
),
3290 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3292 /* Ignore the attribute for functions not returning any value. */
3293 if (VOID_TYPE_P (TREE_TYPE (*node
)))
3295 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3296 *no_add_attrs
= true;
3302 /* Handle a "sentinel" attribute. */
3305 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
3306 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3308 if (!prototype_p (*node
))
3310 warning (OPT_Wattributes
,
3311 "%qE attribute requires prototypes with named arguments", name
);
3312 *no_add_attrs
= true;
3316 if (!stdarg_p (*node
))
3318 warning (OPT_Wattributes
,
3319 "%qE attribute only applies to variadic functions", name
);
3320 *no_add_attrs
= true;
3326 tree position
= TREE_VALUE (args
);
3327 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
3328 && TREE_CODE (position
) != FUNCTION_DECL
)
3329 position
= default_conversion (position
);
3331 if (TREE_CODE (position
) != INTEGER_CST
3332 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
3334 warning (OPT_Wattributes
,
3335 "requested position is not an integer constant");
3336 *no_add_attrs
= true;
3340 if (tree_int_cst_lt (position
, integer_zero_node
))
3342 warning (OPT_Wattributes
,
3343 "requested position is less than zero");
3344 *no_add_attrs
= true;
3352 /* Handle a "type_generic" attribute. */
3355 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3356 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
3357 bool * ARG_UNUSED (no_add_attrs
))
3359 /* Ensure we have a function type. */
3360 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
3362 /* Ensure we have a variadic function. */
3363 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
3368 /* Handle a "target" attribute. */
3371 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3374 /* Ensure we have a function type. */
3375 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3377 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3378 *no_add_attrs
= true;
3380 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3382 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3383 "with %qs attribute", name
, "target_clones");
3384 *no_add_attrs
= true;
3386 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3388 *no_add_attrs
= true;
3390 /* Check that there's no empty string in values of the attribute. */
3391 for (tree t
= args
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
3393 tree value
= TREE_VALUE (t
);
3394 if (TREE_CODE (value
) == STRING_CST
3395 && TREE_STRING_LENGTH (value
) == 1
3396 && TREE_STRING_POINTER (value
)[0] == '\0')
3398 warning (OPT_Wattributes
, "empty string in attribute %<target%>");
3399 *no_add_attrs
= true;
3406 /* Handle a "target_clones" attribute. */
3409 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3410 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3412 /* Ensure we have a function type. */
3413 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3415 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3417 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3418 "with %qs attribute", name
, "always_inline");
3419 *no_add_attrs
= true;
3421 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3423 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3424 "with %qs attribute", name
, "target");
3425 *no_add_attrs
= true;
3428 /* Do not inline functions with multiple clone targets. */
3429 DECL_UNINLINABLE (*node
) = 1;
3433 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3434 *no_add_attrs
= true;
3439 /* For handling "optimize" attribute. arguments as in
3440 struct attribute_spec.handler. */
3443 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3444 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3446 /* Ensure we have a function type. */
3447 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3449 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3450 *no_add_attrs
= true;
3454 struct cl_optimization cur_opts
;
3455 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3457 /* Save current options. */
3458 cl_optimization_save (&cur_opts
, &global_options
);
3460 /* If we previously had some optimization options, use them as the
3463 cl_optimization_restore (&global_options
,
3464 TREE_OPTIMIZATION (old_opts
));
3466 /* Parse options, and update the vector. */
3467 parse_optimize_options (args
, true);
3468 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3469 = build_optimization_node (&global_options
);
3471 /* Restore current options. */
3472 cl_optimization_restore (&global_options
, &cur_opts
);
3478 /* Handle a "no_split_stack" attribute. */
3481 handle_no_split_stack_attribute (tree
*node
, tree name
,
3482 tree
ARG_UNUSED (args
),
3483 int ARG_UNUSED (flags
),
3488 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3490 error_at (DECL_SOURCE_LOCATION (decl
),
3491 "%qE attribute applies only to functions", name
);
3492 *no_add_attrs
= true;
3494 else if (DECL_INITIAL (decl
))
3496 error_at (DECL_SOURCE_LOCATION (decl
),
3497 "can%'t set %qE attribute after definition", name
);
3498 *no_add_attrs
= true;
3504 /* Handle a "returns_nonnull" attribute; arguments as in
3505 struct attribute_spec.handler. */
3508 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3511 // Even without a prototype we still have a return type we can check.
3512 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3514 error ("returns_nonnull attribute on a function not returning a pointer");
3515 *no_add_attrs
= true;
3520 /* Handle a "designated_init" attribute; arguments as in
3521 struct attribute_spec.handler. */
3524 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3527 if (TREE_CODE (*node
) != RECORD_TYPE
)
3529 error ("%qE attribute is only valid on %<struct%> type", name
);
3530 *no_add_attrs
= true;
3536 /* Handle a "fallthrough" attribute; arguments as in struct
3537 attribute_spec.handler. */
3540 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3543 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3544 *no_add_attrs
= true;
3549 handle_patchable_function_entry_attribute (tree
*, tree
, tree
, int, bool *)
3551 /* Nothing to be done here. */