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). */
247 decl_attributes (node, attributes, flags)
248 tree *node, attributes;
252 tree returned_attrs = NULL_TREE;
254 if (!attributes_initialized)
257 (*targetm.insert_attributes) (*node, &attributes);
259 for (a = attributes; a; a = TREE_CHAIN (a))
261 tree name = TREE_PURPOSE (a);
262 tree args = TREE_VALUE (a);
264 const struct attribute_spec *spec = NULL;
265 bool no_add_attrs = 0;
269 i < ((int) (sizeof (attribute_tables)
270 / sizeof (attribute_tables[0])));
275 for (j = 0; attribute_tables[i][j].name != NULL; j++)
277 if (is_attribute_p (attribute_tables[i][j].name, name))
279 spec = &attribute_tables[i][j];
289 warning ("`%s' attribute directive ignored",
290 IDENTIFIER_POINTER (name));
293 else if (list_length (args) < spec->min_length
294 || (spec->max_length >= 0
295 && list_length (args) > spec->max_length))
297 error ("wrong number of arguments specified for `%s' attribute",
298 IDENTIFIER_POINTER (name));
302 if (spec->decl_required && !DECL_P (*anode))
304 if (flags & ((int) ATTR_FLAG_DECL_NEXT
305 | (int) ATTR_FLAG_FUNCTION_NEXT
306 | (int) ATTR_FLAG_ARRAY_NEXT))
308 /* Pass on this attribute to be tried again. */
309 returned_attrs = tree_cons (name, args, returned_attrs);
314 warning ("`%s' attribute does not apply to types",
315 IDENTIFIER_POINTER (name));
320 if (spec->type_required && DECL_P (*anode))
321 anode = &TREE_TYPE (*anode);
323 if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
324 && TREE_CODE (*anode) != METHOD_TYPE)
326 if (TREE_CODE (*anode) == POINTER_TYPE
327 && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
328 || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
330 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
331 *anode = build_type_copy (*anode);
332 anode = &TREE_TYPE (*anode);
334 else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
336 /* Pass on this attribute to be tried again. */
337 returned_attrs = tree_cons (name, args, returned_attrs);
341 if (TREE_CODE (*anode) != FUNCTION_TYPE
342 && TREE_CODE (*anode) != METHOD_TYPE)
344 warning ("`%s' attribute only applies to function types",
345 IDENTIFIER_POINTER (name));
350 if (spec->handler != NULL)
351 returned_attrs = chainon ((*spec->handler) (anode, name, args,
352 flags, &no_add_attrs),
360 old_attrs = DECL_ATTRIBUTES (*anode);
362 old_attrs = TYPE_ATTRIBUTES (*anode);
364 for (a = lookup_attribute (spec->name, old_attrs);
366 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
368 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
374 /* This attribute isn't already in the list. */
376 DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
377 else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
378 TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
380 *anode = build_type_attribute_variant (*anode,
381 tree_cons (name, args,
387 return returned_attrs;
390 /* Handle a "packed" attribute; arguments as in
391 struct attribute_spec.handler. */
394 handle_packed_attribute (node, name, args, flags, no_add_attrs)
397 tree args ATTRIBUTE_UNUSED;
404 if (TREE_CODE (*node) == TYPE_DECL)
405 type = &TREE_TYPE (*node);
412 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
413 *type = build_type_copy (*type);
414 TYPE_PACKED (*type) = 1;
416 else if (TREE_CODE (*node) == FIELD_DECL)
417 DECL_PACKED (*node) = 1;
418 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
419 used for DECL_REGISTER. It wouldn't mean anything anyway. */
422 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
423 *no_add_attrs = true;
429 /* Handle a "nocommon" attribute; arguments as in
430 struct attribute_spec.handler. */
433 handle_nocommon_attribute (node, name, args, flags, no_add_attrs)
436 tree args ATTRIBUTE_UNUSED;
437 int flags ATTRIBUTE_UNUSED;
440 if (TREE_CODE (*node) == VAR_DECL)
441 DECL_COMMON (*node) = 0;
444 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
445 *no_add_attrs = true;
451 /* Handle a "common" attribute; arguments as in
452 struct attribute_spec.handler. */
455 handle_common_attribute (node, name, args, flags, no_add_attrs)
458 tree args ATTRIBUTE_UNUSED;
459 int flags ATTRIBUTE_UNUSED;
462 if (TREE_CODE (*node) == VAR_DECL)
463 DECL_COMMON (*node) = 1;
466 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
467 *no_add_attrs = true;
473 /* Handle a "noreturn" attribute; arguments as in
474 struct attribute_spec.handler. */
477 handle_noreturn_attribute (node, name, args, flags, no_add_attrs)
480 tree args ATTRIBUTE_UNUSED;
481 int flags ATTRIBUTE_UNUSED;
484 tree type = TREE_TYPE (*node);
486 /* See FIXME comment in c_common_attribute_table. */
487 if (TREE_CODE (*node) == FUNCTION_DECL)
488 TREE_THIS_VOLATILE (*node) = 1;
489 else if (TREE_CODE (type) == POINTER_TYPE
490 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
493 (build_type_variant (TREE_TYPE (type),
494 TREE_READONLY (TREE_TYPE (type)), 1));
497 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
498 *no_add_attrs = true;
504 /* Handle a "unused" attribute; arguments as in
505 struct attribute_spec.handler. */
508 handle_unused_attribute (node, name, args, flags, no_add_attrs)
511 tree args ATTRIBUTE_UNUSED;
519 if (TREE_CODE (decl) == PARM_DECL
520 || TREE_CODE (decl) == VAR_DECL
521 || TREE_CODE (decl) == FUNCTION_DECL
522 || TREE_CODE (decl) == LABEL_DECL
523 || TREE_CODE (decl) == TYPE_DECL)
524 TREE_USED (decl) = 1;
527 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
528 *no_add_attrs = true;
533 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
534 *node = build_type_copy (*node);
535 TREE_USED (*node) = 1;
541 /* Handle a "const" attribute; arguments as in
542 struct attribute_spec.handler. */
545 handle_const_attribute (node, name, args, flags, no_add_attrs)
548 tree args ATTRIBUTE_UNUSED;
549 int flags ATTRIBUTE_UNUSED;
552 tree type = TREE_TYPE (*node);
554 /* See FIXME comment on noreturn in c_common_attribute_table. */
555 if (TREE_CODE (*node) == FUNCTION_DECL)
556 TREE_READONLY (*node) = 1;
557 else if (TREE_CODE (type) == POINTER_TYPE
558 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
561 (build_type_variant (TREE_TYPE (type), 1,
562 TREE_THIS_VOLATILE (TREE_TYPE (type))));
565 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
566 *no_add_attrs = true;
572 /* Handle a "transparent_union" attribute; arguments as in
573 struct attribute_spec.handler. */
576 handle_transparent_union_attribute (node, name, args, flags, no_add_attrs)
579 tree args ATTRIBUTE_UNUSED;
583 tree decl = NULL_TREE;
590 type = &TREE_TYPE (decl);
591 is_type = TREE_CODE (*node) == TYPE_DECL;
593 else if (TYPE_P (*node))
594 type = node, is_type = 1;
597 && TREE_CODE (*type) == UNION_TYPE
599 || (TYPE_FIELDS (*type) != 0
600 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))))
602 if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
603 *type = build_type_copy (*type);
604 TYPE_TRANSPARENT_UNION (*type) = 1;
606 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
607 && TREE_CODE (*type) == UNION_TYPE
608 && TYPE_MODE (*type) == DECL_MODE (TYPE_FIELDS (*type)))
609 DECL_TRANSPARENT_UNION (decl) = 1;
612 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
613 *no_add_attrs = true;
619 /* Handle a "constructor" attribute; arguments as in
620 struct attribute_spec.handler. */
623 handle_constructor_attribute (node, name, args, flags, no_add_attrs)
626 tree args ATTRIBUTE_UNUSED;
627 int flags ATTRIBUTE_UNUSED;
631 tree type = TREE_TYPE (decl);
633 if (TREE_CODE (decl) == FUNCTION_DECL
634 && TREE_CODE (type) == FUNCTION_TYPE
635 && decl_function_context (decl) == 0)
637 DECL_STATIC_CONSTRUCTOR (decl) = 1;
638 TREE_USED (decl) = 1;
642 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
643 *no_add_attrs = true;
649 /* Handle a "destructor" attribute; arguments as in
650 struct attribute_spec.handler. */
653 handle_destructor_attribute (node, name, args, flags, no_add_attrs)
656 tree args ATTRIBUTE_UNUSED;
657 int flags ATTRIBUTE_UNUSED;
661 tree type = TREE_TYPE (decl);
663 if (TREE_CODE (decl) == FUNCTION_DECL
664 && TREE_CODE (type) == FUNCTION_TYPE
665 && decl_function_context (decl) == 0)
667 DECL_STATIC_DESTRUCTOR (decl) = 1;
668 TREE_USED (decl) = 1;
672 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
673 *no_add_attrs = true;
679 /* Handle a "mode" attribute; arguments as in
680 struct attribute_spec.handler. */
683 handle_mode_attribute (node, name, args, flags, no_add_attrs)
687 int flags ATTRIBUTE_UNUSED;
691 tree type = TREE_TYPE (decl);
693 *no_add_attrs = true;
695 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
696 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
700 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
701 int len = strlen (p);
702 enum machine_mode mode = VOIDmode;
705 if (len > 4 && p[0] == '_' && p[1] == '_'
706 && p[len - 1] == '_' && p[len - 2] == '_')
708 char *newp = (char *) alloca (len - 1);
710 strcpy (newp, &p[2]);
711 newp[len - 4] = '\0';
715 /* Give this decl a type with the specified mode.
716 First check for the special modes. */
717 if (! strcmp (p, "byte"))
719 else if (!strcmp (p, "word"))
721 else if (! strcmp (p, "pointer"))
724 for (j = 0; j < NUM_MACHINE_MODES; j++)
725 if (!strcmp (p, GET_MODE_NAME (j)))
726 mode = (enum machine_mode) j;
728 if (mode == VOIDmode)
729 error ("unknown machine mode `%s'", p);
730 else if (0 == (typefm = type_for_mode (mode,
731 TREE_UNSIGNED (type))))
732 error ("no data type for mode `%s'", p);
735 TREE_TYPE (decl) = type = typefm;
736 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
737 if (TREE_CODE (decl) != FIELD_DECL)
738 layout_decl (decl, 0);
745 /* Handle a "section" attribute; arguments as in
746 struct attribute_spec.handler. */
749 handle_section_attribute (node, name, args, flags, no_add_attrs)
751 tree name ATTRIBUTE_UNUSED;
753 int flags ATTRIBUTE_UNUSED;
758 if (targetm.have_named_sections)
760 if ((TREE_CODE (decl) == FUNCTION_DECL
761 || TREE_CODE (decl) == VAR_DECL)
762 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
764 if (TREE_CODE (decl) == VAR_DECL
765 && current_function_decl != NULL_TREE
766 && ! TREE_STATIC (decl))
768 error_with_decl (decl,
769 "section attribute cannot be specified for local variables");
770 *no_add_attrs = true;
773 /* The decl may have already been given a section attribute
774 from a previous declaration. Ensure they match. */
775 else if (DECL_SECTION_NAME (decl) != NULL_TREE
776 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
777 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
779 error_with_decl (*node,
780 "section of `%s' conflicts with previous declaration");
781 *no_add_attrs = true;
784 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
788 error_with_decl (*node,
789 "section attribute not allowed for `%s'");
790 *no_add_attrs = true;
795 error_with_decl (*node,
796 "section attributes are not supported for this target");
797 *no_add_attrs = true;
803 /* Handle a "aligned" attribute; arguments as in
804 struct attribute_spec.handler. */
807 handle_aligned_attribute (node, name, args, flags, no_add_attrs)
809 tree name ATTRIBUTE_UNUSED;
814 tree decl = NULL_TREE;
817 tree align_expr = (args ? TREE_VALUE (args)
818 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
824 type = &TREE_TYPE (decl);
825 is_type = TREE_CODE (*node) == TYPE_DECL;
827 else if (TYPE_P (*node))
828 type = node, is_type = 1;
830 /* Strip any NOPs of any kind. */
831 while (TREE_CODE (align_expr) == NOP_EXPR
832 || TREE_CODE (align_expr) == CONVERT_EXPR
833 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
834 align_expr = TREE_OPERAND (align_expr, 0);
836 if (TREE_CODE (align_expr) != INTEGER_CST)
838 error ("requested alignment is not a constant");
839 *no_add_attrs = true;
841 else if ((i = tree_log2 (align_expr)) == -1)
843 error ("requested alignment is not a power of 2");
844 *no_add_attrs = true;
846 else if (i > HOST_BITS_PER_INT - 2)
848 error ("requested alignment is too large");
849 *no_add_attrs = true;
853 /* If we have a TYPE_DECL, then copy the type, so that we
854 don't accidentally modify a builtin type. See pushdecl. */
855 if (decl && TREE_TYPE (decl) != error_mark_node
856 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
858 tree tt = TREE_TYPE (decl);
859 *type = build_type_copy (*type);
860 DECL_ORIGINAL_TYPE (decl) = tt;
861 TYPE_NAME (*type) = decl;
862 TREE_USED (*type) = TREE_USED (decl);
863 TREE_TYPE (decl) = *type;
865 else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
866 *type = build_type_copy (*type);
868 TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
869 TYPE_USER_ALIGN (*type) = 1;
871 else if (TREE_CODE (decl) != VAR_DECL
872 && TREE_CODE (decl) != FIELD_DECL)
874 error_with_decl (decl,
875 "alignment may not be specified for `%s'");
876 *no_add_attrs = true;
880 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
881 DECL_USER_ALIGN (decl) = 1;
887 /* Handle a "weak" attribute; arguments as in
888 struct attribute_spec.handler. */
891 handle_weak_attribute (node, name, args, flags, no_add_attrs)
893 tree name ATTRIBUTE_UNUSED;
894 tree args ATTRIBUTE_UNUSED;
895 int flags ATTRIBUTE_UNUSED;
896 bool *no_add_attrs ATTRIBUTE_UNUSED;
898 declare_weak (*node);
903 /* Handle an "alias" attribute; arguments as in
904 struct attribute_spec.handler. */
907 handle_alias_attribute (node, name, args, flags, no_add_attrs)
911 int flags ATTRIBUTE_UNUSED;
916 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
917 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
919 error_with_decl (decl,
920 "`%s' defined both normally and as an alias");
921 *no_add_attrs = true;
923 else if (decl_function_context (decl) == 0)
927 id = TREE_VALUE (args);
928 if (TREE_CODE (id) != STRING_CST)
930 error ("alias arg not a string");
931 *no_add_attrs = true;
934 id = get_identifier (TREE_STRING_POINTER (id));
935 /* This counts as a use of the object pointed to. */
938 if (TREE_CODE (decl) == FUNCTION_DECL)
939 DECL_INITIAL (decl) = error_mark_node;
941 DECL_EXTERNAL (decl) = 0;
942 assemble_alias (decl, id);
946 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
947 *no_add_attrs = true;
953 /* Handle a "no_instrument_function" attribute; arguments as in
954 struct attribute_spec.handler. */
957 handle_no_instrument_function_attribute (node, name, args, flags, no_add_attrs)
960 tree args ATTRIBUTE_UNUSED;
961 int flags ATTRIBUTE_UNUSED;
966 if (TREE_CODE (decl) != FUNCTION_DECL)
968 error_with_decl (decl,
969 "`%s' attribute applies only to functions",
970 IDENTIFIER_POINTER (name));
971 *no_add_attrs = true;
973 else if (DECL_INITIAL (decl))
975 error_with_decl (decl,
976 "can't set `%s' attribute after definition",
977 IDENTIFIER_POINTER (name));
978 *no_add_attrs = true;
981 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
986 /* Handle a "no_check_memory_usage" attribute; arguments as in
987 struct attribute_spec.handler. */
990 handle_no_check_memory_usage_attribute (node, name, args, flags, no_add_attrs)
993 tree args ATTRIBUTE_UNUSED;
994 int flags ATTRIBUTE_UNUSED;
999 if (TREE_CODE (decl) != FUNCTION_DECL)
1001 error_with_decl (decl,
1002 "`%s' attribute applies only to functions",
1003 IDENTIFIER_POINTER (name));
1004 *no_add_attrs = true;
1006 else if (DECL_INITIAL (decl))
1008 error_with_decl (decl,
1009 "can't set `%s' attribute after definition",
1010 IDENTIFIER_POINTER (name));
1011 *no_add_attrs = true;
1014 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1019 /* Handle a "malloc" attribute; arguments as in
1020 struct attribute_spec.handler. */
1023 handle_malloc_attribute (node, name, args, flags, no_add_attrs)
1026 tree args ATTRIBUTE_UNUSED;
1027 int flags ATTRIBUTE_UNUSED;
1030 if (TREE_CODE (*node) == FUNCTION_DECL)
1031 DECL_IS_MALLOC (*node) = 1;
1032 /* ??? TODO: Support types. */
1035 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1036 *no_add_attrs = true;
1042 /* Handle a "no_limit_stack" attribute; arguments as in
1043 struct attribute_spec.handler. */
1046 handle_no_limit_stack_attribute (node, name, args, flags, no_add_attrs)
1049 tree args ATTRIBUTE_UNUSED;
1050 int flags ATTRIBUTE_UNUSED;
1055 if (TREE_CODE (decl) != FUNCTION_DECL)
1057 error_with_decl (decl,
1058 "`%s' attribute applies only to functions",
1059 IDENTIFIER_POINTER (name));
1060 *no_add_attrs = true;
1062 else if (DECL_INITIAL (decl))
1064 error_with_decl (decl,
1065 "can't set `%s' attribute after definition",
1066 IDENTIFIER_POINTER (name));
1067 *no_add_attrs = true;
1070 DECL_NO_LIMIT_STACK (decl) = 1;
1075 /* Handle a "pure" attribute; arguments as in
1076 struct attribute_spec.handler. */
1079 handle_pure_attribute (node, name, args, flags, no_add_attrs)
1082 tree args ATTRIBUTE_UNUSED;
1083 int flags ATTRIBUTE_UNUSED;
1086 if (TREE_CODE (*node) == FUNCTION_DECL)
1087 DECL_IS_PURE (*node) = 1;
1088 /* ??? TODO: Support types. */
1091 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1092 *no_add_attrs = true;
1098 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1099 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1101 The head of the declspec list is stored in DECLSPECS.
1102 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1104 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1105 the list elements. We drop the containing TREE_LIST nodes and link the
1106 resulting attributes together the way decl_attributes expects them. */
1109 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1111 tree *declspecs, *prefix_attributes;
1113 tree t, s, a, next, specs, attrs;
1115 /* This can happen after an __extension__ in pedantic mode. */
1116 if (specs_attrs != NULL_TREE
1117 && TREE_CODE (specs_attrs) == INTEGER_CST)
1119 *declspecs = NULL_TREE;
1120 *prefix_attributes = NULL_TREE;
1124 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1125 if (specs_attrs != NULL_TREE
1126 && TREE_CODE (specs_attrs) != TREE_LIST)
1128 *declspecs = specs_attrs;
1129 *prefix_attributes = NULL_TREE;
1133 /* Remember to keep the lists in the same order, element-wise. */
1135 specs = s = NULL_TREE;
1136 attrs = a = NULL_TREE;
1137 for (t = specs_attrs; t; t = next)
1139 next = TREE_CHAIN (t);
1140 /* Declspecs have a non-NULL TREE_VALUE. */
1141 if (TREE_VALUE (t) != NULL_TREE)
1143 if (specs == NULL_TREE)
1151 /* The TREE_PURPOSE may also be empty in the case of
1152 __attribute__(()). */
1153 else if (TREE_PURPOSE (t) != NULL_TREE)
1155 if (attrs == NULL_TREE)
1156 attrs = a = TREE_PURPOSE (t);
1159 TREE_CHAIN (a) = TREE_PURPOSE (t);
1160 a = TREE_PURPOSE (t);
1162 /* More attrs can be linked here, move A to the end. */
1163 while (TREE_CHAIN (a) != NULL_TREE)
1168 /* Terminate the lists. */
1170 TREE_CHAIN (s) = NULL_TREE;
1172 TREE_CHAIN (a) = NULL_TREE;
1176 *prefix_attributes = attrs;
1179 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1180 This function is used by the parser when a rule will accept attributes
1181 in a particular position, but we don't want to support that just yet.
1183 A warning is issued for every ignored attribute. */
1186 strip_attrs (specs_attrs)
1191 split_specs_attrs (specs_attrs, &specs, &attrs);
1195 warning ("`%s' attribute ignored",
1196 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1197 attrs = TREE_CHAIN (attrs);