]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/attribs.cc
attribs: fix typedefs in generic code [PR105492]
[thirdparty/gcc.git] / gcc / attribs.cc
1 /* Functions dealing with attribute handling, used by most front ends.
2 Copyright (C) 1992-2022 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
20 #define INCLUDE_STRING
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "target.h"
25 #include "tree.h"
26 #include "stringpool.h"
27 #include "diagnostic-core.h"
28 #include "attribs.h"
29 #include "fold-const.h"
30 #include "stor-layout.h"
31 #include "langhooks.h"
32 #include "plugin.h"
33 #include "selftest.h"
34 #include "hash-set.h"
35 #include "diagnostic.h"
36 #include "pretty-print.h"
37 #include "tree-pretty-print.h"
38 #include "intl.h"
39
40 /* Table of the tables of attributes (common, language, format, machine)
41 searched. */
42 static const struct attribute_spec *attribute_tables[4];
43
44 /* Substring representation. */
45
46 struct substring
47 {
48 const char *str;
49 int length;
50 };
51
52 /* Simple hash function to avoid need to scan whole string. */
53
54 static inline hashval_t
55 substring_hash (const char *str, int l)
56 {
57 return str[0] + str[l - 1] * 256 + l * 65536;
58 }
59
60 /* Used for attribute_hash. */
61
62 struct attribute_hasher : nofree_ptr_hash <attribute_spec>
63 {
64 typedef substring *compare_type;
65 static inline hashval_t hash (const attribute_spec *);
66 static inline bool equal (const attribute_spec *, const substring *);
67 };
68
69 inline hashval_t
70 attribute_hasher::hash (const attribute_spec *spec)
71 {
72 const int l = strlen (spec->name);
73 return substring_hash (spec->name, l);
74 }
75
76 inline bool
77 attribute_hasher::equal (const attribute_spec *spec, const substring *str)
78 {
79 return (strncmp (spec->name, str->str, str->length) == 0
80 && !spec->name[str->length]);
81 }
82
83 /* Scoped attribute name representation. */
84
85 struct scoped_attributes
86 {
87 const char *ns;
88 vec<attribute_spec> attributes;
89 hash_table<attribute_hasher> *attribute_hash;
90 /* True if we should not warn about unknown attributes in this NS. */
91 bool ignored_p;
92 };
93
94 /* The table of scope attributes. */
95 static vec<scoped_attributes> attributes_table;
96
97 static scoped_attributes* find_attribute_namespace (const char*);
98 static void register_scoped_attribute (const struct attribute_spec *,
99 scoped_attributes *);
100 static const struct attribute_spec *lookup_scoped_attribute_spec (const_tree,
101 const_tree);
102
103 static bool attributes_initialized = false;
104
105 /* Default empty table of attributes. */
106
107 static const struct attribute_spec empty_attribute_table[] =
108 {
109 { NULL, 0, 0, false, false, false, false, NULL, NULL }
110 };
111
112 /* Return base name of the attribute. Ie '__attr__' is turned into 'attr'.
113 To avoid need for copying, we simply return length of the string. */
114
115 static void
116 extract_attribute_substring (struct substring *str)
117 {
118 canonicalize_attr_name (str->str, str->length);
119 }
120
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. IGNORED_P is true iff all unknown attributes in this
124 namespace should be ignored for the purposes of -Wattributes. The
125 function returns the namespace into which the attributes have been
126 registered. */
127
128 scoped_attributes *
129 register_scoped_attributes (const struct attribute_spec *attributes,
130 const char *ns, bool ignored_p /*=false*/)
131 {
132 scoped_attributes *result = NULL;
133
134 /* See if we already have attributes in the namespace NS. */
135 result = find_attribute_namespace (ns);
136
137 if (result == NULL)
138 {
139 /* We don't have any namespace NS yet. Create one. */
140 scoped_attributes sa;
141
142 if (attributes_table.is_empty ())
143 attributes_table.create (64);
144
145 memset (&sa, 0, sizeof (sa));
146 sa.ns = ns;
147 sa.attributes.create (64);
148 sa.ignored_p = ignored_p;
149 result = attributes_table.safe_push (sa);
150 result->attribute_hash = new hash_table<attribute_hasher> (200);
151 }
152 else
153 result->ignored_p |= ignored_p;
154
155 /* Really add the attributes to their namespace now. */
156 for (unsigned i = 0; attributes[i].name != NULL; ++i)
157 {
158 result->attributes.safe_push (attributes[i]);
159 register_scoped_attribute (&attributes[i], result);
160 }
161
162 gcc_assert (result != NULL);
163
164 return result;
165 }
166
167 /* Return the namespace which name is NS, NULL if none exist. */
168
169 static scoped_attributes*
170 find_attribute_namespace (const char* ns)
171 {
172 for (scoped_attributes &iter : attributes_table)
173 if (ns == iter.ns
174 || (iter.ns != NULL
175 && ns != NULL
176 && !strcmp (iter.ns, ns)))
177 return &iter;
178 return NULL;
179 }
180
181 /* Make some sanity checks on the attribute tables. */
182
183 static void
184 check_attribute_tables (void)
185 {
186 for (size_t i = 0; i < ARRAY_SIZE (attribute_tables); i++)
187 for (size_t j = 0; attribute_tables[i][j].name != NULL; j++)
188 {
189 /* The name must not begin and end with __. */
190 const char *name = attribute_tables[i][j].name;
191 int len = strlen (name);
192
193 gcc_assert (!(name[0] == '_' && name[1] == '_'
194 && name[len - 1] == '_' && name[len - 2] == '_'));
195
196 /* The minimum and maximum lengths must be consistent. */
197 gcc_assert (attribute_tables[i][j].min_length >= 0);
198
199 gcc_assert (attribute_tables[i][j].max_length == -1
200 || (attribute_tables[i][j].max_length
201 >= attribute_tables[i][j].min_length));
202
203 /* An attribute cannot require both a DECL and a TYPE. */
204 gcc_assert (!attribute_tables[i][j].decl_required
205 || !attribute_tables[i][j].type_required);
206
207 /* If an attribute requires a function type, in particular
208 it requires a type. */
209 gcc_assert (!attribute_tables[i][j].function_type_required
210 || attribute_tables[i][j].type_required);
211 }
212
213 /* Check that each name occurs just once in each table. */
214 for (size_t i = 0; i < ARRAY_SIZE (attribute_tables); i++)
215 for (size_t j = 0; attribute_tables[i][j].name != NULL; j++)
216 for (size_t k = j + 1; attribute_tables[i][k].name != NULL; k++)
217 gcc_assert (strcmp (attribute_tables[i][j].name,
218 attribute_tables[i][k].name));
219
220 /* Check that no name occurs in more than one table. Names that
221 begin with '*' are exempt, and may be overridden. */
222 for (size_t i = 0; i < ARRAY_SIZE (attribute_tables); i++)
223 for (size_t j = i + 1; j < ARRAY_SIZE (attribute_tables); j++)
224 for (size_t k = 0; attribute_tables[i][k].name != NULL; k++)
225 for (size_t l = 0; attribute_tables[j][l].name != NULL; l++)
226 gcc_assert (attribute_tables[i][k].name[0] == '*'
227 || strcmp (attribute_tables[i][k].name,
228 attribute_tables[j][l].name));
229 }
230
231 /* Used to stash pointers to allocated memory so that we can free them at
232 the end of parsing of all TUs. */
233 static vec<attribute_spec *> ignored_attributes_table;
234
235 /* Parse arguments V of -Wno-attributes=.
236 Currently we accept:
237 vendor::attr
238 vendor::
239 This functions also registers the parsed attributes so that we don't
240 warn that we don't recognize them. */
241
242 void
243 handle_ignored_attributes_option (vec<char *> *v)
244 {
245 if (v == nullptr)
246 return;
247
248 for (auto opt : v)
249 {
250 char *cln = strstr (opt, "::");
251 /* We don't accept '::attr'. */
252 if (cln == nullptr || cln == opt)
253 {
254 error ("wrong argument to ignored attributes");
255 inform (input_location, "valid format is %<ns::attr%> or %<ns::%>");
256 continue;
257 }
258 const char *vendor_start = opt;
259 ptrdiff_t vendor_len = cln - opt;
260 const char *attr_start = cln + 2;
261 /* This could really use rawmemchr :(. */
262 ptrdiff_t attr_len = strchr (attr_start, '\0') - attr_start;
263 /* Verify that they look valid. */
264 auto valid_p = [](const char *const s, ptrdiff_t len) {
265 bool ok = false;
266
267 for (int i = 0; i < len; ++i)
268 if (ISALNUM (s[i]))
269 ok = true;
270 else if (s[i] != '_')
271 return false;
272
273 return ok;
274 };
275 if (!valid_p (vendor_start, vendor_len))
276 {
277 error ("wrong argument to ignored attributes");
278 continue;
279 }
280 canonicalize_attr_name (vendor_start, vendor_len);
281 /* We perform all this hijinks so that we don't have to copy OPT. */
282 tree vendor_id = get_identifier_with_length (vendor_start, vendor_len);
283 const char *attr;
284 /* In the "vendor::" case, we should ignore *any* attribute coming
285 from this attribute namespace. */
286 if (attr_len > 0)
287 {
288 if (!valid_p (attr_start, attr_len))
289 {
290 error ("wrong argument to ignored attributes");
291 continue;
292 }
293 canonicalize_attr_name (attr_start, attr_len);
294 tree attr_id = get_identifier_with_length (attr_start, attr_len);
295 attr = IDENTIFIER_POINTER (attr_id);
296 /* If we've already seen this vendor::attr, ignore it. Attempting to
297 register it twice would lead to a crash. */
298 if (lookup_scoped_attribute_spec (vendor_id, attr_id))
299 continue;
300 }
301 else
302 attr = nullptr;
303 /* Create a table with extra attributes which we will register.
304 We can't free it here, so squirrel away the pointers. */
305 attribute_spec *table = new attribute_spec[2];
306 ignored_attributes_table.safe_push (table);
307 table[0] = { attr, 0, -2, false, false, false, false, nullptr, nullptr };
308 table[1] = { nullptr, 0, 0, false, false, false, false, nullptr,
309 nullptr };
310 register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr);
311 }
312 }
313
314 /* Free data we might have allocated when adding extra attributes. */
315
316 void
317 free_attr_data ()
318 {
319 for (auto x : ignored_attributes_table)
320 delete[] x;
321 ignored_attributes_table.release ();
322 }
323
324 /* Initialize attribute tables, and make some sanity checks if checking is
325 enabled. */
326
327 void
328 init_attributes (void)
329 {
330 size_t i;
331
332 if (attributes_initialized)
333 return;
334
335 attribute_tables[0] = lang_hooks.common_attribute_table;
336 attribute_tables[1] = lang_hooks.attribute_table;
337 attribute_tables[2] = lang_hooks.format_attribute_table;
338 attribute_tables[3] = targetm.attribute_table;
339
340 /* Translate NULL pointers to pointers to the empty table. */
341 for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
342 if (attribute_tables[i] == NULL)
343 attribute_tables[i] = empty_attribute_table;
344
345 if (flag_checking)
346 check_attribute_tables ();
347
348 for (i = 0; i < ARRAY_SIZE (attribute_tables); ++i)
349 /* Put all the GNU attributes into the "gnu" namespace. */
350 register_scoped_attributes (attribute_tables[i], "gnu");
351
352 vec<char *> *ignored = (vec<char *> *) flag_ignored_attributes;
353 handle_ignored_attributes_option (ignored);
354
355 invoke_plugin_callbacks (PLUGIN_ATTRIBUTES, NULL);
356 attributes_initialized = true;
357 }
358
359 /* Insert a single ATTR into the attribute table. */
360
361 void
362 register_attribute (const struct attribute_spec *attr)
363 {
364 register_scoped_attribute (attr, find_attribute_namespace ("gnu"));
365 }
366
367 /* Insert a single attribute ATTR into a namespace of attributes. */
368
369 static void
370 register_scoped_attribute (const struct attribute_spec *attr,
371 scoped_attributes *name_space)
372 {
373 struct substring str;
374 attribute_spec **slot;
375
376 gcc_assert (attr != NULL && name_space != NULL);
377
378 gcc_assert (name_space->attribute_hash);
379
380 str.str = attr->name;
381 str.length = strlen (str.str);
382
383 /* Attribute names in the table must be in the form 'text' and not
384 in the form '__text__'. */
385 gcc_checking_assert (!canonicalize_attr_name (str.str, str.length));
386
387 slot = name_space->attribute_hash
388 ->find_slot_with_hash (&str, substring_hash (str.str, str.length),
389 INSERT);
390 gcc_assert (!*slot || attr->name[0] == '*');
391 *slot = CONST_CAST (struct attribute_spec *, attr);
392 }
393
394 /* Return the spec for the scoped attribute with namespace NS and
395 name NAME. */
396
397 static const struct attribute_spec *
398 lookup_scoped_attribute_spec (const_tree ns, const_tree name)
399 {
400 struct substring attr;
401 scoped_attributes *attrs;
402
403 const char *ns_str = (ns != NULL_TREE) ? IDENTIFIER_POINTER (ns): NULL;
404
405 attrs = find_attribute_namespace (ns_str);
406
407 if (attrs == NULL)
408 return NULL;
409
410 attr.str = IDENTIFIER_POINTER (name);
411 attr.length = IDENTIFIER_LENGTH (name);
412 extract_attribute_substring (&attr);
413 return attrs->attribute_hash->find_with_hash (&attr,
414 substring_hash (attr.str,
415 attr.length));
416 }
417
418 /* Return the spec for the attribute named NAME. If NAME is a TREE_LIST,
419 it also specifies the attribute namespace. */
420
421 const struct attribute_spec *
422 lookup_attribute_spec (const_tree name)
423 {
424 tree ns;
425 if (TREE_CODE (name) == TREE_LIST)
426 {
427 ns = TREE_PURPOSE (name);
428 name = TREE_VALUE (name);
429 }
430 else
431 ns = get_identifier ("gnu");
432 return lookup_scoped_attribute_spec (ns, name);
433 }
434
435
436 /* Return the namespace of the attribute ATTR. This accessor works on
437 GNU and C++11 (scoped) attributes. On GNU attributes,
438 it returns an identifier tree for the string "gnu".
439
440 Please read the comments of cxx11_attribute_p to understand the
441 format of attributes. */
442
443 tree
444 get_attribute_namespace (const_tree attr)
445 {
446 if (cxx11_attribute_p (attr))
447 return TREE_PURPOSE (TREE_PURPOSE (attr));
448 return get_identifier ("gnu");
449 }
450
451 /* Check LAST_DECL and NODE of the same symbol for attributes that are
452 recorded in SPEC to be mutually exclusive with ATTRNAME, diagnose
453 them, and return true if any have been found. NODE can be a DECL
454 or a TYPE. */
455
456 static bool
457 diag_attr_exclusions (tree last_decl, tree node, tree attrname,
458 const attribute_spec *spec)
459 {
460 const attribute_spec::exclusions *excl = spec->exclude;
461
462 tree_code code = TREE_CODE (node);
463
464 if ((code == FUNCTION_DECL && !excl->function
465 && (!excl->type || !spec->affects_type_identity))
466 || (code == VAR_DECL && !excl->variable
467 && (!excl->type || !spec->affects_type_identity))
468 || (((code == TYPE_DECL || RECORD_OR_UNION_TYPE_P (node)) && !excl->type)))
469 return false;
470
471 /* True if an attribute that's mutually exclusive with ATTRNAME
472 has been found. */
473 bool found = false;
474
475 if (last_decl && last_decl != node && TREE_TYPE (last_decl) != node)
476 {
477 /* Check both the last DECL and its type for conflicts with
478 the attribute being added to the current decl or type. */
479 found |= diag_attr_exclusions (last_decl, last_decl, attrname, spec);
480 tree decl_type = TREE_TYPE (last_decl);
481 found |= diag_attr_exclusions (last_decl, decl_type, attrname, spec);
482 }
483
484 /* NODE is either the current DECL to which the attribute is being
485 applied or its TYPE. For the former, consider the attributes on
486 both the DECL and its type. */
487 tree attrs[2];
488
489 if (DECL_P (node))
490 {
491 attrs[0] = DECL_ATTRIBUTES (node);
492 attrs[1] = TYPE_ATTRIBUTES (TREE_TYPE (node));
493 }
494 else
495 {
496 attrs[0] = TYPE_ATTRIBUTES (node);
497 attrs[1] = NULL_TREE;
498 }
499
500 /* Iterate over the mutually exclusive attribute names and verify
501 that the symbol doesn't contain it. */
502 for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
503 {
504 if (!attrs[i])
505 continue;
506
507 for ( ; excl->name; ++excl)
508 {
509 /* Avoid checking the attribute against itself. */
510 if (is_attribute_p (excl->name, attrname))
511 continue;
512
513 if (!lookup_attribute (excl->name, attrs[i]))
514 continue;
515
516 /* An exclusion may apply either to a function declaration,
517 type declaration, or a field/variable declaration, or
518 any subset of the three. */
519 if (TREE_CODE (node) == FUNCTION_DECL
520 && !excl->function)
521 continue;
522
523 if (TREE_CODE (node) == TYPE_DECL
524 && !excl->type)
525 continue;
526
527 if ((TREE_CODE (node) == FIELD_DECL
528 || TREE_CODE (node) == VAR_DECL)
529 && !excl->variable)
530 continue;
531
532 found = true;
533
534 /* Print a note? */
535 bool note = last_decl != NULL_TREE;
536 auto_diagnostic_group d;
537 if (TREE_CODE (node) == FUNCTION_DECL
538 && fndecl_built_in_p (node))
539 note &= warning (OPT_Wattributes,
540 "ignoring attribute %qE in declaration of "
541 "a built-in function %qD because it conflicts "
542 "with attribute %qs",
543 attrname, node, excl->name);
544 else
545 note &= warning (OPT_Wattributes,
546 "ignoring attribute %qE because "
547 "it conflicts with attribute %qs",
548 attrname, excl->name);
549
550 if (note)
551 inform (DECL_SOURCE_LOCATION (last_decl),
552 "previous declaration here");
553 }
554 }
555
556 return found;
557 }
558
559 /* Return true iff we should not complain about unknown attributes
560 coming from the attribute namespace NS. This is the case for
561 the -Wno-attributes=ns:: command-line option. */
562
563 static bool
564 attr_namespace_ignored_p (tree ns)
565 {
566 if (ns == NULL_TREE)
567 return false;
568 scoped_attributes *r = find_attribute_namespace (IDENTIFIER_POINTER (ns));
569 return r && r->ignored_p;
570 }
571
572 /* Return true if the attribute ATTR should not be warned about. */
573
574 bool
575 attribute_ignored_p (tree attr)
576 {
577 if (!cxx11_attribute_p (attr))
578 return false;
579 if (tree ns = get_attribute_namespace (attr))
580 {
581 if (attr_namespace_ignored_p (ns))
582 return true;
583 const attribute_spec *as = lookup_attribute_spec (TREE_PURPOSE (attr));
584 if (as && as->max_length == -2)
585 return true;
586 }
587 return false;
588 }
589
590 /* Like above, but takes an attribute_spec AS, which must be nonnull. */
591
592 bool
593 attribute_ignored_p (const attribute_spec *const as)
594 {
595 return as->max_length == -2;
596 }
597
598 /* Process the attributes listed in ATTRIBUTES and install them in *NODE,
599 which is either a DECL (including a TYPE_DECL) or a TYPE. If a DECL,
600 it should be modified in place; if a TYPE, a copy should be created
601 unless ATTR_FLAG_TYPE_IN_PLACE is set in FLAGS. FLAGS gives further
602 information, in the form of a bitwise OR of flags in enum attribute_flags
603 from tree.h. Depending on these flags, some attributes may be
604 returned to be applied at a later stage (for example, to apply
605 a decl attribute to the declaration rather than to its type). */
606
607 tree
608 decl_attributes (tree *node, tree attributes, int flags,
609 tree last_decl /* = NULL_TREE */)
610 {
611 tree returned_attrs = NULL_TREE;
612
613 if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node)
614 return NULL_TREE;
615
616 if (!attributes_initialized)
617 init_attributes ();
618
619 /* If this is a function and the user used #pragma GCC optimize, add the
620 options to the attribute((optimize(...))) list. */
621 if (TREE_CODE (*node) == FUNCTION_DECL && current_optimize_pragma)
622 {
623 tree cur_attr = lookup_attribute ("optimize", attributes);
624 tree opts = copy_list (current_optimize_pragma);
625
626 if (! cur_attr)
627 attributes
628 = tree_cons (get_identifier ("optimize"), opts, attributes);
629 else
630 TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
631 }
632
633 if (TREE_CODE (*node) == FUNCTION_DECL
634 && (optimization_current_node != optimization_default_node
635 || target_option_current_node != target_option_default_node)
636 && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node))
637 {
638 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node;
639 /* Don't set DECL_FUNCTION_SPECIFIC_TARGET for targets that don't
640 support #pragma GCC target or target attribute. */
641 if (target_option_default_node)
642 {
643 tree cur_tree
644 = build_target_option_node (&global_options, &global_options_set);
645 tree old_tree = DECL_FUNCTION_SPECIFIC_TARGET (*node);
646 if (!old_tree)
647 old_tree = target_option_default_node;
648 /* The changes on optimization options can cause the changes in
649 target options, update it accordingly if it's changed. */
650 if (old_tree != cur_tree)
651 DECL_FUNCTION_SPECIFIC_TARGET (*node) = cur_tree;
652 }
653 }
654
655 /* If this is a function and the user used #pragma GCC target, add the
656 options to the attribute((target(...))) list. */
657 if (TREE_CODE (*node) == FUNCTION_DECL
658 && current_target_pragma
659 && targetm.target_option.valid_attribute_p (*node, NULL_TREE,
660 current_target_pragma, 0))
661 {
662 tree cur_attr = lookup_attribute ("target", attributes);
663 tree opts = copy_list (current_target_pragma);
664
665 if (! cur_attr)
666 attributes = tree_cons (get_identifier ("target"), opts, attributes);
667 else
668 TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
669 }
670
671 /* A "naked" function attribute implies "noinline" and "noclone" for
672 those targets that support it. */
673 if (TREE_CODE (*node) == FUNCTION_DECL
674 && attributes
675 && lookup_attribute ("naked", attributes) != NULL
676 && lookup_attribute_spec (get_identifier ("naked"))
677 && lookup_attribute ("noipa", attributes) == NULL)
678 attributes = tree_cons (get_identifier ("noipa"), NULL, attributes);
679
680 /* A "noipa" function attribute implies "noinline", "noclone" and "no_icf"
681 for those targets that support it. */
682 if (TREE_CODE (*node) == FUNCTION_DECL
683 && attributes
684 && lookup_attribute ("noipa", attributes) != NULL
685 && lookup_attribute_spec (get_identifier ("noipa")))
686 {
687 if (lookup_attribute ("noinline", attributes) == NULL)
688 attributes = tree_cons (get_identifier ("noinline"), NULL, attributes);
689
690 if (lookup_attribute ("noclone", attributes) == NULL)
691 attributes = tree_cons (get_identifier ("noclone"), NULL, attributes);
692
693 if (lookup_attribute ("no_icf", attributes) == NULL)
694 attributes = tree_cons (get_identifier ("no_icf"), NULL, attributes);
695 }
696
697 targetm.insert_attributes (*node, &attributes);
698
699 /* Note that attributes on the same declaration are not necessarily
700 in the same order as in the source. */
701 for (tree attr = attributes; attr; attr = TREE_CHAIN (attr))
702 {
703 tree ns = get_attribute_namespace (attr);
704 tree name = get_attribute_name (attr);
705 tree args = TREE_VALUE (attr);
706 tree *anode = node;
707 const struct attribute_spec *spec
708 = lookup_scoped_attribute_spec (ns, name);
709 int fn_ptr_quals = 0;
710 tree fn_ptr_tmp = NULL_TREE;
711 const bool cxx11_attr_p = cxx11_attribute_p (attr);
712
713 if (spec == NULL)
714 {
715 if (!(flags & (int) ATTR_FLAG_BUILT_IN)
716 && !attr_namespace_ignored_p (ns))
717 {
718 if (ns == NULL_TREE || !cxx11_attr_p)
719 warning (OPT_Wattributes, "%qE attribute directive ignored",
720 name);
721 else
722 warning (OPT_Wattributes,
723 "%<%E::%E%> scoped attribute directive ignored",
724 ns, name);
725 }
726 continue;
727 }
728 else
729 {
730 int nargs = list_length (args);
731 if (nargs < spec->min_length
732 || (spec->max_length >= 0
733 && nargs > spec->max_length))
734 {
735 error ("wrong number of arguments specified for %qE attribute",
736 name);
737 if (spec->max_length < 0)
738 inform (input_location, "expected %i or more, found %i",
739 spec->min_length, nargs);
740 else
741 inform (input_location, "expected between %i and %i, found %i",
742 spec->min_length, spec->max_length, nargs);
743 continue;
744 }
745 }
746 gcc_assert (is_attribute_p (spec->name, name));
747
748 if (spec->decl_required && !DECL_P (*anode))
749 {
750 if (flags & ((int) ATTR_FLAG_DECL_NEXT
751 | (int) ATTR_FLAG_FUNCTION_NEXT
752 | (int) ATTR_FLAG_ARRAY_NEXT))
753 {
754 /* Pass on this attribute to be tried again. */
755 tree attr = tree_cons (name, args, NULL_TREE);
756 returned_attrs = chainon (returned_attrs, attr);
757 continue;
758 }
759 else
760 {
761 warning (OPT_Wattributes, "%qE attribute does not apply to types",
762 name);
763 continue;
764 }
765 }
766
767 /* If we require a type, but were passed a decl, set up to make a
768 new type and update the one in the decl. ATTR_FLAG_TYPE_IN_PLACE
769 would have applied if we'd been passed a type, but we cannot modify
770 the decl's type in place here. */
771 if (spec->type_required && DECL_P (*anode))
772 {
773 anode = &TREE_TYPE (*anode);
774 flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
775 }
776
777 if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
778 && TREE_CODE (*anode) != METHOD_TYPE)
779 {
780 if (TREE_CODE (*anode) == POINTER_TYPE
781 && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
782 || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
783 {
784 /* OK, this is a bit convoluted. We can't just make a copy
785 of the pointer type and modify its TREE_TYPE, because if
786 we change the attributes of the target type the pointer
787 type needs to have a different TYPE_MAIN_VARIANT. So we
788 pull out the target type now, frob it as appropriate, and
789 rebuild the pointer type later.
790
791 This would all be simpler if attributes were part of the
792 declarator, grumble grumble. */
793 fn_ptr_tmp = TREE_TYPE (*anode);
794 fn_ptr_quals = TYPE_QUALS (*anode);
795 anode = &fn_ptr_tmp;
796 flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
797 }
798 else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
799 {
800 /* Pass on this attribute to be tried again. */
801 tree attr = tree_cons (name, args, NULL_TREE);
802 returned_attrs = chainon (returned_attrs, attr);
803 continue;
804 }
805
806 if (TREE_CODE (*anode) != FUNCTION_TYPE
807 && TREE_CODE (*anode) != METHOD_TYPE)
808 {
809 warning (OPT_Wattributes,
810 "%qE attribute only applies to function types",
811 name);
812 continue;
813 }
814 }
815
816 if (TYPE_P (*anode)
817 && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
818 && TYPE_SIZE (*anode) != NULL_TREE)
819 {
820 warning (OPT_Wattributes, "type attributes ignored after type is already defined");
821 continue;
822 }
823
824 bool no_add_attrs = false;
825
826 /* Check for exclusions with other attributes on the current
827 declation as well as the last declaration of the same
828 symbol already processed (if one exists). Detect and
829 reject incompatible attributes. */
830 bool built_in = flags & ATTR_FLAG_BUILT_IN;
831 if (spec->exclude
832 && (flag_checking || !built_in)
833 && !error_operand_p (last_decl))
834 {
835 /* Always check attributes on user-defined functions.
836 Check them on built-ins only when -fchecking is set.
837 Ignore __builtin_unreachable -- it's both const and
838 noreturn. */
839
840 if (!built_in
841 || !DECL_P (*anode)
842 || DECL_BUILT_IN_CLASS (*anode) != BUILT_IN_NORMAL
843 || (DECL_FUNCTION_CODE (*anode) != BUILT_IN_UNREACHABLE
844 && (DECL_FUNCTION_CODE (*anode)
845 != BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE)))
846 {
847 bool no_add = diag_attr_exclusions (last_decl, *anode, name, spec);
848 if (!no_add && anode != node)
849 no_add = diag_attr_exclusions (last_decl, *node, name, spec);
850 no_add_attrs |= no_add;
851 }
852 }
853
854 if (no_add_attrs)
855 continue;
856
857 if (spec->handler != NULL)
858 {
859 int cxx11_flag = (cxx11_attr_p ? ATTR_FLAG_CXX11 : 0);
860
861 /* Pass in an array of the current declaration followed
862 by the last pushed/merged declaration if one exists.
863 For calls that modify the type attributes of a DECL
864 and for which *ANODE is *NODE's type, also pass in
865 the DECL as the third element to use in diagnostics.
866 If the handler changes CUR_AND_LAST_DECL[0] replace
867 *ANODE with its value. */
868 tree cur_and_last_decl[3] = { *anode, last_decl };
869 if (anode != node && DECL_P (*node))
870 cur_and_last_decl[2] = *node;
871
872 tree ret = (spec->handler) (cur_and_last_decl, name, args,
873 flags|cxx11_flag, &no_add_attrs);
874
875 /* Fix up typedefs clobbered by attribute handlers. */
876 if (TREE_CODE (*node) == TYPE_DECL
877 && anode == &TREE_TYPE (*node)
878 && DECL_ORIGINAL_TYPE (*node)
879 && TYPE_NAME (*anode) == *node
880 && TYPE_NAME (cur_and_last_decl[0]) != *node)
881 {
882 tree t = cur_and_last_decl[0];
883 DECL_ORIGINAL_TYPE (*node) = t;
884 tree tt = build_variant_type_copy (t);
885 cur_and_last_decl[0] = tt;
886 TREE_TYPE (*node) = tt;
887 TYPE_NAME (tt) = *node;
888 }
889
890 *anode = cur_and_last_decl[0];
891 if (ret == error_mark_node)
892 {
893 warning (OPT_Wattributes, "%qE attribute ignored", name);
894 no_add_attrs = true;
895 }
896 else
897 returned_attrs = chainon (ret, returned_attrs);
898 }
899
900 /* Layout the decl in case anything changed. */
901 if (spec->type_required && DECL_P (*node)
902 && (VAR_P (*node)
903 || TREE_CODE (*node) == PARM_DECL
904 || TREE_CODE (*node) == RESULT_DECL))
905 relayout_decl (*node);
906
907 if (!no_add_attrs)
908 {
909 tree old_attrs;
910 tree a;
911
912 if (DECL_P (*anode))
913 old_attrs = DECL_ATTRIBUTES (*anode);
914 else
915 old_attrs = TYPE_ATTRIBUTES (*anode);
916
917 for (a = lookup_attribute (spec->name, old_attrs);
918 a != NULL_TREE;
919 a = lookup_attribute (spec->name, TREE_CHAIN (a)))
920 {
921 if (simple_cst_equal (TREE_VALUE (a), args) == 1)
922 break;
923 }
924
925 if (a == NULL_TREE)
926 {
927 /* This attribute isn't already in the list. */
928 tree r;
929 /* Preserve the C++11 form. */
930 if (cxx11_attr_p)
931 r = tree_cons (build_tree_list (ns, name), args, old_attrs);
932 else
933 r = tree_cons (name, args, old_attrs);
934
935 if (DECL_P (*anode))
936 DECL_ATTRIBUTES (*anode) = r;
937 else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
938 {
939 TYPE_ATTRIBUTES (*anode) = r;
940 /* If this is the main variant, also push the attributes
941 out to the other variants. */
942 if (*anode == TYPE_MAIN_VARIANT (*anode))
943 {
944 for (tree variant = *anode; variant;
945 variant = TYPE_NEXT_VARIANT (variant))
946 {
947 if (TYPE_ATTRIBUTES (variant) == old_attrs)
948 TYPE_ATTRIBUTES (variant)
949 = TYPE_ATTRIBUTES (*anode);
950 else if (!lookup_attribute
951 (spec->name, TYPE_ATTRIBUTES (variant)))
952 TYPE_ATTRIBUTES (variant) = tree_cons
953 (name, args, TYPE_ATTRIBUTES (variant));
954 }
955 }
956 }
957 else
958 *anode = build_type_attribute_variant (*anode, r);
959 }
960 }
961
962 if (fn_ptr_tmp)
963 {
964 /* Rebuild the function pointer type and put it in the
965 appropriate place. */
966 fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
967 if (fn_ptr_quals)
968 fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
969 if (DECL_P (*node))
970 TREE_TYPE (*node) = fn_ptr_tmp;
971 else
972 {
973 gcc_assert (TREE_CODE (*node) == POINTER_TYPE);
974 *node = fn_ptr_tmp;
975 }
976 }
977 }
978
979 return returned_attrs;
980 }
981
982 /* Return TRUE iff ATTR has been parsed by the front-end as a C++-11
983 attribute.
984
985 When G++ parses a C++11 attribute, it is represented as
986 a TREE_LIST which TREE_PURPOSE is itself a TREE_LIST. TREE_PURPOSE
987 (TREE_PURPOSE (ATTR)) is the namespace of the attribute, and the
988 TREE_VALUE (TREE_PURPOSE (ATTR)) is its non-qualified name. Please
989 use get_attribute_namespace and get_attribute_name to retrieve the
990 namespace and name of the attribute, as these accessors work with
991 GNU attributes as well. */
992
993 bool
994 cxx11_attribute_p (const_tree attr)
995 {
996 if (attr == NULL_TREE
997 || TREE_CODE (attr) != TREE_LIST)
998 return false;
999
1000 return (TREE_CODE (TREE_PURPOSE (attr)) == TREE_LIST);
1001 }
1002
1003 /* Return the name of the attribute ATTR. This accessor works on GNU
1004 and C++11 (scoped) attributes.
1005
1006 Please read the comments of cxx11_attribute_p to understand the
1007 format of attributes. */
1008
1009 tree
1010 get_attribute_name (const_tree attr)
1011 {
1012 if (cxx11_attribute_p (attr))
1013 return TREE_VALUE (TREE_PURPOSE (attr));
1014 return TREE_PURPOSE (attr);
1015 }
1016
1017 /* Subroutine of set_method_tm_attributes. Apply TM attribute ATTR
1018 to the method FNDECL. */
1019
1020 void
1021 apply_tm_attr (tree fndecl, tree attr)
1022 {
1023 decl_attributes (&TREE_TYPE (fndecl), tree_cons (attr, NULL, NULL), 0);
1024 }
1025
1026 /* Makes a function attribute of the form NAME(ARG_NAME) and chains
1027 it to CHAIN. */
1028
1029 tree
1030 make_attribute (const char *name, const char *arg_name, tree chain)
1031 {
1032 tree attr_name;
1033 tree attr_arg_name;
1034 tree attr_args;
1035 tree attr;
1036
1037 attr_name = get_identifier (name);
1038 attr_arg_name = build_string (strlen (arg_name), arg_name);
1039 attr_args = tree_cons (NULL_TREE, attr_arg_name, NULL_TREE);
1040 attr = tree_cons (attr_name, attr_args, chain);
1041 return attr;
1042 }
1043
1044 \f
1045 /* Common functions used for target clone support. */
1046
1047 /* Comparator function to be used in qsort routine to sort attribute
1048 specification strings to "target". */
1049
1050 static int
1051 attr_strcmp (const void *v1, const void *v2)
1052 {
1053 const char *c1 = *(char *const*)v1;
1054 const char *c2 = *(char *const*)v2;
1055 return strcmp (c1, c2);
1056 }
1057
1058 /* ARGLIST is the argument to target attribute. This function tokenizes
1059 the comma separated arguments, sorts them and returns a string which
1060 is a unique identifier for the comma separated arguments. It also
1061 replaces non-identifier characters "=,-" with "_". */
1062
1063 char *
1064 sorted_attr_string (tree arglist)
1065 {
1066 tree arg;
1067 size_t str_len_sum = 0;
1068 char **args = NULL;
1069 char *attr_str, *ret_str;
1070 char *attr = NULL;
1071 unsigned int argnum = 1;
1072 unsigned int i;
1073
1074 for (arg = arglist; arg; arg = TREE_CHAIN (arg))
1075 {
1076 const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
1077 size_t len = strlen (str);
1078 str_len_sum += len + 1;
1079 if (arg != arglist)
1080 argnum++;
1081 for (i = 0; i < strlen (str); i++)
1082 if (str[i] == ',')
1083 argnum++;
1084 }
1085
1086 attr_str = XNEWVEC (char, str_len_sum);
1087 str_len_sum = 0;
1088 for (arg = arglist; arg; arg = TREE_CHAIN (arg))
1089 {
1090 const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
1091 size_t len = strlen (str);
1092 memcpy (attr_str + str_len_sum, str, len);
1093 attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
1094 str_len_sum += len + 1;
1095 }
1096
1097 /* Replace "=,-" with "_". */
1098 for (i = 0; i < strlen (attr_str); i++)
1099 if (attr_str[i] == '=' || attr_str[i]== '-')
1100 attr_str[i] = '_';
1101
1102 if (argnum == 1)
1103 return attr_str;
1104
1105 args = XNEWVEC (char *, argnum);
1106
1107 i = 0;
1108 attr = strtok (attr_str, ",");
1109 while (attr != NULL)
1110 {
1111 args[i] = attr;
1112 i++;
1113 attr = strtok (NULL, ",");
1114 }
1115
1116 qsort (args, argnum, sizeof (char *), attr_strcmp);
1117
1118 ret_str = XNEWVEC (char, str_len_sum);
1119 str_len_sum = 0;
1120 for (i = 0; i < argnum; i++)
1121 {
1122 size_t len = strlen (args[i]);
1123 memcpy (ret_str + str_len_sum, args[i], len);
1124 ret_str[str_len_sum + len] = i < argnum - 1 ? '_' : '\0';
1125 str_len_sum += len + 1;
1126 }
1127
1128 XDELETEVEC (args);
1129 XDELETEVEC (attr_str);
1130 return ret_str;
1131 }
1132
1133
1134 /* This function returns true if FN1 and FN2 are versions of the same function,
1135 that is, the target strings of the function decls are different. This assumes
1136 that FN1 and FN2 have the same signature. */
1137
1138 bool
1139 common_function_versions (tree fn1, tree fn2)
1140 {
1141 tree attr1, attr2;
1142 char *target1, *target2;
1143 bool result;
1144
1145 if (TREE_CODE (fn1) != FUNCTION_DECL
1146 || TREE_CODE (fn2) != FUNCTION_DECL)
1147 return false;
1148
1149 attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
1150 attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
1151
1152 /* At least one function decl should have the target attribute specified. */
1153 if (attr1 == NULL_TREE && attr2 == NULL_TREE)
1154 return false;
1155
1156 /* Diagnose missing target attribute if one of the decls is already
1157 multi-versioned. */
1158 if (attr1 == NULL_TREE || attr2 == NULL_TREE)
1159 {
1160 if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
1161 {
1162 if (attr2 != NULL_TREE)
1163 {
1164 std::swap (fn1, fn2);
1165 attr1 = attr2;
1166 }
1167 error_at (DECL_SOURCE_LOCATION (fn2),
1168 "missing %<target%> attribute for multi-versioned %qD",
1169 fn2);
1170 inform (DECL_SOURCE_LOCATION (fn1),
1171 "previous declaration of %qD", fn1);
1172 /* Prevent diagnosing of the same error multiple times. */
1173 DECL_ATTRIBUTES (fn2)
1174 = tree_cons (get_identifier ("target"),
1175 copy_node (TREE_VALUE (attr1)),
1176 DECL_ATTRIBUTES (fn2));
1177 }
1178 return false;
1179 }
1180
1181 target1 = sorted_attr_string (TREE_VALUE (attr1));
1182 target2 = sorted_attr_string (TREE_VALUE (attr2));
1183
1184 /* The sorted target strings must be different for fn1 and fn2
1185 to be versions. */
1186 if (strcmp (target1, target2) == 0)
1187 result = false;
1188 else
1189 result = true;
1190
1191 XDELETEVEC (target1);
1192 XDELETEVEC (target2);
1193
1194 return result;
1195 }
1196
1197 /* Make a dispatcher declaration for the multi-versioned function DECL.
1198 Calls to DECL function will be replaced with calls to the dispatcher
1199 by the front-end. Return the decl created. */
1200
1201 tree
1202 make_dispatcher_decl (const tree decl)
1203 {
1204 tree func_decl;
1205 char *func_name;
1206 tree fn_type, func_type;
1207
1208 func_name = xstrdup (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1209
1210 fn_type = TREE_TYPE (decl);
1211 func_type = build_function_type (TREE_TYPE (fn_type),
1212 TYPE_ARG_TYPES (fn_type));
1213
1214 func_decl = build_fn_decl (func_name, func_type);
1215 XDELETEVEC (func_name);
1216 TREE_USED (func_decl) = 1;
1217 DECL_CONTEXT (func_decl) = NULL_TREE;
1218 DECL_INITIAL (func_decl) = error_mark_node;
1219 DECL_ARTIFICIAL (func_decl) = 1;
1220 /* Mark this func as external, the resolver will flip it again if
1221 it gets generated. */
1222 DECL_EXTERNAL (func_decl) = 1;
1223 /* This will be of type IFUNCs have to be externally visible. */
1224 TREE_PUBLIC (func_decl) = 1;
1225
1226 return func_decl;
1227 }
1228
1229 /* Returns true if decl is multi-versioned and DECL is the default function,
1230 that is it is not tagged with target specific optimization. */
1231
1232 bool
1233 is_function_default_version (const tree decl)
1234 {
1235 if (TREE_CODE (decl) != FUNCTION_DECL
1236 || !DECL_FUNCTION_VERSIONED (decl))
1237 return false;
1238 tree attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
1239 gcc_assert (attr);
1240 attr = TREE_VALUE (TREE_VALUE (attr));
1241 return (TREE_CODE (attr) == STRING_CST
1242 && strcmp (TREE_STRING_POINTER (attr), "default") == 0);
1243 }
1244
1245 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
1246 is ATTRIBUTE. */
1247
1248 tree
1249 build_decl_attribute_variant (tree ddecl, tree attribute)
1250 {
1251 DECL_ATTRIBUTES (ddecl) = attribute;
1252 return ddecl;
1253 }
1254
1255 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
1256 is ATTRIBUTE and its qualifiers are QUALS.
1257
1258 Record such modified types already made so we don't make duplicates. */
1259
1260 tree
1261 build_type_attribute_qual_variant (tree otype, tree attribute, int quals)
1262 {
1263 tree ttype = otype;
1264 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
1265 {
1266 tree ntype;
1267
1268 /* Building a distinct copy of a tagged type is inappropriate; it
1269 causes breakage in code that expects there to be a one-to-one
1270 relationship between a struct and its fields.
1271 build_duplicate_type is another solution (as used in
1272 handle_transparent_union_attribute), but that doesn't play well
1273 with the stronger C++ type identity model. */
1274 if (TREE_CODE (ttype) == RECORD_TYPE
1275 || TREE_CODE (ttype) == UNION_TYPE
1276 || TREE_CODE (ttype) == QUAL_UNION_TYPE
1277 || TREE_CODE (ttype) == ENUMERAL_TYPE)
1278 {
1279 warning (OPT_Wattributes,
1280 "ignoring attributes applied to %qT after definition",
1281 TYPE_MAIN_VARIANT (ttype));
1282 return build_qualified_type (ttype, quals);
1283 }
1284
1285 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
1286 if (lang_hooks.types.copy_lang_qualifiers
1287 && otype != TYPE_MAIN_VARIANT (otype))
1288 ttype = (lang_hooks.types.copy_lang_qualifiers
1289 (ttype, TYPE_MAIN_VARIANT (otype)));
1290
1291 tree dtype = ntype = build_distinct_type_copy (ttype);
1292
1293 TYPE_ATTRIBUTES (ntype) = attribute;
1294
1295 hashval_t hash = type_hash_canon_hash (ntype);
1296 ntype = type_hash_canon (hash, ntype);
1297
1298 if (ntype != dtype)
1299 /* This variant was already in the hash table, don't mess with
1300 TYPE_CANONICAL. */;
1301 else if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
1302 || !comp_type_attributes (ntype, ttype))
1303 /* If the target-dependent attributes make NTYPE different from
1304 its canonical type, we will need to use structural equality
1305 checks for this type.
1306
1307 We shouldn't get here for stripping attributes from a type;
1308 the no-attribute type might not need structural comparison. But
1309 we can if was discarded from type_hash_table. */
1310 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
1311 else if (TYPE_CANONICAL (ntype) == ntype)
1312 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
1313
1314 ttype = build_qualified_type (ntype, quals);
1315 if (lang_hooks.types.copy_lang_qualifiers
1316 && otype != TYPE_MAIN_VARIANT (otype))
1317 ttype = lang_hooks.types.copy_lang_qualifiers (ttype, otype);
1318 }
1319 else if (TYPE_QUALS (ttype) != quals)
1320 ttype = build_qualified_type (ttype, quals);
1321
1322 return ttype;
1323 }
1324
1325 /* Compare two identifier nodes representing attributes.
1326 Return true if they are the same, false otherwise. */
1327
1328 static bool
1329 cmp_attrib_identifiers (const_tree attr1, const_tree attr2)
1330 {
1331 /* Make sure we're dealing with IDENTIFIER_NODEs. */
1332 gcc_checking_assert (TREE_CODE (attr1) == IDENTIFIER_NODE
1333 && TREE_CODE (attr2) == IDENTIFIER_NODE);
1334
1335 /* Identifiers can be compared directly for equality. */
1336 if (attr1 == attr2)
1337 return true;
1338
1339 return cmp_attribs (IDENTIFIER_POINTER (attr1), IDENTIFIER_LENGTH (attr1),
1340 IDENTIFIER_POINTER (attr2), IDENTIFIER_LENGTH (attr2));
1341 }
1342
1343 /* Compare two constructor-element-type constants. Return 1 if the lists
1344 are known to be equal; otherwise return 0. */
1345
1346 bool
1347 simple_cst_list_equal (const_tree l1, const_tree l2)
1348 {
1349 while (l1 != NULL_TREE && l2 != NULL_TREE)
1350 {
1351 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
1352 return false;
1353
1354 l1 = TREE_CHAIN (l1);
1355 l2 = TREE_CHAIN (l2);
1356 }
1357
1358 return l1 == l2;
1359 }
1360
1361 /* Check if "omp declare simd" attribute arguments, CLAUSES1 and CLAUSES2, are
1362 the same. */
1363
1364 static bool
1365 omp_declare_simd_clauses_equal (tree clauses1, tree clauses2)
1366 {
1367 tree cl1, cl2;
1368 for (cl1 = clauses1, cl2 = clauses2;
1369 cl1 && cl2;
1370 cl1 = OMP_CLAUSE_CHAIN (cl1), cl2 = OMP_CLAUSE_CHAIN (cl2))
1371 {
1372 if (OMP_CLAUSE_CODE (cl1) != OMP_CLAUSE_CODE (cl2))
1373 return false;
1374 if (OMP_CLAUSE_CODE (cl1) != OMP_CLAUSE_SIMDLEN)
1375 {
1376 if (simple_cst_equal (OMP_CLAUSE_DECL (cl1),
1377 OMP_CLAUSE_DECL (cl2)) != 1)
1378 return false;
1379 }
1380 switch (OMP_CLAUSE_CODE (cl1))
1381 {
1382 case OMP_CLAUSE_ALIGNED:
1383 if (simple_cst_equal (OMP_CLAUSE_ALIGNED_ALIGNMENT (cl1),
1384 OMP_CLAUSE_ALIGNED_ALIGNMENT (cl2)) != 1)
1385 return false;
1386 break;
1387 case OMP_CLAUSE_LINEAR:
1388 if (simple_cst_equal (OMP_CLAUSE_LINEAR_STEP (cl1),
1389 OMP_CLAUSE_LINEAR_STEP (cl2)) != 1)
1390 return false;
1391 break;
1392 case OMP_CLAUSE_SIMDLEN:
1393 if (simple_cst_equal (OMP_CLAUSE_SIMDLEN_EXPR (cl1),
1394 OMP_CLAUSE_SIMDLEN_EXPR (cl2)) != 1)
1395 return false;
1396 default:
1397 break;
1398 }
1399 }
1400 return true;
1401 }
1402
1403
1404 /* Compare two attributes for their value identity. Return true if the
1405 attribute values are known to be equal; otherwise return false. */
1406
1407 bool
1408 attribute_value_equal (const_tree attr1, const_tree attr2)
1409 {
1410 if (TREE_VALUE (attr1) == TREE_VALUE (attr2))
1411 return true;
1412
1413 if (TREE_VALUE (attr1) != NULL_TREE
1414 && TREE_CODE (TREE_VALUE (attr1)) == TREE_LIST
1415 && TREE_VALUE (attr2) != NULL_TREE
1416 && TREE_CODE (TREE_VALUE (attr2)) == TREE_LIST)
1417 {
1418 /* Handle attribute format. */
1419 if (is_attribute_p ("format", get_attribute_name (attr1)))
1420 {
1421 attr1 = TREE_VALUE (attr1);
1422 attr2 = TREE_VALUE (attr2);
1423 /* Compare the archetypes (printf/scanf/strftime/...). */
1424 if (!cmp_attrib_identifiers (TREE_VALUE (attr1), TREE_VALUE (attr2)))
1425 return false;
1426 /* Archetypes are the same. Compare the rest. */
1427 return (simple_cst_list_equal (TREE_CHAIN (attr1),
1428 TREE_CHAIN (attr2)) == 1);
1429 }
1430 return (simple_cst_list_equal (TREE_VALUE (attr1),
1431 TREE_VALUE (attr2)) == 1);
1432 }
1433
1434 if (TREE_VALUE (attr1)
1435 && TREE_CODE (TREE_VALUE (attr1)) == OMP_CLAUSE
1436 && TREE_VALUE (attr2)
1437 && TREE_CODE (TREE_VALUE (attr2)) == OMP_CLAUSE)
1438 return omp_declare_simd_clauses_equal (TREE_VALUE (attr1),
1439 TREE_VALUE (attr2));
1440
1441 return (simple_cst_equal (TREE_VALUE (attr1), TREE_VALUE (attr2)) == 1);
1442 }
1443
1444 /* Return 0 if the attributes for two types are incompatible, 1 if they
1445 are compatible, and 2 if they are nearly compatible (which causes a
1446 warning to be generated). */
1447 int
1448 comp_type_attributes (const_tree type1, const_tree type2)
1449 {
1450 const_tree a1 = TYPE_ATTRIBUTES (type1);
1451 const_tree a2 = TYPE_ATTRIBUTES (type2);
1452 const_tree a;
1453
1454 if (a1 == a2)
1455 return 1;
1456 for (a = a1; a != NULL_TREE; a = TREE_CHAIN (a))
1457 {
1458 const struct attribute_spec *as;
1459 const_tree attr;
1460
1461 as = lookup_attribute_spec (get_attribute_name (a));
1462 if (!as || as->affects_type_identity == false)
1463 continue;
1464
1465 attr = lookup_attribute (as->name, CONST_CAST_TREE (a2));
1466 if (!attr || !attribute_value_equal (a, attr))
1467 break;
1468 }
1469 if (!a)
1470 {
1471 for (a = a2; a != NULL_TREE; a = TREE_CHAIN (a))
1472 {
1473 const struct attribute_spec *as;
1474
1475 as = lookup_attribute_spec (get_attribute_name (a));
1476 if (!as || as->affects_type_identity == false)
1477 continue;
1478
1479 if (!lookup_attribute (as->name, CONST_CAST_TREE (a1)))
1480 break;
1481 /* We don't need to compare trees again, as we did this
1482 already in first loop. */
1483 }
1484 /* All types - affecting identity - are equal, so
1485 there is no need to call target hook for comparison. */
1486 if (!a)
1487 return 1;
1488 }
1489 if (lookup_attribute ("transaction_safe", CONST_CAST_TREE (a)))
1490 return 0;
1491 if ((lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (type1)) != NULL)
1492 ^ (lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (type2)) != NULL))
1493 return 0;
1494 /* As some type combinations - like default calling-convention - might
1495 be compatible, we have to call the target hook to get the final result. */
1496 return targetm.comp_type_attributes (type1, type2);
1497 }
1498
1499 /* PREDICATE acts as a function of type:
1500
1501 (const_tree attr, const attribute_spec *as) -> bool
1502
1503 where ATTR is an attribute and AS is its possibly-null specification.
1504 Return a list of every attribute in attribute list ATTRS for which
1505 PREDICATE is true. Return ATTRS itself if PREDICATE returns true
1506 for every attribute. */
1507
1508 template<typename Predicate>
1509 tree
1510 remove_attributes_matching (tree attrs, Predicate predicate)
1511 {
1512 tree new_attrs = NULL_TREE;
1513 tree *ptr = &new_attrs;
1514 const_tree start = attrs;
1515 for (const_tree attr = attrs; attr; attr = TREE_CHAIN (attr))
1516 {
1517 tree name = get_attribute_name (attr);
1518 const attribute_spec *as = lookup_attribute_spec (name);
1519 const_tree end;
1520 if (!predicate (attr, as))
1521 end = attr;
1522 else if (start == attrs)
1523 continue;
1524 else
1525 end = TREE_CHAIN (attr);
1526
1527 for (; start != end; start = TREE_CHAIN (start))
1528 {
1529 *ptr = tree_cons (TREE_PURPOSE (start),
1530 TREE_VALUE (start), NULL_TREE);
1531 TREE_CHAIN (*ptr) = NULL_TREE;
1532 ptr = &TREE_CHAIN (*ptr);
1533 }
1534 start = TREE_CHAIN (attr);
1535 }
1536 gcc_assert (!start || start == attrs);
1537 return start ? attrs : new_attrs;
1538 }
1539
1540 /* If VALUE is true, return the subset of ATTRS that affect type identity,
1541 otherwise return the subset of ATTRS that don't affect type identity. */
1542
1543 tree
1544 affects_type_identity_attributes (tree attrs, bool value)
1545 {
1546 auto predicate = [value](const_tree, const attribute_spec *as) -> bool
1547 {
1548 return bool (as && as->affects_type_identity) == value;
1549 };
1550 return remove_attributes_matching (attrs, predicate);
1551 }
1552
1553 /* Remove attributes that affect type identity from ATTRS unless the
1554 same attributes occur in OK_ATTRS. */
1555
1556 tree
1557 restrict_type_identity_attributes_to (tree attrs, tree ok_attrs)
1558 {
1559 auto predicate = [ok_attrs](const_tree attr,
1560 const attribute_spec *as) -> bool
1561 {
1562 if (!as || !as->affects_type_identity)
1563 return true;
1564
1565 for (tree ok_attr = lookup_attribute (as->name, ok_attrs);
1566 ok_attr;
1567 ok_attr = lookup_attribute (as->name, TREE_CHAIN (ok_attr)))
1568 if (simple_cst_equal (TREE_VALUE (ok_attr), TREE_VALUE (attr)) == 1)
1569 return true;
1570
1571 return false;
1572 };
1573 return remove_attributes_matching (attrs, predicate);
1574 }
1575
1576 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
1577 is ATTRIBUTE.
1578
1579 Record such modified types already made so we don't make duplicates. */
1580
1581 tree
1582 build_type_attribute_variant (tree ttype, tree attribute)
1583 {
1584 return build_type_attribute_qual_variant (ttype, attribute,
1585 TYPE_QUALS (ttype));
1586 }
1587 \f
1588 /* A variant of lookup_attribute() that can be used with an identifier
1589 as the first argument, and where the identifier can be either
1590 'text' or '__text__'.
1591
1592 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
1593 return a pointer to the attribute's list element if the attribute
1594 is part of the list, or NULL_TREE if not found. If the attribute
1595 appears more than once, this only returns the first occurrence; the
1596 TREE_CHAIN of the return value should be passed back in if further
1597 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
1598 can be in the form 'text' or '__text__'. */
1599 static tree
1600 lookup_ident_attribute (tree attr_identifier, tree list)
1601 {
1602 gcc_checking_assert (TREE_CODE (attr_identifier) == IDENTIFIER_NODE);
1603
1604 while (list)
1605 {
1606 gcc_checking_assert (TREE_CODE (get_attribute_name (list))
1607 == IDENTIFIER_NODE);
1608
1609 if (cmp_attrib_identifiers (attr_identifier,
1610 get_attribute_name (list)))
1611 /* Found it. */
1612 break;
1613 list = TREE_CHAIN (list);
1614 }
1615
1616 return list;
1617 }
1618
1619 /* Remove any instances of attribute ATTR_NAME in LIST and return the
1620 modified list. */
1621
1622 tree
1623 remove_attribute (const char *attr_name, tree list)
1624 {
1625 tree *p;
1626 gcc_checking_assert (attr_name[0] != '_');
1627
1628 for (p = &list; *p;)
1629 {
1630 tree l = *p;
1631
1632 tree attr = get_attribute_name (l);
1633 if (is_attribute_p (attr_name, attr))
1634 *p = TREE_CHAIN (l);
1635 else
1636 p = &TREE_CHAIN (l);
1637 }
1638
1639 return list;
1640 }
1641
1642 /* Return an attribute list that is the union of a1 and a2. */
1643
1644 tree
1645 merge_attributes (tree a1, tree a2)
1646 {
1647 tree attributes;
1648
1649 /* Either one unset? Take the set one. */
1650
1651 if ((attributes = a1) == 0)
1652 attributes = a2;
1653
1654 /* One that completely contains the other? Take it. */
1655
1656 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
1657 {
1658 if (attribute_list_contained (a2, a1))
1659 attributes = a2;
1660 else
1661 {
1662 /* Pick the longest list, and hang on the other list. */
1663
1664 if (list_length (a1) < list_length (a2))
1665 attributes = a2, a2 = a1;
1666
1667 for (; a2 != 0; a2 = TREE_CHAIN (a2))
1668 {
1669 tree a;
1670 for (a = lookup_ident_attribute (get_attribute_name (a2),
1671 attributes);
1672 a != NULL_TREE && !attribute_value_equal (a, a2);
1673 a = lookup_ident_attribute (get_attribute_name (a2),
1674 TREE_CHAIN (a)))
1675 ;
1676 if (a == NULL_TREE)
1677 {
1678 a1 = copy_node (a2);
1679 TREE_CHAIN (a1) = attributes;
1680 attributes = a1;
1681 }
1682 }
1683 }
1684 }
1685 return attributes;
1686 }
1687
1688 /* Given types T1 and T2, merge their attributes and return
1689 the result. */
1690
1691 tree
1692 merge_type_attributes (tree t1, tree t2)
1693 {
1694 return merge_attributes (TYPE_ATTRIBUTES (t1),
1695 TYPE_ATTRIBUTES (t2));
1696 }
1697
1698 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
1699 the result. */
1700
1701 tree
1702 merge_decl_attributes (tree olddecl, tree newdecl)
1703 {
1704 return merge_attributes (DECL_ATTRIBUTES (olddecl),
1705 DECL_ATTRIBUTES (newdecl));
1706 }
1707
1708 /* Duplicate all attributes with name NAME in ATTR list to *ATTRS if
1709 they are missing there. */
1710
1711 void
1712 duplicate_one_attribute (tree *attrs, tree attr, const char *name)
1713 {
1714 attr = lookup_attribute (name, attr);
1715 if (!attr)
1716 return;
1717 tree a = lookup_attribute (name, *attrs);
1718 while (attr)
1719 {
1720 tree a2;
1721 for (a2 = a; a2; a2 = lookup_attribute (name, TREE_CHAIN (a2)))
1722 if (attribute_value_equal (attr, a2))
1723 break;
1724 if (!a2)
1725 {
1726 a2 = copy_node (attr);
1727 TREE_CHAIN (a2) = *attrs;
1728 *attrs = a2;
1729 }
1730 attr = lookup_attribute (name, TREE_CHAIN (attr));
1731 }
1732 }
1733
1734 /* Duplicate all attributes from user DECL to the corresponding
1735 builtin that should be propagated. */
1736
1737 void
1738 copy_attributes_to_builtin (tree decl)
1739 {
1740 tree b = builtin_decl_explicit (DECL_FUNCTION_CODE (decl));
1741 if (b)
1742 duplicate_one_attribute (&DECL_ATTRIBUTES (b),
1743 DECL_ATTRIBUTES (decl), "omp declare simd");
1744 }
1745
1746 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
1747
1748 /* Specialization of merge_decl_attributes for various Windows targets.
1749
1750 This handles the following situation:
1751
1752 __declspec (dllimport) int foo;
1753 int foo;
1754
1755 The second instance of `foo' nullifies the dllimport. */
1756
1757 tree
1758 merge_dllimport_decl_attributes (tree old, tree new_tree)
1759 {
1760 tree a;
1761 int delete_dllimport_p = 1;
1762
1763 /* What we need to do here is remove from `old' dllimport if it doesn't
1764 appear in `new'. dllimport behaves like extern: if a declaration is
1765 marked dllimport and a definition appears later, then the object
1766 is not dllimport'd. We also remove a `new' dllimport if the old list
1767 contains dllexport: dllexport always overrides dllimport, regardless
1768 of the order of declaration. */
1769 if (!VAR_OR_FUNCTION_DECL_P (new_tree))
1770 delete_dllimport_p = 0;
1771 else if (DECL_DLLIMPORT_P (new_tree)
1772 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
1773 {
1774 DECL_DLLIMPORT_P (new_tree) = 0;
1775 warning (OPT_Wattributes, "%q+D already declared with dllexport "
1776 "attribute: dllimport ignored", new_tree);
1777 }
1778 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new_tree))
1779 {
1780 /* Warn about overriding a symbol that has already been used, e.g.:
1781 extern int __attribute__ ((dllimport)) foo;
1782 int* bar () {return &foo;}
1783 int foo;
1784 */
1785 if (TREE_USED (old))
1786 {
1787 warning (0, "%q+D redeclared without dllimport attribute "
1788 "after being referenced with dll linkage", new_tree);
1789 /* If we have used a variable's address with dllimport linkage,
1790 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
1791 decl may already have had TREE_CONSTANT computed.
1792 We still remove the attribute so that assembler code refers
1793 to '&foo rather than '_imp__foo'. */
1794 if (VAR_P (old) && TREE_ADDRESSABLE (old))
1795 DECL_DLLIMPORT_P (new_tree) = 1;
1796 }
1797
1798 /* Let an inline definition silently override the external reference,
1799 but otherwise warn about attribute inconsistency. */
1800 else if (VAR_P (new_tree) || !DECL_DECLARED_INLINE_P (new_tree))
1801 warning (OPT_Wattributes, "%q+D redeclared without dllimport "
1802 "attribute: previous dllimport ignored", new_tree);
1803 }
1804 else
1805 delete_dllimport_p = 0;
1806
1807 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new_tree));
1808
1809 if (delete_dllimport_p)
1810 a = remove_attribute ("dllimport", a);
1811
1812 return a;
1813 }
1814
1815 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
1816 struct attribute_spec.handler. */
1817
1818 tree
1819 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
1820 bool *no_add_attrs)
1821 {
1822 tree node = *pnode;
1823 bool is_dllimport;
1824
1825 /* These attributes may apply to structure and union types being created,
1826 but otherwise should pass to the declaration involved. */
1827 if (!DECL_P (node))
1828 {
1829 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
1830 | (int) ATTR_FLAG_ARRAY_NEXT))
1831 {
1832 *no_add_attrs = true;
1833 return tree_cons (name, args, NULL_TREE);
1834 }
1835 if (TREE_CODE (node) == RECORD_TYPE
1836 || TREE_CODE (node) == UNION_TYPE)
1837 {
1838 node = TYPE_NAME (node);
1839 if (!node)
1840 return NULL_TREE;
1841 }
1842 else
1843 {
1844 warning (OPT_Wattributes, "%qE attribute ignored",
1845 name);
1846 *no_add_attrs = true;
1847 return NULL_TREE;
1848 }
1849 }
1850
1851 if (!VAR_OR_FUNCTION_DECL_P (node) && TREE_CODE (node) != TYPE_DECL)
1852 {
1853 *no_add_attrs = true;
1854 warning (OPT_Wattributes, "%qE attribute ignored",
1855 name);
1856 return NULL_TREE;
1857 }
1858
1859 if (TREE_CODE (node) == TYPE_DECL
1860 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
1861 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
1862 {
1863 *no_add_attrs = true;
1864 warning (OPT_Wattributes, "%qE attribute ignored",
1865 name);
1866 return NULL_TREE;
1867 }
1868
1869 is_dllimport = is_attribute_p ("dllimport", name);
1870
1871 /* Report error on dllimport ambiguities seen now before they cause
1872 any damage. */
1873 if (is_dllimport)
1874 {
1875 /* Honor any target-specific overrides. */
1876 if (!targetm.valid_dllimport_attribute_p (node))
1877 *no_add_attrs = true;
1878
1879 else if (TREE_CODE (node) == FUNCTION_DECL
1880 && DECL_DECLARED_INLINE_P (node))
1881 {
1882 warning (OPT_Wattributes, "inline function %q+D declared as "
1883 "dllimport: attribute ignored", node);
1884 *no_add_attrs = true;
1885 }
1886 /* Like MS, treat definition of dllimported variables and
1887 non-inlined functions on declaration as syntax errors. */
1888 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
1889 {
1890 error ("function %q+D definition is marked dllimport", node);
1891 *no_add_attrs = true;
1892 }
1893
1894 else if (VAR_P (node))
1895 {
1896 if (DECL_INITIAL (node))
1897 {
1898 error ("variable %q+D definition is marked dllimport",
1899 node);
1900 *no_add_attrs = true;
1901 }
1902
1903 /* `extern' needn't be specified with dllimport.
1904 Specify `extern' now and hope for the best. Sigh. */
1905 DECL_EXTERNAL (node) = 1;
1906 /* Also, implicitly give dllimport'd variables declared within
1907 a function global scope, unless declared static. */
1908 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
1909 TREE_PUBLIC (node) = 1;
1910 /* Clear TREE_STATIC because DECL_EXTERNAL is set, unless
1911 it is a C++ static data member. */
1912 if (DECL_CONTEXT (node) == NULL_TREE
1913 || !RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (node)))
1914 TREE_STATIC (node) = 0;
1915 }
1916
1917 if (*no_add_attrs == false)
1918 DECL_DLLIMPORT_P (node) = 1;
1919 }
1920 else if (TREE_CODE (node) == FUNCTION_DECL
1921 && DECL_DECLARED_INLINE_P (node)
1922 && flag_keep_inline_dllexport)
1923 /* An exported function, even if inline, must be emitted. */
1924 DECL_EXTERNAL (node) = 0;
1925
1926 /* Report error if symbol is not accessible at global scope. */
1927 if (!TREE_PUBLIC (node) && VAR_OR_FUNCTION_DECL_P (node))
1928 {
1929 error ("external linkage required for symbol %q+D because of "
1930 "%qE attribute", node, name);
1931 *no_add_attrs = true;
1932 }
1933
1934 /* A dllexport'd entity must have default visibility so that other
1935 program units (shared libraries or the main executable) can see
1936 it. A dllimport'd entity must have default visibility so that
1937 the linker knows that undefined references within this program
1938 unit can be resolved by the dynamic linker. */
1939 if (!*no_add_attrs)
1940 {
1941 if (DECL_VISIBILITY_SPECIFIED (node)
1942 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
1943 error ("%qE implies default visibility, but %qD has already "
1944 "been declared with a different visibility",
1945 name, node);
1946 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
1947 DECL_VISIBILITY_SPECIFIED (node) = 1;
1948 }
1949
1950 return NULL_TREE;
1951 }
1952
1953 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
1954
1955 /* Given two lists of attributes, return true if list l2 is
1956 equivalent to l1. */
1957
1958 int
1959 attribute_list_equal (const_tree l1, const_tree l2)
1960 {
1961 if (l1 == l2)
1962 return 1;
1963
1964 return attribute_list_contained (l1, l2)
1965 && attribute_list_contained (l2, l1);
1966 }
1967
1968 /* Given two lists of attributes, return true if list L2 is
1969 completely contained within L1. */
1970 /* ??? This would be faster if attribute names were stored in a canonicalized
1971 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
1972 must be used to show these elements are equivalent (which they are). */
1973 /* ??? It's not clear that attributes with arguments will always be handled
1974 correctly. */
1975
1976 int
1977 attribute_list_contained (const_tree l1, const_tree l2)
1978 {
1979 const_tree t1, t2;
1980
1981 /* First check the obvious, maybe the lists are identical. */
1982 if (l1 == l2)
1983 return 1;
1984
1985 /* Maybe the lists are similar. */
1986 for (t1 = l1, t2 = l2;
1987 t1 != 0 && t2 != 0
1988 && get_attribute_name (t1) == get_attribute_name (t2)
1989 && TREE_VALUE (t1) == TREE_VALUE (t2);
1990 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1991 ;
1992
1993 /* Maybe the lists are equal. */
1994 if (t1 == 0 && t2 == 0)
1995 return 1;
1996
1997 for (; t2 != 0; t2 = TREE_CHAIN (t2))
1998 {
1999 const_tree attr;
2000 /* This CONST_CAST is okay because lookup_attribute does not
2001 modify its argument and the return value is assigned to a
2002 const_tree. */
2003 for (attr = lookup_ident_attribute (get_attribute_name (t2),
2004 CONST_CAST_TREE (l1));
2005 attr != NULL_TREE && !attribute_value_equal (t2, attr);
2006 attr = lookup_ident_attribute (get_attribute_name (t2),
2007 TREE_CHAIN (attr)))
2008 ;
2009
2010 if (attr == NULL_TREE)
2011 return 0;
2012 }
2013
2014 return 1;
2015 }
2016
2017 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
2018 of ATTR_NAME, and LIST is not NULL_TREE.
2019
2020 The function is called from lookup_attribute in order to optimize
2021 for size. */
2022
2023 tree
2024 private_lookup_attribute (const char *attr_name, size_t attr_len, tree list)
2025 {
2026 while (list)
2027 {
2028 tree attr = get_attribute_name (list);
2029 size_t ident_len = IDENTIFIER_LENGTH (attr);
2030 if (cmp_attribs (attr_name, attr_len, IDENTIFIER_POINTER (attr),
2031 ident_len))
2032 break;
2033 list = TREE_CHAIN (list);
2034 }
2035
2036 return list;
2037 }
2038
2039 /* Return true if the function decl or type NODE has been declared
2040 with attribute ANAME among attributes ATTRS. */
2041
2042 static bool
2043 has_attribute (tree node, tree attrs, const char *aname)
2044 {
2045 if (!strcmp (aname, "const"))
2046 {
2047 if (DECL_P (node) && TREE_READONLY (node))
2048 return true;
2049 }
2050 else if (!strcmp (aname, "malloc"))
2051 {
2052 if (DECL_P (node) && DECL_IS_MALLOC (node))
2053 return true;
2054 }
2055 else if (!strcmp (aname, "noreturn"))
2056 {
2057 if (DECL_P (node) && TREE_THIS_VOLATILE (node))
2058 return true;
2059 }
2060 else if (!strcmp (aname, "nothrow"))
2061 {
2062 if (TREE_NOTHROW (node))
2063 return true;
2064 }
2065 else if (!strcmp (aname, "pure"))
2066 {
2067 if (DECL_P (node) && DECL_PURE_P (node))
2068 return true;
2069 }
2070
2071 return lookup_attribute (aname, attrs);
2072 }
2073
2074 /* Return the number of mismatched function or type attributes between
2075 the "template" function declaration TMPL and DECL. The word "template"
2076 doesn't necessarily refer to a C++ template but rather a declaration
2077 whose attributes should be matched by those on DECL. For a non-zero
2078 return value set *ATTRSTR to a string representation of the list of
2079 mismatched attributes with quoted names.
2080 ATTRLIST is a list of additional attributes that SPEC should be
2081 taken to ultimately be declared with. */
2082
2083 unsigned
2084 decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
2085 const char* const blacklist[],
2086 pretty_printer *attrstr)
2087 {
2088 if (TREE_CODE (tmpl) != FUNCTION_DECL)
2089 return 0;
2090
2091 /* Avoid warning if either declaration or its type is deprecated. */
2092 if (TREE_DEPRECATED (tmpl)
2093 || TREE_DEPRECATED (decl))
2094 return 0;
2095
2096 const tree tmpls[] = { tmpl, TREE_TYPE (tmpl) };
2097 const tree decls[] = { decl, TREE_TYPE (decl) };
2098
2099 if (TREE_DEPRECATED (tmpls[1])
2100 || TREE_DEPRECATED (decls[1])
2101 || TREE_DEPRECATED (TREE_TYPE (tmpls[1]))
2102 || TREE_DEPRECATED (TREE_TYPE (decls[1])))
2103 return 0;
2104
2105 tree tmpl_attrs[] = { DECL_ATTRIBUTES (tmpl), TYPE_ATTRIBUTES (tmpls[1]) };
2106 tree decl_attrs[] = { DECL_ATTRIBUTES (decl), TYPE_ATTRIBUTES (decls[1]) };
2107
2108 if (!decl_attrs[0])
2109 decl_attrs[0] = attrlist;
2110 else if (!decl_attrs[1])
2111 decl_attrs[1] = attrlist;
2112
2113 /* Avoid warning if the template has no attributes. */
2114 if (!tmpl_attrs[0] && !tmpl_attrs[1])
2115 return 0;
2116
2117 /* Avoid warning if either declaration contains an attribute on
2118 the white list below. */
2119 const char* const whitelist[] = {
2120 "error", "warning"
2121 };
2122
2123 for (unsigned i = 0; i != 2; ++i)
2124 for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
2125 if (lookup_attribute (whitelist[j], tmpl_attrs[i])
2126 || lookup_attribute (whitelist[j], decl_attrs[i]))
2127 return 0;
2128
2129 /* Put together a list of the black-listed attributes that the template
2130 is declared with and the declaration is not, in case it's not apparent
2131 from the most recent declaration of the template. */
2132 unsigned nattrs = 0;
2133
2134 for (unsigned i = 0; blacklist[i]; ++i)
2135 {
2136 /* Attribute leaf only applies to extern functions. Avoid mentioning
2137 it when it's missing from a static declaration. */
2138 if (!TREE_PUBLIC (decl)
2139 && !strcmp ("leaf", blacklist[i]))
2140 continue;
2141
2142 for (unsigned j = 0; j != 2; ++j)
2143 {
2144 if (!has_attribute (tmpls[j], tmpl_attrs[j], blacklist[i]))
2145 continue;
2146
2147 bool found = false;
2148 unsigned kmax = 1 + !!decl_attrs[1];
2149 for (unsigned k = 0; k != kmax; ++k)
2150 {
2151 if (has_attribute (decls[k], decl_attrs[k], blacklist[i]))
2152 {
2153 found = true;
2154 break;
2155 }
2156 }
2157
2158 if (!found)
2159 {
2160 if (nattrs)
2161 pp_string (attrstr, ", ");
2162 pp_begin_quote (attrstr, pp_show_color (global_dc->printer));
2163 pp_string (attrstr, blacklist[i]);
2164 pp_end_quote (attrstr, pp_show_color (global_dc->printer));
2165 ++nattrs;
2166 }
2167
2168 break;
2169 }
2170 }
2171
2172 return nattrs;
2173 }
2174
2175 /* Issue a warning for the declaration ALIAS for TARGET where ALIAS
2176 specifies either attributes that are incompatible with those of
2177 TARGET, or attributes that are missing and that declaring ALIAS
2178 with would benefit. */
2179
2180 void
2181 maybe_diag_alias_attributes (tree alias, tree target)
2182 {
2183 /* Do not expect attributes to match between aliases and ifunc
2184 resolvers. There is no obvious correspondence between them. */
2185 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (alias)))
2186 return;
2187
2188 const char* const blacklist[] = {
2189 "alloc_align", "alloc_size", "cold", "const", "hot", "leaf", "malloc",
2190 "nonnull", "noreturn", "nothrow", "pure", "returns_nonnull",
2191 "returns_twice", NULL
2192 };
2193
2194 pretty_printer attrnames;
2195 if (warn_attribute_alias > 1)
2196 {
2197 /* With -Wattribute-alias=2 detect alias declarations that are more
2198 restrictive than their targets first. Those indicate potential
2199 codegen bugs. */
2200 if (unsigned n = decls_mismatched_attributes (alias, target, NULL_TREE,
2201 blacklist, &attrnames))
2202 {
2203 auto_diagnostic_group d;
2204 if (warning_n (DECL_SOURCE_LOCATION (alias),
2205 OPT_Wattribute_alias_, n,
2206 "%qD specifies more restrictive attribute than "
2207 "its target %qD: %s",
2208 "%qD specifies more restrictive attributes than "
2209 "its target %qD: %s",
2210 alias, target, pp_formatted_text (&attrnames)))
2211 inform (DECL_SOURCE_LOCATION (target),
2212 "%qD target declared here", alias);
2213 return;
2214 }
2215 }
2216
2217 /* Detect alias declarations that are less restrictive than their
2218 targets. Those suggest potential optimization opportunities
2219 (solved by adding the missing attribute(s) to the alias). */
2220 if (unsigned n = decls_mismatched_attributes (target, alias, NULL_TREE,
2221 blacklist, &attrnames))
2222 {
2223 auto_diagnostic_group d;
2224 if (warning_n (DECL_SOURCE_LOCATION (alias),
2225 OPT_Wmissing_attributes, n,
2226 "%qD specifies less restrictive attribute than "
2227 "its target %qD: %s",
2228 "%qD specifies less restrictive attributes than "
2229 "its target %qD: %s",
2230 alias, target, pp_formatted_text (&attrnames)))
2231 inform (DECL_SOURCE_LOCATION (target),
2232 "%qD target declared here", alias);
2233 }
2234 }
2235
2236 /* Initialize a mapping RWM for a call to a function declared with
2237 attribute access in ATTRS. Each attribute positional operand
2238 inserts one entry into the mapping with the operand number as
2239 the key. */
2240
2241 void
2242 init_attr_rdwr_indices (rdwr_map *rwm, tree attrs)
2243 {
2244 if (!attrs)
2245 return;
2246
2247 for (tree access = attrs;
2248 (access = lookup_attribute ("access", access));
2249 access = TREE_CHAIN (access))
2250 {
2251 /* The TREE_VALUE of an attribute is a TREE_LIST whose TREE_VALUE
2252 is the attribute argument's value. */
2253 tree mode = TREE_VALUE (access);
2254 if (!mode)
2255 return;
2256
2257 /* The (optional) list of VLA bounds. */
2258 tree vblist = TREE_CHAIN (mode);
2259 mode = TREE_VALUE (mode);
2260 if (TREE_CODE (mode) != STRING_CST)
2261 continue;
2262 gcc_assert (TREE_CODE (mode) == STRING_CST);
2263
2264 if (vblist)
2265 vblist = nreverse (copy_list (TREE_VALUE (vblist)));
2266
2267 for (const char *m = TREE_STRING_POINTER (mode); *m; )
2268 {
2269 attr_access acc = { };
2270
2271 /* Skip the internal-only plus sign. */
2272 if (*m == '+')
2273 ++m;
2274
2275 acc.str = m;
2276 acc.mode = acc.from_mode_char (*m);
2277 acc.sizarg = UINT_MAX;
2278
2279 const char *end;
2280 acc.ptrarg = strtoul (++m, const_cast<char**>(&end), 10);
2281 m = end;
2282
2283 if (*m == '[')
2284 {
2285 /* Forms containing the square bracket are internal-only
2286 (not specified by an attribute declaration), and used
2287 for various forms of array and VLA parameters. */
2288 acc.internal_p = true;
2289
2290 /* Search to the closing bracket and look at the preceding
2291 code: it determines the form of the most significant
2292 bound of the array. Others prior to it encode the form
2293 of interior VLA bounds. They're not of interest here. */
2294 end = strchr (m, ']');
2295 const char *p = end;
2296 gcc_assert (p);
2297
2298 while (ISDIGIT (p[-1]))
2299 --p;
2300
2301 if (ISDIGIT (*p))
2302 {
2303 /* A digit denotes a constant bound (as in T[3]). */
2304 acc.static_p = p[-1] == 's';
2305 acc.minsize = strtoull (p, NULL, 10);
2306 }
2307 else if (' ' == p[-1])
2308 {
2309 /* A space denotes an ordinary array of unspecified bound
2310 (as in T[]). */
2311 acc.minsize = 0;
2312 }
2313 else if ('*' == p[-1] || '$' == p[-1])
2314 {
2315 /* An asterisk denotes a VLA. When the closing bracket
2316 is followed by a comma and a dollar sign its bound is
2317 on the list. Otherwise it's a VLA with an unspecified
2318 bound. */
2319 acc.static_p = p[-2] == 's';
2320 acc.minsize = HOST_WIDE_INT_M1U;
2321 }
2322
2323 m = end + 1;
2324 }
2325
2326 if (*m == ',')
2327 {
2328 ++m;
2329 do
2330 {
2331 if (*m == '$')
2332 {
2333 ++m;
2334 if (!acc.size && vblist)
2335 {
2336 /* Extract the list of VLA bounds for the current
2337 parameter, store it in ACC.SIZE, and advance
2338 to the list of bounds for the next VLA parameter.
2339 */
2340 acc.size = TREE_VALUE (vblist);
2341 vblist = TREE_CHAIN (vblist);
2342 }
2343 }
2344
2345 if (ISDIGIT (*m))
2346 {
2347 /* Extract the positional argument. It's absent
2348 for VLAs whose bound doesn't name a function
2349 parameter. */
2350 unsigned pos = strtoul (m, const_cast<char**>(&end), 10);
2351 if (acc.sizarg == UINT_MAX)
2352 acc.sizarg = pos;
2353 m = end;
2354 }
2355 }
2356 while (*m == '$');
2357 }
2358
2359 acc.end = m;
2360
2361 bool existing;
2362 auto &ref = rwm->get_or_insert (acc.ptrarg, &existing);
2363 if (existing)
2364 {
2365 /* Merge the new spec with the existing. */
2366 if (acc.minsize == HOST_WIDE_INT_M1U)
2367 ref.minsize = HOST_WIDE_INT_M1U;
2368
2369 if (acc.sizarg != UINT_MAX)
2370 ref.sizarg = acc.sizarg;
2371
2372 if (acc.mode)
2373 ref.mode = acc.mode;
2374 }
2375 else
2376 ref = acc;
2377
2378 /* Unconditionally add an entry for the required pointer
2379 operand of the attribute, and one for the optional size
2380 operand when it's specified. */
2381 if (acc.sizarg != UINT_MAX)
2382 rwm->put (acc.sizarg, acc);
2383 }
2384 }
2385 }
2386
2387 /* Return the access specification for a function parameter PARM
2388 or null if the current function has no such specification. */
2389
2390 attr_access *
2391 get_parm_access (rdwr_map &rdwr_idx, tree parm,
2392 tree fndecl /* = current_function_decl */)
2393 {
2394 tree fntype = TREE_TYPE (fndecl);
2395 init_attr_rdwr_indices (&rdwr_idx, TYPE_ATTRIBUTES (fntype));
2396
2397 if (rdwr_idx.is_empty ())
2398 return NULL;
2399
2400 unsigned argpos = 0;
2401 tree fnargs = DECL_ARGUMENTS (fndecl);
2402 for (tree arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
2403 if (arg == parm)
2404 return rdwr_idx.get (argpos);
2405
2406 return NULL;
2407 }
2408
2409 /* Return the internal representation as STRING_CST. Internal positional
2410 arguments are zero-based. */
2411
2412 tree
2413 attr_access::to_internal_string () const
2414 {
2415 return build_string (end - str, str);
2416 }
2417
2418 /* Return the human-readable representation of the external attribute
2419 specification (as it might appear in the source code) as STRING_CST.
2420 External positional arguments are one-based. */
2421
2422 tree
2423 attr_access::to_external_string () const
2424 {
2425 char buf[80];
2426 gcc_assert (mode != access_deferred);
2427 int len = snprintf (buf, sizeof buf, "access (%s, %u",
2428 mode_names[mode], ptrarg + 1);
2429 if (sizarg != UINT_MAX)
2430 len += snprintf (buf + len, sizeof buf - len, ", %u", sizarg + 1);
2431 strcpy (buf + len, ")");
2432 return build_string (len + 2, buf);
2433 }
2434
2435 /* Return the number of specified VLA bounds and set *nunspec to
2436 the number of unspecified ones (those designated by [*]). */
2437
2438 unsigned
2439 attr_access::vla_bounds (unsigned *nunspec) const
2440 {
2441 unsigned nbounds = 0;
2442 *nunspec = 0;
2443 /* STR points to the beginning of the specified string for the current
2444 argument that may be followed by the string for the next argument. */
2445 for (const char* p = strchr (str, ']'); p && *p != '['; --p)
2446 {
2447 if (*p == '*')
2448 ++*nunspec;
2449 else if (*p == '$')
2450 ++nbounds;
2451 }
2452 return nbounds;
2453 }
2454
2455 /* Reset front end-specific attribute access data from ATTRS.
2456 Called from the free_lang_data pass. */
2457
2458 /* static */ void
2459 attr_access::free_lang_data (tree attrs)
2460 {
2461 for (tree acs = attrs; (acs = lookup_attribute ("access", acs));
2462 acs = TREE_CHAIN (acs))
2463 {
2464 tree vblist = TREE_VALUE (acs);
2465 vblist = TREE_CHAIN (vblist);
2466 if (!vblist)
2467 continue;
2468
2469 for (vblist = TREE_VALUE (vblist); vblist; vblist = TREE_CHAIN (vblist))
2470 {
2471 tree *pvbnd = &TREE_VALUE (vblist);
2472 if (!*pvbnd || DECL_P (*pvbnd))
2473 continue;
2474
2475 /* VLA bounds that are expressions as opposed to DECLs are
2476 only used in the front end. Reset them to keep front end
2477 trees leaking into the middle end (see pr97172) and to
2478 free up memory. */
2479 *pvbnd = NULL_TREE;
2480 }
2481 }
2482
2483 for (tree argspec = attrs; (argspec = lookup_attribute ("arg spec", argspec));
2484 argspec = TREE_CHAIN (argspec))
2485 {
2486 /* Same as above. */
2487 tree *pvblist = &TREE_VALUE (argspec);
2488 *pvblist = NULL_TREE;
2489 }
2490 }
2491
2492 /* Defined in attr_access. */
2493 constexpr char attr_access::mode_chars[];
2494 constexpr char attr_access::mode_names[][11];
2495
2496 /* Format an array, including a VLA, pointed to by TYPE and used as
2497 a function parameter as a human-readable string. ACC describes
2498 an access to the parameter and is used to determine the outermost
2499 form of the array including its bound which is otherwise obviated
2500 by its decay to pointer. Return the formatted string. */
2501
2502 std::string
2503 attr_access::array_as_string (tree type) const
2504 {
2505 std::string typstr;
2506
2507 if (type == error_mark_node)
2508 return std::string ();
2509
2510 if (this->str)
2511 {
2512 /* For array parameters (but not pointers) create a temporary array
2513 type that corresponds to the form of the parameter including its
2514 qualifiers even though they apply to the pointer, not the array
2515 type. */
2516 const bool vla_p = minsize == HOST_WIDE_INT_M1U;
2517 tree eltype = TREE_TYPE (type);
2518 tree index_type = NULL_TREE;
2519
2520 if (minsize == HOST_WIDE_INT_M1U)
2521 {
2522 /* Determine if this is a VLA (an array whose most significant
2523 bound is nonconstant and whose access string has "$]" in it)
2524 extract the bound expression from SIZE. */
2525 const char *p = end;
2526 for ( ; p != str && *p-- != ']'; );
2527 if (*p == '$')
2528 /* SIZE may have been cleared. Use it with care. */
2529 index_type = build_index_type (size ? TREE_VALUE (size) : size);
2530 }
2531 else if (minsize)
2532 index_type = build_index_type (size_int (minsize - 1));
2533
2534 tree arat = NULL_TREE;
2535 if (static_p || vla_p)
2536 {
2537 tree flag = static_p ? integer_one_node : NULL_TREE;
2538 /* Hack: there's no language-independent way to encode
2539 the "static" specifier or the "*" notation in an array type.
2540 Add a "fake" attribute to have the pretty-printer add "static"
2541 or "*". The "[static N]" notation is only valid in the most
2542 significant bound but [*] can be used for any bound. Because
2543 [*] is represented the same as [0] this hack only works for
2544 the most significant bound like static and the others are
2545 rendered as [0]. */
2546 arat = build_tree_list (get_identifier ("array"), flag);
2547 }
2548
2549 const int quals = TYPE_QUALS (type);
2550 type = build_array_type (eltype, index_type);
2551 type = build_type_attribute_qual_variant (type, arat, quals);
2552 }
2553
2554 /* Format the type using the current pretty printer. The generic tree
2555 printer does a terrible job. */
2556 pretty_printer *pp = global_dc->printer->clone ();
2557 pp_printf (pp, "%qT", type);
2558 typstr = pp_formatted_text (pp);
2559 delete pp;
2560
2561 return typstr;
2562 }
2563
2564 #if CHECKING_P
2565
2566 namespace selftest
2567 {
2568
2569 /* Helper types to verify the consistency attribute exclusions. */
2570
2571 typedef std::pair<const char *, const char *> excl_pair;
2572
2573 struct excl_hash_traits: typed_noop_remove<excl_pair>
2574 {
2575 typedef excl_pair value_type;
2576 typedef value_type compare_type;
2577
2578 static hashval_t hash (const value_type &x)
2579 {
2580 hashval_t h1 = htab_hash_string (x.first);
2581 hashval_t h2 = htab_hash_string (x.second);
2582 return h1 ^ h2;
2583 }
2584
2585 static bool equal (const value_type &x, const value_type &y)
2586 {
2587 return !strcmp (x.first, y.first) && !strcmp (x.second, y.second);
2588 }
2589
2590 static void mark_deleted (value_type &x)
2591 {
2592 x = value_type (NULL, NULL);
2593 }
2594
2595 static const bool empty_zero_p = false;
2596
2597 static void mark_empty (value_type &x)
2598 {
2599 x = value_type ("", "");
2600 }
2601
2602 static bool is_deleted (const value_type &x)
2603 {
2604 return !x.first && !x.second;
2605 }
2606
2607 static bool is_empty (const value_type &x)
2608 {
2609 return !*x.first && !*x.second;
2610 }
2611 };
2612
2613
2614 /* Self-test to verify that each attribute exclusion is symmetric,
2615 meaning that if attribute A is encoded as incompatible with
2616 attribute B then the opposite relationship is also encoded.
2617 This test also detects most cases of misspelled attribute names
2618 in exclusions. */
2619
2620 static void
2621 test_attribute_exclusions ()
2622 {
2623 /* Iterate over the array of attribute tables first (with TI0 as
2624 the index) and over the array of attribute_spec in each table
2625 (with SI0 as the index). */
2626 const size_t ntables = ARRAY_SIZE (attribute_tables);
2627
2628 /* Set of pairs of mutually exclusive attributes. */
2629 typedef hash_set<excl_pair, false, excl_hash_traits> exclusion_set;
2630 exclusion_set excl_set;
2631
2632 for (size_t ti0 = 0; ti0 != ntables; ++ti0)
2633 for (size_t s0 = 0; attribute_tables[ti0][s0].name; ++s0)
2634 {
2635 const attribute_spec::exclusions *excl
2636 = attribute_tables[ti0][s0].exclude;
2637
2638 /* Skip each attribute that doesn't define exclusions. */
2639 if (!excl)
2640 continue;
2641
2642 const char *attr_name = attribute_tables[ti0][s0].name;
2643
2644 /* Iterate over the set of exclusions for every attribute
2645 (with EI0 as the index) adding the exclusions defined
2646 for each to the set. */
2647 for (size_t ei0 = 0; excl[ei0].name; ++ei0)
2648 {
2649 const char *excl_name = excl[ei0].name;
2650
2651 if (!strcmp (attr_name, excl_name))
2652 continue;
2653
2654 excl_set.add (excl_pair (attr_name, excl_name));
2655 }
2656 }
2657
2658 /* Traverse the set of mutually exclusive pairs of attributes
2659 and verify that they are symmetric. */
2660 for (exclusion_set::iterator it = excl_set.begin ();
2661 it != excl_set.end ();
2662 ++it)
2663 {
2664 if (!excl_set.contains (excl_pair ((*it).second, (*it).first)))
2665 {
2666 /* An exclusion for an attribute has been found that
2667 doesn't have a corresponding exclusion in the opposite
2668 direction. */
2669 char desc[120];
2670 sprintf (desc, "'%s' attribute exclusion '%s' must be symmetric",
2671 (*it).first, (*it).second);
2672 fail (SELFTEST_LOCATION, desc);
2673 }
2674 }
2675 }
2676
2677 void
2678 attribs_cc_tests ()
2679 {
2680 test_attribute_exclusions ();
2681 }
2682
2683 } /* namespace selftest */
2684
2685 #endif /* CHECKING_P */