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_leaf_attribute (tree
*, tree
, tree
, int, bool *);
70 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
72 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
73 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
74 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
75 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
76 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
77 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
79 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
81 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
82 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
84 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
86 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
87 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
88 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
89 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
90 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
91 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
92 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
93 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
94 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
95 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
96 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
97 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
99 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
101 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
103 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
105 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
106 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
107 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
109 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
110 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
111 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
112 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
113 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
115 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
117 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
118 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
119 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
120 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
122 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
123 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
124 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
125 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
126 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
127 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
128 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
129 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
130 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
131 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
132 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
133 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
134 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
135 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
137 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
138 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
140 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
141 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
142 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
143 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
144 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
146 /* Table of machine-independent attributes common to all C-like languages.
148 All attributes referencing arguments should be additionally processed
149 in chkp_copy_function_type_adding_bounds for correct instrumentation
150 by Pointer Bounds Checker.
151 Current list of processed common attributes: nonnull. */
152 const struct attribute_spec c_common_attribute_table
[] =
154 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
155 affects_type_identity } */
156 { "packed", 0, 0, false, false, false,
157 handle_packed_attribute
, false},
158 { "nocommon", 0, 0, true, false, false,
159 handle_nocommon_attribute
, false},
160 { "common", 0, 0, true, false, false,
161 handle_common_attribute
, false },
162 /* FIXME: logically, noreturn attributes should be listed as
163 "false, true, true" and apply to function types. But implementing this
164 would require all the places in the compiler that use TREE_THIS_VOLATILE
165 on a decl to identify non-returning functions to be located and fixed
166 to check the function type instead. */
167 { "noreturn", 0, 0, true, false, false,
168 handle_noreturn_attribute
, false },
169 { "volatile", 0, 0, true, false, false,
170 handle_noreturn_attribute
, false },
171 { "stack_protect", 0, 0, true, false, false,
172 handle_stack_protect_attribute
, false },
173 { "noinline", 0, 0, true, false, false,
174 handle_noinline_attribute
, false },
175 { "noclone", 0, 0, true, false, false,
176 handle_noclone_attribute
, false },
177 { "no_icf", 0, 0, true, false, false,
178 handle_noicf_attribute
, false },
179 { "leaf", 0, 0, true, false, false,
180 handle_leaf_attribute
, false },
181 { "always_inline", 0, 0, true, false, false,
182 handle_always_inline_attribute
, false },
183 { "gnu_inline", 0, 0, true, false, false,
184 handle_gnu_inline_attribute
, false },
185 { "artificial", 0, 0, true, false, false,
186 handle_artificial_attribute
, false },
187 { "flatten", 0, 0, true, false, false,
188 handle_flatten_attribute
, false },
189 { "used", 0, 0, true, false, false,
190 handle_used_attribute
, false },
191 { "unused", 0, 0, false, false, false,
192 handle_unused_attribute
, false },
193 { "externally_visible", 0, 0, true, false, false,
194 handle_externally_visible_attribute
, false },
195 { "no_reorder", 0, 0, true, false, false,
196 handle_no_reorder_attribute
, false },
197 /* The same comments as for noreturn attributes apply to const ones. */
198 { "const", 0, 0, true, false, false,
199 handle_const_attribute
, false },
200 { "scalar_storage_order", 1, 1, false, false, false,
201 handle_scalar_storage_order_attribute
, false },
202 { "transparent_union", 0, 0, false, false, false,
203 handle_transparent_union_attribute
, false },
204 { "constructor", 0, 1, true, false, false,
205 handle_constructor_attribute
, false },
206 { "destructor", 0, 1, true, false, false,
207 handle_destructor_attribute
, false },
208 { "mode", 1, 1, false, true, false,
209 handle_mode_attribute
, false },
210 { "section", 1, 1, true, false, false,
211 handle_section_attribute
, false },
212 { "aligned", 0, 1, false, false, false,
213 handle_aligned_attribute
, false },
214 { "weak", 0, 0, true, false, false,
215 handle_weak_attribute
, false },
216 { "noplt", 0, 0, true, false, false,
217 handle_noplt_attribute
, false },
218 { "ifunc", 1, 1, true, false, false,
219 handle_ifunc_attribute
, false },
220 { "alias", 1, 1, true, false, false,
221 handle_alias_attribute
, false },
222 { "weakref", 0, 1, true, false, false,
223 handle_weakref_attribute
, false },
224 { "no_instrument_function", 0, 0, true, false, false,
225 handle_no_instrument_function_attribute
,
227 { "no_profile_instrument_function", 0, 0, true, false, false,
228 handle_no_profile_instrument_function_attribute
,
230 { "malloc", 0, 0, true, false, false,
231 handle_malloc_attribute
, false },
232 { "returns_twice", 0, 0, true, false, false,
233 handle_returns_twice_attribute
, false },
234 { "no_stack_limit", 0, 0, true, false, false,
235 handle_no_limit_stack_attribute
, false },
236 { "pure", 0, 0, true, false, false,
237 handle_pure_attribute
, false },
238 { "transaction_callable", 0, 0, false, true, false,
239 handle_tm_attribute
, false },
240 { "transaction_unsafe", 0, 0, false, true, false,
241 handle_tm_attribute
, true },
242 { "transaction_safe", 0, 0, false, true, false,
243 handle_tm_attribute
, true },
244 { "transaction_safe_dynamic", 0, 0, true, false, false,
245 handle_tm_attribute
, false },
246 { "transaction_may_cancel_outer", 0, 0, false, true, false,
247 handle_tm_attribute
, false },
248 /* ??? These two attributes didn't make the transition from the
249 Intel language document to the multi-vendor language document. */
250 { "transaction_pure", 0, 0, false, true, false,
251 handle_tm_attribute
, false },
252 { "transaction_wrap", 1, 1, true, false, false,
253 handle_tm_wrap_attribute
, false },
254 /* For internal use (marking of builtins) only. The name contains space
255 to prevent its usage in source code. */
256 { "no vops", 0, 0, true, false, false,
257 handle_novops_attribute
, false },
258 { "deprecated", 0, 1, false, false, false,
259 handle_deprecated_attribute
, false },
260 { "vector_size", 1, 1, false, true, false,
261 handle_vector_size_attribute
, true },
262 { "visibility", 1, 1, false, false, false,
263 handle_visibility_attribute
, false },
264 { "tls_model", 1, 1, true, false, false,
265 handle_tls_model_attribute
, false },
266 { "nonnull", 0, -1, false, true, true,
267 handle_nonnull_attribute
, false },
268 { "nothrow", 0, 0, true, false, false,
269 handle_nothrow_attribute
, false },
270 { "may_alias", 0, 0, false, true, false, NULL
, false },
271 { "cleanup", 1, 1, true, false, false,
272 handle_cleanup_attribute
, false },
273 { "warn_unused_result", 0, 0, false, true, true,
274 handle_warn_unused_result_attribute
, false },
275 { "sentinel", 0, 1, false, true, true,
276 handle_sentinel_attribute
, false },
277 /* For internal use (marking of builtins) only. The name contains space
278 to prevent its usage in source code. */
279 { "type generic", 0, 0, false, true, true,
280 handle_type_generic_attribute
, false },
281 { "alloc_size", 1, 2, false, true, true,
282 handle_alloc_size_attribute
, false },
283 { "cold", 0, 0, true, false, false,
284 handle_cold_attribute
, false },
285 { "hot", 0, 0, true, false, false,
286 handle_hot_attribute
, false },
287 { "no_address_safety_analysis",
288 0, 0, true, false, false,
289 handle_no_address_safety_analysis_attribute
,
291 { "no_sanitize", 1, 1, true, false, false,
292 handle_no_sanitize_attribute
,
294 { "no_sanitize_address", 0, 0, true, false, false,
295 handle_no_sanitize_address_attribute
,
297 { "no_sanitize_thread", 0, 0, true, false, false,
298 handle_no_sanitize_thread_attribute
,
300 { "no_sanitize_undefined", 0, 0, true, false, false,
301 handle_no_sanitize_undefined_attribute
,
303 { "asan odr indicator", 0, 0, true, false, false,
304 handle_asan_odr_indicator_attribute
,
306 { "warning", 1, 1, true, false, false,
307 handle_error_attribute
, false },
308 { "error", 1, 1, true, false, false,
309 handle_error_attribute
, false },
310 { "target", 1, -1, true, false, false,
311 handle_target_attribute
, false },
312 { "target_clones", 1, -1, true, false, false,
313 handle_target_clones_attribute
, false },
314 { "optimize", 1, -1, true, false, false,
315 handle_optimize_attribute
, false },
316 /* For internal use only. The leading '*' both prevents its usage in
317 source code and signals that it may be overridden by machine tables. */
318 { "*tm regparm", 0, 0, false, true, true,
319 ignore_attribute
, false },
320 { "no_split_stack", 0, 0, true, false, false,
321 handle_no_split_stack_attribute
, false },
322 /* For internal use (marking of builtins and runtime functions) only.
323 The name contains space to prevent its usage in source code. */
324 { "fn spec", 1, 1, false, true, true,
325 handle_fnspec_attribute
, false },
326 { "warn_unused", 0, 0, false, false, false,
327 handle_warn_unused_attribute
, false },
328 { "returns_nonnull", 0, 0, false, true, true,
329 handle_returns_nonnull_attribute
, false },
330 { "omp declare simd", 0, -1, true, false, false,
331 handle_omp_declare_simd_attribute
, false },
332 { "cilk simd function", 0, -1, true, false, false,
333 handle_omp_declare_simd_attribute
, false },
334 { "simd", 0, 1, true, false, false,
335 handle_simd_attribute
, false },
336 { "omp declare target", 0, 0, true, false, false,
337 handle_omp_declare_target_attribute
, false },
338 { "omp declare target link", 0, 0, true, false, false,
339 handle_omp_declare_target_attribute
, false },
340 { "alloc_align", 1, 1, false, true, true,
341 handle_alloc_align_attribute
, false },
342 { "assume_aligned", 1, 2, false, true, true,
343 handle_assume_aligned_attribute
, false },
344 { "designated_init", 0, 0, false, true, false,
345 handle_designated_init_attribute
, false },
346 { "bnd_variable_size", 0, 0, true, false, false,
347 handle_bnd_variable_size_attribute
, false },
348 { "bnd_legacy", 0, 0, true, false, false,
349 handle_bnd_legacy
, false },
350 { "bnd_instrument", 0, 0, true, false, false,
351 handle_bnd_instrument
, false },
352 { "fallthrough", 0, 0, false, false, false,
353 handle_fallthrough_attribute
, false },
354 { NULL
, 0, 0, false, false, false, NULL
, false }
357 /* Give the specifications for the format attributes, used by C and all
360 All attributes referencing arguments should be additionally processed
361 in chkp_copy_function_type_adding_bounds for correct instrumentation
362 by Pointer Bounds Checker.
363 Current list of processed format attributes: format, format_arg. */
364 const struct attribute_spec c_common_format_attribute_table
[] =
366 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
367 affects_type_identity } */
368 { "format", 3, 3, false, true, true,
369 handle_format_attribute
, false },
370 { "format_arg", 1, 1, false, true, true,
371 handle_format_arg_attribute
, false },
372 { NULL
, 0, 0, false, false, false, NULL
, false }
375 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
376 identifier as an argument, so the front end shouldn't look it up. */
379 attribute_takes_identifier_p (const_tree attr_id
)
381 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
383 /* Unknown attribute that we'll end up ignoring, return true so we
384 don't complain about an identifier argument. */
386 else if (!strcmp ("mode", spec
->name
)
387 || !strcmp ("format", spec
->name
)
388 || !strcmp ("cleanup", spec
->name
))
391 return targetm
.attribute_takes_identifier_p (attr_id
);
394 /* Attribute handlers common to C front ends. */
396 /* Handle a "packed" attribute; arguments as in
397 struct attribute_spec.handler. */
400 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
401 int flags
, bool *no_add_attrs
)
405 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
406 *node
= build_variant_type_copy (*node
);
407 TYPE_PACKED (*node
) = 1;
409 else if (TREE_CODE (*node
) == FIELD_DECL
)
411 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
412 /* Still pack bitfields. */
413 && ! DECL_INITIAL (*node
))
414 warning (OPT_Wattributes
,
415 "%qE attribute ignored for field of type %qT",
416 name
, TREE_TYPE (*node
));
418 DECL_PACKED (*node
) = 1;
420 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
421 used for DECL_REGISTER. It wouldn't mean anything anyway.
422 We can't set DECL_PACKED on the type of a TYPE_DECL, because
423 that changes what the typedef is typing. */
426 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
427 *no_add_attrs
= true;
433 /* Handle a "nocommon" attribute; arguments as in
434 struct attribute_spec.handler. */
437 handle_nocommon_attribute (tree
*node
, tree name
,
438 tree
ARG_UNUSED (args
),
439 int ARG_UNUSED (flags
), bool *no_add_attrs
)
442 DECL_COMMON (*node
) = 0;
445 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
446 *no_add_attrs
= true;
452 /* Handle a "common" attribute; arguments as in
453 struct attribute_spec.handler. */
456 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
457 int ARG_UNUSED (flags
), bool *no_add_attrs
)
460 DECL_COMMON (*node
) = 1;
463 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
464 *no_add_attrs
= true;
470 /* Handle a "noreturn" attribute; arguments as in
471 struct attribute_spec.handler. */
474 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
475 int ARG_UNUSED (flags
), bool *no_add_attrs
)
477 tree type
= TREE_TYPE (*node
);
479 /* See FIXME comment in c_common_attribute_table. */
480 if (TREE_CODE (*node
) == FUNCTION_DECL
481 || objc_method_decl (TREE_CODE (*node
)))
482 TREE_THIS_VOLATILE (*node
) = 1;
483 else if (TREE_CODE (type
) == POINTER_TYPE
484 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
486 = (build_qualified_type
488 (build_type_variant (TREE_TYPE (type
),
489 TYPE_READONLY (TREE_TYPE (type
)), 1)),
493 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
494 *no_add_attrs
= true;
500 /* Handle a "hot" and attribute; arguments as in
501 struct attribute_spec.handler. */
504 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
505 int ARG_UNUSED (flags
), bool *no_add_attrs
)
507 if (TREE_CODE (*node
) == FUNCTION_DECL
508 || TREE_CODE (*node
) == LABEL_DECL
)
510 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
512 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
513 "with attribute %qs", name
, "cold");
514 *no_add_attrs
= true;
516 /* Most of the rest of the hot processing is done later with
521 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
522 *no_add_attrs
= true;
528 /* Handle a "cold" and attribute; arguments as in
529 struct attribute_spec.handler. */
532 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
533 int ARG_UNUSED (flags
), bool *no_add_attrs
)
535 if (TREE_CODE (*node
) == FUNCTION_DECL
536 || TREE_CODE (*node
) == LABEL_DECL
)
538 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
540 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
541 "with attribute %qs", name
, "hot");
542 *no_add_attrs
= true;
544 /* Most of the rest of the cold processing is done later with
549 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
550 *no_add_attrs
= true;
556 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
559 add_no_sanitize_value (tree node
, unsigned int flags
)
561 tree attr
= lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node
));
564 unsigned int old_value
= tree_to_uhwi (TREE_VALUE (attr
));
567 if (flags
== old_value
)
570 TREE_VALUE (attr
) = build_int_cst (unsigned_type_node
, flags
);
573 DECL_ATTRIBUTES (node
)
574 = tree_cons (get_identifier ("no_sanitize"),
575 build_int_cst (unsigned_type_node
, flags
),
576 DECL_ATTRIBUTES (node
));
579 /* Handle a "no_sanitize" attribute; arguments as in
580 struct attribute_spec.handler. */
583 handle_no_sanitize_attribute (tree
*node
, tree name
, tree args
, int,
586 *no_add_attrs
= true;
587 tree id
= TREE_VALUE (args
);
588 if (TREE_CODE (*node
) != FUNCTION_DECL
)
590 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
594 if (TREE_CODE (id
) != STRING_CST
)
596 error ("no_sanitize argument not a string");
600 char *error_value
= NULL
;
601 char *string
= ASTRDUP (TREE_STRING_POINTER (id
));
602 unsigned int flags
= parse_no_sanitize_attribute (string
, &error_value
);
606 error ("wrong argument: \"%s\"", error_value
);
610 add_no_sanitize_value (*node
, flags
);
615 /* Handle a "no_sanitize_address" attribute; arguments as in
616 struct attribute_spec.handler. */
619 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
622 *no_add_attrs
= true;
623 if (TREE_CODE (*node
) != FUNCTION_DECL
)
624 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
626 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
631 /* Handle a "no_sanitize_thread" attribute; arguments as in
632 struct attribute_spec.handler. */
635 handle_no_sanitize_thread_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_THREAD
);
648 /* Handle a "no_address_safety_analysis" attribute; arguments as in
649 struct attribute_spec.handler. */
652 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
655 *no_add_attrs
= true;
656 if (TREE_CODE (*node
) != FUNCTION_DECL
)
657 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
659 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
664 /* Handle a "no_sanitize_undefined" attribute; arguments as in
665 struct attribute_spec.handler. */
668 handle_no_sanitize_undefined_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
,
676 SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
681 /* Handle an "asan odr indicator" attribute; arguments as in
682 struct attribute_spec.handler. */
685 handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int, bool *)
690 /* Handle a "stack_protect" attribute; arguments as in
691 struct attribute_spec.handler. */
694 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
697 if (TREE_CODE (*node
) != FUNCTION_DECL
)
699 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
700 *no_add_attrs
= true;
703 DECL_ATTRIBUTES (*node
)
704 = tree_cons (get_identifier ("stack_protect"),
705 NULL_TREE
, DECL_ATTRIBUTES (*node
));
710 /* Handle a "noinline" attribute; arguments as in
711 struct attribute_spec.handler. */
714 handle_noinline_attribute (tree
*node
, tree name
,
715 tree
ARG_UNUSED (args
),
716 int ARG_UNUSED (flags
), bool *no_add_attrs
)
718 if (TREE_CODE (*node
) == FUNCTION_DECL
)
720 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
722 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
723 "with attribute %qs", name
, "always_inline");
724 *no_add_attrs
= true;
727 DECL_UNINLINABLE (*node
) = 1;
731 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
732 *no_add_attrs
= true;
738 /* Handle a "noclone" attribute; arguments as in
739 struct attribute_spec.handler. */
742 handle_noclone_attribute (tree
*node
, tree name
,
743 tree
ARG_UNUSED (args
),
744 int ARG_UNUSED (flags
), bool *no_add_attrs
)
746 if (TREE_CODE (*node
) != FUNCTION_DECL
)
748 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
749 *no_add_attrs
= true;
755 /* Handle a "no_icf" attribute; arguments as in
756 struct attribute_spec.handler. */
759 handle_noicf_attribute (tree
*node
, tree name
,
760 tree
ARG_UNUSED (args
),
761 int ARG_UNUSED (flags
), bool *no_add_attrs
)
763 if (TREE_CODE (*node
) != FUNCTION_DECL
)
765 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
766 *no_add_attrs
= true;
773 /* Handle a "always_inline" attribute; arguments as in
774 struct attribute_spec.handler. */
777 handle_always_inline_attribute (tree
*node
, tree name
,
778 tree
ARG_UNUSED (args
),
779 int ARG_UNUSED (flags
),
782 if (TREE_CODE (*node
) == FUNCTION_DECL
)
784 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
786 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
787 "with %qs attribute", name
, "noinline");
788 *no_add_attrs
= true;
790 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
792 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
793 "with %qs attribute", name
, "target_clones");
794 *no_add_attrs
= true;
797 /* Set the attribute and mark it for disregarding inline
799 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
803 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
804 *no_add_attrs
= true;
810 /* Handle a "gnu_inline" attribute; arguments as in
811 struct attribute_spec.handler. */
814 handle_gnu_inline_attribute (tree
*node
, tree name
,
815 tree
ARG_UNUSED (args
),
816 int ARG_UNUSED (flags
),
819 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
821 /* Do nothing else, just set the attribute. We'll get at
822 it later with lookup_attribute. */
826 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
827 *no_add_attrs
= true;
833 /* Handle a "leaf" attribute; arguments as in
834 struct attribute_spec.handler. */
837 handle_leaf_attribute (tree
*node
, tree name
,
838 tree
ARG_UNUSED (args
),
839 int ARG_UNUSED (flags
), bool *no_add_attrs
)
841 if (TREE_CODE (*node
) != FUNCTION_DECL
)
843 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
844 *no_add_attrs
= true;
846 if (!TREE_PUBLIC (*node
))
848 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
850 *no_add_attrs
= true;
856 /* Handle an "artificial" attribute; arguments as in
857 struct attribute_spec.handler. */
860 handle_artificial_attribute (tree
*node
, tree name
,
861 tree
ARG_UNUSED (args
),
862 int ARG_UNUSED (flags
),
865 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
867 /* Do nothing else, just set the attribute. We'll get at
868 it later with lookup_attribute. */
872 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
873 *no_add_attrs
= true;
879 /* Handle a "flatten" attribute; arguments as in
880 struct attribute_spec.handler. */
883 handle_flatten_attribute (tree
*node
, tree name
,
884 tree args ATTRIBUTE_UNUSED
,
885 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
887 if (TREE_CODE (*node
) == FUNCTION_DECL
)
888 /* Do nothing else, just set the attribute. We'll get at
889 it later with lookup_attribute. */
893 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
894 *no_add_attrs
= true;
900 /* Handle a "warning" or "error" attribute; arguments as in
901 struct attribute_spec.handler. */
904 handle_error_attribute (tree
*node
, tree name
, tree args
,
905 int ARG_UNUSED (flags
), bool *no_add_attrs
)
907 if (TREE_CODE (*node
) == FUNCTION_DECL
908 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
909 /* Do nothing else, just set the attribute. We'll get at
910 it later with lookup_attribute. */
914 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
915 *no_add_attrs
= true;
921 /* Handle a "used" attribute; arguments as in
922 struct attribute_spec.handler. */
925 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
926 int ARG_UNUSED (flags
), bool *no_add_attrs
)
930 if (TREE_CODE (node
) == FUNCTION_DECL
931 || (VAR_P (node
) && TREE_STATIC (node
))
932 || (TREE_CODE (node
) == TYPE_DECL
))
934 TREE_USED (node
) = 1;
935 DECL_PRESERVE_P (node
) = 1;
937 DECL_READ_P (node
) = 1;
941 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
942 *no_add_attrs
= true;
948 /* Handle a "unused" attribute; arguments as in
949 struct attribute_spec.handler. */
952 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
953 int flags
, bool *no_add_attrs
)
959 if (TREE_CODE (decl
) == PARM_DECL
960 || VAR_OR_FUNCTION_DECL_P (decl
)
961 || TREE_CODE (decl
) == LABEL_DECL
962 || TREE_CODE (decl
) == CONST_DECL
963 || TREE_CODE (decl
) == TYPE_DECL
)
965 TREE_USED (decl
) = 1;
966 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
967 DECL_READ_P (decl
) = 1;
971 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
972 *no_add_attrs
= true;
977 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
978 *node
= build_variant_type_copy (*node
);
979 TREE_USED (*node
) = 1;
985 /* Handle a "externally_visible" attribute; arguments as in
986 struct attribute_spec.handler. */
989 handle_externally_visible_attribute (tree
*pnode
, tree name
,
990 tree
ARG_UNUSED (args
),
991 int ARG_UNUSED (flags
),
996 if (VAR_OR_FUNCTION_DECL_P (node
))
998 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
999 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
1001 warning (OPT_Wattributes
,
1002 "%qE attribute have effect only on public objects", name
);
1003 *no_add_attrs
= true;
1008 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1009 *no_add_attrs
= true;
1015 /* Handle the "no_reorder" attribute. Arguments as in
1016 struct attribute_spec.handler. */
1019 handle_no_reorder_attribute (tree
*pnode
,
1027 if (!VAR_OR_FUNCTION_DECL_P (node
)
1028 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
1030 warning (OPT_Wattributes
,
1031 "%qE attribute only affects top level objects",
1033 *no_add_attrs
= true;
1039 /* Handle a "const" attribute; arguments as in
1040 struct attribute_spec.handler. */
1043 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1044 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1046 tree type
= TREE_TYPE (*node
);
1048 /* See FIXME comment on noreturn in c_common_attribute_table. */
1049 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1050 TREE_READONLY (*node
) = 1;
1051 else if (TREE_CODE (type
) == POINTER_TYPE
1052 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1054 = (build_qualified_type
1056 (build_type_variant (TREE_TYPE (type
), 1,
1057 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
1058 TYPE_QUALS (type
)));
1061 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1062 *no_add_attrs
= true;
1068 /* Handle a "scalar_storage_order" attribute; arguments as in
1069 struct attribute_spec.handler. */
1072 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
1073 int flags
, bool *no_add_attrs
)
1075 tree id
= TREE_VALUE (args
);
1078 if (TREE_CODE (*node
) == TYPE_DECL
1079 && ! (flags
& ATTR_FLAG_CXX11
))
1080 node
= &TREE_TYPE (*node
);
1083 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
1085 error ("scalar_storage_order is not supported because endianness "
1090 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
1092 bool reverse
= false;
1094 if (TREE_CODE (id
) == STRING_CST
1095 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1096 reverse
= !BYTES_BIG_ENDIAN
;
1097 else if (TREE_CODE (id
) == STRING_CST
1098 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1099 reverse
= BYTES_BIG_ENDIAN
;
1102 error ("scalar_storage_order argument must be one of \"big-endian\""
1103 " or \"little-endian\"");
1107 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1110 /* A type variant isn't good enough, since we don't want a cast
1111 to such a type to be removed as a no-op. */
1112 *node
= type
= build_duplicate_type (type
);
1115 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1119 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1120 *no_add_attrs
= true;
1124 /* Handle a "transparent_union" attribute; arguments as in
1125 struct attribute_spec.handler. */
1128 handle_transparent_union_attribute (tree
*node
, tree name
,
1129 tree
ARG_UNUSED (args
), int flags
,
1134 *no_add_attrs
= true;
1136 if (TREE_CODE (*node
) == TYPE_DECL
1137 && ! (flags
& ATTR_FLAG_CXX11
))
1138 node
= &TREE_TYPE (*node
);
1141 if (TREE_CODE (type
) == UNION_TYPE
)
1143 /* Make sure that the first field will work for a transparent union.
1144 If the type isn't complete yet, leave the check to the code in
1146 if (TYPE_SIZE (type
))
1148 tree first
= first_field (type
);
1149 if (first
== NULL_TREE
1150 || DECL_ARTIFICIAL (first
)
1151 || TYPE_MODE (type
) != DECL_MODE (first
))
1155 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1157 /* If the type isn't complete yet, setting the flag
1158 on a variant wouldn't ever be checked. */
1159 if (!TYPE_SIZE (type
))
1162 /* build_duplicate_type doesn't work for C++. */
1163 if (c_dialect_cxx ())
1166 /* A type variant isn't good enough, since we don't want a cast
1167 to such a type to be removed as a no-op. */
1168 *node
= type
= build_duplicate_type (type
);
1171 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1172 TYPE_TRANSPARENT_AGGR (t
) = 1;
1177 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1181 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1182 get the requested priority for a constructor or destructor,
1183 possibly issuing diagnostics for invalid or reserved
1186 static priority_type
1187 get_priority (tree args
, bool is_destructor
)
1193 return DEFAULT_INIT_PRIORITY
;
1195 if (!SUPPORTS_INIT_PRIORITY
)
1198 error ("destructor priorities are not supported");
1200 error ("constructor priorities are not supported");
1201 return DEFAULT_INIT_PRIORITY
;
1204 arg
= TREE_VALUE (args
);
1205 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1207 if (arg
== error_mark_node
)
1208 return DEFAULT_INIT_PRIORITY
;
1209 arg
= default_conversion (arg
);
1210 if (!tree_fits_shwi_p (arg
)
1211 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1214 pri
= tree_to_shwi (arg
);
1215 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1218 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1222 "destructor priorities from 0 to %d are reserved "
1223 "for the implementation",
1224 MAX_RESERVED_INIT_PRIORITY
);
1227 "constructor priorities from 0 to %d are reserved "
1228 "for the implementation",
1229 MAX_RESERVED_INIT_PRIORITY
);
1235 error ("destructor priorities must be integers from 0 to %d inclusive",
1238 error ("constructor priorities must be integers from 0 to %d inclusive",
1240 return DEFAULT_INIT_PRIORITY
;
1243 /* Handle a "constructor" attribute; arguments as in
1244 struct attribute_spec.handler. */
1247 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1248 int ARG_UNUSED (flags
),
1252 tree type
= TREE_TYPE (decl
);
1254 if (TREE_CODE (decl
) == FUNCTION_DECL
1255 && TREE_CODE (type
) == FUNCTION_TYPE
1256 && decl_function_context (decl
) == 0)
1258 priority_type priority
;
1259 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1260 priority
= get_priority (args
, /*is_destructor=*/false);
1261 SET_DECL_INIT_PRIORITY (decl
, priority
);
1262 TREE_USED (decl
) = 1;
1266 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1267 *no_add_attrs
= true;
1273 /* Handle a "destructor" attribute; arguments as in
1274 struct attribute_spec.handler. */
1277 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1278 int ARG_UNUSED (flags
),
1282 tree type
= TREE_TYPE (decl
);
1284 if (TREE_CODE (decl
) == FUNCTION_DECL
1285 && TREE_CODE (type
) == FUNCTION_TYPE
1286 && decl_function_context (decl
) == 0)
1288 priority_type priority
;
1289 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1290 priority
= get_priority (args
, /*is_destructor=*/true);
1291 SET_DECL_FINI_PRIORITY (decl
, priority
);
1292 TREE_USED (decl
) = 1;
1296 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1297 *no_add_attrs
= true;
1303 /* Nonzero if the mode is a valid vector mode for this architecture.
1304 This returns nonzero even if there is no hardware support for the
1305 vector mode, but we can emulate with narrower modes. */
1308 vector_mode_valid_p (machine_mode mode
)
1310 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1311 machine_mode innermode
;
1313 /* Doh! What's going on? */
1314 if (mclass
!= MODE_VECTOR_INT
1315 && mclass
!= MODE_VECTOR_FLOAT
1316 && mclass
!= MODE_VECTOR_FRACT
1317 && mclass
!= MODE_VECTOR_UFRACT
1318 && mclass
!= MODE_VECTOR_ACCUM
1319 && mclass
!= MODE_VECTOR_UACCUM
)
1322 /* Hardware support. Woo hoo! */
1323 if (targetm
.vector_mode_supported_p (mode
))
1326 innermode
= GET_MODE_INNER (mode
);
1328 /* We should probably return 1 if requesting V4DI and we have no DI,
1329 but we have V2DI, but this is probably very unlikely. */
1331 /* If we have support for the inner mode, we can safely emulate it.
1332 We may not have V2DI, but me can emulate with a pair of DIs. */
1333 return targetm
.scalar_mode_supported_p (innermode
);
1337 /* Handle a "mode" attribute; arguments as in
1338 struct attribute_spec.handler. */
1341 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1342 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1345 tree ident
= TREE_VALUE (args
);
1347 *no_add_attrs
= true;
1349 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1350 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1354 const char *p
= IDENTIFIER_POINTER (ident
);
1355 int len
= strlen (p
);
1356 machine_mode mode
= VOIDmode
;
1360 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1361 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1363 char *newp
= (char *) alloca (len
- 1);
1365 strcpy (newp
, &p
[2]);
1366 newp
[len
- 4] = '\0';
1370 /* Change this type to have a type with the specified mode.
1371 First check for the special modes. */
1372 if (!strcmp (p
, "byte"))
1374 else if (!strcmp (p
, "word"))
1376 else if (!strcmp (p
, "pointer"))
1378 else if (!strcmp (p
, "libgcc_cmp_return"))
1379 mode
= targetm
.libgcc_cmp_return_mode ();
1380 else if (!strcmp (p
, "libgcc_shift_count"))
1381 mode
= targetm
.libgcc_shift_count_mode ();
1382 else if (!strcmp (p
, "unwind_word"))
1383 mode
= targetm
.unwind_word_mode ();
1385 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1386 if (!strcmp (p
, GET_MODE_NAME (j
)))
1388 mode
= (machine_mode
) j
;
1392 if (mode
== VOIDmode
)
1394 error ("unknown machine mode %qE", ident
);
1399 switch (GET_MODE_CLASS (mode
))
1402 case MODE_PARTIAL_INT
:
1404 case MODE_DECIMAL_FLOAT
:
1409 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
1412 case MODE_COMPLEX_INT
:
1413 case MODE_COMPLEX_FLOAT
:
1414 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1417 case MODE_VECTOR_INT
:
1418 case MODE_VECTOR_FLOAT
:
1419 case MODE_VECTOR_FRACT
:
1420 case MODE_VECTOR_UFRACT
:
1421 case MODE_VECTOR_ACCUM
:
1422 case MODE_VECTOR_UACCUM
:
1423 warning (OPT_Wattributes
, "specifying vector types with "
1424 "__attribute__ ((mode)) is deprecated");
1425 warning (OPT_Wattributes
,
1426 "use __attribute__ ((vector_size)) instead");
1427 valid_mode
= vector_mode_valid_p (mode
);
1435 error ("unable to emulate %qs", p
);
1439 if (POINTER_TYPE_P (type
))
1441 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1442 tree (*fn
)(tree
, machine_mode
, bool);
1444 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
1446 error ("invalid pointer mode %qs", p
);
1450 if (TREE_CODE (type
) == POINTER_TYPE
)
1451 fn
= build_pointer_type_for_mode
;
1453 fn
= build_reference_type_for_mode
;
1454 typefm
= fn (TREE_TYPE (type
), mode
, false);
1458 /* For fixed-point modes, we need to test if the signness of type
1459 and the machine mode are consistent. */
1460 if (ALL_FIXED_POINT_MODE_P (mode
)
1461 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1463 error ("signedness of type and machine mode %qs don%'t match", p
);
1466 /* For fixed-point modes, we need to pass saturating info. */
1467 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1468 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1469 : TYPE_UNSIGNED (type
));
1472 if (typefm
== NULL_TREE
)
1474 error ("no data type for mode %qs", p
);
1477 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1479 /* For enumeral types, copy the precision from the integer
1480 type returned above. If not an INTEGER_TYPE, we can't use
1481 this mode for this type. */
1482 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1484 error ("cannot use mode %qs for enumeral types", p
);
1488 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1490 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1495 /* We cannot build a type variant, as there's code that assumes
1496 that TYPE_MAIN_VARIANT has the same mode. This includes the
1497 debug generators. Instead, create a subrange type. This
1498 results in all of the enumeral values being emitted only once
1499 in the original, and the subtype gets them by reference. */
1500 if (TYPE_UNSIGNED (type
))
1501 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1503 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1504 TREE_TYPE (typefm
) = type
;
1507 else if (VECTOR_MODE_P (mode
)
1508 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1509 : TREE_CODE (type
) != TREE_CODE (typefm
))
1511 error ("mode %qs applied to inappropriate type", p
);
1515 *node
= build_qualified_type (typefm
, TYPE_QUALS (type
));
1521 /* Handle a "section" attribute; arguments as in
1522 struct attribute_spec.handler. */
1525 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1526 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1530 if (!targetm_common
.have_named_sections
)
1532 error_at (DECL_SOURCE_LOCATION (*node
),
1533 "section attributes are not supported for this target");
1537 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1539 error ("section attribute not allowed for %q+D", *node
);
1543 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1545 error ("section attribute argument not a string constant");
1550 && current_function_decl
!= NULL_TREE
1551 && !TREE_STATIC (decl
))
1553 error_at (DECL_SOURCE_LOCATION (decl
),
1554 "section attribute cannot be specified for local variables");
1558 /* The decl may have already been given a section attribute
1559 from a previous declaration. Ensure they match. */
1560 if (DECL_SECTION_NAME (decl
) != NULL
1561 && strcmp (DECL_SECTION_NAME (decl
),
1562 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1564 error ("section of %q+D conflicts with previous declaration", *node
);
1569 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1570 && DECL_THREAD_LOCAL_P (decl
))
1572 error ("section of %q+D cannot be overridden", *node
);
1576 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1580 *no_add_attrs
= true;
1584 /* If in c++-11, check if the c++-11 alignment constraint with respect
1585 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1586 c++-11 mode, does nothing.
1590 [* if the constant expression evaluates to a fundamental alignment,
1591 the alignment requirement of the declared entity shall be the
1592 specified fundamental alignment.
1594 * if the constant expression evaluates to an extended alignment
1595 and the implementation supports that alignment in the context
1596 of the declaration, the alignment of the declared entity shall
1599 * if the constant expression evaluates to an extended alignment
1600 and the implementation does not support that alignment in the
1601 context of the declaration, the program is ill-formed]. */
1604 check_cxx_fundamental_alignment_constraints (tree node
,
1608 bool alignment_too_large_p
= false;
1609 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1610 unsigned max_align
= 0;
1612 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1613 || (node
== NULL_TREE
|| node
== error_mark_node
))
1616 if (cxx_fundamental_alignment_p (requested_alignment
))
1621 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1622 /* For file scope variables and static members, the target supports
1623 alignments that are at most MAX_OFILE_ALIGNMENT. */
1624 max_align
= MAX_OFILE_ALIGNMENT
;
1626 /* For stack variables, the target supports at most
1627 MAX_STACK_ALIGNMENT. */
1628 max_align
= MAX_STACK_ALIGNMENT
;
1629 if (requested_alignment
> max_align
)
1630 alignment_too_large_p
= true;
1632 /* Let's be liberal for types and fields; don't limit their alignment any
1633 more than check_user_alignment already did. */
1635 if (alignment_too_large_p
)
1636 pedwarn (input_location
, OPT_Wattributes
,
1637 "requested alignment %d is larger than %d",
1638 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1640 return !alignment_too_large_p
;
1643 /* Handle a "aligned" attribute; arguments as in
1644 struct attribute_spec.handler. */
1647 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1648 int flags
, bool *no_add_attrs
)
1650 tree decl
= NULL_TREE
;
1658 align_expr
= TREE_VALUE (args
);
1659 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1660 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1661 align_expr
= default_conversion (align_expr
);
1664 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1669 type
= &TREE_TYPE (decl
);
1670 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1672 else if (TYPE_P (*node
))
1673 type
= node
, is_type
= 1;
1675 if ((i
= check_user_alignment (align_expr
, true)) == -1
1676 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
1677 *no_add_attrs
= true;
1680 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1681 /* OK, modify the type in place. */;
1682 /* If we have a TYPE_DECL, then copy the type, so that we
1683 don't accidentally modify a builtin type. See pushdecl. */
1684 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1685 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1687 tree tt
= TREE_TYPE (decl
);
1688 *type
= build_variant_type_copy (*type
);
1689 DECL_ORIGINAL_TYPE (decl
) = tt
;
1690 TYPE_NAME (*type
) = decl
;
1691 TREE_USED (*type
) = TREE_USED (decl
);
1692 TREE_TYPE (decl
) = *type
;
1695 *type
= build_variant_type_copy (*type
);
1697 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
1698 TYPE_USER_ALIGN (*type
) = 1;
1700 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1701 && TREE_CODE (decl
) != FIELD_DECL
)
1703 error ("alignment may not be specified for %q+D", decl
);
1704 *no_add_attrs
= true;
1706 else if (DECL_USER_ALIGN (decl
)
1707 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1708 /* C++-11 [dcl.align/4]:
1710 When multiple alignment-specifiers are specified for an
1711 entity, the alignment requirement shall be set to the
1712 strictest specified alignment.
1714 This formally comes from the c++11 specification but we are
1715 doing it for the GNU attribute syntax as well. */
1716 *no_add_attrs
= true;
1717 else if (TREE_CODE (decl
) == FUNCTION_DECL
1718 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1720 if (DECL_USER_ALIGN (decl
))
1721 error ("alignment for %q+D was previously specified as %d "
1722 "and may not be decreased", decl
,
1723 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1725 error ("alignment for %q+D must be at least %d", decl
,
1726 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1727 *no_add_attrs
= true;
1731 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
1732 DECL_USER_ALIGN (decl
) = 1;
1738 /* Handle a "weak" attribute; arguments as in
1739 struct attribute_spec.handler. */
1742 handle_weak_attribute (tree
*node
, tree name
,
1743 tree
ARG_UNUSED (args
),
1744 int ARG_UNUSED (flags
),
1745 bool * ARG_UNUSED (no_add_attrs
))
1747 if (TREE_CODE (*node
) == FUNCTION_DECL
1748 && DECL_DECLARED_INLINE_P (*node
))
1750 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1751 *no_add_attrs
= true;
1753 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1755 error ("indirect function %q+D cannot be declared weak", *node
);
1756 *no_add_attrs
= true;
1759 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1760 declare_weak (*node
);
1762 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1767 /* Handle a "noplt" attribute; arguments as in
1768 struct attribute_spec.handler. */
1771 handle_noplt_attribute (tree
*node
, tree name
,
1772 tree
ARG_UNUSED (args
),
1773 int ARG_UNUSED (flags
),
1774 bool * ARG_UNUSED (no_add_attrs
))
1776 if (TREE_CODE (*node
) != FUNCTION_DECL
)
1778 warning (OPT_Wattributes
,
1779 "%qE attribute is only applicable on functions", name
);
1780 *no_add_attrs
= true;
1786 /* Handle an "alias" or "ifunc" attribute; arguments as in
1787 struct attribute_spec.handler, except that IS_ALIAS tells us
1788 whether this is an alias as opposed to ifunc attribute. */
1791 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
1796 if (TREE_CODE (decl
) != FUNCTION_DECL
1797 && (!is_alias
|| !VAR_P (decl
)))
1799 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1800 *no_add_attrs
= true;
1802 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
1803 || (TREE_CODE (decl
) != FUNCTION_DECL
1804 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
1805 /* A static variable declaration is always a tentative definition,
1806 but the alias is a non-tentative definition which overrides. */
1807 || (TREE_CODE (decl
) != FUNCTION_DECL
1808 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
1810 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
1811 *no_add_attrs
= true;
1815 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
1816 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
1818 error ("weak %q+D cannot be defined %qE", decl
, name
);
1819 *no_add_attrs
= true;
1823 /* Note that the very first time we process a nested declaration,
1824 decl_function_context will not be set. Indeed, *would* never
1825 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
1826 we do below. After such frobbery, pushdecl would set the context.
1827 In any case, this is never what we want. */
1828 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
1832 id
= TREE_VALUE (args
);
1833 if (TREE_CODE (id
) != STRING_CST
)
1835 error ("attribute %qE argument not a string", name
);
1836 *no_add_attrs
= true;
1839 id
= get_identifier (TREE_STRING_POINTER (id
));
1840 /* This counts as a use of the object pointed to. */
1843 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1844 DECL_INITIAL (decl
) = error_mark_node
;
1846 TREE_STATIC (decl
) = 1;
1850 /* ifuncs are also aliases, so set that attribute too. */
1851 DECL_ATTRIBUTES (decl
)
1852 = tree_cons (get_identifier ("alias"), args
,
1853 DECL_ATTRIBUTES (decl
));
1854 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("ifunc"),
1855 NULL
, DECL_ATTRIBUTES (decl
));
1860 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1861 *no_add_attrs
= true;
1864 if (decl_in_symtab_p (*node
))
1866 struct symtab_node
*n
= symtab_node::get (decl
);
1867 if (n
&& n
->refuse_visibility_changes
)
1870 error ("%+qD declared alias after being used", decl
);
1872 error ("%+qD declared ifunc after being used", decl
);
1880 /* Handle an "alias" or "ifunc" attribute; arguments as in
1881 struct attribute_spec.handler. */
1884 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
1885 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1887 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
1890 /* Handle an "alias" or "ifunc" attribute; arguments as in
1891 struct attribute_spec.handler. */
1894 handle_alias_attribute (tree
*node
, tree name
, tree args
,
1895 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1897 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
1900 /* Handle a "weakref" attribute; arguments as in struct
1901 attribute_spec.handler. */
1904 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1905 int flags
, bool *no_add_attrs
)
1907 tree attr
= NULL_TREE
;
1909 /* We must ignore the attribute when it is associated with
1910 local-scoped decls, since attribute alias is ignored and many
1911 such symbols do not even have a DECL_WEAK field. */
1912 if (decl_function_context (*node
)
1913 || current_function_decl
1914 || !VAR_OR_FUNCTION_DECL_P (*node
))
1916 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1917 *no_add_attrs
= true;
1921 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1923 error ("indirect function %q+D cannot be declared weakref", *node
);
1924 *no_add_attrs
= true;
1928 /* The idea here is that `weakref("name")' mutates into `weakref,
1929 alias("name")', and weakref without arguments, in turn,
1930 implicitly adds weak. */
1934 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
1935 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
1937 *no_add_attrs
= true;
1939 decl_attributes (node
, attr
, flags
);
1943 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
1944 error_at (DECL_SOURCE_LOCATION (*node
),
1945 "weakref attribute must appear before alias attribute");
1947 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
1948 and that isn't supported; and because it wants to add it to
1949 the list of weak decls, which isn't helpful. */
1950 DECL_WEAK (*node
) = 1;
1953 if (decl_in_symtab_p (*node
))
1955 struct symtab_node
*n
= symtab_node::get (*node
);
1956 if (n
&& n
->refuse_visibility_changes
)
1957 error ("%+qD declared weakref after being used", *node
);
1963 /* Handle an "visibility" attribute; arguments as in
1964 struct attribute_spec.handler. */
1967 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
1968 int ARG_UNUSED (flags
),
1969 bool *ARG_UNUSED (no_add_attrs
))
1972 tree id
= TREE_VALUE (args
);
1973 enum symbol_visibility vis
;
1977 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
1979 else if (!RECORD_OR_UNION_TYPE_P (*node
))
1981 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
1985 else if (TYPE_FIELDS (*node
))
1987 error ("%qE attribute ignored because %qT is already defined",
1992 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
1994 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1998 if (TREE_CODE (id
) != STRING_CST
)
2000 error ("visibility argument not a string");
2004 /* If this is a type, set the visibility on the type decl. */
2007 decl
= TYPE_NAME (decl
);
2010 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
2012 warning (OPT_Wattributes
, "%qE attribute ignored on types",
2018 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
2019 vis
= VISIBILITY_DEFAULT
;
2020 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
2021 vis
= VISIBILITY_INTERNAL
;
2022 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
2023 vis
= VISIBILITY_HIDDEN
;
2024 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
2025 vis
= VISIBILITY_PROTECTED
;
2028 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2029 vis
= VISIBILITY_DEFAULT
;
2032 if (DECL_VISIBILITY_SPECIFIED (decl
)
2033 && vis
!= DECL_VISIBILITY (decl
))
2035 tree attributes
= (TYPE_P (*node
)
2036 ? TYPE_ATTRIBUTES (*node
)
2037 : DECL_ATTRIBUTES (decl
));
2038 if (lookup_attribute ("visibility", attributes
))
2039 error ("%qD redeclared with different visibility", decl
);
2040 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2041 && lookup_attribute ("dllimport", attributes
))
2042 error ("%qD was declared %qs which implies default visibility",
2044 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2045 && lookup_attribute ("dllexport", attributes
))
2046 error ("%qD was declared %qs which implies default visibility",
2050 DECL_VISIBILITY (decl
) = vis
;
2051 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
2053 /* Go ahead and attach the attribute to the node as well. This is needed
2054 so we can determine whether we have VISIBILITY_DEFAULT because the
2055 visibility was not specified, or because it was explicitly overridden
2056 from the containing scope. */
2061 /* Handle an "tls_model" attribute; arguments as in
2062 struct attribute_spec.handler. */
2065 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
2066 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2070 enum tls_model kind
;
2072 *no_add_attrs
= true;
2074 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
2076 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2080 kind
= DECL_TLS_MODEL (decl
);
2081 id
= TREE_VALUE (args
);
2082 if (TREE_CODE (id
) != STRING_CST
)
2084 error ("tls_model argument not a string");
2088 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
2089 kind
= TLS_MODEL_LOCAL_EXEC
;
2090 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
2091 kind
= TLS_MODEL_INITIAL_EXEC
;
2092 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
2093 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
2094 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
2095 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
2097 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2099 set_decl_tls_model (decl
, kind
);
2103 /* Handle a "no_instrument_function" attribute; arguments as in
2104 struct attribute_spec.handler. */
2107 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2108 tree
ARG_UNUSED (args
),
2109 int ARG_UNUSED (flags
),
2114 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2116 error_at (DECL_SOURCE_LOCATION (decl
),
2117 "%qE attribute applies only to functions", name
);
2118 *no_add_attrs
= true;
2121 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2126 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2127 struct attribute_spec.handler. */
2130 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
2131 int, bool *no_add_attrs
)
2133 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2135 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2136 *no_add_attrs
= true;
2142 /* Handle a "malloc" attribute; arguments as in
2143 struct attribute_spec.handler. */
2146 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2147 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2149 if (TREE_CODE (*node
) == FUNCTION_DECL
2150 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
2151 DECL_IS_MALLOC (*node
) = 1;
2154 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2155 *no_add_attrs
= true;
2161 /* Handle a "alloc_size" attribute; arguments as in
2162 struct attribute_spec.handler. */
2165 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2166 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2168 unsigned arg_count
= type_num_arguments (*node
);
2169 for (; args
; args
= TREE_CHAIN (args
))
2171 tree position
= TREE_VALUE (args
);
2172 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2173 && TREE_CODE (position
) != FUNCTION_DECL
)
2174 position
= default_conversion (position
);
2176 if (!tree_fits_uhwi_p (position
)
2178 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2180 warning (OPT_Wattributes
,
2181 "alloc_size parameter outside range");
2182 *no_add_attrs
= true;
2189 /* Handle a "alloc_align" attribute; arguments as in
2190 struct attribute_spec.handler. */
2193 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
2196 unsigned arg_count
= type_num_arguments (*node
);
2197 tree position
= TREE_VALUE (args
);
2198 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2199 && TREE_CODE (position
) != FUNCTION_DECL
)
2200 position
= default_conversion (position
);
2202 if (!tree_fits_uhwi_p (position
)
2204 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2206 warning (OPT_Wattributes
,
2207 "alloc_align parameter outside range");
2208 *no_add_attrs
= true;
2214 /* Handle a "assume_aligned" attribute; arguments as in
2215 struct attribute_spec.handler. */
2218 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
2221 for (; args
; args
= TREE_CHAIN (args
))
2223 tree position
= TREE_VALUE (args
);
2224 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2225 && TREE_CODE (position
) != FUNCTION_DECL
)
2226 position
= default_conversion (position
);
2228 if (TREE_CODE (position
) != INTEGER_CST
)
2230 warning (OPT_Wattributes
,
2231 "assume_aligned parameter not integer constant");
2232 *no_add_attrs
= true;
2239 /* Handle a "fn spec" attribute; arguments as in
2240 struct attribute_spec.handler. */
2243 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
2244 tree args
, int ARG_UNUSED (flags
),
2245 bool *no_add_attrs ATTRIBUTE_UNUSED
)
2248 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2249 && !TREE_CHAIN (args
));
2253 /* Handle a "bnd_variable_size" attribute; arguments as in
2254 struct attribute_spec.handler. */
2257 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2258 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2260 if (TREE_CODE (*node
) != FIELD_DECL
)
2262 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2263 *no_add_attrs
= true;
2269 /* Handle a "bnd_legacy" attribute; arguments as in
2270 struct attribute_spec.handler. */
2273 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2274 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2276 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2278 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2279 *no_add_attrs
= true;
2285 /* Handle a "bnd_instrument" attribute; arguments as in
2286 struct attribute_spec.handler. */
2289 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2290 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2292 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2294 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2295 *no_add_attrs
= true;
2301 /* Handle a "warn_unused" attribute; arguments as in
2302 struct attribute_spec.handler. */
2305 handle_warn_unused_attribute (tree
*node
, tree name
,
2306 tree args ATTRIBUTE_UNUSED
,
2307 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2310 /* Do nothing else, just set the attribute. We'll get at
2311 it later with lookup_attribute. */
2315 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2316 *no_add_attrs
= true;
2322 /* Handle an "omp declare simd" attribute; arguments as in
2323 struct attribute_spec.handler. */
2326 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2331 /* Handle a "simd" attribute. */
2334 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
2336 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2338 if (lookup_attribute ("cilk simd function",
2339 DECL_ATTRIBUTES (*node
)) != NULL
)
2341 error_at (DECL_SOURCE_LOCATION (*node
),
2342 "%<__simd__%> attribute cannot be used in the same "
2343 "function marked as a Cilk Plus SIMD-enabled function");
2344 *no_add_attrs
= true;
2348 tree t
= get_identifier ("omp declare simd");
2349 tree attr
= NULL_TREE
;
2352 tree id
= TREE_VALUE (args
);
2354 if (TREE_CODE (id
) != STRING_CST
)
2356 error ("attribute %qE argument not a string", name
);
2357 *no_add_attrs
= true;
2361 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
2362 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2363 OMP_CLAUSE_NOTINBRANCH
);
2365 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
2366 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2367 OMP_CLAUSE_INBRANCH
);
2370 error ("only %<inbranch%> and %<notinbranch%> flags are "
2371 "allowed for %<__simd__%> attribute");
2372 *no_add_attrs
= true;
2377 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
2378 build_tree_list (NULL_TREE
,
2380 DECL_ATTRIBUTES (*node
));
2385 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2386 *no_add_attrs
= true;
2392 /* Handle an "omp declare target" attribute; arguments as in
2393 struct attribute_spec.handler. */
2396 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2401 /* Handle a "returns_twice" attribute; arguments as in
2402 struct attribute_spec.handler. */
2405 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2406 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2408 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2409 DECL_IS_RETURNS_TWICE (*node
) = 1;
2412 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2413 *no_add_attrs
= true;
2419 /* Handle a "no_limit_stack" attribute; arguments as in
2420 struct attribute_spec.handler. */
2423 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2424 tree
ARG_UNUSED (args
),
2425 int ARG_UNUSED (flags
),
2430 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2432 error_at (DECL_SOURCE_LOCATION (decl
),
2433 "%qE attribute applies only to functions", name
);
2434 *no_add_attrs
= true;
2436 else if (DECL_INITIAL (decl
))
2438 error_at (DECL_SOURCE_LOCATION (decl
),
2439 "can%'t set %qE attribute after definition", name
);
2440 *no_add_attrs
= true;
2443 DECL_NO_LIMIT_STACK (decl
) = 1;
2448 /* Handle a "pure" attribute; arguments as in
2449 struct attribute_spec.handler. */
2452 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2453 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2455 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2456 DECL_PURE_P (*node
) = 1;
2457 /* ??? TODO: Support types. */
2460 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2461 *no_add_attrs
= true;
2467 /* Digest an attribute list destined for a transactional memory statement.
2468 ALLOWED is the set of attributes that are allowed for this statement;
2469 return the attribute we parsed. Multiple attributes are never allowed. */
2472 parse_tm_stmt_attr (tree attrs
, int allowed
)
2477 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2479 tree a
= TREE_PURPOSE (attrs
);
2482 if (is_attribute_p ("outer", a
))
2483 m
= TM_STMT_ATTR_OUTER
;
2485 if ((m
& allowed
) == 0)
2487 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
2496 else if (m_seen
== m
)
2497 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2499 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
2505 /* Transform a TM attribute name into a maskable integer and back.
2506 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2507 to how the lack of an attribute is treated. */
2510 tm_attr_to_mask (tree attr
)
2514 if (is_attribute_p ("transaction_safe", attr
))
2515 return TM_ATTR_SAFE
;
2516 if (is_attribute_p ("transaction_callable", attr
))
2517 return TM_ATTR_CALLABLE
;
2518 if (is_attribute_p ("transaction_pure", attr
))
2519 return TM_ATTR_PURE
;
2520 if (is_attribute_p ("transaction_unsafe", attr
))
2521 return TM_ATTR_IRREVOCABLE
;
2522 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
2523 return TM_ATTR_MAY_CANCEL_OUTER
;
2528 tm_mask_to_attr (int mask
)
2534 str
= "transaction_safe";
2536 case TM_ATTR_CALLABLE
:
2537 str
= "transaction_callable";
2540 str
= "transaction_pure";
2542 case TM_ATTR_IRREVOCABLE
:
2543 str
= "transaction_unsafe";
2545 case TM_ATTR_MAY_CANCEL_OUTER
:
2546 str
= "transaction_may_cancel_outer";
2551 return get_identifier (str
);
2554 /* Return the first TM attribute seen in LIST. */
2557 find_tm_attribute (tree list
)
2559 for (; list
; list
= TREE_CHAIN (list
))
2561 tree name
= TREE_PURPOSE (list
);
2562 if (tm_attr_to_mask (name
) != 0)
2568 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2569 Here we accept only function types, and verify that none of the other
2570 function TM attributes are also applied. */
2571 /* ??? We need to accept class types for C++, but not C. This greatly
2572 complicates this function, since we can no longer rely on the extra
2573 processing given by function_type_required. */
2576 handle_tm_attribute (tree
*node
, tree name
, tree args
,
2577 int flags
, bool *no_add_attrs
)
2579 /* Only one path adds the attribute; others don't. */
2580 *no_add_attrs
= true;
2582 switch (TREE_CODE (*node
))
2586 /* Only tm_callable and tm_safe apply to classes. */
2587 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
2594 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
2595 if (old_name
== name
)
2597 else if (old_name
!= NULL_TREE
)
2598 error ("type was previously declared %qE", old_name
);
2600 *no_add_attrs
= false;
2606 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2607 want to set transaction_safe on the type. */
2608 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
2609 if (!TYPE_P (DECL_CONTEXT (*node
)))
2610 error_at (DECL_SOURCE_LOCATION (*node
),
2611 "%<transaction_safe_dynamic%> may only be specified for "
2612 "a virtual function");
2613 *no_add_attrs
= false;
2614 decl_attributes (&TREE_TYPE (*node
),
2615 build_tree_list (get_identifier ("transaction_safe"),
2623 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
2624 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
2626 tree fn_tmp
= TREE_TYPE (*node
);
2627 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
2628 *node
= build_pointer_type (fn_tmp
);
2635 /* If a function is next, pass it on to be tried next. */
2636 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
2637 return tree_cons (name
, args
, NULL
);
2640 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2647 /* Handle the TM_WRAP attribute; arguments as in
2648 struct attribute_spec.handler. */
2651 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2652 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2656 /* We don't need the attribute even on success, since we
2657 record the entry in an external table. */
2658 *no_add_attrs
= true;
2660 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2661 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2664 tree wrap_decl
= TREE_VALUE (args
);
2665 if (error_operand_p (wrap_decl
))
2667 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
2668 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
2669 error ("%qE argument not an identifier", name
);
2672 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
2673 wrap_decl
= lookup_name (wrap_decl
);
2674 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
2676 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
2677 TREE_TYPE (wrap_decl
)))
2678 record_tm_replacement (wrap_decl
, decl
);
2680 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2683 error ("%qE argument is not a function", name
);
2690 /* Ignore the given attribute. Used when this attribute may be usefully
2691 overridden by the target, but is not used generically. */
2694 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2695 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2698 *no_add_attrs
= true;
2702 /* Handle a "no vops" attribute; arguments as in
2703 struct attribute_spec.handler. */
2706 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2707 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2708 bool *ARG_UNUSED (no_add_attrs
))
2710 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
2711 DECL_IS_NOVOPS (*node
) = 1;
2715 /* Handle a "deprecated" attribute; arguments as in
2716 struct attribute_spec.handler. */
2719 handle_deprecated_attribute (tree
*node
, tree name
,
2720 tree args
, int flags
,
2723 tree type
= NULL_TREE
;
2725 tree what
= NULL_TREE
;
2728 *no_add_attrs
= true;
2729 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
2731 error ("deprecated message is not a string");
2732 *no_add_attrs
= true;
2738 type
= TREE_TYPE (decl
);
2740 if (TREE_CODE (decl
) == TYPE_DECL
2741 || TREE_CODE (decl
) == PARM_DECL
2742 || VAR_OR_FUNCTION_DECL_P (decl
)
2743 || TREE_CODE (decl
) == FIELD_DECL
2744 || TREE_CODE (decl
) == CONST_DECL
2745 || objc_method_decl (TREE_CODE (decl
)))
2746 TREE_DEPRECATED (decl
) = 1;
2750 else if (TYPE_P (*node
))
2752 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2753 *node
= build_variant_type_copy (*node
);
2754 TREE_DEPRECATED (*node
) = 1;
2762 *no_add_attrs
= true;
2763 if (type
&& TYPE_NAME (type
))
2765 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
2766 what
= TYPE_NAME (*node
);
2767 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
2768 && DECL_NAME (TYPE_NAME (type
)))
2769 what
= DECL_NAME (TYPE_NAME (type
));
2772 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
2774 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2780 /* Handle a "vector_size" attribute; arguments as in
2781 struct attribute_spec.handler. */
2784 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
2785 int ARG_UNUSED (flags
),
2788 unsigned HOST_WIDE_INT vecsize
, nunits
;
2789 machine_mode orig_mode
;
2790 tree type
= *node
, new_type
, size
;
2792 *no_add_attrs
= true;
2794 size
= TREE_VALUE (args
);
2795 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
2796 && TREE_CODE (size
) != FUNCTION_DECL
)
2797 size
= default_conversion (size
);
2799 if (!tree_fits_uhwi_p (size
))
2801 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2805 /* Get the vector size (in bytes). */
2806 vecsize
= tree_to_uhwi (size
);
2808 /* We need to provide for vector pointers, vector arrays, and
2809 functions returning vectors. For example:
2811 __attribute__((vector_size(16))) short *foo;
2813 In this case, the mode is SI, but the type being modified is
2814 HI, so we need to look further. */
2816 while (POINTER_TYPE_P (type
)
2817 || TREE_CODE (type
) == FUNCTION_TYPE
2818 || TREE_CODE (type
) == METHOD_TYPE
2819 || TREE_CODE (type
) == ARRAY_TYPE
2820 || TREE_CODE (type
) == OFFSET_TYPE
)
2821 type
= TREE_TYPE (type
);
2823 /* Get the mode of the type being modified. */
2824 orig_mode
= TYPE_MODE (type
);
2826 if ((!INTEGRAL_TYPE_P (type
)
2827 && !SCALAR_FLOAT_TYPE_P (type
)
2828 && !FIXED_POINT_TYPE_P (type
))
2829 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
2830 && GET_MODE_CLASS (orig_mode
) != MODE_INT
2831 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
2832 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
2833 || TREE_CODE (type
) == BOOLEAN_TYPE
)
2835 error ("invalid vector type for attribute %qE", name
);
2839 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
2841 error ("vector size not an integral multiple of component size");
2847 error ("zero vector size");
2851 /* Calculate how many units fit in the vector. */
2852 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
2853 if (nunits
& (nunits
- 1))
2855 error ("number of components of the vector not a power of two");
2859 new_type
= build_vector_type (type
, nunits
);
2861 /* Build back pointers if needed. */
2862 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
2867 /* Handle the "nonnull" attribute. */
2870 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2871 tree args
, int ARG_UNUSED (flags
),
2875 unsigned HOST_WIDE_INT attr_arg_num
;
2877 /* If no arguments are specified, all pointer arguments should be
2878 non-null. Verify a full prototype is given so that the arguments
2879 will have the correct types when we actually check them later.
2880 Avoid diagnosing type-generic built-ins since those have no
2884 if (!prototype_p (type
)
2885 && (!TYPE_ATTRIBUTES (type
)
2886 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
2888 error ("nonnull attribute without arguments on a non-prototype");
2889 *no_add_attrs
= true;
2894 /* Argument list specified. Verify that each argument number references
2895 a pointer argument. */
2896 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
2898 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
2900 tree arg
= TREE_VALUE (args
);
2901 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
2902 && TREE_CODE (arg
) != FUNCTION_DECL
)
2903 TREE_VALUE (args
) = arg
= default_conversion (arg
);
2905 if (!get_nonnull_operand (arg
, &arg_num
))
2907 error ("nonnull argument has invalid operand number (argument %lu)",
2908 (unsigned long) attr_arg_num
);
2909 *no_add_attrs
= true;
2913 if (prototype_p (type
))
2915 function_args_iterator iter
;
2918 function_args_iter_init (&iter
, type
);
2919 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
2921 argument
= function_args_iter_cond (&iter
);
2922 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
2927 || TREE_CODE (argument
) == VOID_TYPE
)
2929 error ("nonnull argument with out-of-range operand number "
2930 "(argument %lu, operand %lu)",
2931 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
2932 *no_add_attrs
= true;
2936 if (TREE_CODE (argument
) != POINTER_TYPE
)
2938 error ("nonnull argument references non-pointer operand "
2939 "(argument %lu, operand %lu)",
2940 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
2941 *no_add_attrs
= true;
2950 /* Handle a "nothrow" attribute; arguments as in
2951 struct attribute_spec.handler. */
2954 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2955 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2957 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2958 TREE_NOTHROW (*node
) = 1;
2959 /* ??? TODO: Support types. */
2962 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2963 *no_add_attrs
= true;
2969 /* Handle a "cleanup" attribute; arguments as in
2970 struct attribute_spec.handler. */
2973 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
2974 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2977 tree cleanup_id
, cleanup_decl
;
2979 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
2980 for global destructors in C++. This requires infrastructure that
2981 we don't have generically at the moment. It's also not a feature
2982 we'd be missing too much, since we do have attribute constructor. */
2983 if (!VAR_P (decl
) || TREE_STATIC (decl
))
2985 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2986 *no_add_attrs
= true;
2990 /* Verify that the argument is a function in scope. */
2991 /* ??? We could support pointers to functions here as well, if
2992 that was considered desirable. */
2993 cleanup_id
= TREE_VALUE (args
);
2994 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
2996 error ("cleanup argument not an identifier");
2997 *no_add_attrs
= true;
3000 cleanup_decl
= lookup_name (cleanup_id
);
3001 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
3003 error ("cleanup argument not a function");
3004 *no_add_attrs
= true;
3008 /* That the function has proper type is checked with the
3009 eventual call to build_function_call. */
3014 /* Handle a "warn_unused_result" attribute. No special handling. */
3017 handle_warn_unused_result_attribute (tree
*node
, tree name
,
3018 tree
ARG_UNUSED (args
),
3019 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3021 /* Ignore the attribute for functions not returning any value. */
3022 if (VOID_TYPE_P (TREE_TYPE (*node
)))
3024 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3025 *no_add_attrs
= true;
3031 /* Handle a "sentinel" attribute. */
3034 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
3035 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3037 if (!prototype_p (*node
))
3039 warning (OPT_Wattributes
,
3040 "%qE attribute requires prototypes with named arguments", name
);
3041 *no_add_attrs
= true;
3045 if (!stdarg_p (*node
))
3047 warning (OPT_Wattributes
,
3048 "%qE attribute only applies to variadic functions", name
);
3049 *no_add_attrs
= true;
3055 tree position
= TREE_VALUE (args
);
3056 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
3057 && TREE_CODE (position
) != FUNCTION_DECL
)
3058 position
= default_conversion (position
);
3060 if (TREE_CODE (position
) != INTEGER_CST
3061 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
3063 warning (OPT_Wattributes
,
3064 "requested position is not an integer constant");
3065 *no_add_attrs
= true;
3069 if (tree_int_cst_lt (position
, integer_zero_node
))
3071 warning (OPT_Wattributes
,
3072 "requested position is less than zero");
3073 *no_add_attrs
= true;
3081 /* Handle a "type_generic" attribute. */
3084 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3085 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
3086 bool * ARG_UNUSED (no_add_attrs
))
3088 /* Ensure we have a function type. */
3089 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
3091 /* Ensure we have a variadic function. */
3092 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
3097 /* Handle a "target" attribute. */
3100 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3103 /* Ensure we have a function type. */
3104 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3106 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3107 *no_add_attrs
= true;
3109 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3111 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3112 "with %qs attribute", name
, "target_clones");
3113 *no_add_attrs
= true;
3115 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3117 *no_add_attrs
= true;
3122 /* Handle a "target_clones" attribute. */
3125 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3126 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3128 /* Ensure we have a function type. */
3129 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3131 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3133 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3134 "with %qs attribute", name
, "always_inline");
3135 *no_add_attrs
= true;
3137 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3139 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3140 "with %qs attribute", name
, "target");
3141 *no_add_attrs
= true;
3144 /* Do not inline functions with multiple clone targets. */
3145 DECL_UNINLINABLE (*node
) = 1;
3149 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3150 *no_add_attrs
= true;
3155 /* For handling "optimize" attribute. arguments as in
3156 struct attribute_spec.handler. */
3159 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3160 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3162 /* Ensure we have a function type. */
3163 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3165 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3166 *no_add_attrs
= true;
3170 struct cl_optimization cur_opts
;
3171 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3173 /* Save current options. */
3174 cl_optimization_save (&cur_opts
, &global_options
);
3176 /* If we previously had some optimization options, use them as the
3179 cl_optimization_restore (&global_options
,
3180 TREE_OPTIMIZATION (old_opts
));
3182 /* Parse options, and update the vector. */
3183 parse_optimize_options (args
, true);
3184 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3185 = build_optimization_node (&global_options
);
3187 /* Restore current options. */
3188 cl_optimization_restore (&global_options
, &cur_opts
);
3194 /* Handle a "no_split_stack" attribute. */
3197 handle_no_split_stack_attribute (tree
*node
, tree name
,
3198 tree
ARG_UNUSED (args
),
3199 int ARG_UNUSED (flags
),
3204 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3206 error_at (DECL_SOURCE_LOCATION (decl
),
3207 "%qE attribute applies only to functions", name
);
3208 *no_add_attrs
= true;
3210 else if (DECL_INITIAL (decl
))
3212 error_at (DECL_SOURCE_LOCATION (decl
),
3213 "can%'t set %qE attribute after definition", name
);
3214 *no_add_attrs
= true;
3220 /* Handle a "returns_nonnull" attribute; arguments as in
3221 struct attribute_spec.handler. */
3224 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3227 // Even without a prototype we still have a return type we can check.
3228 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3230 error ("returns_nonnull attribute on a function not returning a pointer");
3231 *no_add_attrs
= true;
3236 /* Handle a "designated_init" attribute; arguments as in
3237 struct attribute_spec.handler. */
3240 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3243 if (TREE_CODE (*node
) != RECORD_TYPE
)
3245 error ("%qE attribute is only valid on %<struct%> type", name
);
3246 *no_add_attrs
= true;
3252 /* Handle a "fallthrough" attribute; arguments as in struct
3253 attribute_spec.handler. */
3256 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3259 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3260 *no_add_attrs
= true;