1 /* C-family attributes handling.
2 Copyright (C) 1992-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
28 #include "gimple-expr.h"
30 #include "stringpool.h"
32 #include "diagnostic.h"
34 #include "stor-layout.h"
38 #include "trans-mem.h"
40 #include "common/common-target.h"
41 #include "langhooks.h"
42 #include "tree-inline.h"
44 #include "tree-iterator.h"
48 static tree
handle_packed_attribute (tree
*, tree
, tree
, int, bool *);
49 static tree
handle_nocommon_attribute (tree
*, tree
, tree
, int, bool *);
50 static tree
handle_common_attribute (tree
*, tree
, tree
, int, bool *);
51 static tree
handle_noreturn_attribute (tree
*, tree
, tree
, int, bool *);
52 static tree
handle_hot_attribute (tree
*, tree
, tree
, int, bool *);
53 static tree
handle_cold_attribute (tree
*, tree
, tree
, int, bool *);
54 static tree
handle_no_sanitize_attribute (tree
*, tree
, tree
, int, bool *);
55 static tree
handle_no_sanitize_address_attribute (tree
*, tree
, tree
,
57 static tree
handle_no_sanitize_thread_attribute (tree
*, tree
, tree
,
59 static tree
handle_no_address_safety_analysis_attribute (tree
*, tree
, tree
,
61 static tree
handle_no_sanitize_undefined_attribute (tree
*, tree
, tree
, int,
63 static tree
handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int,
65 static tree
handle_stack_protect_attribute (tree
*, tree
, tree
, int, bool *);
66 static tree
handle_noinline_attribute (tree
*, tree
, tree
, int, bool *);
67 static tree
handle_noclone_attribute (tree
*, tree
, tree
, int, bool *);
68 static tree
handle_nocf_check_attribute (tree
*, tree
, tree
, int, bool *);
69 static tree
handle_noicf_attribute (tree
*, tree
, tree
, int, bool *);
70 static tree
handle_noipa_attribute (tree
*, tree
, tree
, int, bool *);
71 static tree
handle_leaf_attribute (tree
*, tree
, tree
, int, bool *);
72 static tree
handle_always_inline_attribute (tree
*, tree
, tree
, int,
74 static tree
handle_gnu_inline_attribute (tree
*, tree
, tree
, int, bool *);
75 static tree
handle_artificial_attribute (tree
*, tree
, tree
, int, bool *);
76 static tree
handle_flatten_attribute (tree
*, tree
, tree
, int, bool *);
77 static tree
handle_error_attribute (tree
*, tree
, tree
, int, bool *);
78 static tree
handle_used_attribute (tree
*, tree
, tree
, int, bool *);
79 static tree
handle_externally_visible_attribute (tree
*, tree
, tree
, int,
81 static tree
handle_no_reorder_attribute (tree
*, tree
, tree
, int,
83 static tree
handle_const_attribute (tree
*, tree
, tree
, int, bool *);
84 static tree
handle_transparent_union_attribute (tree
*, tree
, tree
,
86 static tree
handle_scalar_storage_order_attribute (tree
*, tree
, tree
,
88 static tree
handle_constructor_attribute (tree
*, tree
, tree
, int, bool *);
89 static tree
handle_destructor_attribute (tree
*, tree
, tree
, int, bool *);
90 static tree
handle_mode_attribute (tree
*, tree
, tree
, int, bool *);
91 static tree
handle_section_attribute (tree
*, tree
, tree
, int, bool *);
92 static tree
handle_aligned_attribute (tree
*, tree
, tree
, int, bool *);
93 static tree
handle_warn_if_not_aligned_attribute (tree
*, tree
, tree
,
95 static tree
handle_weak_attribute (tree
*, tree
, tree
, int, bool *) ;
96 static tree
handle_noplt_attribute (tree
*, tree
, tree
, int, bool *) ;
97 static tree
handle_alias_ifunc_attribute (bool, tree
*, tree
, tree
, bool *);
98 static tree
handle_ifunc_attribute (tree
*, tree
, tree
, int, bool *);
99 static tree
handle_alias_attribute (tree
*, tree
, tree
, int, bool *);
100 static tree
handle_weakref_attribute (tree
*, tree
, tree
, int, bool *) ;
101 static tree
handle_visibility_attribute (tree
*, tree
, tree
, int,
103 static tree
handle_tls_model_attribute (tree
*, tree
, tree
, int,
105 static tree
handle_no_instrument_function_attribute (tree
*, tree
,
107 static tree
handle_no_profile_instrument_function_attribute (tree
*, tree
,
109 static tree
handle_malloc_attribute (tree
*, tree
, tree
, int, bool *);
110 static tree
handle_returns_twice_attribute (tree
*, tree
, tree
, int, bool *);
111 static tree
handle_no_limit_stack_attribute (tree
*, tree
, tree
, int,
113 static tree
handle_pure_attribute (tree
*, tree
, tree
, int, bool *);
114 static tree
handle_tm_attribute (tree
*, tree
, tree
, int, bool *);
115 static tree
handle_tm_wrap_attribute (tree
*, tree
, tree
, int, bool *);
116 static tree
handle_novops_attribute (tree
*, tree
, tree
, int, bool *);
117 static tree
handle_deprecated_attribute (tree
*, tree
, tree
, int,
119 static tree
handle_vector_size_attribute (tree
*, tree
, tree
, int,
121 static tree
handle_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
122 static tree
handle_nonstring_attribute (tree
*, tree
, tree
, int, bool *);
123 static tree
handle_nothrow_attribute (tree
*, tree
, tree
, int, bool *);
124 static tree
handle_cleanup_attribute (tree
*, tree
, tree
, int, bool *);
125 static tree
handle_warn_unused_result_attribute (tree
*, tree
, tree
, int,
127 static tree
handle_sentinel_attribute (tree
*, tree
, tree
, int, bool *);
128 static tree
handle_type_generic_attribute (tree
*, tree
, tree
, int, bool *);
129 static tree
handle_alloc_size_attribute (tree
*, tree
, tree
, int, bool *);
130 static tree
handle_alloc_align_attribute (tree
*, tree
, tree
, int, bool *);
131 static tree
handle_assume_aligned_attribute (tree
*, tree
, tree
, int, bool *);
132 static tree
handle_target_attribute (tree
*, tree
, tree
, int, bool *);
133 static tree
handle_target_clones_attribute (tree
*, tree
, tree
, int, bool *);
134 static tree
handle_optimize_attribute (tree
*, tree
, tree
, int, bool *);
135 static tree
ignore_attribute (tree
*, tree
, tree
, int, bool *);
136 static tree
handle_no_split_stack_attribute (tree
*, tree
, tree
, int, bool *);
137 static tree
handle_fnspec_attribute (tree
*, tree
, tree
, int, bool *);
138 static tree
handle_warn_unused_attribute (tree
*, tree
, tree
, int, bool *);
139 static tree
handle_returns_nonnull_attribute (tree
*, tree
, tree
, int, bool *);
140 static tree
handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int,
142 static tree
handle_simd_attribute (tree
*, tree
, tree
, int, bool *);
143 static tree
handle_omp_declare_target_attribute (tree
*, tree
, tree
, int,
145 static tree
handle_designated_init_attribute (tree
*, tree
, tree
, int, bool *);
146 static tree
handle_fallthrough_attribute (tree
*, tree
, tree
, int, bool *);
147 static tree
handle_patchable_function_entry_attribute (tree
*, tree
, tree
,
150 /* Helper to define attribute exclusions. */
151 #define ATTR_EXCL(name, function, type, variable) \
152 { name, function, type, variable }
154 /* Define attributes that are mutually exclusive with one another. */
155 static const struct attribute_spec::exclusions attr_aligned_exclusions
[] =
157 /* Attribute name exclusion applies to:
158 function, type, variable */
159 ATTR_EXCL ("aligned", true, false, false),
160 ATTR_EXCL ("packed", true, false, false),
161 ATTR_EXCL (NULL
, false, false, false)
164 static const struct attribute_spec::exclusions attr_cold_hot_exclusions
[] =
166 ATTR_EXCL ("cold", true, true, true),
167 ATTR_EXCL ("hot", true, true, true),
168 ATTR_EXCL (NULL
, false, false, false)
171 static const struct attribute_spec::exclusions attr_common_exclusions
[] =
173 ATTR_EXCL ("common", true, true, true),
174 ATTR_EXCL ("nocommon", true, true, true),
175 ATTR_EXCL (NULL
, false, false, false),
178 static const struct attribute_spec::exclusions attr_inline_exclusions
[] =
180 ATTR_EXCL ("noinline", true, true, true),
181 ATTR_EXCL (NULL
, false, false, false),
184 static const struct attribute_spec::exclusions attr_noinline_exclusions
[] =
186 ATTR_EXCL ("always_inline", true, true, true),
187 ATTR_EXCL ("gnu_inline", true, true, true),
188 ATTR_EXCL (NULL
, false, false, false),
191 static const struct attribute_spec::exclusions attr_noreturn_exclusions
[] =
193 ATTR_EXCL ("alloc_align", true, true, true),
194 ATTR_EXCL ("alloc_size", true, true, true),
195 ATTR_EXCL ("const", true, true, true),
196 ATTR_EXCL ("malloc", true, true, true),
197 ATTR_EXCL ("pure", true, true, true),
198 ATTR_EXCL ("returns_twice", true, true, true),
199 ATTR_EXCL ("warn_unused_result", true, true, true),
200 ATTR_EXCL (NULL
, false, false, false),
203 static const struct attribute_spec::exclusions
204 attr_warn_unused_result_exclusions
[] =
206 ATTR_EXCL ("noreturn", true, true, true),
207 ATTR_EXCL ("warn_unused_result", true, true, true),
208 ATTR_EXCL (NULL
, false, false, false),
211 static const struct attribute_spec::exclusions attr_returns_twice_exclusions
[] =
213 ATTR_EXCL ("noreturn", true, true, true),
214 ATTR_EXCL (NULL
, false, false, false),
217 /* Exclusions that apply to attribute alloc_align, alloc_size, and malloc. */
218 static const struct attribute_spec::exclusions attr_alloc_exclusions
[] =
220 ATTR_EXCL ("const", true, true, true),
221 ATTR_EXCL ("noreturn", true, true, true),
222 ATTR_EXCL ("pure", true, true, true),
223 ATTR_EXCL (NULL
, false, false, false),
226 static const struct attribute_spec::exclusions attr_const_pure_exclusions
[] =
228 ATTR_EXCL ("const", true, true, true),
229 ATTR_EXCL ("alloc_align", true, true, true),
230 ATTR_EXCL ("alloc_size", true, true, true),
231 ATTR_EXCL ("malloc", true, true, true),
232 ATTR_EXCL ("noreturn", true, true, true),
233 ATTR_EXCL ("pure", true, true, true),
234 ATTR_EXCL (NULL
, false, false, false)
237 /* Table of machine-independent attributes common to all C-like languages.
239 Current list of processed common attributes: nonnull. */
240 const struct attribute_spec c_common_attribute_table
[] =
242 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
243 affects_type_identity, handler, exclude } */
244 { "packed", 0, 0, false, false, false, false,
245 handle_packed_attribute
,
246 attr_aligned_exclusions
},
247 { "nocommon", 0, 0, true, false, false, false,
248 handle_nocommon_attribute
,
249 attr_common_exclusions
},
250 { "common", 0, 0, true, false, false, false,
251 handle_common_attribute
,
252 attr_common_exclusions
},
253 /* FIXME: logically, noreturn attributes should be listed as
254 "false, true, true" and apply to function types. But implementing this
255 would require all the places in the compiler that use TREE_THIS_VOLATILE
256 on a decl to identify non-returning functions to be located and fixed
257 to check the function type instead. */
258 { "noreturn", 0, 0, true, false, false, false,
259 handle_noreturn_attribute
,
260 attr_noreturn_exclusions
},
261 { "volatile", 0, 0, true, false, false, false,
262 handle_noreturn_attribute
, NULL
},
263 { "stack_protect", 0, 0, true, false, false, false,
264 handle_stack_protect_attribute
, NULL
},
265 { "noinline", 0, 0, true, false, false, false,
266 handle_noinline_attribute
,
267 attr_noinline_exclusions
},
268 { "noclone", 0, 0, true, false, false, false,
269 handle_noclone_attribute
, NULL
},
270 { "no_icf", 0, 0, true, false, false, false,
271 handle_noicf_attribute
, NULL
},
272 { "noipa", 0, 0, true, false, false, false,
273 handle_noipa_attribute
, NULL
},
274 { "leaf", 0, 0, true, false, false, false,
275 handle_leaf_attribute
, NULL
},
276 { "always_inline", 0, 0, true, false, false, false,
277 handle_always_inline_attribute
,
278 attr_inline_exclusions
},
279 { "gnu_inline", 0, 0, true, false, false, false,
280 handle_gnu_inline_attribute
,
281 attr_inline_exclusions
},
282 { "artificial", 0, 0, true, false, false, false,
283 handle_artificial_attribute
, NULL
},
284 { "flatten", 0, 0, true, false, false, false,
285 handle_flatten_attribute
, NULL
},
286 { "used", 0, 0, true, false, false, false,
287 handle_used_attribute
, NULL
},
288 { "unused", 0, 0, false, false, false, false,
289 handle_unused_attribute
, NULL
},
290 { "externally_visible", 0, 0, true, false, false, false,
291 handle_externally_visible_attribute
, NULL
},
292 { "no_reorder", 0, 0, true, false, false, false,
293 handle_no_reorder_attribute
, NULL
},
294 /* The same comments as for noreturn attributes apply to const ones. */
295 { "const", 0, 0, true, false, false, false,
296 handle_const_attribute
,
297 attr_const_pure_exclusions
},
298 { "scalar_storage_order", 1, 1, false, false, false, false,
299 handle_scalar_storage_order_attribute
, NULL
},
300 { "transparent_union", 0, 0, false, false, false, false,
301 handle_transparent_union_attribute
, NULL
},
302 { "constructor", 0, 1, true, false, false, false,
303 handle_constructor_attribute
, NULL
},
304 { "destructor", 0, 1, true, false, false, false,
305 handle_destructor_attribute
, NULL
},
306 { "mode", 1, 1, false, true, false, false,
307 handle_mode_attribute
, NULL
},
308 { "section", 1, 1, true, false, false, false,
309 handle_section_attribute
, NULL
},
310 { "aligned", 0, 1, false, false, false, false,
311 handle_aligned_attribute
,
312 attr_aligned_exclusions
},
313 { "warn_if_not_aligned", 0, 1, false, false, false, false,
314 handle_warn_if_not_aligned_attribute
, NULL
},
315 { "weak", 0, 0, true, false, false, false,
316 handle_weak_attribute
, NULL
},
317 { "noplt", 0, 0, true, false, false, false,
318 handle_noplt_attribute
, NULL
},
319 { "ifunc", 1, 1, true, false, false, false,
320 handle_ifunc_attribute
, NULL
},
321 { "alias", 1, 1, true, false, false, false,
322 handle_alias_attribute
, NULL
},
323 { "weakref", 0, 1, true, false, false, false,
324 handle_weakref_attribute
, NULL
},
325 { "no_instrument_function", 0, 0, true, false, false, false,
326 handle_no_instrument_function_attribute
,
328 { "no_profile_instrument_function", 0, 0, true, false, false, false,
329 handle_no_profile_instrument_function_attribute
,
331 { "malloc", 0, 0, true, false, false, false,
332 handle_malloc_attribute
, attr_alloc_exclusions
},
333 { "returns_twice", 0, 0, true, false, false, false,
334 handle_returns_twice_attribute
,
335 attr_returns_twice_exclusions
},
336 { "no_stack_limit", 0, 0, true, false, false, false,
337 handle_no_limit_stack_attribute
, NULL
},
338 { "pure", 0, 0, true, false, false, false,
339 handle_pure_attribute
,
340 attr_const_pure_exclusions
},
341 { "transaction_callable", 0, 0, false, true, false, false,
342 handle_tm_attribute
, NULL
},
343 { "transaction_unsafe", 0, 0, false, true, false, true,
344 handle_tm_attribute
, NULL
},
345 { "transaction_safe", 0, 0, false, true, false, true,
346 handle_tm_attribute
, NULL
},
347 { "transaction_safe_dynamic", 0, 0, true, false, false, false,
348 handle_tm_attribute
, NULL
},
349 { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
350 handle_tm_attribute
, NULL
},
351 /* ??? These two attributes didn't make the transition from the
352 Intel language document to the multi-vendor language document. */
353 { "transaction_pure", 0, 0, false, true, false, false,
354 handle_tm_attribute
, NULL
},
355 { "transaction_wrap", 1, 1, true, false, false, false,
356 handle_tm_wrap_attribute
, NULL
},
357 /* For internal use (marking of builtins) only. The name contains space
358 to prevent its usage in source code. */
359 { "no vops", 0, 0, true, false, false, false,
360 handle_novops_attribute
, NULL
},
361 { "deprecated", 0, 1, false, false, false, false,
362 handle_deprecated_attribute
, NULL
},
363 { "vector_size", 1, 1, false, true, false, true,
364 handle_vector_size_attribute
, NULL
},
365 { "visibility", 1, 1, false, false, false, false,
366 handle_visibility_attribute
, NULL
},
367 { "tls_model", 1, 1, true, false, false, false,
368 handle_tls_model_attribute
, NULL
},
369 { "nonnull", 0, -1, false, true, true, false,
370 handle_nonnull_attribute
, NULL
},
371 { "nonstring", 0, 0, true, false, false, false,
372 handle_nonstring_attribute
, NULL
},
373 { "nothrow", 0, 0, true, false, false, false,
374 handle_nothrow_attribute
, NULL
},
375 { "may_alias", 0, 0, false, true, false, false, NULL
, NULL
},
376 { "cleanup", 1, 1, true, false, false, false,
377 handle_cleanup_attribute
, NULL
},
378 { "warn_unused_result", 0, 0, false, true, true, false,
379 handle_warn_unused_result_attribute
,
380 attr_warn_unused_result_exclusions
},
381 { "sentinel", 0, 1, false, true, true, false,
382 handle_sentinel_attribute
, NULL
},
383 /* For internal use (marking of builtins) only. The name contains space
384 to prevent its usage in source code. */
385 { "type generic", 0, 0, false, true, true, false,
386 handle_type_generic_attribute
, NULL
},
387 { "alloc_size", 1, 2, false, true, true, false,
388 handle_alloc_size_attribute
,
389 attr_alloc_exclusions
},
390 { "cold", 0, 0, true, false, false, false,
391 handle_cold_attribute
,
392 attr_cold_hot_exclusions
},
393 { "hot", 0, 0, true, false, false, false,
394 handle_hot_attribute
,
395 attr_cold_hot_exclusions
},
396 { "no_address_safety_analysis",
397 0, 0, true, false, false, false,
398 handle_no_address_safety_analysis_attribute
,
400 { "no_sanitize", 1, -1, true, false, false, false,
401 handle_no_sanitize_attribute
, NULL
},
402 { "no_sanitize_address", 0, 0, true, false, false, false,
403 handle_no_sanitize_address_attribute
, NULL
},
404 { "no_sanitize_thread", 0, 0, true, false, false, false,
405 handle_no_sanitize_thread_attribute
, NULL
},
406 { "no_sanitize_undefined", 0, 0, true, false, false, false,
407 handle_no_sanitize_undefined_attribute
, NULL
},
408 { "asan odr indicator", 0, 0, true, false, false, false,
409 handle_asan_odr_indicator_attribute
, NULL
},
410 { "warning", 1, 1, true, false, false, false,
411 handle_error_attribute
, NULL
},
412 { "error", 1, 1, true, false, false, false,
413 handle_error_attribute
, NULL
},
414 { "target", 1, -1, true, false, false, false,
415 handle_target_attribute
, NULL
},
416 { "target_clones", 1, -1, true, false, false, false,
417 handle_target_clones_attribute
, NULL
},
418 { "optimize", 1, -1, true, false, false, false,
419 handle_optimize_attribute
, NULL
},
420 /* For internal use only. The leading '*' both prevents its usage in
421 source code and signals that it may be overridden by machine tables. */
422 { "*tm regparm", 0, 0, false, true, true, false,
423 ignore_attribute
, NULL
},
424 { "no_split_stack", 0, 0, true, false, false, false,
425 handle_no_split_stack_attribute
, NULL
},
426 /* For internal use (marking of builtins and runtime functions) only.
427 The name contains space to prevent its usage in source code. */
428 { "fn spec", 1, 1, false, true, true, false,
429 handle_fnspec_attribute
, NULL
},
430 { "warn_unused", 0, 0, false, false, false, false,
431 handle_warn_unused_attribute
, NULL
},
432 { "returns_nonnull", 0, 0, false, true, true, false,
433 handle_returns_nonnull_attribute
, NULL
},
434 { "omp declare simd", 0, -1, true, false, false, false,
435 handle_omp_declare_simd_attribute
, NULL
},
436 { "simd", 0, 1, true, false, false, false,
437 handle_simd_attribute
, NULL
},
438 { "omp declare target", 0, 0, true, false, false, false,
439 handle_omp_declare_target_attribute
, NULL
},
440 { "omp declare target link", 0, 0, true, false, false, false,
441 handle_omp_declare_target_attribute
, NULL
},
442 { "omp declare target implicit", 0, 0, true, false, false, false,
443 handle_omp_declare_target_attribute
, NULL
},
444 { "alloc_align", 1, 1, false, true, true, false,
445 handle_alloc_align_attribute
,
446 attr_alloc_exclusions
},
447 { "assume_aligned", 1, 2, false, true, true, false,
448 handle_assume_aligned_attribute
, NULL
},
449 { "designated_init", 0, 0, false, true, false, false,
450 handle_designated_init_attribute
, NULL
},
451 { "fallthrough", 0, 0, false, false, false, false,
452 handle_fallthrough_attribute
, NULL
},
453 { "patchable_function_entry", 1, 2, true, false, false, false,
454 handle_patchable_function_entry_attribute
,
456 { "nocf_check", 0, 0, false, true, true, true,
457 handle_nocf_check_attribute
, NULL
},
458 { NULL
, 0, 0, false, false, false, false, NULL
, NULL
}
461 /* Give the specifications for the format attributes, used by C and all
464 Current list of processed format attributes: format, format_arg. */
465 const struct attribute_spec c_common_format_attribute_table
[] =
467 /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
468 affects_type_identity, handler, exclude } */
469 { "format", 3, 3, false, true, true, false,
470 handle_format_attribute
, NULL
},
471 { "format_arg", 1, 1, false, true, true, false,
472 handle_format_arg_attribute
, NULL
},
473 { NULL
, 0, 0, false, false, false, false, NULL
, NULL
}
476 /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
477 identifier as an argument, so the front end shouldn't look it up. */
480 attribute_takes_identifier_p (const_tree attr_id
)
482 const struct attribute_spec
*spec
= lookup_attribute_spec (attr_id
);
484 /* Unknown attribute that we'll end up ignoring, return true so we
485 don't complain about an identifier argument. */
487 else if (!strcmp ("mode", spec
->name
)
488 || !strcmp ("format", spec
->name
)
489 || !strcmp ("cleanup", spec
->name
))
492 return targetm
.attribute_takes_identifier_p (attr_id
);
495 /* Attribute handlers common to C front ends. */
497 /* Handle a "packed" attribute; arguments as in
498 struct attribute_spec.handler. */
501 handle_packed_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
502 int flags
, bool *no_add_attrs
)
506 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
508 warning (OPT_Wattributes
,
509 "%qE attribute ignored for type %qT", name
, *node
);
510 *no_add_attrs
= true;
513 TYPE_PACKED (*node
) = 1;
515 else if (TREE_CODE (*node
) == FIELD_DECL
)
517 if (TYPE_ALIGN (TREE_TYPE (*node
)) <= BITS_PER_UNIT
518 /* Still pack bitfields. */
519 && ! DECL_C_BIT_FIELD (*node
))
520 warning (OPT_Wattributes
,
521 "%qE attribute ignored for field of type %qT",
522 name
, TREE_TYPE (*node
));
524 DECL_PACKED (*node
) = 1;
526 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
527 used for DECL_REGISTER. It wouldn't mean anything anyway.
528 We can't set DECL_PACKED on the type of a TYPE_DECL, because
529 that changes what the typedef is typing. */
532 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
533 *no_add_attrs
= true;
539 /* Handle a "nocommon" attribute; arguments as in
540 struct attribute_spec.handler. */
543 handle_nocommon_attribute (tree
*node
, tree name
,
544 tree
ARG_UNUSED (args
),
545 int ARG_UNUSED (flags
), bool *no_add_attrs
)
548 DECL_COMMON (*node
) = 0;
551 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
552 *no_add_attrs
= true;
558 /* Handle a "common" attribute; arguments as in
559 struct attribute_spec.handler. */
562 handle_common_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
563 int ARG_UNUSED (flags
), bool *no_add_attrs
)
566 DECL_COMMON (*node
) = 1;
569 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
570 *no_add_attrs
= true;
576 /* Handle a "noreturn" attribute; arguments as in
577 struct attribute_spec.handler. */
580 handle_noreturn_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
581 int ARG_UNUSED (flags
), bool *no_add_attrs
)
583 tree type
= TREE_TYPE (*node
);
585 /* See FIXME comment in c_common_attribute_table. */
586 if (TREE_CODE (*node
) == FUNCTION_DECL
587 || objc_method_decl (TREE_CODE (*node
)))
588 TREE_THIS_VOLATILE (*node
) = 1;
589 else if (TREE_CODE (type
) == POINTER_TYPE
590 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
592 = (build_qualified_type
594 (build_type_variant (TREE_TYPE (type
),
595 TYPE_READONLY (TREE_TYPE (type
)), 1)),
599 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
600 *no_add_attrs
= true;
606 /* Handle a "hot" and attribute; arguments as in
607 struct attribute_spec.handler. */
610 handle_hot_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
611 int ARG_UNUSED (flags
), bool *no_add_attrs
)
613 if (TREE_CODE (*node
) == FUNCTION_DECL
614 || TREE_CODE (*node
) == LABEL_DECL
)
616 /* Attribute hot processing is done later with lookup_attribute. */
620 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
621 *no_add_attrs
= true;
627 /* Handle a "cold" and attribute; arguments as in
628 struct attribute_spec.handler. */
631 handle_cold_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
632 int ARG_UNUSED (flags
), bool *no_add_attrs
)
634 if (TREE_CODE (*node
) == FUNCTION_DECL
635 || TREE_CODE (*node
) == LABEL_DECL
)
637 /* Attribute cold processing is done later with lookup_attribute. */
641 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
642 *no_add_attrs
= true;
648 /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */
651 add_no_sanitize_value (tree node
, unsigned int flags
)
653 tree attr
= lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node
));
656 unsigned int old_value
= tree_to_uhwi (TREE_VALUE (attr
));
659 if (flags
== old_value
)
662 TREE_VALUE (attr
) = build_int_cst (unsigned_type_node
, flags
);
665 DECL_ATTRIBUTES (node
)
666 = tree_cons (get_identifier ("no_sanitize"),
667 build_int_cst (unsigned_type_node
, flags
),
668 DECL_ATTRIBUTES (node
));
671 /* Handle a "no_sanitize" attribute; arguments as in
672 struct attribute_spec.handler. */
675 handle_no_sanitize_attribute (tree
*node
, tree name
, tree args
, int,
678 unsigned int flags
= 0;
679 *no_add_attrs
= true;
680 if (TREE_CODE (*node
) != FUNCTION_DECL
)
682 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
686 for (; args
; args
= TREE_CHAIN (args
))
688 tree id
= TREE_VALUE (args
);
689 if (TREE_CODE (id
) != STRING_CST
)
691 error ("no_sanitize argument not a string");
695 char *string
= ASTRDUP (TREE_STRING_POINTER (id
));
696 flags
|= parse_no_sanitize_attribute (string
);
699 add_no_sanitize_value (*node
, flags
);
704 /* Handle a "no_sanitize_address" attribute; arguments as in
705 struct attribute_spec.handler. */
708 handle_no_sanitize_address_attribute (tree
*node
, tree name
, tree
, int,
711 *no_add_attrs
= true;
712 if (TREE_CODE (*node
) != FUNCTION_DECL
)
713 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
715 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
720 /* Handle a "no_sanitize_thread" attribute; arguments as in
721 struct attribute_spec.handler. */
724 handle_no_sanitize_thread_attribute (tree
*node
, tree name
, tree
, int,
727 *no_add_attrs
= true;
728 if (TREE_CODE (*node
) != FUNCTION_DECL
)
729 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
731 add_no_sanitize_value (*node
, SANITIZE_THREAD
);
737 /* Handle a "no_address_safety_analysis" attribute; arguments as in
738 struct attribute_spec.handler. */
741 handle_no_address_safety_analysis_attribute (tree
*node
, tree name
, tree
, int,
744 *no_add_attrs
= true;
745 if (TREE_CODE (*node
) != FUNCTION_DECL
)
746 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
748 add_no_sanitize_value (*node
, SANITIZE_ADDRESS
);
753 /* Handle a "no_sanitize_undefined" attribute; arguments as in
754 struct attribute_spec.handler. */
757 handle_no_sanitize_undefined_attribute (tree
*node
, tree name
, tree
, int,
760 *no_add_attrs
= true;
761 if (TREE_CODE (*node
) != FUNCTION_DECL
)
762 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
764 add_no_sanitize_value (*node
,
765 SANITIZE_UNDEFINED
| SANITIZE_UNDEFINED_NONDEFAULT
);
770 /* Handle an "asan odr indicator" attribute; arguments as in
771 struct attribute_spec.handler. */
774 handle_asan_odr_indicator_attribute (tree
*, tree
, tree
, int, bool *)
779 /* Handle a "stack_protect" attribute; arguments as in
780 struct attribute_spec.handler. */
783 handle_stack_protect_attribute (tree
*node
, tree name
, tree
, int,
786 if (TREE_CODE (*node
) != FUNCTION_DECL
)
788 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
789 *no_add_attrs
= true;
795 /* Handle a "noipa" attribute; arguments as in
796 struct attribute_spec.handler. */
799 handle_noipa_attribute (tree
*node
, tree name
, tree
, int, bool *no_add_attrs
)
801 if (TREE_CODE (*node
) != FUNCTION_DECL
)
803 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
804 *no_add_attrs
= true;
810 /* Handle a "noinline" attribute; arguments as in
811 struct attribute_spec.handler. */
814 handle_noinline_attribute (tree
*node
, tree name
,
815 tree
ARG_UNUSED (args
),
816 int ARG_UNUSED (flags
), bool *no_add_attrs
)
818 if (TREE_CODE (*node
) == FUNCTION_DECL
)
820 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
822 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
823 "with attribute %qs", name
, "always_inline");
824 *no_add_attrs
= true;
827 DECL_UNINLINABLE (*node
) = 1;
831 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
832 *no_add_attrs
= true;
838 /* Handle a "noclone" attribute; arguments as in
839 struct attribute_spec.handler. */
842 handle_noclone_attribute (tree
*node
, tree name
,
843 tree
ARG_UNUSED (args
),
844 int ARG_UNUSED (flags
), bool *no_add_attrs
)
846 if (TREE_CODE (*node
) != FUNCTION_DECL
)
848 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
849 *no_add_attrs
= true;
855 /* Handle a "nocf_check" attribute; arguments as in
856 struct attribute_spec.handler. */
859 handle_nocf_check_attribute (tree
*node
, tree name
,
860 tree
ARG_UNUSED (args
),
861 int ARG_UNUSED (flags
), bool *no_add_attrs
)
863 if (TREE_CODE (*node
) != FUNCTION_TYPE
864 && TREE_CODE (*node
) != METHOD_TYPE
)
866 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
867 *no_add_attrs
= true;
869 else if (!(flag_cf_protection
& CF_BRANCH
))
871 warning (OPT_Wattributes
, "%qE attribute ignored. Use "
872 "-fcf-protection option to enable it", name
);
873 *no_add_attrs
= true;
879 /* Handle a "no_icf" attribute; arguments as in
880 struct attribute_spec.handler. */
883 handle_noicf_attribute (tree
*node
, tree name
,
884 tree
ARG_UNUSED (args
),
885 int ARG_UNUSED (flags
), bool *no_add_attrs
)
887 if (TREE_CODE (*node
) != FUNCTION_DECL
)
889 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
890 *no_add_attrs
= true;
897 /* Handle a "always_inline" attribute; arguments as in
898 struct attribute_spec.handler. */
901 handle_always_inline_attribute (tree
*node
, tree name
,
902 tree
ARG_UNUSED (args
),
903 int ARG_UNUSED (flags
),
906 if (TREE_CODE (*node
) == FUNCTION_DECL
)
908 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node
)))
910 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
911 "with %qs attribute", name
, "noinline");
912 *no_add_attrs
= true;
914 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
916 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
917 "with %qs attribute", name
, "target_clones");
918 *no_add_attrs
= true;
921 /* Set the attribute and mark it for disregarding inline
923 DECL_DISREGARD_INLINE_LIMITS (*node
) = 1;
927 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
928 *no_add_attrs
= true;
934 /* Handle a "gnu_inline" attribute; arguments as in
935 struct attribute_spec.handler. */
938 handle_gnu_inline_attribute (tree
*node
, tree name
,
939 tree
ARG_UNUSED (args
),
940 int ARG_UNUSED (flags
),
943 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
945 /* Do nothing else, just set the attribute. We'll get at
946 it later with lookup_attribute. */
950 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
951 *no_add_attrs
= true;
957 /* Handle a "leaf" attribute; arguments as in
958 struct attribute_spec.handler. */
961 handle_leaf_attribute (tree
*node
, tree name
,
962 tree
ARG_UNUSED (args
),
963 int ARG_UNUSED (flags
), bool *no_add_attrs
)
965 if (TREE_CODE (*node
) != FUNCTION_DECL
)
967 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
968 *no_add_attrs
= true;
970 if (!TREE_PUBLIC (*node
))
972 warning (OPT_Wattributes
, "%qE attribute has no effect on unit local "
974 *no_add_attrs
= true;
980 /* Handle an "artificial" attribute; arguments as in
981 struct attribute_spec.handler. */
984 handle_artificial_attribute (tree
*node
, tree name
,
985 tree
ARG_UNUSED (args
),
986 int ARG_UNUSED (flags
),
989 if (TREE_CODE (*node
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (*node
))
991 /* Do nothing else, just set the attribute. We'll get at
992 it later with lookup_attribute. */
996 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
997 *no_add_attrs
= true;
1003 /* Handle a "flatten" attribute; arguments as in
1004 struct attribute_spec.handler. */
1007 handle_flatten_attribute (tree
*node
, tree name
,
1008 tree args ATTRIBUTE_UNUSED
,
1009 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
1011 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1012 /* Do nothing else, just set the attribute. We'll get at
1013 it later with lookup_attribute. */
1017 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1018 *no_add_attrs
= true;
1024 /* Handle a "warning" or "error" attribute; arguments as in
1025 struct attribute_spec.handler. */
1028 handle_error_attribute (tree
*node
, tree name
, tree args
,
1029 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1031 if (TREE_CODE (*node
) == FUNCTION_DECL
1032 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
1033 /* Do nothing else, just set the attribute. We'll get at
1034 it later with lookup_attribute. */
1038 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1039 *no_add_attrs
= true;
1045 /* Handle a "used" attribute; arguments as in
1046 struct attribute_spec.handler. */
1049 handle_used_attribute (tree
*pnode
, tree name
, tree
ARG_UNUSED (args
),
1050 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1054 if (TREE_CODE (node
) == FUNCTION_DECL
1055 || (VAR_P (node
) && TREE_STATIC (node
))
1056 || (TREE_CODE (node
) == TYPE_DECL
))
1058 TREE_USED (node
) = 1;
1059 DECL_PRESERVE_P (node
) = 1;
1061 DECL_READ_P (node
) = 1;
1065 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1066 *no_add_attrs
= true;
1072 /* Handle a "unused" attribute; arguments as in
1073 struct attribute_spec.handler. */
1076 handle_unused_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1077 int flags
, bool *no_add_attrs
)
1083 if (TREE_CODE (decl
) == PARM_DECL
1084 || VAR_OR_FUNCTION_DECL_P (decl
)
1085 || TREE_CODE (decl
) == LABEL_DECL
1086 || TREE_CODE (decl
) == CONST_DECL
1087 || TREE_CODE (decl
) == TYPE_DECL
)
1089 TREE_USED (decl
) = 1;
1090 if (VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
1091 DECL_READ_P (decl
) = 1;
1095 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1096 *no_add_attrs
= true;
1101 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1102 *node
= build_variant_type_copy (*node
);
1103 TREE_USED (*node
) = 1;
1109 /* Handle a "externally_visible" attribute; arguments as in
1110 struct attribute_spec.handler. */
1113 handle_externally_visible_attribute (tree
*pnode
, tree name
,
1114 tree
ARG_UNUSED (args
),
1115 int ARG_UNUSED (flags
),
1120 if (VAR_OR_FUNCTION_DECL_P (node
))
1122 if ((!TREE_STATIC (node
) && TREE_CODE (node
) != FUNCTION_DECL
1123 && !DECL_EXTERNAL (node
)) || !TREE_PUBLIC (node
))
1125 warning (OPT_Wattributes
,
1126 "%qE attribute have effect only on public objects", name
);
1127 *no_add_attrs
= true;
1132 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1133 *no_add_attrs
= true;
1139 /* Handle the "no_reorder" attribute. Arguments as in
1140 struct attribute_spec.handler. */
1143 handle_no_reorder_attribute (tree
*pnode
,
1151 if (!VAR_OR_FUNCTION_DECL_P (node
)
1152 && !(TREE_STATIC (node
) || DECL_EXTERNAL (node
)))
1154 warning (OPT_Wattributes
,
1155 "%qE attribute only affects top level objects",
1157 *no_add_attrs
= true;
1163 /* Handle a "const" attribute; arguments as in
1164 struct attribute_spec.handler. */
1167 handle_const_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
1168 int flags
, bool *no_add_attrs
)
1170 tree type
= TREE_TYPE (*node
);
1172 /* See FIXME comment on noreturn in c_common_attribute_table. */
1173 if (TREE_CODE (*node
) == FUNCTION_DECL
)
1174 TREE_READONLY (*node
) = 1;
1175 else if (TREE_CODE (type
) == POINTER_TYPE
1176 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
1178 = (build_qualified_type
1180 (build_type_variant (TREE_TYPE (type
), 1,
1181 TREE_THIS_VOLATILE (TREE_TYPE (type
)))),
1182 TYPE_QUALS (type
)));
1185 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1186 *no_add_attrs
= true;
1189 /* void __builtin_unreachable(void) is const. Accept other such
1190 built-ins but warn on user-defined functions that return void. */
1191 if (!(flags
& ATTR_FLAG_BUILT_IN
)
1192 && TREE_CODE (*node
) == FUNCTION_DECL
1193 && VOID_TYPE_P (TREE_TYPE (type
)))
1194 warning (OPT_Wattributes
, "%qE attribute on function "
1195 "returning %<void%>", name
);
1200 /* Handle a "scalar_storage_order" attribute; arguments as in
1201 struct attribute_spec.handler. */
1204 handle_scalar_storage_order_attribute (tree
*node
, tree name
, tree args
,
1205 int flags
, bool *no_add_attrs
)
1207 tree id
= TREE_VALUE (args
);
1210 if (TREE_CODE (*node
) == TYPE_DECL
1211 && ! (flags
& ATTR_FLAG_CXX11
))
1212 node
= &TREE_TYPE (*node
);
1215 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
)
1217 error ("scalar_storage_order is not supported because endianness "
1222 if (RECORD_OR_UNION_TYPE_P (type
) && !c_dialect_cxx ())
1224 bool reverse
= false;
1226 if (TREE_CODE (id
) == STRING_CST
1227 && strcmp (TREE_STRING_POINTER (id
), "big-endian") == 0)
1228 reverse
= !BYTES_BIG_ENDIAN
;
1229 else if (TREE_CODE (id
) == STRING_CST
1230 && strcmp (TREE_STRING_POINTER (id
), "little-endian") == 0)
1231 reverse
= BYTES_BIG_ENDIAN
;
1234 error ("scalar_storage_order argument must be one of \"big-endian\""
1235 " or \"little-endian\"");
1239 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1242 /* A type variant isn't good enough, since we don't want a cast
1243 to such a type to be removed as a no-op. */
1244 *node
= type
= build_duplicate_type (type
);
1247 TYPE_REVERSE_STORAGE_ORDER (type
) = reverse
;
1251 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1252 *no_add_attrs
= true;
1256 /* Handle a "transparent_union" attribute; arguments as in
1257 struct attribute_spec.handler. */
1260 handle_transparent_union_attribute (tree
*node
, tree name
,
1261 tree
ARG_UNUSED (args
), int flags
,
1266 *no_add_attrs
= true;
1268 if (TREE_CODE (*node
) == TYPE_DECL
1269 && ! (flags
& ATTR_FLAG_CXX11
))
1270 node
= &TREE_TYPE (*node
);
1273 if (TREE_CODE (type
) == UNION_TYPE
)
1275 /* Make sure that the first field will work for a transparent union.
1276 If the type isn't complete yet, leave the check to the code in
1278 if (TYPE_SIZE (type
))
1280 tree first
= first_field (type
);
1281 if (first
== NULL_TREE
1282 || DECL_ARTIFICIAL (first
)
1283 || TYPE_MODE (type
) != DECL_MODE (first
))
1287 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1289 /* If the type isn't complete yet, setting the flag
1290 on a variant wouldn't ever be checked. */
1291 if (!TYPE_SIZE (type
))
1294 /* build_duplicate_type doesn't work for C++. */
1295 if (c_dialect_cxx ())
1298 /* A type variant isn't good enough, since we don't want a cast
1299 to such a type to be removed as a no-op. */
1300 *node
= type
= build_duplicate_type (type
);
1303 for (tree t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
1304 TYPE_TRANSPARENT_AGGR (t
) = 1;
1309 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1313 /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to
1314 get the requested priority for a constructor or destructor,
1315 possibly issuing diagnostics for invalid or reserved
1318 static priority_type
1319 get_priority (tree args
, bool is_destructor
)
1325 return DEFAULT_INIT_PRIORITY
;
1327 if (!SUPPORTS_INIT_PRIORITY
)
1330 error ("destructor priorities are not supported");
1332 error ("constructor priorities are not supported");
1333 return DEFAULT_INIT_PRIORITY
;
1336 arg
= TREE_VALUE (args
);
1337 if (TREE_CODE (arg
) == IDENTIFIER_NODE
)
1339 if (arg
== error_mark_node
)
1340 return DEFAULT_INIT_PRIORITY
;
1341 arg
= default_conversion (arg
);
1342 if (!tree_fits_shwi_p (arg
)
1343 || !INTEGRAL_TYPE_P (TREE_TYPE (arg
)))
1346 pri
= tree_to_shwi (arg
);
1347 if (pri
< 0 || pri
> MAX_INIT_PRIORITY
)
1350 if (pri
<= MAX_RESERVED_INIT_PRIORITY
)
1353 warning (OPT_Wprio_ctor_dtor
,
1354 "destructor priorities from 0 to %d are reserved "
1355 "for the implementation",
1356 MAX_RESERVED_INIT_PRIORITY
);
1358 warning (OPT_Wprio_ctor_dtor
,
1359 "constructor priorities from 0 to %d are reserved "
1360 "for the implementation",
1361 MAX_RESERVED_INIT_PRIORITY
);
1367 error ("destructor priorities must be integers from 0 to %d inclusive",
1370 error ("constructor priorities must be integers from 0 to %d inclusive",
1372 return DEFAULT_INIT_PRIORITY
;
1375 /* Handle a "constructor" attribute; arguments as in
1376 struct attribute_spec.handler. */
1379 handle_constructor_attribute (tree
*node
, tree name
, tree args
,
1380 int ARG_UNUSED (flags
),
1384 tree type
= TREE_TYPE (decl
);
1386 if (TREE_CODE (decl
) == FUNCTION_DECL
1387 && TREE_CODE (type
) == FUNCTION_TYPE
1388 && decl_function_context (decl
) == 0)
1390 priority_type priority
;
1391 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1392 priority
= get_priority (args
, /*is_destructor=*/false);
1393 SET_DECL_INIT_PRIORITY (decl
, priority
);
1394 TREE_USED (decl
) = 1;
1398 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1399 *no_add_attrs
= true;
1405 /* Handle a "destructor" attribute; arguments as in
1406 struct attribute_spec.handler. */
1409 handle_destructor_attribute (tree
*node
, tree name
, tree args
,
1410 int ARG_UNUSED (flags
),
1414 tree type
= TREE_TYPE (decl
);
1416 if (TREE_CODE (decl
) == FUNCTION_DECL
1417 && TREE_CODE (type
) == FUNCTION_TYPE
1418 && decl_function_context (decl
) == 0)
1420 priority_type priority
;
1421 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1422 priority
= get_priority (args
, /*is_destructor=*/true);
1423 SET_DECL_FINI_PRIORITY (decl
, priority
);
1424 TREE_USED (decl
) = 1;
1428 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1429 *no_add_attrs
= true;
1435 /* Nonzero if the mode is a valid vector mode for this architecture.
1436 This returns nonzero even if there is no hardware support for the
1437 vector mode, but we can emulate with narrower modes. */
1440 vector_mode_valid_p (machine_mode mode
)
1442 enum mode_class mclass
= GET_MODE_CLASS (mode
);
1444 /* Doh! What's going on? */
1445 if (mclass
!= MODE_VECTOR_INT
1446 && mclass
!= MODE_VECTOR_FLOAT
1447 && mclass
!= MODE_VECTOR_FRACT
1448 && mclass
!= MODE_VECTOR_UFRACT
1449 && mclass
!= MODE_VECTOR_ACCUM
1450 && mclass
!= MODE_VECTOR_UACCUM
)
1453 /* Hardware support. Woo hoo! */
1454 if (targetm
.vector_mode_supported_p (mode
))
1457 /* We should probably return 1 if requesting V4DI and we have no DI,
1458 but we have V2DI, but this is probably very unlikely. */
1460 /* If we have support for the inner mode, we can safely emulate it.
1461 We may not have V2DI, but me can emulate with a pair of DIs. */
1462 return targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1466 /* Handle a "mode" attribute; arguments as in
1467 struct attribute_spec.handler. */
1470 handle_mode_attribute (tree
*node
, tree name
, tree args
,
1471 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1474 tree ident
= TREE_VALUE (args
);
1476 *no_add_attrs
= true;
1478 if (TREE_CODE (ident
) != IDENTIFIER_NODE
)
1479 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
1483 const char *p
= IDENTIFIER_POINTER (ident
);
1484 int len
= strlen (p
);
1485 machine_mode mode
= VOIDmode
;
1489 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
1490 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
1492 char *newp
= (char *) alloca (len
- 1);
1494 strcpy (newp
, &p
[2]);
1495 newp
[len
- 4] = '\0';
1499 /* Change this type to have a type with the specified mode.
1500 First check for the special modes. */
1501 if (!strcmp (p
, "byte"))
1503 else if (!strcmp (p
, "word"))
1505 else if (!strcmp (p
, "pointer"))
1507 else if (!strcmp (p
, "libgcc_cmp_return"))
1508 mode
= targetm
.libgcc_cmp_return_mode ();
1509 else if (!strcmp (p
, "libgcc_shift_count"))
1510 mode
= targetm
.libgcc_shift_count_mode ();
1511 else if (!strcmp (p
, "unwind_word"))
1512 mode
= targetm
.unwind_word_mode ();
1514 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
1515 if (!strcmp (p
, GET_MODE_NAME (j
)))
1517 mode
= (machine_mode
) j
;
1521 if (mode
== VOIDmode
)
1523 error ("unknown machine mode %qE", ident
);
1527 /* Allow the target a chance to translate MODE into something supported.
1529 mode
= targetm
.translate_mode_attribute (mode
);
1532 switch (GET_MODE_CLASS (mode
))
1535 case MODE_PARTIAL_INT
:
1537 case MODE_DECIMAL_FLOAT
:
1543 = targetm
.scalar_mode_supported_p (as_a
<scalar_mode
> (mode
));
1546 case MODE_COMPLEX_INT
:
1547 case MODE_COMPLEX_FLOAT
:
1548 valid_mode
= targetm
.scalar_mode_supported_p (GET_MODE_INNER (mode
));
1551 case MODE_VECTOR_INT
:
1552 case MODE_VECTOR_FLOAT
:
1553 case MODE_VECTOR_FRACT
:
1554 case MODE_VECTOR_UFRACT
:
1555 case MODE_VECTOR_ACCUM
:
1556 case MODE_VECTOR_UACCUM
:
1557 warning (OPT_Wattributes
, "specifying vector types with "
1558 "__attribute__ ((mode)) is deprecated");
1559 warning (OPT_Wattributes
,
1560 "use __attribute__ ((vector_size)) instead");
1561 valid_mode
= vector_mode_valid_p (mode
);
1569 error ("unable to emulate %qs", p
);
1573 if (POINTER_TYPE_P (type
))
1575 scalar_int_mode addr_mode
;
1576 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (type
));
1577 tree (*fn
)(tree
, machine_mode
, bool);
1579 if (!is_a
<scalar_int_mode
> (mode
, &addr_mode
)
1580 || !targetm
.addr_space
.valid_pointer_mode (addr_mode
, as
))
1582 error ("invalid pointer mode %qs", p
);
1586 if (TREE_CODE (type
) == POINTER_TYPE
)
1587 fn
= build_pointer_type_for_mode
;
1589 fn
= build_reference_type_for_mode
;
1590 typefm
= fn (TREE_TYPE (type
), addr_mode
, false);
1594 /* For fixed-point modes, we need to test if the signness of type
1595 and the machine mode are consistent. */
1596 if (ALL_FIXED_POINT_MODE_P (mode
)
1597 && TYPE_UNSIGNED (type
) != UNSIGNED_FIXED_POINT_MODE_P (mode
))
1599 error ("signedness of type and machine mode %qs don%'t match", p
);
1602 /* For fixed-point modes, we need to pass saturating info. */
1603 typefm
= lang_hooks
.types
.type_for_mode (mode
,
1604 ALL_FIXED_POINT_MODE_P (mode
) ? TYPE_SATURATING (type
)
1605 : TYPE_UNSIGNED (type
));
1608 if (typefm
== NULL_TREE
)
1610 error ("no data type for mode %qs", p
);
1613 else if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1615 /* For enumeral types, copy the precision from the integer
1616 type returned above. If not an INTEGER_TYPE, we can't use
1617 this mode for this type. */
1618 if (TREE_CODE (typefm
) != INTEGER_TYPE
)
1620 error ("cannot use mode %qs for enumeral types", p
);
1624 if (flags
& ATTR_FLAG_TYPE_IN_PLACE
)
1626 TYPE_PRECISION (type
) = TYPE_PRECISION (typefm
);
1631 /* We cannot build a type variant, as there's code that assumes
1632 that TYPE_MAIN_VARIANT has the same mode. This includes the
1633 debug generators. Instead, create a subrange type. This
1634 results in all of the enumeral values being emitted only once
1635 in the original, and the subtype gets them by reference. */
1636 if (TYPE_UNSIGNED (type
))
1637 typefm
= make_unsigned_type (TYPE_PRECISION (typefm
));
1639 typefm
= make_signed_type (TYPE_PRECISION (typefm
));
1640 TREE_TYPE (typefm
) = type
;
1643 else if (VECTOR_MODE_P (mode
)
1644 ? TREE_CODE (type
) != TREE_CODE (TREE_TYPE (typefm
))
1645 : TREE_CODE (type
) != TREE_CODE (typefm
))
1647 error ("mode %qs applied to inappropriate type", p
);
1651 *node
= build_qualified_type (typefm
, TYPE_QUALS (type
));
1657 /* Handle a "section" attribute; arguments as in
1658 struct attribute_spec.handler. */
1661 handle_section_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
1662 int ARG_UNUSED (flags
), bool *no_add_attrs
)
1666 if (!targetm_common
.have_named_sections
)
1668 error_at (DECL_SOURCE_LOCATION (*node
),
1669 "section attributes are not supported for this target");
1673 if (!VAR_OR_FUNCTION_DECL_P (decl
))
1675 error ("section attribute not allowed for %q+D", *node
);
1679 if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
1681 error ("section attribute argument not a string constant");
1686 && current_function_decl
!= NULL_TREE
1687 && !TREE_STATIC (decl
))
1689 error_at (DECL_SOURCE_LOCATION (decl
),
1690 "section attribute cannot be specified for local variables");
1694 /* The decl may have already been given a section attribute
1695 from a previous declaration. Ensure they match. */
1696 if (DECL_SECTION_NAME (decl
) != NULL
1697 && strcmp (DECL_SECTION_NAME (decl
),
1698 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
1700 error ("section of %q+D conflicts with previous declaration", *node
);
1705 && !targetm
.have_tls
&& targetm
.emutls
.tmpl_section
1706 && DECL_THREAD_LOCAL_P (decl
))
1708 error ("section of %q+D cannot be overridden", *node
);
1712 set_decl_section_name (decl
, TREE_STRING_POINTER (TREE_VALUE (args
)));
1716 *no_add_attrs
= true;
1720 /* If in c++-11, check if the c++-11 alignment constraint with respect
1721 to fundamental alignment (in [dcl.align]) are satisfied. If not in
1722 c++-11 mode, does nothing.
1726 [* if the constant expression evaluates to a fundamental alignment,
1727 the alignment requirement of the declared entity shall be the
1728 specified fundamental alignment.
1730 * if the constant expression evaluates to an extended alignment
1731 and the implementation supports that alignment in the context
1732 of the declaration, the alignment of the declared entity shall
1735 * if the constant expression evaluates to an extended alignment
1736 and the implementation does not support that alignment in the
1737 context of the declaration, the program is ill-formed]. */
1740 check_cxx_fundamental_alignment_constraints (tree node
,
1744 bool alignment_too_large_p
= false;
1745 unsigned requested_alignment
= (1U << align_log
) * BITS_PER_UNIT
;
1746 unsigned max_align
= 0;
1748 if ((!(flags
& ATTR_FLAG_CXX11
) && !warn_cxx_compat
)
1749 || (node
== NULL_TREE
|| node
== error_mark_node
))
1752 if (cxx_fundamental_alignment_p (requested_alignment
))
1757 if (TREE_STATIC (node
) || DECL_EXTERNAL (node
))
1758 /* For file scope variables and static members, the target supports
1759 alignments that are at most MAX_OFILE_ALIGNMENT. */
1760 max_align
= MAX_OFILE_ALIGNMENT
;
1762 /* For stack variables, the target supports at most
1763 MAX_STACK_ALIGNMENT. */
1764 max_align
= MAX_STACK_ALIGNMENT
;
1765 if (requested_alignment
> max_align
)
1766 alignment_too_large_p
= true;
1768 /* Let's be liberal for types and fields; don't limit their alignment any
1769 more than check_user_alignment already did. */
1771 if (alignment_too_large_p
)
1772 pedwarn (input_location
, OPT_Wattributes
,
1773 "requested alignment %d is larger than %d",
1774 requested_alignment
/ BITS_PER_UNIT
, max_align
/ BITS_PER_UNIT
);
1776 return !alignment_too_large_p
;
1779 /* Common codes shared by handle_warn_if_not_aligned_attribute and
1780 handle_aligned_attribute. */
1783 common_handle_aligned_attribute (tree
*node
, tree name
, tree args
, int flags
,
1785 bool warn_if_not_aligned_p
)
1787 tree decl
= NULL_TREE
;
1789 bool is_type
= false;
1792 /* The last (already pushed) declaration with all validated attributes
1793 merged in or the current about-to-be-pushed one if one hasn't been
1795 tree last_decl
= node
[1] ? node
[1] : *node
;
1799 align_expr
= TREE_VALUE (args
);
1800 if (align_expr
&& TREE_CODE (align_expr
) != IDENTIFIER_NODE
1801 && TREE_CODE (align_expr
) != FUNCTION_DECL
)
1802 align_expr
= default_conversion (align_expr
);
1805 align_expr
= size_int (ATTRIBUTE_ALIGNED_VALUE
/ BITS_PER_UNIT
);
1810 type
= &TREE_TYPE (decl
);
1811 is_type
= TREE_CODE (*node
) == TYPE_DECL
;
1813 else if (TYPE_P (*node
))
1814 type
= node
, is_type
= true;
1816 /* Log2 of specified alignment. */
1817 int pow2align
= check_user_alignment (align_expr
, true);
1819 || !check_cxx_fundamental_alignment_constraints (*node
, pow2align
, flags
))
1821 *no_add_attrs
= true;
1825 /* The alignment in bits corresponding to the specified alignment. */
1826 unsigned bitalign
= (1U << pow2align
) * BITS_PER_UNIT
;
1828 /* The alignment of the current declaration and that of the last
1829 pushed declaration, determined on demand below. */
1830 unsigned curalign
= 0;
1831 unsigned lastalign
= 0;
1835 if ((flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
1836 /* OK, modify the type in place. */;
1837 /* If we have a TYPE_DECL, then copy the type, so that we
1838 don't accidentally modify a builtin type. See pushdecl. */
1839 else if (decl
&& TREE_TYPE (decl
) != error_mark_node
1840 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
1842 tree tt
= TREE_TYPE (decl
);
1843 *type
= build_variant_type_copy (*type
);
1844 DECL_ORIGINAL_TYPE (decl
) = tt
;
1845 TYPE_NAME (*type
) = decl
;
1846 TREE_USED (*type
) = TREE_USED (decl
);
1847 TREE_TYPE (decl
) = *type
;
1850 *type
= build_variant_type_copy (*type
);
1852 if (warn_if_not_aligned_p
)
1854 SET_TYPE_WARN_IF_NOT_ALIGN (*type
, bitalign
);
1855 warn_if_not_aligned_p
= false;
1859 SET_TYPE_ALIGN (*type
, bitalign
);
1860 TYPE_USER_ALIGN (*type
) = 1;
1863 else if (! VAR_OR_FUNCTION_DECL_P (decl
)
1864 && TREE_CODE (decl
) != FIELD_DECL
)
1866 error ("alignment may not be specified for %q+D", decl
);
1867 *no_add_attrs
= true;
1869 else if (TREE_CODE (decl
) == FUNCTION_DECL
1870 && ((curalign
= DECL_ALIGN (decl
)) > bitalign
1871 || ((lastalign
= DECL_ALIGN (last_decl
)) > bitalign
)))
1873 /* Either a prior attribute on the same declaration or one
1874 on a prior declaration of the same function specifies
1875 stricter alignment than this attribute. */
1876 bool note
= lastalign
!= 0;
1878 curalign
= lastalign
;
1880 curalign
/= BITS_PER_UNIT
;
1881 bitalign
/= BITS_PER_UNIT
;
1884 auto_diagnostic_group d
;
1885 if (DECL_USER_ALIGN (decl
) || DECL_USER_ALIGN (last_decl
))
1886 diagd
= warning (OPT_Wattributes
,
1887 "ignoring attribute %<%E (%u)%> because it conflicts "
1888 "with attribute %<%E (%u)%>",
1889 name
, bitalign
, name
, curalign
);
1890 else if (!warn_if_not_aligned_p
)
1891 /* Do not error out for attribute warn_if_not_aligned. */
1892 error ("alignment for %q+D must be at least %d", decl
, curalign
);
1895 inform (DECL_SOURCE_LOCATION (last_decl
), "previous declaration here");
1897 *no_add_attrs
= true;
1899 else if (DECL_USER_ALIGN (decl
)
1900 && DECL_ALIGN (decl
) > bitalign
)
1901 /* C++-11 [dcl.align/4]:
1903 When multiple alignment-specifiers are specified for an
1904 entity, the alignment requirement shall be set to the
1905 strictest specified alignment.
1907 This formally comes from the c++11 specification but we are
1908 doing it for the GNU attribute syntax as well. */
1909 *no_add_attrs
= true;
1910 else if (!warn_if_not_aligned_p
1911 && TREE_CODE (decl
) == FUNCTION_DECL
1912 && DECL_ALIGN (decl
) > bitalign
)
1914 /* Don't warn function alignment here if warn_if_not_aligned_p is
1915 true. It will be warned later. */
1916 if (DECL_USER_ALIGN (decl
))
1917 error ("alignment for %q+D was previously specified as %d "
1918 "and may not be decreased", decl
,
1919 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1921 error ("alignment for %q+D must be at least %d", decl
,
1922 DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1923 *no_add_attrs
= true;
1927 if (warn_if_not_aligned_p
)
1929 if (TREE_CODE (decl
) == FIELD_DECL
&& !DECL_C_BIT_FIELD (decl
))
1931 SET_DECL_WARN_IF_NOT_ALIGN (decl
, bitalign
);
1932 warn_if_not_aligned_p
= false;
1937 SET_DECL_ALIGN (decl
, bitalign
);
1938 DECL_USER_ALIGN (decl
) = 1;
1942 if (warn_if_not_aligned_p
)
1944 error ("%<warn_if_not_aligned%> may not be specified for %q+D",
1946 *no_add_attrs
= true;
1952 /* Handle a "aligned" attribute; arguments as in
1953 struct attribute_spec.handler. */
1956 handle_aligned_attribute (tree
*node
, tree name
, tree args
,
1957 int flags
, bool *no_add_attrs
)
1959 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1960 no_add_attrs
, false);
1963 /* Handle a "warn_if_not_aligned" attribute; arguments as in
1964 struct attribute_spec.handler. */
1967 handle_warn_if_not_aligned_attribute (tree
*node
, tree name
,
1968 tree args
, int flags
,
1971 return common_handle_aligned_attribute (node
, name
, args
, flags
,
1972 no_add_attrs
, true);
1975 /* Handle a "weak" attribute; arguments as in
1976 struct attribute_spec.handler. */
1979 handle_weak_attribute (tree
*node
, tree name
,
1980 tree
ARG_UNUSED (args
),
1981 int ARG_UNUSED (flags
),
1982 bool * ARG_UNUSED (no_add_attrs
))
1984 if (TREE_CODE (*node
) == FUNCTION_DECL
1985 && DECL_DECLARED_INLINE_P (*node
))
1987 warning (OPT_Wattributes
, "inline function %q+D declared weak", *node
);
1988 *no_add_attrs
= true;
1990 else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
1992 error ("indirect function %q+D cannot be declared weak", *node
);
1993 *no_add_attrs
= true;
1996 else if (VAR_OR_FUNCTION_DECL_P (*node
))
1997 declare_weak (*node
);
1999 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2004 /* Handle a "noplt" attribute; arguments as in
2005 struct attribute_spec.handler. */
2008 handle_noplt_attribute (tree
*node
, tree name
,
2009 tree
ARG_UNUSED (args
),
2010 int ARG_UNUSED (flags
),
2011 bool * ARG_UNUSED (no_add_attrs
))
2013 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2015 warning (OPT_Wattributes
,
2016 "%qE attribute is only applicable on functions", name
);
2017 *no_add_attrs
= true;
2023 /* Handle an "alias" or "ifunc" attribute; arguments as in
2024 struct attribute_spec.handler, except that IS_ALIAS tells us
2025 whether this is an alias as opposed to ifunc attribute. */
2028 handle_alias_ifunc_attribute (bool is_alias
, tree
*node
, tree name
, tree args
,
2033 if (TREE_CODE (decl
) != FUNCTION_DECL
2034 && (!is_alias
|| !VAR_P (decl
)))
2036 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2037 *no_add_attrs
= true;
2039 else if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
2040 || (TREE_CODE (decl
) != FUNCTION_DECL
2041 && TREE_PUBLIC (decl
) && !DECL_EXTERNAL (decl
))
2042 /* A static variable declaration is always a tentative definition,
2043 but the alias is a non-tentative definition which overrides. */
2044 || (TREE_CODE (decl
) != FUNCTION_DECL
2045 && ! TREE_PUBLIC (decl
) && DECL_INITIAL (decl
)))
2047 error ("%q+D defined both normally and as %qE attribute", decl
, name
);
2048 *no_add_attrs
= true;
2052 && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2053 || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))))
2055 error ("weak %q+D cannot be defined %qE", decl
, name
);
2056 *no_add_attrs
= true;
2060 /* Note that the very first time we process a nested declaration,
2061 decl_function_context will not be set. Indeed, *would* never
2062 be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that
2063 we do below. After such frobbery, pushdecl would set the context.
2064 In any case, this is never what we want. */
2065 else if (decl_function_context (decl
) == 0 && current_function_decl
== NULL
)
2069 id
= TREE_VALUE (args
);
2070 if (TREE_CODE (id
) != STRING_CST
)
2072 error ("attribute %qE argument not a string", name
);
2073 *no_add_attrs
= true;
2076 id
= get_identifier (TREE_STRING_POINTER (id
));
2077 /* This counts as a use of the object pointed to. */
2080 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2081 DECL_INITIAL (decl
) = error_mark_node
;
2083 TREE_STATIC (decl
) = 1;
2087 /* ifuncs are also aliases, so set that attribute too. */
2088 DECL_ATTRIBUTES (decl
)
2089 = tree_cons (get_identifier ("alias"), args
,
2090 DECL_ATTRIBUTES (decl
));
2091 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("ifunc"),
2092 NULL
, DECL_ATTRIBUTES (decl
));
2097 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2098 *no_add_attrs
= true;
2101 if (decl_in_symtab_p (*node
))
2103 struct symtab_node
*n
= symtab_node::get (decl
);
2104 if (n
&& n
->refuse_visibility_changes
)
2107 error ("%+qD declared alias after being used", decl
);
2109 error ("%+qD declared ifunc after being used", decl
);
2117 /* Handle an "alias" or "ifunc" attribute; arguments as in
2118 struct attribute_spec.handler. */
2121 handle_ifunc_attribute (tree
*node
, tree name
, tree args
,
2122 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2124 return handle_alias_ifunc_attribute (false, node
, name
, args
, no_add_attrs
);
2127 /* Handle an "alias" or "ifunc" attribute; arguments as in
2128 struct attribute_spec.handler. */
2131 handle_alias_attribute (tree
*node
, tree name
, tree args
,
2132 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2134 return handle_alias_ifunc_attribute (true, node
, name
, args
, no_add_attrs
);
2137 /* Handle a "weakref" attribute; arguments as in struct
2138 attribute_spec.handler. */
2141 handle_weakref_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2142 int flags
, bool *no_add_attrs
)
2144 tree attr
= NULL_TREE
;
2146 /* We must ignore the attribute when it is associated with
2147 local-scoped decls, since attribute alias is ignored and many
2148 such symbols do not even have a DECL_WEAK field. */
2149 if (decl_function_context (*node
)
2150 || current_function_decl
2151 || !VAR_OR_FUNCTION_DECL_P (*node
))
2153 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2154 *no_add_attrs
= true;
2158 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node
)))
2160 error ("indirect function %q+D cannot be declared weakref", *node
);
2161 *no_add_attrs
= true;
2165 /* The idea here is that `weakref("name")' mutates into `weakref,
2166 alias("name")', and weakref without arguments, in turn,
2167 implicitly adds weak. */
2171 attr
= tree_cons (get_identifier ("alias"), args
, attr
);
2172 attr
= tree_cons (get_identifier ("weakref"), NULL_TREE
, attr
);
2174 *no_add_attrs
= true;
2176 decl_attributes (node
, attr
, flags
);
2180 if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node
)))
2181 error_at (DECL_SOURCE_LOCATION (*node
),
2182 "weakref attribute must appear before alias attribute");
2184 /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
2185 and that isn't supported; and because it wants to add it to
2186 the list of weak decls, which isn't helpful. */
2187 DECL_WEAK (*node
) = 1;
2190 if (decl_in_symtab_p (*node
))
2192 struct symtab_node
*n
= symtab_node::get (*node
);
2193 if (n
&& n
->refuse_visibility_changes
)
2194 error ("%+qD declared weakref after being used", *node
);
2200 /* Handle an "visibility" attribute; arguments as in
2201 struct attribute_spec.handler. */
2204 handle_visibility_attribute (tree
*node
, tree name
, tree args
,
2205 int ARG_UNUSED (flags
),
2206 bool *ARG_UNUSED (no_add_attrs
))
2209 tree id
= TREE_VALUE (args
);
2210 enum symbol_visibility vis
;
2214 if (TREE_CODE (*node
) == ENUMERAL_TYPE
)
2216 else if (!RECORD_OR_UNION_TYPE_P (*node
))
2218 warning (OPT_Wattributes
, "%qE attribute ignored on non-class types",
2222 else if (TYPE_FIELDS (*node
))
2224 error ("%qE attribute ignored because %qT is already defined",
2229 else if (decl_function_context (decl
) != 0 || !TREE_PUBLIC (decl
))
2231 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2235 if (TREE_CODE (id
) != STRING_CST
)
2237 error ("visibility argument not a string");
2241 /* If this is a type, set the visibility on the type decl. */
2244 decl
= TYPE_NAME (decl
);
2247 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
2249 warning (OPT_Wattributes
, "%qE attribute ignored on types",
2255 if (strcmp (TREE_STRING_POINTER (id
), "default") == 0)
2256 vis
= VISIBILITY_DEFAULT
;
2257 else if (strcmp (TREE_STRING_POINTER (id
), "internal") == 0)
2258 vis
= VISIBILITY_INTERNAL
;
2259 else if (strcmp (TREE_STRING_POINTER (id
), "hidden") == 0)
2260 vis
= VISIBILITY_HIDDEN
;
2261 else if (strcmp (TREE_STRING_POINTER (id
), "protected") == 0)
2262 vis
= VISIBILITY_PROTECTED
;
2265 error ("visibility argument must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
2266 vis
= VISIBILITY_DEFAULT
;
2269 if (DECL_VISIBILITY_SPECIFIED (decl
)
2270 && vis
!= DECL_VISIBILITY (decl
))
2272 tree attributes
= (TYPE_P (*node
)
2273 ? TYPE_ATTRIBUTES (*node
)
2274 : DECL_ATTRIBUTES (decl
));
2275 if (lookup_attribute ("visibility", attributes
))
2276 error ("%qD redeclared with different visibility", decl
);
2277 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2278 && lookup_attribute ("dllimport", attributes
))
2279 error ("%qD was declared %qs which implies default visibility",
2281 else if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
2282 && lookup_attribute ("dllexport", attributes
))
2283 error ("%qD was declared %qs which implies default visibility",
2287 DECL_VISIBILITY (decl
) = vis
;
2288 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
2290 /* Go ahead and attach the attribute to the node as well. This is needed
2291 so we can determine whether we have VISIBILITY_DEFAULT because the
2292 visibility was not specified, or because it was explicitly overridden
2293 from the containing scope. */
2298 /* Handle an "tls_model" attribute; arguments as in
2299 struct attribute_spec.handler. */
2302 handle_tls_model_attribute (tree
*node
, tree name
, tree args
,
2303 int ARG_UNUSED (flags
),
2304 bool *ARG_UNUSED (no_add_attrs
))
2308 enum tls_model kind
;
2310 if (!VAR_P (decl
) || !DECL_THREAD_LOCAL_P (decl
))
2312 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2316 kind
= DECL_TLS_MODEL (decl
);
2317 id
= TREE_VALUE (args
);
2318 if (TREE_CODE (id
) != STRING_CST
)
2320 error ("tls_model argument not a string");
2324 if (!strcmp (TREE_STRING_POINTER (id
), "local-exec"))
2325 kind
= TLS_MODEL_LOCAL_EXEC
;
2326 else if (!strcmp (TREE_STRING_POINTER (id
), "initial-exec"))
2327 kind
= TLS_MODEL_INITIAL_EXEC
;
2328 else if (!strcmp (TREE_STRING_POINTER (id
), "local-dynamic"))
2329 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
2330 else if (!strcmp (TREE_STRING_POINTER (id
), "global-dynamic"))
2331 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
2333 error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
2335 set_decl_tls_model (decl
, kind
);
2339 /* Handle a "no_instrument_function" attribute; arguments as in
2340 struct attribute_spec.handler. */
2343 handle_no_instrument_function_attribute (tree
*node
, tree name
,
2344 tree
ARG_UNUSED (args
),
2345 int ARG_UNUSED (flags
),
2350 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2352 error_at (DECL_SOURCE_LOCATION (decl
),
2353 "%qE attribute applies only to functions", name
);
2354 *no_add_attrs
= true;
2357 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
2362 /* Handle a "no_profile_instrument_function" attribute; arguments as in
2363 struct attribute_spec.handler. */
2366 handle_no_profile_instrument_function_attribute (tree
*node
, tree name
, tree
,
2367 int, bool *no_add_attrs
)
2369 if (TREE_CODE (*node
) != FUNCTION_DECL
)
2371 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2372 *no_add_attrs
= true;
2378 /* Handle a "malloc" attribute; arguments as in
2379 struct attribute_spec.handler. */
2382 handle_malloc_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2383 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2385 if (TREE_CODE (*node
) == FUNCTION_DECL
2386 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node
))))
2387 DECL_IS_MALLOC (*node
) = 1;
2390 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2391 *no_add_attrs
= true;
2397 /* Handle a "alloc_size" attribute; arguments as in
2398 struct attribute_spec.handler. */
2401 handle_alloc_size_attribute (tree
*node
, tree
ARG_UNUSED (name
), tree args
,
2402 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2404 unsigned arg_count
= type_num_arguments (*node
);
2405 for (; args
; args
= TREE_CHAIN (args
))
2407 tree position
= TREE_VALUE (args
);
2408 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2409 && TREE_CODE (position
) != FUNCTION_DECL
)
2410 position
= default_conversion (position
);
2412 if (!tree_fits_uhwi_p (position
)
2414 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2416 warning (OPT_Wattributes
,
2417 "alloc_size parameter outside range");
2418 *no_add_attrs
= true;
2425 /* Handle a "alloc_align" attribute; arguments as in
2426 struct attribute_spec.handler. */
2429 handle_alloc_align_attribute (tree
*node
, tree
, tree args
, int,
2432 unsigned arg_count
= type_num_arguments (*node
);
2433 tree position
= TREE_VALUE (args
);
2434 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2435 && TREE_CODE (position
) != FUNCTION_DECL
)
2436 position
= default_conversion (position
);
2438 if (!tree_fits_uhwi_p (position
)
2440 || !IN_RANGE (tree_to_uhwi (position
), 1, arg_count
))
2442 warning (OPT_Wattributes
,
2443 "alloc_align parameter outside range");
2444 *no_add_attrs
= true;
2450 /* Handle a "assume_aligned" attribute; arguments as in
2451 struct attribute_spec.handler. */
2454 handle_assume_aligned_attribute (tree
*, tree
, tree args
, int,
2457 for (; args
; args
= TREE_CHAIN (args
))
2459 tree position
= TREE_VALUE (args
);
2460 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
2461 && TREE_CODE (position
) != FUNCTION_DECL
)
2462 position
= default_conversion (position
);
2464 if (TREE_CODE (position
) != INTEGER_CST
)
2466 warning (OPT_Wattributes
,
2467 "assume_aligned parameter not integer constant");
2468 *no_add_attrs
= true;
2475 /* Handle a "fn spec" attribute; arguments as in
2476 struct attribute_spec.handler. */
2479 handle_fnspec_attribute (tree
*node ATTRIBUTE_UNUSED
, tree
ARG_UNUSED (name
),
2480 tree args
, int ARG_UNUSED (flags
),
2481 bool *no_add_attrs ATTRIBUTE_UNUSED
)
2484 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
2485 && !TREE_CHAIN (args
));
2489 /* Handle a "warn_unused" attribute; arguments as in
2490 struct attribute_spec.handler. */
2493 handle_warn_unused_attribute (tree
*node
, tree name
,
2494 tree args ATTRIBUTE_UNUSED
,
2495 int flags ATTRIBUTE_UNUSED
, bool *no_add_attrs
)
2498 /* Do nothing else, just set the attribute. We'll get at
2499 it later with lookup_attribute. */
2503 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2504 *no_add_attrs
= true;
2510 /* Handle an "omp declare simd" attribute; arguments as in
2511 struct attribute_spec.handler. */
2514 handle_omp_declare_simd_attribute (tree
*, tree
, tree
, int, bool *)
2519 /* Handle a "simd" attribute. */
2522 handle_simd_attribute (tree
*node
, tree name
, tree args
, int, bool *no_add_attrs
)
2524 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2526 tree t
= get_identifier ("omp declare simd");
2527 tree attr
= NULL_TREE
;
2530 tree id
= TREE_VALUE (args
);
2532 if (TREE_CODE (id
) != STRING_CST
)
2534 error ("attribute %qE argument not a string", name
);
2535 *no_add_attrs
= true;
2539 if (strcmp (TREE_STRING_POINTER (id
), "notinbranch") == 0)
2540 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2541 OMP_CLAUSE_NOTINBRANCH
);
2542 else if (strcmp (TREE_STRING_POINTER (id
), "inbranch") == 0)
2543 attr
= build_omp_clause (DECL_SOURCE_LOCATION (*node
),
2544 OMP_CLAUSE_INBRANCH
);
2547 error ("only %<inbranch%> and %<notinbranch%> flags are "
2548 "allowed for %<__simd__%> attribute");
2549 *no_add_attrs
= true;
2554 DECL_ATTRIBUTES (*node
)
2555 = tree_cons (t
, build_tree_list (NULL_TREE
, attr
),
2556 DECL_ATTRIBUTES (*node
));
2560 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2561 *no_add_attrs
= true;
2567 /* Handle an "omp declare target" attribute; arguments as in
2568 struct attribute_spec.handler. */
2571 handle_omp_declare_target_attribute (tree
*, tree
, tree
, int, bool *)
2576 /* Handle a "returns_twice" attribute; arguments as in
2577 struct attribute_spec.handler. */
2580 handle_returns_twice_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2581 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2583 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2584 DECL_IS_RETURNS_TWICE (*node
) = 1;
2587 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2588 *no_add_attrs
= true;
2594 /* Handle a "no_limit_stack" attribute; arguments as in
2595 struct attribute_spec.handler. */
2598 handle_no_limit_stack_attribute (tree
*node
, tree name
,
2599 tree
ARG_UNUSED (args
),
2600 int ARG_UNUSED (flags
),
2605 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2607 error_at (DECL_SOURCE_LOCATION (decl
),
2608 "%qE attribute applies only to functions", name
);
2609 *no_add_attrs
= true;
2611 else if (DECL_INITIAL (decl
))
2613 error_at (DECL_SOURCE_LOCATION (decl
),
2614 "can%'t set %qE attribute after definition", name
);
2615 *no_add_attrs
= true;
2618 DECL_NO_LIMIT_STACK (decl
) = 1;
2623 /* Handle a "pure" attribute; arguments as in
2624 struct attribute_spec.handler. */
2627 handle_pure_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
2628 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2630 if (TREE_CODE (*node
) == FUNCTION_DECL
)
2632 tree type
= TREE_TYPE (*node
);
2633 if (VOID_TYPE_P (TREE_TYPE (type
)))
2634 warning (OPT_Wattributes
, "%qE attribute on function "
2635 "returning %<void%>", name
);
2637 DECL_PURE_P (*node
) = 1;
2638 /* ??? TODO: Support types. */
2642 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2643 *no_add_attrs
= true;
2649 /* Digest an attribute list destined for a transactional memory statement.
2650 ALLOWED is the set of attributes that are allowed for this statement;
2651 return the attribute we parsed. Multiple attributes are never allowed. */
2654 parse_tm_stmt_attr (tree attrs
, int allowed
)
2659 for ( ; attrs
; attrs
= TREE_CHAIN (attrs
))
2661 tree a
= TREE_PURPOSE (attrs
);
2664 if (is_attribute_p ("outer", a
))
2665 m
= TM_STMT_ATTR_OUTER
;
2667 if ((m
& allowed
) == 0)
2669 warning (OPT_Wattributes
, "%qE attribute directive ignored", a
);
2678 else if (m_seen
== m
)
2679 warning (OPT_Wattributes
, "%qE attribute duplicated", a
);
2681 warning (OPT_Wattributes
, "%qE attribute follows %qE", a
, a_seen
);
2687 /* Transform a TM attribute name into a maskable integer and back.
2688 Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
2689 to how the lack of an attribute is treated. */
2692 tm_attr_to_mask (tree attr
)
2696 if (is_attribute_p ("transaction_safe", attr
))
2697 return TM_ATTR_SAFE
;
2698 if (is_attribute_p ("transaction_callable", attr
))
2699 return TM_ATTR_CALLABLE
;
2700 if (is_attribute_p ("transaction_pure", attr
))
2701 return TM_ATTR_PURE
;
2702 if (is_attribute_p ("transaction_unsafe", attr
))
2703 return TM_ATTR_IRREVOCABLE
;
2704 if (is_attribute_p ("transaction_may_cancel_outer", attr
))
2705 return TM_ATTR_MAY_CANCEL_OUTER
;
2710 tm_mask_to_attr (int mask
)
2716 str
= "transaction_safe";
2718 case TM_ATTR_CALLABLE
:
2719 str
= "transaction_callable";
2722 str
= "transaction_pure";
2724 case TM_ATTR_IRREVOCABLE
:
2725 str
= "transaction_unsafe";
2727 case TM_ATTR_MAY_CANCEL_OUTER
:
2728 str
= "transaction_may_cancel_outer";
2733 return get_identifier (str
);
2736 /* Return the first TM attribute seen in LIST. */
2739 find_tm_attribute (tree list
)
2741 for (; list
; list
= TREE_CHAIN (list
))
2743 tree name
= TREE_PURPOSE (list
);
2744 if (tm_attr_to_mask (name
) != 0)
2750 /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
2751 Here we accept only function types, and verify that none of the other
2752 function TM attributes are also applied. */
2753 /* ??? We need to accept class types for C++, but not C. This greatly
2754 complicates this function, since we can no longer rely on the extra
2755 processing given by function_type_required. */
2758 handle_tm_attribute (tree
*node
, tree name
, tree args
,
2759 int flags
, bool *no_add_attrs
)
2761 /* Only one path adds the attribute; others don't. */
2762 *no_add_attrs
= true;
2764 switch (TREE_CODE (*node
))
2768 /* Only tm_callable and tm_safe apply to classes. */
2769 if (tm_attr_to_mask (name
) & ~(TM_ATTR_SAFE
| TM_ATTR_CALLABLE
))
2776 tree old_name
= find_tm_attribute (TYPE_ATTRIBUTES (*node
));
2777 if (old_name
== name
)
2779 else if (old_name
!= NULL_TREE
)
2780 error ("type was previously declared %qE", old_name
);
2782 *no_add_attrs
= false;
2788 /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
2789 want to set transaction_safe on the type. */
2790 gcc_assert (is_attribute_p ("transaction_safe_dynamic", name
));
2791 if (!TYPE_P (DECL_CONTEXT (*node
)))
2792 error_at (DECL_SOURCE_LOCATION (*node
),
2793 "%<transaction_safe_dynamic%> may only be specified for "
2794 "a virtual function");
2795 *no_add_attrs
= false;
2796 decl_attributes (&TREE_TYPE (*node
),
2797 build_tree_list (get_identifier ("transaction_safe"),
2805 enum tree_code subcode
= TREE_CODE (TREE_TYPE (*node
));
2806 if (subcode
== FUNCTION_TYPE
|| subcode
== METHOD_TYPE
)
2808 tree fn_tmp
= TREE_TYPE (*node
);
2809 decl_attributes (&fn_tmp
, tree_cons (name
, args
, NULL
), 0);
2810 *node
= build_pointer_type (fn_tmp
);
2817 /* If a function is next, pass it on to be tried next. */
2818 if (flags
& (int) ATTR_FLAG_FUNCTION_NEXT
)
2819 return tree_cons (name
, args
, NULL
);
2822 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2829 /* Handle the TM_WRAP attribute; arguments as in
2830 struct attribute_spec.handler. */
2833 handle_tm_wrap_attribute (tree
*node
, tree name
, tree args
,
2834 int ARG_UNUSED (flags
), bool *no_add_attrs
)
2838 /* We don't need the attribute even on success, since we
2839 record the entry in an external table. */
2840 *no_add_attrs
= true;
2842 if (TREE_CODE (decl
) != FUNCTION_DECL
)
2843 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2846 tree wrap_decl
= TREE_VALUE (args
);
2847 if (error_operand_p (wrap_decl
))
2849 else if (TREE_CODE (wrap_decl
) != IDENTIFIER_NODE
2850 && !VAR_OR_FUNCTION_DECL_P (wrap_decl
))
2851 error ("%qE argument not an identifier", name
);
2854 if (TREE_CODE (wrap_decl
) == IDENTIFIER_NODE
)
2855 wrap_decl
= lookup_name (wrap_decl
);
2856 if (wrap_decl
&& TREE_CODE (wrap_decl
) == FUNCTION_DECL
)
2858 if (lang_hooks
.types_compatible_p (TREE_TYPE (decl
),
2859 TREE_TYPE (wrap_decl
)))
2860 record_tm_replacement (wrap_decl
, decl
);
2862 error ("%qD is not compatible with %qD", wrap_decl
, decl
);
2865 error ("%qE argument is not a function", name
);
2872 /* Ignore the given attribute. Used when this attribute may be usefully
2873 overridden by the target, but is not used generically. */
2876 ignore_attribute (tree
* ARG_UNUSED (node
), tree
ARG_UNUSED (name
),
2877 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2880 *no_add_attrs
= true;
2884 /* Handle a "no vops" attribute; arguments as in
2885 struct attribute_spec.handler. */
2888 handle_novops_attribute (tree
*node
, tree
ARG_UNUSED (name
),
2889 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
2890 bool *ARG_UNUSED (no_add_attrs
))
2892 gcc_assert (TREE_CODE (*node
) == FUNCTION_DECL
);
2893 DECL_IS_NOVOPS (*node
) = 1;
2897 /* Handle a "deprecated" attribute; arguments as in
2898 struct attribute_spec.handler. */
2901 handle_deprecated_attribute (tree
*node
, tree name
,
2902 tree args
, int flags
,
2905 tree type
= NULL_TREE
;
2907 tree what
= NULL_TREE
;
2910 *no_add_attrs
= true;
2911 else if (TREE_CODE (TREE_VALUE (args
)) != STRING_CST
)
2913 error ("deprecated message is not a string");
2914 *no_add_attrs
= true;
2920 type
= TREE_TYPE (decl
);
2922 if (TREE_CODE (decl
) == TYPE_DECL
2923 || TREE_CODE (decl
) == PARM_DECL
2924 || VAR_OR_FUNCTION_DECL_P (decl
)
2925 || TREE_CODE (decl
) == FIELD_DECL
2926 || TREE_CODE (decl
) == CONST_DECL
2927 || objc_method_decl (TREE_CODE (decl
)))
2928 TREE_DEPRECATED (decl
) = 1;
2932 else if (TYPE_P (*node
))
2934 if (!(flags
& (int) ATTR_FLAG_TYPE_IN_PLACE
))
2935 *node
= build_variant_type_copy (*node
);
2936 TREE_DEPRECATED (*node
) = 1;
2944 *no_add_attrs
= true;
2945 if (type
&& TYPE_NAME (type
))
2947 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
2948 what
= TYPE_NAME (*node
);
2949 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
2950 && DECL_NAME (TYPE_NAME (type
)))
2951 what
= DECL_NAME (TYPE_NAME (type
));
2954 warning (OPT_Wattributes
, "%qE attribute ignored for %qE", name
, what
);
2956 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2962 /* Handle a "vector_size" attribute; arguments as in
2963 struct attribute_spec.handler. */
2966 handle_vector_size_attribute (tree
*node
, tree name
, tree args
,
2967 int ARG_UNUSED (flags
),
2970 unsigned HOST_WIDE_INT vecsize
, nunits
;
2971 machine_mode orig_mode
;
2972 tree type
= *node
, new_type
, size
;
2974 *no_add_attrs
= true;
2976 size
= TREE_VALUE (args
);
2977 if (size
&& TREE_CODE (size
) != IDENTIFIER_NODE
2978 && TREE_CODE (size
) != FUNCTION_DECL
)
2979 size
= default_conversion (size
);
2981 if (!tree_fits_uhwi_p (size
))
2983 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
2987 /* Get the vector size (in bytes). */
2988 vecsize
= tree_to_uhwi (size
);
2990 /* We need to provide for vector pointers, vector arrays, and
2991 functions returning vectors. For example:
2993 __attribute__((vector_size(16))) short *foo;
2995 In this case, the mode is SI, but the type being modified is
2996 HI, so we need to look further. */
2998 while (POINTER_TYPE_P (type
)
2999 || TREE_CODE (type
) == FUNCTION_TYPE
3000 || TREE_CODE (type
) == METHOD_TYPE
3001 || TREE_CODE (type
) == ARRAY_TYPE
3002 || TREE_CODE (type
) == OFFSET_TYPE
)
3003 type
= TREE_TYPE (type
);
3005 /* Get the mode of the type being modified. */
3006 orig_mode
= TYPE_MODE (type
);
3008 if ((!INTEGRAL_TYPE_P (type
)
3009 && !SCALAR_FLOAT_TYPE_P (type
)
3010 && !FIXED_POINT_TYPE_P (type
))
3011 || (!SCALAR_FLOAT_MODE_P (orig_mode
)
3012 && GET_MODE_CLASS (orig_mode
) != MODE_INT
3013 && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode
))
3014 || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
))
3015 || TREE_CODE (type
) == BOOLEAN_TYPE
)
3017 error ("invalid vector type for attribute %qE", name
);
3021 if (vecsize
% tree_to_uhwi (TYPE_SIZE_UNIT (type
)))
3023 error ("vector size not an integral multiple of component size");
3029 error ("zero vector size");
3033 /* Calculate how many units fit in the vector. */
3034 nunits
= vecsize
/ tree_to_uhwi (TYPE_SIZE_UNIT (type
));
3035 if (nunits
& (nunits
- 1))
3037 error ("number of components of the vector not a power of two");
3041 new_type
= build_vector_type (type
, nunits
);
3043 /* Build back pointers if needed. */
3044 *node
= lang_hooks
.types
.reconstruct_complex_type (*node
, new_type
);
3049 /* Handle the "nonnull" attribute. */
3052 handle_nonnull_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3053 tree args
, int ARG_UNUSED (flags
),
3057 unsigned HOST_WIDE_INT attr_arg_num
;
3059 /* If no arguments are specified, all pointer arguments should be
3060 non-null. Verify a full prototype is given so that the arguments
3061 will have the correct types when we actually check them later.
3062 Avoid diagnosing type-generic built-ins since those have no
3066 if (!prototype_p (type
)
3067 && (!TYPE_ATTRIBUTES (type
)
3068 || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type
))))
3070 error ("nonnull attribute without arguments on a non-prototype");
3071 *no_add_attrs
= true;
3076 /* Argument list specified. Verify that each argument number references
3077 a pointer argument. */
3078 for (attr_arg_num
= 1; args
; attr_arg_num
++, args
= TREE_CHAIN (args
))
3080 unsigned HOST_WIDE_INT arg_num
= 0, ck_num
;
3082 tree arg
= TREE_VALUE (args
);
3083 if (arg
&& TREE_CODE (arg
) != IDENTIFIER_NODE
3084 && TREE_CODE (arg
) != FUNCTION_DECL
)
3085 TREE_VALUE (args
) = arg
= default_conversion (arg
);
3087 if (!get_nonnull_operand (arg
, &arg_num
))
3089 error ("nonnull argument has invalid operand number (argument %lu)",
3090 (unsigned long) attr_arg_num
);
3091 *no_add_attrs
= true;
3095 if (prototype_p (type
))
3097 function_args_iterator iter
;
3100 function_args_iter_init (&iter
, type
);
3101 for (ck_num
= 1; ; ck_num
++, function_args_iter_next (&iter
))
3103 argument
= function_args_iter_cond (&iter
);
3104 if (argument
== NULL_TREE
|| ck_num
== arg_num
)
3109 || TREE_CODE (argument
) == VOID_TYPE
)
3111 error ("nonnull argument with out-of-range operand number "
3112 "(argument %lu, operand %lu)",
3113 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3114 *no_add_attrs
= true;
3118 if (TREE_CODE (argument
) != POINTER_TYPE
)
3120 error ("nonnull argument references non-pointer operand "
3121 "(argument %lu, operand %lu)",
3122 (unsigned long) attr_arg_num
, (unsigned long) arg_num
);
3123 *no_add_attrs
= true;
3132 /* Handle the "nonstring" variable attribute. */
3135 handle_nonstring_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3136 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3139 tree_code code
= TREE_CODE (*node
);
3142 || code
== FIELD_DECL
3143 || code
== PARM_DECL
)
3145 tree type
= TREE_TYPE (*node
);
3147 if (POINTER_TYPE_P (type
) || TREE_CODE (type
) == ARRAY_TYPE
)
3149 /* Accept the attribute on arrays and pointers to all three
3150 narrow character types. */
3151 tree eltype
= TREE_TYPE (type
);
3152 eltype
= TYPE_MAIN_VARIANT (eltype
);
3153 if (eltype
== char_type_node
3154 || eltype
== signed_char_type_node
3155 || eltype
== unsigned_char_type_node
)
3159 warning (OPT_Wattributes
,
3160 "%qE attribute ignored on objects of type %qT",
3162 *no_add_attrs
= true;
3166 if (code
== FUNCTION_DECL
)
3167 warning (OPT_Wattributes
,
3168 "%qE attribute does not apply to functions", name
);
3169 else if (code
== TYPE_DECL
)
3170 warning (OPT_Wattributes
,
3171 "%qE attribute does not apply to types", name
);
3173 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3175 *no_add_attrs
= true;
3179 /* Handle a "nothrow" attribute; arguments as in
3180 struct attribute_spec.handler. */
3183 handle_nothrow_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3184 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3186 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3187 TREE_NOTHROW (*node
) = 1;
3188 /* ??? TODO: Support types. */
3191 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3192 *no_add_attrs
= true;
3198 /* Handle a "cleanup" attribute; arguments as in
3199 struct attribute_spec.handler. */
3202 handle_cleanup_attribute (tree
*node
, tree name
, tree args
,
3203 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3206 tree cleanup_id
, cleanup_decl
;
3208 /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
3209 for global destructors in C++. This requires infrastructure that
3210 we don't have generically at the moment. It's also not a feature
3211 we'd be missing too much, since we do have attribute constructor. */
3212 if (!VAR_P (decl
) || TREE_STATIC (decl
))
3214 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3215 *no_add_attrs
= true;
3219 /* Verify that the argument is a function in scope. */
3220 /* ??? We could support pointers to functions here as well, if
3221 that was considered desirable. */
3222 cleanup_id
= TREE_VALUE (args
);
3223 if (TREE_CODE (cleanup_id
) != IDENTIFIER_NODE
)
3225 error ("cleanup argument not an identifier");
3226 *no_add_attrs
= true;
3229 cleanup_decl
= lookup_name (cleanup_id
);
3230 if (!cleanup_decl
|| TREE_CODE (cleanup_decl
) != FUNCTION_DECL
)
3232 error ("cleanup argument not a function");
3233 *no_add_attrs
= true;
3237 /* That the function has proper type is checked with the
3238 eventual call to build_function_call. */
3243 /* Handle a "warn_unused_result" attribute. No special handling. */
3246 handle_warn_unused_result_attribute (tree
*node
, tree name
,
3247 tree
ARG_UNUSED (args
),
3248 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3250 /* Ignore the attribute for functions not returning any value. */
3251 if (VOID_TYPE_P (TREE_TYPE (*node
)))
3253 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3254 *no_add_attrs
= true;
3260 /* Handle a "sentinel" attribute. */
3263 handle_sentinel_attribute (tree
*node
, tree name
, tree args
,
3264 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3266 if (!prototype_p (*node
))
3268 warning (OPT_Wattributes
,
3269 "%qE attribute requires prototypes with named arguments", name
);
3270 *no_add_attrs
= true;
3274 if (!stdarg_p (*node
))
3276 warning (OPT_Wattributes
,
3277 "%qE attribute only applies to variadic functions", name
);
3278 *no_add_attrs
= true;
3284 tree position
= TREE_VALUE (args
);
3285 if (position
&& TREE_CODE (position
) != IDENTIFIER_NODE
3286 && TREE_CODE (position
) != FUNCTION_DECL
)
3287 position
= default_conversion (position
);
3289 if (TREE_CODE (position
) != INTEGER_CST
3290 || !INTEGRAL_TYPE_P (TREE_TYPE (position
)))
3292 warning (OPT_Wattributes
,
3293 "requested position is not an integer constant");
3294 *no_add_attrs
= true;
3298 if (tree_int_cst_lt (position
, integer_zero_node
))
3300 warning (OPT_Wattributes
,
3301 "requested position is less than zero");
3302 *no_add_attrs
= true;
3310 /* Handle a "type_generic" attribute. */
3313 handle_type_generic_attribute (tree
*node
, tree
ARG_UNUSED (name
),
3314 tree
ARG_UNUSED (args
), int ARG_UNUSED (flags
),
3315 bool * ARG_UNUSED (no_add_attrs
))
3317 /* Ensure we have a function type. */
3318 gcc_assert (TREE_CODE (*node
) == FUNCTION_TYPE
);
3320 /* Ensure we have a variadic function. */
3321 gcc_assert (!prototype_p (*node
) || stdarg_p (*node
));
3326 /* Handle a "target" attribute. */
3329 handle_target_attribute (tree
*node
, tree name
, tree args
, int flags
,
3332 /* Ensure we have a function type. */
3333 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3335 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3336 *no_add_attrs
= true;
3338 else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node
)))
3340 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3341 "with %qs attribute", name
, "target_clones");
3342 *no_add_attrs
= true;
3344 else if (! targetm
.target_option
.valid_attribute_p (*node
, name
, args
,
3346 *no_add_attrs
= true;
3348 /* Check that there's no empty string in values of the attribute. */
3349 for (tree t
= args
; t
!= NULL_TREE
; t
= TREE_CHAIN (t
))
3351 tree value
= TREE_VALUE (t
);
3352 if (TREE_CODE (value
) == STRING_CST
3353 && TREE_STRING_LENGTH (value
) == 1
3354 && TREE_STRING_POINTER (value
)[0] == '\0')
3356 warning (OPT_Wattributes
, "empty string in attribute %<target%>");
3357 *no_add_attrs
= true;
3364 /* Handle a "target_clones" attribute. */
3367 handle_target_clones_attribute (tree
*node
, tree name
, tree
ARG_UNUSED (args
),
3368 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3370 /* Ensure we have a function type. */
3371 if (TREE_CODE (*node
) == FUNCTION_DECL
)
3373 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node
)))
3375 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3376 "with %qs attribute", name
, "always_inline");
3377 *no_add_attrs
= true;
3379 else if (lookup_attribute ("target", DECL_ATTRIBUTES (*node
)))
3381 warning (OPT_Wattributes
, "%qE attribute ignored due to conflict "
3382 "with %qs attribute", name
, "target");
3383 *no_add_attrs
= true;
3386 /* Do not inline functions with multiple clone targets. */
3387 DECL_UNINLINABLE (*node
) = 1;
3391 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3392 *no_add_attrs
= true;
3397 /* For handling "optimize" attribute. arguments as in
3398 struct attribute_spec.handler. */
3401 handle_optimize_attribute (tree
*node
, tree name
, tree args
,
3402 int ARG_UNUSED (flags
), bool *no_add_attrs
)
3404 /* Ensure we have a function type. */
3405 if (TREE_CODE (*node
) != FUNCTION_DECL
)
3407 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3408 *no_add_attrs
= true;
3412 struct cl_optimization cur_opts
;
3413 tree old_opts
= DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
);
3415 /* Save current options. */
3416 cl_optimization_save (&cur_opts
, &global_options
);
3418 /* If we previously had some optimization options, use them as the
3421 cl_optimization_restore (&global_options
,
3422 TREE_OPTIMIZATION (old_opts
));
3424 /* Parse options, and update the vector. */
3425 parse_optimize_options (args
, true);
3426 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node
)
3427 = build_optimization_node (&global_options
);
3429 /* Restore current options. */
3430 cl_optimization_restore (&global_options
, &cur_opts
);
3436 /* Handle a "no_split_stack" attribute. */
3439 handle_no_split_stack_attribute (tree
*node
, tree name
,
3440 tree
ARG_UNUSED (args
),
3441 int ARG_UNUSED (flags
),
3446 if (TREE_CODE (decl
) != FUNCTION_DECL
)
3448 error_at (DECL_SOURCE_LOCATION (decl
),
3449 "%qE attribute applies only to functions", name
);
3450 *no_add_attrs
= true;
3452 else if (DECL_INITIAL (decl
))
3454 error_at (DECL_SOURCE_LOCATION (decl
),
3455 "can%'t set %qE attribute after definition", name
);
3456 *no_add_attrs
= true;
3462 /* Handle a "returns_nonnull" attribute; arguments as in
3463 struct attribute_spec.handler. */
3466 handle_returns_nonnull_attribute (tree
*node
, tree
, tree
, int,
3469 // Even without a prototype we still have a return type we can check.
3470 if (TREE_CODE (TREE_TYPE (*node
)) != POINTER_TYPE
)
3472 error ("returns_nonnull attribute on a function not returning a pointer");
3473 *no_add_attrs
= true;
3478 /* Handle a "designated_init" attribute; arguments as in
3479 struct attribute_spec.handler. */
3482 handle_designated_init_attribute (tree
*node
, tree name
, tree
, int,
3485 if (TREE_CODE (*node
) != RECORD_TYPE
)
3487 error ("%qE attribute is only valid on %<struct%> type", name
);
3488 *no_add_attrs
= true;
3494 /* Handle a "fallthrough" attribute; arguments as in struct
3495 attribute_spec.handler. */
3498 handle_fallthrough_attribute (tree
*, tree name
, tree
, int,
3501 warning (OPT_Wattributes
, "%qE attribute ignored", name
);
3502 *no_add_attrs
= true;
3507 handle_patchable_function_entry_attribute (tree
*, tree
, tree
, int, bool *)
3509 /* Nothing to be done here. */