1 /* C-family attributes handling.
2 Copyright (C) 1992-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
28 #include "gimple-expr.h"
30 #include "stringpool.h"
32 #include "diagnostic.h"
34 #include "stor-layout.h"
38 #include "trans-mem.h"
40 #include "common/common-target.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
44 #include "tree-iterator.h"
48 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
49 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
50 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
51 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
52 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
53 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
54 static tree
handle_no_sanitize_attribute (tree
*, tree
, tree
, int, bool *);
55 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
57 static tree
handle_no_sanitize_thread_attribute (tree
*, tree
, tree
,
59 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
61 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
63 static tree
handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int,
65 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
66 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
67 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
68 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
69 static tree
handle_noipa_attribute (tree
*, tree
, tree
, int, bool *);
70 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
71 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
73 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
74 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
75 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
76 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
77 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
78 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
80 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
82 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
83 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
85 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
87 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
88 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
89 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
90 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
91 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
92 static tree
handle_warn_if_not_aligned_attribute (tree
*, tree
, tree
,
94 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
95 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
96 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
97 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
98 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
99 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
100 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
102 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
104 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
106 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
108 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
109 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
110 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
112 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
113 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
114 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
115 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
116 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
118 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
120 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
121 static tree
handle_nonstring_attribute (tree
*, tree
, tree
, int, bool *);
122 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
123 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
124 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
126 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
127 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
128 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
129 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
130 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
131 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
132 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
133 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
134 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
135 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
136 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
137 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
138 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
139 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
141 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
142 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
144 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
145 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
146 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
147 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
148 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
149 static tree
handle_patchable_function_entry_attribute (tree
*, tree
, tree
,
152 /* Table of machine-independent attributes common to all C-like languages.
154 All attributes referencing arguments should be additionally processed
155 in chkp_copy_function_type_adding_bounds for correct instrumentation
156 by Pointer Bounds Checker.
157 Current list of processed common attributes: nonnull. */
158 const struct attribute_spec c_common_attribute_table
[] =
160 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
161 affects_type_identity } */
162 { "packed", 0, 0, false, false, false,
163 handle_packed_attribute
, false},
164 { "nocommon", 0, 0, true, false, false,
165 handle_nocommon_attribute
, false},
166 { "common", 0, 0, true, false, false,
167 handle_common_attribute
, false },
168 /* FIXME: logically, noreturn attributes should be listed as
169 "false, true, true" and apply to function types. But implementing this
170 would require all the places in the compiler that use TREE_THIS_VOLATILE
171 on a decl to identify non-returning functions to be located and fixed
172 to check the function type instead. */
173 { "noreturn", 0, 0, true, false, false,
174 handle_noreturn_attribute
, false },
175 { "volatile", 0, 0, true, false, false,
176 handle_noreturn_attribute
, false },
177 { "stack_protect", 0, 0, true, false, false,
178 handle_stack_protect_attribute
, false },
179 { "noinline", 0, 0, true, false, false,
180 handle_noinline_attribute
, false },
181 { "noclone", 0, 0, true, false, false,
182 handle_noclone_attribute
, false },
183 { "no_icf", 0, 0, true, false, false,
184 handle_noicf_attribute
, false },
185 { "noipa", 0, 0, true, false, false,
186 handle_noipa_attribute
, false },
187 { "leaf", 0, 0, true, false, false,
188 handle_leaf_attribute
, false },
189 { "always_inline", 0, 0, true, false, false,
190 handle_always_inline_attribute
, false },
191 { "gnu_inline", 0, 0, true, false, false,
192 handle_gnu_inline_attribute
, false },
193 { "artificial", 0, 0, true, false, false,
194 handle_artificial_attribute
, false },
195 { "flatten", 0, 0, true, false, false,
196 handle_flatten_attribute
, false },
197 { "used", 0, 0, true, false, false,
198 handle_used_attribute
, false },
199 { "unused", 0, 0, false, false, false,
200 handle_unused_attribute
, false },
201 { "externally_visible", 0, 0, true, false, false,
202 handle_externally_visible_attribute
, false },
203 { "no_reorder", 0, 0, true, false, false,
204 handle_no_reorder_attribute
, false },
205 /* The same comments as for noreturn attributes apply to const ones. */
206 { "const", 0, 0, true, false, false,
207 handle_const_attribute
, false },
208 { "scalar_storage_order", 1, 1, false, false, false,
209 handle_scalar_storage_order_attribute
, false },
210 { "transparent_union", 0, 0, false, false, false,
211 handle_transparent_union_attribute
, false },
212 { "constructor", 0, 1, true, false, false,
213 handle_constructor_attribute
, false },
214 { "destructor", 0, 1, true, false, false,
215 handle_destructor_attribute
, false },
216 { "mode", 1, 1, false, true, false,
217 handle_mode_attribute
, false },
218 { "section", 1, 1, true, false, false,
219 handle_section_attribute
, false },
220 { "aligned", 0, 1, false, false, false,
221 handle_aligned_attribute
, false },
222 { "warn_if_not_aligned", 0, 1, false, false, false,
223 handle_warn_if_not_aligned_attribute
,
225 { "weak", 0, 0, true, false, false,
226 handle_weak_attribute
, false },
227 { "noplt", 0, 0, true, false, false,
228 handle_noplt_attribute
, false },
229 { "ifunc", 1, 1, true, false, false,
230 handle_ifunc_attribute
, false },
231 { "alias", 1, 1, true, false, false,
232 handle_alias_attribute
, false },
233 { "weakref", 0, 1, true, false, false,
234 handle_weakref_attribute
, false },
235 { "no_instrument_function", 0, 0, true, false, false,
236 handle_no_instrument_function_attribute
,
238 { "no_profile_instrument_function", 0, 0, true, false, false,
239 handle_no_profile_instrument_function_attribute
,
241 { "malloc", 0, 0, true, false, false,
242 handle_malloc_attribute
, false },
243 { "returns_twice", 0, 0, true, false, false,
244 handle_returns_twice_attribute
, false },
245 { "no_stack_limit", 0, 0, true, false, false,
246 handle_no_limit_stack_attribute
, false },
247 { "pure", 0, 0, true, false, false,
248 handle_pure_attribute
, false },
249 { "transaction_callable", 0, 0, false, true, false,
250 handle_tm_attribute
, false },
251 { "transaction_unsafe", 0, 0, false, true, false,
252 handle_tm_attribute
, true },
253 { "transaction_safe", 0, 0, false, true, false,
254 handle_tm_attribute
, true },
255 { "transaction_safe_dynamic", 0, 0, true, false, false,
256 handle_tm_attribute
, false },
257 { "transaction_may_cancel_outer", 0, 0, false, true, false,
258 handle_tm_attribute
, false },
259 /* ??? These two attributes didn't make the transition from the
260 Intel language document to the multi-vendor language document. */
261 { "transaction_pure", 0, 0, false, true, false,
262 handle_tm_attribute
, false },
263 { "transaction_wrap", 1, 1, true, false, false,
264 handle_tm_wrap_attribute
, false },
265 /* For internal use (marking of builtins) only. The name contains space
266 to prevent its usage in source code. */
267 { "no vops", 0, 0, true, false, false,
268 handle_novops_attribute
, false },
269 { "deprecated", 0, 1, false, false, false,
270 handle_deprecated_attribute
, false },
271 { "vector_size", 1, 1, false, true, false,
272 handle_vector_size_attribute
, true },
273 { "visibility", 1, 1, false, false, false,
274 handle_visibility_attribute
, false },
275 { "tls_model", 1, 1, true, false, false,
276 handle_tls_model_attribute
, false },
277 { "nonnull", 0, -1, false, true, true,
278 handle_nonnull_attribute
, false },
279 { "nonstring", 0, 0, true, false, false,
280 handle_nonstring_attribute
, false },
281 { "nothrow", 0, 0, true, false, false,
282 handle_nothrow_attribute
, false },
283 { "may_alias", 0, 0, false, true, false, NULL
, false },
284 { "cleanup", 1, 1, true, false, false,
285 handle_cleanup_attribute
, false },
286 { "warn_unused_result", 0, 0, false, true, true,
287 handle_warn_unused_result_attribute
, false },
288 { "sentinel", 0, 1, false, true, true,
289 handle_sentinel_attribute
, false },
290 /* For internal use (marking of builtins) only. The name contains space
291 to prevent its usage in source code. */
292 { "type generic", 0, 0, false, true, true,
293 handle_type_generic_attribute
, false },
294 { "alloc_size", 1, 2, false, true, true,
295 handle_alloc_size_attribute
, false },
296 { "cold", 0, 0, true, false, false,
297 handle_cold_attribute
, false },
298 { "hot", 0, 0, true, false, false,
299 handle_hot_attribute
, false },
300 { "no_address_safety_analysis",
301 0, 0, true, false, false,
302 handle_no_address_safety_analysis_attribute
,
304 { "no_sanitize", 1, 1, true, false, false,
305 handle_no_sanitize_attribute
,
307 { "no_sanitize_address", 0, 0, true, false, false,
308 handle_no_sanitize_address_attribute
,
310 { "no_sanitize_thread", 0, 0, true, false, false,
311 handle_no_sanitize_thread_attribute
,
313 { "no_sanitize_undefined", 0, 0, true, false, false,
314 handle_no_sanitize_undefined_attribute
,
316 { "asan odr indicator", 0, 0, true, false, false,
317 handle_asan_odr_indicator_attribute
,
319 { "warning", 1, 1, true, false, false,
320 handle_error_attribute
, false },
321 { "error", 1, 1, true, false, false,
322 handle_error_attribute
, false },
323 { "target", 1, -1, true, false, false,
324 handle_target_attribute
, false },
325 { "target_clones", 1, -1, true, false, false,
326 handle_target_clones_attribute
, false },
327 { "optimize", 1, -1, true, false, false,
328 handle_optimize_attribute
, false },
329 /* For internal use only. The leading '*' both prevents its usage in
330 source code and signals that it may be overridden by machine tables. */
331 { "*tm regparm", 0, 0, false, true, true,
332 ignore_attribute
, false },
333 { "no_split_stack", 0, 0, true, false, false,
334 handle_no_split_stack_attribute
, false },
335 /* For internal use (marking of builtins and runtime functions) only.
336 The name contains space to prevent its usage in source code. */
337 { "fn spec", 1, 1, false, true, true,
338 handle_fnspec_attribute
, false },
339 { "warn_unused", 0, 0, false, false, false,
340 handle_warn_unused_attribute
, false },
341 { "returns_nonnull", 0, 0, false, true, true,
342 handle_returns_nonnull_attribute
, false },
343 { "omp declare simd", 0, -1, true, false, false,
344 handle_omp_declare_simd_attribute
, false },
345 { "cilk simd function", 0, -1, true, false, false,
346 handle_omp_declare_simd_attribute
, false },
347 { "simd", 0, 1, true, false, false,
348 handle_simd_attribute
, false },
349 { "omp declare target", 0, 0, true, false, false,
350 handle_omp_declare_target_attribute
, false },
351 { "omp declare target link", 0, 0, true, false, false,
352 handle_omp_declare_target_attribute
, false },
353 { "alloc_align", 1, 1, false, true, true,
354 handle_alloc_align_attribute
, false },
355 { "assume_aligned", 1, 2, false, true, true,
356 handle_assume_aligned_attribute
, false },
357 { "designated_init", 0, 0, false, true, false,
358 handle_designated_init_attribute
, false },
359 { "bnd_variable_size", 0, 0, true, false, false,
360 handle_bnd_variable_size_attribute
, false },
361 { "bnd_legacy", 0, 0, true, false, false,
362 handle_bnd_legacy
, false },
363 { "bnd_instrument", 0, 0, true, false, false,
364 handle_bnd_instrument
, false },
365 { "fallthrough", 0, 0, false, false, false,
366 handle_fallthrough_attribute
, false },
367 { "patchable_function_entry", 1, 2, true, false, false,
368 handle_patchable_function_entry_attribute
,
370 { NULL
, 0, 0, false, false, false, NULL
, false }
373 /* Give the specifications for the format attributes, used by C and all
376 All attributes referencing arguments should be additionally processed
377 in chkp_copy_function_type_adding_bounds for correct instrumentation
378 by Pointer Bounds Checker.
379 Current list of processed format attributes: format, format_arg. */
380 const struct attribute_spec c_common_format_attribute_table
[] =
382 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
383 affects_type_identity } */
384 { "format", 3, 3, false, true, true,
385 handle_format_attribute
, false },
386 { "format_arg", 1, 1, false, true, true,
387 handle_format_arg_attribute
, false },
388 { NULL
, 0, 0, false, false, false, NULL
, false }
391 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
392 identifier as an argument, so the front end shouldn't look it up. */
395 attribute_takes_identifier_p (const_tree attr_id
)
397 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
399 /* Unknown attribute that we'll end up ignoring, return true so we
400 don't complain about an identifier argument. */
402 else if (!strcmp ("mode", spec
->name
)
403 || !strcmp ("format", spec
->name
)
404 || !strcmp ("cleanup", spec
->name
))
407 return targetm
.attribute_takes_identifier_p (attr_id
);
410 /* Attribute handlers common to C front ends. */
412 /* Handle a "packed" attribute; arguments as in
413 struct attribute_spec.handler. */
416 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
417 int flags
, bool *no_add_attrs
)
421 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
422 *node
= build_variant_type_copy (*node
);
423 TYPE_PACKED (*node
) = 1;
425 else if (TREE_CODE (*node
) == FIELD_DECL
)
427 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
428 /* Still pack bitfields. */
429 && ! DECL_INITIAL (*node
))
430 warning (OPT_Wattributes
,
431 "%qE attribute ignored for field of type %qT",
432 name
, TREE_TYPE (*node
));
434 DECL_PACKED (*node
) = 1;
436 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
437 used for DECL_REGISTER. It wouldn't mean anything anyway.
438 We can't set DECL_PACKED on the type of a TYPE_DECL, because
439 that changes what the typedef is typing. */
442 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
443 *no_add_attrs
= true;
449 /* Handle a "nocommon" attribute; arguments as in
450 struct attribute_spec.handler. */
453 handle_nocommon_attribute (tree
*node
, tree name
,
454 tree
ARG_UNUSED (args
),
455 int ARG_UNUSED (flags
), bool *no_add_attrs
)
458 DECL_COMMON (*node
) = 0;
461 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
462 *no_add_attrs
= true;
468 /* Handle a "common" attribute; arguments as in
469 struct attribute_spec.handler. */
472 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
473 int ARG_UNUSED (flags
), bool *no_add_attrs
)
476 DECL_COMMON (*node
) = 1;
479 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
480 *no_add_attrs
= true;
486 /* Handle a "noreturn" attribute; arguments as in
487 struct attribute_spec.handler. */
490 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
491 int ARG_UNUSED (flags
), bool *no_add_attrs
)
493 tree type
= TREE_TYPE (*node
);
495 /* See FIXME comment in c_common_attribute_table. */
496 if (TREE_CODE (*node
) == FUNCTION_DECL
497 || objc_method_decl (TREE_CODE (*node
)))
498 TREE_THIS_VOLATILE (*node
) = 1;
499 else if (TREE_CODE (type
) == POINTER_TYPE
500 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
502 = (build_qualified_type
504 (build_type_variant (TREE_TYPE (type
),
505 TYPE_READONLY (TREE_TYPE (type
)), 1)),
509 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
510 *no_add_attrs
= true;
516 /* Handle a "hot" and attribute; arguments as in
517 struct attribute_spec.handler. */
520 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
521 int ARG_UNUSED (flags
), bool *no_add_attrs
)
523 if (TREE_CODE (*node
) == FUNCTION_DECL
524 || TREE_CODE (*node
) == LABEL_DECL
)
526 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
528 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
529 "with attribute %qs", name
, "cold");
530 *no_add_attrs
= true;
532 /* Most of the rest of the hot processing is done later with
537 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
538 *no_add_attrs
= true;
544 /* Handle a "cold" and attribute; arguments as in
545 struct attribute_spec.handler. */
548 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
549 int ARG_UNUSED (flags
), bool *no_add_attrs
)
551 if (TREE_CODE (*node
) == FUNCTION_DECL
552 || TREE_CODE (*node
) == LABEL_DECL
)
554 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
556 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
557 "with attribute %qs", name
, "hot");
558 *no_add_attrs
= true;
560 /* Most of the rest of the cold processing is done later with
565 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
566 *no_add_attrs
= true;
572 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
575 add_no_sanitize_value (tree node
, unsigned int flags
)
577 tree attr
= lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node
));
580 unsigned int old_value
= tree_to_uhwi (TREE_VALUE (attr
));
583 if (flags
== old_value
)
586 TREE_VALUE (attr
) = build_int_cst (unsigned_type_node
, flags
);
589 DECL_ATTRIBUTES (node
)
590 = tree_cons (get_identifier ("no_sanitize"),
591 build_int_cst (unsigned_type_node
, flags
),
592 DECL_ATTRIBUTES (node
));
595 /* Handle a "no_sanitize" attribute; arguments as in
596 struct attribute_spec.handler. */
599 handle_no_sanitize_attribute (tree
*node
, tree name
, tree args
, int,
602 *no_add_attrs
= true;
603 tree id
= TREE_VALUE (args
);
604 if (TREE_CODE (*node
) != FUNCTION_DECL
)
606 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
610 if (TREE_CODE (id
) != STRING_CST
)
612 error ("no_sanitize argument not a string");
616 char *error_value
= NULL
;
617 char *string
= ASTRDUP (TREE_STRING_POINTER (id
));
618 unsigned int flags
= parse_no_sanitize_attribute (string
, &error_value
);
622 error ("wrong argument: \"%s\"", error_value
);
626 add_no_sanitize_value (*node
, flags
);
631 /* Handle a "no_sanitize_address" attribute; arguments as in
632 struct attribute_spec.handler. */
635 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
638 *no_add_attrs
= true;
639 if (TREE_CODE (*node
) != FUNCTION_DECL
)
640 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
642 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
647 /* Handle a "no_sanitize_thread" attribute; arguments as in
648 struct attribute_spec.handler. */
651 handle_no_sanitize_thread_attribute (tree
*node
, tree name
, tree
, int,
654 *no_add_attrs
= true;
655 if (TREE_CODE (*node
) != FUNCTION_DECL
)
656 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
658 add_no_sanitize_value (*node
, SANITIZE_THREAD
);
664 /* Handle a "no_address_safety_analysis" attribute; arguments as in
665 struct attribute_spec.handler. */
668 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
671 *no_add_attrs
= true;
672 if (TREE_CODE (*node
) != FUNCTION_DECL
)
673 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
675 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
680 /* Handle a "no_sanitize_undefined" attribute; arguments as in
681 struct attribute_spec.handler. */
684 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
687 *no_add_attrs
= true;
688 if (TREE_CODE (*node
) != FUNCTION_DECL
)
689 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
691 add_no_sanitize_value (*node
,
692 SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
697 /* Handle an "asan odr indicator" attribute; arguments as in
698 struct attribute_spec.handler. */
701 handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int, bool *)
706 /* Handle a "stack_protect" attribute; arguments as in
707 struct attribute_spec.handler. */
710 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
713 if (TREE_CODE (*node
) != FUNCTION_DECL
)
715 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
716 *no_add_attrs
= true;
722 /* Handle a "noipa" attribute; arguments as in
723 struct attribute_spec.handler. */
726 handle_noipa_attribute (tree
*node
, tree name
, tree
, int, bool *no_add_attrs
)
728 if (TREE_CODE (*node
) != FUNCTION_DECL
)
730 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
731 *no_add_attrs
= true;
734 DECL_ATTRIBUTES (*node
)
735 = tree_cons (get_identifier ("stack_protect"),
736 NULL_TREE
, DECL_ATTRIBUTES (*node
));
741 /* Handle a "noinline" attribute; arguments as in
742 struct attribute_spec.handler. */
745 handle_noinline_attribute (tree
*node
, tree name
,
746 tree
ARG_UNUSED (args
),
747 int ARG_UNUSED (flags
), bool *no_add_attrs
)
749 if (TREE_CODE (*node
) == FUNCTION_DECL
)
751 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
753 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
754 "with attribute %qs", name
, "always_inline");
755 *no_add_attrs
= true;
758 DECL_UNINLINABLE (*node
) = 1;
762 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
763 *no_add_attrs
= true;
769 /* Handle a "noclone" attribute; arguments as in
770 struct attribute_spec.handler. */
773 handle_noclone_attribute (tree
*node
, tree name
,
774 tree
ARG_UNUSED (args
),
775 int ARG_UNUSED (flags
), bool *no_add_attrs
)
777 if (TREE_CODE (*node
) != FUNCTION_DECL
)
779 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
780 *no_add_attrs
= true;
786 /* Handle a "no_icf" attribute; arguments as in
787 struct attribute_spec.handler. */
790 handle_noicf_attribute (tree
*node
, tree name
,
791 tree
ARG_UNUSED (args
),
792 int ARG_UNUSED (flags
), bool *no_add_attrs
)
794 if (TREE_CODE (*node
) != FUNCTION_DECL
)
796 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
797 *no_add_attrs
= true;
804 /* Handle a "always_inline" attribute; arguments as in
805 struct attribute_spec.handler. */
808 handle_always_inline_attribute (tree
*node
, tree name
,
809 tree
ARG_UNUSED (args
),
810 int ARG_UNUSED (flags
),
813 if (TREE_CODE (*node
) == FUNCTION_DECL
)
815 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
817 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
818 "with %qs attribute", name
, "noinline");
819 *no_add_attrs
= true;
821 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
823 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
824 "with %qs attribute", name
, "target_clones");
825 *no_add_attrs
= true;
828 /* Set the attribute and mark it for disregarding inline
830 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
834 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
835 *no_add_attrs
= true;
841 /* Handle a "gnu_inline" attribute; arguments as in
842 struct attribute_spec.handler. */
845 handle_gnu_inline_attribute (tree
*node
, tree name
,
846 tree
ARG_UNUSED (args
),
847 int ARG_UNUSED (flags
),
850 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
852 /* Do nothing else, just set the attribute. We'll get at
853 it later with lookup_attribute. */
857 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
858 *no_add_attrs
= true;
864 /* Handle a "leaf" attribute; arguments as in
865 struct attribute_spec.handler. */
868 handle_leaf_attribute (tree
*node
, tree name
,
869 tree
ARG_UNUSED (args
),
870 int ARG_UNUSED (flags
), bool *no_add_attrs
)
872 if (TREE_CODE (*node
) != FUNCTION_DECL
)
874 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
875 *no_add_attrs
= true;
877 if (!TREE_PUBLIC (*node
))
879 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
881 *no_add_attrs
= true;
887 /* Handle an "artificial" attribute; arguments as in
888 struct attribute_spec.handler. */
891 handle_artificial_attribute (tree
*node
, tree name
,
892 tree
ARG_UNUSED (args
),
893 int ARG_UNUSED (flags
),
896 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
898 /* Do nothing else, just set the attribute. We'll get at
899 it later with lookup_attribute. */
903 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
904 *no_add_attrs
= true;
910 /* Handle a "flatten" attribute; arguments as in
911 struct attribute_spec.handler. */
914 handle_flatten_attribute (tree
*node
, tree name
,
915 tree args ATTRIBUTE_UNUSED
,
916 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
918 if (TREE_CODE (*node
) == FUNCTION_DECL
)
919 /* Do nothing else, just set the attribute. We'll get at
920 it later with lookup_attribute. */
924 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
925 *no_add_attrs
= true;
931 /* Handle a "warning" or "error" attribute; arguments as in
932 struct attribute_spec.handler. */
935 handle_error_attribute (tree
*node
, tree name
, tree args
,
936 int ARG_UNUSED (flags
), bool *no_add_attrs
)
938 if (TREE_CODE (*node
) == FUNCTION_DECL
939 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
940 /* Do nothing else, just set the attribute. We'll get at
941 it later with lookup_attribute. */
945 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
946 *no_add_attrs
= true;
952 /* Handle a "used" attribute; arguments as in
953 struct attribute_spec.handler. */
956 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
957 int ARG_UNUSED (flags
), bool *no_add_attrs
)
961 if (TREE_CODE (node
) == FUNCTION_DECL
962 || (VAR_P (node
) && TREE_STATIC (node
))
963 || (TREE_CODE (node
) == TYPE_DECL
))
965 TREE_USED (node
) = 1;
966 DECL_PRESERVE_P (node
) = 1;
968 DECL_READ_P (node
) = 1;
972 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
973 *no_add_attrs
= true;
979 /* Handle a "unused" attribute; arguments as in
980 struct attribute_spec.handler. */
983 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
984 int flags
, bool *no_add_attrs
)
990 if (TREE_CODE (decl
) == PARM_DECL
991 || VAR_OR_FUNCTION_DECL_P (decl
)
992 || TREE_CODE (decl
) == LABEL_DECL
993 || TREE_CODE (decl
) == CONST_DECL
994 || TREE_CODE (decl
) == TYPE_DECL
)
996 TREE_USED (decl
) = 1;
997 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
998 DECL_READ_P (decl
) = 1;
1002 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1003 *no_add_attrs
= true;
1008 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1009 *node
= build_variant_type_copy (*node
);
1010 TREE_USED (*node
) = 1;
1016 /* Handle a "externally_visible" attribute; arguments as in
1017 struct attribute_spec.handler. */
1020 handle_externally_visible_attribute (tree
*pnode
, tree name
,
1021 tree
ARG_UNUSED (args
),
1022 int ARG_UNUSED (flags
),
1027 if (VAR_OR_FUNCTION_DECL_P (node
))
1029 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
1030 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
1032 warning (OPT_Wattributes
,
1033 "%qE attribute have effect only on public objects", name
);
1034 *no_add_attrs
= true;
1039 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1040 *no_add_attrs
= true;
1046 /* Handle the "no_reorder" attribute. Arguments as in
1047 struct attribute_spec.handler. */
1050 handle_no_reorder_attribute (tree
*pnode
,
1058 if (!VAR_OR_FUNCTION_DECL_P (node
)
1059 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
1061 warning (OPT_Wattributes
,
1062 "%qE attribute only affects top level objects",
1064 *no_add_attrs
= true;
1070 /* Handle a "const" attribute; arguments as in
1071 struct attribute_spec.handler. */
1074 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1075 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1077 tree type
= TREE_TYPE (*node
);
1079 /* See FIXME comment on noreturn in c_common_attribute_table. */
1080 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1081 TREE_READONLY (*node
) = 1;
1082 else if (TREE_CODE (type
) == POINTER_TYPE
1083 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1085 = (build_qualified_type
1087 (build_type_variant (TREE_TYPE (type
), 1,
1088 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
1089 TYPE_QUALS (type
)));
1092 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1093 *no_add_attrs
= true;
1099 /* Handle a "scalar_storage_order" attribute; arguments as in
1100 struct attribute_spec.handler. */
1103 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
1104 int flags
, bool *no_add_attrs
)
1106 tree id
= TREE_VALUE (args
);
1109 if (TREE_CODE (*node
) == TYPE_DECL
1110 && ! (flags
& ATTR_FLAG_CXX11
))
1111 node
= &TREE_TYPE (*node
);
1114 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
1116 error ("scalar_storage_order is not supported because endianness "
1121 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
1123 bool reverse
= false;
1125 if (TREE_CODE (id
) == STRING_CST
1126 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1127 reverse
= !BYTES_BIG_ENDIAN
;
1128 else if (TREE_CODE (id
) == STRING_CST
1129 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1130 reverse
= BYTES_BIG_ENDIAN
;
1133 error ("scalar_storage_order argument must be one of \"big-endian\""
1134 " or \"little-endian\"");
1138 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1141 /* A type variant isn't good enough, since we don't want a cast
1142 to such a type to be removed as a no-op. */
1143 *node
= type
= build_duplicate_type (type
);
1146 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1150 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1151 *no_add_attrs
= true;
1155 /* Handle a "transparent_union" attribute; arguments as in
1156 struct attribute_spec.handler. */
1159 handle_transparent_union_attribute (tree
*node
, tree name
,
1160 tree
ARG_UNUSED (args
), int flags
,
1165 *no_add_attrs
= true;
1167 if (TREE_CODE (*node
) == TYPE_DECL
1168 && ! (flags
& ATTR_FLAG_CXX11
))
1169 node
= &TREE_TYPE (*node
);
1172 if (TREE_CODE (type
) == UNION_TYPE
)
1174 /* Make sure that the first field will work for a transparent union.
1175 If the type isn't complete yet, leave the check to the code in
1177 if (TYPE_SIZE (type
))
1179 tree first
= first_field (type
);
1180 if (first
== NULL_TREE
1181 || DECL_ARTIFICIAL (first
)
1182 || TYPE_MODE (type
) != DECL_MODE (first
))
1186 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1188 /* If the type isn't complete yet, setting the flag
1189 on a variant wouldn't ever be checked. */
1190 if (!TYPE_SIZE (type
))
1193 /* build_duplicate_type doesn't work for C++. */
1194 if (c_dialect_cxx ())
1197 /* A type variant isn't good enough, since we don't want a cast
1198 to such a type to be removed as a no-op. */
1199 *node
= type
= build_duplicate_type (type
);
1202 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1203 TYPE_TRANSPARENT_AGGR (t
) = 1;
1208 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1212 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1213 get the requested priority for a constructor or destructor,
1214 possibly issuing diagnostics for invalid or reserved
1217 static priority_type
1218 get_priority (tree args
, bool is_destructor
)
1224 return DEFAULT_INIT_PRIORITY
;
1226 if (!SUPPORTS_INIT_PRIORITY
)
1229 error ("destructor priorities are not supported");
1231 error ("constructor priorities are not supported");
1232 return DEFAULT_INIT_PRIORITY
;
1235 arg
= TREE_VALUE (args
);
1236 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1238 if (arg
== error_mark_node
)
1239 return DEFAULT_INIT_PRIORITY
;
1240 arg
= default_conversion (arg
);
1241 if (!tree_fits_shwi_p (arg
)
1242 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1245 pri
= tree_to_shwi (arg
);
1246 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1249 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1253 "destructor priorities from 0 to %d are reserved "
1254 "for the implementation",
1255 MAX_RESERVED_INIT_PRIORITY
);
1258 "constructor priorities from 0 to %d are reserved "
1259 "for the implementation",
1260 MAX_RESERVED_INIT_PRIORITY
);
1266 error ("destructor priorities must be integers from 0 to %d inclusive",
1269 error ("constructor priorities must be integers from 0 to %d inclusive",
1271 return DEFAULT_INIT_PRIORITY
;
1274 /* Handle a "constructor" attribute; arguments as in
1275 struct attribute_spec.handler. */
1278 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1279 int ARG_UNUSED (flags
),
1283 tree type
= TREE_TYPE (decl
);
1285 if (TREE_CODE (decl
) == FUNCTION_DECL
1286 && TREE_CODE (type
) == FUNCTION_TYPE
1287 && decl_function_context (decl
) == 0)
1289 priority_type priority
;
1290 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1291 priority
= get_priority (args
, /*is_destructor=*/false);
1292 SET_DECL_INIT_PRIORITY (decl
, priority
);
1293 TREE_USED (decl
) = 1;
1297 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1298 *no_add_attrs
= true;
1304 /* Handle a "destructor" attribute; arguments as in
1305 struct attribute_spec.handler. */
1308 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1309 int ARG_UNUSED (flags
),
1313 tree type
= TREE_TYPE (decl
);
1315 if (TREE_CODE (decl
) == FUNCTION_DECL
1316 && TREE_CODE (type
) == FUNCTION_TYPE
1317 && decl_function_context (decl
) == 0)
1319 priority_type priority
;
1320 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1321 priority
= get_priority (args
, /*is_destructor=*/true);
1322 SET_DECL_FINI_PRIORITY (decl
, priority
);
1323 TREE_USED (decl
) = 1;
1327 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1328 *no_add_attrs
= true;
1334 /* Nonzero if the mode is a valid vector mode for this architecture.
1335 This returns nonzero even if there is no hardware support for the
1336 vector mode, but we can emulate with narrower modes. */
1339 vector_mode_valid_p (machine_mode mode
)
1341 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1343 /* Doh! What's going on? */
1344 if (mclass
!= MODE_VECTOR_INT
1345 && mclass
!= MODE_VECTOR_FLOAT
1346 && mclass
!= MODE_VECTOR_FRACT
1347 && mclass
!= MODE_VECTOR_UFRACT
1348 && mclass
!= MODE_VECTOR_ACCUM
1349 && mclass
!= MODE_VECTOR_UACCUM
)
1352 /* Hardware support. Woo hoo! */
1353 if (targetm
.vector_mode_supported_p (mode
))
1356 /* We should probably return 1 if requesting V4DI and we have no DI,
1357 but we have V2DI, but this is probably very unlikely. */
1359 /* If we have support for the inner mode, we can safely emulate it.
1360 We may not have V2DI, but me can emulate with a pair of DIs. */
1361 return targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1365 /* Handle a "mode" attribute; arguments as in
1366 struct attribute_spec.handler. */
1369 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1370 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1373 tree ident
= TREE_VALUE (args
);
1375 *no_add_attrs
= true;
1377 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1378 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1382 const char *p
= IDENTIFIER_POINTER (ident
);
1383 int len
= strlen (p
);
1384 machine_mode mode
= VOIDmode
;
1388 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1389 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1391 char *newp
= (char *) alloca (len
- 1);
1393 strcpy (newp
, &p
[2]);
1394 newp
[len
- 4] = '\0';
1398 /* Change this type to have a type with the specified mode.
1399 First check for the special modes. */
1400 if (!strcmp (p
, "byte"))
1402 else if (!strcmp (p
, "word"))
1404 else if (!strcmp (p
, "pointer"))
1406 else if (!strcmp (p
, "libgcc_cmp_return"))
1407 mode
= targetm
.libgcc_cmp_return_mode ();
1408 else if (!strcmp (p
, "libgcc_shift_count"))
1409 mode
= targetm
.libgcc_shift_count_mode ();
1410 else if (!strcmp (p
, "unwind_word"))
1411 mode
= targetm
.unwind_word_mode ();
1413 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1414 if (!strcmp (p
, GET_MODE_NAME (j
)))
1416 mode
= (machine_mode
) j
;
1420 if (mode
== VOIDmode
)
1422 error ("unknown machine mode %qE", ident
);
1427 switch (GET_MODE_CLASS (mode
))
1430 case MODE_PARTIAL_INT
:
1432 case MODE_DECIMAL_FLOAT
:
1438 = targetm
.scalar_mode_supported_p (as_a
<scalar_mode
> (mode
));
1441 case MODE_COMPLEX_INT
:
1442 case MODE_COMPLEX_FLOAT
:
1443 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1446 case MODE_VECTOR_INT
:
1447 case MODE_VECTOR_FLOAT
:
1448 case MODE_VECTOR_FRACT
:
1449 case MODE_VECTOR_UFRACT
:
1450 case MODE_VECTOR_ACCUM
:
1451 case MODE_VECTOR_UACCUM
:
1452 warning (OPT_Wattributes
, "specifying vector types with "
1453 "__attribute__ ((mode)) is deprecated");
1454 warning (OPT_Wattributes
,
1455 "use __attribute__ ((vector_size)) instead");
1456 valid_mode
= vector_mode_valid_p (mode
);
1464 error ("unable to emulate %qs", p
);
1468 if (POINTER_TYPE_P (type
))
1470 scalar_int_mode addr_mode
;
1471 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1472 tree (*fn
)(tree
, machine_mode
, bool);
1474 if (!is_a
<scalar_int_mode
> (mode
, &addr_mode
)
1475 || !targetm
.addr_space
.valid_pointer_mode (addr_mode
, as
))
1477 error ("invalid pointer mode %qs", p
);
1481 if (TREE_CODE (type
) == POINTER_TYPE
)
1482 fn
= build_pointer_type_for_mode
;
1484 fn
= build_reference_type_for_mode
;
1485 typefm
= fn (TREE_TYPE (type
), addr_mode
, false);
1489 /* For fixed-point modes, we need to test if the signness of type
1490 and the machine mode are consistent. */
1491 if (ALL_FIXED_POINT_MODE_P (mode
)
1492 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1494 error ("signedness of type and machine mode %qs don%'t match", p
);
1497 /* For fixed-point modes, we need to pass saturating info. */
1498 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1499 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1500 : TYPE_UNSIGNED (type
));
1503 if (typefm
== NULL_TREE
)
1505 error ("no data type for mode %qs", p
);
1508 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1510 /* For enumeral types, copy the precision from the integer
1511 type returned above. If not an INTEGER_TYPE, we can't use
1512 this mode for this type. */
1513 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1515 error ("cannot use mode %qs for enumeral types", p
);
1519 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1521 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1526 /* We cannot build a type variant, as there's code that assumes
1527 that TYPE_MAIN_VARIANT has the same mode. This includes the
1528 debug generators. Instead, create a subrange type. This
1529 results in all of the enumeral values being emitted only once
1530 in the original, and the subtype gets them by reference. */
1531 if (TYPE_UNSIGNED (type
))
1532 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1534 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1535 TREE_TYPE (typefm
) = type
;
1538 else if (VECTOR_MODE_P (mode
)
1539 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1540 : TREE_CODE (type
) != TREE_CODE (typefm
))
1542 error ("mode %qs applied to inappropriate type", p
);
1546 *node
= build_qualified_type (typefm
, TYPE_QUALS (type
));
1552 /* Handle a "section" attribute; arguments as in
1553 struct attribute_spec.handler. */
1556 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1557 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1561 if (!targetm_common
.have_named_sections
)
1563 error_at (DECL_SOURCE_LOCATION (*node
),
1564 "section attributes are not supported for this target");
1568 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1570 error ("section attribute not allowed for %q+D", *node
);
1574 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1576 error ("section attribute argument not a string constant");
1581 && current_function_decl
!= NULL_TREE
1582 && !TREE_STATIC (decl
))
1584 error_at (DECL_SOURCE_LOCATION (decl
),
1585 "section attribute cannot be specified for local variables");
1589 /* The decl may have already been given a section attribute
1590 from a previous declaration. Ensure they match. */
1591 if (DECL_SECTION_NAME (decl
) != NULL
1592 && strcmp (DECL_SECTION_NAME (decl
),
1593 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1595 error ("section of %q+D conflicts with previous declaration", *node
);
1600 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1601 && DECL_THREAD_LOCAL_P (decl
))
1603 error ("section of %q+D cannot be overridden", *node
);
1607 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1611 *no_add_attrs
= true;
1615 /* If in c++-11, check if the c++-11 alignment constraint with respect
1616 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1617 c++-11 mode, does nothing.
1621 [* if the constant expression evaluates to a fundamental alignment,
1622 the alignment requirement of the declared entity shall be the
1623 specified fundamental alignment.
1625 * if the constant expression evaluates to an extended alignment
1626 and the implementation supports that alignment in the context
1627 of the declaration, the alignment of the declared entity shall
1630 * if the constant expression evaluates to an extended alignment
1631 and the implementation does not support that alignment in the
1632 context of the declaration, the program is ill-formed]. */
1635 check_cxx_fundamental_alignment_constraints (tree node
,
1639 bool alignment_too_large_p
= false;
1640 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1641 unsigned max_align
= 0;
1643 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1644 || (node
== NULL_TREE
|| node
== error_mark_node
))
1647 if (cxx_fundamental_alignment_p (requested_alignment
))
1652 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1653 /* For file scope variables and static members, the target supports
1654 alignments that are at most MAX_OFILE_ALIGNMENT. */
1655 max_align
= MAX_OFILE_ALIGNMENT
;
1657 /* For stack variables, the target supports at most
1658 MAX_STACK_ALIGNMENT. */
1659 max_align
= MAX_STACK_ALIGNMENT
;
1660 if (requested_alignment
> max_align
)
1661 alignment_too_large_p
= true;
1663 /* Let's be liberal for types and fields; don't limit their alignment any
1664 more than check_user_alignment already did. */
1666 if (alignment_too_large_p
)
1667 pedwarn (input_location
, OPT_Wattributes
,
1668 "requested alignment %d is larger than %d",
1669 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1671 return !alignment_too_large_p
;
1674 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1675 handle_aligned_attribute. */
1678 common_handle_aligned_attribute (tree
*node
, tree args
, int flags
,
1680 bool warn_if_not_aligned_p
)
1682 tree decl
= NULL_TREE
;
1690 align_expr
= TREE_VALUE (args
);
1691 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1692 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1693 align_expr
= default_conversion (align_expr
);
1696 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1701 type
= &TREE_TYPE (decl
);
1702 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1704 else if (TYPE_P (*node
))
1705 type
= node
, is_type
= 1;
1707 if ((i
= check_user_alignment (align_expr
, true)) == -1
1708 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
1709 *no_add_attrs
= true;
1712 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1713 /* OK, modify the type in place. */;
1714 /* If we have a TYPE_DECL, then copy the type, so that we
1715 don't accidentally modify a builtin type. See pushdecl. */
1716 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1717 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1719 tree tt
= TREE_TYPE (decl
);
1720 *type
= build_variant_type_copy (*type
);
1721 DECL_ORIGINAL_TYPE (decl
) = tt
;
1722 TYPE_NAME (*type
) = decl
;
1723 TREE_USED (*type
) = TREE_USED (decl
);
1724 TREE_TYPE (decl
) = *type
;
1727 *type
= build_variant_type_copy (*type
);
1729 if (warn_if_not_aligned_p
)
1731 SET_TYPE_WARN_IF_NOT_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
1732 warn_if_not_aligned_p
= false;
1736 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
1737 TYPE_USER_ALIGN (*type
) = 1;
1740 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1741 && TREE_CODE (decl
) != FIELD_DECL
)
1743 error ("alignment may not be specified for %q+D", decl
);
1744 *no_add_attrs
= true;
1746 else if (DECL_USER_ALIGN (decl
)
1747 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1748 /* C++-11 [dcl.align/4]:
1750 When multiple alignment-specifiers are specified for an
1751 entity, the alignment requirement shall be set to the
1752 strictest specified alignment.
1754 This formally comes from the c++11 specification but we are
1755 doing it for the GNU attribute syntax as well. */
1756 *no_add_attrs
= true;
1757 else if (TREE_CODE (decl
) == FUNCTION_DECL
1758 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1760 if (DECL_USER_ALIGN (decl
))
1761 error ("alignment for %q+D was previously specified as %d "
1762 "and may not be decreased", decl
,
1763 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1765 error ("alignment for %q+D must be at least %d", decl
,
1766 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1767 *no_add_attrs
= true;
1771 if (warn_if_not_aligned_p
)
1773 if (TREE_CODE (decl
) == FIELD_DECL
&& !DECL_INITIAL (decl
))
1775 SET_DECL_WARN_IF_NOT_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
1776 warn_if_not_aligned_p
= false;
1781 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
1782 DECL_USER_ALIGN (decl
) = 1;
1786 if (warn_if_not_aligned_p
)
1788 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1790 *no_add_attrs
= true;
1796 /* Handle a "aligned" attribute; arguments as in
1797 struct attribute_spec.handler. */
1800 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1801 int flags
, bool *no_add_attrs
)
1803 return common_handle_aligned_attribute (node
, args
, flags
,
1804 no_add_attrs
, false);
1807 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1808 struct attribute_spec.handler. */
1811 handle_warn_if_not_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
),
1812 tree args
, int flags
,
1815 return common_handle_aligned_attribute (node
, args
, flags
,
1816 no_add_attrs
, true);
1819 /* Handle a "weak" attribute; arguments as in
1820 struct attribute_spec.handler. */
1823 handle_weak_attribute (tree
*node
, tree name
,
1824 tree
ARG_UNUSED (args
),
1825 int ARG_UNUSED (flags
),
1826 bool * ARG_UNUSED (no_add_attrs
))
1828 if (TREE_CODE (*node
) == FUNCTION_DECL
1829 && DECL_DECLARED_INLINE_P (*node
))
1831 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1832 *no_add_attrs
= true;
1834 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1836 error ("indirect function %q+D cannot be declared weak", *node
);
1837 *no_add_attrs
= true;
1840 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1841 declare_weak (*node
);
1843 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1848 /* Handle a "noplt" attribute; arguments as in
1849 struct attribute_spec.handler. */
1852 handle_noplt_attribute (tree
*node
, tree name
,
1853 tree
ARG_UNUSED (args
),
1854 int ARG_UNUSED (flags
),
1855 bool * ARG_UNUSED (no_add_attrs
))
1857 if (TREE_CODE (*node
) != FUNCTION_DECL
)
1859 warning (OPT_Wattributes
,
1860 "%qE attribute is only applicable on functions", name
);
1861 *no_add_attrs
= true;
1867 /* Handle an "alias" or "ifunc" attribute; arguments as in
1868 struct attribute_spec.handler, except that IS_ALIAS tells us
1869 whether this is an alias as opposed to ifunc attribute. */
1872 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
1877 if (TREE_CODE (decl
) != FUNCTION_DECL
1878 && (!is_alias
|| !VAR_P (decl
)))
1880 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1881 *no_add_attrs
= true;
1883 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
1884 || (TREE_CODE (decl
) != FUNCTION_DECL
1885 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
1886 /* A static variable declaration is always a tentative definition,
1887 but the alias is a non-tentative definition which overrides. */
1888 || (TREE_CODE (decl
) != FUNCTION_DECL
1889 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
1891 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
1892 *no_add_attrs
= true;
1896 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
1897 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
1899 error ("weak %q+D cannot be defined %qE", decl
, name
);
1900 *no_add_attrs
= true;
1904 /* Note that the very first time we process a nested declaration,
1905 decl_function_context will not be set. Indeed, *would* never
1906 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
1907 we do below. After such frobbery, pushdecl would set the context.
1908 In any case, this is never what we want. */
1909 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
1913 id
= TREE_VALUE (args
);
1914 if (TREE_CODE (id
) != STRING_CST
)
1916 error ("attribute %qE argument not a string", name
);
1917 *no_add_attrs
= true;
1920 id
= get_identifier (TREE_STRING_POINTER (id
));
1921 /* This counts as a use of the object pointed to. */
1924 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1925 DECL_INITIAL (decl
) = error_mark_node
;
1927 TREE_STATIC (decl
) = 1;
1931 /* ifuncs are also aliases, so set that attribute too. */
1932 DECL_ATTRIBUTES (decl
)
1933 = tree_cons (get_identifier ("alias"), args
,
1934 DECL_ATTRIBUTES (decl
));
1935 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("ifunc"),
1936 NULL
, DECL_ATTRIBUTES (decl
));
1941 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1942 *no_add_attrs
= true;
1945 if (decl_in_symtab_p (*node
))
1947 struct symtab_node
*n
= symtab_node::get (decl
);
1948 if (n
&& n
->refuse_visibility_changes
)
1951 error ("%+qD declared alias after being used", decl
);
1953 error ("%+qD declared ifunc after being used", decl
);
1961 /* Handle an "alias" or "ifunc" attribute; arguments as in
1962 struct attribute_spec.handler. */
1965 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
1966 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1968 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
1971 /* Handle an "alias" or "ifunc" attribute; arguments as in
1972 struct attribute_spec.handler. */
1975 handle_alias_attribute (tree
*node
, tree name
, tree args
,
1976 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1978 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
1981 /* Handle a "weakref" attribute; arguments as in struct
1982 attribute_spec.handler. */
1985 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1986 int flags
, bool *no_add_attrs
)
1988 tree attr
= NULL_TREE
;
1990 /* We must ignore the attribute when it is associated with
1991 local-scoped decls, since attribute alias is ignored and many
1992 such symbols do not even have a DECL_WEAK field. */
1993 if (decl_function_context (*node
)
1994 || current_function_decl
1995 || !VAR_OR_FUNCTION_DECL_P (*node
))
1997 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1998 *no_add_attrs
= true;
2002 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
2004 error ("indirect function %q+D cannot be declared weakref", *node
);
2005 *no_add_attrs
= true;
2009 /* The idea here is that `weakref("name")' mutates into `weakref,
2010 alias("name")', and weakref without arguments, in turn,
2011 implicitly adds weak. */
2015 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
2016 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
2018 *no_add_attrs
= true;
2020 decl_attributes (node
, attr
, flags
);
2024 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
2025 error_at (DECL_SOURCE_LOCATION (*node
),
2026 "weakref attribute must appear before alias attribute");
2028 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2029 and that isn't supported; and because it wants to add it to
2030 the list of weak decls, which isn't helpful. */
2031 DECL_WEAK (*node
) = 1;
2034 if (decl_in_symtab_p (*node
))
2036 struct symtab_node
*n
= symtab_node::get (*node
);
2037 if (n
&& n
->refuse_visibility_changes
)
2038 error ("%+qD declared weakref after being used", *node
);
2044 /* Handle an "visibility" attribute; arguments as in
2045 struct attribute_spec.handler. */
2048 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
2049 int ARG_UNUSED (flags
),
2050 bool *ARG_UNUSED (no_add_attrs
))
2053 tree id
= TREE_VALUE (args
);
2054 enum symbol_visibility vis
;
2058 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
2060 else if (!RECORD_OR_UNION_TYPE_P (*node
))
2062 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
2066 else if (TYPE_FIELDS (*node
))
2068 error ("%qE attribute ignored because %qT is already defined",
2073 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
2075 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2079 if (TREE_CODE (id
) != STRING_CST
)
2081 error ("visibility argument not a string");
2085 /* If this is a type, set the visibility on the type decl. */
2088 decl
= TYPE_NAME (decl
);
2091 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
2093 warning (OPT_Wattributes
, "%qE attribute ignored on types",
2099 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
2100 vis
= VISIBILITY_DEFAULT
;
2101 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
2102 vis
= VISIBILITY_INTERNAL
;
2103 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
2104 vis
= VISIBILITY_HIDDEN
;
2105 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
2106 vis
= VISIBILITY_PROTECTED
;
2109 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2110 vis
= VISIBILITY_DEFAULT
;
2113 if (DECL_VISIBILITY_SPECIFIED (decl
)
2114 && vis
!= DECL_VISIBILITY (decl
))
2116 tree attributes
= (TYPE_P (*node
)
2117 ? TYPE_ATTRIBUTES (*node
)
2118 : DECL_ATTRIBUTES (decl
));
2119 if (lookup_attribute ("visibility", attributes
))
2120 error ("%qD redeclared with different visibility", decl
);
2121 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2122 && lookup_attribute ("dllimport", attributes
))
2123 error ("%qD was declared %qs which implies default visibility",
2125 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2126 && lookup_attribute ("dllexport", attributes
))
2127 error ("%qD was declared %qs which implies default visibility",
2131 DECL_VISIBILITY (decl
) = vis
;
2132 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
2134 /* Go ahead and attach the attribute to the node as well. This is needed
2135 so we can determine whether we have VISIBILITY_DEFAULT because the
2136 visibility was not specified, or because it was explicitly overridden
2137 from the containing scope. */
2142 /* Handle an "tls_model" attribute; arguments as in
2143 struct attribute_spec.handler. */
2146 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
2147 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2151 enum tls_model kind
;
2153 *no_add_attrs
= true;
2155 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
2157 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2161 kind
= DECL_TLS_MODEL (decl
);
2162 id
= TREE_VALUE (args
);
2163 if (TREE_CODE (id
) != STRING_CST
)
2165 error ("tls_model argument not a string");
2169 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
2170 kind
= TLS_MODEL_LOCAL_EXEC
;
2171 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
2172 kind
= TLS_MODEL_INITIAL_EXEC
;
2173 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
2174 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
2175 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
2176 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
2178 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2180 set_decl_tls_model (decl
, kind
);
2184 /* Handle a "no_instrument_function" attribute; arguments as in
2185 struct attribute_spec.handler. */
2188 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2189 tree
ARG_UNUSED (args
),
2190 int ARG_UNUSED (flags
),
2195 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2197 error_at (DECL_SOURCE_LOCATION (decl
),
2198 "%qE attribute applies only to functions", name
);
2199 *no_add_attrs
= true;
2202 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2207 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2208 struct attribute_spec.handler. */
2211 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
2212 int, bool *no_add_attrs
)
2214 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2216 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2217 *no_add_attrs
= true;
2223 /* Handle a "malloc" attribute; arguments as in
2224 struct attribute_spec.handler. */
2227 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2228 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2230 if (TREE_CODE (*node
) == FUNCTION_DECL
2231 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
2232 DECL_IS_MALLOC (*node
) = 1;
2235 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2236 *no_add_attrs
= true;
2242 /* Handle a "alloc_size" attribute; arguments as in
2243 struct attribute_spec.handler. */
2246 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2247 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2249 unsigned arg_count
= type_num_arguments (*node
);
2250 for (; args
; args
= TREE_CHAIN (args
))
2252 tree position
= TREE_VALUE (args
);
2253 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2254 && TREE_CODE (position
) != FUNCTION_DECL
)
2255 position
= default_conversion (position
);
2257 if (!tree_fits_uhwi_p (position
)
2259 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2261 warning (OPT_Wattributes
,
2262 "alloc_size parameter outside range");
2263 *no_add_attrs
= true;
2270 /* Handle a "alloc_align" attribute; arguments as in
2271 struct attribute_spec.handler. */
2274 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
2277 unsigned arg_count
= type_num_arguments (*node
);
2278 tree position
= TREE_VALUE (args
);
2279 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2280 && TREE_CODE (position
) != FUNCTION_DECL
)
2281 position
= default_conversion (position
);
2283 if (!tree_fits_uhwi_p (position
)
2285 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2287 warning (OPT_Wattributes
,
2288 "alloc_align parameter outside range");
2289 *no_add_attrs
= true;
2295 /* Handle a "assume_aligned" attribute; arguments as in
2296 struct attribute_spec.handler. */
2299 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
2302 for (; args
; args
= TREE_CHAIN (args
))
2304 tree position
= TREE_VALUE (args
);
2305 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2306 && TREE_CODE (position
) != FUNCTION_DECL
)
2307 position
= default_conversion (position
);
2309 if (TREE_CODE (position
) != INTEGER_CST
)
2311 warning (OPT_Wattributes
,
2312 "assume_aligned parameter not integer constant");
2313 *no_add_attrs
= true;
2320 /* Handle a "fn spec" attribute; arguments as in
2321 struct attribute_spec.handler. */
2324 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
2325 tree args
, int ARG_UNUSED (flags
),
2326 bool *no_add_attrs ATTRIBUTE_UNUSED
)
2329 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2330 && !TREE_CHAIN (args
));
2334 /* Handle a "bnd_variable_size" attribute; arguments as in
2335 struct attribute_spec.handler. */
2338 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2339 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2341 if (TREE_CODE (*node
) != FIELD_DECL
)
2343 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2344 *no_add_attrs
= true;
2350 /* Handle a "bnd_legacy" attribute; arguments as in
2351 struct attribute_spec.handler. */
2354 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2355 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2357 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2359 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2360 *no_add_attrs
= true;
2366 /* Handle a "bnd_instrument" attribute; arguments as in
2367 struct attribute_spec.handler. */
2370 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2371 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2373 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2375 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2376 *no_add_attrs
= true;
2382 /* Handle a "warn_unused" attribute; arguments as in
2383 struct attribute_spec.handler. */
2386 handle_warn_unused_attribute (tree
*node
, tree name
,
2387 tree args ATTRIBUTE_UNUSED
,
2388 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2391 /* Do nothing else, just set the attribute. We'll get at
2392 it later with lookup_attribute. */
2396 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2397 *no_add_attrs
= true;
2403 /* Handle an "omp declare simd" attribute; arguments as in
2404 struct attribute_spec.handler. */
2407 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2412 /* Handle a "simd" attribute. */
2415 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
2417 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2419 if (lookup_attribute ("cilk simd function",
2420 DECL_ATTRIBUTES (*node
)) != NULL
)
2422 error_at (DECL_SOURCE_LOCATION (*node
),
2423 "%<__simd__%> attribute cannot be used in the same "
2424 "function marked as a Cilk Plus SIMD-enabled function");
2425 *no_add_attrs
= true;
2429 tree t
= get_identifier ("omp declare simd");
2430 tree attr
= NULL_TREE
;
2433 tree id
= TREE_VALUE (args
);
2435 if (TREE_CODE (id
) != STRING_CST
)
2437 error ("attribute %qE argument not a string", name
);
2438 *no_add_attrs
= true;
2442 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
2443 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2444 OMP_CLAUSE_NOTINBRANCH
);
2446 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
2447 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2448 OMP_CLAUSE_INBRANCH
);
2451 error ("only %<inbranch%> and %<notinbranch%> flags are "
2452 "allowed for %<__simd__%> attribute");
2453 *no_add_attrs
= true;
2458 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
2459 build_tree_list (NULL_TREE
,
2461 DECL_ATTRIBUTES (*node
));
2466 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2467 *no_add_attrs
= true;
2473 /* Handle an "omp declare target" attribute; arguments as in
2474 struct attribute_spec.handler. */
2477 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2482 /* Handle a "returns_twice" attribute; arguments as in
2483 struct attribute_spec.handler. */
2486 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2487 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2489 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2490 DECL_IS_RETURNS_TWICE (*node
) = 1;
2493 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2494 *no_add_attrs
= true;
2500 /* Handle a "no_limit_stack" attribute; arguments as in
2501 struct attribute_spec.handler. */
2504 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2505 tree
ARG_UNUSED (args
),
2506 int ARG_UNUSED (flags
),
2511 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2513 error_at (DECL_SOURCE_LOCATION (decl
),
2514 "%qE attribute applies only to functions", name
);
2515 *no_add_attrs
= true;
2517 else if (DECL_INITIAL (decl
))
2519 error_at (DECL_SOURCE_LOCATION (decl
),
2520 "can%'t set %qE attribute after definition", name
);
2521 *no_add_attrs
= true;
2524 DECL_NO_LIMIT_STACK (decl
) = 1;
2529 /* Handle a "pure" attribute; arguments as in
2530 struct attribute_spec.handler. */
2533 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2534 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2536 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2537 DECL_PURE_P (*node
) = 1;
2538 /* ??? TODO: Support types. */
2541 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2542 *no_add_attrs
= true;
2548 /* Digest an attribute list destined for a transactional memory statement.
2549 ALLOWED is the set of attributes that are allowed for this statement;
2550 return the attribute we parsed. Multiple attributes are never allowed. */
2553 parse_tm_stmt_attr (tree attrs
, int allowed
)
2558 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2560 tree a
= TREE_PURPOSE (attrs
);
2563 if (is_attribute_p ("outer", a
))
2564 m
= TM_STMT_ATTR_OUTER
;
2566 if ((m
& allowed
) == 0)
2568 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
2577 else if (m_seen
== m
)
2578 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2580 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
2586 /* Transform a TM attribute name into a maskable integer and back.
2587 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2588 to how the lack of an attribute is treated. */
2591 tm_attr_to_mask (tree attr
)
2595 if (is_attribute_p ("transaction_safe", attr
))
2596 return TM_ATTR_SAFE
;
2597 if (is_attribute_p ("transaction_callable", attr
))
2598 return TM_ATTR_CALLABLE
;
2599 if (is_attribute_p ("transaction_pure", attr
))
2600 return TM_ATTR_PURE
;
2601 if (is_attribute_p ("transaction_unsafe", attr
))
2602 return TM_ATTR_IRREVOCABLE
;
2603 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
2604 return TM_ATTR_MAY_CANCEL_OUTER
;
2609 tm_mask_to_attr (int mask
)
2615 str
= "transaction_safe";
2617 case TM_ATTR_CALLABLE
:
2618 str
= "transaction_callable";
2621 str
= "transaction_pure";
2623 case TM_ATTR_IRREVOCABLE
:
2624 str
= "transaction_unsafe";
2626 case TM_ATTR_MAY_CANCEL_OUTER
:
2627 str
= "transaction_may_cancel_outer";
2632 return get_identifier (str
);
2635 /* Return the first TM attribute seen in LIST. */
2638 find_tm_attribute (tree list
)
2640 for (; list
; list
= TREE_CHAIN (list
))
2642 tree name
= TREE_PURPOSE (list
);
2643 if (tm_attr_to_mask (name
) != 0)
2649 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2650 Here we accept only function types, and verify that none of the other
2651 function TM attributes are also applied. */
2652 /* ??? We need to accept class types for C++, but not C. This greatly
2653 complicates this function, since we can no longer rely on the extra
2654 processing given by function_type_required. */
2657 handle_tm_attribute (tree
*node
, tree name
, tree args
,
2658 int flags
, bool *no_add_attrs
)
2660 /* Only one path adds the attribute; others don't. */
2661 *no_add_attrs
= true;
2663 switch (TREE_CODE (*node
))
2667 /* Only tm_callable and tm_safe apply to classes. */
2668 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
2675 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
2676 if (old_name
== name
)
2678 else if (old_name
!= NULL_TREE
)
2679 error ("type was previously declared %qE", old_name
);
2681 *no_add_attrs
= false;
2687 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2688 want to set transaction_safe on the type. */
2689 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
2690 if (!TYPE_P (DECL_CONTEXT (*node
)))
2691 error_at (DECL_SOURCE_LOCATION (*node
),
2692 "%<transaction_safe_dynamic%> may only be specified for "
2693 "a virtual function");
2694 *no_add_attrs
= false;
2695 decl_attributes (&TREE_TYPE (*node
),
2696 build_tree_list (get_identifier ("transaction_safe"),
2704 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
2705 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
2707 tree fn_tmp
= TREE_TYPE (*node
);
2708 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
2709 *node
= build_pointer_type (fn_tmp
);
2716 /* If a function is next, pass it on to be tried next. */
2717 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
2718 return tree_cons (name
, args
, NULL
);
2721 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2728 /* Handle the TM_WRAP attribute; arguments as in
2729 struct attribute_spec.handler. */
2732 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2733 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2737 /* We don't need the attribute even on success, since we
2738 record the entry in an external table. */
2739 *no_add_attrs
= true;
2741 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2742 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2745 tree wrap_decl
= TREE_VALUE (args
);
2746 if (error_operand_p (wrap_decl
))
2748 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
2749 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
2750 error ("%qE argument not an identifier", name
);
2753 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
2754 wrap_decl
= lookup_name (wrap_decl
);
2755 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
2757 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
2758 TREE_TYPE (wrap_decl
)))
2759 record_tm_replacement (wrap_decl
, decl
);
2761 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2764 error ("%qE argument is not a function", name
);
2771 /* Ignore the given attribute. Used when this attribute may be usefully
2772 overridden by the target, but is not used generically. */
2775 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2776 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2779 *no_add_attrs
= true;
2783 /* Handle a "no vops" attribute; arguments as in
2784 struct attribute_spec.handler. */
2787 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2788 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2789 bool *ARG_UNUSED (no_add_attrs
))
2791 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
2792 DECL_IS_NOVOPS (*node
) = 1;
2796 /* Handle a "deprecated" attribute; arguments as in
2797 struct attribute_spec.handler. */
2800 handle_deprecated_attribute (tree
*node
, tree name
,
2801 tree args
, int flags
,
2804 tree type
= NULL_TREE
;
2806 tree what
= NULL_TREE
;
2809 *no_add_attrs
= true;
2810 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
2812 error ("deprecated message is not a string");
2813 *no_add_attrs
= true;
2819 type
= TREE_TYPE (decl
);
2821 if (TREE_CODE (decl
) == TYPE_DECL
2822 || TREE_CODE (decl
) == PARM_DECL
2823 || VAR_OR_FUNCTION_DECL_P (decl
)
2824 || TREE_CODE (decl
) == FIELD_DECL
2825 || TREE_CODE (decl
) == CONST_DECL
2826 || objc_method_decl (TREE_CODE (decl
)))
2827 TREE_DEPRECATED (decl
) = 1;
2831 else if (TYPE_P (*node
))
2833 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2834 *node
= build_variant_type_copy (*node
);
2835 TREE_DEPRECATED (*node
) = 1;
2843 *no_add_attrs
= true;
2844 if (type
&& TYPE_NAME (type
))
2846 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
2847 what
= TYPE_NAME (*node
);
2848 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
2849 && DECL_NAME (TYPE_NAME (type
)))
2850 what
= DECL_NAME (TYPE_NAME (type
));
2853 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
2855 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2861 /* Handle a "vector_size" attribute; arguments as in
2862 struct attribute_spec.handler. */
2865 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
2866 int ARG_UNUSED (flags
),
2869 unsigned HOST_WIDE_INT vecsize
, nunits
;
2870 machine_mode orig_mode
;
2871 tree type
= *node
, new_type
, size
;
2873 *no_add_attrs
= true;
2875 size
= TREE_VALUE (args
);
2876 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
2877 && TREE_CODE (size
) != FUNCTION_DECL
)
2878 size
= default_conversion (size
);
2880 if (!tree_fits_uhwi_p (size
))
2882 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2886 /* Get the vector size (in bytes). */
2887 vecsize
= tree_to_uhwi (size
);
2889 /* We need to provide for vector pointers, vector arrays, and
2890 functions returning vectors. For example:
2892 __attribute__((vector_size(16))) short *foo;
2894 In this case, the mode is SI, but the type being modified is
2895 HI, so we need to look further. */
2897 while (POINTER_TYPE_P (type
)
2898 || TREE_CODE (type
) == FUNCTION_TYPE
2899 || TREE_CODE (type
) == METHOD_TYPE
2900 || TREE_CODE (type
) == ARRAY_TYPE
2901 || TREE_CODE (type
) == OFFSET_TYPE
)
2902 type
= TREE_TYPE (type
);
2904 /* Get the mode of the type being modified. */
2905 orig_mode
= TYPE_MODE (type
);
2907 if ((!INTEGRAL_TYPE_P (type
)
2908 && !SCALAR_FLOAT_TYPE_P (type
)
2909 && !FIXED_POINT_TYPE_P (type
))
2910 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
2911 && GET_MODE_CLASS (orig_mode
) != MODE_INT
2912 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
2913 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
2914 || TREE_CODE (type
) == BOOLEAN_TYPE
)
2916 error ("invalid vector type for attribute %qE", name
);
2920 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
2922 error ("vector size not an integral multiple of component size");
2928 error ("zero vector size");
2932 /* Calculate how many units fit in the vector. */
2933 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
2934 if (nunits
& (nunits
- 1))
2936 error ("number of components of the vector not a power of two");
2940 new_type
= build_vector_type (type
, nunits
);
2942 /* Build back pointers if needed. */
2943 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
2948 /* Handle the "nonnull" attribute. */
2951 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2952 tree args
, int ARG_UNUSED (flags
),
2956 unsigned HOST_WIDE_INT attr_arg_num
;
2958 /* If no arguments are specified, all pointer arguments should be
2959 non-null. Verify a full prototype is given so that the arguments
2960 will have the correct types when we actually check them later.
2961 Avoid diagnosing type-generic built-ins since those have no
2965 if (!prototype_p (type
)
2966 && (!TYPE_ATTRIBUTES (type
)
2967 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
2969 error ("nonnull attribute without arguments on a non-prototype");
2970 *no_add_attrs
= true;
2975 /* Argument list specified. Verify that each argument number references
2976 a pointer argument. */
2977 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
2979 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
2981 tree arg
= TREE_VALUE (args
);
2982 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
2983 && TREE_CODE (arg
) != FUNCTION_DECL
)
2984 TREE_VALUE (args
) = arg
= default_conversion (arg
);
2986 if (!get_nonnull_operand (arg
, &arg_num
))
2988 error ("nonnull argument has invalid operand number (argument %lu)",
2989 (unsigned long) attr_arg_num
);
2990 *no_add_attrs
= true;
2994 if (prototype_p (type
))
2996 function_args_iterator iter
;
2999 function_args_iter_init (&iter
, type
);
3000 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
3002 argument
= function_args_iter_cond (&iter
);
3003 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
3008 || TREE_CODE (argument
) == VOID_TYPE
)
3010 error ("nonnull argument with out-of-range operand number "
3011 "(argument %lu, operand %lu)",
3012 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3013 *no_add_attrs
= true;
3017 if (TREE_CODE (argument
) != POINTER_TYPE
)
3019 error ("nonnull argument references non-pointer operand "
3020 "(argument %lu, operand %lu)",
3021 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3022 *no_add_attrs
= true;
3031 /* Handle the "nonstring" variable attribute. */
3034 handle_nonstring_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3035 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3038 tree_code code
= TREE_CODE (*node
);
3041 || code
== FIELD_DECL
3042 || code
== PARM_DECL
)
3044 tree type
= TREE_TYPE (*node
);
3046 if (POINTER_TYPE_P (type
) || TREE_CODE (type
) == ARRAY_TYPE
)
3048 tree eltype
= TREE_TYPE (type
);
3049 if (eltype
== char_type_node
)
3053 warning (OPT_Wattributes
,
3054 "%qE attribute ignored on objects of type %qT",
3056 *no_add_attrs
= true;
3060 if (code
== FUNCTION_DECL
)
3061 warning (OPT_Wattributes
,
3062 "%qE attribute does not apply to functions", name
);
3063 else if (code
== TYPE_DECL
)
3064 warning (OPT_Wattributes
,
3065 "%qE attribute does not apply to types", name
);
3067 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3069 *no_add_attrs
= true;
3073 /* Handle a "nothrow" attribute; arguments as in
3074 struct attribute_spec.handler. */
3077 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3078 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3080 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3081 TREE_NOTHROW (*node
) = 1;
3082 /* ??? TODO: Support types. */
3085 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3086 *no_add_attrs
= true;
3092 /* Handle a "cleanup" attribute; arguments as in
3093 struct attribute_spec.handler. */
3096 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
3097 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3100 tree cleanup_id
, cleanup_decl
;
3102 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3103 for global destructors in C++. This requires infrastructure that
3104 we don't have generically at the moment. It's also not a feature
3105 we'd be missing too much, since we do have attribute constructor. */
3106 if (!VAR_P (decl
) || TREE_STATIC (decl
))
3108 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3109 *no_add_attrs
= true;
3113 /* Verify that the argument is a function in scope. */
3114 /* ??? We could support pointers to functions here as well, if
3115 that was considered desirable. */
3116 cleanup_id
= TREE_VALUE (args
);
3117 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
3119 error ("cleanup argument not an identifier");
3120 *no_add_attrs
= true;
3123 cleanup_decl
= lookup_name (cleanup_id
);
3124 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
3126 error ("cleanup argument not a function");
3127 *no_add_attrs
= true;
3131 /* That the function has proper type is checked with the
3132 eventual call to build_function_call. */
3137 /* Handle a "warn_unused_result" attribute. No special handling. */
3140 handle_warn_unused_result_attribute (tree
*node
, tree name
,
3141 tree
ARG_UNUSED (args
),
3142 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3144 /* Ignore the attribute for functions not returning any value. */
3145 if (VOID_TYPE_P (TREE_TYPE (*node
)))
3147 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3148 *no_add_attrs
= true;
3154 /* Handle a "sentinel" attribute. */
3157 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
3158 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3160 if (!prototype_p (*node
))
3162 warning (OPT_Wattributes
,
3163 "%qE attribute requires prototypes with named arguments", name
);
3164 *no_add_attrs
= true;
3168 if (!stdarg_p (*node
))
3170 warning (OPT_Wattributes
,
3171 "%qE attribute only applies to variadic functions", name
);
3172 *no_add_attrs
= true;
3178 tree position
= TREE_VALUE (args
);
3179 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
3180 && TREE_CODE (position
) != FUNCTION_DECL
)
3181 position
= default_conversion (position
);
3183 if (TREE_CODE (position
) != INTEGER_CST
3184 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
3186 warning (OPT_Wattributes
,
3187 "requested position is not an integer constant");
3188 *no_add_attrs
= true;
3192 if (tree_int_cst_lt (position
, integer_zero_node
))
3194 warning (OPT_Wattributes
,
3195 "requested position is less than zero");
3196 *no_add_attrs
= true;
3204 /* Handle a "type_generic" attribute. */
3207 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3208 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
3209 bool * ARG_UNUSED (no_add_attrs
))
3211 /* Ensure we have a function type. */
3212 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
3214 /* Ensure we have a variadic function. */
3215 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
3220 /* Handle a "target" attribute. */
3223 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3226 /* Ensure we have a function type. */
3227 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3229 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3230 *no_add_attrs
= true;
3232 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3234 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3235 "with %qs attribute", name
, "target_clones");
3236 *no_add_attrs
= true;
3238 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3240 *no_add_attrs
= true;
3242 /* Check that there's no empty string in values of the attribute. */
3243 for (tree t
= args
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
3245 tree value
= TREE_VALUE (t
);
3246 if (TREE_CODE (value
) == STRING_CST
3247 && TREE_STRING_LENGTH (value
) == 1
3248 && TREE_STRING_POINTER (value
)[0] == '\0')
3250 warning (OPT_Wattributes
, "empty string in attribute %<target%>");
3251 *no_add_attrs
= true;
3258 /* Handle a "target_clones" attribute. */
3261 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3262 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3264 /* Ensure we have a function type. */
3265 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3267 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3269 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3270 "with %qs attribute", name
, "always_inline");
3271 *no_add_attrs
= true;
3273 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3275 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3276 "with %qs attribute", name
, "target");
3277 *no_add_attrs
= true;
3280 /* Do not inline functions with multiple clone targets. */
3281 DECL_UNINLINABLE (*node
) = 1;
3285 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3286 *no_add_attrs
= true;
3291 /* For handling "optimize" attribute. arguments as in
3292 struct attribute_spec.handler. */
3295 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3296 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3298 /* Ensure we have a function type. */
3299 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3301 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3302 *no_add_attrs
= true;
3306 struct cl_optimization cur_opts
;
3307 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3309 /* Save current options. */
3310 cl_optimization_save (&cur_opts
, &global_options
);
3312 /* If we previously had some optimization options, use them as the
3315 cl_optimization_restore (&global_options
,
3316 TREE_OPTIMIZATION (old_opts
));
3318 /* Parse options, and update the vector. */
3319 parse_optimize_options (args
, true);
3320 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3321 = build_optimization_node (&global_options
);
3323 /* Restore current options. */
3324 cl_optimization_restore (&global_options
, &cur_opts
);
3330 /* Handle a "no_split_stack" attribute. */
3333 handle_no_split_stack_attribute (tree
*node
, tree name
,
3334 tree
ARG_UNUSED (args
),
3335 int ARG_UNUSED (flags
),
3340 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3342 error_at (DECL_SOURCE_LOCATION (decl
),
3343 "%qE attribute applies only to functions", name
);
3344 *no_add_attrs
= true;
3346 else if (DECL_INITIAL (decl
))
3348 error_at (DECL_SOURCE_LOCATION (decl
),
3349 "can%'t set %qE attribute after definition", name
);
3350 *no_add_attrs
= true;
3356 /* Handle a "returns_nonnull" attribute; arguments as in
3357 struct attribute_spec.handler. */
3360 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3363 // Even without a prototype we still have a return type we can check.
3364 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3366 error ("returns_nonnull attribute on a function not returning a pointer");
3367 *no_add_attrs
= true;
3372 /* Handle a "designated_init" attribute; arguments as in
3373 struct attribute_spec.handler. */
3376 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3379 if (TREE_CODE (*node
) != RECORD_TYPE
)
3381 error ("%qE attribute is only valid on %<struct%> type", name
);
3382 *no_add_attrs
= true;
3388 /* Handle a "fallthrough" attribute; arguments as in struct
3389 attribute_spec.handler. */
3392 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3395 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3396 *no_add_attrs
= true;
3401 handle_patchable_function_entry_attribute (tree
*, tree
, tree
, int, bool *)
3403 /* Nothing to be done here. */