2014-12-19 Andrew MacLeod <amacleod@redhat.com>
[official-gcc.git] / gcc / attribs.c
blob96d40db4974d3fd9bee10ed1d4aa915cf0a2676f
1 /* Functions dealing with attribute handling, used by most front ends.
2 Copyright (C) 1992-2014 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
9 version.
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
14 for more details.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "stringpool.h"
26 #include "attribs.h"
27 #include "stor-layout.h"
28 #include "flags.h"
29 #include "diagnostic-core.h"
30 #include "ggc.h"
31 #include "tm_p.h"
32 #include "cpplib.h"
33 #include "target.h"
34 #include "langhooks.h"
35 #include "hash-table.h"
36 #include "plugin.h"
38 /* Table of the tables of attributes (common, language, format, machine)
39 searched. */
40 static const struct attribute_spec *attribute_tables[4];
42 /* Substring representation. */
44 struct substring
46 const char *str;
47 int length;
50 /* Simple hash function to avoid need to scan whole string. */
52 static inline hashval_t
53 substring_hash (const char *str, int l)
55 return str[0] + str[l - 1] * 256 + l * 65536;
58 /* Used for attribute_hash. */
60 struct attribute_hasher : typed_noop_remove <attribute_spec>
62 typedef attribute_spec value_type;
63 typedef substring compare_type;
64 static inline hashval_t hash (const value_type *);
65 static inline bool equal (const value_type *, const compare_type *);
68 inline hashval_t
69 attribute_hasher::hash (const value_type *spec)
71 const int l = strlen (spec->name);
72 return substring_hash (spec->name, l);
75 inline bool
76 attribute_hasher::equal (const value_type *spec, const compare_type *str)
78 return (strncmp (spec->name, str->str, str->length) == 0
79 && !spec->name[str->length]);
82 /* Scoped attribute name representation. */
84 struct scoped_attributes
86 const char *ns;
87 vec<attribute_spec> attributes;
88 hash_table<attribute_hasher> *attribute_hash;
91 /* The table of scope attributes. */
92 static vec<scoped_attributes> attributes_table;
94 static scoped_attributes* find_attribute_namespace (const char*);
95 static void register_scoped_attribute (const struct attribute_spec *,
96 scoped_attributes *);
98 static bool attributes_initialized = false;
100 /* Default empty table of attributes. */
102 static const struct attribute_spec empty_attribute_table[] =
104 { NULL, 0, 0, false, false, false, NULL, NULL, false }
107 /* Return base name of the attribute. Ie '__attr__' is turned into 'attr'.
108 To avoid need for copying, we simply return length of the string. */
110 static void
111 extract_attribute_substring (struct substring *str)
113 if (str->length > 4 && str->str[0] == '_' && str->str[1] == '_'
114 && str->str[str->length - 1] == '_' && str->str[str->length - 2] == '_')
116 str->length -= 4;
117 str->str += 2;
121 /* Insert an array of attributes ATTRIBUTES into a namespace. This
122 array must be NULL terminated. NS is the name of attribute
123 namespace. The function returns the namespace into which the
124 attributes have been registered. */
126 scoped_attributes*
127 register_scoped_attributes (const struct attribute_spec * attributes,
128 const char* ns)
130 scoped_attributes *result = NULL;
132 /* See if we already have attributes in the namespace NS. */
133 result = find_attribute_namespace (ns);
135 if (result == NULL)
137 /* We don't have any namespace NS yet. Create one. */
138 scoped_attributes sa;
140 if (!attributes_table.is_empty ())
141 attributes_table.create (64);
143 memset (&sa, 0, sizeof (sa));
144 sa.ns = ns;
145 sa.attributes.create (64);
146 result = attributes_table.safe_push (sa);
147 result->attribute_hash = new hash_table<attribute_hasher> (200);
150 /* Really add the attributes to their namespace now. */
151 for (unsigned i = 0; attributes[i].name != NULL; ++i)
153 result->attributes.safe_push (attributes[i]);
154 register_scoped_attribute (&attributes[i], result);
157 gcc_assert (result != NULL);
159 return result;
162 /* Return the namespace which name is NS, NULL if none exist. */
164 static scoped_attributes*
165 find_attribute_namespace (const char* ns)
167 unsigned ix;
168 scoped_attributes *iter;
170 FOR_EACH_VEC_ELT (attributes_table, ix, iter)
171 if (ns == iter->ns
172 || (iter->ns != NULL
173 && ns != NULL
174 && !strcmp (iter->ns, ns)))
175 return iter;
176 return NULL;
179 /* Initialize attribute tables, and make some sanity checks
180 if --enable-checking. */
182 void
183 init_attributes (void)
185 size_t i;
187 if (attributes_initialized)
188 return;
190 attribute_tables[0] = lang_hooks.common_attribute_table;
191 attribute_tables[1] = lang_hooks.attribute_table;
192 attribute_tables[2] = lang_hooks.format_attribute_table;
193 attribute_tables[3] = targetm.attribute_table;
195 /* Translate NULL pointers to pointers to the empty table. */
196 for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
197 if (attribute_tables[i] == NULL)
198 attribute_tables[i] = empty_attribute_table;
200 #ifdef ENABLE_CHECKING
201 /* Make some sanity checks on the attribute tables. */
202 for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
204 int j;
206 for (j = 0; attribute_tables[i][j].name != NULL; j++)
208 /* The name must not begin and end with __. */
209 const char *name = attribute_tables[i][j].name;
210 int len = strlen (name);
212 gcc_assert (!(name[0] == '_' && name[1] == '_'
213 && name[len - 1] == '_' && name[len - 2] == '_'));
215 /* The minimum and maximum lengths must be consistent. */
216 gcc_assert (attribute_tables[i][j].min_length >= 0);
218 gcc_assert (attribute_tables[i][j].max_length == -1
219 || (attribute_tables[i][j].max_length
220 >= attribute_tables[i][j].min_length));
222 /* An attribute cannot require both a DECL and a TYPE. */
223 gcc_assert (!attribute_tables[i][j].decl_required
224 || !attribute_tables[i][j].type_required);
226 /* If an attribute requires a function type, in particular
227 it requires a type. */
228 gcc_assert (!attribute_tables[i][j].function_type_required
229 || attribute_tables[i][j].type_required);
233 /* Check that each name occurs just once in each table. */
234 for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
236 int j, k;
237 for (j = 0; attribute_tables[i][j].name != NULL; j++)
238 for (k = j + 1; attribute_tables[i][k].name != NULL; k++)
239 gcc_assert (strcmp (attribute_tables[i][j].name,
240 attribute_tables[i][k].name));
242 /* Check that no name occurs in more than one table. Names that
243 begin with '*' are exempt, and may be overridden. */
244 for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
246 size_t j, k, l;
248 for (j = i + 1; j < ARRAY_SIZE (attribute_tables); j++)
249 for (k = 0; attribute_tables[i][k].name != NULL; k++)
250 for (l = 0; attribute_tables[j][l].name != NULL; l++)
251 gcc_assert (attribute_tables[i][k].name[0] == '*'
252 || strcmp (attribute_tables[i][k].name,
253 attribute_tables[j][l].name));
255 #endif
257 for (i = 0; i < ARRAY_SIZE (attribute_tables); ++i)
258 /* Put all the GNU attributes into the "gnu" namespace. */
259 register_scoped_attributes (attribute_tables[i], "gnu");
261 invoke_plugin_callbacks (PLUGIN_ATTRIBUTES, NULL);
262 attributes_initialized = true;
265 /* Insert a single ATTR into the attribute table. */
267 void
268 register_attribute (const struct attribute_spec *attr)
270 register_scoped_attribute (attr, find_attribute_namespace ("gnu"));
273 /* Insert a single attribute ATTR into a namespace of attributes. */
275 static void
276 register_scoped_attribute (const struct attribute_spec *attr,
277 scoped_attributes *name_space)
279 struct substring str;
280 attribute_spec **slot;
282 gcc_assert (attr != NULL && name_space != NULL);
284 gcc_assert (name_space->attribute_hash);
286 str.str = attr->name;
287 str.length = strlen (str.str);
289 /* Attribute names in the table must be in the form 'text' and not
290 in the form '__text__'. */
291 gcc_assert (str.length > 0 && str.str[0] != '_');
293 slot = name_space->attribute_hash
294 ->find_slot_with_hash (&str, substring_hash (str.str, str.length),
295 INSERT);
296 gcc_assert (!*slot || attr->name[0] == '*');
297 *slot = CONST_CAST (struct attribute_spec *, attr);
300 /* Return the spec for the scoped attribute with namespace NS and
301 name NAME. */
303 static const struct attribute_spec *
304 lookup_scoped_attribute_spec (const_tree ns, const_tree name)
306 struct substring attr;
307 scoped_attributes *attrs;
309 const char *ns_str = (ns != NULL_TREE) ? IDENTIFIER_POINTER (ns): NULL;
311 attrs = find_attribute_namespace (ns_str);
313 if (attrs == NULL)
314 return NULL;
316 attr.str = IDENTIFIER_POINTER (name);
317 attr.length = IDENTIFIER_LENGTH (name);
318 extract_attribute_substring (&attr);
319 return attrs->attribute_hash->find_with_hash (&attr,
320 substring_hash (attr.str,
321 attr.length));
324 /* Return the spec for the attribute named NAME. If NAME is a TREE_LIST,
325 it also specifies the attribute namespace. */
327 const struct attribute_spec *
328 lookup_attribute_spec (const_tree name)
330 tree ns;
331 if (TREE_CODE (name) == TREE_LIST)
333 ns = TREE_PURPOSE (name);
334 name = TREE_VALUE (name);
336 else
337 ns = get_identifier ("gnu");
338 return lookup_scoped_attribute_spec (ns, name);
342 /* Return the namespace of the attribute ATTR. This accessor works on
343 GNU and C++11 (scoped) attributes. On GNU attributes,
344 it returns an identifier tree for the string "gnu".
346 Please read the comments of cxx11_attribute_p to understand the
347 format of attributes. */
349 static tree
350 get_attribute_namespace (const_tree attr)
352 if (cxx11_attribute_p (attr))
353 return TREE_PURPOSE (TREE_PURPOSE (attr));
354 return get_identifier ("gnu");
357 /* Lookup the spec for attribute A using FLAGS, and issue any warnings or
358 errors as appropriate. Return NULL or a valid spec. */
360 static const struct attribute_spec *
361 process_attribute_spec (tree a, int flags)
363 tree name = get_attribute_name (a);
364 tree ns = get_attribute_namespace (a);
365 tree args = TREE_VALUE (a);
366 const struct attribute_spec *spec = lookup_scoped_attribute_spec (ns, name);
368 if (spec == NULL)
370 if (!(flags & (int) ATTR_FLAG_BUILT_IN))
372 if (ns == NULL_TREE || !cxx11_attribute_p (a))
373 warning (OPT_Wattributes, "%qE attribute directive ignored",
374 name);
375 else
376 warning (OPT_Wattributes,
377 "%<%E::%E%> scoped attribute directive ignored",
378 ns, name);
380 return NULL;
382 else if (list_length (args) < spec->min_length
383 || (spec->max_length >= 0
384 && list_length (args) > spec->max_length))
386 error ("wrong number of arguments specified for %qE attribute",
387 name);
388 return NULL;
390 gcc_assert (is_attribute_p (spec->name, name));
391 return spec;
394 /* Perform the type specific processing of type_attribute. This is factored
395 out to allow decl_attributes() to process underlying types when necessary.
396 In those cases, DECL_NODE is passed in so the decl can have re-layout
397 called. SPEC is the already verified attribute spec structure. Otherwise
398 the parameters match those of type_attribute. */
400 static tree
401 finalize_type_attribute (tree *node, const struct attribute_spec *spec,
402 tree a, tree returned_attrs, int flags,
403 tree *decl_node = NULL)
405 bool no_add_attrs = 0;
406 int fn_ptr_quals = 0;
407 tree fn_ptr_tmp = NULL_TREE;
408 tree name = get_attribute_name (a);
409 tree args = TREE_VALUE (a);
410 tree *anode = node;
412 gcc_checking_assert (TYPE_P (*node));
414 if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
415 && TREE_CODE (*anode) != METHOD_TYPE)
417 if (TREE_CODE (*anode) == POINTER_TYPE
418 && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
419 || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
421 /* OK, this is a bit convoluted. We can't just make a copy
422 of the pointer type and modify its TREE_TYPE, because if
423 we change the attributes of the target type the pointer
424 type needs to have a different TYPE_MAIN_VARIANT. So we
425 pull out the target type now, frob it as appropriate, and
426 rebuild the pointer type later.
428 This would all be simpler if attributes were part of the
429 declarator, grumble grumble. */
430 fn_ptr_tmp = TREE_TYPE (*anode);
431 fn_ptr_quals = TYPE_QUALS (*anode);
432 anode = &fn_ptr_tmp;
433 flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
435 else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
437 /* Pass on this attribute to be tried again. */
438 returned_attrs = tree_cons (name, args, returned_attrs);
439 return returned_attrs;
442 if (TREE_CODE (*anode) != FUNCTION_TYPE
443 && TREE_CODE (*anode) != METHOD_TYPE)
445 warning (OPT_Wattributes,
446 "%qE attribute only applies to function types",
447 name);
448 return returned_attrs;
452 if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
453 && TYPE_SIZE (*anode) != NULL_TREE)
455 warning (OPT_Wattributes, "type attributes ignored after type is already defined");
456 return returned_attrs;
459 if (spec->type_handler != NULL)
461 int cxx11_flag =
462 cxx11_attribute_p (a) ? ATTR_FLAG_CXX11 : 0;
464 returned_attrs = chainon ((*spec->type_handler) (anode, name, args,
465 flags|cxx11_flag,
466 &no_add_attrs),
467 returned_attrs);
470 /* If there was a decl change the layout in case anything changed. */
471 if (decl_node && spec->type_required
472 && (TREE_CODE (*decl_node) == VAR_DECL
473 || TREE_CODE (*decl_node) == PARM_DECL
474 || TREE_CODE (*decl_node) == RESULT_DECL))
475 relayout_decl (*decl_node);
477 if (!no_add_attrs)
479 tree old_attrs;
480 tree a;
482 old_attrs = TYPE_ATTRIBUTES (*anode);
484 for (a = lookup_attribute (spec->name, old_attrs);
485 a != NULL_TREE;
486 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
488 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
489 break;
492 if (a == NULL_TREE)
494 if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
496 TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
497 /* If this is the main variant, also push the attributes
498 out to the other variants. */
499 if (*anode == TYPE_MAIN_VARIANT (*anode))
501 tree variant;
502 for (variant = *anode; variant;
503 variant = TYPE_NEXT_VARIANT (variant))
505 if (TYPE_ATTRIBUTES (variant) == old_attrs)
506 TYPE_ATTRIBUTES (variant)
507 = TYPE_ATTRIBUTES (*anode);
508 else if (!lookup_attribute
509 (spec->name, TYPE_ATTRIBUTES (variant)))
510 TYPE_ATTRIBUTES (variant) = tree_cons
511 (name, args, TYPE_ATTRIBUTES (variant));
515 else
516 *anode = build_type_attribute_variant (*anode,
517 tree_cons (name, args,
518 old_attrs));
522 if (fn_ptr_tmp)
524 /* Rebuild the function pointer type and put it in the
525 appropriate place. */
526 fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
527 if (fn_ptr_quals)
528 fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
529 if (decl_node)
530 TREE_TYPE (*decl_node) = fn_ptr_tmp;
531 else
533 gcc_assert (TREE_CODE (*node) == POINTER_TYPE);
534 *node = fn_ptr_tmp;
537 return returned_attrs;
541 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
542 which is a TYPE. A copy should be created unless ATTR_FLAG_TYPE_IN_PLACE
543 is set in FLAGS. FLAGS gives further information, in the form of a
544 bitwise OR of flags in enum attribute_flags from tree.h.
545 Depending on these flags, some attributes may be returned to be
546 applied at a later stage (for example, to apply a decl attribute to the
547 declaration rather than to its type). */
549 tree
550 type_attributes (tree *node, tree attributes, int flags)
552 tree a;
553 tree returned_attrs = NULL_TREE;
555 if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node)
556 return NULL_TREE;
558 gcc_checking_assert (TYPE_P (*node));
560 if (!attributes_initialized)
561 init_attributes ();
563 targetm.insert_attributes (*node, &attributes);
565 for (a = attributes; a; a = TREE_CHAIN (a))
567 tree name = get_attribute_name (a);
568 tree args = TREE_VALUE (a);
569 const struct attribute_spec *spec = process_attribute_spec (a, flags);
571 if (!spec)
572 continue;
574 if (cxx11_attribute_p (a) && !(flags & ATTR_FLAG_TYPE_IN_PLACE))
576 /* This is a c++11 attribute that appertains to a
577 type-specifier, outside of the definition of, a class
578 type. Ignore it. */
579 warning (OPT_Wattributes, "attribute ignored");
580 inform (input_location,
581 "an attribute that appertains to a type-specifier "
582 "is ignored");
583 continue;
586 if (spec->decl_required)
588 if (flags & ((int) ATTR_FLAG_DECL_NEXT
589 | (int) ATTR_FLAG_FUNCTION_NEXT
590 | (int) ATTR_FLAG_ARRAY_NEXT))
592 /* Pass on this attribute to be tried again. */
593 returned_attrs = tree_cons (name, args, returned_attrs);
594 continue;
596 else
598 warning (OPT_Wattributes, "%qE attribute does not apply to types",
599 name);
600 continue;
604 returned_attrs = finalize_type_attribute (node, spec, a, returned_attrs,
605 flags);
608 return returned_attrs;
614 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
615 which is a DECL (including a TYPE_DECL) it should be modified in place;
616 FLAGS gives further information, in the form of a bitwise OR of flags in
617 enum attribute_flags from tree.h. Depending on these flags, some
618 attributes may be returned to be applied at a later stage. */
620 tree
621 decl_attributes (tree *node, tree attributes, int flags)
623 tree a;
624 tree returned_attrs = NULL_TREE;
627 if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node)
628 return NULL_TREE;
630 gcc_checking_assert (DECL_P (*node));
632 if (!attributes_initialized)
633 init_attributes ();
635 /* If this is a function and the user used #pragma GCC optimize, add the
636 options to the attribute((optimize(...))) list. */
637 if (TREE_CODE (*node) == FUNCTION_DECL && current_optimize_pragma)
639 tree cur_attr = lookup_attribute ("optimize", attributes);
640 tree opts = copy_list (current_optimize_pragma);
642 if (! cur_attr)
643 attributes
644 = tree_cons (get_identifier ("optimize"), opts, attributes);
645 else
646 TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
649 if (TREE_CODE (*node) == FUNCTION_DECL
650 && optimization_current_node != optimization_default_node
651 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node))
652 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node;
654 /* If this is a function and the user used #pragma GCC target, add the
655 options to the attribute((target(...))) list. */
656 if (TREE_CODE (*node) == FUNCTION_DECL
657 && current_target_pragma
658 && targetm.target_option.valid_attribute_p (*node, NULL_TREE,
659 current_target_pragma, 0))
661 tree cur_attr = lookup_attribute ("target", attributes);
662 tree opts = copy_list (current_target_pragma);
664 if (! cur_attr)
665 attributes = tree_cons (get_identifier ("target"), opts, attributes);
666 else
667 TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
670 /* A "naked" function attribute implies "noinline" and "noclone" for
671 those targets that support it. */
672 if (TREE_CODE (*node) == FUNCTION_DECL
673 && attributes
674 && lookup_attribute_spec (get_identifier ("naked"))
675 && lookup_attribute ("naked", attributes) != NULL)
677 if (lookup_attribute ("noinline", attributes) == NULL)
678 attributes = tree_cons (get_identifier ("noinline"), NULL, attributes);
680 if (lookup_attribute ("noclone", attributes) == NULL)
681 attributes = tree_cons (get_identifier ("noclone"), NULL, attributes);
684 targetm.insert_attributes (*node, &attributes);
686 for (a = attributes; a; a = TREE_CHAIN (a))
688 tree name = get_attribute_name (a);
689 tree args = TREE_VALUE (a);
690 tree *anode = node;
691 bool no_add_attrs = 0;
692 const struct attribute_spec *spec = process_attribute_spec (a, flags);
694 gcc_assert (DECL_P (*node));
696 if (!spec)
697 continue;
699 /* If we require a type, but were passed a decl, set up to make a
700 new type and update the one in the decl. ATTR_FLAG_TYPE_IN_PLACE
701 would have applied if we'd been passed a type, but we cannot modify
702 the decl's type in place here. */
703 if (spec->type_required)
705 anode = &TREE_TYPE (*anode);
706 flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
707 returned_attrs = finalize_type_attribute (anode, spec, a,
708 returned_attrs, flags,
709 node);
710 continue;
712 if (spec->decl_handler != NULL)
714 int cxx11_flag =
715 cxx11_attribute_p (a) ? ATTR_FLAG_CXX11 : 0;
716 returned_attrs = chainon ((*spec->decl_handler) (anode, name, args,
717 flags|cxx11_flag,
718 &no_add_attrs),
719 returned_attrs);
722 if (!no_add_attrs)
724 tree old_attrs;
725 tree a;
727 old_attrs = DECL_ATTRIBUTES (*anode);
729 for (a = lookup_attribute (spec->name, old_attrs);
730 a != NULL_TREE;
731 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
733 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
734 break;
737 if (a == NULL_TREE)
738 /* This attribute isn't already in the list. */
739 DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
743 return returned_attrs;
746 /* Return TRUE iff ATTR has been parsed by the front-end as a C++-11
747 attribute.
749 When G++ parses a C++11 attribute, it is represented as
750 a TREE_LIST which TREE_PURPOSE is itself a TREE_LIST. TREE_PURPOSE
751 (TREE_PURPOSE (ATTR)) is the namespace of the attribute, and the
752 TREE_VALUE (TREE_PURPOSE (ATTR)) is its non-qualified name. Please
753 use get_attribute_namespace and get_attribute_name to retrieve the
754 namespace and name of the attribute, as these accessors work with
755 GNU attributes as well. */
757 bool
758 cxx11_attribute_p (const_tree attr)
760 if (attr == NULL_TREE
761 || TREE_CODE (attr) != TREE_LIST)
762 return false;
764 return (TREE_CODE (TREE_PURPOSE (attr)) == TREE_LIST);
767 /* Return the name of the attribute ATTR. This accessor works on GNU
768 and C++11 (scoped) attributes.
770 Please read the comments of cxx11_attribute_p to understand the
771 format of attributes. */
773 tree
774 get_attribute_name (const_tree attr)
776 if (cxx11_attribute_p (attr))
777 return TREE_VALUE (TREE_PURPOSE (attr));
778 return TREE_PURPOSE (attr);
781 /* Subroutine of set_method_tm_attributes. Apply TM attribute ATTR
782 to the method FNDECL. */
784 void
785 apply_tm_attr (tree fndecl, tree attr)
787 type_attributes (&TREE_TYPE (fndecl), tree_cons (attr, NULL, NULL), 0);