1 /* C-family attributes handling.
2 Copyright (C) 1992-2016 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_address_attribute (tree
*, tree
, tree
,
56 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
58 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
60 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
61 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
62 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
63 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
64 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
65 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
67 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
68 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
69 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
70 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
71 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
72 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
74 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
76 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
77 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
79 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
81 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
82 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
83 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
84 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
85 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
86 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
87 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
88 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
89 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
90 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
91 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
92 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
94 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
96 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
98 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
100 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
101 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
102 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
104 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
105 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
106 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
107 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
108 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
110 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
112 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
113 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
114 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
115 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
117 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
118 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
119 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
120 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
121 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
122 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
123 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
124 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
125 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
126 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
127 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
128 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
129 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
130 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
132 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
133 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
135 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
136 static tree
handle_bnd_variable_size_attribute (tree
*, tree
, tree
, int, bool *);
137 static tree
handle_bnd_legacy (tree
*, tree
, tree
, int, bool *);
138 static tree
handle_bnd_instrument (tree
*, tree
, tree
, int, bool *);
139 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
141 /* Table of machine-independent attributes common to all C-like languages.
143 All attributes referencing arguments should be additionally processed
144 in chkp_copy_function_type_adding_bounds for correct instrumentation
145 by Pointer Bounds Checker.
146 Current list of processed common attributes: nonnull. */
147 const struct attribute_spec c_common_attribute_table
[] =
149 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
150 affects_type_identity } */
151 { "packed", 0, 0, false, false, false,
152 handle_packed_attribute
, false},
153 { "nocommon", 0, 0, true, false, false,
154 handle_nocommon_attribute
, false},
155 { "common", 0, 0, true, false, false,
156 handle_common_attribute
, false },
157 /* FIXME: logically, noreturn attributes should be listed as
158 "false, true, true" and apply to function types. But implementing this
159 would require all the places in the compiler that use TREE_THIS_VOLATILE
160 on a decl to identify non-returning functions to be located and fixed
161 to check the function type instead. */
162 { "noreturn", 0, 0, true, false, false,
163 handle_noreturn_attribute
, false },
164 { "volatile", 0, 0, true, false, false,
165 handle_noreturn_attribute
, false },
166 { "stack_protect", 0, 0, true, false, false,
167 handle_stack_protect_attribute
, false },
168 { "noinline", 0, 0, true, false, false,
169 handle_noinline_attribute
, false },
170 { "noclone", 0, 0, true, false, false,
171 handle_noclone_attribute
, false },
172 { "no_icf", 0, 0, true, false, false,
173 handle_noicf_attribute
, false },
174 { "leaf", 0, 0, true, false, false,
175 handle_leaf_attribute
, false },
176 { "always_inline", 0, 0, true, false, false,
177 handle_always_inline_attribute
, false },
178 { "gnu_inline", 0, 0, true, false, false,
179 handle_gnu_inline_attribute
, false },
180 { "artificial", 0, 0, true, false, false,
181 handle_artificial_attribute
, false },
182 { "flatten", 0, 0, true, false, false,
183 handle_flatten_attribute
, false },
184 { "used", 0, 0, true, false, false,
185 handle_used_attribute
, false },
186 { "unused", 0, 0, false, false, false,
187 handle_unused_attribute
, false },
188 { "externally_visible", 0, 0, true, false, false,
189 handle_externally_visible_attribute
, false },
190 { "no_reorder", 0, 0, true, false, false,
191 handle_no_reorder_attribute
, false },
192 /* The same comments as for noreturn attributes apply to const ones. */
193 { "const", 0, 0, true, false, false,
194 handle_const_attribute
, false },
195 { "scalar_storage_order", 1, 1, false, false, false,
196 handle_scalar_storage_order_attribute
, false },
197 { "transparent_union", 0, 0, false, false, false,
198 handle_transparent_union_attribute
, false },
199 { "constructor", 0, 1, true, false, false,
200 handle_constructor_attribute
, false },
201 { "destructor", 0, 1, true, false, false,
202 handle_destructor_attribute
, false },
203 { "mode", 1, 1, false, true, false,
204 handle_mode_attribute
, false },
205 { "section", 1, 1, true, false, false,
206 handle_section_attribute
, false },
207 { "aligned", 0, 1, false, false, false,
208 handle_aligned_attribute
, false },
209 { "weak", 0, 0, true, false, false,
210 handle_weak_attribute
, false },
211 { "noplt", 0, 0, true, false, false,
212 handle_noplt_attribute
, false },
213 { "ifunc", 1, 1, true, false, false,
214 handle_ifunc_attribute
, false },
215 { "alias", 1, 1, true, false, false,
216 handle_alias_attribute
, false },
217 { "weakref", 0, 1, true, false, false,
218 handle_weakref_attribute
, false },
219 { "no_instrument_function", 0, 0, true, false, false,
220 handle_no_instrument_function_attribute
,
222 { "no_profile_instrument_function", 0, 0, true, false, false,
223 handle_no_profile_instrument_function_attribute
,
225 { "malloc", 0, 0, true, false, false,
226 handle_malloc_attribute
, false },
227 { "returns_twice", 0, 0, true, false, false,
228 handle_returns_twice_attribute
, false },
229 { "no_stack_limit", 0, 0, true, false, false,
230 handle_no_limit_stack_attribute
, false },
231 { "pure", 0, 0, true, false, false,
232 handle_pure_attribute
, false },
233 { "transaction_callable", 0, 0, false, true, false,
234 handle_tm_attribute
, false },
235 { "transaction_unsafe", 0, 0, false, true, false,
236 handle_tm_attribute
, true },
237 { "transaction_safe", 0, 0, false, true, false,
238 handle_tm_attribute
, true },
239 { "transaction_safe_dynamic", 0, 0, true, false, false,
240 handle_tm_attribute
, false },
241 { "transaction_may_cancel_outer", 0, 0, false, true, false,
242 handle_tm_attribute
, false },
243 /* ??? These two attributes didn't make the transition from the
244 Intel language document to the multi-vendor language document. */
245 { "transaction_pure", 0, 0, false, true, false,
246 handle_tm_attribute
, false },
247 { "transaction_wrap", 1, 1, true, false, false,
248 handle_tm_wrap_attribute
, false },
249 /* For internal use (marking of builtins) only. The name contains space
250 to prevent its usage in source code. */
251 { "no vops", 0, 0, true, false, false,
252 handle_novops_attribute
, false },
253 { "deprecated", 0, 1, false, false, false,
254 handle_deprecated_attribute
, false },
255 { "vector_size", 1, 1, false, true, false,
256 handle_vector_size_attribute
, true },
257 { "visibility", 1, 1, false, false, false,
258 handle_visibility_attribute
, false },
259 { "tls_model", 1, 1, true, false, false,
260 handle_tls_model_attribute
, false },
261 { "nonnull", 0, -1, false, true, true,
262 handle_nonnull_attribute
, false },
263 { "nothrow", 0, 0, true, false, false,
264 handle_nothrow_attribute
, false },
265 { "may_alias", 0, 0, false, true, false, NULL
, false },
266 { "cleanup", 1, 1, true, false, false,
267 handle_cleanup_attribute
, false },
268 { "warn_unused_result", 0, 0, false, true, true,
269 handle_warn_unused_result_attribute
, false },
270 { "sentinel", 0, 1, false, true, true,
271 handle_sentinel_attribute
, false },
272 /* For internal use (marking of builtins) only. The name contains space
273 to prevent its usage in source code. */
274 { "type generic", 0, 0, false, true, true,
275 handle_type_generic_attribute
, false },
276 { "alloc_size", 1, 2, false, true, true,
277 handle_alloc_size_attribute
, false },
278 { "cold", 0, 0, true, false, false,
279 handle_cold_attribute
, false },
280 { "hot", 0, 0, true, false, false,
281 handle_hot_attribute
, false },
282 { "no_address_safety_analysis",
283 0, 0, true, false, false,
284 handle_no_address_safety_analysis_attribute
,
286 { "no_sanitize_address", 0, 0, true, false, false,
287 handle_no_sanitize_address_attribute
,
289 { "no_sanitize_thread", 0, 0, true, false, false,
290 handle_no_sanitize_address_attribute
,
292 { "no_sanitize_undefined", 0, 0, true, false, false,
293 handle_no_sanitize_undefined_attribute
,
295 { "warning", 1, 1, true, false, false,
296 handle_error_attribute
, false },
297 { "error", 1, 1, true, false, false,
298 handle_error_attribute
, false },
299 { "target", 1, -1, true, false, false,
300 handle_target_attribute
, false },
301 { "target_clones", 1, -1, true, false, false,
302 handle_target_clones_attribute
, false },
303 { "optimize", 1, -1, true, false, false,
304 handle_optimize_attribute
, false },
305 /* For internal use only. The leading '*' both prevents its usage in
306 source code and signals that it may be overridden by machine tables. */
307 { "*tm regparm", 0, 0, false, true, true,
308 ignore_attribute
, false },
309 { "no_split_stack", 0, 0, true, false, false,
310 handle_no_split_stack_attribute
, false },
311 /* For internal use (marking of builtins and runtime functions) only.
312 The name contains space to prevent its usage in source code. */
313 { "fn spec", 1, 1, false, true, true,
314 handle_fnspec_attribute
, false },
315 { "warn_unused", 0, 0, false, false, false,
316 handle_warn_unused_attribute
, false },
317 { "returns_nonnull", 0, 0, false, true, true,
318 handle_returns_nonnull_attribute
, false },
319 { "omp declare simd", 0, -1, true, false, false,
320 handle_omp_declare_simd_attribute
, false },
321 { "cilk simd function", 0, -1, true, false, false,
322 handle_omp_declare_simd_attribute
, false },
323 { "simd", 0, 1, true, false, false,
324 handle_simd_attribute
, false },
325 { "omp declare target", 0, 0, true, false, false,
326 handle_omp_declare_target_attribute
, false },
327 { "omp declare target link", 0, 0, true, false, false,
328 handle_omp_declare_target_attribute
, false },
329 { "alloc_align", 1, 1, false, true, true,
330 handle_alloc_align_attribute
, false },
331 { "assume_aligned", 1, 2, false, true, true,
332 handle_assume_aligned_attribute
, false },
333 { "designated_init", 0, 0, false, true, false,
334 handle_designated_init_attribute
, false },
335 { "bnd_variable_size", 0, 0, true, false, false,
336 handle_bnd_variable_size_attribute
, false },
337 { "bnd_legacy", 0, 0, true, false, false,
338 handle_bnd_legacy
, false },
339 { "bnd_instrument", 0, 0, true, false, false,
340 handle_bnd_instrument
, false },
341 { "fallthrough", 0, 0, false, false, false,
342 handle_fallthrough_attribute
, false },
343 { NULL
, 0, 0, false, false, false, NULL
, false }
346 /* Give the specifications for the format attributes, used by C and all
349 All attributes referencing arguments should be additionally processed
350 in chkp_copy_function_type_adding_bounds for correct instrumentation
351 by Pointer Bounds Checker.
352 Current list of processed format attributes: format, format_arg. */
353 const struct attribute_spec c_common_format_attribute_table
[] =
355 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
356 affects_type_identity } */
357 { "format", 3, 3, false, true, true,
358 handle_format_attribute
, false },
359 { "format_arg", 1, 1, false, true, true,
360 handle_format_arg_attribute
, false },
361 { NULL
, 0, 0, false, false, false, NULL
, false }
364 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
365 identifier as an argument, so the front end shouldn't look it up. */
368 attribute_takes_identifier_p (const_tree attr_id
)
370 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
372 /* Unknown attribute that we'll end up ignoring, return true so we
373 don't complain about an identifier argument. */
375 else if (!strcmp ("mode", spec
->name
)
376 || !strcmp ("format", spec
->name
)
377 || !strcmp ("cleanup", spec
->name
))
380 return targetm
.attribute_takes_identifier_p (attr_id
);
383 /* Attribute handlers common to C front ends. */
385 /* Handle a "packed" attribute; arguments as in
386 struct attribute_spec.handler. */
389 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
390 int flags
, bool *no_add_attrs
)
394 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
395 *node
= build_variant_type_copy (*node
);
396 TYPE_PACKED (*node
) = 1;
398 else if (TREE_CODE (*node
) == FIELD_DECL
)
400 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
401 /* Still pack bitfields. */
402 && ! DECL_INITIAL (*node
))
403 warning (OPT_Wattributes
,
404 "%qE attribute ignored for field of type %qT",
405 name
, TREE_TYPE (*node
));
407 DECL_PACKED (*node
) = 1;
409 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
410 used for DECL_REGISTER. It wouldn't mean anything anyway.
411 We can't set DECL_PACKED on the type of a TYPE_DECL, because
412 that changes what the typedef is typing. */
415 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
416 *no_add_attrs
= true;
422 /* Handle a "nocommon" attribute; arguments as in
423 struct attribute_spec.handler. */
426 handle_nocommon_attribute (tree
*node
, tree name
,
427 tree
ARG_UNUSED (args
),
428 int ARG_UNUSED (flags
), bool *no_add_attrs
)
431 DECL_COMMON (*node
) = 0;
434 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
435 *no_add_attrs
= true;
441 /* Handle a "common" attribute; arguments as in
442 struct attribute_spec.handler. */
445 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
446 int ARG_UNUSED (flags
), bool *no_add_attrs
)
449 DECL_COMMON (*node
) = 1;
452 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
453 *no_add_attrs
= true;
459 /* Handle a "noreturn" attribute; arguments as in
460 struct attribute_spec.handler. */
463 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
464 int ARG_UNUSED (flags
), bool *no_add_attrs
)
466 tree type
= TREE_TYPE (*node
);
468 /* See FIXME comment in c_common_attribute_table. */
469 if (TREE_CODE (*node
) == FUNCTION_DECL
470 || objc_method_decl (TREE_CODE (*node
)))
471 TREE_THIS_VOLATILE (*node
) = 1;
472 else if (TREE_CODE (type
) == POINTER_TYPE
473 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
475 = (build_qualified_type
477 (build_type_variant (TREE_TYPE (type
),
478 TYPE_READONLY (TREE_TYPE (type
)), 1)),
482 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
483 *no_add_attrs
= true;
489 /* Handle a "hot" and attribute; arguments as in
490 struct attribute_spec.handler. */
493 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
494 int ARG_UNUSED (flags
), bool *no_add_attrs
)
496 if (TREE_CODE (*node
) == FUNCTION_DECL
497 || TREE_CODE (*node
) == LABEL_DECL
)
499 if (lookup_attribute ("cold", DECL_ATTRIBUTES (*node
)) != NULL
)
501 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
502 "with attribute %qs", name
, "cold");
503 *no_add_attrs
= true;
505 /* Most of the rest of the hot processing is done later with
510 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
511 *no_add_attrs
= true;
517 /* Handle a "cold" and attribute; arguments as in
518 struct attribute_spec.handler. */
521 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
522 int ARG_UNUSED (flags
), bool *no_add_attrs
)
524 if (TREE_CODE (*node
) == FUNCTION_DECL
525 || TREE_CODE (*node
) == LABEL_DECL
)
527 if (lookup_attribute ("hot", DECL_ATTRIBUTES (*node
)) != NULL
)
529 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
530 "with attribute %qs", name
, "hot");
531 *no_add_attrs
= true;
533 /* Most of the rest of the cold processing is done later with
538 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
539 *no_add_attrs
= true;
545 /* Handle a "no_sanitize_address" attribute; arguments as in
546 struct attribute_spec.handler. */
549 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
552 if (TREE_CODE (*node
) != FUNCTION_DECL
)
554 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
555 *no_add_attrs
= true;
561 /* Handle a "no_address_safety_analysis" attribute; arguments as in
562 struct attribute_spec.handler. */
565 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
568 if (TREE_CODE (*node
) != FUNCTION_DECL
)
569 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
570 else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node
)))
571 DECL_ATTRIBUTES (*node
)
572 = tree_cons (get_identifier ("no_sanitize_address"),
573 NULL_TREE
, DECL_ATTRIBUTES (*node
));
574 *no_add_attrs
= true;
578 /* Handle a "no_sanitize_undefined" attribute; arguments as in
579 struct attribute_spec.handler. */
582 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
585 if (TREE_CODE (*node
) != FUNCTION_DECL
)
587 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
588 *no_add_attrs
= true;
594 /* Handle a "stack_protect" attribute; arguments as in
595 struct attribute_spec.handler. */
598 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
601 if (TREE_CODE (*node
) != FUNCTION_DECL
)
603 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
604 *no_add_attrs
= true;
607 DECL_ATTRIBUTES (*node
)
608 = tree_cons (get_identifier ("stack_protect"),
609 NULL_TREE
, DECL_ATTRIBUTES (*node
));
614 /* Handle a "noinline" attribute; arguments as in
615 struct attribute_spec.handler. */
618 handle_noinline_attribute (tree
*node
, tree name
,
619 tree
ARG_UNUSED (args
),
620 int ARG_UNUSED (flags
), bool *no_add_attrs
)
622 if (TREE_CODE (*node
) == FUNCTION_DECL
)
624 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
626 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
627 "with attribute %qs", name
, "always_inline");
628 *no_add_attrs
= true;
631 DECL_UNINLINABLE (*node
) = 1;
635 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
636 *no_add_attrs
= true;
642 /* Handle a "noclone" attribute; arguments as in
643 struct attribute_spec.handler. */
646 handle_noclone_attribute (tree
*node
, tree name
,
647 tree
ARG_UNUSED (args
),
648 int ARG_UNUSED (flags
), bool *no_add_attrs
)
650 if (TREE_CODE (*node
) != FUNCTION_DECL
)
652 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
653 *no_add_attrs
= true;
659 /* Handle a "no_icf" attribute; arguments as in
660 struct attribute_spec.handler. */
663 handle_noicf_attribute (tree
*node
, tree name
,
664 tree
ARG_UNUSED (args
),
665 int ARG_UNUSED (flags
), bool *no_add_attrs
)
667 if (TREE_CODE (*node
) != FUNCTION_DECL
)
669 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
670 *no_add_attrs
= true;
677 /* Handle a "always_inline" attribute; arguments as in
678 struct attribute_spec.handler. */
681 handle_always_inline_attribute (tree
*node
, tree name
,
682 tree
ARG_UNUSED (args
),
683 int ARG_UNUSED (flags
),
686 if (TREE_CODE (*node
) == FUNCTION_DECL
)
688 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
690 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
691 "with %qs attribute", name
, "noinline");
692 *no_add_attrs
= true;
694 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
696 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
697 "with %qs attribute", name
, "target_clones");
698 *no_add_attrs
= true;
701 /* Set the attribute and mark it for disregarding inline
703 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
707 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
708 *no_add_attrs
= true;
714 /* Handle a "gnu_inline" attribute; arguments as in
715 struct attribute_spec.handler. */
718 handle_gnu_inline_attribute (tree
*node
, tree name
,
719 tree
ARG_UNUSED (args
),
720 int ARG_UNUSED (flags
),
723 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
725 /* Do nothing else, just set the attribute. We'll get at
726 it later with lookup_attribute. */
730 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
731 *no_add_attrs
= true;
737 /* Handle a "leaf" attribute; arguments as in
738 struct attribute_spec.handler. */
741 handle_leaf_attribute (tree
*node
, tree name
,
742 tree
ARG_UNUSED (args
),
743 int ARG_UNUSED (flags
), bool *no_add_attrs
)
745 if (TREE_CODE (*node
) != FUNCTION_DECL
)
747 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
748 *no_add_attrs
= true;
750 if (!TREE_PUBLIC (*node
))
752 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
754 *no_add_attrs
= true;
760 /* Handle an "artificial" attribute; arguments as in
761 struct attribute_spec.handler. */
764 handle_artificial_attribute (tree
*node
, tree name
,
765 tree
ARG_UNUSED (args
),
766 int ARG_UNUSED (flags
),
769 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
771 /* Do nothing else, just set the attribute. We'll get at
772 it later with lookup_attribute. */
776 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
777 *no_add_attrs
= true;
783 /* Handle a "flatten" attribute; arguments as in
784 struct attribute_spec.handler. */
787 handle_flatten_attribute (tree
*node
, tree name
,
788 tree args ATTRIBUTE_UNUSED
,
789 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
791 if (TREE_CODE (*node
) == FUNCTION_DECL
)
792 /* Do nothing else, just set the attribute. We'll get at
793 it later with lookup_attribute. */
797 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
798 *no_add_attrs
= true;
804 /* Handle a "warning" or "error" attribute; arguments as in
805 struct attribute_spec.handler. */
808 handle_error_attribute (tree
*node
, tree name
, tree args
,
809 int ARG_UNUSED (flags
), bool *no_add_attrs
)
811 if (TREE_CODE (*node
) == FUNCTION_DECL
812 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
813 /* Do nothing else, just set the attribute. We'll get at
814 it later with lookup_attribute. */
818 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
819 *no_add_attrs
= true;
825 /* Handle a "used" attribute; arguments as in
826 struct attribute_spec.handler. */
829 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
830 int ARG_UNUSED (flags
), bool *no_add_attrs
)
834 if (TREE_CODE (node
) == FUNCTION_DECL
835 || (VAR_P (node
) && TREE_STATIC (node
))
836 || (TREE_CODE (node
) == TYPE_DECL
))
838 TREE_USED (node
) = 1;
839 DECL_PRESERVE_P (node
) = 1;
841 DECL_READ_P (node
) = 1;
845 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
846 *no_add_attrs
= true;
852 /* Handle a "unused" attribute; arguments as in
853 struct attribute_spec.handler. */
856 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
857 int flags
, bool *no_add_attrs
)
863 if (TREE_CODE (decl
) == PARM_DECL
864 || VAR_OR_FUNCTION_DECL_P (decl
)
865 || TREE_CODE (decl
) == LABEL_DECL
866 || TREE_CODE (decl
) == CONST_DECL
867 || TREE_CODE (decl
) == TYPE_DECL
)
869 TREE_USED (decl
) = 1;
870 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
871 DECL_READ_P (decl
) = 1;
875 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
876 *no_add_attrs
= true;
881 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
882 *node
= build_variant_type_copy (*node
);
883 TREE_USED (*node
) = 1;
889 /* Handle a "externally_visible" attribute; arguments as in
890 struct attribute_spec.handler. */
893 handle_externally_visible_attribute (tree
*pnode
, tree name
,
894 tree
ARG_UNUSED (args
),
895 int ARG_UNUSED (flags
),
900 if (VAR_OR_FUNCTION_DECL_P (node
))
902 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
903 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
905 warning (OPT_Wattributes
,
906 "%qE attribute have effect only on public objects", name
);
907 *no_add_attrs
= true;
912 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
913 *no_add_attrs
= true;
919 /* Handle the "no_reorder" attribute. Arguments as in
920 struct attribute_spec.handler. */
923 handle_no_reorder_attribute (tree
*pnode
,
931 if (!VAR_OR_FUNCTION_DECL_P (node
)
932 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
934 warning (OPT_Wattributes
,
935 "%qE attribute only affects top level objects",
937 *no_add_attrs
= true;
943 /* Handle a "const" attribute; arguments as in
944 struct attribute_spec.handler. */
947 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
948 int ARG_UNUSED (flags
), bool *no_add_attrs
)
950 tree type
= TREE_TYPE (*node
);
952 /* See FIXME comment on noreturn in c_common_attribute_table. */
953 if (TREE_CODE (*node
) == FUNCTION_DECL
)
954 TREE_READONLY (*node
) = 1;
955 else if (TREE_CODE (type
) == POINTER_TYPE
956 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
958 = (build_qualified_type
960 (build_type_variant (TREE_TYPE (type
), 1,
961 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
965 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
966 *no_add_attrs
= true;
972 /* Handle a "scalar_storage_order" attribute; arguments as in
973 struct attribute_spec.handler. */
976 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
977 int flags
, bool *no_add_attrs
)
979 tree id
= TREE_VALUE (args
);
982 if (TREE_CODE (*node
) == TYPE_DECL
983 && ! (flags
& ATTR_FLAG_CXX11
))
984 node
= &TREE_TYPE (*node
);
987 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
989 error ("scalar_storage_order is not supported because endianness "
994 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
996 bool reverse
= false;
998 if (TREE_CODE (id
) == STRING_CST
999 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1000 reverse
= !BYTES_BIG_ENDIAN
;
1001 else if (TREE_CODE (id
) == STRING_CST
1002 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1003 reverse
= BYTES_BIG_ENDIAN
;
1006 error ("scalar_storage_order argument must be one of \"big-endian\""
1007 " or \"little-endian\"");
1011 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1014 /* A type variant isn't good enough, since we don't want a cast
1015 to such a type to be removed as a no-op. */
1016 *node
= type
= build_duplicate_type (type
);
1019 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1023 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1024 *no_add_attrs
= true;
1028 /* Handle a "transparent_union" attribute; arguments as in
1029 struct attribute_spec.handler. */
1032 handle_transparent_union_attribute (tree
*node
, tree name
,
1033 tree
ARG_UNUSED (args
), int flags
,
1038 *no_add_attrs
= true;
1040 if (TREE_CODE (*node
) == TYPE_DECL
1041 && ! (flags
& ATTR_FLAG_CXX11
))
1042 node
= &TREE_TYPE (*node
);
1045 if (TREE_CODE (type
) == UNION_TYPE
)
1047 /* Make sure that the first field will work for a transparent union.
1048 If the type isn't complete yet, leave the check to the code in
1050 if (TYPE_SIZE (type
))
1052 tree first
= first_field (type
);
1053 if (first
== NULL_TREE
1054 || DECL_ARTIFICIAL (first
)
1055 || TYPE_MODE (type
) != DECL_MODE (first
))
1059 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1061 /* If the type isn't complete yet, setting the flag
1062 on a variant wouldn't ever be checked. */
1063 if (!TYPE_SIZE (type
))
1066 /* build_duplicate_type doesn't work for C++. */
1067 if (c_dialect_cxx ())
1070 /* A type variant isn't good enough, since we don't want a cast
1071 to such a type to be removed as a no-op. */
1072 *node
= type
= build_duplicate_type (type
);
1075 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1076 TYPE_TRANSPARENT_AGGR (t
) = 1;
1081 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1085 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1086 get the requested priority for a constructor or destructor,
1087 possibly issuing diagnostics for invalid or reserved
1090 static priority_type
1091 get_priority (tree args
, bool is_destructor
)
1097 return DEFAULT_INIT_PRIORITY
;
1099 if (!SUPPORTS_INIT_PRIORITY
)
1102 error ("destructor priorities are not supported");
1104 error ("constructor priorities are not supported");
1105 return DEFAULT_INIT_PRIORITY
;
1108 arg
= TREE_VALUE (args
);
1109 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1111 if (arg
== error_mark_node
)
1112 return DEFAULT_INIT_PRIORITY
;
1113 arg
= default_conversion (arg
);
1114 if (!tree_fits_shwi_p (arg
)
1115 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1118 pri
= tree_to_shwi (arg
);
1119 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1122 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1126 "destructor priorities from 0 to %d are reserved "
1127 "for the implementation",
1128 MAX_RESERVED_INIT_PRIORITY
);
1131 "constructor priorities from 0 to %d are reserved "
1132 "for the implementation",
1133 MAX_RESERVED_INIT_PRIORITY
);
1139 error ("destructor priorities must be integers from 0 to %d inclusive",
1142 error ("constructor priorities must be integers from 0 to %d inclusive",
1144 return DEFAULT_INIT_PRIORITY
;
1147 /* Handle a "constructor" attribute; arguments as in
1148 struct attribute_spec.handler. */
1151 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1152 int ARG_UNUSED (flags
),
1156 tree type
= TREE_TYPE (decl
);
1158 if (TREE_CODE (decl
) == FUNCTION_DECL
1159 && TREE_CODE (type
) == FUNCTION_TYPE
1160 && decl_function_context (decl
) == 0)
1162 priority_type priority
;
1163 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1164 priority
= get_priority (args
, /*is_destructor=*/false);
1165 SET_DECL_INIT_PRIORITY (decl
, priority
);
1166 TREE_USED (decl
) = 1;
1170 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1171 *no_add_attrs
= true;
1177 /* Handle a "destructor" attribute; arguments as in
1178 struct attribute_spec.handler. */
1181 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1182 int ARG_UNUSED (flags
),
1186 tree type
= TREE_TYPE (decl
);
1188 if (TREE_CODE (decl
) == FUNCTION_DECL
1189 && TREE_CODE (type
) == FUNCTION_TYPE
1190 && decl_function_context (decl
) == 0)
1192 priority_type priority
;
1193 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1194 priority
= get_priority (args
, /*is_destructor=*/true);
1195 SET_DECL_FINI_PRIORITY (decl
, priority
);
1196 TREE_USED (decl
) = 1;
1200 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1201 *no_add_attrs
= true;
1207 /* Nonzero if the mode is a valid vector mode for this architecture.
1208 This returns nonzero even if there is no hardware support for the
1209 vector mode, but we can emulate with narrower modes. */
1212 vector_mode_valid_p (machine_mode mode
)
1214 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1215 machine_mode innermode
;
1217 /* Doh! What's going on? */
1218 if (mclass
!= MODE_VECTOR_INT
1219 && mclass
!= MODE_VECTOR_FLOAT
1220 && mclass
!= MODE_VECTOR_FRACT
1221 && mclass
!= MODE_VECTOR_UFRACT
1222 && mclass
!= MODE_VECTOR_ACCUM
1223 && mclass
!= MODE_VECTOR_UACCUM
)
1226 /* Hardware support. Woo hoo! */
1227 if (targetm
.vector_mode_supported_p (mode
))
1230 innermode
= GET_MODE_INNER (mode
);
1232 /* We should probably return 1 if requesting V4DI and we have no DI,
1233 but we have V2DI, but this is probably very unlikely. */
1235 /* If we have support for the inner mode, we can safely emulate it.
1236 We may not have V2DI, but me can emulate with a pair of DIs. */
1237 return targetm
.scalar_mode_supported_p (innermode
);
1241 /* Handle a "mode" attribute; arguments as in
1242 struct attribute_spec.handler. */
1245 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1246 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1249 tree ident
= TREE_VALUE (args
);
1251 *no_add_attrs
= true;
1253 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1254 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1258 const char *p
= IDENTIFIER_POINTER (ident
);
1259 int len
= strlen (p
);
1260 machine_mode mode
= VOIDmode
;
1264 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1265 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1267 char *newp
= (char *) alloca (len
- 1);
1269 strcpy (newp
, &p
[2]);
1270 newp
[len
- 4] = '\0';
1274 /* Change this type to have a type with the specified mode.
1275 First check for the special modes. */
1276 if (!strcmp (p
, "byte"))
1278 else if (!strcmp (p
, "word"))
1280 else if (!strcmp (p
, "pointer"))
1282 else if (!strcmp (p
, "libgcc_cmp_return"))
1283 mode
= targetm
.libgcc_cmp_return_mode ();
1284 else if (!strcmp (p
, "libgcc_shift_count"))
1285 mode
= targetm
.libgcc_shift_count_mode ();
1286 else if (!strcmp (p
, "unwind_word"))
1287 mode
= targetm
.unwind_word_mode ();
1289 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1290 if (!strcmp (p
, GET_MODE_NAME (j
)))
1292 mode
= (machine_mode
) j
;
1296 if (mode
== VOIDmode
)
1298 error ("unknown machine mode %qE", ident
);
1303 switch (GET_MODE_CLASS (mode
))
1306 case MODE_PARTIAL_INT
:
1308 case MODE_DECIMAL_FLOAT
:
1313 valid_mode
= targetm
.scalar_mode_supported_p (mode
);
1316 case MODE_COMPLEX_INT
:
1317 case MODE_COMPLEX_FLOAT
:
1318 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1321 case MODE_VECTOR_INT
:
1322 case MODE_VECTOR_FLOAT
:
1323 case MODE_VECTOR_FRACT
:
1324 case MODE_VECTOR_UFRACT
:
1325 case MODE_VECTOR_ACCUM
:
1326 case MODE_VECTOR_UACCUM
:
1327 warning (OPT_Wattributes
, "specifying vector types with "
1328 "__attribute__ ((mode)) is deprecated");
1329 warning (OPT_Wattributes
,
1330 "use __attribute__ ((vector_size)) instead");
1331 valid_mode
= vector_mode_valid_p (mode
);
1339 error ("unable to emulate %qs", p
);
1343 if (POINTER_TYPE_P (type
))
1345 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1346 tree (*fn
)(tree
, machine_mode
, bool);
1348 if (!targetm
.addr_space
.valid_pointer_mode (mode
, as
))
1350 error ("invalid pointer mode %qs", p
);
1354 if (TREE_CODE (type
) == POINTER_TYPE
)
1355 fn
= build_pointer_type_for_mode
;
1357 fn
= build_reference_type_for_mode
;
1358 typefm
= fn (TREE_TYPE (type
), mode
, false);
1362 /* For fixed-point modes, we need to test if the signness of type
1363 and the machine mode are consistent. */
1364 if (ALL_FIXED_POINT_MODE_P (mode
)
1365 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1367 error ("signedness of type and machine mode %qs don%'t match", p
);
1370 /* For fixed-point modes, we need to pass saturating info. */
1371 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1372 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1373 : TYPE_UNSIGNED (type
));
1376 if (typefm
== NULL_TREE
)
1378 error ("no data type for mode %qs", p
);
1381 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1383 /* For enumeral types, copy the precision from the integer
1384 type returned above. If not an INTEGER_TYPE, we can't use
1385 this mode for this type. */
1386 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1388 error ("cannot use mode %qs for enumeral types", p
);
1392 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1394 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1399 /* We cannot build a type variant, as there's code that assumes
1400 that TYPE_MAIN_VARIANT has the same mode. This includes the
1401 debug generators. Instead, create a subrange type. This
1402 results in all of the enumeral values being emitted only once
1403 in the original, and the subtype gets them by reference. */
1404 if (TYPE_UNSIGNED (type
))
1405 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1407 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1408 TREE_TYPE (typefm
) = type
;
1411 else if (VECTOR_MODE_P (mode
)
1412 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1413 : TREE_CODE (type
) != TREE_CODE (typefm
))
1415 error ("mode %qs applied to inappropriate type", p
);
1425 /* Handle a "section" attribute; arguments as in
1426 struct attribute_spec.handler. */
1429 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1430 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1434 if (!targetm_common
.have_named_sections
)
1436 error_at (DECL_SOURCE_LOCATION (*node
),
1437 "section attributes are not supported for this target");
1441 user_defined_section_attribute
= true;
1443 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1445 error ("section attribute not allowed for %q+D", *node
);
1449 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1451 error ("section attribute argument not a string constant");
1456 && current_function_decl
!= NULL_TREE
1457 && !TREE_STATIC (decl
))
1459 error_at (DECL_SOURCE_LOCATION (decl
),
1460 "section attribute cannot be specified for local variables");
1464 /* The decl may have already been given a section attribute
1465 from a previous declaration. Ensure they match. */
1466 if (DECL_SECTION_NAME (decl
) != NULL
1467 && strcmp (DECL_SECTION_NAME (decl
),
1468 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1470 error ("section of %q+D conflicts with previous declaration", *node
);
1475 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1476 && DECL_THREAD_LOCAL_P (decl
))
1478 error ("section of %q+D cannot be overridden", *node
);
1482 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1486 *no_add_attrs
= true;
1490 /* If in c++-11, check if the c++-11 alignment constraint with respect
1491 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1492 c++-11 mode, does nothing.
1496 [* if the constant expression evaluates to a fundamental alignment,
1497 the alignment requirement of the declared entity shall be the
1498 specified fundamental alignment.
1500 * if the constant expression evaluates to an extended alignment
1501 and the implementation supports that alignment in the context
1502 of the declaration, the alignment of the declared entity shall
1505 * if the constant expression evaluates to an extended alignment
1506 and the implementation does not support that alignment in the
1507 context of the declaration, the program is ill-formed]. */
1510 check_cxx_fundamental_alignment_constraints (tree node
,
1514 bool alignment_too_large_p
= false;
1515 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1516 unsigned max_align
= 0;
1518 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1519 || (node
== NULL_TREE
|| node
== error_mark_node
))
1522 if (cxx_fundamental_alignment_p (requested_alignment
))
1527 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1528 /* For file scope variables and static members, the target supports
1529 alignments that are at most MAX_OFILE_ALIGNMENT. */
1530 max_align
= MAX_OFILE_ALIGNMENT
;
1532 /* For stack variables, the target supports at most
1533 MAX_STACK_ALIGNMENT. */
1534 max_align
= MAX_STACK_ALIGNMENT
;
1535 if (requested_alignment
> max_align
)
1536 alignment_too_large_p
= true;
1538 /* Let's be liberal for types and fields; don't limit their alignment any
1539 more than check_user_alignment already did. */
1541 if (alignment_too_large_p
)
1542 pedwarn (input_location
, OPT_Wattributes
,
1543 "requested alignment %d is larger than %d",
1544 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1546 return !alignment_too_large_p
;
1549 /* Handle a "aligned" attribute; arguments as in
1550 struct attribute_spec.handler. */
1553 handle_aligned_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1554 int flags
, bool *no_add_attrs
)
1556 tree decl
= NULL_TREE
;
1564 align_expr
= TREE_VALUE (args
);
1565 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1566 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1567 align_expr
= default_conversion (align_expr
);
1570 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1575 type
= &TREE_TYPE (decl
);
1576 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1578 else if (TYPE_P (*node
))
1579 type
= node
, is_type
= 1;
1581 if ((i
= check_user_alignment (align_expr
, true)) == -1
1582 || !check_cxx_fundamental_alignment_constraints (*node
, i
, flags
))
1583 *no_add_attrs
= true;
1586 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1587 /* OK, modify the type in place. */;
1588 /* If we have a TYPE_DECL, then copy the type, so that we
1589 don't accidentally modify a builtin type. See pushdecl. */
1590 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1591 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1593 tree tt
= TREE_TYPE (decl
);
1594 *type
= build_variant_type_copy (*type
);
1595 DECL_ORIGINAL_TYPE (decl
) = tt
;
1596 TYPE_NAME (*type
) = decl
;
1597 TREE_USED (*type
) = TREE_USED (decl
);
1598 TREE_TYPE (decl
) = *type
;
1601 *type
= build_variant_type_copy (*type
);
1603 SET_TYPE_ALIGN (*type
, (1U << i
) * BITS_PER_UNIT
);
1604 TYPE_USER_ALIGN (*type
) = 1;
1606 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1607 && TREE_CODE (decl
) != FIELD_DECL
)
1609 error ("alignment may not be specified for %q+D", decl
);
1610 *no_add_attrs
= true;
1612 else if (DECL_USER_ALIGN (decl
)
1613 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1614 /* C++-11 [dcl.align/4]:
1616 When multiple alignment-specifiers are specified for an
1617 entity, the alignment requirement shall be set to the
1618 strictest specified alignment.
1620 This formally comes from the c++11 specification but we are
1621 doing it for the GNU attribute syntax as well. */
1622 *no_add_attrs
= true;
1623 else if (TREE_CODE (decl
) == FUNCTION_DECL
1624 && DECL_ALIGN (decl
) > (1U << i
) * BITS_PER_UNIT
)
1626 if (DECL_USER_ALIGN (decl
))
1627 error ("alignment for %q+D was previously specified as %d "
1628 "and may not be decreased", decl
,
1629 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1631 error ("alignment for %q+D must be at least %d", decl
,
1632 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1633 *no_add_attrs
= true;
1637 SET_DECL_ALIGN (decl
, (1U << i
) * BITS_PER_UNIT
);
1638 DECL_USER_ALIGN (decl
) = 1;
1644 /* Handle a "weak" attribute; arguments as in
1645 struct attribute_spec.handler. */
1648 handle_weak_attribute (tree
*node
, tree name
,
1649 tree
ARG_UNUSED (args
),
1650 int ARG_UNUSED (flags
),
1651 bool * ARG_UNUSED (no_add_attrs
))
1653 if (TREE_CODE (*node
) == FUNCTION_DECL
1654 && DECL_DECLARED_INLINE_P (*node
))
1656 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1657 *no_add_attrs
= true;
1659 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1661 error ("indirect function %q+D cannot be declared weak", *node
);
1662 *no_add_attrs
= true;
1665 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1666 declare_weak (*node
);
1668 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1673 /* Handle a "noplt" attribute; arguments as in
1674 struct attribute_spec.handler. */
1677 handle_noplt_attribute (tree
*node
, tree name
,
1678 tree
ARG_UNUSED (args
),
1679 int ARG_UNUSED (flags
),
1680 bool * ARG_UNUSED (no_add_attrs
))
1682 if (TREE_CODE (*node
) != FUNCTION_DECL
)
1684 warning (OPT_Wattributes
,
1685 "%qE attribute is only applicable on functions", name
);
1686 *no_add_attrs
= true;
1692 /* Handle an "alias" or "ifunc" attribute; arguments as in
1693 struct attribute_spec.handler, except that IS_ALIAS tells us
1694 whether this is an alias as opposed to ifunc attribute. */
1697 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
1702 if (TREE_CODE (decl
) != FUNCTION_DECL
1703 && (!is_alias
|| !VAR_P (decl
)))
1705 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1706 *no_add_attrs
= true;
1708 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
1709 || (TREE_CODE (decl
) != FUNCTION_DECL
1710 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
1711 /* A static variable declaration is always a tentative definition,
1712 but the alias is a non-tentative definition which overrides. */
1713 || (TREE_CODE (decl
) != FUNCTION_DECL
1714 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
1716 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
1717 *no_add_attrs
= true;
1721 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
1722 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
1724 error ("weak %q+D cannot be defined %qE", decl
, name
);
1725 *no_add_attrs
= true;
1729 /* Note that the very first time we process a nested declaration,
1730 decl_function_context will not be set. Indeed, *would* never
1731 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
1732 we do below. After such frobbery, pushdecl would set the context.
1733 In any case, this is never what we want. */
1734 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
1738 id
= TREE_VALUE (args
);
1739 if (TREE_CODE (id
) != STRING_CST
)
1741 error ("attribute %qE argument not a string", name
);
1742 *no_add_attrs
= true;
1745 id
= get_identifier (TREE_STRING_POINTER (id
));
1746 /* This counts as a use of the object pointed to. */
1749 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1750 DECL_INITIAL (decl
) = error_mark_node
;
1752 TREE_STATIC (decl
) = 1;
1755 /* ifuncs are also aliases, so set that attribute too. */
1756 DECL_ATTRIBUTES (decl
)
1757 = tree_cons (get_identifier ("alias"), args
, DECL_ATTRIBUTES (decl
));
1761 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1762 *no_add_attrs
= true;
1765 if (decl_in_symtab_p (*node
))
1767 struct symtab_node
*n
= symtab_node::get (decl
);
1768 if (n
&& n
->refuse_visibility_changes
)
1771 error ("%+D declared alias after being used", decl
);
1773 error ("%+D declared ifunc after being used", decl
);
1781 /* Handle an "alias" or "ifunc" attribute; arguments as in
1782 struct attribute_spec.handler. */
1785 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
1786 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1788 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
1791 /* Handle an "alias" or "ifunc" attribute; arguments as in
1792 struct attribute_spec.handler. */
1795 handle_alias_attribute (tree
*node
, tree name
, tree args
,
1796 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1798 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
1801 /* Handle a "weakref" attribute; arguments as in struct
1802 attribute_spec.handler. */
1805 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1806 int flags
, bool *no_add_attrs
)
1808 tree attr
= NULL_TREE
;
1810 /* We must ignore the attribute when it is associated with
1811 local-scoped decls, since attribute alias is ignored and many
1812 such symbols do not even have a DECL_WEAK field. */
1813 if (decl_function_context (*node
)
1814 || current_function_decl
1815 || !VAR_OR_FUNCTION_DECL_P (*node
))
1817 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1818 *no_add_attrs
= true;
1822 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1824 error ("indirect function %q+D cannot be declared weakref", *node
);
1825 *no_add_attrs
= true;
1829 /* The idea here is that `weakref("name")' mutates into `weakref,
1830 alias("name")', and weakref without arguments, in turn,
1831 implicitly adds weak. */
1835 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
1836 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
1838 *no_add_attrs
= true;
1840 decl_attributes (node
, attr
, flags
);
1844 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
1845 error_at (DECL_SOURCE_LOCATION (*node
),
1846 "weakref attribute must appear before alias attribute");
1848 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
1849 and that isn't supported; and because it wants to add it to
1850 the list of weak decls, which isn't helpful. */
1851 DECL_WEAK (*node
) = 1;
1854 if (decl_in_symtab_p (*node
))
1856 struct symtab_node
*n
= symtab_node::get (*node
);
1857 if (n
&& n
->refuse_visibility_changes
)
1858 error ("%+D declared weakref after being used", *node
);
1864 /* Handle an "visibility" attribute; arguments as in
1865 struct attribute_spec.handler. */
1868 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
1869 int ARG_UNUSED (flags
),
1870 bool *ARG_UNUSED (no_add_attrs
))
1873 tree id
= TREE_VALUE (args
);
1874 enum symbol_visibility vis
;
1878 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
1880 else if (!RECORD_OR_UNION_TYPE_P (*node
))
1882 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
1886 else if (TYPE_FIELDS (*node
))
1888 error ("%qE attribute ignored because %qT is already defined",
1893 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
1895 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1899 if (TREE_CODE (id
) != STRING_CST
)
1901 error ("visibility argument not a string");
1905 /* If this is a type, set the visibility on the type decl. */
1908 decl
= TYPE_NAME (decl
);
1911 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
1913 warning (OPT_Wattributes
, "%qE attribute ignored on types",
1919 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
1920 vis
= VISIBILITY_DEFAULT
;
1921 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
1922 vis
= VISIBILITY_INTERNAL
;
1923 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
1924 vis
= VISIBILITY_HIDDEN
;
1925 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
1926 vis
= VISIBILITY_PROTECTED
;
1929 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
1930 vis
= VISIBILITY_DEFAULT
;
1933 if (DECL_VISIBILITY_SPECIFIED (decl
)
1934 && vis
!= DECL_VISIBILITY (decl
))
1936 tree attributes
= (TYPE_P (*node
)
1937 ? TYPE_ATTRIBUTES (*node
)
1938 : DECL_ATTRIBUTES (decl
));
1939 if (lookup_attribute ("visibility", attributes
))
1940 error ("%qD redeclared with different visibility", decl
);
1941 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1942 && lookup_attribute ("dllimport", attributes
))
1943 error ("%qD was declared %qs which implies default visibility",
1945 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
1946 && lookup_attribute ("dllexport", attributes
))
1947 error ("%qD was declared %qs which implies default visibility",
1951 DECL_VISIBILITY (decl
) = vis
;
1952 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
1954 /* Go ahead and attach the attribute to the node as well. This is needed
1955 so we can determine whether we have VISIBILITY_DEFAULT because the
1956 visibility was not specified, or because it was explicitly overridden
1957 from the containing scope. */
1962 /* Handle an "tls_model" attribute; arguments as in
1963 struct attribute_spec.handler. */
1966 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
1967 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1971 enum tls_model kind
;
1973 *no_add_attrs
= true;
1975 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
1977 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1981 kind
= DECL_TLS_MODEL (decl
);
1982 id
= TREE_VALUE (args
);
1983 if (TREE_CODE (id
) != STRING_CST
)
1985 error ("tls_model argument not a string");
1989 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
1990 kind
= TLS_MODEL_LOCAL_EXEC
;
1991 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
1992 kind
= TLS_MODEL_INITIAL_EXEC
;
1993 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
1994 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
1995 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
1996 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
1998 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2000 set_decl_tls_model (decl
, kind
);
2004 /* Handle a "no_instrument_function" attribute; arguments as in
2005 struct attribute_spec.handler. */
2008 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2009 tree
ARG_UNUSED (args
),
2010 int ARG_UNUSED (flags
),
2015 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2017 error_at (DECL_SOURCE_LOCATION (decl
),
2018 "%qE attribute applies only to functions", name
);
2019 *no_add_attrs
= true;
2022 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2027 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2028 struct attribute_spec.handler. */
2031 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
2032 int, bool *no_add_attrs
)
2034 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2036 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2037 *no_add_attrs
= true;
2043 /* Handle a "malloc" attribute; arguments as in
2044 struct attribute_spec.handler. */
2047 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2048 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2050 if (TREE_CODE (*node
) == FUNCTION_DECL
2051 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
2052 DECL_IS_MALLOC (*node
) = 1;
2055 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2056 *no_add_attrs
= true;
2062 /* Handle a "alloc_size" attribute; arguments as in
2063 struct attribute_spec.handler. */
2066 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2067 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2069 unsigned arg_count
= type_num_arguments (*node
);
2070 for (; args
; args
= TREE_CHAIN (args
))
2072 tree position
= TREE_VALUE (args
);
2073 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2074 && TREE_CODE (position
) != FUNCTION_DECL
)
2075 position
= default_conversion (position
);
2077 if (!tree_fits_uhwi_p (position
)
2079 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2081 warning (OPT_Wattributes
,
2082 "alloc_size parameter outside range");
2083 *no_add_attrs
= true;
2090 /* Handle a "alloc_align" attribute; arguments as in
2091 struct attribute_spec.handler. */
2094 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
2097 unsigned arg_count
= type_num_arguments (*node
);
2098 tree position
= TREE_VALUE (args
);
2099 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2100 && TREE_CODE (position
) != FUNCTION_DECL
)
2101 position
= default_conversion (position
);
2103 if (!tree_fits_uhwi_p (position
)
2105 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2107 warning (OPT_Wattributes
,
2108 "alloc_align parameter outside range");
2109 *no_add_attrs
= true;
2115 /* Handle a "assume_aligned" attribute; arguments as in
2116 struct attribute_spec.handler. */
2119 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
2122 for (; args
; args
= TREE_CHAIN (args
))
2124 tree position
= TREE_VALUE (args
);
2125 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2126 && TREE_CODE (position
) != FUNCTION_DECL
)
2127 position
= default_conversion (position
);
2129 if (TREE_CODE (position
) != INTEGER_CST
)
2131 warning (OPT_Wattributes
,
2132 "assume_aligned parameter not integer constant");
2133 *no_add_attrs
= true;
2140 /* Handle a "fn spec" attribute; arguments as in
2141 struct attribute_spec.handler. */
2144 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
2145 tree args
, int ARG_UNUSED (flags
),
2146 bool *no_add_attrs ATTRIBUTE_UNUSED
)
2149 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2150 && !TREE_CHAIN (args
));
2154 /* Handle a "bnd_variable_size" attribute; arguments as in
2155 struct attribute_spec.handler. */
2158 handle_bnd_variable_size_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2159 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2161 if (TREE_CODE (*node
) != FIELD_DECL
)
2163 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2164 *no_add_attrs
= true;
2170 /* Handle a "bnd_legacy" attribute; arguments as in
2171 struct attribute_spec.handler. */
2174 handle_bnd_legacy (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2175 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2177 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2179 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2180 *no_add_attrs
= true;
2186 /* Handle a "bnd_instrument" attribute; arguments as in
2187 struct attribute_spec.handler. */
2190 handle_bnd_instrument (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2191 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2193 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2195 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2196 *no_add_attrs
= true;
2202 /* Handle a "warn_unused" attribute; arguments as in
2203 struct attribute_spec.handler. */
2206 handle_warn_unused_attribute (tree
*node
, tree name
,
2207 tree args ATTRIBUTE_UNUSED
,
2208 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2211 /* Do nothing else, just set the attribute. We'll get at
2212 it later with lookup_attribute. */
2216 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2217 *no_add_attrs
= true;
2223 /* Handle an "omp declare simd" attribute; arguments as in
2224 struct attribute_spec.handler. */
2227 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2232 /* Handle a "simd" attribute. */
2235 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
2237 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2239 if (lookup_attribute ("cilk simd function",
2240 DECL_ATTRIBUTES (*node
)) != NULL
)
2242 error_at (DECL_SOURCE_LOCATION (*node
),
2243 "%<__simd__%> attribute cannot be used in the same "
2244 "function marked as a Cilk Plus SIMD-enabled function");
2245 *no_add_attrs
= true;
2249 tree t
= get_identifier ("omp declare simd");
2250 tree attr
= NULL_TREE
;
2253 tree id
= TREE_VALUE (args
);
2255 if (TREE_CODE (id
) != STRING_CST
)
2257 error ("attribute %qE argument not a string", name
);
2258 *no_add_attrs
= true;
2262 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
2263 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2264 OMP_CLAUSE_NOTINBRANCH
);
2266 if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
2267 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2268 OMP_CLAUSE_INBRANCH
);
2271 error ("only %<inbranch%> and %<notinbranch%> flags are "
2272 "allowed for %<__simd__%> attribute");
2273 *no_add_attrs
= true;
2278 DECL_ATTRIBUTES (*node
) = tree_cons (t
,
2279 build_tree_list (NULL_TREE
,
2281 DECL_ATTRIBUTES (*node
));
2286 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2287 *no_add_attrs
= true;
2293 /* Handle an "omp declare target" attribute; arguments as in
2294 struct attribute_spec.handler. */
2297 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2302 /* Handle a "returns_twice" attribute; arguments as in
2303 struct attribute_spec.handler. */
2306 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2307 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2309 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2310 DECL_IS_RETURNS_TWICE (*node
) = 1;
2313 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2314 *no_add_attrs
= true;
2320 /* Handle a "no_limit_stack" attribute; arguments as in
2321 struct attribute_spec.handler. */
2324 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2325 tree
ARG_UNUSED (args
),
2326 int ARG_UNUSED (flags
),
2331 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2333 error_at (DECL_SOURCE_LOCATION (decl
),
2334 "%qE attribute applies only to functions", name
);
2335 *no_add_attrs
= true;
2337 else if (DECL_INITIAL (decl
))
2339 error_at (DECL_SOURCE_LOCATION (decl
),
2340 "can%'t set %qE attribute after definition", name
);
2341 *no_add_attrs
= true;
2344 DECL_NO_LIMIT_STACK (decl
) = 1;
2349 /* Handle a "pure" attribute; arguments as in
2350 struct attribute_spec.handler. */
2353 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2354 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2356 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2357 DECL_PURE_P (*node
) = 1;
2358 /* ??? TODO: Support types. */
2361 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2362 *no_add_attrs
= true;
2368 /* Digest an attribute list destined for a transactional memory statement.
2369 ALLOWED is the set of attributes that are allowed for this statement;
2370 return the attribute we parsed. Multiple attributes are never allowed. */
2373 parse_tm_stmt_attr (tree attrs
, int allowed
)
2378 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2380 tree a
= TREE_PURPOSE (attrs
);
2383 if (is_attribute_p ("outer", a
))
2384 m
= TM_STMT_ATTR_OUTER
;
2386 if ((m
& allowed
) == 0)
2388 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
2397 else if (m_seen
== m
)
2398 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2400 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
2406 /* Transform a TM attribute name into a maskable integer and back.
2407 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2408 to how the lack of an attribute is treated. */
2411 tm_attr_to_mask (tree attr
)
2415 if (is_attribute_p ("transaction_safe", attr
))
2416 return TM_ATTR_SAFE
;
2417 if (is_attribute_p ("transaction_callable", attr
))
2418 return TM_ATTR_CALLABLE
;
2419 if (is_attribute_p ("transaction_pure", attr
))
2420 return TM_ATTR_PURE
;
2421 if (is_attribute_p ("transaction_unsafe", attr
))
2422 return TM_ATTR_IRREVOCABLE
;
2423 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
2424 return TM_ATTR_MAY_CANCEL_OUTER
;
2429 tm_mask_to_attr (int mask
)
2435 str
= "transaction_safe";
2437 case TM_ATTR_CALLABLE
:
2438 str
= "transaction_callable";
2441 str
= "transaction_pure";
2443 case TM_ATTR_IRREVOCABLE
:
2444 str
= "transaction_unsafe";
2446 case TM_ATTR_MAY_CANCEL_OUTER
:
2447 str
= "transaction_may_cancel_outer";
2452 return get_identifier (str
);
2455 /* Return the first TM attribute seen in LIST. */
2458 find_tm_attribute (tree list
)
2460 for (; list
; list
= TREE_CHAIN (list
))
2462 tree name
= TREE_PURPOSE (list
);
2463 if (tm_attr_to_mask (name
) != 0)
2469 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2470 Here we accept only function types, and verify that none of the other
2471 function TM attributes are also applied. */
2472 /* ??? We need to accept class types for C++, but not C. This greatly
2473 complicates this function, since we can no longer rely on the extra
2474 processing given by function_type_required. */
2477 handle_tm_attribute (tree
*node
, tree name
, tree args
,
2478 int flags
, bool *no_add_attrs
)
2480 /* Only one path adds the attribute; others don't. */
2481 *no_add_attrs
= true;
2483 switch (TREE_CODE (*node
))
2487 /* Only tm_callable and tm_safe apply to classes. */
2488 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
2495 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
2496 if (old_name
== name
)
2498 else if (old_name
!= NULL_TREE
)
2499 error ("type was previously declared %qE", old_name
);
2501 *no_add_attrs
= false;
2507 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2508 want to set transaction_safe on the type. */
2509 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
2510 if (!TYPE_P (DECL_CONTEXT (*node
)))
2511 error_at (DECL_SOURCE_LOCATION (*node
),
2512 "%<transaction_safe_dynamic%> may only be specified for "
2513 "a virtual function");
2514 *no_add_attrs
= false;
2515 decl_attributes (&TREE_TYPE (*node
),
2516 build_tree_list (get_identifier ("transaction_safe"),
2524 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
2525 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
2527 tree fn_tmp
= TREE_TYPE (*node
);
2528 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
2529 *node
= build_pointer_type (fn_tmp
);
2536 /* If a function is next, pass it on to be tried next. */
2537 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
2538 return tree_cons (name
, args
, NULL
);
2541 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2548 /* Handle the TM_WRAP attribute; arguments as in
2549 struct attribute_spec.handler. */
2552 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2553 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2557 /* We don't need the attribute even on success, since we
2558 record the entry in an external table. */
2559 *no_add_attrs
= true;
2561 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2562 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2565 tree wrap_decl
= TREE_VALUE (args
);
2566 if (error_operand_p (wrap_decl
))
2568 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
2569 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
2570 error ("%qE argument not an identifier", name
);
2573 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
2574 wrap_decl
= lookup_name (wrap_decl
);
2575 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
2577 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
2578 TREE_TYPE (wrap_decl
)))
2579 record_tm_replacement (wrap_decl
, decl
);
2581 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2584 error ("%qE argument is not a function", name
);
2591 /* Ignore the given attribute. Used when this attribute may be usefully
2592 overridden by the target, but is not used generically. */
2595 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2596 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2599 *no_add_attrs
= true;
2603 /* Handle a "no vops" attribute; arguments as in
2604 struct attribute_spec.handler. */
2607 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2608 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2609 bool *ARG_UNUSED (no_add_attrs
))
2611 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
2612 DECL_IS_NOVOPS (*node
) = 1;
2616 /* Handle a "deprecated" attribute; arguments as in
2617 struct attribute_spec.handler. */
2620 handle_deprecated_attribute (tree
*node
, tree name
,
2621 tree args
, int flags
,
2624 tree type
= NULL_TREE
;
2626 tree what
= NULL_TREE
;
2629 *no_add_attrs
= true;
2630 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
2632 error ("deprecated message is not a string");
2633 *no_add_attrs
= true;
2639 type
= TREE_TYPE (decl
);
2641 if (TREE_CODE (decl
) == TYPE_DECL
2642 || TREE_CODE (decl
) == PARM_DECL
2643 || VAR_OR_FUNCTION_DECL_P (decl
)
2644 || TREE_CODE (decl
) == FIELD_DECL
2645 || TREE_CODE (decl
) == CONST_DECL
2646 || objc_method_decl (TREE_CODE (decl
)))
2647 TREE_DEPRECATED (decl
) = 1;
2651 else if (TYPE_P (*node
))
2653 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2654 *node
= build_variant_type_copy (*node
);
2655 TREE_DEPRECATED (*node
) = 1;
2663 *no_add_attrs
= true;
2664 if (type
&& TYPE_NAME (type
))
2666 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
2667 what
= TYPE_NAME (*node
);
2668 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
2669 && DECL_NAME (TYPE_NAME (type
)))
2670 what
= DECL_NAME (TYPE_NAME (type
));
2673 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
2675 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2681 /* Handle a "vector_size" attribute; arguments as in
2682 struct attribute_spec.handler. */
2685 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
2686 int ARG_UNUSED (flags
),
2689 unsigned HOST_WIDE_INT vecsize
, nunits
;
2690 machine_mode orig_mode
;
2691 tree type
= *node
, new_type
, size
;
2693 *no_add_attrs
= true;
2695 size
= TREE_VALUE (args
);
2696 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
2697 && TREE_CODE (size
) != FUNCTION_DECL
)
2698 size
= default_conversion (size
);
2700 if (!tree_fits_uhwi_p (size
))
2702 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2706 /* Get the vector size (in bytes). */
2707 vecsize
= tree_to_uhwi (size
);
2709 /* We need to provide for vector pointers, vector arrays, and
2710 functions returning vectors. For example:
2712 __attribute__((vector_size(16))) short *foo;
2714 In this case, the mode is SI, but the type being modified is
2715 HI, so we need to look further. */
2717 while (POINTER_TYPE_P (type
)
2718 || TREE_CODE (type
) == FUNCTION_TYPE
2719 || TREE_CODE (type
) == METHOD_TYPE
2720 || TREE_CODE (type
) == ARRAY_TYPE
2721 || TREE_CODE (type
) == OFFSET_TYPE
)
2722 type
= TREE_TYPE (type
);
2724 /* Get the mode of the type being modified. */
2725 orig_mode
= TYPE_MODE (type
);
2727 if ((!INTEGRAL_TYPE_P (type
)
2728 && !SCALAR_FLOAT_TYPE_P (type
)
2729 && !FIXED_POINT_TYPE_P (type
))
2730 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
2731 && GET_MODE_CLASS (orig_mode
) != MODE_INT
2732 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
2733 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
2734 || TREE_CODE (type
) == BOOLEAN_TYPE
)
2736 error ("invalid vector type for attribute %qE", name
);
2740 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
2742 error ("vector size not an integral multiple of component size");
2748 error ("zero vector size");
2752 /* Calculate how many units fit in the vector. */
2753 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
2754 if (nunits
& (nunits
- 1))
2756 error ("number of components of the vector not a power of two");
2760 new_type
= build_vector_type (type
, nunits
);
2762 /* Build back pointers if needed. */
2763 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
2768 /* Handle the "nonnull" attribute. */
2771 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2772 tree args
, int ARG_UNUSED (flags
),
2776 unsigned HOST_WIDE_INT attr_arg_num
;
2778 /* If no arguments are specified, all pointer arguments should be
2779 non-null. Verify a full prototype is given so that the arguments
2780 will have the correct types when we actually check them later.
2781 Avoid diagnosing type-generic built-ins since those have no
2785 if (!prototype_p (type
)
2786 && (!TYPE_ATTRIBUTES (type
)
2787 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
2789 error ("nonnull attribute without arguments on a non-prototype");
2790 *no_add_attrs
= true;
2795 /* Argument list specified. Verify that each argument number references
2796 a pointer argument. */
2797 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
2799 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
2801 tree arg
= TREE_VALUE (args
);
2802 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
2803 && TREE_CODE (arg
) != FUNCTION_DECL
)
2804 arg
= default_conversion (arg
);
2806 if (!get_nonnull_operand (arg
, &arg_num
))
2808 error ("nonnull argument has invalid operand number (argument %lu)",
2809 (unsigned long) attr_arg_num
);
2810 *no_add_attrs
= true;
2814 if (prototype_p (type
))
2816 function_args_iterator iter
;
2819 function_args_iter_init (&iter
, type
);
2820 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
2822 argument
= function_args_iter_cond (&iter
);
2823 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
2828 || TREE_CODE (argument
) == VOID_TYPE
)
2830 error ("nonnull argument with out-of-range operand number "
2831 "(argument %lu, operand %lu)",
2832 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
2833 *no_add_attrs
= true;
2837 if (TREE_CODE (argument
) != POINTER_TYPE
)
2839 error ("nonnull argument references non-pointer operand "
2840 "(argument %lu, operand %lu)",
2841 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
2842 *no_add_attrs
= true;
2851 /* Handle a "nothrow" attribute; arguments as in
2852 struct attribute_spec.handler. */
2855 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2856 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2858 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2859 TREE_NOTHROW (*node
) = 1;
2860 /* ??? TODO: Support types. */
2863 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2864 *no_add_attrs
= true;
2870 /* Handle a "cleanup" attribute; arguments as in
2871 struct attribute_spec.handler. */
2874 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
2875 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2878 tree cleanup_id
, cleanup_decl
;
2880 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
2881 for global destructors in C++. This requires infrastructure that
2882 we don't have generically at the moment. It's also not a feature
2883 we'd be missing too much, since we do have attribute constructor. */
2884 if (!VAR_P (decl
) || TREE_STATIC (decl
))
2886 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2887 *no_add_attrs
= true;
2891 /* Verify that the argument is a function in scope. */
2892 /* ??? We could support pointers to functions here as well, if
2893 that was considered desirable. */
2894 cleanup_id
= TREE_VALUE (args
);
2895 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
2897 error ("cleanup argument not an identifier");
2898 *no_add_attrs
= true;
2901 cleanup_decl
= lookup_name (cleanup_id
);
2902 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
2904 error ("cleanup argument not a function");
2905 *no_add_attrs
= true;
2909 /* That the function has proper type is checked with the
2910 eventual call to build_function_call. */
2915 /* Handle a "warn_unused_result" attribute. No special handling. */
2918 handle_warn_unused_result_attribute (tree
*node
, tree name
,
2919 tree
ARG_UNUSED (args
),
2920 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2922 /* Ignore the attribute for functions not returning any value. */
2923 if (VOID_TYPE_P (TREE_TYPE (*node
)))
2925 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2926 *no_add_attrs
= true;
2932 /* Handle a "sentinel" attribute. */
2935 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
2936 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2938 if (!prototype_p (*node
))
2940 warning (OPT_Wattributes
,
2941 "%qE attribute requires prototypes with named arguments", name
);
2942 *no_add_attrs
= true;
2946 if (!stdarg_p (*node
))
2948 warning (OPT_Wattributes
,
2949 "%qE attribute only applies to variadic functions", name
);
2950 *no_add_attrs
= true;
2956 tree position
= TREE_VALUE (args
);
2957 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2958 && TREE_CODE (position
) != FUNCTION_DECL
)
2959 position
= default_conversion (position
);
2961 if (TREE_CODE (position
) != INTEGER_CST
2962 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
2964 warning (OPT_Wattributes
,
2965 "requested position is not an integer constant");
2966 *no_add_attrs
= true;
2970 if (tree_int_cst_lt (position
, integer_zero_node
))
2972 warning (OPT_Wattributes
,
2973 "requested position is less than zero");
2974 *no_add_attrs
= true;
2982 /* Handle a "type_generic" attribute. */
2985 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2986 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2987 bool * ARG_UNUSED (no_add_attrs
))
2989 /* Ensure we have a function type. */
2990 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
2992 /* Ensure we have a variadic function. */
2993 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
2998 /* Handle a "target" attribute. */
3001 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3004 /* Ensure we have a function type. */
3005 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3007 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3008 *no_add_attrs
= true;
3010 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3012 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3013 "with %qs attribute", name
, "target_clones");
3014 *no_add_attrs
= true;
3016 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3018 *no_add_attrs
= true;
3023 /* Handle a "target_clones" attribute. */
3026 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3027 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3029 /* Ensure we have a function type. */
3030 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3032 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3034 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3035 "with %qs attribute", name
, "always_inline");
3036 *no_add_attrs
= true;
3038 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3040 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3041 "with %qs attribute", name
, "target");
3042 *no_add_attrs
= true;
3045 /* Do not inline functions with multiple clone targets. */
3046 DECL_UNINLINABLE (*node
) = 1;
3050 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3051 *no_add_attrs
= true;
3056 /* For handling "optimize" attribute. arguments as in
3057 struct attribute_spec.handler. */
3060 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3061 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3063 /* Ensure we have a function type. */
3064 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3066 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3067 *no_add_attrs
= true;
3071 struct cl_optimization cur_opts
;
3072 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3074 /* Save current options. */
3075 cl_optimization_save (&cur_opts
, &global_options
);
3077 /* If we previously had some optimization options, use them as the
3080 cl_optimization_restore (&global_options
,
3081 TREE_OPTIMIZATION (old_opts
));
3083 /* Parse options, and update the vector. */
3084 parse_optimize_options (args
, true);
3085 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3086 = build_optimization_node (&global_options
);
3088 /* Restore current options. */
3089 cl_optimization_restore (&global_options
, &cur_opts
);
3095 /* Handle a "no_split_stack" attribute. */
3098 handle_no_split_stack_attribute (tree
*node
, tree name
,
3099 tree
ARG_UNUSED (args
),
3100 int ARG_UNUSED (flags
),
3105 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3107 error_at (DECL_SOURCE_LOCATION (decl
),
3108 "%qE attribute applies only to functions", name
);
3109 *no_add_attrs
= true;
3111 else if (DECL_INITIAL (decl
))
3113 error_at (DECL_SOURCE_LOCATION (decl
),
3114 "can%'t set %qE attribute after definition", name
);
3115 *no_add_attrs
= true;
3121 /* Handle a "returns_nonnull" attribute; arguments as in
3122 struct attribute_spec.handler. */
3125 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3128 // Even without a prototype we still have a return type we can check.
3129 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3131 error ("returns_nonnull attribute on a function not returning a pointer");
3132 *no_add_attrs
= true;
3137 /* Handle a "designated_init" attribute; arguments as in
3138 struct attribute_spec.handler. */
3141 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3144 if (TREE_CODE (*node
) != RECORD_TYPE
)
3146 error ("%qE attribute is only valid on %<struct%> type", name
);
3147 *no_add_attrs
= true;
3153 /* Handle a "fallthrough" attribute; arguments as in struct
3154 attribute_spec.handler. */
3157 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3160 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3161 *no_add_attrs
= true;