1 /* Functions dealing with attribute handling, used by most front ends.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
36 static void init_attributes PARAMS ((void));
38 /* Table of the tables of attributes (common, format, language, machine)
40 static const struct attribute_spec *attribute_tables[4];
42 static bool attributes_initialized = false;
44 static tree handle_packed_attribute PARAMS ((tree *, tree, tree, int,
46 static tree handle_nocommon_attribute PARAMS ((tree *, tree, tree, int,
48 static tree handle_common_attribute PARAMS ((tree *, tree, tree, int,
50 static tree handle_noreturn_attribute PARAMS ((tree *, tree, tree, int,
52 static tree handle_noinline_attribute PARAMS ((tree *, tree, tree, int,
54 static tree handle_used_attribute PARAMS ((tree *, tree, tree, int,
56 static tree handle_unused_attribute PARAMS ((tree *, tree, tree, int,
58 static tree handle_const_attribute PARAMS ((tree *, tree, tree, int,
60 static tree handle_transparent_union_attribute PARAMS ((tree *, tree, tree,
62 static tree handle_constructor_attribute PARAMS ((tree *, tree, tree, int,
64 static tree handle_destructor_attribute PARAMS ((tree *, tree, tree, int,
66 static tree handle_mode_attribute PARAMS ((tree *, tree, tree, int,
68 static tree handle_section_attribute PARAMS ((tree *, tree, tree, int,
70 static tree handle_aligned_attribute PARAMS ((tree *, tree, tree, int,
72 static tree handle_weak_attribute PARAMS ((tree *, tree, tree, int,
74 static tree handle_alias_attribute PARAMS ((tree *, tree, tree, int,
76 static tree handle_no_instrument_function_attribute PARAMS ((tree *, tree,
79 static tree handle_malloc_attribute PARAMS ((tree *, tree, tree, int,
81 static tree handle_no_limit_stack_attribute PARAMS ((tree *, tree, tree, int,
83 static tree handle_pure_attribute PARAMS ((tree *, tree, tree, int,
86 /* Table of machine-independent attributes common to all C-like languages. */
87 static const struct attribute_spec c_common_attribute_table[] =
89 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
90 { "packed", 0, 0, false, false, false,
91 handle_packed_attribute },
92 { "nocommon", 0, 0, true, false, false,
93 handle_nocommon_attribute },
94 { "common", 0, 0, true, false, false,
95 handle_common_attribute },
96 /* FIXME: logically, noreturn attributes should be listed as
97 "false, true, true" and apply to function types. But implementing this
98 would require all the places in the compiler that use TREE_THIS_VOLATILE
99 on a decl to identify non-returning functions to be located and fixed
100 to check the function type instead. */
101 { "noreturn", 0, 0, true, false, false,
102 handle_noreturn_attribute },
103 { "volatile", 0, 0, true, false, false,
104 handle_noreturn_attribute },
105 { "noinline", 0, 0, true, false, false,
106 handle_noinline_attribute },
107 { "used", 0, 0, true, false, false,
108 handle_used_attribute },
109 { "unused", 0, 0, false, false, false,
110 handle_unused_attribute },
111 /* The same comments as for noreturn attributes apply to const ones. */
112 { "const", 0, 0, true, false, false,
113 handle_const_attribute },
114 { "transparent_union", 0, 0, false, false, false,
115 handle_transparent_union_attribute },
116 { "constructor", 0, 0, true, false, false,
117 handle_constructor_attribute },
118 { "destructor", 0, 0, true, false, false,
119 handle_destructor_attribute },
120 { "mode", 1, 1, true, false, false,
121 handle_mode_attribute },
122 { "section", 1, 1, true, false, false,
123 handle_section_attribute },
124 { "aligned", 0, 1, false, false, false,
125 handle_aligned_attribute },
126 { "weak", 0, 0, true, false, false,
127 handle_weak_attribute },
128 { "alias", 1, 1, true, false, false,
129 handle_alias_attribute },
130 { "no_instrument_function", 0, 0, true, false, false,
131 handle_no_instrument_function_attribute },
132 { "malloc", 0, 0, true, false, false,
133 handle_malloc_attribute },
134 { "no_stack_limit", 0, 0, true, false, false,
135 handle_no_limit_stack_attribute },
136 { "pure", 0, 0, true, false, false,
137 handle_pure_attribute },
138 { NULL, 0, 0, false, false, false, NULL }
141 /* Default empty table of attributes. */
142 static const struct attribute_spec empty_attribute_table[] =
144 { NULL, 0, 0, false, false, false, NULL }
147 /* Table of machine-independent attributes for checking formats, if used. */
148 const struct attribute_spec *format_attribute_table = empty_attribute_table;
150 /* Table of machine-independent attributes for a particular language. */
151 const struct attribute_spec *lang_attribute_table = empty_attribute_table;
153 /* Flag saying whether common language attributes are to be supported. */
154 int lang_attribute_common = 1;
156 /* Initialize attribute tables, and make some sanity checks
157 if --enable-checking. */
162 #ifdef ENABLE_CHECKING
167 = lang_attribute_common ? c_common_attribute_table : empty_attribute_table;
168 attribute_tables[1] = lang_attribute_table;
169 attribute_tables[2] = format_attribute_table;
170 attribute_tables[3] = targetm.attribute_table;
172 #ifdef ENABLE_CHECKING
173 /* Make some sanity checks on the attribute tables. */
175 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
180 for (j = 0; attribute_tables[i][j].name != NULL; j++)
182 /* The name must not begin and end with __. */
183 const char *name = attribute_tables[i][j].name;
184 int len = strlen (name);
185 if (name[0] == '_' && name[1] == '_'
186 && name[len - 1] == '_' && name[len - 2] == '_')
188 /* The minimum and maximum lengths must be consistent. */
189 if (attribute_tables[i][j].min_length < 0)
191 if (attribute_tables[i][j].max_length != -1
192 && (attribute_tables[i][j].max_length
193 < attribute_tables[i][j].min_length))
195 /* An attribute cannot require both a DECL and a TYPE. */
196 if (attribute_tables[i][j].decl_required
197 && attribute_tables[i][j].type_required)
199 /* If an attribute requires a function type, in particular
200 it requires a type. */
201 if (attribute_tables[i][j].function_type_required
202 && !attribute_tables[i][j].type_required)
207 /* Check that each name occurs just once in each table. */
209 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
213 for (j = 0; attribute_tables[i][j].name != NULL; j++)
214 for (k = j + 1; attribute_tables[i][k].name != NULL; k++)
215 if (!strcmp (attribute_tables[i][j].name,
216 attribute_tables[i][k].name))
219 /* Check that no name occurs in more than one table. */
221 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
227 j < ((int) (sizeof (attribute_tables)
228 / sizeof (attribute_tables[0])));
230 for (k = 0; attribute_tables[i][k].name != NULL; k++)
231 for (l = 0; attribute_tables[j][l].name != NULL; l++)
232 if (!strcmp (attribute_tables[i][k].name,
233 attribute_tables[j][l].name))
238 attributes_initialized = true;
241 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
242 which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL,
243 it should be modified in place; if a TYPE, a copy should be created
244 unless ATTR_FLAG_TYPE_IN_PLACE is set in FLAGS. FLAGS gives further
245 information, in the form of a bitwise OR of flags in enum attribute_flags
246 from tree.h. Depending on these flags, some attributes may be
247 returned to be applied at a later stage (for example, to apply
248 a decl attribute to the declaration rather than to its type). If
249 ATTR_FLAG_BUILT_IN is not set and *NODE is a DECL, then also consider
250 whether there might be some default attributes to apply to this DECL;
251 if so, decl_attributes will be called recursively with those attributes
252 and ATTR_FLAG_BUILT_IN set. */
255 decl_attributes (node, attributes, flags)
256 tree *node, attributes;
260 tree returned_attrs = NULL_TREE;
262 if (!attributes_initialized)
265 (*targetm.insert_attributes) (*node, &attributes);
267 if (DECL_P (*node) && TREE_CODE (*node) == FUNCTION_DECL
268 && !(flags & (int) ATTR_FLAG_BUILT_IN))
269 insert_default_attributes (*node);
271 for (a = attributes; a; a = TREE_CHAIN (a))
273 tree name = TREE_PURPOSE (a);
274 tree args = TREE_VALUE (a);
276 const struct attribute_spec *spec = NULL;
277 bool no_add_attrs = 0;
281 i < ((int) (sizeof (attribute_tables)
282 / sizeof (attribute_tables[0])));
287 for (j = 0; attribute_tables[i][j].name != NULL; j++)
289 if (is_attribute_p (attribute_tables[i][j].name, name))
291 spec = &attribute_tables[i][j];
301 warning ("`%s' attribute directive ignored",
302 IDENTIFIER_POINTER (name));
305 else if (list_length (args) < spec->min_length
306 || (spec->max_length >= 0
307 && list_length (args) > spec->max_length))
309 error ("wrong number of arguments specified for `%s' attribute",
310 IDENTIFIER_POINTER (name));
314 if (spec->decl_required && !DECL_P (*anode))
316 if (flags & ((int) ATTR_FLAG_DECL_NEXT
317 | (int) ATTR_FLAG_FUNCTION_NEXT
318 | (int) ATTR_FLAG_ARRAY_NEXT))
320 /* Pass on this attribute to be tried again. */
321 returned_attrs = tree_cons (name, args, returned_attrs);
326 warning ("`%s' attribute does not apply to types",
327 IDENTIFIER_POINTER (name));
332 if (spec->type_required && DECL_P (*anode))
333 anode = &TREE_TYPE (*anode);
335 if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
336 && TREE_CODE (*anode) != METHOD_TYPE)
338 if (TREE_CODE (*anode) == POINTER_TYPE
339 && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
340 || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
342 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
343 *anode = build_type_copy (*anode);
344 anode = &TREE_TYPE (*anode);
346 else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
348 /* Pass on this attribute to be tried again. */
349 returned_attrs = tree_cons (name, args, returned_attrs);
353 if (TREE_CODE (*anode) != FUNCTION_TYPE
354 && TREE_CODE (*anode) != METHOD_TYPE)
356 warning ("`%s' attribute only applies to function types",
357 IDENTIFIER_POINTER (name));
362 if (spec->handler != NULL)
363 returned_attrs = chainon ((*spec->handler) (anode, name, args,
364 flags, &no_add_attrs),
372 old_attrs = DECL_ATTRIBUTES (*anode);
374 old_attrs = TYPE_ATTRIBUTES (*anode);
376 for (a = lookup_attribute (spec->name, old_attrs);
378 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
380 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
386 /* This attribute isn't already in the list. */
388 DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
389 else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
390 TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
392 *anode = build_type_attribute_variant (*anode,
393 tree_cons (name, args,
399 return returned_attrs;
402 /* Handle a "packed" attribute; arguments as in
403 struct attribute_spec.handler. */
406 handle_packed_attribute (node, name, args, flags, no_add_attrs)
409 tree args ATTRIBUTE_UNUSED;
416 if (TREE_CODE (*node) == TYPE_DECL)
417 type = &TREE_TYPE (*node);
424 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
425 *type = build_type_copy (*type);
426 TYPE_PACKED (*type) = 1;
428 else if (TREE_CODE (*node) == FIELD_DECL)
429 DECL_PACKED (*node) = 1;
430 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
431 used for DECL_REGISTER. It wouldn't mean anything anyway. */
434 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
435 *no_add_attrs = true;
441 /* Handle a "nocommon" attribute; arguments as in
442 struct attribute_spec.handler. */
445 handle_nocommon_attribute (node, name, args, flags, no_add_attrs)
448 tree args ATTRIBUTE_UNUSED;
449 int flags ATTRIBUTE_UNUSED;
452 if (TREE_CODE (*node) == VAR_DECL)
453 DECL_COMMON (*node) = 0;
456 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
457 *no_add_attrs = true;
463 /* Handle a "common" attribute; arguments as in
464 struct attribute_spec.handler. */
467 handle_common_attribute (node, name, args, flags, no_add_attrs)
470 tree args ATTRIBUTE_UNUSED;
471 int flags ATTRIBUTE_UNUSED;
474 if (TREE_CODE (*node) == VAR_DECL)
475 DECL_COMMON (*node) = 1;
478 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
479 *no_add_attrs = true;
485 /* Handle a "noreturn" attribute; arguments as in
486 struct attribute_spec.handler. */
489 handle_noreturn_attribute (node, name, args, flags, no_add_attrs)
492 tree args ATTRIBUTE_UNUSED;
493 int flags ATTRIBUTE_UNUSED;
496 tree type = TREE_TYPE (*node);
498 /* See FIXME comment in c_common_attribute_table. */
499 if (TREE_CODE (*node) == FUNCTION_DECL)
500 TREE_THIS_VOLATILE (*node) = 1;
501 else if (TREE_CODE (type) == POINTER_TYPE
502 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
505 (build_type_variant (TREE_TYPE (type),
506 TREE_READONLY (TREE_TYPE (type)), 1));
509 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
510 *no_add_attrs = true;
516 /* Handle a "noinline" attribute; arguments as in
517 struct attribute_spec.handler. */
520 handle_noinline_attribute (node, name, args, flags, no_add_attrs)
523 tree args ATTRIBUTE_UNUSED;
524 int flags ATTRIBUTE_UNUSED;
527 if (TREE_CODE (*node) == FUNCTION_DECL)
528 DECL_UNINLINABLE (*node) = 1;
531 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
532 *no_add_attrs = true;
538 /* Handle a "used" attribute; arguments as in
539 struct attribute_spec.handler. */
542 handle_used_attribute (node, name, args, flags, no_add_attrs)
545 tree args ATTRIBUTE_UNUSED;
546 int flags ATTRIBUTE_UNUSED;
549 if (TREE_CODE (*node) == FUNCTION_DECL)
550 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (*node))
551 = TREE_USED (*node) = 1;
554 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
555 *no_add_attrs = true;
561 /* Handle a "unused" attribute; arguments as in
562 struct attribute_spec.handler. */
565 handle_unused_attribute (node, name, args, flags, no_add_attrs)
568 tree args ATTRIBUTE_UNUSED;
576 if (TREE_CODE (decl) == PARM_DECL
577 || TREE_CODE (decl) == VAR_DECL
578 || TREE_CODE (decl) == FUNCTION_DECL
579 || TREE_CODE (decl) == LABEL_DECL
580 || TREE_CODE (decl) == TYPE_DECL)
581 TREE_USED (decl) = 1;
584 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
585 *no_add_attrs = true;
590 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
591 *node = build_type_copy (*node);
592 TREE_USED (*node) = 1;
598 /* Handle a "const" attribute; arguments as in
599 struct attribute_spec.handler. */
602 handle_const_attribute (node, name, args, flags, no_add_attrs)
605 tree args ATTRIBUTE_UNUSED;
606 int flags ATTRIBUTE_UNUSED;
609 tree type = TREE_TYPE (*node);
611 /* See FIXME comment on noreturn in c_common_attribute_table. */
612 if (TREE_CODE (*node) == FUNCTION_DECL)
613 TREE_READONLY (*node) = 1;
614 else if (TREE_CODE (type) == POINTER_TYPE
615 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
618 (build_type_variant (TREE_TYPE (type), 1,
619 TREE_THIS_VOLATILE (TREE_TYPE (type))));
622 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
623 *no_add_attrs = true;
629 /* Handle a "transparent_union" attribute; arguments as in
630 struct attribute_spec.handler. */
633 handle_transparent_union_attribute (node, name, args, flags, no_add_attrs)
636 tree args ATTRIBUTE_UNUSED;
640 tree decl = NULL_TREE;
647 type = &TREE_TYPE (decl);
648 is_type = TREE_CODE (*node) == TYPE_DECL;
650 else if (TYPE_P (*node))
651 type = node, is_type = 1;
654 && TREE_CODE (*type) == UNION_TYPE
656 || (TYPE_FIELDS (*type) != 0
657 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
659 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
660 *type = build_type_copy (*type);
661 TYPE_TRANSPARENT_UNION (*type) = 1;
663 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
664 && TREE_CODE (*type) == UNION_TYPE
665 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
666 DECL_TRANSPARENT_UNION (decl) = 1;
669 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
670 *no_add_attrs = true;
676 /* Handle a "constructor" attribute; arguments as in
677 struct attribute_spec.handler. */
680 handle_constructor_attribute (node, name, args, flags, no_add_attrs)
683 tree args ATTRIBUTE_UNUSED;
684 int flags ATTRIBUTE_UNUSED;
688 tree type = TREE_TYPE (decl);
690 if (TREE_CODE (decl) == FUNCTION_DECL
691 && TREE_CODE (type) == FUNCTION_TYPE
692 && decl_function_context (decl) == 0)
694 DECL_STATIC_CONSTRUCTOR (decl) = 1;
695 TREE_USED (decl) = 1;
699 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
700 *no_add_attrs = true;
706 /* Handle a "destructor" attribute; arguments as in
707 struct attribute_spec.handler. */
710 handle_destructor_attribute (node, name, args, flags, no_add_attrs)
713 tree args ATTRIBUTE_UNUSED;
714 int flags ATTRIBUTE_UNUSED;
718 tree type = TREE_TYPE (decl);
720 if (TREE_CODE (decl) == FUNCTION_DECL
721 && TREE_CODE (type) == FUNCTION_TYPE
722 && decl_function_context (decl) == 0)
724 DECL_STATIC_DESTRUCTOR (decl) = 1;
725 TREE_USED (decl) = 1;
729 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
730 *no_add_attrs = true;
736 /* Handle a "mode" attribute; arguments as in
737 struct attribute_spec.handler. */
740 handle_mode_attribute (node, name, args, flags, no_add_attrs)
744 int flags ATTRIBUTE_UNUSED;
748 tree type = TREE_TYPE (decl);
750 *no_add_attrs = true;
752 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
753 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
757 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
758 int len = strlen (p);
759 enum machine_mode mode = VOIDmode;
762 if (len > 4 && p[0] == '_' && p[1] == '_'
763 && p[len - 1] == '_' && p[len - 2] == '_')
765 char *newp = (char *) alloca (len - 1);
767 strcpy (newp, &p[2]);
768 newp[len - 4] = '\0';
772 /* Give this decl a type with the specified mode.
773 First check for the special modes. */
774 if (! strcmp (p, "byte"))
776 else if (!strcmp (p, "word"))
778 else if (! strcmp (p, "pointer"))
781 for (j = 0; j < NUM_MACHINE_MODES; j++)
782 if (!strcmp (p, GET_MODE_NAME (j)))
783 mode = (enum machine_mode) j;
785 if (mode == VOIDmode)
786 error ("unknown machine mode `%s'", p);
787 else if (0 == (typefm = type_for_mode (mode,
788 TREE_UNSIGNED (type))))
789 error ("no data type for mode `%s'", p);
792 TREE_TYPE (decl) = type = typefm;
793 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
794 if (TREE_CODE (decl) != FIELD_DECL)
795 layout_decl (decl, 0);
802 /* Handle a "section" attribute; arguments as in
803 struct attribute_spec.handler. */
806 handle_section_attribute (node, name, args, flags, no_add_attrs)
808 tree name ATTRIBUTE_UNUSED;
810 int flags ATTRIBUTE_UNUSED;
815 if (targetm.have_named_sections)
817 if ((TREE_CODE (decl) == FUNCTION_DECL
818 || TREE_CODE (decl) == VAR_DECL)
819 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
821 if (TREE_CODE (decl) == VAR_DECL
822 && current_function_decl != NULL_TREE
823 && ! TREE_STATIC (decl))
825 error_with_decl (decl,
826 "section attribute cannot be specified for local variables");
827 *no_add_attrs = true;
830 /* The decl may have already been given a section attribute
831 from a previous declaration. Ensure they match. */
832 else if (DECL_SECTION_NAME (decl) != NULL_TREE
833 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
834 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
836 error_with_decl (*node,
837 "section of `%s' conflicts with previous declaration");
838 *no_add_attrs = true;
841 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
845 error_with_decl (*node,
846 "section attribute not allowed for `%s'");
847 *no_add_attrs = true;
852 error_with_decl (*node,
853 "section attributes are not supported for this target");
854 *no_add_attrs = true;
860 /* Handle a "aligned" attribute; arguments as in
861 struct attribute_spec.handler. */
864 handle_aligned_attribute (node, name, args, flags, no_add_attrs)
866 tree name ATTRIBUTE_UNUSED;
871 tree decl = NULL_TREE;
874 tree align_expr = (args ? TREE_VALUE (args)
875 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
881 type = &TREE_TYPE (decl);
882 is_type = TREE_CODE (*node) == TYPE_DECL;
884 else if (TYPE_P (*node))
885 type = node, is_type = 1;
887 /* Strip any NOPs of any kind. */
888 while (TREE_CODE (align_expr) == NOP_EXPR
889 || TREE_CODE (align_expr) == CONVERT_EXPR
890 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
891 align_expr = TREE_OPERAND (align_expr, 0);
893 if (TREE_CODE (align_expr) != INTEGER_CST)
895 error ("requested alignment is not a constant");
896 *no_add_attrs = true;
898 else if ((i = tree_log2 (align_expr)) == -1)
900 error ("requested alignment is not a power of 2");
901 *no_add_attrs = true;
903 else if (i > HOST_BITS_PER_INT - 2)
905 error ("requested alignment is too large");
906 *no_add_attrs = true;
910 /* If we have a TYPE_DECL, then copy the type, so that we
911 don't accidentally modify a builtin type. See pushdecl. */
912 if (decl && TREE_TYPE (decl) != error_mark_node
913 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
915 tree tt = TREE_TYPE (decl);
916 *type = build_type_copy (*type);
917 DECL_ORIGINAL_TYPE (decl) = tt;
918 TYPE_NAME (*type) = decl;
919 TREE_USED (*type) = TREE_USED (decl);
920 TREE_TYPE (decl) = *type;
922 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
923 *type = build_type_copy (*type);
925 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
926 TYPE_USER_ALIGN (*type) = 1;
928 else if (TREE_CODE (decl) != VAR_DECL
929 && TREE_CODE (decl) != FIELD_DECL)
931 error_with_decl (decl,
932 "alignment may not be specified for `%s'");
933 *no_add_attrs = true;
937 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
938 DECL_USER_ALIGN (decl) = 1;
944 /* Handle a "weak" attribute; arguments as in
945 struct attribute_spec.handler. */
948 handle_weak_attribute (node, name, args, flags, no_add_attrs)
950 tree name ATTRIBUTE_UNUSED;
951 tree args ATTRIBUTE_UNUSED;
952 int flags ATTRIBUTE_UNUSED;
953 bool *no_add_attrs ATTRIBUTE_UNUSED;
955 declare_weak (*node);
960 /* Handle an "alias" attribute; arguments as in
961 struct attribute_spec.handler. */
964 handle_alias_attribute (node, name, args, flags, no_add_attrs)
968 int flags ATTRIBUTE_UNUSED;
973 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
974 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
976 error_with_decl (decl,
977 "`%s' defined both normally and as an alias");
978 *no_add_attrs = true;
980 else if (decl_function_context (decl) == 0)
984 id = TREE_VALUE (args);
985 if (TREE_CODE (id) != STRING_CST)
987 error ("alias arg not a string");
988 *no_add_attrs = true;
991 id = get_identifier (TREE_STRING_POINTER (id));
992 /* This counts as a use of the object pointed to. */
995 if (TREE_CODE (decl) == FUNCTION_DECL)
996 DECL_INITIAL (decl) = error_mark_node;
998 DECL_EXTERNAL (decl) = 0;
999 assemble_alias (decl, id);
1003 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1004 *no_add_attrs = true;
1010 /* Handle a "no_instrument_function" attribute; arguments as in
1011 struct attribute_spec.handler. */
1014 handle_no_instrument_function_attribute (node, name, args, flags, no_add_attrs)
1017 tree args ATTRIBUTE_UNUSED;
1018 int flags ATTRIBUTE_UNUSED;
1023 if (TREE_CODE (decl) != FUNCTION_DECL)
1025 error_with_decl (decl,
1026 "`%s' attribute applies only to functions",
1027 IDENTIFIER_POINTER (name));
1028 *no_add_attrs = true;
1030 else if (DECL_INITIAL (decl))
1032 error_with_decl (decl,
1033 "can't set `%s' attribute after definition",
1034 IDENTIFIER_POINTER (name));
1035 *no_add_attrs = true;
1038 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1043 /* Handle a "malloc" attribute; arguments as in
1044 struct attribute_spec.handler. */
1047 handle_malloc_attribute (node, name, args, flags, no_add_attrs)
1050 tree args ATTRIBUTE_UNUSED;
1051 int flags ATTRIBUTE_UNUSED;
1054 if (TREE_CODE (*node) == FUNCTION_DECL)
1055 DECL_IS_MALLOC (*node) = 1;
1056 /* ??? TODO: Support types. */
1059 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1060 *no_add_attrs = true;
1066 /* Handle a "no_limit_stack" attribute; arguments as in
1067 struct attribute_spec.handler. */
1070 handle_no_limit_stack_attribute (node, name, args, flags, no_add_attrs)
1073 tree args ATTRIBUTE_UNUSED;
1074 int flags ATTRIBUTE_UNUSED;
1079 if (TREE_CODE (decl) != FUNCTION_DECL)
1081 error_with_decl (decl,
1082 "`%s' attribute applies only to functions",
1083 IDENTIFIER_POINTER (name));
1084 *no_add_attrs = true;
1086 else if (DECL_INITIAL (decl))
1088 error_with_decl (decl,
1089 "can't set `%s' attribute after definition",
1090 IDENTIFIER_POINTER (name));
1091 *no_add_attrs = true;
1094 DECL_NO_LIMIT_STACK (decl) = 1;
1099 /* Handle a "pure" attribute; arguments as in
1100 struct attribute_spec.handler. */
1103 handle_pure_attribute (node, name, args, flags, no_add_attrs)
1106 tree args ATTRIBUTE_UNUSED;
1107 int flags ATTRIBUTE_UNUSED;
1110 if (TREE_CODE (*node) == FUNCTION_DECL)
1111 DECL_IS_PURE (*node) = 1;
1112 /* ??? TODO: Support types. */
1115 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1116 *no_add_attrs = true;
1122 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1123 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1125 The head of the declspec list is stored in DECLSPECS.
1126 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1128 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1129 the list elements. We drop the containing TREE_LIST nodes and link the
1130 resulting attributes together the way decl_attributes expects them. */
1133 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1135 tree *declspecs, *prefix_attributes;
1137 tree t, s, a, next, specs, attrs;
1139 /* This can happen after an __extension__ in pedantic mode. */
1140 if (specs_attrs != NULL_TREE
1141 && TREE_CODE (specs_attrs) == INTEGER_CST)
1143 *declspecs = NULL_TREE;
1144 *prefix_attributes = NULL_TREE;
1148 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1149 if (specs_attrs != NULL_TREE
1150 && TREE_CODE (specs_attrs) != TREE_LIST)
1152 *declspecs = specs_attrs;
1153 *prefix_attributes = NULL_TREE;
1157 /* Remember to keep the lists in the same order, element-wise. */
1159 specs = s = NULL_TREE;
1160 attrs = a = NULL_TREE;
1161 for (t = specs_attrs; t; t = next)
1163 next = TREE_CHAIN (t);
1164 /* Declspecs have a non-NULL TREE_VALUE. */
1165 if (TREE_VALUE (t) != NULL_TREE)
1167 if (specs == NULL_TREE)
1175 /* The TREE_PURPOSE may also be empty in the case of
1176 __attribute__(()). */
1177 else if (TREE_PURPOSE (t) != NULL_TREE)
1179 if (attrs == NULL_TREE)
1180 attrs = a = TREE_PURPOSE (t);
1183 TREE_CHAIN (a) = TREE_PURPOSE (t);
1184 a = TREE_PURPOSE (t);
1186 /* More attrs can be linked here, move A to the end. */
1187 while (TREE_CHAIN (a) != NULL_TREE)
1192 /* Terminate the lists. */
1194 TREE_CHAIN (s) = NULL_TREE;
1196 TREE_CHAIN (a) = NULL_TREE;
1200 *prefix_attributes = attrs;
1203 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1204 This function is used by the parser when a rule will accept attributes
1205 in a particular position, but we don't want to support that just yet.
1207 A warning is issued for every ignored attribute. */
1210 strip_attrs (specs_attrs)
1215 split_specs_attrs (specs_attrs, &specs, &attrs);
1219 warning ("`%s' attribute ignored",
1220 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1221 attrs = TREE_CHAIN (attrs);