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_unused_attribute PARAMS ((tree *, tree, tree, int,
54 static tree handle_const_attribute PARAMS ((tree *, tree, tree, int,
56 static tree handle_transparent_union_attribute PARAMS ((tree *, tree, tree,
58 static tree handle_constructor_attribute PARAMS ((tree *, tree, tree, int,
60 static tree handle_destructor_attribute PARAMS ((tree *, tree, tree, int,
62 static tree handle_mode_attribute PARAMS ((tree *, tree, tree, int,
64 static tree handle_section_attribute PARAMS ((tree *, tree, tree, int,
66 static tree handle_aligned_attribute PARAMS ((tree *, tree, tree, int,
68 static tree handle_weak_attribute PARAMS ((tree *, tree, tree, int,
70 static tree handle_alias_attribute PARAMS ((tree *, tree, tree, int,
72 static tree handle_no_instrument_function_attribute PARAMS ((tree *, tree,
75 static tree handle_no_check_memory_usage_attribute PARAMS ((tree *, tree, tree,
77 static tree handle_malloc_attribute PARAMS ((tree *, tree, tree, int,
79 static tree handle_no_limit_stack_attribute PARAMS ((tree *, tree, tree, int,
81 static tree handle_pure_attribute PARAMS ((tree *, tree, tree, int,
84 /* Table of machine-independent attributes common to all C-like languages. */
85 static const struct attribute_spec c_common_attribute_table[] =
87 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
88 { "packed", 0, 0, false, false, false,
89 handle_packed_attribute },
90 { "nocommon", 0, 0, true, false, false,
91 handle_nocommon_attribute },
92 { "common", 0, 0, true, false, false,
93 handle_common_attribute },
94 /* FIXME: logically, noreturn attributes should be listed as
95 "false, true, true" and apply to function types. But implementing this
96 would require all the places in the compiler that use TREE_THIS_VOLATILE
97 on a decl to identify non-returning functions to be located and fixed
98 to check the function type instead. */
99 { "noreturn", 0, 0, true, false, false,
100 handle_noreturn_attribute },
101 { "volatile", 0, 0, true, false, false,
102 handle_noreturn_attribute },
103 { "unused", 0, 0, false, false, false,
104 handle_unused_attribute },
105 /* The same comments as for noreturn attributes apply to const ones. */
106 { "const", 0, 0, true, false, false,
107 handle_const_attribute },
108 { "transparent_union", 0, 0, false, false, false,
109 handle_transparent_union_attribute },
110 { "constructor", 0, 0, true, false, false,
111 handle_constructor_attribute },
112 { "destructor", 0, 0, true, false, false,
113 handle_destructor_attribute },
114 { "mode", 1, 1, true, false, false,
115 handle_mode_attribute },
116 { "section", 1, 1, true, false, false,
117 handle_section_attribute },
118 { "aligned", 0, 1, false, false, false,
119 handle_aligned_attribute },
120 { "weak", 0, 0, true, false, false,
121 handle_weak_attribute },
122 { "alias", 1, 1, true, false, false,
123 handle_alias_attribute },
124 { "no_instrument_function", 0, 0, true, false, false,
125 handle_no_instrument_function_attribute },
126 { "no_check_memory_usage", 0, 0, true, false, false,
127 handle_no_check_memory_usage_attribute },
128 { "malloc", 0, 0, true, false, false,
129 handle_malloc_attribute },
130 { "no_stack_limit", 0, 0, true, false, false,
131 handle_no_limit_stack_attribute },
132 { "pure", 0, 0, true, false, false,
133 handle_pure_attribute },
134 { NULL, 0, 0, false, false, false, NULL }
137 /* Default empty table of attributes. */
138 static const struct attribute_spec empty_attribute_table[] =
140 { NULL, 0, 0, false, false, false, NULL }
143 /* Table of machine-independent attributes for checking formats, if used. */
144 const struct attribute_spec *format_attribute_table = empty_attribute_table;
146 /* Table of machine-independent attributes for a particular language. */
147 const struct attribute_spec *lang_attribute_table = empty_attribute_table;
149 /* Flag saying whether common language attributes are to be supported. */
150 int lang_attribute_common = 1;
152 /* Initialize attribute tables, and make some sanity checks
153 if --enable-checking. */
158 #ifdef ENABLE_CHECKING
163 = lang_attribute_common ? c_common_attribute_table : empty_attribute_table;
164 attribute_tables[1] = lang_attribute_table;
165 attribute_tables[2] = format_attribute_table;
166 attribute_tables[3] = targetm.attribute_table;
168 #ifdef ENABLE_CHECKING
169 /* Make some sanity checks on the attribute tables. */
171 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
176 for (j = 0; attribute_tables[i][j].name != NULL; j++)
178 /* The name must not begin and end with __. */
179 const char *name = attribute_tables[i][j].name;
180 int len = strlen (name);
181 if (name[0] == '_' && name[1] == '_'
182 && name[len - 1] == '_' && name[len - 2] == '_')
184 /* The minimum and maximum lengths must be consistent. */
185 if (attribute_tables[i][j].min_length < 0)
187 if (attribute_tables[i][j].max_length != -1
188 && (attribute_tables[i][j].max_length
189 < attribute_tables[i][j].min_length))
191 /* An attribute cannot require both a DECL and a TYPE. */
192 if (attribute_tables[i][j].decl_required
193 && attribute_tables[i][j].type_required)
195 /* If an attribute requires a function type, in particular
196 it requires a type. */
197 if (attribute_tables[i][j].function_type_required
198 && !attribute_tables[i][j].type_required)
203 /* Check that each name occurs just once in each table. */
205 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
209 for (j = 0; attribute_tables[i][j].name != NULL; j++)
210 for (k = j + 1; attribute_tables[i][k].name != NULL; k++)
211 if (!strcmp (attribute_tables[i][j].name,
212 attribute_tables[i][k].name))
215 /* Check that no name occurs in more than one table. */
217 i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
223 j < ((int) (sizeof (attribute_tables)
224 / sizeof (attribute_tables[0])));
226 for (k = 0; attribute_tables[i][k].name != NULL; k++)
227 for (l = 0; attribute_tables[j][l].name != NULL; l++)
228 if (!strcmp (attribute_tables[i][k].name,
229 attribute_tables[j][l].name))
234 attributes_initialized = true;
237 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
238 which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL,
239 it should be modified in place; if a TYPE, a copy should be created
240 unless ATTR_FLAG_TYPE_IN_PLACE is set in FLAGS. FLAGS gives further
241 information, in the form of a bitwise OR of flags in enum attribute_flags
242 from tree.h. Depending on these flags, some attributes may be
243 returned to be applied at a later stage (for example, to apply
244 a decl attribute to the declaration rather than to its type). If
245 ATTR_FLAG_BUILT_IN is not set and *NODE is a DECL, then also consider
246 whether there might be some default attributes to apply to this DECL;
247 if so, decl_attributes will be called recusrively with those attributes
248 and ATTR_FLAG_BUILT_IN set. */
251 decl_attributes (node, attributes, flags)
252 tree *node, attributes;
256 tree returned_attrs = NULL_TREE;
258 if (!attributes_initialized)
261 (*targetm.insert_attributes) (*node, &attributes);
263 if (DECL_P (*node) && TREE_CODE (*node) == FUNCTION_DECL
264 && !(flags & (int) ATTR_FLAG_BUILT_IN))
265 insert_default_attributes (*node);
267 for (a = attributes; a; a = TREE_CHAIN (a))
269 tree name = TREE_PURPOSE (a);
270 tree args = TREE_VALUE (a);
272 const struct attribute_spec *spec = NULL;
273 bool no_add_attrs = 0;
277 i < ((int) (sizeof (attribute_tables)
278 / sizeof (attribute_tables[0])));
283 for (j = 0; attribute_tables[i][j].name != NULL; j++)
285 if (is_attribute_p (attribute_tables[i][j].name, name))
287 spec = &attribute_tables[i][j];
297 warning ("`%s' attribute directive ignored",
298 IDENTIFIER_POINTER (name));
301 else if (list_length (args) < spec->min_length
302 || (spec->max_length >= 0
303 && list_length (args) > spec->max_length))
305 error ("wrong number of arguments specified for `%s' attribute",
306 IDENTIFIER_POINTER (name));
310 if (spec->decl_required && !DECL_P (*anode))
312 if (flags & ((int) ATTR_FLAG_DECL_NEXT
313 | (int) ATTR_FLAG_FUNCTION_NEXT
314 | (int) ATTR_FLAG_ARRAY_NEXT))
316 /* Pass on this attribute to be tried again. */
317 returned_attrs = tree_cons (name, args, returned_attrs);
322 warning ("`%s' attribute does not apply to types",
323 IDENTIFIER_POINTER (name));
328 if (spec->type_required && DECL_P (*anode))
329 anode = &TREE_TYPE (*anode);
331 if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
332 && TREE_CODE (*anode) != METHOD_TYPE)
334 if (TREE_CODE (*anode) == POINTER_TYPE
335 && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
336 || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
338 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
339 *anode = build_type_copy (*anode);
340 anode = &TREE_TYPE (*anode);
342 else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
344 /* Pass on this attribute to be tried again. */
345 returned_attrs = tree_cons (name, args, returned_attrs);
349 if (TREE_CODE (*anode) != FUNCTION_TYPE
350 && TREE_CODE (*anode) != METHOD_TYPE)
352 warning ("`%s' attribute only applies to function types",
353 IDENTIFIER_POINTER (name));
358 if (spec->handler != NULL)
359 returned_attrs = chainon ((*spec->handler) (anode, name, args,
360 flags, &no_add_attrs),
368 old_attrs = DECL_ATTRIBUTES (*anode);
370 old_attrs = TYPE_ATTRIBUTES (*anode);
372 for (a = lookup_attribute (spec->name, old_attrs);
374 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
376 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
382 /* This attribute isn't already in the list. */
384 DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
385 else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
386 TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
388 *anode = build_type_attribute_variant (*anode,
389 tree_cons (name, args,
395 return returned_attrs;
398 /* Handle a "packed" attribute; arguments as in
399 struct attribute_spec.handler. */
402 handle_packed_attribute (node, name, args, flags, no_add_attrs)
405 tree args ATTRIBUTE_UNUSED;
412 if (TREE_CODE (*node) == TYPE_DECL)
413 type = &TREE_TYPE (*node);
420 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
421 *type = build_type_copy (*type);
422 TYPE_PACKED (*type) = 1;
424 else if (TREE_CODE (*node) == FIELD_DECL)
425 DECL_PACKED (*node) = 1;
426 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
427 used for DECL_REGISTER. It wouldn't mean anything anyway. */
430 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
431 *no_add_attrs = true;
437 /* Handle a "nocommon" attribute; arguments as in
438 struct attribute_spec.handler. */
441 handle_nocommon_attribute (node, name, args, flags, no_add_attrs)
444 tree args ATTRIBUTE_UNUSED;
445 int flags ATTRIBUTE_UNUSED;
448 if (TREE_CODE (*node) == VAR_DECL)
449 DECL_COMMON (*node) = 0;
452 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
453 *no_add_attrs = true;
459 /* Handle a "common" attribute; arguments as in
460 struct attribute_spec.handler. */
463 handle_common_attribute (node, name, args, flags, no_add_attrs)
466 tree args ATTRIBUTE_UNUSED;
467 int flags ATTRIBUTE_UNUSED;
470 if (TREE_CODE (*node) == VAR_DECL)
471 DECL_COMMON (*node) = 1;
474 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
475 *no_add_attrs = true;
481 /* Handle a "noreturn" attribute; arguments as in
482 struct attribute_spec.handler. */
485 handle_noreturn_attribute (node, name, args, flags, no_add_attrs)
488 tree args ATTRIBUTE_UNUSED;
489 int flags ATTRIBUTE_UNUSED;
492 tree type = TREE_TYPE (*node);
494 /* See FIXME comment in c_common_attribute_table. */
495 if (TREE_CODE (*node) == FUNCTION_DECL)
496 TREE_THIS_VOLATILE (*node) = 1;
497 else if (TREE_CODE (type) == POINTER_TYPE
498 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
501 (build_type_variant (TREE_TYPE (type),
502 TREE_READONLY (TREE_TYPE (type)), 1));
505 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
506 *no_add_attrs = true;
512 /* Handle a "unused" attribute; arguments as in
513 struct attribute_spec.handler. */
516 handle_unused_attribute (node, name, args, flags, no_add_attrs)
519 tree args ATTRIBUTE_UNUSED;
527 if (TREE_CODE (decl) == PARM_DECL
528 || TREE_CODE (decl) == VAR_DECL
529 || TREE_CODE (decl) == FUNCTION_DECL
530 || TREE_CODE (decl) == LABEL_DECL
531 || TREE_CODE (decl) == TYPE_DECL)
532 TREE_USED (decl) = 1;
535 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
536 *no_add_attrs = true;
541 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
542 *node = build_type_copy (*node);
543 TREE_USED (*node) = 1;
549 /* Handle a "const" attribute; arguments as in
550 struct attribute_spec.handler. */
553 handle_const_attribute (node, name, args, flags, no_add_attrs)
556 tree args ATTRIBUTE_UNUSED;
557 int flags ATTRIBUTE_UNUSED;
560 tree type = TREE_TYPE (*node);
562 /* See FIXME comment on noreturn in c_common_attribute_table. */
563 if (TREE_CODE (*node) == FUNCTION_DECL)
564 TREE_READONLY (*node) = 1;
565 else if (TREE_CODE (type) == POINTER_TYPE
566 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
569 (build_type_variant (TREE_TYPE (type), 1,
570 TREE_THIS_VOLATILE (TREE_TYPE (type))));
573 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
574 *no_add_attrs = true;
580 /* Handle a "transparent_union" attribute; arguments as in
581 struct attribute_spec.handler. */
584 handle_transparent_union_attribute (node, name, args, flags, no_add_attrs)
587 tree args ATTRIBUTE_UNUSED;
591 tree decl = NULL_TREE;
598 type = &TREE_TYPE (decl);
599 is_type = TREE_CODE (*node) == TYPE_DECL;
601 else if (TYPE_P (*node))
602 type = node, is_type = 1;
605 && TREE_CODE (*type) == UNION_TYPE
607 || (TYPE_FIELDS (*type) != 0
608 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
610 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
611 *type = build_type_copy (*type);
612 TYPE_TRANSPARENT_UNION (*type) = 1;
614 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
615 && TREE_CODE (*type) == UNION_TYPE
616 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
617 DECL_TRANSPARENT_UNION (decl) = 1;
620 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
621 *no_add_attrs = true;
627 /* Handle a "constructor" attribute; arguments as in
628 struct attribute_spec.handler. */
631 handle_constructor_attribute (node, name, args, flags, no_add_attrs)
634 tree args ATTRIBUTE_UNUSED;
635 int flags ATTRIBUTE_UNUSED;
639 tree type = TREE_TYPE (decl);
641 if (TREE_CODE (decl) == FUNCTION_DECL
642 && TREE_CODE (type) == FUNCTION_TYPE
643 && decl_function_context (decl) == 0)
645 DECL_STATIC_CONSTRUCTOR (decl) = 1;
646 TREE_USED (decl) = 1;
650 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
651 *no_add_attrs = true;
657 /* Handle a "destructor" attribute; arguments as in
658 struct attribute_spec.handler. */
661 handle_destructor_attribute (node, name, args, flags, no_add_attrs)
664 tree args ATTRIBUTE_UNUSED;
665 int flags ATTRIBUTE_UNUSED;
669 tree type = TREE_TYPE (decl);
671 if (TREE_CODE (decl) == FUNCTION_DECL
672 && TREE_CODE (type) == FUNCTION_TYPE
673 && decl_function_context (decl) == 0)
675 DECL_STATIC_DESTRUCTOR (decl) = 1;
676 TREE_USED (decl) = 1;
680 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
681 *no_add_attrs = true;
687 /* Handle a "mode" attribute; arguments as in
688 struct attribute_spec.handler. */
691 handle_mode_attribute (node, name, args, flags, no_add_attrs)
695 int flags ATTRIBUTE_UNUSED;
699 tree type = TREE_TYPE (decl);
701 *no_add_attrs = true;
703 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
704 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
708 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
709 int len = strlen (p);
710 enum machine_mode mode = VOIDmode;
713 if (len > 4 && p[0] == '_' && p[1] == '_'
714 && p[len - 1] == '_' && p[len - 2] == '_')
716 char *newp = (char *) alloca (len - 1);
718 strcpy (newp, &p[2]);
719 newp[len - 4] = '\0';
723 /* Give this decl a type with the specified mode.
724 First check for the special modes. */
725 if (! strcmp (p, "byte"))
727 else if (!strcmp (p, "word"))
729 else if (! strcmp (p, "pointer"))
732 for (j = 0; j < NUM_MACHINE_MODES; j++)
733 if (!strcmp (p, GET_MODE_NAME (j)))
734 mode = (enum machine_mode) j;
736 if (mode == VOIDmode)
737 error ("unknown machine mode `%s'", p);
738 else if (0 == (typefm = type_for_mode (mode,
739 TREE_UNSIGNED (type))))
740 error ("no data type for mode `%s'", p);
743 TREE_TYPE (decl) = type = typefm;
744 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
745 if (TREE_CODE (decl) != FIELD_DECL)
746 layout_decl (decl, 0);
753 /* Handle a "section" attribute; arguments as in
754 struct attribute_spec.handler. */
757 handle_section_attribute (node, name, args, flags, no_add_attrs)
759 tree name ATTRIBUTE_UNUSED;
761 int flags ATTRIBUTE_UNUSED;
766 if (targetm.have_named_sections)
768 if ((TREE_CODE (decl) == FUNCTION_DECL
769 || TREE_CODE (decl) == VAR_DECL)
770 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
772 if (TREE_CODE (decl) == VAR_DECL
773 && current_function_decl != NULL_TREE
774 && ! TREE_STATIC (decl))
776 error_with_decl (decl,
777 "section attribute cannot be specified for local variables");
778 *no_add_attrs = true;
781 /* The decl may have already been given a section attribute
782 from a previous declaration. Ensure they match. */
783 else if (DECL_SECTION_NAME (decl) != NULL_TREE
784 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
785 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
787 error_with_decl (*node,
788 "section of `%s' conflicts with previous declaration");
789 *no_add_attrs = true;
792 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
796 error_with_decl (*node,
797 "section attribute not allowed for `%s'");
798 *no_add_attrs = true;
803 error_with_decl (*node,
804 "section attributes are not supported for this target");
805 *no_add_attrs = true;
811 /* Handle a "aligned" attribute; arguments as in
812 struct attribute_spec.handler. */
815 handle_aligned_attribute (node, name, args, flags, no_add_attrs)
817 tree name ATTRIBUTE_UNUSED;
822 tree decl = NULL_TREE;
825 tree align_expr = (args ? TREE_VALUE (args)
826 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
832 type = &TREE_TYPE (decl);
833 is_type = TREE_CODE (*node) == TYPE_DECL;
835 else if (TYPE_P (*node))
836 type = node, is_type = 1;
838 /* Strip any NOPs of any kind. */
839 while (TREE_CODE (align_expr) == NOP_EXPR
840 || TREE_CODE (align_expr) == CONVERT_EXPR
841 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
842 align_expr = TREE_OPERAND (align_expr, 0);
844 if (TREE_CODE (align_expr) != INTEGER_CST)
846 error ("requested alignment is not a constant");
847 *no_add_attrs = true;
849 else if ((i = tree_log2 (align_expr)) == -1)
851 error ("requested alignment is not a power of 2");
852 *no_add_attrs = true;
854 else if (i > HOST_BITS_PER_INT - 2)
856 error ("requested alignment is too large");
857 *no_add_attrs = true;
861 /* If we have a TYPE_DECL, then copy the type, so that we
862 don't accidentally modify a builtin type. See pushdecl. */
863 if (decl && TREE_TYPE (decl) != error_mark_node
864 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
866 tree tt = TREE_TYPE (decl);
867 *type = build_type_copy (*type);
868 DECL_ORIGINAL_TYPE (decl) = tt;
869 TYPE_NAME (*type) = decl;
870 TREE_USED (*type) = TREE_USED (decl);
871 TREE_TYPE (decl) = *type;
873 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
874 *type = build_type_copy (*type);
876 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
877 TYPE_USER_ALIGN (*type) = 1;
879 else if (TREE_CODE (decl) != VAR_DECL
880 && TREE_CODE (decl) != FIELD_DECL)
882 error_with_decl (decl,
883 "alignment may not be specified for `%s'");
884 *no_add_attrs = true;
888 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
889 DECL_USER_ALIGN (decl) = 1;
895 /* Handle a "weak" attribute; arguments as in
896 struct attribute_spec.handler. */
899 handle_weak_attribute (node, name, args, flags, no_add_attrs)
901 tree name ATTRIBUTE_UNUSED;
902 tree args ATTRIBUTE_UNUSED;
903 int flags ATTRIBUTE_UNUSED;
904 bool *no_add_attrs ATTRIBUTE_UNUSED;
906 declare_weak (*node);
911 /* Handle an "alias" attribute; arguments as in
912 struct attribute_spec.handler. */
915 handle_alias_attribute (node, name, args, flags, no_add_attrs)
919 int flags ATTRIBUTE_UNUSED;
924 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
925 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
927 error_with_decl (decl,
928 "`%s' defined both normally and as an alias");
929 *no_add_attrs = true;
931 else if (decl_function_context (decl) == 0)
935 id = TREE_VALUE (args);
936 if (TREE_CODE (id) != STRING_CST)
938 error ("alias arg not a string");
939 *no_add_attrs = true;
942 id = get_identifier (TREE_STRING_POINTER (id));
943 /* This counts as a use of the object pointed to. */
946 if (TREE_CODE (decl) == FUNCTION_DECL)
947 DECL_INITIAL (decl) = error_mark_node;
949 DECL_EXTERNAL (decl) = 0;
950 assemble_alias (decl, id);
954 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
955 *no_add_attrs = true;
961 /* Handle a "no_instrument_function" attribute; arguments as in
962 struct attribute_spec.handler. */
965 handle_no_instrument_function_attribute (node, name, args, flags, no_add_attrs)
968 tree args ATTRIBUTE_UNUSED;
969 int flags ATTRIBUTE_UNUSED;
974 if (TREE_CODE (decl) != FUNCTION_DECL)
976 error_with_decl (decl,
977 "`%s' attribute applies only to functions",
978 IDENTIFIER_POINTER (name));
979 *no_add_attrs = true;
981 else if (DECL_INITIAL (decl))
983 error_with_decl (decl,
984 "can't set `%s' attribute after definition",
985 IDENTIFIER_POINTER (name));
986 *no_add_attrs = true;
989 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
994 /* Handle a "no_check_memory_usage" attribute; arguments as in
995 struct attribute_spec.handler. */
998 handle_no_check_memory_usage_attribute (node, name, args, flags, no_add_attrs)
1001 tree args ATTRIBUTE_UNUSED;
1002 int flags ATTRIBUTE_UNUSED;
1007 if (TREE_CODE (decl) != FUNCTION_DECL)
1009 error_with_decl (decl,
1010 "`%s' attribute applies only to functions",
1011 IDENTIFIER_POINTER (name));
1012 *no_add_attrs = true;
1014 else if (DECL_INITIAL (decl))
1016 error_with_decl (decl,
1017 "can't set `%s' attribute after definition",
1018 IDENTIFIER_POINTER (name));
1019 *no_add_attrs = true;
1022 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1027 /* Handle a "malloc" attribute; arguments as in
1028 struct attribute_spec.handler. */
1031 handle_malloc_attribute (node, name, args, flags, no_add_attrs)
1034 tree args ATTRIBUTE_UNUSED;
1035 int flags ATTRIBUTE_UNUSED;
1038 if (TREE_CODE (*node) == FUNCTION_DECL)
1039 DECL_IS_MALLOC (*node) = 1;
1040 /* ??? TODO: Support types. */
1043 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1044 *no_add_attrs = true;
1050 /* Handle a "no_limit_stack" attribute; arguments as in
1051 struct attribute_spec.handler. */
1054 handle_no_limit_stack_attribute (node, name, args, flags, no_add_attrs)
1057 tree args ATTRIBUTE_UNUSED;
1058 int flags ATTRIBUTE_UNUSED;
1063 if (TREE_CODE (decl) != FUNCTION_DECL)
1065 error_with_decl (decl,
1066 "`%s' attribute applies only to functions",
1067 IDENTIFIER_POINTER (name));
1068 *no_add_attrs = true;
1070 else if (DECL_INITIAL (decl))
1072 error_with_decl (decl,
1073 "can't set `%s' attribute after definition",
1074 IDENTIFIER_POINTER (name));
1075 *no_add_attrs = true;
1078 DECL_NO_LIMIT_STACK (decl) = 1;
1083 /* Handle a "pure" attribute; arguments as in
1084 struct attribute_spec.handler. */
1087 handle_pure_attribute (node, name, args, flags, no_add_attrs)
1090 tree args ATTRIBUTE_UNUSED;
1091 int flags ATTRIBUTE_UNUSED;
1094 if (TREE_CODE (*node) == FUNCTION_DECL)
1095 DECL_IS_PURE (*node) = 1;
1096 /* ??? TODO: Support types. */
1099 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1100 *no_add_attrs = true;
1106 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1107 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1109 The head of the declspec list is stored in DECLSPECS.
1110 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1112 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1113 the list elements. We drop the containing TREE_LIST nodes and link the
1114 resulting attributes together the way decl_attributes expects them. */
1117 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1119 tree *declspecs, *prefix_attributes;
1121 tree t, s, a, next, specs, attrs;
1123 /* This can happen after an __extension__ in pedantic mode. */
1124 if (specs_attrs != NULL_TREE
1125 && TREE_CODE (specs_attrs) == INTEGER_CST)
1127 *declspecs = NULL_TREE;
1128 *prefix_attributes = NULL_TREE;
1132 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1133 if (specs_attrs != NULL_TREE
1134 && TREE_CODE (specs_attrs) != TREE_LIST)
1136 *declspecs = specs_attrs;
1137 *prefix_attributes = NULL_TREE;
1141 /* Remember to keep the lists in the same order, element-wise. */
1143 specs = s = NULL_TREE;
1144 attrs = a = NULL_TREE;
1145 for (t = specs_attrs; t; t = next)
1147 next = TREE_CHAIN (t);
1148 /* Declspecs have a non-NULL TREE_VALUE. */
1149 if (TREE_VALUE (t) != NULL_TREE)
1151 if (specs == NULL_TREE)
1159 /* The TREE_PURPOSE may also be empty in the case of
1160 __attribute__(()). */
1161 else if (TREE_PURPOSE (t) != NULL_TREE)
1163 if (attrs == NULL_TREE)
1164 attrs = a = TREE_PURPOSE (t);
1167 TREE_CHAIN (a) = TREE_PURPOSE (t);
1168 a = TREE_PURPOSE (t);
1170 /* More attrs can be linked here, move A to the end. */
1171 while (TREE_CHAIN (a) != NULL_TREE)
1176 /* Terminate the lists. */
1178 TREE_CHAIN (s) = NULL_TREE;
1180 TREE_CHAIN (a) = NULL_TREE;
1184 *prefix_attributes = attrs;
1187 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1188 This function is used by the parser when a rule will accept attributes
1189 in a particular position, but we don't want to support that just yet.
1191 A warning is issued for every ignored attribute. */
1194 strip_attrs (specs_attrs)
1199 split_specs_attrs (specs_attrs, &specs, &attrs);
1203 warning ("`%s' attribute ignored",
1204 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1205 attrs = TREE_CHAIN (attrs);