LCOV - code coverage report
Current view: top level - gcc/c-family - c-attribs.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.8 % 2479 2126
Test Date: 2026-12-05 16:10:02 Functions: 92.8 % 125 116
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* C-family attributes handling.
       2              :    Copyright (C) 1992-2026 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 "function.h"
      26              : #include "tree.h"
      27              : #include "memmodel.h"
      28              : #include "c-common.h"
      29              : #include "gimple-expr.h"
      30              : #include "tm_p.h"
      31              : #include "stringpool.h"
      32              : #include "cgraph.h"
      33              : #include "diagnostic.h"
      34              : #include "intl.h"
      35              : #include "stor-layout.h"
      36              : #include "calls.h"
      37              : #include "attribs.h"
      38              : #include "attr-handlers.h"
      39              : #include "varasm.h"
      40              : #include "trans-mem.h"
      41              : #include "c-objc.h"
      42              : #include "common/common-target.h"
      43              : #include "langhooks.h"
      44              : #include "tree-inline.h"
      45              : #include "ipa-strub.h"
      46              : #include "toplev.h"
      47              : #include "tree-iterator.h"
      48              : #include "opts.h"
      49              : #include "gimplify.h"
      50              : #include "tree-pretty-print.h"
      51              : #include "gcc-rich-location.h"
      52              : #include "gcc-urlifier.h"
      53              : #include "attr-callback.h"
      54              : 
      55              : static tree handle_packed_attribute (tree *, tree, tree, int, bool *);
      56              : static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *);
      57              : static tree handle_common_attribute (tree *, tree, tree, int, bool *);
      58              : static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
      59              : static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
      60              : static tree handle_no_sanitize_attribute (tree *, tree, tree, int, bool *);
      61              : static tree handle_no_sanitize_address_attribute (tree *, tree, tree,
      62              :                                                   int, bool *);
      63              : static tree handle_no_sanitize_thread_attribute (tree *, tree, tree,
      64              :                                                  int, bool *);
      65              : static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree,
      66              :                                                          int, bool *);
      67              : static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int,
      68              :                                                     bool *);
      69              : static tree handle_no_sanitize_coverage_attribute (tree *, tree, tree, int,
      70              :                                                    bool *);
      71              : static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int,
      72              :                                                  bool *);
      73              : static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *);
      74              : static tree handle_no_stack_protector_function_attribute (tree *, tree,
      75              :                                                         tree, int, bool *);
      76              : static tree handle_strub_attribute (tree *, tree, tree, int, bool *);
      77              : static tree handle_noclone_attribute (tree *, tree, tree, int, bool *);
      78              : static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *);
      79              : static tree handle_symver_attribute (tree *, tree, tree, int, bool *);
      80              : static tree handle_noicf_attribute (tree *, tree, tree, int, bool *);
      81              : static tree handle_noipa_attribute (tree *, tree, tree, int, bool *);
      82              : static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *);
      83              : static tree handle_artificial_attribute (tree *, tree, tree, int, bool *);
      84              : static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
      85              : static tree handle_error_attribute (tree *, tree, tree, int, bool *);
      86              : static tree handle_uninitialized_attribute (tree *, tree, tree, int, bool *);
      87              : static tree handle_externally_visible_attribute (tree *, tree, tree, int,
      88              :                                                  bool *);
      89              : static tree handle_no_reorder_attribute (tree *, tree, tree, int,
      90              :                                                  bool *);
      91              : static tree handle_transparent_union_attribute (tree *, tree, tree,
      92              :                                                 int, bool *);
      93              : static tree handle_scalar_storage_order_attribute (tree *, tree, tree,
      94              :                                                    int, bool *);
      95              : static tree handle_constructor_attribute (tree *, tree, tree, int, bool *);
      96              : static tree handle_destructor_attribute (tree *, tree, tree, int, bool *);
      97              : static tree handle_mode_attribute (tree *, tree, tree, int, bool *);
      98              : static tree handle_special_var_sec_attribute (tree *, tree, tree, int, bool *);
      99              : static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree,
     100              :                                                   int, bool *);
     101              : static tree handle_strict_flex_array_attribute (tree *, tree, tree,
     102              :                                                  int, bool *);
     103              : static tree handle_counted_by_attribute (tree *, tree, tree,
     104              :                                            int, bool *);
     105              : static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
     106              : static tree handle_ifunc_attribute (tree *, tree, tree, int, bool *);
     107              : static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ;
     108              : static tree handle_tls_model_attribute (tree *, tree, tree, int,
     109              :                                         bool *);
     110              : static tree handle_no_instrument_function_attribute (tree *, tree,
     111              :                                                      tree, int, bool *);
     112              : static tree handle_no_profile_instrument_function_attribute (tree *, tree,
     113              :                                                              tree, int, bool *);
     114              : static tree handle_malloc_attribute (tree *, tree, tree, int, bool *);
     115              : static tree handle_dealloc_attribute (tree *, tree, tree, int, bool *);
     116              : static tree handle_tainted_args_attribute (tree *, tree, tree, int, bool *);
     117              : static tree handle_no_limit_stack_attribute (tree *, tree, tree, int,
     118              :                                              bool *);
     119              : static tree handle_tm_attribute (tree *, tree, tree, int, bool *);
     120              : static tree handle_tm_wrap_attribute (tree *, tree, tree, int, bool *);
     121              : static tree handle_callback_only_attribute (tree *, tree, tree, int, bool *);
     122              : static tree handle_unavailable_attribute (tree *, tree, tree, int,
     123              :                                           bool *);
     124              : static tree handle_vector_size_attribute (tree *, tree, tree, int,
     125              :                                           bool *) ATTRIBUTE_NONNULL(3);
     126              : static tree handle_vector_mask_attribute (tree *, tree, tree, int,
     127              :                                           bool *) ATTRIBUTE_NONNULL(3);
     128              : static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *);
     129              : static tree handle_nonnull_if_nonzero_attribute (tree *, tree, tree, int,
     130              :                                                  bool *);
     131              : static tree handle_nonstring_attribute (tree *, tree, tree, int, bool *);
     132              : static tree handle_expected_throw_attribute (tree *, tree, tree, int, bool *);
     133              : static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *);
     134              : static tree handle_warn_unused_result_attribute (tree *, tree, tree, int,
     135              :                                                  bool *);
     136              : static tree handle_access_attribute (tree *, tree, tree, int, bool *);
     137              : 
     138              : static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *);
     139              : static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *);
     140              : static tree handle_alloc_align_attribute (tree *, tree, tree, int, bool *);
     141              : static tree handle_assume_aligned_attribute (tree *, tree, tree, int, bool *);
     142              : static tree handle_assume_attribute (tree *, tree, tree, int, bool *);
     143              : static tree handle_target_version_attribute (tree *, tree, tree, int, bool *);
     144              : static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *);
     145              : static tree handle_optimize_attribute (tree *, tree, tree, int, bool *);
     146              : static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *);
     147              : static tree handle_zero_call_used_regs_attribute (tree *, tree, tree, int,
     148              :                                                   bool *);
     149              : static tree handle_argspec_attribute (tree *, tree, tree, int, bool *);
     150              : static tree handle_warn_unused_attribute (tree *, tree, tree, int, bool *);
     151              : static tree handle_returns_nonnull_attribute (tree *, tree, tree, int, bool *);
     152              : static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int,
     153              :                                                bool *);
     154              : static tree handle_omp_declare_variant_attribute (tree *, tree, tree, int,
     155              :                                                   bool *);
     156              : static tree handle_simd_attribute (tree *, tree, tree, int, bool *);
     157              : static tree handle_omp_declare_target_attribute (tree *, tree, tree, int,
     158              :                                                  bool *);
     159              : static tree handle_non_overlapping_attribute (tree *, tree, tree, int, bool *);
     160              : static tree handle_designated_init_attribute (tree *, tree, tree, int, bool *);
     161              : static tree handle_patchable_function_entry_attribute (tree *, tree, tree,
     162              :                                                        int, bool *);
     163              : static tree handle_copy_attribute (tree *, tree, tree, int, bool *);
     164              : static tree handle_nsobject_attribute (tree *, tree, tree, int, bool *);
     165              : static tree handle_objc_root_class_attribute (tree *, tree, tree, int, bool *);
     166              : static tree handle_objc_nullability_attribute (tree *, tree, tree, int, bool *);
     167              : static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int,
     168              :                                                     bool *);
     169              : static tree handle_hardbool_attribute (tree *, tree, tree, int, bool *);
     170              : static tree handle_fd_arg_attribute (tree *, tree, tree, int, bool *);
     171              : static tree handle_flag_enum_attribute (tree *, tree, tree, int, bool *);
     172              : static tree handle_no_implicit_truncation_attribute (tree *, tree, tree, int,
     173              :                                                      bool *);
     174              : static tree handle_null_terminated_string_arg_attribute (tree *, tree, tree, int, bool *);
     175              : 
     176              : static tree handle_btf_decl_tag_attribute (tree *, tree, tree, int, bool *);
     177              : static tree handle_btf_type_tag_attribute (tree *, tree, tree, int, bool *);
     178              : 
     179              : static tree handle_suppress_coverage_attribute (tree *, tree, tree, int,
     180              :                                                 bool *);
     181              : 
     182              : /* Helper to define attribute exclusions.  */
     183              : #define ATTR_EXCL(name, function, type, variable)       \
     184              :   { name, function, type, variable }
     185              : 
     186              : /* Define attributes that are mutually exclusive with one another.  */
     187              : extern const struct attribute_spec::exclusions attr_aligned_exclusions[] =
     188              : {
     189              :   /* Attribute name     exclusion applies to:
     190              :                         function, type, variable */
     191              :   ATTR_EXCL ("aligned", true, false, false),
     192              :   ATTR_EXCL ("packed", true, false, false),
     193              :   ATTR_EXCL (NULL, false, false, false)
     194              : };
     195              : 
     196              : static const struct attribute_spec::exclusions attr_common_exclusions[] =
     197              : {
     198              :   ATTR_EXCL ("common", true, true, true),
     199              :   ATTR_EXCL ("nocommon", true, true, true),
     200              :   ATTR_EXCL (NULL, false, false, false),
     201              : };
     202              : 
     203              : static const struct attribute_spec::exclusions attr_inline_exclusions[] =
     204              : {
     205              :   ATTR_EXCL ("noinline", true, true, true),
     206              :   ATTR_EXCL (NULL, false, false, false),
     207              : };
     208              : 
     209              : static const struct attribute_spec::exclusions attr_target_clones_exclusions[] =
     210              : {
     211              :   ATTR_EXCL ("always_inline", true, true, true),
     212              :   ATTR_EXCL ("target", TARGET_HAS_FMV_TARGET_ATTRIBUTE,
     213              :              TARGET_HAS_FMV_TARGET_ATTRIBUTE, TARGET_HAS_FMV_TARGET_ATTRIBUTE),
     214              :   ATTR_EXCL ("omp declare simd", true, true, true),
     215              :   ATTR_EXCL ("simd", true, true, true),
     216              :   ATTR_EXCL (NULL, false, false, false),
     217              : };
     218              : 
     219              : static const struct attribute_spec::exclusions attr_target_version_exclusions[] =
     220              : {
     221              :   ATTR_EXCL ("omp declare simd", true, true, true),
     222              :   ATTR_EXCL ("simd", true, true, true),
     223              :   ATTR_EXCL (NULL, false, false, false),
     224              : };
     225              : 
     226              : static const struct attribute_spec::exclusions attr_omp_declare_simd_exclusions[] =
     227              : {
     228              :   ATTR_EXCL ("target_version", true, true, true),
     229              :   ATTR_EXCL ("target_clones", true, true, true),
     230              :   ATTR_EXCL (NULL, false, false, false),
     231              : };
     232              : 
     233              : static const struct attribute_spec::exclusions attr_simd_exclusions[] =
     234              : {
     235              :   ATTR_EXCL ("target_version", true, true, true),
     236              :   ATTR_EXCL ("target_clones", true, true, true),
     237              :   ATTR_EXCL (NULL, false, false, false),
     238              : };
     239              : 
     240              : static const struct attribute_spec::exclusions
     241              : attr_warn_unused_result_exclusions[] =
     242              : {
     243              :   ATTR_EXCL ("noreturn", true, true, true),
     244              :   ATTR_EXCL ("warn_unused_result", true, true, true),
     245              :   ATTR_EXCL (NULL, false, false, false),
     246              : };
     247              : 
     248              : static const struct attribute_spec::exclusions attr_stack_protect_exclusions[] =
     249              : {
     250              :   ATTR_EXCL ("stack_protect", true, false, false),
     251              :   ATTR_EXCL ("no_stack_protector", true, false, false),
     252              :   ATTR_EXCL (NULL, false, false, false),
     253              : };
     254              : 
     255              : 
     256              : /* Table of machine-independent attributes common to all C-like languages.
     257              : 
     258              :    Current list of processed common attributes: nonnull.  */
     259              : const struct attribute_spec c_common_gnu_attributes[] =
     260              : {
     261              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
     262              :        affects_type_identity, handler, exclude } */
     263              :   { "signed_bool_precision",  1, 1, false, true, false, true,
     264              :                               handle_signed_bool_precision_attribute, NULL },
     265              :   { "hardbool",               0, 2, false, true, false, true,
     266              :                               handle_hardbool_attribute, NULL },
     267              :   { "packed",                 0, 0, false, false, false, false,
     268              :                               handle_packed_attribute,
     269              :                               attr_aligned_exclusions },
     270              :   { "nocommon",               0, 0, true,  false, false, false,
     271              :                               handle_nocommon_attribute,
     272              :                               attr_common_exclusions },
     273              :   { "common",                 0, 0, true,  false, false, false,
     274              :                               handle_common_attribute,
     275              :                               attr_common_exclusions },
     276              :   { "musttail",                     0, 0, false, false, false,
     277              :                               false, handle_musttail_attribute, NULL },
     278              :   /* FIXME: logically, noreturn attributes should be listed as
     279              :      "false, true, true" and apply to function types.  But implementing this
     280              :      would require all the places in the compiler that use TREE_THIS_VOLATILE
     281              :      on a decl to identify non-returning functions to be located and fixed
     282              :      to check the function type instead.  */
     283              :   { "noreturn",               0, 0, true,  false, false, false,
     284              :                               handle_noreturn_attribute,
     285              :                               attr_noreturn_exclusions },
     286              :   { "volatile",               0, 0, true,  false, false, false,
     287              :                               handle_noreturn_attribute, NULL },
     288              :   { "stack_protect",          0, 0, true,  false, false, false,
     289              :                               handle_stack_protect_attribute,
     290              :                               attr_stack_protect_exclusions },
     291              :   { "no_stack_protector",     0, 0, true, false, false, false,
     292              :                               handle_no_stack_protector_function_attribute,
     293              :                               attr_stack_protect_exclusions },
     294              :   { "strub",                0, 1, false, true, false, true,
     295              :                               handle_strub_attribute, NULL },
     296              :   { "noinline",               0, 0, true,  false, false, false,
     297              :                               handle_noinline_attribute,
     298              :                               attr_noinline_exclusions },
     299              :   { "noclone",                0, 0, true,  false, false, false,
     300              :                               handle_noclone_attribute, NULL },
     301              :   { "no_icf",                 0, 0, true,  false, false, false,
     302              :                               handle_noicf_attribute, NULL },
     303              :   { "noipa",                0, 0, true,  false, false, false,
     304              :                               handle_noipa_attribute, NULL },
     305              :   { "leaf",                   0, 0, true,  false, false, false,
     306              :                               handle_leaf_attribute, NULL },
     307              :   { "always_inline",          0, 0, true,  false, false, false,
     308              :                               handle_always_inline_attribute,
     309              :                               attr_always_inline_exclusions },
     310              :   { "gnu_inline",             0, 0, true,  false, false, false,
     311              :                               handle_gnu_inline_attribute,
     312              :                               attr_inline_exclusions },
     313              :   { "artificial",             0, 0, true,  false, false, false,
     314              :                               handle_artificial_attribute, NULL },
     315              :   { "flatten",                0, 0, true,  false, false, false,
     316              :                               handle_flatten_attribute, NULL },
     317              :   { "used",                   0, 0, true,  false, false, false,
     318              :                               handle_used_attribute, NULL },
     319              :   { "unused",                 0, 0, false, false, false, false,
     320              :                               handle_unused_attribute, NULL },
     321              :   { "uninitialized",        0, 0, true, false, false, false,
     322              :                               handle_uninitialized_attribute, NULL },
     323              :   { "retain",                 0, 0, true,  false, false, false,
     324              :                               handle_retain_attribute, NULL },
     325              :   { "externally_visible",     0, 0, true,  false, false, false,
     326              :                               handle_externally_visible_attribute, NULL },
     327              :   { "no_reorder",           0, 0, true, false, false, false,
     328              :                               handle_no_reorder_attribute, NULL },
     329              :   /* The same comments as for noreturn attributes apply to const ones.  */
     330              :   { "const",                  0, 0, true,  false, false, false,
     331              :                               handle_const_attribute,
     332              :                               attr_const_pure_exclusions },
     333              :   { "scalar_storage_order",   1, 1, false, false, false, false,
     334              :                               handle_scalar_storage_order_attribute, NULL },
     335              :   { "transparent_union",      0, 0, false, false, false, false,
     336              :                               handle_transparent_union_attribute, NULL },
     337              :   { "constructor",            0, 1, true,  false, false, false,
     338              :                               handle_constructor_attribute, NULL },
     339              :   { "destructor",             0, 1, true,  false, false, false,
     340              :                               handle_destructor_attribute, NULL },
     341              :   { "mode",                   1, 1, false,  true, false, false,
     342              :                               handle_mode_attribute, NULL },
     343              :   { "section",                1, 1, true,  false, false, false,
     344              :                               handle_section_attribute, attr_section_exclusions },
     345              :   { "aligned",                0, 1, false, false, false, false,
     346              :                               handle_aligned_attribute,
     347              :                               attr_aligned_exclusions },
     348              :   { "warn_if_not_aligned",    0, 1, false, false, false, false,
     349              :                               handle_warn_if_not_aligned_attribute, NULL },
     350              :   { "strict_flex_array",      1, 1, true, false, false, false,
     351              :                               handle_strict_flex_array_attribute, NULL },
     352              :   { "counted_by",           1, 1, true, false, false, false,
     353              :                               handle_counted_by_attribute, NULL },
     354              :   { "weak",                   0, 0, true,  false, false, false,
     355              :                               handle_weak_attribute, NULL },
     356              :   { "noplt",                   0, 0, true,  false, false, false,
     357              :                               handle_noplt_attribute, NULL },
     358              :   { "ifunc",                  1, 1, true,  false, false, false,
     359              :                               handle_ifunc_attribute, NULL },
     360              :   { "alias",                  1, 1, true,  false, false, false,
     361              :                               handle_alias_attribute, NULL },
     362              :   { "weakref",                0, 1, true,  false, false, false,
     363              :                               handle_weakref_attribute, NULL },
     364              :   { "no_instrument_function", 0, 0, true,  false, false, false,
     365              :                               handle_no_instrument_function_attribute,
     366              :                               NULL },
     367              :   { "no_profile_instrument_function",  0, 0, true, false, false, false,
     368              :                               handle_no_profile_instrument_function_attribute,
     369              :                               NULL },
     370              :   { "malloc",                 0, 2, true,  false, false, false,
     371              :                               handle_malloc_attribute, attr_alloc_exclusions },
     372              :   { "returns_twice",          0, 0, true,  false, false, false,
     373              :                               handle_returns_twice_attribute,
     374              :                               attr_returns_twice_exclusions },
     375              :   { "no_stack_limit",         0, 0, true,  false, false, false,
     376              :                               handle_no_limit_stack_attribute, NULL },
     377              :   { "pure",                   0, 0, true,  false, false, false,
     378              :                               handle_pure_attribute,
     379              :                               attr_const_pure_exclusions },
     380              :   { "reproducible",           0, 0, false, true,  true,  false,
     381              :                               handle_reproducible_attribute, NULL },
     382              :   { "unsequenced",            0, 0, false, true,  true,  false,
     383              :                               handle_unsequenced_attribute, NULL },
     384              :   { "reproducible noptr",     0, 0, false, true,  true,  false,
     385              :                               handle_reproducible_attribute, NULL },
     386              :   { "unsequenced noptr",      0, 0, false, true,  true,  false,
     387              :                               handle_unsequenced_attribute, NULL },
     388              :   { "transaction_callable",   0, 0, false, true,  false, false,
     389              :                               handle_tm_attribute, NULL },
     390              :   { "transaction_unsafe",     0, 0, false, true,  false, true,
     391              :                               handle_tm_attribute, NULL },
     392              :   { "transaction_safe",       0, 0, false, true,  false, true,
     393              :                               handle_tm_attribute, NULL },
     394              :   { "transaction_safe_dynamic", 0, 0, true, false,  false, false,
     395              :                               handle_tm_attribute, NULL },
     396              :   { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
     397              :                               handle_tm_attribute, NULL },
     398              :   { "callback_only",          1, -1, true, false, false, false,
     399              :                               handle_callback_only_attribute, NULL },
     400              :   /* ??? These two attributes didn't make the transition from the
     401              :      Intel language document to the multi-vendor language document.  */
     402              :   { "transaction_pure",       0, 0, false, true,  false, false,
     403              :                               handle_tm_attribute, NULL },
     404              :   { "transaction_wrap",       1, 1, true,  false,  false, false,
     405              :                              handle_tm_wrap_attribute, NULL },
     406              :   /* For internal use (marking of builtins) only.  The name contains space
     407              :      to prevent its usage in source code.  */
     408              :   { "no vops",                0, 0, true,  false, false, false,
     409              :                               handle_novops_attribute, NULL },
     410              :   { "deprecated",             0, 1, false, false, false, false,
     411              :                               handle_deprecated_attribute, NULL },
     412              :   { "unavailable",            0, 1, false, false, false, false,
     413              :                               handle_unavailable_attribute, NULL },
     414              :   { "vector_size",          1, 1, false, true, false, true,
     415              :                               handle_vector_size_attribute, NULL },
     416              :   { "vector_mask",          0, 0, false, true, false, true,
     417              :                               handle_vector_mask_attribute, NULL },
     418              :   { "visibility",           1, 1, false, false, false, false,
     419              :                               handle_visibility_attribute, NULL },
     420              :   { "tls_model",            1, 1, true,  false, false, false,
     421              :                               handle_tls_model_attribute, NULL },
     422              :   { "nonnull",                0, -1, false, true, true, false,
     423              :                               handle_nonnull_attribute, NULL },
     424              :   { "nonnull_if_nonzero",     2, 3, false, true, true, false,
     425              :                               handle_nonnull_if_nonzero_attribute, NULL },
     426              :   { "nonstring",              0, 0, true, false, false, false,
     427              :                               handle_nonstring_attribute, NULL },
     428              :   { "nothrow",                0, 0, true,  false, false, false,
     429              :                               handle_nothrow_attribute, NULL },
     430              :   { "expected_throw",         0, 0, true,  false, false, false,
     431              :                               handle_expected_throw_attribute, NULL },
     432              :   { "may_alias",            0, 0, false, true, false, false, NULL, NULL },
     433              :   { "cleanup",                      1, 1, true, false, false, false,
     434              :                               handle_cleanup_attribute, NULL },
     435              :   { "warn_unused_result",     0, 0, false, true, true, false,
     436              :                               handle_warn_unused_result_attribute,
     437              :                               attr_warn_unused_result_exclusions },
     438              :   { "sentinel",               0, 1, false, true, true, false,
     439              :                               handle_sentinel_attribute, NULL },
     440              :   /* For internal use (marking of builtins) only.  The name contains space
     441              :      to prevent its usage in source code.  */
     442              :   { "type generic",           0, 0, false, true, true, false,
     443              :                               handle_type_generic_attribute, NULL },
     444              :   { "alloc_size",           1, 2, false, true, true, false,
     445              :                               handle_alloc_size_attribute,
     446              :                               attr_alloc_exclusions },
     447              :   { "cold",                 0, 0, false,  false, false, false,
     448              :                               handle_cold_attribute,
     449              :                               attr_cold_hot_exclusions },
     450              :   { "hot",                  0, 0, false,  false, false, false,
     451              :                               handle_hot_attribute,
     452              :                               attr_cold_hot_exclusions },
     453              :   { "no_address_safety_analysis",
     454              :                               0, 0, true, false, false, false,
     455              :                               handle_no_address_safety_analysis_attribute,
     456              :                               NULL },
     457              :   { "no_sanitize",          1, -1, true, false, false, false,
     458              :                               handle_no_sanitize_attribute, NULL },
     459              :   { "no_sanitize_address",    0, 0, true, false, false, false,
     460              :                               handle_no_sanitize_address_attribute, NULL },
     461              :   { "no_sanitize_thread",     0, 0, true, false, false, false,
     462              :                               handle_no_sanitize_thread_attribute, NULL },
     463              :   { "no_sanitize_undefined",  0, 0, true, false, false, false,
     464              :                               handle_no_sanitize_undefined_attribute, NULL },
     465              :   { "no_sanitize_coverage",   0, 0, true, false, false, false,
     466              :                               handle_no_sanitize_coverage_attribute, NULL },
     467              :   { "asan odr indicator",     0, 0, true, false, false, false,
     468              :                               handle_asan_odr_indicator_attribute, NULL },
     469              :   { "warning",                      1, 1, true,  false, false, false,
     470              :                               handle_error_attribute, NULL },
     471              :   { "error",                1, 1, true,  false, false, false,
     472              :                               handle_error_attribute, NULL },
     473              :   { "target",                 1, -1, true, false, false, false,
     474              :                               handle_target_attribute,
     475              :                               attr_target_exclusions },
     476              :   { "target_version",         1, 1, true, false, false, false,
     477              :                               handle_target_version_attribute,
     478              :                               attr_target_version_exclusions},
     479              :   { "target_clones",          1, -1, true, false, false, false,
     480              :                               handle_target_clones_attribute,
     481              :                               attr_target_clones_exclusions },
     482              :   { "optimize",               1, -1, true, false, false, false,
     483              :                               handle_optimize_attribute, NULL },
     484              :   /* For internal use only.  The leading '*' both prevents its usage in
     485              :      source code and signals that it may be overridden by machine tables.  */
     486              :   { "*tm regparm",            0, 0, false, true, true, false,
     487              :                               ignore_attribute, NULL },
     488              :   { "no_split_stack",       0, 0, true,  false, false, false,
     489              :                               handle_no_split_stack_attribute, NULL },
     490              :   { "zero_call_used_regs",    1, 1, true, false, false, false,
     491              :                               handle_zero_call_used_regs_attribute, NULL },
     492              :   /* For internal use only (marking of function arguments).
     493              :      The name contains a space to prevent its usage in source code.  */
     494              :   { "arg spec",                     1, -1, true, false, false, false,
     495              :                               handle_argspec_attribute, NULL },
     496              :   /* For internal use (marking of builtins and runtime functions) only.
     497              :      The name contains space to prevent its usage in source code.  */
     498              :   { "fn spec",                      1, 1, false, true, true, false,
     499              :                               handle_fnspec_attribute, NULL },
     500              :   { "warn_unused",            0, 0, false, false, false, false,
     501              :                               handle_warn_unused_attribute, NULL },
     502              :   { "returns_nonnull",        0, 0, false, true, true, false,
     503              :                               handle_returns_nonnull_attribute, NULL },
     504              :   { "omp declare simd",       0, -1, true,  false, false, false,
     505              :                               handle_omp_declare_simd_attribute,
     506              :                               attr_omp_declare_simd_exclusions },
     507              :   { "omp declare variant base", 0, -1, true,  false, false, false,
     508              :                               handle_omp_declare_variant_attribute, NULL },
     509              :   { "omp declare variant variant", 0, -1, true,  false, false, false,
     510              :                               handle_omp_declare_variant_attribute, NULL },
     511              :   { "omp declare variant variant args", 0, -1, true,  false,
     512              :                               false, false,
     513              :                               handle_omp_declare_variant_attribute, NULL },
     514              :   { "simd",                 0, 1, true,  false, false, false,
     515              :                               handle_simd_attribute, attr_simd_exclusions },
     516              :   { "omp declare target",     0, -1, true, false, false, false,
     517              :                               handle_omp_declare_target_attribute, NULL },
     518              :   { "omp declare target link", 0, 0, true, false, false, false,
     519              :                               handle_omp_declare_target_attribute, NULL },
     520              :   { "omp declare target implicit", 0, 0, true, false, false, false,
     521              :                               handle_omp_declare_target_attribute, NULL },
     522              :   { "omp declare target indirect", 0, 0, true, false, false, false,
     523              :                               handle_omp_declare_target_attribute, NULL },
     524              :   { "omp declare target host", 0, 0, true, false, false, false,
     525              :                               handle_omp_declare_target_attribute, NULL },
     526              :   { "omp declare target nohost", 0, 0, true, false, false, false,
     527              :                               handle_omp_declare_target_attribute, NULL },
     528              :   { "omp groupprivate",             0, 0, true, false, false, false,
     529              :                               handle_omp_declare_target_attribute, NULL },
     530              :   { "non overlapping",              0, 0, true, false, false, false,
     531              :                               handle_non_overlapping_attribute, NULL },
     532              :   { "alloc_align",          1, 1, false, true, true, false,
     533              :                               handle_alloc_align_attribute,
     534              :                               attr_alloc_exclusions },
     535              :   { "assume_aligned",       1, 2, false, true, true, false,
     536              :                               handle_assume_aligned_attribute, NULL },
     537              :   { "designated_init",        0, 0, false, true, false, false,
     538              :                               handle_designated_init_attribute, NULL },
     539              :   { "fallthrough",          0, 0, false, false, false, false,
     540              :                               handle_fallthrough_attribute, NULL },
     541              :   { "assume",               1, 1, false, false, false, false,
     542              :                               handle_assume_attribute, NULL },
     543              :   { "patchable_function_entry",       1, 2, true, false, false, false,
     544              :                               handle_patchable_function_entry_attribute,
     545              :                               NULL },
     546              :   { "nocf_check",           0, 0, false, true, true, true,
     547              :                               handle_nocf_check_attribute, NULL },
     548              :   { "symver",               1, -1, true, false, false, false,
     549              :                               handle_symver_attribute, NULL},
     550              :   { "copy",                   1, 1, false, false, false, false,
     551              :                               handle_copy_attribute, NULL },
     552              :   { "noinit",               0, 0, true,  false, false, false,
     553              :                               handle_special_var_sec_attribute, attr_section_exclusions },
     554              :   { "persistent",           0, 0, true,  false, false, false,
     555              :                               handle_special_var_sec_attribute, attr_section_exclusions },
     556              :   { "access",               1, 3, false, true, true, false,
     557              :                               handle_access_attribute, NULL },
     558              :   { "suppress_coverage",       0, 0, true, false, false, false,
     559              :                               handle_suppress_coverage_attribute, NULL },
     560              :   /* Attributes used by Objective-C.  */
     561              :   { "NSObject",                     0, 0, true, false, false, false,
     562              :                               handle_nsobject_attribute, NULL },
     563              :   { "objc_root_class",              0, 0, true, false, false, false,
     564              :                               handle_objc_root_class_attribute, NULL },
     565              :   { "objc_nullability",             1, 1, true, false, false, false,
     566              :                               handle_objc_nullability_attribute, NULL },
     567              :   { "*dealloc",                1, 2, true, false, false, false,
     568              :                               handle_dealloc_attribute, NULL },
     569              :   { "tainted_args",         0, 0, true,  false, false, false,
     570              :                               handle_tainted_args_attribute, NULL },
     571              :   { "fd_arg",             1, 1, false, true, true, false,
     572              :             handle_fd_arg_attribute, NULL},
     573              :   { "fd_arg_read",        1, 1, false, true, true, false,
     574              :             handle_fd_arg_attribute, NULL},
     575              :   { "fd_arg_write",       1, 1, false, true, true, false,
     576              :             handle_fd_arg_attribute, NULL},
     577              :   { "flag_enum",            0, 0, false, true, false, false,
     578              :                               handle_flag_enum_attribute, NULL },
     579              :   { "null_terminated_string_arg", 1, 1, false, true, true, false,
     580              :                               handle_null_terminated_string_arg_attribute, NULL},
     581              :   { "btf_type_tag",         1, 1, false, true, false, false,
     582              :                               handle_btf_type_tag_attribute, NULL},
     583              :   { "btf_decl_tag",         1, 1, true, false, false, false,
     584              :                               handle_btf_decl_tag_attribute, NULL},
     585              :   { "no_implicit_truncation", 0, 0, false, true, false, false,
     586              :                               handle_no_implicit_truncation_attribute, NULL }
     587              : };
     588              : 
     589              : const struct scoped_attribute_specs c_common_gnu_attribute_table =
     590              : {
     591              :   "gnu", { c_common_gnu_attributes }
     592              : };
     593              : 
     594              : /* Attributes also recognized in the clang:: namespace.  */
     595              : const struct attribute_spec c_common_clang_attributes[] = {
     596              :   { "flag_enum",            0, 0, false, true, false, false,
     597              :                               handle_flag_enum_attribute, NULL },
     598              :   { "musttail",                     0, 0, false, false, false,
     599              :                               false, handle_musttail_attribute, NULL }
     600              : };
     601              : 
     602              : const struct scoped_attribute_specs c_common_clang_attribute_table =
     603              : {
     604              :   "clang", { c_common_clang_attributes }
     605              : };
     606              : 
     607              : /* Give the specifications for the format attributes, used by C and all
     608              :    descendants.
     609              : 
     610              :    Current list of processed format attributes: format, format_arg.  */
     611              : const struct attribute_spec c_common_format_attributes[] =
     612              : {
     613              :   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
     614              :        affects_type_identity, handler, exclude } */
     615              :   { "format",                 3, 3, false, true,  true, false,
     616              :                               handle_format_attribute, NULL },
     617              :   { "format_arg",             1, 1, false, true,  true, false,
     618              :                               handle_format_arg_attribute, NULL }
     619              : };
     620              : 
     621              : const struct scoped_attribute_specs c_common_format_attribute_table =
     622              : {
     623              :   "gnu", { c_common_format_attributes }
     624              : };
     625              : 
     626              : /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain
     627              :    identifier as an argument, so the front end shouldn't look it up.  */
     628              : 
     629              : bool
     630     17127731 : attribute_takes_identifier_p (const_tree attr_id)
     631              : {
     632     17127731 :   const struct attribute_spec *spec = lookup_attribute_spec (attr_id);
     633     17127731 :   if (spec == NULL)
     634              :     {
     635              :       /* Unknown attribute that we'll end up ignoring, return true so we
     636              :          don't complain about an identifier argument.  Except C++
     637              :          annotations.  */
     638           36 :       if (c_dialect_cxx () && id_equal (attr_id, "annotation "))
     639              :         return false;
     640           36 :       return true;
     641              :     }
     642     17127695 :   else if (!strcmp ("mode", spec->name)
     643     17072225 :            || !strcmp ("format", spec->name)
     644     16668519 :            || !strcmp ("cleanup", spec->name)
     645     16668173 :            || !strcmp ("access", spec->name)
     646     15836520 :            || !strcmp ("counted_by", spec->name)
     647     15836091 :            || !strcmp ("old parm name", spec->name))
     648              :     return true;
     649              :   else
     650     15836091 :     return targetm.attribute_takes_identifier_p (attr_id);
     651              : }
     652              : 
     653              : /* Set a musttail attribute MUSTTAIL_P on return expression RETVAL
     654              :    at LOC.  */
     655              : 
     656              : void
     657    143913620 : set_musttail_on_return (tree retval, location_t loc, bool musttail_p)
     658              : {
     659    143913620 :   if (retval && musttail_p)
     660              :     {
     661          844 :       tree t = retval;
     662          844 :       if (TREE_CODE (t) == TARGET_EXPR)
     663           18 :         t = TARGET_EXPR_INITIAL (t);
     664          844 :       if (TREE_CODE (t) != CALL_EXPR)
     665           12 :         error_at (loc, "cannot tail-call: return value must be a call");
     666              :       else
     667          832 :         CALL_EXPR_MUST_TAIL_CALL (t) = 1;
     668              :     }
     669    143912776 :   else if (musttail_p && !retval)
     670            8 :     error_at (loc, "cannot tail-call: return value must be a call");
     671    143913620 : }
     672              : 
     673              : /* Verify that argument value POS at position ARGNO to attribute NAME
     674              :    applied to function FN (which is either a function declaration or function
     675              :    type) refers to a function parameter at position POS and the expected type
     676              :    CODE.  Treat CODE == INTEGER_TYPE as matching all C integral types except
     677              :    bool.  If successful, return POS after default conversions (and possibly
     678              :    adjusted by ADJUST_POS).  Otherwise, issue appropriate warnings and return
     679              :    null.  A non-zero 1-based ARGNO should be passed in by callers only for
     680              :    attributes with more than one argument.
     681              : 
     682              :    N.B. This function modifies POS.  */
     683              : 
     684              : tree
     685     87601269 : positional_argument (const_tree fn, const_tree atname, tree &pos,
     686              :                      tree_code code, int argno /* = 0 */,
     687              :                      int flags /* = posargflags () */)
     688              : {
     689     87601269 :   auto_urlify_attributes sentinel;
     690              : 
     691     87601269 :   const_tree fndecl = TYPE_P (fn) ? NULL_TREE : fn;
     692     87601269 :   const_tree fntype = TYPE_P (fn) ? fn : TREE_TYPE (fn);
     693     87601269 :   if (pos && TREE_CODE (pos) != IDENTIFIER_NODE
     694     87601269 :       && TREE_CODE (pos) != FUNCTION_DECL)
     695     87601245 :     pos = default_conversion (pos);
     696              : 
     697     87601269 :   tree postype = TREE_TYPE (pos);
     698     87601269 :   if (pos == error_mark_node || !postype)
     699              :     {
     700              :       /* Only mention the positional argument number when it's non-zero.  */
     701           20 :       if (argno < 1)
     702            9 :         warning (OPT_Wattributes,
     703              :                  "%qE attribute argument is invalid", atname);
     704              :       else
     705           11 :         warning (OPT_Wattributes,
     706              :                  "%qE attribute argument %i is invalid", atname, argno);
     707              : 
     708              :       return NULL_TREE;
     709              :     }
     710              : 
     711     87601249 :   if (!INTEGRAL_TYPE_P (postype))
     712              :     {
     713              :       /* Handle this case specially to avoid mentioning the value
     714              :          of pointer constants in diagnostics.  Only mention
     715              :          the positional argument number when it's non-zero.  */
     716           43 :       if (argno < 1)
     717           31 :         warning (OPT_Wattributes,
     718              :                  "%qE attribute argument has type %qT",
     719              :                  atname, postype);
     720              :       else
     721           12 :         warning (OPT_Wattributes,
     722              :                  "%qE attribute argument %i has type %qT",
     723              :                  atname, argno, postype);
     724              : 
     725              :       return NULL_TREE;
     726              :     }
     727              : 
     728     87601206 :   if (TREE_CODE (pos) != INTEGER_CST)
     729              :     {
     730              :       /* Only mention the argument number when it's non-zero.  */
     731            9 :       if (argno < 1)
     732            3 :         warning (OPT_Wattributes,
     733              :                  "%qE attribute argument value %qE is not an integer "
     734              :                  "constant",
     735              :                  atname, pos);
     736              :       else
     737            6 :         warning (OPT_Wattributes,
     738              :                  "%qE attribute argument %i value %qE is not an integer "
     739              :                  "constant",
     740              :                  atname, argno, pos);
     741              : 
     742              :       return NULL_TREE;
     743              :     }
     744              : 
     745              :   /* Argument positions are 1-based.  */
     746     87601197 :   if (integer_zerop (pos))
     747              :     {
     748      5204214 :       if (flags & POSARG_ZERO)
     749              :         /* Zero is explicitly allowed.  */
     750      5204201 :         return pos;
     751              : 
     752           13 :       if (argno < 1)
     753           12 :         warning (OPT_Wattributes,
     754              :                  "%qE attribute argument value %qE does not refer to "
     755              :                  "a function parameter",
     756              :                  atname, pos);
     757              :       else
     758            1 :         warning (OPT_Wattributes,
     759              :                  "%qE attribute argument %i value %qE does not refer to "
     760              :                  "a function parameter",
     761              :                  atname, argno, pos);
     762              : 
     763              :       return NULL_TREE;
     764              :     }
     765              : 
     766     82396983 :   if (!prototype_p (fntype))
     767          123 :     return pos;
     768              : 
     769              :    /* ADJUST_POS is non-zero in C++ when the function type has invisible
     770              :       parameters generated by the compiler, such as the in-charge or VTT
     771              :       parameters.  */
     772     82396860 :   const int adjust_pos = maybe_adjust_arg_pos_for_attribute (fndecl);
     773              : 
     774              :   /* Verify that the argument position does not exceed the number
     775              :      of formal arguments to the function.  When POSARG_ELLIPSIS
     776              :      is set, ARGNO may be beyond the last argument of a vararg
     777              :      function.  */
     778     82396860 :   unsigned nargs = type_num_arguments (fntype);
     779     82396860 :   if (!nargs
     780     82396854 :       || !tree_fits_uhwi_p (pos)
     781     82396851 :       || ((flags & POSARG_ELLIPSIS) == 0
     782     76522366 :           && !IN_RANGE (tree_to_uhwi (pos) + adjust_pos, 1, nargs)))
     783              :     {
     784              : 
     785           34 :       if (argno < 1)
     786           16 :         warning (OPT_Wattributes,
     787              :                  "%qE attribute argument value %qE exceeds the number "
     788              :                  "of function parameters %u",
     789              :                  atname, pos, nargs);
     790              :       else
     791           18 :         warning (OPT_Wattributes,
     792              :                  "%qE attribute argument %i value %qE exceeds the number "
     793              :                  "of function parameters %u",
     794              :                  atname, argno, pos, nargs);
     795              :       return NULL_TREE;
     796              :     }
     797              : 
     798              :   /* Verify that the type of the referenced formal argument matches
     799              :      the expected type.   Invisible parameters may have been added by
     800              :      the compiler, so adjust the position accordingly.  */
     801     82396826 :   unsigned HOST_WIDE_INT ipos = tree_to_uhwi (pos) + adjust_pos;
     802              : 
     803              :   /* Zero was handled above.  */
     804     82396826 :   gcc_assert (ipos != 0);
     805              : 
     806     82396826 :   if (tree argtype = type_argument_type (fntype, ipos))
     807              :     {
     808     76522343 :       if (argtype == error_mark_node)
     809              :         return NULL_TREE;
     810              : 
     811     76522340 :       if (flags & POSARG_ELLIPSIS)
     812              :         {
     813            2 :           if (argno < 1)
     814            0 :             error ("%qE attribute argument value %qE does not refer to "
     815              :                    "a variable argument list",
     816              :                    atname, pos);
     817              :           else
     818            2 :             error ("%qE attribute argument %i value %qE does not refer to "
     819              :                    "a variable argument list",
     820              :                    atname, argno, pos);
     821              :           return NULL_TREE;
     822              :         }
     823              : 
     824              :       /* Where the expected code is STRING_CST accept any pointer
     825              :          expected by attribute format (this includes possibly qualified
     826              :          char pointers and, for targets like Darwin, also pointers to
     827              :          struct CFString).  */
     828     76522338 :       bool type_match;
     829     76522338 :       if (code == STRING_CST)
     830     12318436 :         type_match = valid_format_string_type_p (argtype);
     831     64203902 :       else if (code == INTEGER_TYPE)
     832              :         /* For integers, accept enums, wide characters and other types
     833              :            that match INTEGRAL_TYPE_P except for bool.  */
     834     19731778 :         type_match = (INTEGRAL_TYPE_P (argtype)
     835     19731778 :                       && TREE_CODE (argtype) != BOOLEAN_TYPE);
     836              :       else
     837     44472124 :         type_match = TREE_CODE (argtype) == code;
     838              : 
     839     56790560 :       if (!type_match)
     840              :         {
     841           76 :           if (code == STRING_CST)
     842              :             {
     843              :               /* Reject invalid format strings with an error.  */
     844           24 :               if (argno < 1)
     845            6 :                 error ("%qE attribute argument value %qE refers to "
     846              :                        "parameter type %qT",
     847              :                        atname, pos, argtype);
     848              :               else
     849           18 :                 error ("%qE attribute argument %i value %qE refers to "
     850              :                        "parameter type %qT",
     851              :                        atname, argno, pos, argtype);
     852              : 
     853              :               return NULL_TREE;
     854              :             }
     855              : 
     856           52 :           if (argno < 1)
     857           42 :             warning (OPT_Wattributes,
     858              :                      "%qE attribute argument value %qE refers to "
     859              :                      "parameter type %qT",
     860              :                      atname, pos, argtype);
     861              :           else
     862           10 :             warning (OPT_Wattributes,
     863              :                    "%qE attribute argument %i value %qE refers to "
     864              :                      "parameter type %qT",
     865              :                      atname, argno, pos, argtype);
     866              :           return NULL_TREE;
     867              :         }
     868              :     }
     869      5874483 :   else if (!(flags & POSARG_ELLIPSIS))
     870              :     {
     871            0 :       if (argno < 1)
     872            0 :         warning (OPT_Wattributes,
     873              :                  "%qE attribute argument value %qE refers to "
     874              :                  "a variadic function parameter of unknown type",
     875              :                  atname, pos);
     876              :       else
     877            0 :         warning (OPT_Wattributes,
     878              :                  "%qE attribute argument %i value %qE refers to "
     879              :                  "a variadic function parameter of unknown type",
     880              :                  atname, argno, pos);
     881              :       return NULL_TREE;
     882              :     }
     883              : 
     884     82396745 :   return build_int_cst (TREE_TYPE (pos), ipos);
     885     87601269 : }
     886              : 
     887              : /* Attribute handlers common to C front ends.  */
     888              : 
     889              : /* Handle a "signed_bool_precision" attribute; arguments as in
     890              :    struct attribute_spec.handler.  */
     891              : 
     892              : static tree
     893            4 : handle_signed_bool_precision_attribute (tree *node, tree name, tree args,
     894              :                                         int, bool *no_add_attrs)
     895              : {
     896            4 :   *no_add_attrs = true;
     897            4 :   if (!flag_gimple)
     898              :     {
     899            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
     900            0 :       return NULL_TREE;
     901              :     }
     902              : 
     903            4 :   if (!TYPE_P (*node) || TREE_CODE (*node) != BOOLEAN_TYPE)
     904              :     {
     905            0 :       warning (OPT_Wattributes, "%qE attribute only supported on "
     906              :                "boolean types", name);
     907            0 :       return NULL_TREE;
     908              :     }
     909              : 
     910            4 :   unsigned HOST_WIDE_INT prec = HOST_WIDE_INT_M1U;
     911            4 :   if (tree_fits_uhwi_p (TREE_VALUE (args)))
     912            4 :     prec = tree_to_uhwi (TREE_VALUE (args));
     913            8 :   if (prec > MAX_FIXED_MODE_SIZE)
     914              :     {
     915            0 :       warning (OPT_Wattributes, "%qE attribute with unsupported boolean "
     916              :                "precision", name);
     917            0 :       return NULL_TREE;
     918              :     }
     919              : 
     920            4 :   tree new_type = build_nonstandard_boolean_type (prec);
     921            4 :   *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
     922              : 
     923            4 :   return NULL_TREE;
     924              : }
     925              : 
     926              : /* Handle a "hardbool" attribute; arguments as in struct
     927              :    attribute_spec.handler.  */
     928              : 
     929              : static tree
     930          492 : handle_hardbool_attribute (tree *node, tree name, tree args,
     931              :                            int /* flags */, bool *no_add_attrs)
     932              : {
     933          492 :   if (c_language != clk_c)
     934              :     {
     935            0 :       error ("%qE attribute only supported in C", name);
     936            0 :       *no_add_attrs = TRUE;
     937            0 :       return NULL_TREE;
     938              :     }
     939              : 
     940          492 :   if (!TYPE_P (*node) || TREE_CODE (*node) != INTEGER_TYPE)
     941              :     {
     942            5 :       error ("%qE attribute only supported on "
     943              :              "integral types", name);
     944            5 :       *no_add_attrs = TRUE;
     945            5 :       return NULL_TREE;
     946              :     }
     947              : 
     948          487 :   tree orig = *node;
     949              :   /* Drop qualifiers from the base type.  Keep attributes, so that, in the odd
     950              :      chance attributes are applicable and relevant to the base type, if they
     951              :      are specified first, or through a typedef, they wouldn't be dropped on the
     952              :      floor here.  */
     953          487 :   tree unqual = build_qualified_type (orig, TYPE_UNQUALIFIED);
     954          487 :   *node = build_distinct_type_copy (unqual);
     955              : 
     956          487 :   TREE_SET_CODE (*node, ENUMERAL_TYPE);
     957          487 :   ENUM_UNDERLYING_TYPE (*node) = unqual;
     958          487 :   SET_TYPE_STRUCTURAL_EQUALITY (*node);
     959              : 
     960          487 :   tree false_value;
     961          487 :   if (args)
     962          481 :     false_value = fold_convert (*node, TREE_VALUE (args));
     963              :   else
     964            6 :     false_value = fold_convert (*node, integer_zero_node);
     965              : 
     966          487 :   if (TREE_OVERFLOW_P (false_value))
     967              :     {
     968          114 :       warning (OPT_Wattributes,
     969              :                "overflows in conversion from %qT to %qT "
     970              :                "changes value from %qE to %qE",
     971           57 :                TREE_TYPE (TREE_VALUE (args)), *node,
     972           57 :                TREE_VALUE (args), false_value);
     973           57 :       TREE_OVERFLOW (false_value) = false;
     974              :     }
     975              : 
     976          487 :   tree true_value;
     977          487 :   if (args && TREE_CHAIN (args))
     978          480 :     true_value = fold_convert (*node, TREE_VALUE (TREE_CHAIN (args)));
     979              :   else
     980            7 :     true_value = fold_build1 (BIT_NOT_EXPR, *node, false_value);
     981              : 
     982          487 :   if (TREE_OVERFLOW_P (true_value))
     983              :     {
     984           57 :       warning (OPT_Wattributes,
     985              :                "overflows in conversion from %qT to %qT "
     986              :                "changes value from %qE to %qE",
     987           57 :                TREE_TYPE (TREE_VALUE (TREE_CHAIN (args))), *node,
     988           57 :                TREE_VALUE (TREE_CHAIN (args)), true_value);
     989           57 :       TREE_OVERFLOW (true_value) = false;
     990              :     }
     991              : 
     992          487 :   if (tree_int_cst_compare (false_value, true_value) == 0)
     993              :     {
     994            2 :       error ("%qE attribute requires different values for"
     995              :              " %<false%> and %<true%> for type %qT",
     996              :              name, *node);
     997            2 :       *no_add_attrs = TRUE;
     998            2 :       return NULL_TREE;
     999              :     }
    1000              : 
    1001          485 :   tree values = build_tree_list (get_identifier ("false"),
    1002              :                                  false_value);
    1003          485 :   TREE_CHAIN (values) = build_tree_list (get_identifier ("true"),
    1004              :                                          true_value);
    1005              : 
    1006              :   /* Do *not* set TYPE_MIN_VALUE, TYPE_MAX_VALUE, nor TYPE_PRECISION according
    1007              :      to the false and true values.  That might cause the constants to be the
    1008              :      only acceptable values, which would drop the very hardening checks this
    1009              :      attribute is supposed to add.  */
    1010              : 
    1011          485 :   TYPE_ATTRIBUTES (*node) = tree_cons (name, args,
    1012          485 :                                        TYPE_ATTRIBUTES (*node));
    1013          485 :   *no_add_attrs = TRUE;
    1014              : 
    1015          485 :   gcc_checking_assert (!TYPE_CACHED_VALUES_P (*node));
    1016          485 :   TYPE_VALUES (*node) = values;
    1017              : 
    1018          485 :   if (TYPE_QUALS (orig) != TYPE_QUALS (*node))
    1019           14 :     *node = build_qualified_type (*node, TYPE_QUALS (orig));
    1020              : 
    1021          485 :   if (TREE_CODE (orig) == TYPE_DECL)
    1022            0 :     TYPE_NAME (*node) = TYPE_NAME (orig);
    1023              :   else
    1024          485 :     TYPE_NAME (*node) = NULL_TREE;
    1025              : 
    1026              :   return NULL_TREE;
    1027              : }
    1028              : 
    1029              : /* Handle a "packed" attribute; arguments as in
    1030              :    struct attribute_spec.handler.  */
    1031              : 
    1032              : static tree
    1033         5495 : handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1034              :                          int flags, bool *no_add_attrs)
    1035              : {
    1036         5495 :   if (TYPE_P (*node))
    1037              :     {
    1038         2579 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1039              :         {
    1040           68 :           warning (OPT_Wattributes,
    1041              :                    "%qE attribute ignored for type %qT", name, *node);
    1042           68 :           *no_add_attrs = true;
    1043              :         }
    1044              :       else
    1045         2511 :         TYPE_PACKED (*node) = 1;
    1046              :     }
    1047         2916 :   else if (TREE_CODE (*node) == FIELD_DECL)
    1048              :     {
    1049         2904 :       if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
    1050              :           /* Still pack bitfields.  */
    1051         2904 :           && ! DECL_C_BIT_FIELD (*node))
    1052          448 :         warning (OPT_Wattributes,
    1053              :                  "%qE attribute ignored for field of type %qT",
    1054          448 :                  name, TREE_TYPE (*node));
    1055              :       else
    1056         2456 :         DECL_PACKED (*node) = 1;
    1057              :     }
    1058              :   /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
    1059              :      used for DECL_REGISTER.  It wouldn't mean anything anyway.
    1060              :      We can't set DECL_PACKED on the type of a TYPE_DECL, because
    1061              :      that changes what the typedef is typing.  */
    1062              :   else
    1063              :     {
    1064           12 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1065           12 :       *no_add_attrs = true;
    1066              :     }
    1067              : 
    1068         5495 :   return NULL_TREE;
    1069              : }
    1070              : 
    1071              : /* Handle a "nocommon" attribute; arguments as in
    1072              :    struct attribute_spec.handler.  */
    1073              : 
    1074              : static tree
    1075           11 : handle_nocommon_attribute (tree *node, tree name,
    1076              :                            tree ARG_UNUSED (args),
    1077              :                            int ARG_UNUSED (flags), bool *no_add_attrs)
    1078              : {
    1079           11 :   if (VAR_P (*node))
    1080           11 :     DECL_COMMON (*node) = 0;
    1081              :   else
    1082              :     {
    1083            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1084            0 :       *no_add_attrs = true;
    1085              :     }
    1086              : 
    1087           11 :   return NULL_TREE;
    1088              : }
    1089              : 
    1090              : /* Handle a "common" attribute; arguments as in
    1091              :    struct attribute_spec.handler.  */
    1092              : 
    1093              : static tree
    1094           41 : handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1095              :                          int ARG_UNUSED (flags), bool *no_add_attrs)
    1096              : {
    1097           41 :   if (VAR_P (*node))
    1098           37 :     DECL_COMMON (*node) = 1;
    1099              :   else
    1100              :     {
    1101            4 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1102            4 :       *no_add_attrs = true;
    1103              :     }
    1104              : 
    1105           41 :   return NULL_TREE;
    1106              : }
    1107              : 
    1108              : /* Handle a "musttail" attribute; arguments as in
    1109              :    struct attribute_spec.handler.  */
    1110              : 
    1111              : tree
    1112            3 : handle_musttail_attribute (tree ARG_UNUSED (*node), tree name, tree ARG_UNUSED (args),
    1113              :                            int ARG_UNUSED (flags), bool *no_add_attrs)
    1114              : {
    1115              :   /* Currently only a statement attribute, handled directly in parser.  */
    1116            3 :   warning (OPT_Wattributes, "%qE attribute ignored", name);
    1117            3 :   *no_add_attrs = true;
    1118            3 :   return NULL_TREE;
    1119              : }
    1120              : 
    1121              : /* Handle a "noreturn" attribute; arguments as in
    1122              :    struct attribute_spec.handler.  */
    1123              : 
    1124              : tree
    1125      4165296 : handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1126              :                            int ARG_UNUSED (flags), bool *no_add_attrs)
    1127              : {
    1128      4165296 :   tree type = TREE_TYPE (*node);
    1129              : 
    1130              :   /* See FIXME comment in c_common_attribute_table.  */
    1131      4165296 :   if (TREE_CODE (*node) == FUNCTION_DECL
    1132      4165296 :       || objc_method_decl (TREE_CODE (*node)))
    1133      4165139 :     TREE_THIS_VOLATILE (*node) = 1;
    1134          157 :   else if (TREE_CODE (type) == POINTER_TYPE
    1135          157 :            && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
    1136           47 :     TREE_TYPE (*node)
    1137           47 :       = (build_qualified_type
    1138           94 :          (build_pointer_type
    1139           94 :           (build_type_variant (TREE_TYPE (type),
    1140              :                                TYPE_READONLY (TREE_TYPE (type)), 1)),
    1141           47 :           TYPE_QUALS (type)));
    1142              :   else
    1143              :     {
    1144          110 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1145          110 :       *no_add_attrs = true;
    1146              :     }
    1147              : 
    1148      4165296 :   return NULL_TREE;
    1149              : }
    1150              : 
    1151              : /* Handle a "hot" and attribute; arguments as in
    1152              :    struct attribute_spec.handler.  */
    1153              : 
    1154              : static tree
    1155          162 : handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1156              :                       int ARG_UNUSED (flags), bool *no_add_attrs)
    1157              : {
    1158          162 :   if (TREE_CODE (*node) == FUNCTION_DECL
    1159          162 :       || TREE_CODE (*node) == LABEL_DECL)
    1160              :     {
    1161              :       /* Attribute hot processing is done later with lookup_attribute.  */
    1162              :     }
    1163            9 :   else if ((TREE_CODE (*node) == RECORD_TYPE
    1164            9 :             || TREE_CODE (*node) == UNION_TYPE)
    1165            6 :            && c_dialect_cxx ()
    1166            6 :            && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1167              :     {
    1168              :       /* Check conflict here as decl_attributes will otherwise only catch
    1169              :          it late at the function when the attribute is used on a class.  */
    1170            6 :       tree cold_attr = lookup_attribute ("cold", TYPE_ATTRIBUTES (*node));
    1171            6 :       if (cold_attr)
    1172              :         {
    1173            0 :           warning (OPT_Wattributes, "ignoring attribute %qE because it "
    1174              :                    "conflicts with attribute %qs", name, "cold");
    1175            0 :           *no_add_attrs = true;
    1176              :         }
    1177              :     }
    1178            3 :   else if (flags & ((int) ATTR_FLAG_FUNCTION_NEXT
    1179              :                     | (int) ATTR_FLAG_DECL_NEXT))
    1180              :     {
    1181              :         /* Avoid applying the attribute to a function return type when
    1182              :            used as:  void __attribute ((hot)) foo (void).  It will be
    1183              :            passed to the function.  */
    1184            3 :         *no_add_attrs = true;
    1185              :     }
    1186              :   else
    1187              :     {
    1188            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1189            0 :       *no_add_attrs = true;
    1190              :     }
    1191              : 
    1192          162 :   return NULL_TREE;
    1193              : }
    1194              : 
    1195              : /* Handle a "cold" and attribute; arguments as in
    1196              :    struct attribute_spec.handler.  */
    1197              : 
    1198              : static tree
    1199      1932396 : handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1200              :                        int ARG_UNUSED (flags), bool *no_add_attrs)
    1201              : {
    1202      1932396 :   if (TREE_CODE (*node) == FUNCTION_DECL
    1203      1932396 :       || TREE_CODE (*node) == LABEL_DECL)
    1204              :     {
    1205              :       /* Attribute cold processing is done later with lookup_attribute.  */
    1206              :     }
    1207           28 :   else if ((TREE_CODE (*node) == RECORD_TYPE
    1208           28 :             || TREE_CODE (*node) == UNION_TYPE)
    1209            6 :            && c_dialect_cxx ()
    1210            6 :            && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1211              :     {
    1212              :       /* Check conflict here as decl_attributes will otherwise only catch
    1213              :          it late at the function when the attribute is used on a class.  */
    1214            6 :       tree hot_attr = lookup_attribute ("hot", TYPE_ATTRIBUTES (*node));
    1215            6 :       if (hot_attr)
    1216              :         {
    1217            0 :           warning (OPT_Wattributes, "ignoring attribute %qE because it "
    1218              :                    "conflicts with attribute %qs", name, "hot");
    1219            0 :           *no_add_attrs = true;
    1220              :         }
    1221              :     }
    1222           22 :   else if (flags & ((int) ATTR_FLAG_FUNCTION_NEXT
    1223              :                     | (int) ATTR_FLAG_DECL_NEXT))
    1224              :     {
    1225              :         /* Avoid applying the attribute to a function return type when
    1226              :            used as:  void __attribute ((cold)) foo (void).  It will be
    1227              :            passed to the function.  */
    1228            0 :         *no_add_attrs = true;
    1229              :     }
    1230              :   else
    1231              :     {
    1232           22 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1233           22 :       *no_add_attrs = true;
    1234              :     }
    1235              : 
    1236      1932396 :   return NULL_TREE;
    1237              : }
    1238              : 
    1239              : /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES.  */
    1240              : 
    1241              : void
    1242          582 : add_no_sanitize_value (tree node, sanitize_code_type flags)
    1243              : {
    1244          582 :   tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node));
    1245          582 :   if (attr)
    1246              :     {
    1247           21 :       sanitize_code_type old_value =
    1248           21 :         tree_to_sanitize_code_type (TREE_VALUE (attr));
    1249           21 :       flags |= old_value;
    1250              : 
    1251           21 :       if (flags == old_value)
    1252              :         return;
    1253              : 
    1254            7 :       TREE_VALUE (attr) = build_int_cst (uint64_type_node, flags);
    1255              :     }
    1256              :   else
    1257          561 :     DECL_ATTRIBUTES (node)
    1258         1122 :       = tree_cons (get_identifier ("no_sanitize"),
    1259          561 :                    build_int_cst (uint64_type_node, flags),
    1260          561 :                    DECL_ATTRIBUTES (node));
    1261              : }
    1262              : 
    1263              : /* Handle a "no_sanitize" attribute; arguments as in
    1264              :    struct attribute_spec.handler.  */
    1265              : 
    1266              : static tree
    1267          220 : handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
    1268              :                               bool *no_add_attrs)
    1269              : {
    1270          220 :   sanitize_code_type flags = 0;
    1271          220 :   *no_add_attrs = true;
    1272          220 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1273              :     {
    1274            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1275            0 :       return NULL_TREE;
    1276              :     }
    1277              : 
    1278          500 :   for (; args; args = TREE_CHAIN (args))
    1279              :     {
    1280          280 :       tree id = TREE_VALUE (args);
    1281          280 :       if (TREE_CODE (id) != STRING_CST)
    1282              :         {
    1283            0 :           error ("%qE argument not a string", name);
    1284            0 :           return NULL_TREE;
    1285              :         }
    1286              : 
    1287          280 :       char *string = ASTRDUP (TREE_STRING_POINTER (id));
    1288          280 :       flags |= parse_no_sanitize_attribute (string);
    1289              :     }
    1290              : 
    1291          220 :   add_no_sanitize_value (*node, flags);
    1292              : 
    1293          220 :   return NULL_TREE;
    1294              : }
    1295              : 
    1296              : /* Handle a "no_sanitize_address" attribute; arguments as in
    1297              :    struct attribute_spec.handler.  */
    1298              : 
    1299              : static tree
    1300          156 : handle_no_sanitize_address_attribute (tree *node, tree name, tree, int,
    1301              :                                       bool *no_add_attrs)
    1302              : {
    1303          156 :   *no_add_attrs = true;
    1304          156 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1305           14 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    1306              :   else
    1307          142 :     add_no_sanitize_value (*node, (sanitize_code_type) SANITIZE_ADDRESS);
    1308              : 
    1309          156 :   return NULL_TREE;
    1310              : }
    1311              : 
    1312              : /* Handle a "no_sanitize_thread" attribute; arguments as in
    1313              :    struct attribute_spec.handler.  */
    1314              : 
    1315              : static tree
    1316           24 : handle_no_sanitize_thread_attribute (tree *node, tree name, tree, int,
    1317              :                                       bool *no_add_attrs)
    1318              : {
    1319           24 :   *no_add_attrs = true;
    1320           24 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1321            0 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    1322              :   else
    1323           24 :     add_no_sanitize_value (*node, (sanitize_code_type) SANITIZE_THREAD);
    1324              : 
    1325           24 :   return NULL_TREE;
    1326              : }
    1327              : 
    1328              : 
    1329              : /* Handle a "no_address_safety_analysis" attribute; arguments as in
    1330              :    struct attribute_spec.handler.  */
    1331              : 
    1332              : static tree
    1333           28 : handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int,
    1334              :                                              bool *no_add_attrs)
    1335              : {
    1336           28 :   *no_add_attrs = true;
    1337           28 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1338           14 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    1339              :   else
    1340           14 :     add_no_sanitize_value (*node, (sanitize_code_type) SANITIZE_ADDRESS);
    1341              : 
    1342           28 :   return NULL_TREE;
    1343              : }
    1344              : 
    1345              : /* Handle a "no_sanitize_undefined" attribute; arguments as in
    1346              :    struct attribute_spec.handler.  */
    1347              : 
    1348              : static tree
    1349          145 : handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int,
    1350              :                                       bool *no_add_attrs)
    1351              : {
    1352          145 :   *no_add_attrs = true;
    1353          145 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1354            0 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    1355              :   else
    1356          145 :     add_no_sanitize_value (*node,
    1357              :                            SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT);
    1358              : 
    1359          145 :   return NULL_TREE;
    1360              : }
    1361              : 
    1362              : /* Handle a "no_sanitize_coverage" attribute; arguments as in
    1363              :    struct attribute_spec.handler.  */
    1364              : 
    1365              : static tree
    1366           16 : handle_no_sanitize_coverage_attribute (tree *node, tree name, tree, int,
    1367              :                                        bool *no_add_attrs)
    1368              : {
    1369           16 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1370              :     {
    1371            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1372            0 :       *no_add_attrs = true;
    1373              :     }
    1374              : 
    1375           16 :   return NULL_TREE;
    1376              : }
    1377              : 
    1378              : /* Handle an "asan odr indicator" attribute; arguments as in
    1379              :    struct attribute_spec.handler.  */
    1380              : 
    1381              : static tree
    1382            0 : handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *)
    1383              : {
    1384            0 :   return NULL_TREE;
    1385              : }
    1386              : 
    1387              : /* Handle a "stack_protect" attribute; arguments as in
    1388              :    struct attribute_spec.handler.  */
    1389              : 
    1390              : static tree
    1391           10 : handle_stack_protect_attribute (tree *node, tree name, tree, int,
    1392              :                                 bool *no_add_attrs)
    1393              : {
    1394           10 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1395              :     {
    1396            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1397            0 :       *no_add_attrs = true;
    1398              :     }
    1399              : 
    1400           10 :   return NULL_TREE;
    1401              : }
    1402              : 
    1403              : /* Handle a "no_stack_protector" attribute; arguments as in
    1404              :    struct attribute_spec.handler.  */
    1405              : 
    1406              : static tree
    1407            9 : handle_no_stack_protector_function_attribute (tree *node, tree name, tree,
    1408              :                                               int, bool *no_add_attrs)
    1409              : {
    1410            9 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1411              :     {
    1412            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1413            0 :       *no_add_attrs = true;
    1414              :     }
    1415              : 
    1416            9 :   return NULL_TREE;
    1417              : }
    1418              : 
    1419              : /* Handle a "noipa" attribute; arguments as in
    1420              :    struct attribute_spec.handler.  */
    1421              : 
    1422              : static tree
    1423        24441 : handle_noipa_attribute (tree *node, tree name, tree, int, bool *no_add_attrs)
    1424              : {
    1425        24441 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1426              :     {
    1427            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1428            0 :       *no_add_attrs = true;
    1429              :     }
    1430              : 
    1431        24441 :   return NULL_TREE;
    1432              : }
    1433              : 
    1434              : /* Handle a "strub" attribute; arguments as in
    1435              :    struct attribute_spec.handler.  */
    1436              : 
    1437              : static tree
    1438         2874 : handle_strub_attribute (tree *node, tree name,
    1439              :                         tree args,
    1440              :                         int ARG_UNUSED (flags), bool *no_add_attrs)
    1441              : {
    1442         2874 :   bool enable = true;
    1443              : 
    1444         2874 :   if (args && FUNCTION_POINTER_TYPE_P (*node))
    1445          134 :     *node = TREE_TYPE (*node);
    1446              : 
    1447         2874 :   if (args && FUNC_OR_METHOD_TYPE_P (*node))
    1448              :     {
    1449         2195 :       switch (strub_validate_fn_attr_parm (TREE_VALUE (args)))
    1450              :         {
    1451              :         case 1:
    1452              :         case 2:
    1453              :           enable = true;
    1454              :           break;
    1455              : 
    1456            0 :         case 0:
    1457            0 :           warning (OPT_Wattributes,
    1458              :                    "%qE attribute ignored because of argument %qE",
    1459            0 :                    name, TREE_VALUE (args));
    1460            0 :           *no_add_attrs = true;
    1461            0 :           enable = false;
    1462            0 :           break;
    1463              : 
    1464              :         case -1:
    1465              :         case -2:
    1466         1034 :           enable = false;
    1467              :           break;
    1468              : 
    1469            0 :         default:
    1470            0 :           gcc_unreachable ();
    1471              :         }
    1472              : 
    1473         2195 :       args = TREE_CHAIN (args);
    1474              :     }
    1475              : 
    1476         2195 :   if (args)
    1477              :     {
    1478            0 :       warning (OPT_Wattributes,
    1479              :                "ignoring attribute %qE because of excess arguments"
    1480              :                " starting at %qE",
    1481            0 :                name, TREE_VALUE (args));
    1482            0 :       *no_add_attrs = true;
    1483            0 :       enable = false;
    1484              :     }
    1485              : 
    1486              :   /* Warn about unmet expectations that the strub attribute works like a
    1487              :      qualifier.  ??? Could/should we extend it to the element/field types
    1488              :      here?  */
    1489         2874 :   if (TREE_CODE (*node) == ARRAY_TYPE
    1490              :       || VECTOR_TYPE_P (*node)
    1491         2874 :       || TREE_CODE (*node) == COMPLEX_TYPE)
    1492            8 :     warning (OPT_Wattributes,
    1493              :              "attribute %qE does not apply to elements"
    1494              :              " of non-scalar type %qT",
    1495              :              name, *node);
    1496         2866 :   else if (RECORD_OR_UNION_TYPE_P (*node))
    1497            4 :     warning (OPT_Wattributes,
    1498              :              "attribute %qE does not apply to fields"
    1499              :              " of aggregate type %qT",
    1500              :              name, *node);
    1501              : 
    1502              :   /* If we see a strub-enabling attribute, and we're at the default setting,
    1503              :      implicitly or explicitly, note that the attribute was seen, so that we can
    1504              :      reduce the compile-time overhead to nearly zero when the strub feature is
    1505              :      not used.  */
    1506         2874 :   if (enable && flag_strub < -2)
    1507          608 :     flag_strub += 2;
    1508              : 
    1509         2874 :   return NULL_TREE;
    1510              : }
    1511              : 
    1512              : /* Handle a "noclone" attribute; arguments as in
    1513              :    struct attribute_spec.handler.  */
    1514              : 
    1515              : static tree
    1516       154841 : handle_noclone_attribute (tree *node, tree name,
    1517              :                           tree ARG_UNUSED (args),
    1518              :                           int ARG_UNUSED (flags), bool *no_add_attrs)
    1519              : {
    1520       154841 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    1521              :     {
    1522            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1523            0 :       *no_add_attrs = true;
    1524              :     }
    1525              : 
    1526       154841 :   return NULL_TREE;
    1527              : }
    1528              : 
    1529              : /* Handle a "nocf_check" attribute; arguments as in
    1530              :    struct attribute_spec.handler.  */
    1531              : 
    1532              : static tree
    1533           99 : handle_nocf_check_attribute (tree *node, tree name,
    1534              :                           tree ARG_UNUSED (args),
    1535              :                           int ARG_UNUSED (flags), bool *no_add_attrs)
    1536              : {
    1537           99 :   if (TREE_CODE (*node) != FUNCTION_TYPE
    1538           99 :       && TREE_CODE (*node) != METHOD_TYPE)
    1539              :     {
    1540            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1541            0 :       *no_add_attrs = true;
    1542              :     }
    1543           99 :   else if (!(flag_cf_protection & CF_BRANCH))
    1544              :     {
    1545           34 :       warning (OPT_Wattributes, "%qE attribute ignored. Use "
    1546              :                                 "%<-fcf-protection%> option to enable it",
    1547              :                                 name);
    1548           34 :       *no_add_attrs = true;
    1549              :     }
    1550              : 
    1551           99 :   return NULL_TREE;
    1552              : }
    1553              : 
    1554              : /* Handle a "no_icf" attribute; arguments as in
    1555              :    struct attribute_spec.handler.  */
    1556              : 
    1557              : static tree
    1558        24456 : handle_noicf_attribute (tree *node, tree name,
    1559              :                         tree ARG_UNUSED (args),
    1560              :                         int ARG_UNUSED (flags), bool *no_add_attrs)
    1561              : {
    1562        24456 :   if (TREE_CODE (*node) != FUNCTION_DECL
    1563        24456 :       && (TREE_CODE (*node) != VAR_DECL || !is_global_var (*node)))
    1564              :     {
    1565            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1566            0 :       *no_add_attrs = true;
    1567              :     }
    1568              : 
    1569        24456 :   return NULL_TREE;
    1570              : }
    1571              : 
    1572              : /* Handle a "gnu_inline" attribute; arguments as in
    1573              :    struct attribute_spec.handler.  */
    1574              : 
    1575              : static tree
    1576     38755167 : handle_gnu_inline_attribute (tree *node, tree name,
    1577              :                              tree ARG_UNUSED (args),
    1578              :                              int ARG_UNUSED (flags),
    1579              :                              bool *no_add_attrs)
    1580              : {
    1581     38755167 :   if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
    1582              :     {
    1583              :       /* Do nothing else, just set the attribute.  We'll get at
    1584              :          it later with lookup_attribute.  */
    1585              :     }
    1586              :   else
    1587              :     {
    1588        68938 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1589        68938 :       *no_add_attrs = true;
    1590              :     }
    1591              : 
    1592     38755167 :   return NULL_TREE;
    1593              : }
    1594              : 
    1595              : /* Handle an "artificial" attribute; arguments as in
    1596              :    struct attribute_spec.handler.  */
    1597              : 
    1598              : static tree
    1599     38104711 : handle_artificial_attribute (tree *node, tree name,
    1600              :                              tree ARG_UNUSED (args),
    1601              :                              int ARG_UNUSED (flags),
    1602              :                              bool *no_add_attrs)
    1603              : {
    1604     38104711 :   if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node))
    1605              :     {
    1606              :       /* Do nothing else, just set the attribute.  We'll get at
    1607              :          it later with lookup_attribute.  */
    1608              :     }
    1609              :   else
    1610              :     {
    1611        68938 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1612        68938 :       *no_add_attrs = true;
    1613              :     }
    1614              : 
    1615     38104711 :   return NULL_TREE;
    1616              : }
    1617              : 
    1618              : /* Handle a "flatten" attribute; arguments as in
    1619              :    struct attribute_spec.handler.  */
    1620              : 
    1621              : static tree
    1622          159 : handle_flatten_attribute (tree *node, tree name,
    1623              :                           tree args ATTRIBUTE_UNUSED,
    1624              :                           int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
    1625              : {
    1626          159 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    1627              :     /* Do nothing else, just set the attribute.  We'll get at
    1628              :        it later with lookup_attribute.  */
    1629              :     ;
    1630              :   else
    1631              :     {
    1632            4 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1633            4 :       *no_add_attrs = true;
    1634              :     }
    1635              : 
    1636          159 :   return NULL_TREE;
    1637              : }
    1638              : 
    1639              : /* Handle a "warning" or "error" attribute; arguments as in
    1640              :    struct attribute_spec.handler.  */
    1641              : 
    1642              : static tree
    1643          108 : handle_error_attribute (tree *node, tree name, tree args,
    1644              :                         int ARG_UNUSED (flags), bool *no_add_attrs)
    1645              : {
    1646          108 :   if (TREE_CODE (*node) == FUNCTION_DECL
    1647          215 :       && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
    1648              :     /* Do nothing else, just set the attribute.  We'll get at
    1649              :        it later with lookup_attribute.  */
    1650              :     ;
    1651              :   else
    1652              :     {
    1653            3 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1654            3 :       *no_add_attrs = true;
    1655              :     }
    1656              : 
    1657          108 :   return NULL_TREE;
    1658              : }
    1659              : 
    1660              : /* Handle a "unused" attribute; arguments as in
    1661              :    struct attribute_spec.handler.  */
    1662              : 
    1663              : tree
    1664       802643 : handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1665              :                          int flags, bool *no_add_attrs)
    1666              : {
    1667       802643 :   if (DECL_P (*node))
    1668              :     {
    1669       802489 :       tree decl = *node;
    1670              : 
    1671       802489 :       if (TREE_CODE (decl) == PARM_DECL
    1672       512167 :           || VAR_OR_FUNCTION_DECL_P (decl)
    1673       122479 :           || TREE_CODE (decl) == LABEL_DECL
    1674       122398 :           || TREE_CODE (decl) == CONST_DECL
    1675          287 :           || TREE_CODE (decl) == FIELD_DECL
    1676          266 :           || TREE_CODE (decl) == TYPE_DECL)
    1677              :         {
    1678       802488 :           TREE_USED (decl) = 1;
    1679       802488 :           if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
    1680       524110 :             DECL_READ_P (decl) = 1;
    1681              :         }
    1682              :       else
    1683              :         {
    1684            1 :           warning (OPT_Wattributes, "%qE attribute ignored", name);
    1685            1 :           *no_add_attrs = true;
    1686              :         }
    1687              :     }
    1688              :   else
    1689              :     {
    1690          154 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1691           85 :         *node = build_variant_type_copy (*node);
    1692          154 :       TREE_USED (*node) = 1;
    1693              :     }
    1694              : 
    1695       802643 :   return NULL_TREE;
    1696              : }
    1697              : 
    1698              : /* Handle an "uninitialized" attribute; arguments as in
    1699              :    struct attribute_spec.handler.  */
    1700              : 
    1701              : static tree
    1702        16694 : handle_uninitialized_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    1703              :                                 int ARG_UNUSED (flags), bool *no_add_attrs)
    1704              : {
    1705        16694 :   tree decl = *node;
    1706        16694 :   if (!VAR_P (decl))
    1707              :     {
    1708            8 :       warning (OPT_Wattributes, "%qE attribute ignored because %qD "
    1709              :                "is not a variable", name, decl);
    1710            8 :       *no_add_attrs = true;
    1711              :     }
    1712        16686 :   else if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
    1713              :     {
    1714           24 :       warning (OPT_Wattributes, "%qE attribute ignored because %qD "
    1715              :                "is not a local variable", name, decl);
    1716           24 :       *no_add_attrs = true;
    1717              :     }
    1718              : 
    1719        16694 :   return NULL_TREE;
    1720              : }
    1721              : 
    1722              : /* Handle a "externally_visible" attribute; arguments as in
    1723              :    struct attribute_spec.handler.  */
    1724              : 
    1725              : static tree
    1726       281080 : handle_externally_visible_attribute (tree *pnode, tree name,
    1727              :                                      tree ARG_UNUSED (args),
    1728              :                                      int ARG_UNUSED (flags),
    1729              :                                      bool *no_add_attrs)
    1730              : {
    1731       281080 :   tree node = *pnode;
    1732              : 
    1733       281080 :   if (VAR_OR_FUNCTION_DECL_P (node))
    1734              :     {
    1735       281038 :       if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
    1736       562114 :            && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
    1737              :         {
    1738           17 :           warning (OPT_Wattributes,
    1739              :                    "%qE attribute have effect only on public objects", name);
    1740           17 :           *no_add_attrs = true;
    1741              :         }
    1742              :     }
    1743              :   else
    1744              :     {
    1745            4 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1746            4 :       *no_add_attrs = true;
    1747              :     }
    1748              : 
    1749       281080 :   return NULL_TREE;
    1750              : }
    1751              : 
    1752              : /* Handle the "no_reorder" attribute.  Arguments as in
    1753              :    struct attribute_spec.handler.  */
    1754              : 
    1755              : static tree
    1756           17 : handle_no_reorder_attribute (tree *pnode,
    1757              :                              tree name,
    1758              :                              tree,
    1759              :                              int,
    1760              :                              bool *no_add_attrs)
    1761              : {
    1762           17 :   tree node = *pnode;
    1763              : 
    1764           15 :   if (!VAR_OR_FUNCTION_DECL_P (node)
    1765           17 :         && !(TREE_STATIC (node) || DECL_EXTERNAL (node)))
    1766              :     {
    1767            0 :       warning (OPT_Wattributes,
    1768              :                 "%qE attribute only affects top level objects",
    1769              :                 name);
    1770            0 :       *no_add_attrs = true;
    1771              :     }
    1772              : 
    1773           17 :   return NULL_TREE;
    1774              : }
    1775              : 
    1776              : /* Handle a "scalar_storage_order" attribute; arguments as in
    1777              :    struct attribute_spec.handler.  */
    1778              : 
    1779              : static tree
    1780          950 : handle_scalar_storage_order_attribute (tree *node, tree name, tree args,
    1781              :                                        int flags, bool *no_add_attrs)
    1782              : {
    1783          950 :   tree id = TREE_VALUE (args);
    1784          950 :   tree type;
    1785              : 
    1786          950 :   if (TREE_CODE (*node) == TYPE_DECL
    1787            3 :       && ! (flags & ATTR_FLAG_CXX11))
    1788            3 :     node = &TREE_TYPE (*node);
    1789          950 :   type = *node;
    1790              : 
    1791          950 :   if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN)
    1792              :     {
    1793              :       error ("%qE attribute is not supported because endianness is not uniform",
    1794              :              name);
    1795              :       return NULL_TREE;
    1796              :     }
    1797              : 
    1798          950 :   if (RECORD_OR_UNION_TYPE_P (type) && !c_dialect_cxx ())
    1799              :     {
    1800          947 :       bool reverse = false;
    1801              : 
    1802          947 :       if (TREE_CODE (id) == STRING_CST
    1803          947 :           && strcmp (TREE_STRING_POINTER (id), "big-endian") == 0)
    1804              :         reverse = !BYTES_BIG_ENDIAN;
    1805          452 :       else if (TREE_CODE (id) == STRING_CST
    1806          452 :                && strcmp (TREE_STRING_POINTER (id), "little-endian") == 0)
    1807              :         reverse = BYTES_BIG_ENDIAN;
    1808              :       else
    1809              :         {
    1810            3 :           error ("attribute %qE argument must be one of %qs or %qs",
    1811              :                  name, "big-endian", "little-endian");
    1812            3 :           return NULL_TREE;
    1813              :         }
    1814              : 
    1815          944 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1816              :         {
    1817            2 :           if (reverse)
    1818              :             /* A type variant isn't good enough, since we don't want a cast
    1819              :                to such a type to be removed as a no-op.  */
    1820            1 :             *node = type = build_duplicate_type (type);
    1821              :         }
    1822              : 
    1823          944 :       TYPE_REVERSE_STORAGE_ORDER (type) = reverse;
    1824          944 :       return NULL_TREE;
    1825              :     }
    1826              : 
    1827            3 :   warning (OPT_Wattributes, "%qE attribute ignored", name);
    1828            3 :   *no_add_attrs = true;
    1829            3 :   return NULL_TREE;
    1830              : }
    1831              : 
    1832              : /* Handle a "transparent_union" attribute; arguments as in
    1833              :    struct attribute_spec.handler.  */
    1834              : 
    1835              : static tree
    1836          150 : handle_transparent_union_attribute (tree *node, tree name,
    1837              :                                     tree ARG_UNUSED (args), int flags,
    1838              :                                     bool *no_add_attrs)
    1839              : {
    1840          150 :   tree type;
    1841              : 
    1842          150 :   *no_add_attrs = true;
    1843              : 
    1844          150 :   if (TREE_CODE (*node) == TYPE_DECL
    1845           89 :       && ! (flags & ATTR_FLAG_CXX11))
    1846           83 :     node = &TREE_TYPE (*node);
    1847          150 :   type = *node;
    1848              : 
    1849          150 :   if (TREE_CODE (type) == UNION_TYPE)
    1850              :     {
    1851              :       /* Make sure that the first field will work for a transparent union.
    1852              :          If the type isn't complete yet, leave the check to the code in
    1853              :          finish_struct.  */
    1854          144 :       if (TYPE_SIZE (type))
    1855              :         {
    1856           83 :           tree first = first_field (type);
    1857           83 :           if (first == NULL_TREE
    1858           71 :               || DECL_ARTIFICIAL (first)
    1859          154 :               || TYPE_MODE (type) != DECL_MODE (first))
    1860           12 :             goto ignored;
    1861              :         }
    1862              : 
    1863          132 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    1864              :         {
    1865              :           /* If the type isn't complete yet, setting the flag
    1866              :              on a variant wouldn't ever be checked.  */
    1867           65 :           if (!TYPE_SIZE (type))
    1868            0 :             goto ignored;
    1869              : 
    1870              :           /* build_duplicate_type doesn't work for C++.  */
    1871           65 :           if (c_dialect_cxx ())
    1872            3 :             goto ignored;
    1873              : 
    1874              :           /* A type variant isn't good enough, since we don't want a cast
    1875              :              to such a type to be removed as a no-op.  */
    1876           62 :           *node = type = build_duplicate_type (type);
    1877              :         }
    1878              : 
    1879          275 :       for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
    1880          146 :         TYPE_TRANSPARENT_AGGR (t) = 1;
    1881              :       return NULL_TREE;
    1882              :     }
    1883              : 
    1884            6 :  ignored:
    1885           21 :   warning (OPT_Wattributes, "%qE attribute ignored", name);
    1886           21 :   return NULL_TREE;
    1887              : }
    1888              : 
    1889              : /* Subroutine of handle_{con,de}structor_attribute.  Evaluate ARGS to
    1890              :    get the requested priority for a constructor or destructor,
    1891              :    possibly issuing diagnostics for invalid or reserved
    1892              :    priorities.  */
    1893              : 
    1894              : static priority_type
    1895          693 : get_priority (tree args, bool is_destructor)
    1896              : {
    1897          693 :   HOST_WIDE_INT pri;
    1898          693 :   tree arg;
    1899              : 
    1900          693 :   if (!args)
    1901              :     return DEFAULT_INIT_PRIORITY;
    1902              : 
    1903          273 :   if (!SUPPORTS_INIT_PRIORITY)
    1904              :     {
    1905              :       if (is_destructor)
    1906              :         error ("destructor priorities are not supported");
    1907              :       else
    1908              :         error ("constructor priorities are not supported");
    1909              :       return DEFAULT_INIT_PRIORITY;
    1910              :     }
    1911              : 
    1912          273 :   arg = TREE_VALUE (args);
    1913          273 :   if (TREE_CODE (arg) == IDENTIFIER_NODE || TREE_CODE (arg) == FUNCTION_DECL)
    1914            8 :     goto invalid;
    1915          265 :   if (arg == error_mark_node)
    1916              :     return DEFAULT_INIT_PRIORITY;
    1917          261 :   arg = default_conversion (arg);
    1918          261 :   if (!tree_fits_shwi_p (arg)
    1919          261 :       || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
    1920           11 :     goto invalid;
    1921              : 
    1922          250 :   pri = tree_to_shwi (arg);
    1923          250 :   if (pri < 0 || pri > MAX_INIT_PRIORITY)
    1924            8 :     goto invalid;
    1925              : 
    1926          242 :   if (pri <= MAX_RESERVED_INIT_PRIORITY)
    1927              :     {
    1928           24 :       if (is_destructor)
    1929            8 :         warning (OPT_Wprio_ctor_dtor,
    1930              :                  "destructor priorities from 0 to %d are reserved "
    1931              :                  "for the implementation",
    1932              :                  MAX_RESERVED_INIT_PRIORITY);
    1933              :       else
    1934           16 :         warning (OPT_Wprio_ctor_dtor,
    1935              :                  "constructor priorities from 0 to %d are reserved "
    1936              :                  "for the implementation",
    1937              :                  MAX_RESERVED_INIT_PRIORITY);
    1938              :     }
    1939          242 :   return pri;
    1940              : 
    1941           27 :  invalid:
    1942           27 :   if (is_destructor)
    1943           12 :     error ("destructor priorities must be integers from 0 to %d inclusive",
    1944              :            MAX_INIT_PRIORITY);
    1945              :   else
    1946           15 :     error ("constructor priorities must be integers from 0 to %d inclusive",
    1947              :            MAX_INIT_PRIORITY);
    1948              :   return DEFAULT_INIT_PRIORITY;
    1949              : }
    1950              : 
    1951              : /* Handle a "constructor" attribute; arguments as in
    1952              :    struct attribute_spec.handler.  */
    1953              : 
    1954              : static tree
    1955          506 : handle_constructor_attribute (tree *node, tree name, tree args,
    1956              :                               int ARG_UNUSED (flags),
    1957              :                               bool *no_add_attrs)
    1958              : {
    1959          506 :   tree decl = *node;
    1960          506 :   tree type = TREE_TYPE (decl);
    1961              : 
    1962          506 :   if (TREE_CODE (decl) == FUNCTION_DECL
    1963          506 :       && TREE_CODE (type) == FUNCTION_TYPE
    1964         1012 :       && decl_function_context (decl) == 0)
    1965              :     {
    1966          506 :       priority_type priority;
    1967          506 :       DECL_STATIC_CONSTRUCTOR (decl) = 1;
    1968          506 :       priority = get_priority (args, /*is_destructor=*/false);
    1969          506 :       SET_DECL_INIT_PRIORITY (decl, priority);
    1970          506 :       TREE_USED (decl) = 1;
    1971              :     }
    1972              :   else
    1973              :     {
    1974            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    1975            0 :       *no_add_attrs = true;
    1976              :     }
    1977              : 
    1978          506 :   return NULL_TREE;
    1979              : }
    1980              : 
    1981              : /* Handle a "destructor" attribute; arguments as in
    1982              :    struct attribute_spec.handler.  */
    1983              : 
    1984              : static tree
    1985          187 : handle_destructor_attribute (tree *node, tree name, tree args,
    1986              :                              int ARG_UNUSED (flags),
    1987              :                              bool *no_add_attrs)
    1988              : {
    1989          187 :   tree decl = *node;
    1990          187 :   tree type = TREE_TYPE (decl);
    1991              : 
    1992          187 :   if (TREE_CODE (decl) == FUNCTION_DECL
    1993          187 :       && TREE_CODE (type) == FUNCTION_TYPE
    1994          374 :       && decl_function_context (decl) == 0)
    1995              :     {
    1996          187 :       priority_type priority;
    1997          187 :       DECL_STATIC_DESTRUCTOR (decl) = 1;
    1998          187 :       priority = get_priority (args, /*is_destructor=*/true);
    1999          187 :       SET_DECL_FINI_PRIORITY (decl, priority);
    2000          187 :       TREE_USED (decl) = 1;
    2001              :     }
    2002              :   else
    2003              :     {
    2004            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    2005            0 :       *no_add_attrs = true;
    2006              :     }
    2007              : 
    2008          187 :   return NULL_TREE;
    2009              : }
    2010              : 
    2011              : /* Nonzero if the mode is a valid vector mode for this architecture.
    2012              :    This returns nonzero even if there is no hardware support for the
    2013              :    vector mode, but we can emulate with narrower modes.  */
    2014              : 
    2015              : static bool
    2016            0 : vector_mode_valid_p (machine_mode mode)
    2017              : {
    2018            0 :   enum mode_class mclass = GET_MODE_CLASS (mode);
    2019              : 
    2020              :   /* Doh!  What's going on?  */
    2021            0 :   if (mclass != MODE_VECTOR_INT
    2022            0 :       && mclass != MODE_VECTOR_FLOAT
    2023              :       && mclass != MODE_VECTOR_FRACT
    2024            0 :       && mclass != MODE_VECTOR_UFRACT
    2025              :       && mclass != MODE_VECTOR_ACCUM
    2026            0 :       && mclass != MODE_VECTOR_UACCUM)
    2027              :     return false;
    2028              : 
    2029              :   /* Hardware support.  Woo hoo!  */
    2030            0 :   if (targetm.vector_mode_supported_p (mode))
    2031              :     return true;
    2032              : 
    2033              :   /* We should probably return 1 if requesting V4DI and we have no DI,
    2034              :      but we have V2DI, but this is probably very unlikely.  */
    2035              : 
    2036              :   /* If we have support for the inner mode, we can safely emulate it.
    2037              :      We may not have V2DI, but me can emulate with a pair of DIs.  */
    2038            0 :   return targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
    2039              : }
    2040              : 
    2041              : 
    2042              : /* Handle a "mode" attribute; arguments as in
    2043              :    struct attribute_spec.handler.  */
    2044              : 
    2045              : static tree
    2046        55442 : handle_mode_attribute (tree *node, tree name, tree args,
    2047              :                        int ARG_UNUSED (flags), bool *no_add_attrs)
    2048              : {
    2049        55442 :   tree type = *node;
    2050        55442 :   tree ident = TREE_VALUE (args);
    2051              : 
    2052        55442 :   *no_add_attrs = true;
    2053              : 
    2054        55442 :   if (TREE_CODE (ident) != IDENTIFIER_NODE)
    2055            2 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    2056              :   else
    2057              :     {
    2058        55440 :       const char *p = IDENTIFIER_POINTER (ident);
    2059        55440 :       int len = strlen (p);
    2060        55440 :       machine_mode mode = VOIDmode;
    2061        55440 :       tree typefm;
    2062        55440 :       bool valid_mode;
    2063              : 
    2064        55440 :       if (len > 4 && p[0] == '_' && p[1] == '_'
    2065        35769 :           && p[len - 1] == '_' && p[len - 2] == '_')
    2066              :         {
    2067        35769 :           char *newp = (char *) alloca (len - 1);
    2068              : 
    2069        35769 :           strcpy (newp, &p[2]);
    2070        35769 :           newp[len - 4] = '\0';
    2071        35769 :           p = newp;
    2072              :         }
    2073              : 
    2074              :       /* Change this type to have a type with the specified mode.
    2075              :          First check for the special modes.  */
    2076        55440 :       if (!strcmp (p, "byte"))
    2077           82 :         mode = byte_mode;
    2078        55358 :       else if (!strcmp (p, "word"))
    2079        33498 :         mode = word_mode;
    2080        21860 :       else if (!strcmp (p, "pointer"))
    2081          767 :         mode = ptr_mode;
    2082        21093 :       else if (!strcmp (p, "libgcc_cmp_return"))
    2083          814 :         mode = targetm.libgcc_cmp_return_mode ();
    2084        20279 :       else if (!strcmp (p, "libgcc_shift_count"))
    2085          308 :         mode = targetm.libgcc_shift_count_mode ();
    2086        19971 :       else if (!strcmp (p, "unwind_word"))
    2087          410 :         mode = targetm.unwind_word_mode ();
    2088              :       else
    2089        19561 :         parse_machine_mode (p, &mode);
    2090              : 
    2091        55440 :       if (mode == VOIDmode)
    2092              :         {
    2093            2 :           error ("unknown machine mode %qE", ident);
    2094           10 :           return NULL_TREE;
    2095              :         }
    2096              : 
    2097              :       /* Allow the target a chance to translate MODE into something supported.
    2098              :          See PR86324.  */
    2099        55438 :       mode = targetm.translate_mode_attribute (mode);
    2100              : 
    2101        55438 :       valid_mode = false;
    2102        55438 :       switch (GET_MODE_CLASS (mode))
    2103              :         {
    2104        53428 :         case MODE_INT:
    2105        53428 :         case MODE_PARTIAL_INT:
    2106        53428 :         case MODE_FLOAT:
    2107        53428 :         case MODE_DECIMAL_FLOAT:
    2108        53428 :         case MODE_FRACT:
    2109        53428 :         case MODE_UFRACT:
    2110        53428 :         case MODE_ACCUM:
    2111        53428 :         case MODE_UACCUM:
    2112        53428 :           valid_mode
    2113        53428 :             = targetm.scalar_mode_supported_p (as_a <scalar_mode> (mode));
    2114        53428 :           break;
    2115              : 
    2116         2010 :         case MODE_COMPLEX_INT:
    2117         2010 :         case MODE_COMPLEX_FLOAT:
    2118         2010 :           valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode));
    2119         2010 :           break;
    2120              : 
    2121            0 :         case MODE_VECTOR_INT:
    2122            0 :         case MODE_VECTOR_FLOAT:
    2123            0 :         case MODE_VECTOR_FRACT:
    2124            0 :         case MODE_VECTOR_UFRACT:
    2125            0 :         case MODE_VECTOR_ACCUM:
    2126            0 :         case MODE_VECTOR_UACCUM:
    2127            0 :           warning (OPT_Wattributes, "specifying vector types with "
    2128              :                    "%<__attribute__ ((mode))%> is deprecated");
    2129            0 :           inform (input_location,
    2130              :                   "use %<__attribute__ ((vector_size))%> instead");
    2131            0 :           valid_mode = vector_mode_valid_p (mode);
    2132            0 :           break;
    2133              : 
    2134              :         default:
    2135              :           break;
    2136              :         }
    2137        55438 :       if (!valid_mode)
    2138              :         {
    2139            7 :           error ("unable to emulate %qs", p);
    2140            7 :           return NULL_TREE;
    2141              :         }
    2142              : 
    2143        55431 :       if (POINTER_TYPE_P (type))
    2144              :         {
    2145            0 :           scalar_int_mode addr_mode;
    2146            0 :           addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
    2147            0 :           tree (*fn)(tree, machine_mode, bool);
    2148              : 
    2149            0 :           if (!is_a <scalar_int_mode> (mode, &addr_mode)
    2150            0 :               || !targetm.addr_space.valid_pointer_mode (addr_mode, as))
    2151              :             {
    2152            0 :               error ("invalid pointer mode %qs", p);
    2153            0 :               return NULL_TREE;
    2154              :             }
    2155              : 
    2156            0 :           if (TREE_CODE (type) == POINTER_TYPE)
    2157              :             fn = build_pointer_type_for_mode;
    2158              :           else
    2159            0 :             fn = build_reference_type_for_mode;
    2160            0 :           typefm = fn (TREE_TYPE (type), addr_mode, false);
    2161              :         }
    2162              :       else
    2163              :         {
    2164              :           /* For fixed-point modes, we need to test if the signness of type
    2165              :              and the machine mode are consistent.  */
    2166        55431 :           if (ALL_FIXED_POINT_MODE_P (mode)
    2167        55431 :               && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode))
    2168              :             {
    2169            0 :               error ("signedness of type and machine mode %qs don%'t match", p);
    2170            0 :               return NULL_TREE;
    2171              :             }
    2172              :           /* For fixed-point modes, we need to pass saturating info.  */
    2173       110862 :           typefm = lang_hooks.types.type_for_mode (mode,
    2174        55431 :                         ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type)
    2175        55431 :                                                       : TYPE_UNSIGNED (type));
    2176              :         }
    2177              : 
    2178        55431 :       if (typefm == NULL_TREE)
    2179              :         {
    2180            0 :           error ("no data type for mode %qs", p);
    2181            0 :           return NULL_TREE;
    2182              :         }
    2183        55431 :       else if (TREE_CODE (type) == ENUMERAL_TYPE)
    2184              :         {
    2185              :           /* For enumeral types, copy the precision from the integer
    2186              :              type returned above.  If not an INTEGER_TYPE, we can't use
    2187              :              this mode for this type.  */
    2188          108 :           if (TREE_CODE (typefm) != INTEGER_TYPE)
    2189              :             {
    2190            0 :               error ("cannot use mode %qs for enumerated types", p);
    2191            0 :               return NULL_TREE;
    2192              :             }
    2193              : 
    2194          108 :           if (flags & ATTR_FLAG_TYPE_IN_PLACE)
    2195              :             {
    2196           34 :               TYPE_PRECISION (type) = TYPE_PRECISION (typefm);
    2197           34 :               typefm = type;
    2198              :             }
    2199              :           else
    2200              :             {
    2201              :               /* We cannot build a type variant, as there's code that assumes
    2202              :                  that TYPE_MAIN_VARIANT has the same mode.  This includes the
    2203              :                  debug generators.  Instead, create a subrange type.  This
    2204              :                  results in all of the enumeral values being emitted only once
    2205              :                  in the original, and the subtype gets them by reference.  */
    2206           74 :               if (TYPE_UNSIGNED (type))
    2207           74 :                 typefm = make_unsigned_type (TYPE_PRECISION (typefm));
    2208              :               else
    2209            0 :                 typefm = make_signed_type (TYPE_PRECISION (typefm));
    2210           74 :               TREE_TYPE (typefm) = type;
    2211              :             }
    2212          108 :           *no_add_attrs = false;
    2213              :         }
    2214       110646 :       else if (VECTOR_MODE_P (mode)
    2215        55323 :                ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
    2216        55323 :                : TREE_CODE (type) != TREE_CODE (typefm))
    2217              :         {
    2218            1 :           error ("mode %qs applied to inappropriate type", p);
    2219            1 :           return NULL_TREE;
    2220              :         }
    2221              : 
    2222              :       /* Copy any quals and attributes to the new type.  */
    2223        55430 :       *node = build_type_attribute_qual_variant (typefm, TYPE_ATTRIBUTES (type),
    2224        55430 :                                                  TYPE_QUALS (type));
    2225        55430 :       if (TYPE_USER_ALIGN (type))
    2226            4 :         *node = build_aligned_type (*node, TYPE_ALIGN (type));
    2227              :     }
    2228              : 
    2229              :   return NULL_TREE;
    2230              : }
    2231              : 
    2232              : /* Common codes shared by handle_warn_if_not_aligned_attribute and
    2233              :    handle_aligned_attribute.  */
    2234              : 
    2235              : static tree
    2236       658992 : common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
    2237              :                                  bool *no_add_attrs,
    2238              :                                  bool warn_if_not_aligned_p)
    2239              : {
    2240       658992 :   tree decl = NULL_TREE;
    2241       658992 :   tree *type = NULL;
    2242       658992 :   bool is_type = false;
    2243       658992 :   tree align_expr;
    2244              : 
    2245              :   /* The last (already pushed) declaration with all validated attributes
    2246              :      merged in or the current about-to-be-pushed one if one hasn't been
    2247              :      yet.  */
    2248       658992 :   tree last_decl = node[1] ? node[1] : *node;
    2249              : 
    2250       658992 :   if (args)
    2251              :     {
    2252       618992 :       align_expr = TREE_VALUE (args);
    2253       618992 :       if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE
    2254       618992 :           && TREE_CODE (align_expr) != FUNCTION_DECL)
    2255       618984 :         align_expr = default_conversion (align_expr);
    2256              :     }
    2257              :   else
    2258        80000 :     align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT);
    2259              : 
    2260       658992 :   if (DECL_P (*node))
    2261              :     {
    2262       629567 :       decl = *node;
    2263       629567 :       type = &TREE_TYPE (decl);
    2264       629567 :       is_type = TREE_CODE (*node) == TYPE_DECL;
    2265              :     }
    2266        29425 :   else if (TYPE_P (*node))
    2267        29425 :     type = node, is_type = true;
    2268              : 
    2269              :   /* True to consider invalid alignments greater than MAX_OFILE_ALIGNMENT.  */
    2270      1317984 :   bool objfile = (TREE_CODE (*node) == FUNCTION_DECL
    2271       658992 :                   || (VAR_P (*node) && TREE_STATIC (*node)));
    2272              :   /* Log2 of specified alignment.  */
    2273       658992 :   int pow2align = check_user_alignment (align_expr, objfile,
    2274              :                                         /* warn_zero = */ true);
    2275       658992 :   if (pow2align == -1)
    2276              :     {
    2277          158 :       *no_add_attrs = true;
    2278          158 :       return NULL_TREE;
    2279              :     }
    2280              : 
    2281              :   /* The alignment in bits corresponding to the specified alignment.  */
    2282       658834 :   unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT;
    2283              : 
    2284              :   /* The alignment of the current declaration and that of the last
    2285              :      pushed declaration, determined on demand below.  */
    2286       658834 :   unsigned curalign = 0;
    2287       658834 :   unsigned lastalign = 0;
    2288              : 
    2289              :   /* True when SET_DECL_ALIGN() should be called for the decl when
    2290              :      *NO_ADD_ATTRS is false.  */
    2291       658834 :   bool set_align = true;
    2292       658834 :   if (is_type)
    2293              :     {
    2294       276015 :       if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    2295              :         /* OK, modify the type in place.  */;
    2296              :       /* If we have a TYPE_DECL, then copy the type, so that we
    2297              :          don't accidentally modify a builtin type.  See pushdecl.  */
    2298       234904 :       else if (decl && TREE_TYPE (decl) != error_mark_node
    2299       470295 :                && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
    2300              :         {
    2301       234805 :           tree tt = TREE_TYPE (decl);
    2302       234805 :           *type = build_variant_type_copy (*type);
    2303       234805 :           DECL_ORIGINAL_TYPE (decl) = tt;
    2304       234805 :           TYPE_NAME (*type) = decl;
    2305       234805 :           TREE_USED (*type) = TREE_USED (decl);
    2306       234805 :           TREE_TYPE (decl) = *type;
    2307              :         }
    2308              :       else
    2309          586 :         *type = build_variant_type_copy (*type);
    2310              : 
    2311       276015 :       if (warn_if_not_aligned_p)
    2312              :         {
    2313           72 :           SET_TYPE_WARN_IF_NOT_ALIGN (*type, bitalign);
    2314           72 :           warn_if_not_aligned_p = false;
    2315              :         }
    2316              :       else
    2317              :         {
    2318       275943 :           SET_TYPE_ALIGN (*type, bitalign);
    2319       275943 :           TYPE_USER_ALIGN (*type) = 1;
    2320              :         }
    2321              :     }
    2322       382819 :   else if (! VAR_OR_FUNCTION_DECL_P (decl)
    2323       345498 :            && TREE_CODE (decl) != FIELD_DECL)
    2324              :     {
    2325           55 :       error ("alignment may not be specified for %q+D", decl);
    2326           55 :       *no_add_attrs = true;
    2327              :     }
    2328       382764 :   else if (TREE_CODE (decl) == FUNCTION_DECL
    2329       382764 :            && (((curalign = DECL_ALIGN (decl)) > bitalign)
    2330          319 :                | ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
    2331              :     {
    2332              :       /* Either a prior attribute on the same declaration or one
    2333              :          on a prior declaration of the same function specifies
    2334              :          stricter alignment than this attribute.  */
    2335           50 :       bool note = (lastalign > curalign
    2336           50 :                    || (lastalign == curalign
    2337           15 :                        && (DECL_USER_ALIGN (last_decl)
    2338           15 :                            > DECL_USER_ALIGN (decl))));
    2339              :       if (note)
    2340              :         curalign = lastalign;
    2341              : 
    2342           50 :       curalign /= BITS_PER_UNIT;
    2343           50 :       unsigned newalign = bitalign / BITS_PER_UNIT;
    2344              : 
    2345           50 :       auto_diagnostic_group d;
    2346           50 :       if ((DECL_USER_ALIGN (decl)
    2347           50 :            || DECL_USER_ALIGN (last_decl)))
    2348              :         {
    2349           65 :           if (warning (OPT_Wattributes,
    2350              :                        "ignoring attribute %<%E (%u)%> because it conflicts "
    2351              :                        "with attribute %<%E (%u)%>",
    2352              :                        name, newalign, name, curalign)
    2353           50 :               && note)
    2354           35 :             inform (DECL_SOURCE_LOCATION (last_decl),
    2355              :                     "previous declaration here");
    2356              :           /* Only reject attempts to relax/override an alignment
    2357              :              explicitly specified previously and accept declarations
    2358              :              that appear to relax the implicit function alignment for
    2359              :              the target.  Both increasing and increasing the alignment
    2360              :              set by -falign-functions setting is permitted.  */
    2361           50 :           *no_add_attrs = true;
    2362              :         }
    2363            0 :       else if (!warn_if_not_aligned_p)
    2364              :         {
    2365              :           /* Do not fail for attribute warn_if_not_aligned.  Otherwise,
    2366              :              silently avoid applying the alignment to the declaration
    2367              :              because it's implicitly satisfied by the target.  Apply
    2368              :              the attribute nevertheless so it can be retrieved by
    2369              :              __builtin_has_attribute.  */
    2370           50 :           set_align = false;
    2371              :         }
    2372           50 :     }
    2373       382714 :   else if (DECL_USER_ALIGN (decl)
    2374       382714 :            && DECL_ALIGN (decl) > bitalign)
    2375              :     /* C++-11 [dcl.align/4]:
    2376              : 
    2377              :            When multiple alignment-specifiers are specified for an
    2378              :            entity, the alignment requirement shall be set to the
    2379              :            strictest specified alignment.
    2380              : 
    2381              :       This formally comes from the c++11 specification but we are
    2382              :       doing it for the GNU attribute syntax as well.  */
    2383            3 :     *no_add_attrs = true;
    2384       382711 :   else if (warn_if_not_aligned_p
    2385           52 :            && TREE_CODE (decl) == FIELD_DECL
    2386       382755 :            && !DECL_C_BIT_FIELD (decl))
    2387              :     {
    2388           40 :       SET_DECL_WARN_IF_NOT_ALIGN (decl, bitalign);
    2389           40 :       warn_if_not_aligned_p = false;
    2390           40 :       set_align = false;
    2391              :     }
    2392              : 
    2393       658834 :   if (warn_if_not_aligned_p)
    2394              :     {
    2395           12 :       error ("%<warn_if_not_aligned%> may not be specified for %q+D",
    2396              :              decl);
    2397           12 :       *no_add_attrs = true;
    2398              :     }
    2399       658822 :   else if (!is_type && !*no_add_attrs && set_align)
    2400              :     {
    2401       382659 :       SET_DECL_ALIGN (decl, bitalign);
    2402       382659 :       DECL_USER_ALIGN (decl) = 1;
    2403              :     }
    2404              : 
    2405              :   return NULL_TREE;
    2406              : }
    2407              : 
    2408              : /* Handle a "aligned" attribute; arguments as in
    2409              :    struct attribute_spec.handler.  */
    2410              : 
    2411              : tree
    2412       658868 : handle_aligned_attribute (tree *node, tree name, tree args,
    2413              :                           int flags, bool *no_add_attrs)
    2414              : {
    2415       658868 :   return common_handle_aligned_attribute (node, name, args, flags,
    2416       658868 :                                          no_add_attrs, false);
    2417              : }
    2418              : 
    2419              : /* Handle a "warn_if_not_aligned" attribute; arguments as in
    2420              :    struct attribute_spec.handler.  */
    2421              : 
    2422              : static tree
    2423          124 : handle_warn_if_not_aligned_attribute (tree *node, tree name,
    2424              :                                       tree args, int flags,
    2425              :                                       bool *no_add_attrs)
    2426              : {
    2427          124 :   return common_handle_aligned_attribute (node, name, args, flags,
    2428          124 :                                           no_add_attrs, true);
    2429              : }
    2430              : 
    2431              : /* Handle a "strict_flex_array" attribute; arguments as in
    2432              :    struct attribute_spec.handler.  */
    2433              : 
    2434              : static tree
    2435           22 : handle_strict_flex_array_attribute (tree *node, tree name,
    2436              :                                     tree args, int ARG_UNUSED (flags),
    2437              :                                     bool *no_add_attrs)
    2438              : {
    2439           22 :   tree decl = *node;
    2440           22 :   tree argval = TREE_VALUE (args);
    2441              : 
    2442              :   /* This attribute only applies to field decls of a structure.  */
    2443           22 :   if (TREE_CODE (decl) != FIELD_DECL)
    2444              :     {
    2445            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    2446              :                 "%qE attribute may not be specified for %q+D", name, decl);
    2447            4 :       *no_add_attrs = true;
    2448              :     }
    2449              :   /* This attribute only applies to field with array type.  */
    2450           18 :   else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
    2451              :     {
    2452            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    2453              :                 "%qE attribute may not be specified for a non-array field",
    2454              :                 name);
    2455            4 :       *no_add_attrs = true;
    2456              :     }
    2457           14 :   else if (TREE_CODE (argval) != INTEGER_CST)
    2458              :     {
    2459            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    2460              :                 "%qE attribute argument not an integer", name);
    2461            4 :       *no_add_attrs = true;
    2462              :     }
    2463           10 :   else if (!tree_fits_uhwi_p (argval) || tree_to_uhwi (argval) > 3)
    2464              :     {
    2465            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    2466              :                 "%qE attribute argument %qE is not an integer constant"
    2467              :                 " between 0 and 3", name, argval);
    2468            4 :       *no_add_attrs = true;
    2469              :     }
    2470              : 
    2471           22 :   return NULL_TREE;
    2472              : }
    2473              : 
    2474              : /* Handle a "counted_by" attribute; arguments as in
    2475              :    struct attribute_spec.handler.  */
    2476              : 
    2477              : static tree
    2478          429 : handle_counted_by_attribute (tree *node, tree name,
    2479              :                              tree args, int ARG_UNUSED (flags),
    2480              :                              bool *no_add_attrs)
    2481              : {
    2482          429 :   tree decl = *node;
    2483          429 :   tree argval = TREE_VALUE (args);
    2484          429 :   tree old_counted_by = lookup_attribute ("counted_by", DECL_ATTRIBUTES (decl));
    2485              : 
    2486              :   /* This attribute is not supported in C++.  */
    2487          429 :   if (c_dialect_cxx ())
    2488              :     {
    2489           12 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    2490              :                   "%qE attribute is not supported for C++ for now, ignored",
    2491              :                   name);
    2492           12 :       *no_add_attrs = true;
    2493              :     }
    2494              :   /* This attribute only applies to field decls of a structure.  */
    2495          417 :   else if (TREE_CODE (decl) != FIELD_DECL)
    2496              :     {
    2497            2 :       error_at (DECL_SOURCE_LOCATION (decl),
    2498              :                 "%qE attribute is not allowed for a non-field"
    2499              :                 " declaration %q+D", name, decl);
    2500            2 :       *no_add_attrs = true;
    2501              :     }
    2502              :   /* This attribute only applies to a field with array type or pointer type.  */
    2503          415 :   else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
    2504          415 :            && TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE)
    2505              :     {
    2506            2 :       error_at (DECL_SOURCE_LOCATION (decl),
    2507              :                 "%qE attribute is not allowed for a non-array"
    2508              :                 " or non-pointer field", name);
    2509            2 :       *no_add_attrs = true;
    2510              :     }
    2511              :   /* This attribute only applies to a C99 flexible array member type.  */
    2512          413 :   else if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
    2513          413 :            && !flexible_array_member_type_p (TREE_TYPE (decl)))
    2514              :     {
    2515            1 :       error_at (DECL_SOURCE_LOCATION (decl),
    2516              :                 "%qE attribute is not allowed for a non-flexible"
    2517              :                 " array member field", name);
    2518            1 :       *no_add_attrs = true;
    2519              :     }
    2520              :   /* This attribute can be applied to a pointer to void type, but issue
    2521              :      warning when -Wpointer-arith is presenting.  */
    2522          412 :   else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
    2523          412 :            && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == VOID_TYPE)
    2524              :     {
    2525           11 :       if (warn_pointer_arith)
    2526            1 :         warning_at (DECL_SOURCE_LOCATION (decl),
    2527            1 :                     OPT_Wpointer_arith,
    2528              :                     "%qE attribute is used for a pointer to void",
    2529              :                     name);
    2530              :     }
    2531              :   /* This attribute cannot be applied to a pointer to function type.  */
    2532          401 :   else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
    2533          401 :            && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == FUNCTION_TYPE)
    2534              :     {
    2535            1 :       error_at (DECL_SOURCE_LOCATION (decl),
    2536              :                 "%qE attribute is not allowed for a pointer to"
    2537              :                 " function", name);
    2538            1 :       *no_add_attrs = true;
    2539              :     }
    2540              :   /* This attribute cannot be applied to a pointer to structure or union
    2541              :      with flexible array member.  */
    2542          400 :   else if (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
    2543          260 :            && RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))
    2544          452 :            && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (TREE_TYPE (decl))))
    2545              :     {
    2546            1 :         error_at (DECL_SOURCE_LOCATION (decl),
    2547              :                   "%qE attribute is not allowed for a pointer to"
    2548              :                   " structure or union with flexible array member", name);
    2549            1 :         *no_add_attrs = true;
    2550              :     }
    2551              :   /* The argument should be an identifier.  */
    2552          399 :   else if (TREE_CODE (argval) != IDENTIFIER_NODE)
    2553              :     {
    2554            2 :       error_at (DECL_SOURCE_LOCATION (decl),
    2555              :                 "%<counted_by%> argument is not an identifier");
    2556            2 :       *no_add_attrs = true;
    2557              :     }
    2558              :   /* Issue error when there is a counted_by attribute with a different
    2559              :      field as the argument for the same flexible array member or
    2560              :      pointer field.  */
    2561          397 :   else if (old_counted_by != NULL_TREE)
    2562              :     {
    2563            5 :       tree old_fieldname = TREE_VALUE (TREE_VALUE (old_counted_by));
    2564            5 :       if (strcmp (IDENTIFIER_POINTER (old_fieldname),
    2565            5 :                   IDENTIFIER_POINTER (argval)) != 0)
    2566              :         {
    2567            3 :           error_at (DECL_SOURCE_LOCATION (decl),
    2568              :                     "%<counted_by%> argument %qE conflicts with"
    2569              :                     " previous declaration %qE", argval, old_fieldname);
    2570            3 :           *no_add_attrs = true;
    2571              :         }
    2572              :     }
    2573              : 
    2574          429 :   return NULL_TREE;
    2575              : }
    2576              : 
    2577              : /* Handle a "noinit" or "persistent" attribute; arguments as in
    2578              :    struct attribute_spec.handler.
    2579              :    This generic handler is used for "special variable sections" that allow the
    2580              :    section name to be set using a dedicated attribute.  Additional validation
    2581              :    is performed for the specific properties of the section corresponding to the
    2582              :    attribute.
    2583              :    The ".noinit" section *is not* loaded by the program loader, and is not
    2584              :    initialized by the runtime startup code.
    2585              :    The ".persistent" section *is* loaded by the program loader, but is not
    2586              :    initialized by the runtime startup code.  */
    2587              : static tree
    2588            0 : handle_special_var_sec_attribute (tree *node, tree name, tree args,
    2589              :                                   int flags, bool *no_add_attrs)
    2590              : {
    2591            0 :   tree decl = *node;
    2592            0 :   tree res = NULL_TREE;
    2593              : 
    2594              :   /* First perform generic validation common to "noinit" and "persistent"
    2595              :      attributes.  */
    2596            0 :   if (!targetm_common.have_named_sections)
    2597              :     {
    2598            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    2599              :                 "section attributes are not supported for this target");
    2600            0 :       goto fail;
    2601              :     }
    2602              : 
    2603            0 :   if (!VAR_P (decl))
    2604              :     {
    2605            0 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    2606              :                   "ignoring %qE attribute not set on a variable",
    2607              :                   name);
    2608            0 :       goto fail;
    2609              :     }
    2610              : 
    2611            0 :   if (VAR_P (decl)
    2612            0 :       && current_function_decl != NULL_TREE
    2613            0 :       && !TREE_STATIC (decl))
    2614              :     {
    2615            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    2616              :                 "%qE attribute cannot be specified for local variables",
    2617              :                 name);
    2618            0 :       goto fail;
    2619              :     }
    2620              : 
    2621            0 :   if (VAR_P (decl)
    2622            0 :       && !targetm.have_tls && targetm.emutls.tmpl_section
    2623            0 :       && DECL_THREAD_LOCAL_P (decl))
    2624              :     {
    2625            0 :       error ("section of %q+D cannot be overridden", decl);
    2626            0 :       goto fail;
    2627              :     }
    2628              : 
    2629            0 :   if (!targetm.have_switchable_bss_sections)
    2630              :     {
    2631            0 :       error ("%qE attribute is specific to ELF targets", name);
    2632            0 :       goto fail;
    2633              :     }
    2634              : 
    2635            0 :   if (TREE_READONLY (decl))
    2636              :     {
    2637            0 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    2638              :                   "ignoring %qE attribute set on const variable",
    2639              :                   name);
    2640            0 :       goto fail;
    2641              :     }
    2642              : 
    2643              :   /* Now validate noinit/persistent individually.  */
    2644            0 :   if (strcmp (IDENTIFIER_POINTER (name), "noinit") == 0)
    2645              :     {
    2646            0 :       if (DECL_INITIAL (decl))
    2647              :         {
    2648            0 :           warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    2649              :                       "ignoring %qE attribute set on initialized variable",
    2650              :                       name);
    2651            0 :           goto fail;
    2652              :         }
    2653              :       /* If this var is thought to be common, then change this.  "noinit"
    2654              :          variables must be placed in an explicit ".noinit" section.  */
    2655            0 :       DECL_COMMON (decl) = 0;
    2656              :     }
    2657            0 :   else if (strcmp (IDENTIFIER_POINTER (name), "persistent") == 0)
    2658              :     {
    2659            0 :       if (DECL_COMMON (decl) || DECL_INITIAL (decl) == NULL_TREE)
    2660              :         {
    2661            0 :           warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    2662              :                       "ignoring %qE attribute set on uninitialized variable",
    2663              :                       name);
    2664            0 :           goto fail;
    2665              :         }
    2666              :     }
    2667              :   else
    2668            0 :     gcc_unreachable ();
    2669              : 
    2670            0 :   res = targetm.handle_generic_attribute (node, name, args, flags,
    2671              :                                           no_add_attrs);
    2672              : 
    2673              :   /* If the back end confirms the attribute can be added then continue onto
    2674              :      final processing.  */
    2675            0 :   if (!(*no_add_attrs))
    2676              :     return res;
    2677              : 
    2678            0 : fail:
    2679            0 :   *no_add_attrs = true;
    2680            0 :   return res;
    2681              : }
    2682              : 
    2683              : /* Handle a "noplt" attribute; arguments as in
    2684              :    struct attribute_spec.handler.  */
    2685              : 
    2686              : static tree
    2687            7 : handle_noplt_attribute (tree *node, tree name,
    2688              :                        tree ARG_UNUSED (args),
    2689              :                        int ARG_UNUSED (flags),
    2690              :                        bool * ARG_UNUSED (no_add_attrs))
    2691              : {
    2692            7 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    2693              :     {
    2694            0 :       warning (OPT_Wattributes,
    2695              :                "%qE attribute is only applicable on functions", name);
    2696            0 :       *no_add_attrs = true;
    2697            0 :       return NULL_TREE;
    2698              :     }
    2699              :   return NULL_TREE;
    2700              : }
    2701              : 
    2702              : /* Handle a "symver" attribute.  */
    2703              : 
    2704              : static tree
    2705            2 : handle_symver_attribute (tree *node, tree ARG_UNUSED (name), tree args,
    2706              :                          int ARG_UNUSED (flags), bool *no_add_attrs)
    2707              : {
    2708            2 :   tree symver;
    2709            2 :   const char *symver_str;
    2710              : 
    2711            2 :   if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL)
    2712              :     {
    2713            0 :       warning (OPT_Wattributes,
    2714              :                "%<symver%> attribute only applies to functions and variables");
    2715            0 :       *no_add_attrs = true;
    2716            0 :       return NULL_TREE;
    2717              :     }
    2718              : 
    2719            2 :   if (!decl_in_symtab_p (*node))
    2720              :     {
    2721            0 :       warning (OPT_Wattributes,
    2722              :                "%<symver%> attribute is only applicable to symbols");
    2723            0 :       *no_add_attrs = true;
    2724            0 :       return NULL_TREE;
    2725              :     }
    2726              : 
    2727            4 :   for (; args; args = TREE_CHAIN (args))
    2728              :     {
    2729            2 :       symver = TREE_VALUE (args);
    2730            2 :       if (TREE_CODE (symver) != STRING_CST)
    2731              :         {
    2732            0 :           error ("%<symver%> attribute argument not a string constant");
    2733            0 :           *no_add_attrs = true;
    2734            0 :           return NULL_TREE;
    2735              :         }
    2736              : 
    2737            2 :       symver_str = TREE_STRING_POINTER (symver);
    2738              : 
    2739            2 :       int ats = 0;
    2740           22 :       for (int n = 0; (int)n < TREE_STRING_LENGTH (symver); n++)
    2741           20 :         if (symver_str[n] == '@')
    2742            2 :           ats++;
    2743              : 
    2744            2 :       if (ats != 1 && ats != 2)
    2745              :         {
    2746            0 :           error ("symver attribute argument must have format %<name@nodename%>");
    2747            0 :           error ("%<symver%> attribute argument %qs must contain one or two "
    2748              :                  "%<@%>", symver_str);
    2749            0 :           *no_add_attrs = true;
    2750            0 :           return NULL_TREE;
    2751              :         }
    2752              :     }
    2753              : 
    2754              :   return NULL_TREE;
    2755              : }
    2756              : 
    2757              : /* Handle an "alias" or "ifunc" attribute; arguments as in
    2758              :    struct attribute_spec.handler.  */
    2759              : 
    2760              : static tree
    2761          124 : handle_ifunc_attribute (tree *node, tree name, tree args,
    2762              :                         int ARG_UNUSED (flags), bool *no_add_attrs)
    2763              : {
    2764          124 :   return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs);
    2765              : }
    2766              : 
    2767              : /* Handle the "copy" attribute NAME by copying the set of attributes
    2768              :    from the symbol referenced by ARGS to the declaration of *NODE.  */
    2769              : 
    2770              : static tree
    2771         1123 : handle_copy_attribute (tree *node, tree name, tree args,
    2772              :                        int flags, bool *no_add_attrs)
    2773              : {
    2774              :   /* Do not apply the copy attribute itself.  It serves no purpose
    2775              :      other than to copy other attributes.  */
    2776         1123 :   *no_add_attrs = true;
    2777              : 
    2778         1123 :   tree decl = *node;
    2779              : 
    2780         1123 :   tree ref = TREE_VALUE (args);
    2781         1123 :   if (ref == error_mark_node)
    2782              :     return NULL_TREE;
    2783              : 
    2784         1122 :   location_t loc = input_location;
    2785         1122 :   if (DECL_P (decl))
    2786         1119 :     loc = DECL_SOURCE_LOCATION (decl);
    2787         1122 :   if (TREE_CODE (ref) == STRING_CST)
    2788              :     {
    2789              :       /* Explicitly handle this case since using a string literal
    2790              :          as an argument is a likely mistake.  */
    2791            2 :       error_at (loc, "%qE attribute argument cannot be a string", name);
    2792            2 :       return NULL_TREE;
    2793              :     }
    2794              : 
    2795         1120 :   if (CONSTANT_CLASS_P (ref)
    2796         1120 :       && (INTEGRAL_TYPE_P (TREE_TYPE (ref))
    2797           15 :           || FLOAT_TYPE_P (TREE_TYPE (ref))))
    2798              :     {
    2799              :       /* Similar to the string case, since some function attributes
    2800              :          accept literal numbers as arguments (e.g., alloc_size or
    2801              :          nonnull) using one here is a likely mistake.  */
    2802            1 :       error_at (loc, "%qE attribute argument cannot be a constant arithmetic "
    2803              :                 "expression", name);
    2804            1 :       return NULL_TREE;
    2805              :     }
    2806              : 
    2807         1119 :   if (ref == node[1])
    2808              :     {
    2809              :       /* Another possible mistake (but indirect self-references aren't
    2810              :          and diagnosed and shouldn't be).  */
    2811            9 :       if (warning_at (loc, OPT_Wattributes,
    2812              :                       "%qE attribute ignored on a redeclaration "
    2813              :                       "of the referenced symbol", name)
    2814            9 :           && DECL_P (node[1]))
    2815            9 :         inform (DECL_SOURCE_LOCATION (node[1]), "previous declaration here");
    2816              :       return NULL_TREE;
    2817              :     }
    2818              : 
    2819              :   /* Consider address-of expressions in the attribute argument
    2820              :      as requests to copy from the referenced entity.  */
    2821         1110 :   if (TREE_CODE (ref) == ADDR_EXPR)
    2822           18 :     ref = TREE_OPERAND (ref, 0);
    2823              : 
    2824         1153 :   do
    2825              :     {
    2826              :       /* Drill down into references to find the referenced decl.  */
    2827         1153 :       tree_code refcode = TREE_CODE (ref);
    2828         1153 :       if (refcode == ARRAY_REF
    2829         1153 :           || refcode == INDIRECT_REF)
    2830           51 :         ref = TREE_OPERAND (ref, 0);
    2831         1102 :       else if (refcode == COMPONENT_REF)
    2832           70 :         ref = TREE_OPERAND (ref, 1);
    2833              :       else
    2834              :         break;
    2835              :     }
    2836          121 :   while (!DECL_P (ref));
    2837              : 
    2838              :   /* For object pointer expressions, consider those to be requests
    2839              :      to copy from their type, such as in:
    2840              :        struct __attribute__ (copy ((struct T *)0)) U { ... };
    2841              :      which copies type attributes from struct T to the declaration
    2842              :      of struct U.  */
    2843         1087 :   if ((CONSTANT_CLASS_P (ref) || EXPR_P (ref))
    2844           72 :       && POINTER_TYPE_P (TREE_TYPE (ref))
    2845         1165 :       && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (ref)))
    2846           44 :     ref = TREE_TYPE (ref);
    2847              : 
    2848         1110 :   tree reftype = TYPE_P (ref) ? ref : TREE_TYPE (ref);
    2849              : 
    2850         1110 :   if (DECL_P (decl))
    2851              :     {
    2852         1108 :       if ((VAR_P (decl)
    2853           21 :            && (TREE_CODE (ref) == FUNCTION_DECL
    2854           20 :                || (EXPR_P (ref)
    2855            1 :                    && POINTER_TYPE_P (reftype)
    2856            1 :                    && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (reftype)))))
    2857         1127 :           || (TREE_CODE (decl) == FUNCTION_DECL
    2858          950 :               && (VAR_P (ref)
    2859          949 :                   || (EXPR_P (ref)
    2860           17 :                       && !FUNC_OR_METHOD_TYPE_P (reftype)
    2861           11 :                       && (!POINTER_TYPE_P (reftype)
    2862           10 :                           || !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (reftype)))))))
    2863              :         {
    2864              :           /* It makes no sense to try to copy function attributes
    2865              :              to a variable, or variable attributes to a function.  */
    2866            6 :           if (warning (OPT_Wattributes,
    2867              :                        "%qE attribute ignored on a declaration of "
    2868              :                        "a different kind than referenced symbol", name)
    2869            4 :               && DECL_P (ref))
    2870            2 :             inform (DECL_SOURCE_LOCATION (ref),
    2871              :                     "symbol %qD referenced by %qD declared here", ref, decl);
    2872              :           return NULL_TREE;
    2873              :         }
    2874              : 
    2875         1104 :       tree attrs = NULL_TREE;
    2876         1104 :       if (DECL_P (ref))
    2877         1036 :         attrs = DECL_ATTRIBUTES (ref);
    2878           68 :       else if (TYPE_P (ref))
    2879           42 :         attrs = TYPE_ATTRIBUTES (ref);
    2880              : 
    2881              :       /* Copy decl attributes from REF to DECL.  */
    2882         1894 :       for (tree at = attrs; at; at = TREE_CHAIN (at))
    2883              :         {
    2884              :           /* Avoid copying attributes that affect a symbol linkage,
    2885              :              inlining, or visibility since those in all likelihood
    2886              :              only apply to the target.
    2887              :              FIXME: make it possible to specify which attributes to
    2888              :              copy or not to copy in the copy attribute itself.  */
    2889          790 :           tree atname = get_attribute_name (at);
    2890          790 :           if (is_attribute_p ("alias", atname)
    2891          789 :               || is_attribute_p ("always_inline", atname)
    2892          787 :               || is_attribute_p ("gnu_inline", atname)
    2893          778 :               || is_attribute_p ("ifunc", atname)
    2894          778 :               || is_attribute_p ("noinline", atname)
    2895          766 :               || is_attribute_p ("visibility", atname)
    2896          529 :               || is_attribute_p ("weak", atname)
    2897          529 :               || is_attribute_p ("weakref", atname)
    2898         1319 :               || is_attribute_p ("target_clones", atname))
    2899          262 :             continue;
    2900              : 
    2901              :           /* Attribute leaf only applies to extern functions.
    2902              :              Avoid copying it to static ones.  */
    2903          549 :           if (!TREE_PUBLIC (decl)
    2904          528 :               && is_attribute_p ("leaf", atname))
    2905           21 :             continue;
    2906              : 
    2907          507 :           tree atargs = TREE_VALUE (at);
    2908              :           /* Create a copy of just the one attribute ar AT, including
    2909              :              its argumentsm and add it to DECL.  */
    2910          507 :           tree attr = tree_cons (atname, copy_list (atargs), NULL_TREE);
    2911          507 :           decl_attributes (node, attr, flags,  EXPR_P (ref) ? NULL_TREE : ref);
    2912              :         }
    2913              : 
    2914              :       /* Proceed to copy type attributes below.  */
    2915              :     }
    2916            2 :   else if (!TYPE_P (decl))
    2917              :     {
    2918            0 :       error_at (loc, "%qE attribute must apply to a declaration", name);
    2919            0 :       return NULL_TREE;
    2920              :     }
    2921              : 
    2922              :   /* A function declared with attribute nothrow has the attribute
    2923              :      attached to it, but a C++ throw() function does not.  */
    2924         1106 :   if (TREE_NOTHROW (ref))
    2925          579 :     TREE_NOTHROW (decl) = true;
    2926              : 
    2927              :   /* Similarly, a function declared with attribute noreturn has it
    2928              :      attached on to it, but a C11 _Noreturn function does not.  */
    2929         1106 :   if (DECL_P (ref)
    2930         1036 :       && TREE_THIS_VOLATILE (ref)
    2931           33 :       && FUNC_OR_METHOD_TYPE_P (reftype))
    2932           32 :     TREE_THIS_VOLATILE (decl) = true;
    2933              : 
    2934         1106 :   if (POINTER_TYPE_P (reftype))
    2935           96 :     reftype = TREE_TYPE (reftype);
    2936              : 
    2937         1106 :   if (!TYPE_P (reftype))
    2938              :     return NULL_TREE;
    2939              : 
    2940         1106 :   tree attrs = TYPE_ATTRIBUTES (reftype);
    2941              : 
    2942              :   /* Copy type attributes from REF to DECL.  Pass in REF if it's a DECL
    2943              :      or a type but not if it's an expression.  Set ATTR_FLAG_INTERNAL
    2944              :      since the attributes' arguments may be in their internal form.  */
    2945         1445 :   for (tree at = attrs; at; at = TREE_CHAIN (at))
    2946          339 :     decl_attributes (node, at, flags | ATTR_FLAG_INTERNAL,
    2947          339 :                      EXPR_P (ref) ? NULL_TREE : ref);
    2948              : 
    2949              :   return NULL_TREE;
    2950              : }
    2951              : 
    2952              : /* Handle a "weakref" attribute; arguments as in struct
    2953              :    attribute_spec.handler.  */
    2954              : 
    2955              : static tree
    2956          917 : handle_weakref_attribute (tree *node, tree name, tree args,
    2957              :                           int flags, bool *no_add_attrs)
    2958              : {
    2959          917 :   tree attr = NULL_TREE;
    2960              : 
    2961              :   /* We must ignore the attribute when it is associated with
    2962              :      local-scoped decls, since attribute alias is ignored and many
    2963              :      such symbols do not even have a DECL_WEAK field.  */
    2964          917 :   if (decl_function_context (*node)
    2965          917 :       || current_function_decl
    2966         1834 :       || !VAR_OR_FUNCTION_DECL_P (*node))
    2967              :     {
    2968            2 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    2969            2 :       *no_add_attrs = true;
    2970            2 :       return NULL_TREE;
    2971              :     }
    2972              : 
    2973          915 :   if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node)))
    2974              :     {
    2975            0 :       error ("indirect function %q+D cannot be declared %qE",
    2976              :              *node, name);
    2977            0 :       *no_add_attrs = true;
    2978            0 :       return NULL_TREE;
    2979              :     }
    2980              : 
    2981              :   /* The idea here is that `weakref("name")' mutates into `weakref,
    2982              :      alias("name")', and weakref without arguments, in turn,
    2983              :      implicitly adds weak.  */
    2984              : 
    2985          915 :   if (args)
    2986              :     {
    2987          455 :       attr = tree_cons (get_identifier ("alias"), args, attr);
    2988          455 :       attr = tree_cons (get_identifier ("weakref"), NULL_TREE, attr);
    2989              : 
    2990          455 :       *no_add_attrs = true;
    2991              : 
    2992          455 :       decl_attributes (node, attr, flags);
    2993              :     }
    2994              :   else
    2995              :     {
    2996          460 :       if (lookup_attribute ("alias", DECL_ATTRIBUTES (*node)))
    2997            0 :         error_at (DECL_SOURCE_LOCATION (*node),
    2998              :                   "%qE attribute must appear before %qs attribute",
    2999              :                   name, "alias");
    3000              : 
    3001              :       /* Can't call declare_weak because it wants this to be TREE_PUBLIC,
    3002              :          and that isn't supported; and because it wants to add it to
    3003              :          the list of weak decls, which isn't helpful.  */
    3004          460 :       DECL_WEAK (*node) = 1;
    3005              :     }
    3006              : 
    3007          915 :   if (decl_in_symtab_p (*node))
    3008              :     {
    3009          915 :       struct symtab_node *n = symtab_node::get (*node);
    3010          915 :       if (n && n->refuse_visibility_changes)
    3011            0 :         error ("%+qD declared %qE after being used", *node, name);
    3012              :     }
    3013              : 
    3014              :   return NULL_TREE;
    3015              : }
    3016              : 
    3017              : /* If ID, the STRING_CST argument of a "tls_model" attribute, names a TLS
    3018              :    access model, store that model in *KIND and return true.  Otherwise
    3019              :    return false.  */
    3020              : 
    3021              : bool
    3022          382 : parse_tls_model (const_tree id, enum tls_model *kind)
    3023              : {
    3024          382 :   if (!strcmp (TREE_STRING_POINTER (id), "local-exec"))
    3025           31 :     *kind = TLS_MODEL_LOCAL_EXEC;
    3026          351 :   else if (!strcmp (TREE_STRING_POINTER (id), "initial-exec"))
    3027          131 :     *kind = TLS_MODEL_INITIAL_EXEC;
    3028          220 :   else if (!strcmp (TREE_STRING_POINTER (id), "local-dynamic"))
    3029           64 :     *kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
    3030          166 :   else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
    3031          165 :     *kind = TLS_MODEL_GLOBAL_DYNAMIC;
    3032              :   else
    3033              :     return false;
    3034              : 
    3035              :   return true;
    3036              : }
    3037              : 
    3038              : /* DECL has just become weak.  If it is a thread-local variable, the TLS
    3039              :    access model chosen for it may assume that it binds locally, which a
    3040              :    weak symbol need not, so recompute the model.  An explicit tls_model
    3041              :    attribute remains a lower bound.  */
    3042              : 
    3043              : void
    3044          143 : weak_decl_tls_model (tree decl)
    3045              : {
    3046          143 :   if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
    3047           90 :     return;
    3048              : 
    3049           53 :   tls_model model = decl_default_tls_model (decl);
    3050           53 :   tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
    3051           53 :   tls_model attr_model;
    3052           53 :   if (attr
    3053           16 :       && parse_tls_model (TREE_VALUE (TREE_VALUE (attr)), &attr_model)
    3054           69 :       && attr_model > model)
    3055              :     model = attr_model;
    3056           53 :   if (model < DECL_TLS_MODEL (decl))
    3057           52 :     set_decl_tls_model (decl, model);
    3058              : }
    3059              : 
    3060              : /* Handle an "tls_model" attribute; arguments as in
    3061              :    struct attribute_spec.handler.  */
    3062              : 
    3063              : static tree
    3064          379 : handle_tls_model_attribute (tree *node, tree name, tree args,
    3065              :                             int ARG_UNUSED (flags), bool *no_add_attrs)
    3066              : {
    3067          379 :   tree id;
    3068          379 :   tree decl = *node;
    3069          379 :   enum tls_model kind;
    3070              : 
    3071          379 :   if (!VAR_P (decl))
    3072              :     {
    3073            2 :       warning (OPT_Wattributes, "%qE attribute ignored because %qD "
    3074              :                "is not a variable",
    3075              :                name, decl);
    3076            2 :       return NULL_TREE;
    3077              :     }
    3078              : 
    3079          377 :   if (!DECL_THREAD_LOCAL_P (decl))
    3080              :     {
    3081            2 :       warning (OPT_Wattributes, "%qE attribute ignored because %qD does "
    3082              :                "not have thread storage duration", name, decl);
    3083            2 :       return NULL_TREE;
    3084              :     }
    3085              : 
    3086          375 :   kind = DECL_TLS_MODEL (decl);
    3087          375 :   id = TREE_VALUE (args);
    3088          375 :   if (TREE_CODE (id) != STRING_CST)
    3089              :     {
    3090            9 :       error ("%qE argument not a string", name);
    3091            9 :       *no_add_attrs = true;
    3092            9 :       return NULL_TREE;
    3093              :     }
    3094              : 
    3095          366 :   if (!parse_tls_model (id, &kind))
    3096            1 :     error ("%qE argument must be one of %qs, %qs, %qs, or %qs",
    3097              :            name,
    3098              :            "local-exec", "initial-exec", "local-dynamic", "global-dynamic");
    3099              : 
    3100          366 :   set_decl_tls_model (decl, kind);
    3101          366 :   return NULL_TREE;
    3102              : }
    3103              : 
    3104              : /* Handle a "no_instrument_function" attribute; arguments as in
    3105              :    struct attribute_spec.handler.  */
    3106              : 
    3107              : static tree
    3108           76 : handle_no_instrument_function_attribute (tree *node, tree name,
    3109              :                                          tree ARG_UNUSED (args),
    3110              :                                          int ARG_UNUSED (flags),
    3111              :                                          bool *no_add_attrs)
    3112              : {
    3113           76 :   tree decl = *node;
    3114              : 
    3115           76 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    3116              :     {
    3117            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    3118              :                 "%qE attribute applies only to functions", name);
    3119            0 :       *no_add_attrs = true;
    3120              :     }
    3121              :   else
    3122           76 :     DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
    3123              : 
    3124           76 :   return NULL_TREE;
    3125              : }
    3126              : 
    3127              : /* Handle a "no_profile_instrument_function" attribute; arguments as in
    3128              :    struct attribute_spec.handler.  */
    3129              : 
    3130              : static tree
    3131            3 : handle_no_profile_instrument_function_attribute (tree *node, tree name, tree,
    3132              :                                                  int, bool *no_add_attrs)
    3133              : {
    3134            3 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    3135              :     {
    3136            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    3137            0 :       *no_add_attrs = true;
    3138              :     }
    3139              : 
    3140            3 :   return NULL_TREE;
    3141              : }
    3142              : 
    3143              : /* If ALLOC_DECL and DEALLOC_DECL are a pair of user-defined functions,
    3144              :    if they are declared inline issue warnings and return null.  Otherwise
    3145              :    create attribute noinline, install it in ALLOC_DECL, and return it.
    3146              :    Otherwise return null. */
    3147              : 
    3148              : static tree
    3149       359030 : maybe_add_noinline (tree name, tree alloc_decl, tree dealloc_decl,
    3150              :                     bool *no_add_attrs)
    3151              : {
    3152       359030 :   if (fndecl_built_in_p (alloc_decl) || fndecl_built_in_p (dealloc_decl))
    3153              :     return NULL_TREE;
    3154              : 
    3155              :   /* When inlining (or optimization) is enabled and the allocator and
    3156              :      deallocator are not built-in functions, ignore the attribute on
    3157              :      functions declared inline since it could lead to false positives
    3158              :      when inlining one or the other call would wind up calling
    3159              :      a mismatched allocator or  deallocator.  */
    3160       226996 :   if ((optimize && DECL_DECLARED_INLINE_P (alloc_decl))
    3161       494104 :       || lookup_attribute ("always_inline", DECL_ATTRIBUTES (alloc_decl)))
    3162              :     {
    3163            4 :       warning (OPT_Wattributes,
    3164              :                "%<%E (%E)%> attribute ignored on functions "
    3165            4 :                "declared %qs", name, DECL_NAME (dealloc_decl), "inline");
    3166            4 :       *no_add_attrs = true;
    3167            4 :       return NULL_TREE;
    3168              :     }
    3169              : 
    3170       226992 :   if ((optimize && DECL_DECLARED_INLINE_P (dealloc_decl))
    3171       494092 :       || lookup_attribute ("always_inline", DECL_ATTRIBUTES (dealloc_decl)))
    3172              :     {
    3173           12 :       warning (OPT_Wattributes,
    3174              :                "%<%E (%E)%> attribute ignored with deallocation "
    3175              :                "functions declared %qs",
    3176           12 :                name, DECL_NAME (dealloc_decl), "inline");
    3177           12 :       inform (DECL_SOURCE_LOCATION (dealloc_decl),
    3178              :               "deallocation function declared here" );
    3179           12 :       *no_add_attrs = true;
    3180           12 :       return NULL_TREE;
    3181              :     }
    3182              : 
    3183              :   /* Disable inlining for non-standard deallocators to avoid false
    3184              :      positives due to mismatches between the inlined implementation
    3185              :      of one and not the other pair of functions.  */
    3186       267096 :   tree attr = tree_cons (get_identifier ("noinline"), NULL_TREE, NULL_TREE);
    3187       267096 :   decl_attributes (&alloc_decl, attr, 0);
    3188       267096 :   return attr;
    3189              : }
    3190              : 
    3191              : /* Handle the "malloc" attribute.  */
    3192              : 
    3193              : static tree
    3194      3408747 : handle_malloc_attribute (tree *node, tree name, tree args, int flags,
    3195              :                          bool *no_add_attrs)
    3196              : {
    3197      3408747 :   if (flags & ATTR_FLAG_INTERNAL)
    3198              :     /* Recursive call.  */
    3199              :     return NULL_TREE;
    3200              : 
    3201              :   /* The argument-less form (declaring the function malloc-like) is shared
    3202              :      with libgccjit; the deallocator-argument form below is
    3203              :      specific to the C family.  */
    3204      3408747 :   if (!args)
    3205      3049672 :     return handle_malloc_common (node, name, args, flags, no_add_attrs);
    3206              : 
    3207       359075 :   tree fndecl = *node;
    3208              : 
    3209       359075 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    3210              :     {
    3211            4 :       warning (OPT_Wattributes, "%qE attribute ignored; valid only "
    3212              :                "for functions",
    3213              :                name);
    3214            4 :       *no_add_attrs = true;
    3215            4 :       return NULL_TREE;
    3216              :     }
    3217              : 
    3218       359071 :   tree rettype = TREE_TYPE (TREE_TYPE (*node));
    3219       359071 :   if (!POINTER_TYPE_P (rettype))
    3220              :     {
    3221            4 :       warning (OPT_Wattributes, "%qE attribute ignored on functions "
    3222              :                "returning %qT; valid only for pointer return types",
    3223              :                name, rettype);
    3224            4 :       *no_add_attrs = true;
    3225            4 :       return NULL_TREE;
    3226              :     }
    3227              : 
    3228       359067 :   if (!args)
    3229              :     {
    3230              :       /* Only the form of the attribute with no arguments declares
    3231              :          a function malloc-like.  */
    3232              :       DECL_IS_MALLOC (*node) = 1;
    3233              :       return NULL_TREE;
    3234              :     }
    3235              : 
    3236       359067 :   tree dealloc = TREE_VALUE (args);
    3237       359067 :   if (error_operand_p (dealloc))
    3238              :     {
    3239              :       /* If the argument is in error it will have already been diagnosed.
    3240              :          Avoid issuing redundant errors here.  */
    3241            1 :       *no_add_attrs = true;
    3242            1 :       return NULL_TREE;
    3243              :     }
    3244              : 
    3245       359066 :   STRIP_NOPS (dealloc);
    3246       359066 :   if (TREE_CODE (dealloc) == ADDR_EXPR)
    3247              :     {
    3248              :       /* In C++ the argument may be wrapped in a cast to disambiguate
    3249              :          one of a number of overloads (such as operator delete).  To
    3250              :          make things interesting, the cast looks different between
    3251              :          different C++ versions.  Strip it and install the attribute
    3252              :          with the disambiguated function.  */
    3253           16 :       dealloc = TREE_OPERAND (dealloc, 0);
    3254              : 
    3255           16 :       *no_add_attrs = true;
    3256           16 :       tree attr = tree_cons (NULL_TREE, dealloc, TREE_CHAIN (args));
    3257           16 :       attr = build_tree_list (name, attr);
    3258           16 :       return decl_attributes (node, attr, 0);
    3259              :     }
    3260              : 
    3261       359050 :   if (TREE_CODE (dealloc) != FUNCTION_DECL)
    3262              :     {
    3263            7 :       if (TREE_CODE (dealloc) == OVERLOAD)
    3264              :         {
    3265              :           /* Handle specially the common case of specifying one of a number
    3266              :              of overloads, such as operator delete.  */
    3267            4 :           error ("%qE attribute argument 1 is ambiguous", name);
    3268            4 :           inform (input_location,
    3269              :                   "use a cast to the expected type to disambiguate");
    3270            4 :           *no_add_attrs = true;
    3271            4 :           return NULL_TREE;
    3272              :         }
    3273              : 
    3274            3 :       error ("%qE attribute argument 1 does not name a function", name);
    3275            3 :       if (DECL_P (dealloc))
    3276            1 :         inform (DECL_SOURCE_LOCATION (dealloc),
    3277              :                 "argument references a symbol declared here");
    3278            3 :       *no_add_attrs = true;
    3279            3 :       return NULL_TREE;
    3280              :     }
    3281              : 
    3282              :   /* Mentioning the deallocation function qualifies as its use.  */
    3283       359043 :   TREE_USED (dealloc) = 1;
    3284              : 
    3285       359043 :   tree fntype = TREE_TYPE (dealloc);
    3286       359043 :   tree argpos = TREE_CHAIN (args) ? TREE_VALUE (TREE_CHAIN (args)) : NULL_TREE;
    3287       359043 :   if (!argpos)
    3288              :     {
    3289         5415 :       tree argtypes = TYPE_ARG_TYPES (fntype);
    3290         5415 :       if (!argtypes)
    3291              :         {
    3292              :           /* Reject functions without a prototype.  */
    3293            0 :           error ("%qE attribute argument 1 must take a pointer "
    3294              :                  "type as its first argument", name);
    3295            0 :           inform (DECL_SOURCE_LOCATION (dealloc),
    3296              :                   "referenced symbol declared here");
    3297            0 :           *no_add_attrs = true;
    3298            0 :           return NULL_TREE;
    3299              :         }
    3300              : 
    3301         5415 :       tree argtype = TREE_VALUE (argtypes);
    3302         5415 :       if (TREE_CODE (argtype) != POINTER_TYPE)
    3303              :         {
    3304              :           /* Reject functions that don't take a pointer as their first
    3305              :              argument.  */
    3306           13 :           error ("%qE attribute argument 1 must take a pointer type "
    3307              :                  "as its first argument; have %qT", name, argtype);
    3308           13 :           inform (DECL_SOURCE_LOCATION (dealloc),
    3309              :                   "referenced symbol declared here");
    3310           13 :           *no_add_attrs = true;
    3311           13 :           return NULL_TREE;
    3312              :         }
    3313              : 
    3314              :       /* Disable inlining for non-standard deallocators to avoid false
    3315              :          positives (or warn if either function is explicitly inline).  */
    3316         5402 :       tree at_noinline =
    3317         5402 :         maybe_add_noinline (name, fndecl, dealloc, no_add_attrs);
    3318         5402 :       if (*no_add_attrs)
    3319              :         return NULL_TREE;
    3320              : 
    3321              :       /* Add attribute *dealloc to the deallocator function associating
    3322              :          it with this one.  Ideally, the attribute would reference
    3323              :          the DECL of the deallocator but since that changes for each
    3324              :          redeclaration, use DECL_NAME instead.  (DECL_ASSEMBLER_NAME
    3325              :          need not be set at this point and setting it here is too early.  */
    3326         5394 :       tree attrs = build_tree_list (NULL_TREE, DECL_NAME (fndecl));
    3327         5394 :       attrs = tree_cons (get_identifier ("*dealloc"), attrs, at_noinline);
    3328         5394 :       decl_attributes (&dealloc, attrs, 0);
    3329         5394 :       return NULL_TREE;
    3330              :     }
    3331              : 
    3332              :   /* Validate the positional argument.  */
    3333       353628 :   argpos = positional_argument (fntype, name, argpos, POINTER_TYPE);
    3334       353628 :   if (!argpos)
    3335              :     {
    3336            0 :       *no_add_attrs = true;
    3337            0 :       return NULL_TREE;
    3338              :     }
    3339              : 
    3340              :   /* As above, disable inlining for non-standard deallocators to avoid
    3341              :      false positives (or warn).  */
    3342       353628 :   tree at_noinline =
    3343       353628 :     maybe_add_noinline (name, fndecl, dealloc, no_add_attrs);
    3344       353628 :   if (*no_add_attrs)
    3345              :     return NULL_TREE;
    3346              : 
    3347              :   /* It's valid to declare the same function with multiple instances
    3348              :      of attribute malloc, each naming the same or different deallocator
    3349              :      functions, and each referencing either the same or a different
    3350              :      positional argument.  */
    3351       353620 :   tree attrs = tree_cons (NULL_TREE, argpos, NULL_TREE);
    3352       353620 :   attrs = tree_cons (NULL_TREE, DECL_NAME (fndecl), attrs);
    3353       353620 :   attrs = tree_cons (get_identifier ("*dealloc"), attrs, at_noinline);
    3354       353620 :   decl_attributes (&dealloc, attrs, 0);
    3355       353620 :   return NULL_TREE;
    3356              : }
    3357              : 
    3358              : /* Handle the internal "*dealloc" attribute added for functions declared
    3359              :    with the one- and two-argument forms of attribute malloc.  Add it
    3360              :    to *NODE unless it's already there with the same arguments.  */
    3361              : 
    3362              : static tree
    3363       359038 : handle_dealloc_attribute (tree *node, tree name, tree args, int,
    3364              :                           bool *no_add_attrs)
    3365              : {
    3366       359038 :   tree fndecl = *node;
    3367              : 
    3368       359038 :   tree attrs = DECL_ATTRIBUTES (fndecl);
    3369       359038 :   if (!attrs)
    3370              :     return NULL_TREE;
    3371              : 
    3372       307089 :   tree arg = TREE_VALUE (args);
    3373       307089 :   args = TREE_CHAIN (args);
    3374       609153 :   tree arg_pos = args ? TREE_VALUE (args) : integer_zero_node;
    3375              : 
    3376       307089 :   gcc_checking_assert ((DECL_P (arg)
    3377              :                         && fndecl_built_in_p (arg, BUILT_IN_NORMAL))
    3378              :                        || TREE_CODE (arg) == IDENTIFIER_NODE);
    3379              : 
    3380       307089 :   const char* const namestr = IDENTIFIER_POINTER (name);
    3381      1139269 :   for (tree at = attrs; (at = lookup_attribute (namestr, at));
    3382       832180 :        at = TREE_CHAIN (at))
    3383              :     {
    3384       832533 :       tree alloc = TREE_VALUE (at);
    3385       832533 :       if (!alloc)
    3386            0 :         continue;
    3387              : 
    3388       832533 :       tree pos = TREE_CHAIN (alloc);
    3389       832533 :       alloc = TREE_VALUE (alloc);
    3390      1654384 :       pos = pos ? TREE_VALUE (pos) : integer_zero_node;
    3391       832533 :       gcc_checking_assert ((DECL_P (alloc)
    3392              :                             && fndecl_built_in_p (alloc, BUILT_IN_NORMAL))
    3393              :                            || TREE_CODE (alloc) == IDENTIFIER_NODE);
    3394              : 
    3395       832533 :       if (alloc == arg && tree_int_cst_equal (pos, arg_pos))
    3396              :         {
    3397              :           /* The function already has the attribute either without any
    3398              :              arguments or with the same arguments as the attribute that's
    3399              :              being added.  Return without adding another copy.  */
    3400          353 :           *no_add_attrs = true;
    3401          353 :           return NULL_TREE;
    3402              :         }
    3403              :     }
    3404              : 
    3405              :   return NULL_TREE;
    3406              : }
    3407              : 
    3408              : /* Handle the "alloc_size (argpos1 [, argpos2])" function type attribute.
    3409              :    *NODE is the type of the function the attribute is being applied to.  */
    3410              : 
    3411              : static tree
    3412      2430733 : handle_alloc_size_attribute (tree *node, tree name, tree args,
    3413              :                              int ARG_UNUSED (flags), bool *no_add_attrs)
    3414              : {
    3415      2430733 :   tree fntype = *node;
    3416      2430733 :   tree rettype = TREE_TYPE (fntype);
    3417      2430733 :   if (!POINTER_TYPE_P (rettype))
    3418              :     {
    3419           39 :       warning (OPT_Wattributes,
    3420              :                "%qE attribute ignored on a function returning %qT",
    3421              :                name, rettype);
    3422           39 :       *no_add_attrs = true;
    3423           39 :       return NULL_TREE;
    3424              :     }
    3425              : 
    3426      2430694 :   tree newargs[2] = { NULL_TREE, NULL_TREE };
    3427      5364612 :   for (int i = 1; args; ++i)
    3428              :     {
    3429      2933954 :       tree pos = TREE_VALUE (args);
    3430              :       /* NEXT is null when the attribute includes just one argument.
    3431              :          That's used to tell positional_argument to avoid mentioning
    3432              :          the argument number in diagnostics (since there's just one
    3433              :          mentioning it is unnecessary and coule be confusing).  */
    3434      2933954 :       tree next = TREE_CHAIN (args);
    3435      2933954 :       if (tree val = positional_argument (fntype, name, pos, INTEGER_TYPE,
    3436      2933954 :                                           next || i > 1 ? i : 0))
    3437              :         {
    3438      2933918 :           TREE_VALUE (args) = val;
    3439      2933918 :           newargs[i - 1] = val;
    3440              :         }
    3441              :       else
    3442              :         {
    3443           36 :           *no_add_attrs = true;
    3444           36 :           return NULL_TREE;
    3445              :         }
    3446              : 
    3447      2933918 :       args = next;
    3448              :     }
    3449              : 
    3450      2430658 :   if (!validate_attr_args (node, name, newargs))
    3451           39 :     *no_add_attrs = true;
    3452              : 
    3453              :   return NULL_TREE;
    3454              : }
    3455              : 
    3456              : 
    3457              : /* Handle an "alloc_align (argpos)" attribute.  */
    3458              : 
    3459              : static tree
    3460       101965 : handle_alloc_align_attribute (tree *node, tree name, tree args, int,
    3461              :                               bool *no_add_attrs)
    3462              : {
    3463       101965 :   tree fntype = *node;
    3464       101965 :   tree rettype = TREE_TYPE (fntype);
    3465       101965 :   if (!POINTER_TYPE_P (rettype))
    3466              :     {
    3467           11 :       warning (OPT_Wattributes,
    3468              :                "%qE attribute ignored on a function returning %qT",
    3469              :                name, rettype);
    3470           11 :       *no_add_attrs = true;
    3471           11 :       return NULL_TREE;
    3472              :     }
    3473              : 
    3474       101954 :   if (tree val = positional_argument (*node, name, TREE_VALUE (args),
    3475              :                                       INTEGER_TYPE))
    3476       101922 :     if (validate_attr_arg (node, name, val))
    3477              :       return NULL_TREE;
    3478              : 
    3479           40 :   *no_add_attrs = true;
    3480           40 :   return NULL_TREE;
    3481              : }
    3482              : 
    3483              : /* Handle a "assume_aligned" attribute; arguments as in
    3484              :    struct attribute_spec.handler.  */
    3485              : 
    3486              : static tree
    3487           58 : handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
    3488              :                                  bool *no_add_attrs)
    3489              : {
    3490           58 :   tree decl = *node;
    3491           58 :   tree rettype = TREE_TYPE (decl);
    3492           58 :   if (TREE_CODE (rettype) != POINTER_TYPE)
    3493              :     {
    3494            6 :       warning (OPT_Wattributes,
    3495              :                "%qE attribute ignored on a function returning %qT",
    3496              :                name, rettype);
    3497            6 :       *no_add_attrs = true;
    3498            6 :       return NULL_TREE;
    3499              :     }
    3500              : 
    3501              :   /* The alignment specified by the first argument.  */
    3502              :   tree align = NULL_TREE;
    3503              : 
    3504          102 :   for (; args; args = TREE_CHAIN (args))
    3505              :     {
    3506           69 :       tree val = TREE_VALUE (args);
    3507           69 :       if (val && TREE_CODE (val) != IDENTIFIER_NODE
    3508           69 :           && TREE_CODE (val) != FUNCTION_DECL)
    3509           65 :         val = default_conversion (val);
    3510              : 
    3511           69 :       if (!tree_fits_shwi_p (val))
    3512              :         {
    3513            5 :           warning (OPT_Wattributes,
    3514              :                    "%qE attribute argument %E is not an integer constant",
    3515              :                    name, val);
    3516            5 :           *no_add_attrs = true;
    3517            5 :           return NULL_TREE;
    3518              :         }
    3519           64 :       else if (tree_int_cst_sgn (val) < 0)
    3520              :         {
    3521            8 :           warning (OPT_Wattributes,
    3522              :                    "%qE attribute argument %E is not positive", name, val);
    3523            8 :           *no_add_attrs = true;
    3524            8 :           return NULL_TREE;
    3525              :         }
    3526              : 
    3527           56 :       if (!align)
    3528              :         {
    3529              :           /* Validate and save the alignment.  */
    3530           40 :           if (!integer_pow2p (val))
    3531              :             {
    3532            5 :               warning (OPT_Wattributes,
    3533              :                        "%qE attribute argument %E is not a power of 2",
    3534              :                        name, val);
    3535            5 :               *no_add_attrs = true;
    3536            5 :               return NULL_TREE;
    3537              :             }
    3538              : 
    3539              :           align = val;
    3540              :         }
    3541           16 :       else if (tree_int_cst_le (align, val))
    3542              :         {
    3543              :           /* The misalignment specified by the second argument
    3544              :              must be non-negative and less than the alignment.  */
    3545            2 :           warning (OPT_Wattributes,
    3546              :                    "%qE attribute argument %E is not in the range [0, %wu]",
    3547            1 :                    name, val, tree_to_uhwi (align) - 1);
    3548            1 :           *no_add_attrs = true;
    3549            1 :           return NULL_TREE;
    3550              :         }
    3551              :     }
    3552              :   return NULL_TREE;
    3553              : }
    3554              : 
    3555              : /* Handle the internal-only "arg spec" attribute.  */
    3556              : 
    3557              : static tree
    3558       443656 : handle_argspec_attribute (tree *, tree, tree args, int, bool *)
    3559              : {
    3560              :   /* Verify the attribute has one or two arguments and their kind.  */
    3561       887312 :   gcc_assert (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST);
    3562       443656 :   if (TREE_CHAIN (args))
    3563              :     {
    3564       443656 :       tree val = TREE_VALUE (TREE_CHAIN (args));
    3565       443656 :       gcc_assert (!TREE_CHAIN (TREE_CHAIN (args)));
    3566       443656 :       gcc_assert (TYPE_P (val));
    3567              :     }
    3568       443656 :   return NULL_TREE;
    3569              : }
    3570              : 
    3571              : /* Handle a "warn_unused" attribute; arguments as in
    3572              :    struct attribute_spec.handler.  */
    3573              : 
    3574              : static tree
    3575            3 : handle_warn_unused_attribute (tree *node, tree name,
    3576              :                               tree args ATTRIBUTE_UNUSED,
    3577              :                               int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
    3578              : {
    3579            3 :   if (TYPE_P (*node))
    3580              :     /* Do nothing else, just set the attribute.  We'll get at
    3581              :        it later with lookup_attribute.  */
    3582              :     ;
    3583              :   else
    3584              :     {
    3585            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    3586            0 :       *no_add_attrs = true;
    3587              :     }
    3588              : 
    3589            3 :   return NULL_TREE;
    3590              : }
    3591              : 
    3592              : /* Handle an "omp declare simd" attribute; arguments as in
    3593              :    struct attribute_spec.handler.  */
    3594              : 
    3595              : static tree
    3596         1090 : handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *)
    3597              : {
    3598         1090 :   return NULL_TREE;
    3599              : }
    3600              : 
    3601              : /* Handle an "omp declare variant {base,variant}" attribute; arguments as in
    3602              :    struct attribute_spec.handler.  */
    3603              : 
    3604              : static tree
    3605         1543 : handle_omp_declare_variant_attribute (tree *, tree, tree, int, bool *)
    3606              : {
    3607         1543 :   return NULL_TREE;
    3608              : }
    3609              : 
    3610              : /* Handle a "simd" attribute.  */
    3611              : 
    3612              : static tree
    3613         9014 : handle_simd_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs)
    3614              : {
    3615         9014 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    3616              :     {
    3617         9014 :       tree t = get_identifier ("omp declare simd");
    3618         9014 :       tree attr = NULL_TREE;
    3619         9014 :       if (args)
    3620              :         {
    3621         8889 :           tree id = TREE_VALUE (args);
    3622              : 
    3623         8889 :           if (TREE_CODE (id) != STRING_CST)
    3624              :             {
    3625            0 :               error ("attribute %qE argument not a string", name);
    3626            0 :               *no_add_attrs = true;
    3627            0 :               return NULL_TREE;
    3628              :             }
    3629              : 
    3630         8889 :           if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
    3631         8881 :             attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
    3632              :                                      OMP_CLAUSE_NOTINBRANCH);
    3633            8 :           else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
    3634            4 :             attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
    3635              :                                      OMP_CLAUSE_INBRANCH);
    3636              :           else
    3637              :             {
    3638            4 :               error ("only %<inbranch%> and %<notinbranch%> flags are "
    3639              :                      "allowed for %<__simd__%> attribute");
    3640            4 :               *no_add_attrs = true;
    3641            4 :               return NULL_TREE;
    3642              :             }
    3643              :         }
    3644              : 
    3645         9010 :       DECL_ATTRIBUTES (*node)
    3646        18020 :         = tree_cons (t, build_tree_list (NULL_TREE, attr),
    3647         9010 :                      DECL_ATTRIBUTES (*node));
    3648              :     }
    3649              :   else
    3650              :     {
    3651            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    3652            0 :       *no_add_attrs = true;
    3653              :     }
    3654              : 
    3655              :   return NULL_TREE;
    3656              : }
    3657              : 
    3658              : /* Handle an "omp declare target" attribute; arguments as in
    3659              :    struct attribute_spec.handler.  */
    3660              : 
    3661              : static tree
    3662         2992 : handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
    3663              : {
    3664         2992 :   return NULL_TREE;
    3665              : }
    3666              : 
    3667              : /* Handle an "non overlapping" attribute; arguments as in
    3668              :    struct attribute_spec.handler.  */
    3669              : 
    3670              : static tree
    3671            0 : handle_non_overlapping_attribute (tree *, tree, tree, int, bool *)
    3672              : {
    3673            0 :   return NULL_TREE;
    3674              : }
    3675              : 
    3676              : /* Handle a "no_limit_stack" attribute; arguments as in
    3677              :    struct attribute_spec.handler.  */
    3678              : 
    3679              : static tree
    3680            0 : handle_no_limit_stack_attribute (tree *node, tree name,
    3681              :                                  tree ARG_UNUSED (args),
    3682              :                                  int ARG_UNUSED (flags),
    3683              :                                  bool *no_add_attrs)
    3684              : {
    3685            0 :   tree decl = *node;
    3686              : 
    3687            0 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    3688              :     {
    3689            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    3690              :              "%qE attribute applies only to functions", name);
    3691            0 :       *no_add_attrs = true;
    3692              :     }
    3693            0 :   else if (DECL_INITIAL (decl))
    3694              :     {
    3695            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    3696              :                 "cannot set %qE attribute after definition", name);
    3697            0 :       *no_add_attrs = true;
    3698              :     }
    3699              :   else
    3700            0 :     DECL_NO_LIMIT_STACK (decl) = 1;
    3701              : 
    3702            0 :   return NULL_TREE;
    3703              : }
    3704              : 
    3705              : /* Handle an "unsequenced" attribute; arguments as in
    3706              :    struct attribute_spec.handler.  */
    3707              : 
    3708              : tree
    3709          311 : handle_unsequenced_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    3710              :                               int flags, bool *no_add_attrs)
    3711              : {
    3712          311 :   tree fntype = *node;
    3713          779 :   for (tree argtype = TYPE_ARG_TYPES (fntype); argtype;
    3714          468 :        argtype = TREE_CHAIN (argtype))
    3715              :     /* If any of the arguments have pointer or reference type, just
    3716              :        add the attribute alone.  */
    3717          507 :     if (POINTER_TYPE_P (TREE_VALUE (argtype)))
    3718              :       return NULL_TREE;
    3719              : 
    3720          272 :   if (VOID_TYPE_P (TREE_TYPE (fntype)))
    3721            5 :     warning (OPT_Wattributes, "%qE attribute on function type "
    3722              :              "without pointer arguments returning %<void%>", name);
    3723          272 :   const char *name2;
    3724          272 :   if (IDENTIFIER_LENGTH (name) == sizeof ("unsequenced") - 1)
    3725              :     name2 = "unsequenced noptr";
    3726              :   else
    3727          130 :     name2 = "reproducible noptr";
    3728          272 :   if (!lookup_attribute (name2, TYPE_ATTRIBUTES (fntype)))
    3729              :     {
    3730          252 :       *no_add_attrs = true;
    3731          252 :       gcc_assert ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE) == 0);
    3732          252 :       tree attr = tree_cons (get_identifier (name2), NULL_TREE,
    3733          252 :                              TYPE_ATTRIBUTES (fntype));
    3734          252 :       if (!lookup_attribute (IDENTIFIER_POINTER (name),
    3735          252 :                              TYPE_ATTRIBUTES (fntype)))
    3736          252 :         attr = tree_cons (name, NULL_TREE, attr);
    3737          252 :       *node = build_type_attribute_variant (*node, attr);
    3738              :     }
    3739              :   return NULL_TREE;
    3740              : }
    3741              : 
    3742              : /* Handle a "reproducible" attribute; arguments as in
    3743              :    struct attribute_spec.handler.  */
    3744              : 
    3745              : tree
    3746          118 : handle_reproducible_attribute (tree *node, tree name, tree args, int flags,
    3747              :                                bool *no_add_attrs)
    3748              : {
    3749          118 :   return handle_unsequenced_attribute (node, name, args, flags, no_add_attrs);
    3750              : }
    3751              : 
    3752              : /* Digest an attribute list destined for a transactional memory statement.
    3753              :    ALLOWED is the set of attributes that are allowed for this statement;
    3754              :    return the attribute we parsed.  Multiple attributes are never allowed.  */
    3755              : 
    3756              : int
    3757           46 : parse_tm_stmt_attr (tree attrs, int allowed)
    3758              : {
    3759           46 :   tree a_seen = NULL;
    3760           46 :   int m_seen = 0;
    3761              : 
    3762           93 :   for ( ; attrs ; attrs = TREE_CHAIN (attrs))
    3763              :     {
    3764           47 :       tree a = get_attribute_name (attrs);
    3765           47 :       tree ns = get_attribute_namespace (attrs);
    3766           47 :       int m = 0;
    3767              : 
    3768           47 :       if (is_attribute_p ("outer", a)
    3769           76 :           && (ns == NULL_TREE || strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0))
    3770           43 :         m = TM_STMT_ATTR_OUTER;
    3771              : 
    3772           43 :       if ((m & allowed) == 0)
    3773              :         {
    3774            4 :           warning (OPT_Wattributes, "%qE attribute directive ignored", a);
    3775            4 :           continue;
    3776              :         }
    3777              : 
    3778           43 :       if (m_seen == 0)
    3779              :         {
    3780              :           a_seen = a;
    3781              :           m_seen = m;
    3782              :         }
    3783            1 :       else if (m_seen == m)
    3784            1 :         warning (OPT_Wattributes, "%qE attribute duplicated", a);
    3785              :       else
    3786              :         warning (OPT_Wattributes, "%qE attribute follows %qE", a, a_seen);
    3787              :     }
    3788              : 
    3789           46 :   return m_seen;
    3790              : }
    3791              : 
    3792              : /* Transform a TM attribute name into a maskable integer and back.
    3793              :    Note that NULL (i.e. no attribute) is mapped to UNKNOWN, corresponding
    3794              :    to how the lack of an attribute is treated.  */
    3795              : 
    3796              : int
    3797     17805082 : tm_attr_to_mask (tree attr)
    3798              : {
    3799     17805082 :   if (attr == NULL)
    3800              :     return 0;
    3801     17804802 :   if (is_attribute_p ("transaction_safe", attr))
    3802              :     return TM_ATTR_SAFE;
    3803     17804675 :   if (is_attribute_p ("transaction_callable", attr))
    3804              :     return TM_ATTR_CALLABLE;
    3805     17804574 :   if (is_attribute_p ("transaction_pure", attr))
    3806              :     return TM_ATTR_PURE;
    3807     17804556 :   if (is_attribute_p ("transaction_unsafe", attr))
    3808              :     return TM_ATTR_IRREVOCABLE;
    3809     17804547 :   if (is_attribute_p ("transaction_may_cancel_outer", attr))
    3810            0 :     return TM_ATTR_MAY_CANCEL_OUTER;
    3811              :   return 0;
    3812              : }
    3813              : 
    3814              : tree
    3815           41 : tm_mask_to_attr (int mask)
    3816              : {
    3817           41 :   const char *str;
    3818           41 :   switch (mask)
    3819              :     {
    3820              :     case TM_ATTR_SAFE:
    3821              :       str = "transaction_safe";
    3822              :       break;
    3823            9 :     case TM_ATTR_CALLABLE:
    3824            9 :       str = "transaction_callable";
    3825            9 :       break;
    3826            9 :     case TM_ATTR_PURE:
    3827            9 :       str = "transaction_pure";
    3828            9 :       break;
    3829            0 :     case TM_ATTR_IRREVOCABLE:
    3830            0 :       str = "transaction_unsafe";
    3831            0 :       break;
    3832            0 :     case TM_ATTR_MAY_CANCEL_OUTER:
    3833            0 :       str = "transaction_may_cancel_outer";
    3834            0 :       break;
    3835            0 :     default:
    3836            0 :       gcc_unreachable ();
    3837              :     }
    3838           41 :   return get_identifier (str);
    3839              : }
    3840              : 
    3841              : /* Return the first TM attribute seen in LIST.  */
    3842              : 
    3843              : tree
    3844      1430729 : find_tm_attribute (tree list)
    3845              : {
    3846      1435465 :   for (; list ; list = TREE_CHAIN (list))
    3847              :     {
    3848         4884 :       tree name = get_attribute_name (list);
    3849         4884 :       if (tm_attr_to_mask (name) != 0)
    3850              :         return name;
    3851              :     }
    3852              :   return NULL_TREE;
    3853              : }
    3854              : 
    3855              : /* Handle the TM attributes; arguments as in struct attribute_spec.handler.
    3856              :    Here we accept only function types, and verify that none of the other
    3857              :    function TM attributes are also applied.  */
    3858              : /* ??? We need to accept class types for C++, but not C.  This greatly
    3859              :    complicates this function, since we can no longer rely on the extra
    3860              :    processing given by function_type_required.  */
    3861              : 
    3862              : static tree
    3863      1424044 : handle_tm_attribute (tree *node, tree name, tree args,
    3864              :                      int flags, bool *no_add_attrs)
    3865              : {
    3866              :   /* Only one path adds the attribute; others don't.  */
    3867      1424044 :   *no_add_attrs = true;
    3868              : 
    3869      1424044 :   switch (TREE_CODE (*node))
    3870              :     {
    3871           16 :     case RECORD_TYPE:
    3872           16 :     case UNION_TYPE:
    3873              :       /* Only tm_callable and tm_safe apply to classes.  */
    3874           16 :       if (tm_attr_to_mask (name) & ~(TM_ATTR_SAFE | TM_ATTR_CALLABLE))
    3875            0 :         goto ignored;
    3876              :       /* FALLTHRU */
    3877              : 
    3878      1423945 :     case FUNCTION_TYPE:
    3879      1423945 :     case METHOD_TYPE:
    3880      1423945 :       {
    3881      1423945 :         tree old_name = find_tm_attribute (TYPE_ATTRIBUTES (*node));
    3882      1423945 :         if (old_name == name)
    3883              :           ;
    3884      1423945 :         else if (old_name != NULL_TREE)
    3885           12 :           error ("type was previously declared %qE", old_name);
    3886              :         else
    3887      1423933 :           *no_add_attrs = false;
    3888              :       }
    3889              :       break;
    3890              : 
    3891           29 :     case FUNCTION_DECL:
    3892           29 :       {
    3893              :         /* transaction_safe_dynamic goes on the FUNCTION_DECL, but we also
    3894              :            want to set transaction_safe on the type.  */
    3895           29 :         gcc_assert (is_attribute_p ("transaction_safe_dynamic", name));
    3896           29 :         if (!TYPE_P (DECL_CONTEXT (*node)))
    3897            1 :           error_at (DECL_SOURCE_LOCATION (*node),
    3898              :                     "%<transaction_safe_dynamic%> may only be specified for "
    3899              :                     "a virtual function");
    3900           29 :         *no_add_attrs = false;
    3901           29 :         decl_attributes (&TREE_TYPE (*node),
    3902              :                          build_tree_list (get_identifier ("transaction_safe"),
    3903              :                                           NULL_TREE),
    3904              :                          0);
    3905           29 :         break;
    3906              :       }
    3907              : 
    3908           62 :     case POINTER_TYPE:
    3909           62 :       {
    3910           62 :         enum tree_code subcode = TREE_CODE (TREE_TYPE (*node));
    3911           62 :         if (subcode == FUNCTION_TYPE || subcode == METHOD_TYPE)
    3912              :           {
    3913           62 :             tree fn_tmp = TREE_TYPE (*node);
    3914           62 :             decl_attributes (&fn_tmp, tree_cons (name, args, NULL), 0);
    3915           62 :             *node = build_pointer_type (fn_tmp);
    3916           62 :             break;
    3917              :           }
    3918              :       }
    3919              :       /* FALLTHRU */
    3920              : 
    3921            8 :     default:
    3922              :       /* If a function is next, pass it on to be tried next.  */
    3923            8 :       if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
    3924            0 :         return tree_cons (name, args, NULL);
    3925              : 
    3926            8 :     ignored:
    3927            8 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    3928            8 :       break;
    3929              :     }
    3930              : 
    3931              :   return NULL_TREE;
    3932              : }
    3933              : 
    3934              : /* Handle the TM_WRAP attribute; arguments as in
    3935              :    struct attribute_spec.handler.  */
    3936              : 
    3937              : static tree
    3938           36 : handle_tm_wrap_attribute (tree *node, tree name, tree args,
    3939              :                           int ARG_UNUSED (flags), bool *no_add_attrs)
    3940              : {
    3941           36 :   tree decl = *node;
    3942              : 
    3943              :   /* We don't need the attribute even on success, since we
    3944              :      record the entry in an external table.  */
    3945           36 :   *no_add_attrs = true;
    3946              : 
    3947           36 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    3948            0 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    3949              :   else
    3950              :     {
    3951           36 :       tree wrap_decl = TREE_VALUE (args);
    3952           36 :       if (error_operand_p (wrap_decl))
    3953              :         ;
    3954           32 :       else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
    3955              :                && !VAR_OR_FUNCTION_DECL_P (wrap_decl))
    3956            8 :         error ("%qE argument not an identifier", name);
    3957              :       else
    3958              :         {
    3959           24 :           if (TREE_CODE (wrap_decl) == IDENTIFIER_NODE)
    3960            0 :             wrap_decl = lookup_name (wrap_decl);
    3961           24 :           if (wrap_decl && TREE_CODE (wrap_decl) == FUNCTION_DECL)
    3962              :             {
    3963           20 :               if (lang_hooks.types_compatible_p (TREE_TYPE (decl),
    3964           20 :                                                  TREE_TYPE (wrap_decl)))
    3965           12 :                 record_tm_replacement (wrap_decl, decl);
    3966              :               else
    3967            8 :                 error ("%qD is not compatible with %qD", wrap_decl, decl);
    3968              :             }
    3969              :           else
    3970            4 :             error ("%qE argument is not a function", name);
    3971              :         }
    3972              :     }
    3973              : 
    3974           36 :   return NULL_TREE;
    3975              : }
    3976              : 
    3977              : /* Handle a "callback_only" attribute; arguments as in
    3978              :    struct attribute_spec.handler.  */
    3979              : tree
    3980       103955 : handle_callback_only_attribute (tree *node, tree name, tree args,
    3981              :                                 int ARG_UNUSED (flags), bool *no_add_attrs)
    3982              : {
    3983       103955 :   tree decl = *node;
    3984       103955 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    3985              :     {
    3986            1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    3987              :                   "%qE attribute can only be used on functions", name);
    3988            1 :       *no_add_attrs = true;
    3989            1 :       return NULL_TREE;
    3990              :     }
    3991              : 
    3992       103954 :   tree decl_type = TREE_TYPE (decl);
    3993       103954 :   if (!prototype_p (decl_type))
    3994              :     {
    3995            2 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    3996              :                   "%qE attribute requires a prototype", name);
    3997            2 :       *no_add_attrs = true;
    3998            2 :       return NULL_TREE;
    3999              :     }
    4000       103952 :   else if (stdarg_p (decl_type))
    4001              :     {
    4002            1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4003              :                   "%qE attribute cannot be used on variadic functions", name);
    4004            1 :       *no_add_attrs = true;
    4005            1 :       return NULL_TREE;
    4006              :     }
    4007              : 
    4008       103951 :   tree val = positional_argument (decl, name, TREE_VALUE (args), POINTER_TYPE,
    4009              :                                   1, POSARG_ZERO);
    4010       103951 :   if (!val)
    4011              :     {
    4012            7 :       *no_add_attrs = true;
    4013            7 :       return NULL_TREE;
    4014              :     }
    4015       103944 :   TREE_VALUE (args) = val;
    4016              : 
    4017              :   /* We have to use the function type for validation, as
    4018              :      DECL_ARGUMENTS returns NULL at this point.  */
    4019       103944 :   int callback_fn_idx = TREE_INT_CST_LOW (val);
    4020       103944 :   tree decl_type_args = TYPE_ARG_TYPES (decl_type);
    4021              : 
    4022       103944 :   if (callback_fn_idx == CB_UNKNOWN_POS)
    4023              :     {
    4024            1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4025              :                   "callback function position cannot be marked as unknown");
    4026            1 :       *no_add_attrs = true;
    4027            1 :       return NULL_TREE;
    4028              :     }
    4029              : 
    4030       103943 :   --callback_fn_idx;
    4031              : 
    4032              :   /* Search for the type of the callback function in parameters of the original
    4033              :      function.  We know it's there because it's been validated by
    4034              :      positional_argument.  */
    4035       103943 :   tree cfn = chain_index (callback_fn_idx, decl_type_args);
    4036       103943 :   gcc_checking_assert (cfn != NULL_TREE);
    4037       103943 :   cfn = TREE_VALUE (cfn);
    4038       103943 :   tree cfn_pointee_type = TREE_TYPE (cfn);
    4039       103943 :   if (TREE_CODE (cfn) != POINTER_TYPE
    4040       103943 :       || TREE_CODE (cfn_pointee_type) != FUNCTION_TYPE)
    4041              :     {
    4042            0 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4043              :                   "argument no. %d is not an address of a function",
    4044              :                   callback_fn_idx + 1);
    4045            0 :       *no_add_attrs = true;
    4046            0 :       return NULL_TREE;
    4047              :     }
    4048              : 
    4049       103943 :   tree type_args = TYPE_ARG_TYPES (cfn_pointee_type);
    4050              : 
    4051       103943 :   if (!prototype_p (cfn_pointee_type))
    4052              :     {
    4053            1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4054              :                   "%qE callback function must have a prototype", name);
    4055            1 :       *no_add_attrs = true;
    4056            1 :       return NULL_TREE;
    4057              :     }
    4058       103942 :   else if (stdarg_p (cfn_pointee_type))
    4059              :     {
    4060            1 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4061              :                   "%qE callback function cannot be variadic", name);
    4062            1 :       *no_add_attrs = true;
    4063            1 :       return NULL_TREE;
    4064              :     }
    4065              : 
    4066              :   /* Compare the length of the list of argument indices
    4067              :      and the real number of parameters the callback takes.  */
    4068       103941 :   unsigned cfn_nargs = list_length (TREE_CHAIN (args));
    4069       103941 :   unsigned type_nargs = list_length (type_args) - 1;
    4070       103941 :   if (cfn_nargs != type_nargs)
    4071              :     {
    4072            3 :       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4073              :                   "argument number mismatch, %d expected, got %d", type_nargs,
    4074              :                   cfn_nargs);
    4075            3 :       *no_add_attrs = true;
    4076            3 :       return NULL_TREE;
    4077              :     }
    4078              : 
    4079       103938 :   unsigned curr = 0;
    4080       103938 :   tree it, cfn_it;
    4081              :   /* Validate type compatibility of the arguments passed
    4082              :      from caller function to callback.  "it" is used to step
    4083              :      through the parameters of the caller, "cfn_it" is
    4084              :      stepping through the parameters of the callback.  */
    4085       207877 :   for (it = type_args, cfn_it = TREE_CHAIN (args); curr < type_nargs;
    4086       103939 :        it = TREE_CHAIN (it), cfn_it = TREE_CHAIN (cfn_it), curr++)
    4087              :     {
    4088       103943 :       if (TREE_CODE (TREE_VALUE (cfn_it)) != INTEGER_CST)
    4089              :         {
    4090            1 :           warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4091              :                       "argument no. %d is not an integer constant", curr + 1);
    4092            1 :           *no_add_attrs = true;
    4093            1 :           continue;
    4094              :         }
    4095              : 
    4096       103942 :       tree expected_type = TREE_VALUE (it);
    4097       207884 :       tree arg_val = positional_argument (decl, name, TREE_VALUE (cfn_it),
    4098       103942 :                                           TREE_CODE (expected_type), curr + 1,
    4099              :                                           POSARG_ZERO);
    4100       103942 :       if (!arg_val)
    4101              :         {
    4102            4 :           *no_add_attrs = true;
    4103            4 :           return NULL_TREE;
    4104              :         }
    4105              : 
    4106       103938 :       TREE_VALUE (cfn_it) = arg_val;
    4107       103938 :       int arg_idx = TREE_INT_CST_LOW (TREE_VALUE (cfn_it));
    4108              : 
    4109              :       /* No need to check for type compatibility,
    4110              :          if we don't know what we are passing.  */
    4111       103938 :       if (arg_idx == CB_UNKNOWN_POS)
    4112            2 :         continue;
    4113              : 
    4114       103936 :       arg_idx -= 1;
    4115       103936 :       tree arg_type = chain_index (arg_idx, decl_type_args);
    4116       103936 :       gcc_checking_assert (arg_type != NULL_TREE);
    4117       103936 :       arg_type = TREE_VALUE (arg_type);
    4118              :       /* Check the type of the value we are about to pass ("arg_type")
    4119              :          for compatibility with the actual type the callback function
    4120              :          expects ("expected_type").  */
    4121       103936 :       if (!types_compatible_p (expected_type, arg_type))
    4122              :         {
    4123            0 :           warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4124              :                       "argument type at index %d is not compatible with "
    4125              :                       "callback argument type at index %d",
    4126              :                       arg_idx + 1, curr + 1);
    4127            0 :           *no_add_attrs = true;
    4128            0 :           continue;
    4129              :         }
    4130              :     }
    4131              : 
    4132              :   /* Check that the decl does not already have a callback attribute describing
    4133              :      the same argument.  */
    4134       103934 :   it = lookup_attribute ("callback_only", DECL_ATTRIBUTES (decl));
    4135       207870 :   for (; it; it = lookup_attribute ("callback_only", TREE_CHAIN (it)))
    4136            3 :     if (callback_get_fn_index (it) == callback_fn_idx)
    4137              :       {
    4138            1 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
    4139              :                     "function declaration has multiple callback attributes "
    4140              :                     "describing argument no. %d",
    4141              :                     callback_fn_idx + 1);
    4142            1 :         *no_add_attrs = true;
    4143            1 :         break;
    4144              :       }
    4145              : 
    4146              :   return NULL_TREE;
    4147              : }
    4148              : 
    4149              : /* Handle a "deprecated" attribute; arguments as in
    4150              :    struct attribute_spec.handler.  */
    4151              : 
    4152              : tree
    4153      1395952 : handle_deprecated_attribute (tree *node, tree name,
    4154              :                              tree args, int flags,
    4155              :                              bool *no_add_attrs)
    4156              : {
    4157      1395952 :   tree type = NULL_TREE;
    4158      1395952 :   int warn = 0;
    4159      1395952 :   tree what = NULL_TREE;
    4160              : 
    4161      1395952 :   if (!args)
    4162       634344 :     *no_add_attrs = true;
    4163       761608 :   else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    4164              :     {
    4165            7 :       error ("deprecated message is not a string");
    4166            7 :       *no_add_attrs = true;
    4167              :     }
    4168              : 
    4169      1395952 :   if (DECL_P (*node))
    4170              :     {
    4171      1018450 :       tree decl = *node;
    4172      1018450 :       type = TREE_TYPE (decl);
    4173              : 
    4174      1018450 :       if (TREE_CODE (decl) == TYPE_DECL
    4175      1018450 :           || TREE_CODE (decl) == PARM_DECL
    4176              :           || VAR_OR_FUNCTION_DECL_P (decl)
    4177              :           || TREE_CODE (decl) == FIELD_DECL
    4178              :           || TREE_CODE (decl) == CONST_DECL
    4179           29 :           || objc_method_decl (TREE_CODE (decl))
    4180           29 :           || TREE_CODE (decl) == CONCEPT_DECL)
    4181      1018435 :         TREE_DEPRECATED (decl) = 1;
    4182           15 :       else if (TREE_CODE (decl) == LABEL_DECL)
    4183              :         {
    4184           15 :           pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
    4185              :                    name);
    4186           15 :           *no_add_attrs = true;
    4187           15 :           return NULL_TREE;
    4188              :         }
    4189              :       else
    4190              :         warn = 1;
    4191              :     }
    4192       377502 :   else if (TYPE_P (*node))
    4193              :     {
    4194       377502 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    4195        10113 :         *node = build_variant_type_copy (*node);
    4196       377502 :       TREE_DEPRECATED (*node) = 1;
    4197       377502 :       type = *node;
    4198              :     }
    4199              :   else
    4200              :     warn = 1;
    4201              : 
    4202      1395937 :   if (warn)
    4203              :     {
    4204            0 :       *no_add_attrs = true;
    4205            0 :       if (type && TYPE_NAME (type))
    4206              :         {
    4207            0 :           if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
    4208            0 :             what = TYPE_NAME (type);
    4209            0 :           else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
    4210            0 :                    && DECL_NAME (TYPE_NAME (type)))
    4211            0 :             what = DECL_NAME (TYPE_NAME (type));
    4212              :         }
    4213            0 :       if (what)
    4214            0 :         warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
    4215              :       else
    4216            0 :         warning (OPT_Wattributes, "%qE attribute ignored", name);
    4217              :     }
    4218              : 
    4219              :   return NULL_TREE;
    4220              : }
    4221              : 
    4222              : /* Handle a "unavailable" attribute; arguments as in
    4223              :    struct attribute_spec.handler.  */
    4224              : 
    4225              : static tree
    4226          256 : handle_unavailable_attribute (tree *node, tree name,
    4227              :                              tree args, int flags,
    4228              :                              bool *no_add_attrs)
    4229              : {
    4230          256 :   tree type = NULL_TREE;
    4231          256 :   int warn = 0;
    4232          256 :   tree what = NULL_TREE;
    4233              : 
    4234          256 :   if (!args)
    4235          161 :     *no_add_attrs = true;
    4236           95 :   else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    4237              :     {
    4238            0 :       error ("the message attached to %<unavailable%> is not a string");
    4239            0 :       *no_add_attrs = true;
    4240              :     }
    4241              : 
    4242          256 :   if (DECL_P (*node))
    4243              :     {
    4244          217 :       tree decl = *node;
    4245          217 :       type = TREE_TYPE (decl);
    4246              : 
    4247          217 :       if (TREE_CODE (decl) == TYPE_DECL
    4248          217 :           || TREE_CODE (decl) == PARM_DECL
    4249              :           || VAR_OR_FUNCTION_DECL_P (decl)
    4250              :           || TREE_CODE (decl) == FIELD_DECL
    4251              :           || TREE_CODE (decl) == CONST_DECL
    4252            0 :           || objc_method_decl (TREE_CODE (decl)))
    4253          217 :         TREE_UNAVAILABLE (decl) = 1;
    4254              :       else
    4255              :         warn = 1;
    4256              :     }
    4257           39 :   else if (TYPE_P (*node))
    4258              :     {
    4259           39 :       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    4260            0 :         *node = build_variant_type_copy (*node);
    4261           39 :       TREE_UNAVAILABLE (*node) = 1;
    4262           39 :       type = *node;
    4263              :     }
    4264              :   else
    4265              :     warn = 1;
    4266              : 
    4267          256 :   if (warn)
    4268              :     {
    4269            0 :       *no_add_attrs = true;
    4270            0 :       if (type && TYPE_NAME (type))
    4271              :         {
    4272            0 :           if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
    4273            0 :             what = TYPE_NAME (*node);
    4274            0 :           else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
    4275            0 :                    && DECL_NAME (TYPE_NAME (type)))
    4276            0 :             what = DECL_NAME (TYPE_NAME (type));
    4277              :         }
    4278            0 :       if (what)
    4279            0 :         warning (OPT_Wattributes, "%qE attribute ignored for %qE", name, what);
    4280              :       else
    4281            0 :         warning (OPT_Wattributes, "%qE attribute ignored", name);
    4282              :     }
    4283              : 
    4284          256 :   return NULL_TREE;
    4285              : }
    4286              : 
    4287              : /* Return the "base" type from TYPE that is suitable to apply attribute
    4288              :    vector_size to by stripping arrays, function types, etc.  */
    4289              : static tree
    4290       532742 : type_for_vector_size (tree type)
    4291              : {
    4292              :   /* We need to provide for vector pointers, vector arrays, and
    4293              :      functions returning vectors.  For example:
    4294              : 
    4295              :        __attribute__((vector_size(16))) short *foo;
    4296              : 
    4297              :      In this case, the mode is SI, but the type being modified is
    4298              :      HI, so we need to look further.  */
    4299              : 
    4300       532742 :   while (POINTER_TYPE_P (type)
    4301              :          || TREE_CODE (type) == FUNCTION_TYPE
    4302              :          || TREE_CODE (type) == METHOD_TYPE
    4303              :          || TREE_CODE (type) == ARRAY_TYPE
    4304       533224 :          || TREE_CODE (type) == OFFSET_TYPE)
    4305          482 :     type = TREE_TYPE (type);
    4306              : 
    4307       532742 :   return type;
    4308              : }
    4309              : 
    4310              : /* Given TYPE, return the base type to which the vector_size attribute
    4311              :    ATNAME with ARGS, when non-null, can be applied, if one exists.
    4312              :    On success and when both ARGS and PTRNUNITS are non-null, set
    4313              :    *PTRNUNINTS to the number of vector units.  When PTRNUNITS is not
    4314              :    null, issue a warning when the attribute argument is not constant
    4315              :    and an error if there is no such type.  Otherwise issue a warning
    4316              :    in the latter case and return null.  */
    4317              : 
    4318              : static tree
    4319       532735 : type_valid_for_vector_size (tree type, tree atname, tree args,
    4320              :                             unsigned HOST_WIDE_INT *ptrnunits)
    4321              : {
    4322       532735 :   bool hardbool_p = c_hardbool_type_attr (type);
    4323       532735 :   bool error_p = ptrnunits != NULL || hardbool_p;
    4324              : 
    4325              :   /* Get the mode of the type being modified.  */
    4326       532735 :   machine_mode orig_mode = TYPE_MODE (type);
    4327              : 
    4328       532735 :   if ((!INTEGRAL_TYPE_P (type)
    4329       532735 :        && !SCALAR_FLOAT_TYPE_P (type)
    4330            1 :        && !FIXED_POINT_TYPE_P (type))
    4331       532734 :       || (!SCALAR_FLOAT_MODE_P (orig_mode)
    4332       342382 :           && GET_MODE_CLASS (orig_mode) != MODE_INT
    4333            2 :           && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
    4334       532732 :       || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
    4335       532732 :       || TREE_CODE (type) == BOOLEAN_TYPE
    4336       532725 :       || hardbool_p
    4337      1065459 :       || BITINT_TYPE_P (type))
    4338              :     {
    4339           13 :       if (error_p)
    4340           13 :         error ("invalid vector type for attribute %qE", atname);
    4341              :       else
    4342            0 :         warning (OPT_Wattributes, "invalid vector type for attribute %qE",
    4343              :                  atname);
    4344              :       return NULL_TREE;
    4345              :     }
    4346              : 
    4347              :   /* When no argument has been provided this is just a request to validate
    4348              :      the type above.  Return TYPE to indicate success.  */
    4349       532722 :   if (!args)
    4350              :     return type;
    4351              : 
    4352       532722 :   tree size = TREE_VALUE (args);
    4353              :   /* Erroneous arguments have already been diagnosed.  */
    4354       532722 :   if (size == error_mark_node)
    4355              :     return NULL_TREE;
    4356              : 
    4357       532718 :   if (size && TREE_CODE (size) != IDENTIFIER_NODE
    4358       532718 :       && TREE_CODE (size) != FUNCTION_DECL)
    4359       532710 :     size = default_conversion (size);
    4360              : 
    4361       532718 :   if (TREE_CODE (size) != INTEGER_CST)
    4362              :     {
    4363            8 :       if (error_p)
    4364            8 :         error ("%qE attribute argument value %qE is not an integer constant",
    4365              :                atname, size);
    4366              :       else
    4367            0 :         warning (OPT_Wattributes,
    4368              :                  "%qE attribute argument value %qE is not an integer constant",
    4369              :                  atname, size);
    4370              :       return NULL_TREE;
    4371              :     }
    4372              : 
    4373       532710 :   if (!TYPE_UNSIGNED (TREE_TYPE (size))
    4374       532710 :       && tree_int_cst_sgn (size) < 0)
    4375              :     {
    4376            1 :       if (error_p)
    4377            1 :         error ("%qE attribute argument value %qE is negative",
    4378              :                atname, size);
    4379              :       else
    4380            0 :         warning (OPT_Wattributes,
    4381              :                  "%qE attribute argument value %qE is negative",
    4382              :                  atname, size);
    4383              :       return NULL_TREE;
    4384              :     }
    4385              : 
    4386              :   /* The attribute argument value is constrained by the maximum bit
    4387              :      alignment representable in unsigned int on the host.  */
    4388       532709 :   unsigned HOST_WIDE_INT vecsize;
    4389       532709 :   unsigned HOST_WIDE_INT maxsize = tree_to_uhwi (max_object_size ());
    4390       532709 :   if (!tree_fits_uhwi_p (size)
    4391       532709 :       || (vecsize = tree_to_uhwi (size)) > maxsize)
    4392              :     {
    4393            2 :       if (error_p)
    4394            2 :         error ("%qE attribute argument value %qE exceeds %wu",
    4395              :                atname, size, maxsize);
    4396              :       else
    4397            0 :         warning (OPT_Wattributes,
    4398              :                  "%qE attribute argument value %qE exceeds %wu",
    4399              :                  atname, size, maxsize);
    4400              :       return NULL_TREE;
    4401              :     }
    4402              : 
    4403       532707 :   if (vecsize % tree_to_uhwi (TYPE_SIZE_UNIT (type)))
    4404              :     {
    4405           54 :       if (error_p)
    4406            2 :         error ("vector size not an integral multiple of component size");
    4407              :       return NULL_TREE;
    4408              :     }
    4409              : 
    4410       532653 :   if (vecsize == 0)
    4411              :     {
    4412            1 :       error ("zero vector size");
    4413            1 :       return NULL;
    4414              :     }
    4415              : 
    4416              :   /* Calculate how many units fit in the vector.  */
    4417       532652 :   unsigned HOST_WIDE_INT nunits = vecsize / tree_to_uhwi (TYPE_SIZE_UNIT (type));
    4418       532652 :   if (nunits & (nunits - 1))
    4419              :     {
    4420            0 :       if (error_p)
    4421            0 :         error ("number of vector components %wu not a power of two", nunits);
    4422              :       else
    4423            0 :         warning (OPT_Wattributes,
    4424              :                  "number of vector components %wu not a power of two", nunits);
    4425              :       return NULL_TREE;
    4426              :     }
    4427              : 
    4428       532652 :   if (nunits >= (unsigned HOST_WIDE_INT)INT_MAX)
    4429              :     {
    4430            1 :       if (error_p)
    4431            1 :         error ("number of vector components %wu exceeds %d",
    4432              :                nunits, INT_MAX - 1);
    4433              :       else
    4434            0 :         warning (OPT_Wattributes,
    4435              :                  "number of vector components %wu exceeds %d",
    4436              :                  nunits, INT_MAX - 1);
    4437              :       return NULL_TREE;
    4438              :     }
    4439              : 
    4440       532651 :   if (ptrnunits)
    4441       532527 :     *ptrnunits = nunits;
    4442              : 
    4443              :   return type;
    4444              : }
    4445              : 
    4446              : /* Handle a "vector_size" attribute; arguments as in
    4447              :    struct attribute_spec.handler.  */
    4448              : 
    4449              : static tree
    4450       532559 : handle_vector_size_attribute (tree *node, tree name, tree args,
    4451              :                               int ARG_UNUSED (flags),
    4452              :                               bool *no_add_attrs)
    4453              : {
    4454       532559 :   *no_add_attrs = true;
    4455              : 
    4456              :   /* Determine the "base" type to apply the attribute to.  */
    4457       532559 :   tree type = type_for_vector_size (*node);
    4458              : 
    4459              :   /* Get the vector size (in bytes) and let the function compute
    4460              :      the number of vector units.  */
    4461       532559 :   unsigned HOST_WIDE_INT nunits;
    4462       532559 :   type = type_valid_for_vector_size (type, name, args, &nunits);
    4463       532559 :   if (!type)
    4464              :     return NULL_TREE;
    4465              : 
    4466       532527 :   gcc_checking_assert (args != NULL);
    4467              : 
    4468       532527 :   tree new_type = build_vector_type (type, nunits);
    4469              : 
    4470              :   /* Build back pointers if needed.  */
    4471       532527 :   *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
    4472              : 
    4473       532527 :   return NULL_TREE;
    4474              : }
    4475              : 
    4476              : /* Handle a "vector_mask" attribute; arguments as in
    4477              :    struct attribute_spec.handler.  */
    4478              : 
    4479              : static tree
    4480            7 : handle_vector_mask_attribute (tree *node, tree name, tree,
    4481              :                               int ARG_UNUSED (flags),
    4482              :                               bool *no_add_attrs)
    4483              : {
    4484            7 :   *no_add_attrs = true;
    4485            7 :   if (!flag_gimple)
    4486              :     {
    4487            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    4488            0 :       return NULL_TREE;
    4489              :     }
    4490              : 
    4491              :   /* Determine the "base" type to apply the attribute to.  */
    4492            7 :   tree type = type_for_vector_size (*node);
    4493            7 :   if (!VECTOR_TYPE_P (type) || VECTOR_BOOLEAN_TYPE_P (type))
    4494              :     {
    4495            0 :       warning (OPT_Wattributes, "%qE attribute only supported on "
    4496              :                "non-mask vector types", name);
    4497            0 :       return NULL_TREE;
    4498              :     }
    4499              : 
    4500            7 :   tree new_type = truth_type_for (type);
    4501              : 
    4502              :   /* Build back pointers if needed.  */
    4503            7 :   *node = lang_hooks.types.reconstruct_complex_type (*node, new_type);
    4504              : 
    4505            7 :   return NULL_TREE;
    4506              : }
    4507              : 
    4508              : /* Handle the "nonnull" attribute.  */
    4509              : 
    4510              : static tree
    4511     47409153 : handle_nonnull_attribute (tree *node, tree name,
    4512              :                           tree args, int ARG_UNUSED (flags),
    4513              :                           bool *no_add_attrs)
    4514              : {
    4515     47409153 :   tree type = *node;
    4516              : 
    4517              :   /* If no arguments are specified, all pointer arguments should be
    4518              :      non-null.  Verify a full prototype is given so that the arguments
    4519              :      will have the correct types when we actually check them later.
    4520              :      Avoid diagnosing type-generic built-ins since those have no
    4521              :      prototype.  */
    4522     47409153 :   if (!args)
    4523              :     {
    4524     25940316 :       if (!prototype_p (type)
    4525     25940316 :           && (!TYPE_ATTRIBUTES (type)
    4526       874860 :               || !lookup_attribute ("type generic", TYPE_ATTRIBUTES (type))))
    4527              :         {
    4528            1 :           error ("%qE attribute without arguments on a non-prototype",
    4529              :                  name);
    4530            1 :           *no_add_attrs = true;
    4531              :         }
    4532              :       return NULL_TREE;
    4533              :     }
    4534              : 
    4535     49495952 :   for (int i = 1; args; ++i)
    4536              :     {
    4537     28027141 :       tree pos = TREE_VALUE (args);
    4538              :       /* NEXT is null when the attribute includes just one argument.
    4539              :          That's used to tell positional_argument to avoid mentioning
    4540              :          the argument number in diagnostics (since there's just one
    4541              :          mentioning it is unnecessary and could be confusing).  */
    4542     28027141 :       tree next = TREE_CHAIN (args);
    4543     28027141 :       if (tree val = positional_argument (type, name, pos, POINTER_TYPE,
    4544     28027141 :                                           next || i > 1 ? i : 0))
    4545     28027115 :         TREE_VALUE (args) = val;
    4546              :       else
    4547              :         {
    4548           26 :           *no_add_attrs = true;
    4549           26 :           break;
    4550              :         }
    4551     28027115 :       args = next;
    4552              :     }
    4553              : 
    4554              :   return NULL_TREE;
    4555              : }
    4556              : 
    4557              : /* Handle the "nonnull_if_nonzero" attribute.  */
    4558              : 
    4559              : static tree
    4560     15883449 : handle_nonnull_if_nonzero_attribute (tree *node, tree name,
    4561              :                                      tree args, int ARG_UNUSED (flags),
    4562              :                                      bool *no_add_attrs)
    4563              : {
    4564     15883449 :   tree type = *node;
    4565     15883449 :   tree pos = TREE_VALUE (args);
    4566     15883449 :   tree pos2 = TREE_VALUE (TREE_CHAIN (args));
    4567     15883449 :   tree chain2 = TREE_CHAIN (TREE_CHAIN (args));
    4568     15883449 :   tree pos3 = NULL_TREE;
    4569     15883449 :   if (chain2)
    4570       812452 :     pos3 = TREE_VALUE (chain2);
    4571     15883449 :   tree val = positional_argument (type, name, pos, POINTER_TYPE, 1);
    4572     15883449 :   tree val2 = positional_argument (type, name, pos2, INTEGER_TYPE, 2);
    4573     15883449 :   tree val3 = NULL_TREE;
    4574     15883449 :   if (chain2)
    4575       812452 :     val3 = positional_argument (type, name, pos3, INTEGER_TYPE, 3);
    4576     15883449 :   if (val && val2 && (!chain2 || val3))
    4577              :     {
    4578     15883436 :       TREE_VALUE (args) = val;
    4579     15883436 :       TREE_VALUE (TREE_CHAIN (args)) = val2;
    4580     15883436 :       if (chain2)
    4581       812447 :         TREE_VALUE (chain2) = val3;
    4582              :     }
    4583              :   else
    4584           13 :     *no_add_attrs = true;
    4585              : 
    4586     15883449 :   return NULL_TREE;
    4587              : }
    4588              : 
    4589              : /* Handle the "fd_arg", "fd_arg_read" and "fd_arg_write" attributes */
    4590              : 
    4591              : static tree
    4592           32 : handle_fd_arg_attribute (tree *node, tree name, tree args,
    4593              :                               int ARG_UNUSED (flags), bool *no_add_attrs)
    4594              : {
    4595           32 :   tree type = *node;
    4596           32 :   if (!args)
    4597              :     {
    4598            0 :       if (!prototype_p (type))
    4599              :         {
    4600            0 :           error ("%qE attribute without arguments on a non-prototype", name);
    4601            0 :           *no_add_attrs = true;
    4602              :         }
    4603              :       return NULL_TREE;
    4604              :     }
    4605              : 
    4606           32 :   if (positional_argument (*node, name, TREE_VALUE (args), INTEGER_TYPE))
    4607              :       return NULL_TREE;
    4608              : 
    4609           20 :   *no_add_attrs = true;
    4610           20 :   return NULL_TREE;
    4611              : }
    4612              : 
    4613              : /* Handle the "flag_enum" attribute.  */
    4614              : 
    4615              : static tree
    4616        42974 : handle_flag_enum_attribute (tree *node, tree ARG_UNUSED (name),
    4617              :                             tree ARG_UNUSED (args), int ARG_UNUSED (flags),
    4618              :                             bool *no_add_attrs)
    4619              : {
    4620        42974 :   if (TREE_CODE (*node) != ENUMERAL_TYPE)
    4621              :     {
    4622            0 :       warning (OPT_Wattributes, "%qE attribute ignored on non-enum", name);
    4623            0 :       *no_add_attrs = true;
    4624              :     }
    4625              : 
    4626        42974 :   return NULL_TREE;
    4627              : }
    4628              : 
    4629              : /* Handle the "null_terminated_string_arg" attribute.  */
    4630              : 
    4631              : static tree
    4632           64 : handle_null_terminated_string_arg_attribute (tree *node, tree name, tree args,
    4633              :                                              int ARG_UNUSED (flags),
    4634              :                                              bool *no_add_attrs)
    4635              : {
    4636           64 :   if (positional_argument (*node, name, TREE_VALUE (args), POINTER_TYPE))
    4637              :     return NULL_TREE;
    4638              : 
    4639           20 :   *no_add_attrs = true;
    4640           20 :   return NULL_TREE;
    4641              : }
    4642              : 
    4643              : /* Handle the "no_implicit_truncation" attribute.  */
    4644              : 
    4645              : static tree
    4646           66 : handle_no_implicit_truncation_attribute (tree *node, tree name,
    4647              :                                          tree ARG_UNUSED (args),
    4648              :                                          int ARG_UNUSED (flags),
    4649              :                                          bool *no_add_attrs)
    4650              : {
    4651           66 :   if (!INTEGRAL_TYPE_P (*node))
    4652              :     {
    4653           14 :       warning (OPT_Wattributes, "%qE attribute ignored on non-integer type",
    4654              :                name);
    4655           14 :       *no_add_attrs = true;
    4656              :     }
    4657           52 :   else if (TREE_CODE (*node) == ENUMERAL_TYPE)
    4658              :     {
    4659            4 :       warning (OPT_Wattributes, "%qE attribute ignored on enumerated type",
    4660              :                name);
    4661            4 :       *no_add_attrs = true;
    4662              :     }
    4663           48 :   else if (c_promoting_integer_type_p (*node))
    4664              :     {
    4665            8 :       warning (OPT_Wattributes, "%qE attribute ignored on type that promotes",
    4666              :                name);
    4667            8 :       *no_add_attrs = true;
    4668              :     }
    4669              : 
    4670           66 :   return NULL_TREE;
    4671              : }
    4672              : 
    4673              : /* Common argument checking for btf_type_tag and btf_decl_tag.
    4674              :    Return true if the ARGS are valid, otherwise emit an error and
    4675              :    return false.  */
    4676              : 
    4677              : static bool
    4678          113 : btf_tag_args_ok (tree name, tree args)
    4679              : {
    4680          113 :   if (!args) /* Correct number of args (1) is checked for us.  */
    4681              :     return false;
    4682          113 :   else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
    4683              :     {
    4684            2 :       error ("%qE attribute requires a string argument", name);
    4685            2 :       return false;
    4686              :     }
    4687              : 
    4688              :   /* Only narrow character strings are accepted.  */
    4689          111 :   tree argtype = TREE_TYPE (TREE_TYPE (TREE_VALUE (args)));
    4690          111 :   if (!(argtype == char_type_node
    4691            6 :         || argtype == char8_type_node
    4692            6 :         || argtype == signed_char_type_node
    4693            6 :         || argtype == unsigned_char_type_node))
    4694              :     {
    4695            6 :       error ("unsupported wide string type argument in %qE attribute", name);
    4696            6 :       return false;
    4697              :     }
    4698              : 
    4699              :   return true;
    4700              : }
    4701              : 
    4702              : /* Handle the "btf_decl_tag" attribute.  */
    4703              : 
    4704              : static tree
    4705           52 : handle_btf_decl_tag_attribute (tree * ARG_UNUSED (node), tree name, tree args,
    4706              :                                int ARG_UNUSED (flags), bool *no_add_attrs)
    4707              : {
    4708           52 :   if (!btf_tag_args_ok (name, args))
    4709            4 :     *no_add_attrs = true;
    4710              : 
    4711           52 :   return NULL_TREE;
    4712              : }
    4713              : 
    4714              : /* Handle the "btf_type_tag" attribute.  */
    4715              : 
    4716              : static tree
    4717           61 : handle_btf_type_tag_attribute (tree *node, tree name, tree args,
    4718              :                                int flags, bool *no_add_attrs)
    4719              : {
    4720           61 :   if (!btf_tag_args_ok (name, args))
    4721              :     {
    4722            4 :       *no_add_attrs = true;
    4723            4 :       return NULL_TREE;
    4724              :     }
    4725              : 
    4726           57 :   if (TREE_CODE (*node) == FUNCTION_TYPE || TREE_CODE (*node) == METHOD_TYPE)
    4727              :     {
    4728            3 :       warning (OPT_Wattributes,
    4729              :                "%qE attribute does not apply to functions", name);
    4730            3 :       *no_add_attrs = true;
    4731            3 :       return NULL_TREE;
    4732              :     }
    4733              : 
    4734              :   /* Ensure a variant type is always created to hold the type_tag,
    4735              :      unless ATTR_FLAG_IN_PLACE is set.  Same logic as in
    4736              :      common_handle_aligned_attribute.  */
    4737           54 :   tree decl = NULL_TREE;
    4738           54 :   tree *type = NULL;
    4739           54 :   bool is_type = false;
    4740              : 
    4741           54 :   if (DECL_P (*node))
    4742              :     {
    4743            0 :       decl = *node;
    4744            0 :       type = &TREE_TYPE (decl);
    4745            0 :       is_type = TREE_CODE (*node) == TYPE_DECL;
    4746              :     }
    4747           54 :   else if (TYPE_P (*node))
    4748              :     type = node, is_type = true;
    4749              : 
    4750            0 :   if (is_type)
    4751              :     {
    4752           54 :       if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
    4753              :         /* OK, modify the type in place.  */;
    4754              : 
    4755              :       /* If we have a TYPE_DECL, then copy the type, so that we
    4756              :          don't accidentally modify a builtin type.  See pushdecl.  */
    4757            0 :       else if (decl && TREE_TYPE (decl) != error_mark_node
    4758           50 :                && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
    4759              :         {
    4760            0 :           tree tt = TREE_TYPE (decl);
    4761            0 :           *type = build_variant_type_copy (*type);
    4762            0 :           DECL_ORIGINAL_TYPE (decl) = tt;
    4763            0 :           TYPE_NAME (*type) = decl;
    4764            0 :           TREE_USED (*type) = TREE_USED (decl);
    4765            0 :           TREE_TYPE (decl) = *type;
    4766              :         }
    4767              :       else
    4768           50 :         *type = build_variant_type_copy (*type);
    4769              :     }
    4770              : 
    4771              :   return NULL_TREE;
    4772              : }
    4773              : 
    4774              : /* Handle the "nonstring" variable attribute.  */
    4775              : 
    4776              : static tree
    4777          894 : handle_nonstring_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    4778              :                             int ARG_UNUSED (flags), bool *no_add_attrs)
    4779              : {
    4780          894 :   gcc_assert (!args);
    4781          894 :   tree_code code = TREE_CODE (*node);
    4782              : 
    4783          894 :   if (VAR_P (*node)
    4784          409 :       || code == FIELD_DECL
    4785          409 :       || code == PARM_DECL)
    4786              :     {
    4787          886 :       tree type = TREE_TYPE (*node);
    4788              : 
    4789          886 :       if (POINTER_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)
    4790              :         {
    4791              :           /* Accept the attribute on arrays and pointers to all three
    4792              :              narrow character types, including multi-dimensional arrays
    4793              :              or pointers to them.  */
    4794          878 :           tree eltype = strip_array_types (TREE_TYPE (type));
    4795          878 :           eltype = TYPE_MAIN_VARIANT (eltype);
    4796          878 :           if (eltype == char_type_node
    4797          136 :               || eltype == signed_char_type_node
    4798           72 :               || eltype == unsigned_char_type_node)
    4799              :             return NULL_TREE;
    4800              :         }
    4801              : 
    4802           16 :       warning (OPT_Wattributes,
    4803              :                "%qE attribute ignored on objects of type %qT",
    4804              :                name, type);
    4805           16 :       *no_add_attrs = true;
    4806           16 :       return NULL_TREE;
    4807              :     }
    4808              : 
    4809            8 :   if (code == FUNCTION_DECL)
    4810            4 :     warning (OPT_Wattributes,
    4811              :              "%qE attribute does not apply to functions", name);
    4812            4 :   else if (code == TYPE_DECL)
    4813            4 :     warning (OPT_Wattributes,
    4814              :              "%qE attribute does not apply to types", name);
    4815              :   else
    4816            0 :     warning (OPT_Wattributes, "%qE attribute ignored", name);
    4817              : 
    4818            8 :   *no_add_attrs = true;
    4819            8 :   return NULL_TREE;
    4820              : }
    4821              : 
    4822              : /* Handle the "suppress_coverge" attribute.  We don't really do anything here,
    4823              :    just check later if it is set.  */
    4824              : static tree
    4825           18 : handle_suppress_coverage_attribute (tree *node, tree name,
    4826              :                                     tree ARG_UNUSED (args),
    4827              :                                     int ARG_UNUSED (flags), bool *no_add_attrs)
    4828              : {
    4829           18 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    4830              :     {
    4831            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    4832            0 :       *no_add_attrs = true;
    4833              :     }
    4834              : 
    4835           18 :   return NULL_TREE;
    4836              : }
    4837              : 
    4838              : /* Given a function type FUNCTYPE, returns the type of the parameter
    4839              :    ARGNO or null if ARGNO exceeds the number of parameters.  On failure
    4840              :    set *NARGS to the number of function parameters.  */
    4841              : 
    4842              : static tree
    4843      1367265 : get_argument_type (tree functype, unsigned argno, unsigned *nargs)
    4844              : {
    4845      1367265 :   function_args_iterator iter;
    4846      1367265 :   function_args_iter_init (&iter, functype);
    4847              : 
    4848      1367265 :   unsigned count = 0;
    4849              : 
    4850      4163511 :   for ( ; iter.next; ++count, function_args_iter_next (&iter))
    4851              :     {
    4852      2796240 :       if (count + 1 == argno)
    4853              :         {
    4854      1367259 :           tree argtype = function_args_iter_cond (&iter);
    4855      1367259 :           if (VOID_TYPE_P (argtype))
    4856              :             break;
    4857      1367256 :           if (argtype != error_mark_node)
    4858              :             return argtype;
    4859              :         }
    4860              :     }
    4861              : 
    4862            9 :   *nargs = count;
    4863            9 :   return NULL_TREE;
    4864              : }
    4865              : 
    4866              : /* Given a function FNDECL return the function argument at the zero-
    4867              :    based position ARGNO or null if it can't be found.  */
    4868              : 
    4869              : static tree
    4870            6 : get_argument (tree fndecl, unsigned argno)
    4871              : {
    4872            6 :   if (!DECL_P (fndecl))
    4873              :     return NULL_TREE;
    4874              : 
    4875            6 :   unsigned i = 0;
    4876           10 :   for (tree arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg))
    4877            8 :     if (i++ == argno)
    4878              :       return arg;
    4879              : 
    4880              :   return NULL_TREE;
    4881              : }
    4882              : 
    4883              : /* Attempt to append attribute access specification ATTRSPEC, optionally
    4884              :    described by the human-readable string ATTRSTR, for type T, to one in
    4885              :    ATTRS. VBLIST is an optional list of bounds of variable length array
    4886              :    parameters described by ATTRSTR.
    4887              :    Issue warning for conflicts and return null if any are found.
    4888              :    Return the concatenated access string on success.  */
    4889              : 
    4890              : static tree
    4891      1164439 : append_access_attr (tree node[3], tree attrs, const char *attrstr,
    4892              :                     const char *attrspec, tree vblist = NULL_TREE)
    4893              : {
    4894      1164439 :   tree argstr = build_string (strlen (attrspec) + 1, attrspec);
    4895      1164439 :   tree ataccess = tree_cons (NULL_TREE, argstr, vblist);
    4896      1164439 :   ataccess = tree_cons (get_identifier ("access"), ataccess, NULL_TREE);
    4897              : 
    4898              :   /* The access specification being applied.  This may be an implicit
    4899              :      access spec synthesized for array (or VLA) parameters even for
    4900              :      a declaration with an explicit access spec already applied, if
    4901              :      this call corresponds to the first declaration of the function.  */
    4902      1164439 :   rdwr_map new_idxs;
    4903      1164439 :   init_attr_rdwr_indices (&new_idxs, ataccess);
    4904              : 
    4905              :   /* The current access specification already applied.  */
    4906      1164439 :   rdwr_map cur_idxs;
    4907      1164439 :   init_attr_rdwr_indices (&cur_idxs, attrs);
    4908              : 
    4909      1164439 :   tree args = TYPE_ARG_TYPES (node[0]);
    4910      1164439 :   int argpos = 0;
    4911      1164439 :   std::string spec;
    4912      5424117 :   for (tree arg = args; arg; arg = TREE_CHAIN (arg), argpos++)
    4913              :     {
    4914      4259678 :       const attr_access* const newa = new_idxs.get (argpos);
    4915              : 
    4916      4259678 :       if (!newa)
    4917      4259595 :         continue;
    4918              : 
    4919              :       /* The map has two equal entries for each pointer argument that
    4920              :          has an associated size argument.  Process just the entry for
    4921              :          the former.  */
    4922      1811220 :       if ((unsigned)argpos != newa->ptrarg)
    4923       612123 :         continue;
    4924              : 
    4925      1199097 :       const attr_access* const cura = cur_idxs.get (argpos);
    4926      1199097 :       if (!cura)
    4927              :         {
    4928              :           /* The new attribute needs to be added.  */
    4929      1192460 :           tree str = newa->to_internal_string ();
    4930      1192460 :           spec += TREE_STRING_POINTER (str);
    4931      1192460 :           continue;
    4932      1192460 :         }
    4933              : 
    4934              :       /* The new access spec refers to an array/pointer argument for
    4935              :          which an access spec already exists.  Check and diagnose any
    4936              :          conflicts.  If no conflicts are found, merge the two.  */
    4937              : 
    4938         6637 :       if (!attrstr)
    4939              :         {
    4940         6443 :           tree str = NULL_TREE;
    4941         6443 :           if (newa->mode != access_deferred)
    4942            0 :             str = newa->to_external_string ();
    4943         6443 :           else if (cura->mode != access_deferred)
    4944         2198 :             str = cura->to_external_string ();
    4945         2198 :           if (str)
    4946         2198 :             attrstr = TREE_STRING_POINTER (str);
    4947              :         }
    4948              : 
    4949         6637 :       location_t curloc = input_location;
    4950         6637 :       if (node[2] && DECL_P (node[2]))
    4951         6637 :         curloc = DECL_SOURCE_LOCATION (node[2]);
    4952              : 
    4953         6637 :       location_t prevloc = UNKNOWN_LOCATION;
    4954         6637 :       if (node[1] && DECL_P (node[1]))
    4955         3728 :         prevloc = DECL_SOURCE_LOCATION (node[1]);
    4956              : 
    4957         6637 :       if (newa->mode != cura->mode
    4958         2220 :           && newa->mode != access_deferred
    4959           22 :           && cura->mode != access_deferred
    4960           10 :           && newa->internal_p == cura->internal_p)
    4961              :         {
    4962              :           /* Mismatch in access mode.  */
    4963           10 :           auto_diagnostic_group d;
    4964            0 :           if (warning_at (curloc, OPT_Wattributes,
    4965              :                           "attribute %qs mismatch with mode %qs",
    4966           10 :                           attrstr, cura->mode_names[cura->mode])
    4967           10 :               && prevloc != UNKNOWN_LOCATION)
    4968           10 :             inform (prevloc, "previous declaration here");
    4969           10 :           continue;
    4970           10 :         }
    4971              : 
    4972              :       /* Set if PTRARG refers to a VLA with an unspecified bound (T[*]).
    4973              :          Be prepared for either CURA or NEWA to refer to it, depending
    4974              :          on which happens to come first in the declaration.  */
    4975        13254 :       const bool cur_vla_ub = (cura->internal_p
    4976         4280 :                                && cura->sizarg == UINT_MAX
    4977        10801 :                                && cura->minsize == HOST_WIDE_INT_M1U);
    4978        13254 :       const bool new_vla_ub = (newa->internal_p
    4979         6443 :                                && newa->sizarg == UINT_MAX
    4980        12960 :                                && newa->minsize == HOST_WIDE_INT_M1U);
    4981              : 
    4982         6627 :       if (newa->sizarg != cura->sizarg
    4983         2149 :           && attrstr
    4984         2145 :           && (!(cur_vla_ub ^ new_vla_ub)
    4985           19 :               || (!cura->internal_p && !newa->internal_p)))
    4986              :         {
    4987              :           /* Avoid diagnosing redeclarations of functions with no explicit
    4988              :              attribute access that add one.  */
    4989         2126 :           if (newa->mode == access_deferred
    4990         2116 :               && cura->mode != access_deferred
    4991         2116 :               && newa->sizarg == UINT_MAX
    4992         2112 :               && cura->sizarg != UINT_MAX)
    4993         2112 :             continue;
    4994              : 
    4995           14 :           if (cura->mode == access_deferred
    4996            4 :               && newa->mode != access_deferred
    4997            4 :               && cura->sizarg == UINT_MAX
    4998            3 :               && newa->sizarg != UINT_MAX)
    4999            3 :             continue;
    5000              : 
    5001              :           /* The two specs designate different size arguments.  It's okay
    5002              :              for the explicit spec to specify a size where none is provided
    5003              :              by the implicit (VLA) one, as in:
    5004              :                __attribute__ ((access (read_write, 1, 2)))
    5005              :                void f (int*, int);
    5006              :              but not for two explicit access attributes to do that.  */
    5007           11 :           bool warned = false;
    5008              : 
    5009           11 :           auto_diagnostic_group d;
    5010              : 
    5011           11 :           if (newa->sizarg == UINT_MAX)
    5012              :             /* Mismatch in the presence of the size argument.  */
    5013            2 :             warned = warning_at (curloc, OPT_Wattributes,
    5014              :                                  "attribute %qs missing positional argument 2 "
    5015              :                                  "provided in previous designation by argument "
    5016            2 :                                  "%u", attrstr, cura->sizarg + 1);
    5017            9 :           else if (cura->sizarg == UINT_MAX)
    5018              :             /* Mismatch in the presence of the size argument.  */
    5019            3 :             warned = warning_at (curloc, OPT_Wattributes,
    5020              :                                  "attribute %qs positional argument 2 "
    5021              :                                  "missing in previous designation",
    5022              :                                  attrstr);
    5023            6 :           else if (newa->internal_p || cura->internal_p)
    5024              :             /* Mismatch in the value of the size argument and a VLA bound.  */
    5025            4 :             warned = warning_at (curloc, OPT_Wattributes,
    5026              :                                  "attribute %qs positional argument 2 "
    5027              :                                  "conflicts with previous designation "
    5028              :                                  "by argument %u",
    5029              :                                  attrstr, cura->sizarg + 1);
    5030              :           else
    5031              :             /* Mismatch in the value of the size argument between two
    5032              :                explicit access attributes.  */
    5033            2 :             warned = warning_at (curloc, OPT_Wattributes,
    5034              :                                  "attribute %qs mismatched positional argument "
    5035              :                                  "values %i and %i",
    5036              :                                  attrstr, newa->sizarg + 1, cura->sizarg + 1);
    5037              : 
    5038           11 :           if (warned)
    5039              :             {
    5040              :               /* If the previous declaration is a function (as opposed
    5041              :                  to a typedef of one), find the location of the array
    5042              :                  or pointer argument that uses the conflicting VLA bound
    5043              :                  and point to it in the note.  */
    5044           11 :               const attr_access* const pa = cura->size ? cura : newa;
    5045           11 :               tree size = pa->size ? TREE_VALUE (pa->size) : NULL_TREE;
    5046            6 :               if (size && DECL_P (size))
    5047              :                 {
    5048            6 :                   location_t argloc = UNKNOWN_LOCATION;
    5049            6 :                   if (tree arg = get_argument (node[2], pa->ptrarg))
    5050            4 :                     argloc = DECL_SOURCE_LOCATION (arg);
    5051              : 
    5052            6 :                   gcc_rich_location richloc (DECL_SOURCE_LOCATION (size));
    5053            6 :                   if (argloc != UNKNOWN_LOCATION)
    5054            4 :                     richloc.add_range (argloc);
    5055              : 
    5056            6 :                   inform (&richloc, "designating the bound of variable "
    5057              :                           "length array argument %u",
    5058            6 :                           pa->ptrarg + 1);
    5059            6 :                 }
    5060            5 :               else if (prevloc != UNKNOWN_LOCATION)
    5061            3 :                 inform (prevloc, "previous declaration here");
    5062              :             }
    5063              : 
    5064           11 :           continue;
    5065           11 :         }
    5066              : 
    5067         4501 :       if (newa->internal_p == cura->internal_p)
    5068         4418 :         continue;
    5069              : 
    5070              :       /* Merge the CURA and NEWA.  */
    5071           83 :       attr_access merged = *newa;
    5072              : 
    5073              :       /* VLA seen in a declaration takes precedence.  */
    5074           83 :       if (cura->minsize == HOST_WIDE_INT_M1U)
    5075           17 :         merged.minsize = HOST_WIDE_INT_M1U;
    5076              : 
    5077              :       /* Use the explicitly specified size positional argument.  */
    5078           83 :       if (cura->sizarg != UINT_MAX)
    5079           25 :         merged.sizarg = cura->sizarg;
    5080              : 
    5081              :       /* Use the explicitly specified mode.  */
    5082           83 :       if (merged.mode == access_deferred)
    5083           68 :         merged.mode = cura->mode;
    5084              : 
    5085           83 :       tree str = merged.to_internal_string ();
    5086           83 :       spec += TREE_STRING_POINTER (str);
    5087              :     }
    5088              : 
    5089      1164439 :   if (!spec.length ())
    5090              :     return NULL_TREE;
    5091              : 
    5092      1160203 :   return build_string (spec.length (), spec.c_str ());
    5093      1164439 : }
    5094              : 
    5095              : /* Convenience wrapper for the above.  */
    5096              : 
    5097              : static tree
    5098       755604 : append_access_attr_idxs (tree node[3], tree attrs, const char *attrstr,
    5099              :                          char code, HOST_WIDE_INT idxs[2])
    5100              : {
    5101       755604 :   char attrspec[80];
    5102       755604 :   int n = sprintf (attrspec, "%c%u", code, (unsigned) idxs[0] - 1);
    5103       755604 :   if (idxs[1])
    5104       611886 :     n += sprintf (attrspec + n, ",%u", (unsigned) idxs[1] - 1);
    5105              : 
    5106       755604 :   return append_access_attr (node, attrs, attrstr, attrspec);
    5107              : }
    5108              : 
    5109              : /* Handle the access attribute for function type NODE[0], with the function
    5110              :    DECL optionally in NODE[1].  The handler is called both in response to
    5111              :    an explicit attribute access on a declaration with a mode and one or two
    5112              :    positional arguments, and for internally synthesized access specifications
    5113              :    with a string argument optionally followed by a DECL or expression
    5114              :    representing a VLA bound.  To speed up parsing, the handler transforms
    5115              :    the attribute and its arguments into a string.  */
    5116              : 
    5117              : static tree
    5118      2324242 : handle_access_attribute (tree node[3], tree name, tree args, int flags,
    5119              :                          bool *no_add_attrs)
    5120              : {
    5121      2324242 :   tree attrs = TYPE_ATTRIBUTES (*node);
    5122      2324242 :   tree type = *node;
    5123      2324242 :   if (POINTER_TYPE_P (type))
    5124              :     {
    5125            0 :       tree ptype = TREE_TYPE (type);
    5126            0 :       if (FUNC_OR_METHOD_TYPE_P (ptype))
    5127      2324242 :         type = ptype;
    5128              :     }
    5129              : 
    5130      2324242 :   *no_add_attrs = true;
    5131              : 
    5132              :   /* Verify a full prototype is provided so that the argument types
    5133              :      can be validated.  Avoid diagnosing type-generic built-ins since
    5134              :      those have no prototype.  */
    5135      2324242 :   if (!args
    5136            0 :       && !prototype_p (type)
    5137      2324242 :       && (!attrs || !lookup_attribute ("type generic", attrs)))
    5138              :     {
    5139            0 :       error ("attribute %qE without arguments on a non-prototype", name);
    5140            0 :       return NULL_TREE;
    5141              :     }
    5142              : 
    5143      2324242 :   tree access_mode = TREE_VALUE (args);
    5144      2324242 :   if (TREE_CODE (access_mode) == STRING_CST)
    5145              :     {
    5146      1568813 :       const char* const str = TREE_STRING_POINTER (access_mode);
    5147      1568813 :       if (*str == '+')
    5148              :         {
    5149              :           /* This is a request to merge an internal specification for
    5150              :              a function declaration involving arrays but no explicit
    5151              :              attribute access.  */
    5152       408835 :           tree vblist = TREE_CHAIN (args);
    5153       408835 :           tree axstr = append_access_attr (node, attrs, NULL, str + 1,
    5154              :                                            vblist);
    5155       408835 :           if (!axstr)
    5156              :             return NULL_TREE;
    5157              : 
    5158              :           /* Replace any existing access attribute specification with
    5159              :              the concatenation above.  */
    5160       404778 :           tree axsat = tree_cons (NULL_TREE, axstr, vblist);
    5161       404778 :           axsat = tree_cons (name, axsat, NULL_TREE);
    5162              : 
    5163              :           /* Recursively call self to "replace" the documented/external
    5164              :              form of the attribute with the condensend internal form.  */
    5165       404778 :           decl_attributes (node, axsat, flags | ATTR_FLAG_INTERNAL);
    5166       404778 :           return NULL_TREE;
    5167              :         }
    5168              : 
    5169      1159978 :       if (flags & ATTR_FLAG_INTERNAL)
    5170              :         {
    5171              :           /* This is a recursive call to handle the condensed internal
    5172              :              form of the attribute (see below).  Since all validation
    5173              :              has been done simply return here, accepting the attribute
    5174              :              as is.  */
    5175      1159976 :           *no_add_attrs = false;
    5176      1159976 :           return NULL_TREE;
    5177              :         }
    5178              :     }
    5179              : 
    5180              :   /* Set to true when the access mode has the form of a function call
    5181              :      as in 'attribute (read_only (1, 2))'.  That's an easy mistake to
    5182              :      make and so worth a special diagnostic.  */
    5183       755431 :   bool funcall = false;
    5184       755431 :   if (TREE_CODE (access_mode) == CALL_EXPR)
    5185              :     {
    5186            6 :       access_mode = CALL_EXPR_FN (access_mode);
    5187            6 :       if (TREE_CODE (access_mode) != ADDR_EXPR)
    5188              :         {
    5189            0 :           error ("attribute %qE invalid mode", name);
    5190            0 :           return NULL_TREE;
    5191              :         }
    5192            6 :       access_mode = TREE_OPERAND (access_mode, 0);
    5193            6 :       access_mode = DECL_NAME (access_mode);
    5194            6 :       funcall = true;
    5195              :     }
    5196       755425 :   else if (TREE_CODE (access_mode) != IDENTIFIER_NODE)
    5197              :     {
    5198            5 :       error ("attribute %qE mode %qE is not an identifier; expected one of "
    5199              :              "%qs, %qs, %qs, or %qs", name, access_mode,
    5200              :              "read_only", "read_write", "write_only", "none");
    5201            5 :       return NULL_TREE;
    5202              :     }
    5203              : 
    5204       755426 :   const char* const access_str = IDENTIFIER_POINTER (access_mode);
    5205       755426 :   const char *ps = access_str;
    5206       755426 :   if (ps[0] == '_' && ps[1] == '_')
    5207              :     {
    5208       754884 :       size_t len = strlen (ps);
    5209       754884 :       if (ps[len - 1] == '_' && ps[len - 2] == '_')
    5210       754884 :         ps += 2;
    5211              :     }
    5212              : 
    5213       755426 :   int imode;
    5214              : 
    5215       755426 :   {
    5216       755426 :     const int nmodes = ARRAY_SIZE (attr_access::mode_names);
    5217              : 
    5218      2038652 :     for (imode = 0; imode != nmodes; ++imode)
    5219      2038634 :       if (!strncmp (ps, attr_access::mode_names[imode],
    5220      2038634 :                     strlen (attr_access::mode_names[imode])))
    5221              :         break;
    5222              : 
    5223       755426 :     if (imode == nmodes)
    5224              :       {
    5225           18 :         error ("attribute %qE invalid mode %qs; expected one of "
    5226              :                "%qs, %qs, %qs, or %qs", name, access_str,
    5227              :                "read_only", "read_write", "write_only", "none");
    5228           18 :         return NULL_TREE;
    5229              :       }
    5230              :   }
    5231              : 
    5232       755408 :   const ::access_mode mode = static_cast<::access_mode>(imode);
    5233              : 
    5234       755408 :   if (funcall)
    5235              :     {
    5236            3 :       error ("attribute %qE unexpected %<(%> after mode %qs; expected "
    5237              :              "a positional argument or %<)%>",
    5238              :              name, access_str);
    5239            3 :       return NULL_TREE;
    5240              :     }
    5241              : 
    5242       755405 :   args = TREE_CHAIN (args);
    5243       755405 :   if (!args)
    5244              :     {
    5245              :       /* The first positional argument is required.  It may be worth
    5246              :          dropping the requirement at some point and having read_only
    5247              :          apply to all const-qualified pointers and read_write or
    5248              :          write_only to the rest.  */
    5249            4 :       error ("attribute %<%E(%s)%> missing an argument",
    5250              :              name, access_str);
    5251            4 :       return NULL_TREE;
    5252              :     }
    5253              : 
    5254              :   /* One or more positional arguments have been specified.  Validate
    5255              :      them.  */
    5256       755401 :   tree idxnodes[2] = { NULL_TREE, NULL_TREE };
    5257       755401 :   tree argtypes[2] = { NULL_TREE, NULL_TREE };
    5258              :   /* 1-based attribute positional arguments or zero if not specified.
    5259              :      Invalid negative or excessive values are also stored but used
    5260              :      only in diagnostics.  */
    5261       755401 :   HOST_WIDE_INT idxs[2] = { 0, 0 };
    5262              : 
    5263              :   /* Number of function formal arguments (used in diagnostics).  */
    5264       755401 :   unsigned nfuncargs = 0;
    5265              :   /* Number of (optional) attribute positional arguments.  */
    5266       755401 :   unsigned nattrargs = 0;
    5267              : 
    5268      2122672 :   for (unsigned i = 0; i != 2; ++i, args = TREE_CHAIN (args), ++nattrargs)
    5269              :     {
    5270      1510802 :       if (!args)
    5271              :         break;
    5272              : 
    5273      1367271 :       idxnodes[i] = TREE_VALUE (args);
    5274              : 
    5275      1367271 :       if (TREE_CODE (idxnodes[i]) != IDENTIFIER_NODE
    5276      1367271 :           && TREE_CODE (idxnodes[i]) != FUNCTION_DECL)
    5277      1367271 :         idxnodes[i] = default_conversion (idxnodes[i]);
    5278              : 
    5279      1367271 :       if (tree_fits_shwi_p (idxnodes[i]))
    5280              :         {
    5281      1367265 :           idxs[i] = tree_to_shwi (idxnodes[i]);
    5282      1367265 :           argtypes[i] = get_argument_type (type, idxs[i], &nfuncargs);
    5283              :         }
    5284              :     }
    5285              : 
    5286       755401 :   if ((nattrargs == 1 && !idxs[0])
    5287       755398 :       || (nattrargs == 2 && (!idxs[0] || !idxs[1])))
    5288              :     {
    5289            6 :       if (idxnodes[1])
    5290            3 :         error ("attribute %<%E(%s, %E, %E)%> invalid positional argument %i",
    5291            3 :                name, access_str, idxnodes[0], idxnodes[1], idxs[0] ? 2 : 1);
    5292              :       else
    5293            3 :         error ("attribute %<%E(%s, %E)%> invalid positional argument %i",
    5294            3 :                name, access_str, idxnodes[0], idxs[0] ? 2 : 1);
    5295              :       return NULL_TREE;
    5296              :     }
    5297              : 
    5298              :   /* Format the attribute specification to include in diagnostics.  */
    5299       755395 :   char attrstr[80];
    5300       755395 :   if (idxnodes[1])
    5301      1223734 :     snprintf (attrstr, sizeof attrstr, "%s(%s, %lli, %lli)",
    5302       611867 :               IDENTIFIER_POINTER (name), access_str,
    5303       611867 :               (long long) idxs[0], (long long) idxs[1]);
    5304       143528 :   else if (idxnodes[0])
    5305       287056 :     snprintf (attrstr, sizeof attrstr, "%s(%s, %lli)",
    5306       143528 :               IDENTIFIER_POINTER (name), access_str,
    5307       143528 :               (long long) idxs[0]);
    5308              :   else
    5309            0 :     snprintf (attrstr, sizeof attrstr, "%s(%s)",
    5310            0 :               IDENTIFIER_POINTER (name), access_str);
    5311              : 
    5312              :   /* Verify the positional argument values are in range.  */
    5313       755395 :   if (!argtypes[0] || (idxnodes[1] && !argtypes[1]))
    5314              :     {
    5315            9 :       if (idxnodes[0])
    5316              :         {
    5317            9 :           if (idxs[0] < 0 || idxs[1] < 0)
    5318            9 :             error ("attribute %qs positional argument %i invalid value %wi",
    5319              :                    attrstr, idxs[0] < 0 ? 1 : 2,
    5320              :                    idxs[0] < 0 ? idxs[0] : idxs[1]);
    5321              :           else
    5322            3 :             error ("attribute %qs positional argument %i value %wi exceeds "
    5323              :                    "number of function arguments %u",
    5324              :                    attrstr, idxs[0] ? 1 : 2,
    5325              :                    idxs[0] ? idxs[0] : idxs[1],
    5326              :                    nfuncargs);
    5327              :         }
    5328              :       else
    5329            0 :         error ("attribute %qs invalid positional argument", attrstr);
    5330              : 
    5331              :       return NULL_TREE;
    5332              :     }
    5333              : 
    5334       755386 :   if (!POINTER_TYPE_P (argtypes[0]))
    5335              :     {
    5336              :       /* The first argument must have a pointer or reference type.  */
    5337            4 :       error ("attribute %qs positional argument 1 references "
    5338              :              "non-pointer argument type %qT",
    5339              :              attrstr, argtypes[0]);
    5340            4 :       return NULL_TREE;
    5341              :     }
    5342              : 
    5343       755382 :   {
    5344              :     /* Pointers to functions are not allowed.  */
    5345       755382 :     tree ptrtype = TREE_TYPE (argtypes[0]);
    5346       755382 :     if (FUNC_OR_METHOD_TYPE_P (ptrtype))
    5347              :       {
    5348            3 :         error ("attribute %qs positional argument 1 references "
    5349              :                "argument of function type %qT",
    5350              :                attrstr, ptrtype);
    5351            3 :         return NULL_TREE;
    5352              :       }
    5353              :   }
    5354              : 
    5355       755379 :   if (mode == access_read_write || mode == access_write_only)
    5356              :     {
    5357              :       /* Read_write and write_only modes must reference non-const
    5358              :          arguments.  */
    5359       504571 :       if (TYPE_READONLY (TREE_TYPE (argtypes[0])))
    5360              :         {
    5361            3 :           error ("attribute %qs positional argument 1 references "
    5362              :                  "%qs-qualified argument type %qT",
    5363              :                  attrstr, "const", argtypes[0]);
    5364            3 :           return NULL_TREE;
    5365              :         }
    5366              :     }
    5367       250808 :   else if (!TYPE_READONLY (TREE_TYPE (argtypes[0])))
    5368              :     {
    5369              :       /* A read_only mode should ideally reference const-qualified
    5370              :          arguments but it's not diagnosed error if one doesn't.
    5371              :          This makes it possible to annotate legacy, const-incorrect
    5372              :          APIs.  It might be worth a diagnostic along the lines of
    5373              :          -Wsuggest-const.  */
    5374       250808 :       ;
    5375              :     }
    5376              : 
    5377       755376 :   if (argtypes[1] && !INTEGRAL_TYPE_P (argtypes[1]))
    5378              :     {
    5379           12 :       error ("attribute %qs positional argument 2 references "
    5380              :              "non-integer argument type %qT",
    5381              :              attrstr, argtypes[1]);
    5382           12 :       return NULL_TREE;
    5383              :     }
    5384              : 
    5385              :   /* Verify that the new attribute doesn't conflict with any existing
    5386              :      attributes specified on previous declarations of the same type
    5387              :      and if not, concatenate the two.  */
    5388       755364 :   const char code = attr_access::mode_chars[mode];
    5389       755364 :   tree new_attrs = append_access_attr_idxs (node, attrs, attrstr, code, idxs);
    5390       755364 :   if (!new_attrs)
    5391              :     return NULL_TREE;
    5392              : 
    5393              :   /* Replace any existing access attribute specification with
    5394              :      the concatenation above.  */
    5395       755349 :   new_attrs = tree_cons (NULL_TREE, new_attrs, NULL_TREE);
    5396       755349 :   new_attrs = tree_cons (name, new_attrs, NULL_TREE);
    5397              : 
    5398       755349 :   if (node[1])
    5399              :     {
    5400              :       /* Repeat for the previously declared type.  */
    5401          240 :       attrs = TYPE_ATTRIBUTES (TREE_TYPE (node[1]));
    5402          240 :       new_attrs = append_access_attr_idxs (node, attrs, attrstr, code, idxs);
    5403          240 :       if (!new_attrs)
    5404              :         return NULL_TREE;
    5405              : 
    5406           76 :       new_attrs = tree_cons (NULL_TREE, new_attrs, NULL_TREE);
    5407           76 :       new_attrs = tree_cons (name, new_attrs, NULL_TREE);
    5408              :     }
    5409              : 
    5410              :   /* Recursively call self to "replace" the documented/external form
    5411              :      of the attribute with the condensed internal form.  */
    5412       755185 :   decl_attributes (node, new_attrs, flags | ATTR_FLAG_INTERNAL);
    5413       755185 :   return NULL_TREE;
    5414              : }
    5415              : 
    5416              : 
    5417              : /* This function builds a string which is concatenated to SPEC and returns
    5418              :    list of variably bounds corresponding to an array/VLA parameter with
    5419              :    type TYPE.  The string consists of one dollar symbol for each specified
    5420              :    variable bound, one asterisk for each unspecified variable bound,
    5421              :    a space for an array of unknown size (only possibly for the outermost),
    5422              :    and a zero for a zero-sized array.
    5423              : 
    5424              :    The chainof variable bounds starts with the most significant bound.
    5425              :    For example, the TYPE T[2][m][3][n] will produce "$$" and (m, (n, nil)).  */
    5426              : 
    5427              : static tree
    5428       988569 : build_arg_spec (tree type, std::string *spec)
    5429              : {
    5430      1007636 :   while (POINTER_TYPE_P (type))
    5431        19067 :     type = TREE_TYPE (type);
    5432              : 
    5433       988569 :   if (TREE_CODE (type) != ARRAY_TYPE)
    5434              :     return NULL_TREE;
    5435              : 
    5436       503381 :   tree list = build_arg_spec (TREE_TYPE (type), spec);
    5437              : 
    5438       503381 :   if (!COMPLETE_TYPE_P (type))
    5439              :     {
    5440        65969 :       (*spec) += ' ';
    5441        65969 :       return list;
    5442              :     }
    5443              : 
    5444       437412 :   tree mval = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
    5445              : 
    5446       437412 :   if (!mval)
    5447              :     {
    5448           56 :      (*spec) += '0';
    5449           56 :      return list;
    5450              :     }
    5451              : 
    5452       437356 :   if (TREE_CODE (mval) == COMPOUND_EXPR
    5453          156 :       && integer_zerop (TREE_OPERAND (mval, 0))
    5454       437512 :       && integer_zerop (TREE_OPERAND (mval, 1)))
    5455              :     {
    5456          146 :       (*spec) += '*';
    5457          146 :       return list;
    5458              :     }
    5459              : 
    5460       437210 :   if (TREE_CODE (mval) == INTEGER_CST)
    5461              :     return list;
    5462              : 
    5463              :   /* A variable bound.  */
    5464        13977 :   (*spec) += '$';
    5465              : 
    5466        13977 :   mval = array_type_nelts_top (type);
    5467              : 
    5468              :   /* Remove NOP_EXPR and SAVE_EXPR to uncover possible PARM_DECLS.  */
    5469        13977 :   if (TREE_CODE (mval) == NOP_EXPR)
    5470        13967 :     mval = TREE_OPERAND (mval, 0);
    5471        13977 :    if (TREE_CODE (mval) == SAVE_EXPR)
    5472              :     {
    5473        13942 :       mval = TREE_OPERAND (mval, 0);
    5474        13942 :       if (TREE_CODE (mval) == NOP_EXPR)
    5475            0 :         mval = TREE_OPERAND (mval, 0);
    5476              :     }
    5477              : 
    5478        13977 :   return tree_cons (NULL_TREE, mval, list);
    5479              : }
    5480              : 
    5481              : /* Extract attribute "arg spec" from each FNDECL argument that has it,
    5482              :    build a single attribute access corresponding to all the arguments,
    5483              :    and return the result.  SKIP_VOIDPTR set to ignore void* parameters
    5484              :    (used for user-defined functions for which, unlike in for built-ins,
    5485              :    void* cannot be relied on to determine anything about the access
    5486              :    through it or whether it even takes place).
    5487              : 
    5488              :    For example, the parameters in the declaration:
    5489              : 
    5490              :      void f (int x, int y, char [x][1][y][3], char [y][2][y][5]);
    5491              : 
    5492              :    result in the following attribute access:
    5493              : 
    5494              :      value: "+^2[*],$0$1^3[*],$1$1"
    5495              :      list:  < <0, x> <1, y> >
    5496              : 
    5497              :    where the list has a single value which itself is a list, each
    5498              :    of whose <node>s corresponds to one VLA bound for each of the two
    5499              :    parameters.  */
    5500              : 
    5501              : tree
    5502     53803201 : build_attr_access_from_parms (tree parms, bool skip_voidptr)
    5503              : {
    5504              :   /* Maps each named integral argument DECL seen so far to its position
    5505              :      in the argument list; used to associate VLA sizes with arguments.  */
    5506     53803201 :   hash_map<tree, unsigned> arg2pos;
    5507              : 
    5508              :   /* The string representation of the access specification for all
    5509              :      arguments.  */
    5510     53803201 :   std::string spec;
    5511     53803201 :   unsigned argpos = 0;
    5512              : 
    5513              :   /* A TREE_LIST of VLA bounds.  */
    5514     53803201 :   tree vblist = NULL_TREE;
    5515              : 
    5516    184203074 :   for (tree arg = parms; arg; arg = TREE_CHAIN (arg), ++argpos)
    5517              :     {
    5518    130399873 :       if (!DECL_P (arg))
    5519        34274 :         continue;
    5520              : 
    5521    130365599 :       tree argtype = TREE_TYPE (arg);
    5522    130365599 :       if (DECL_NAME (arg) && INTEGRAL_TYPE_P (argtype))
    5523     38773449 :         arg2pos.put (arg, argpos);
    5524              :     }
    5525              : 
    5526     53803201 :   tree nnlist = NULL_TREE;
    5527     53803201 :   argpos = 0;
    5528    184203074 :   for (tree arg = parms; arg; arg = TREE_CHAIN (arg), ++argpos)
    5529              :     {
    5530    130399873 :       if (!DECL_P (arg))
    5531        34274 :         continue;
    5532              : 
    5533    130365599 :       tree argtype = TREE_TYPE (arg);
    5534              : 
    5535    130365599 :       tree argspec = DECL_ATTRIBUTES (arg);
    5536    130365599 :       if (!argspec)
    5537    129861117 :         continue;
    5538              : 
    5539       504482 :       if (POINTER_TYPE_P (argtype))
    5540              :         {
    5541              :           /* void* arguments in user-defined functions could point to
    5542              :              anything; skip them.  */
    5543       487206 :           tree reftype = TREE_TYPE (argtype);
    5544       487206 :           if (skip_voidptr && VOID_TYPE_P (reftype))
    5545            8 :             continue;
    5546              :         }
    5547              : 
    5548              :       /* Each parameter should have at most one "arg spec" attribute.  */
    5549       504474 :       argspec = lookup_attribute ("arg spec", argspec);
    5550       504474 :       if (!argspec)
    5551        19286 :         continue;
    5552              : 
    5553              :       /* Attribute arg spec should have one or two arguments.  */
    5554       485188 :       argspec = TREE_VALUE (argspec);
    5555              : 
    5556              :       /* The attribute arg spec string.  */
    5557       485188 :       const char *s = TREE_STRING_POINTER (TREE_VALUE (argspec));
    5558       485188 :       bool static_p = s && (0 == strcmp("static", s));
    5559              : 
    5560              :       /* Collect the list of nonnull arguments which use "[static ..]".  */
    5561          138 :       if (static_p)
    5562          138 :         nnlist = tree_cons (NULL_TREE, build_int_cst (integer_type_node,
    5563          138 :                                                       argpos + 1), nnlist);
    5564              : 
    5565       485188 :       tree argvbs;
    5566              :       /* Create the attribute access string from the arg spec data,
    5567              :          optionally followed by position of the VLA bound argument if
    5568              :          it is one.  */
    5569       485188 :       {
    5570       485188 :         size_t specend = spec.length ();
    5571       485188 :         if (!specend)
    5572              :           {
    5573       448208 :             spec = '+';
    5574       448208 :             specend = 1;
    5575              :           }
    5576              : 
    5577       485188 :         spec += attr_access::mode_chars[access_deferred];
    5578       970376 :         spec += std::to_string (argpos);
    5579       485188 :         spec += '[';
    5580       485188 :         tree type = TREE_VALUE (TREE_CHAIN (argspec));
    5581       485188 :         argvbs = build_arg_spec (type, &spec);
    5582              : 
    5583              :         /* Postprocess the string to bring it in the format expected
    5584              :            by the code handling the access attribute.  First, we
    5585              :            add 's' if the array was declared as [static ...].  */
    5586       485188 :         if (static_p)
    5587              :           {
    5588          138 :             size_t send = spec.length();
    5589              : 
    5590          138 :             if (spec[send - 1] == '[')
    5591              :               {
    5592          111 :                 spec += 's';
    5593              :               }
    5594              :             else
    5595              :               {
    5596              :                 /* If there is a symbol, we need to swap the order.  */
    5597           27 :                 spec += spec[send - 1];
    5598           27 :                 spec[send - 1] = 's';
    5599              :               }
    5600              :           }
    5601              : 
    5602              :         /* If the outermost bound is an integer constant, we need to write
    5603              :            the size  if it is constant.  */
    5604       970376 :         if (type && TYPE_DOMAIN (type))
    5605              :           {
    5606       419219 :             tree mval = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
    5607       419219 :             if (mval && TREE_CODE (mval) == INTEGER_CST)
    5608              :               {
    5609       417853 :                 char buf[40];
    5610       417853 :                 unsigned HOST_WIDE_INT n = tree_to_uhwi (mval) + 1;
    5611       417853 :                 sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, n);
    5612       417853 :                 spec += buf;
    5613              :               }
    5614              :           }
    5615       485188 :         spec += ']';
    5616              : 
    5617              :         /* Trim the trailing NUL.  */
    5618       485188 :         spec.resize (spec.length ());
    5619              :       }
    5620              : 
    5621              :       /* The (optional) list of expressions denoting the VLA bounds
    5622              :          N in ARGTYPE <arg>[Ni]...[Nj]...[Nk].  */
    5623       485188 :       if (argvbs)
    5624              :         {
    5625         1485 :           spec += ',';
    5626              :           /* Add ARGVBS to the list.  Their presence is indicated by
    5627              :              appending a comma followed by the dollar sign and, when
    5628              :              it corresponds to a function parameter, the position of
    5629              :              each bound Ni, so it can be distinguished from
    5630              :              an unspecified bound (as in T[*]).  The list is in reverse
    5631              :              order of arguments and needs to be reversed to access in
    5632              :              order.  */
    5633         1485 :           vblist = tree_cons (NULL_TREE, argvbs, vblist);
    5634              : 
    5635        16947 :           for (tree vb = argvbs; vb; vb = TREE_CHAIN (vb))
    5636              :             {
    5637        13977 :               tree bound = TREE_VALUE (vb);
    5638        13977 :               if (const unsigned *psizpos = arg2pos.get (bound))
    5639              :                 {
    5640              :                   /* BOUND previously seen in the parameter list.  */
    5641          413 :                   TREE_PURPOSE (vb) = size_int (*psizpos);
    5642              :                   /* Format the position string in place.  */
    5643          413 :                   int len = snprintf (NULL, 0, "$%u", *psizpos);
    5644          413 :                   size_t specend = spec.length ();
    5645          413 :                   spec.resize (specend + len + 1);
    5646          413 :                   sprintf (&spec[specend], "$%u", *psizpos);
    5647              :                   /* Trim the trailing NUL.  */
    5648          413 :                   spec.resize (specend + len);
    5649              :                 }
    5650              :               else
    5651              :                 {
    5652              :                   /* BOUND doesn't name a parameter (it could be a global
    5653              :                      variable or an expression such as a function call).  */
    5654        13564 :                   spec += '$';
    5655              :                 }
    5656              :             }
    5657              :         }
    5658              :     }
    5659              : 
    5660     53803201 :   if (!spec.length ())
    5661              :     return NULL_TREE;
    5662              : 
    5663              :   /* If we have nonnull arguments, synthesize an attribute.  */
    5664       448208 :   if (nnlist != NULL_TREE)
    5665          130 :     nnlist = build_tree_list (get_identifier ("nonnull"), nnlist);
    5666              : 
    5667              :   /* Attribute access takes a two or three arguments.  Wrap VBLIST in
    5668              :      another list in case it has more nodes than would otherwise fit.  */
    5669       448208 :   vblist = build_tree_list (NULL_TREE, vblist);
    5670              : 
    5671              :   /* Build a single attribute access with the string describing all
    5672              :      array arguments and an optional list of any non-parameter VLA
    5673              :      bounds in order.  */
    5674       448208 :   tree str = build_string (spec.length (), spec.c_str ());
    5675       448208 :   tree attrargs = tree_cons (NULL_TREE, str, vblist);
    5676       448208 :   tree name = get_identifier ("access");
    5677       448208 :   return tree_cons (name, attrargs, nnlist);
    5678     53803201 : }
    5679              : 
    5680              : 
    5681              : /* Handle a "nothrow" attribute; arguments as in
    5682              :    struct attribute_spec.handler.  */
    5683              : 
    5684              : static tree
    5685           14 : handle_expected_throw_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    5686              :                                  int ARG_UNUSED (flags), bool *no_add_attrs)
    5687              : {
    5688           14 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    5689              :     /* No flag to set here.  */;
    5690              :   /* ??? TODO: Support types.  */
    5691              :   else
    5692              :     {
    5693            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5694            0 :       *no_add_attrs = true;
    5695              :     }
    5696              : 
    5697           14 :   return NULL_TREE;
    5698              : }
    5699              : 
    5700              : /* Handle a "cleanup" attribute; arguments as in
    5701              :    struct attribute_spec.handler.  */
    5702              : 
    5703              : static tree
    5704          338 : handle_cleanup_attribute (tree *node, tree name, tree args,
    5705              :                           int ARG_UNUSED (flags), bool *no_add_attrs)
    5706              : {
    5707          338 :   tree decl = *node;
    5708          338 :   tree cleanup_id, cleanup_decl;
    5709              : 
    5710              :   /* ??? Could perhaps support cleanups on TREE_STATIC, much like we do
    5711              :      for global destructors in C++.  This requires infrastructure that
    5712              :      we don't have generically at the moment.  It's also not a feature
    5713              :      we'd be missing too much, since we do have attribute constructor.  */
    5714          338 :   if (!VAR_P (decl) || TREE_STATIC (decl))
    5715              :     {
    5716           12 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5717           12 :       *no_add_attrs = true;
    5718           12 :       return NULL_TREE;
    5719              :     }
    5720              : 
    5721              :   /* Verify that the argument is a function in scope.  */
    5722              :   /* ??? We could support pointers to functions here as well, if
    5723              :      that was considered desirable.  */
    5724          326 :   cleanup_id = TREE_VALUE (args);
    5725          326 :   if (TREE_CODE (cleanup_id) != IDENTIFIER_NODE)
    5726              :     {
    5727            4 :       error ("cleanup argument not an identifier");
    5728            4 :       *no_add_attrs = true;
    5729            4 :       return NULL_TREE;
    5730              :     }
    5731          322 :   cleanup_decl = lookup_name (cleanup_id);
    5732          322 :   if (!cleanup_decl || TREE_CODE (cleanup_decl) != FUNCTION_DECL)
    5733              :     {
    5734            8 :       error ("cleanup argument not a function");
    5735            8 :       *no_add_attrs = true;
    5736            8 :       return NULL_TREE;
    5737              :     }
    5738              : 
    5739              :   /* That the function has proper type is checked with the
    5740              :      eventual call to build_function_call.  */
    5741              : 
    5742              :   return NULL_TREE;
    5743              : }
    5744              : 
    5745              : /* Handle a "warn_unused_result" attribute.  No special handling.  */
    5746              : 
    5747              : static tree
    5748      2955240 : handle_warn_unused_result_attribute (tree *node, tree name,
    5749              :                                tree ARG_UNUSED (args),
    5750              :                                int ARG_UNUSED (flags), bool *no_add_attrs)
    5751              : {
    5752              :   /* Ignore the attribute for functions not returning any value.  */
    5753      2955240 :   if (VOID_TYPE_P (TREE_TYPE (*node)))
    5754              :     {
    5755            9 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5756            9 :       *no_add_attrs = true;
    5757              :     }
    5758              : 
    5759      2955240 :   return NULL_TREE;
    5760              : }
    5761              : 
    5762              : /* Handle a "sentinel" attribute.  */
    5763              : 
    5764              : static tree
    5765      1127333 : handle_sentinel_attribute (tree *node, tree name, tree args,
    5766              :                            int ARG_UNUSED (flags), bool *no_add_attrs)
    5767              : {
    5768      1127333 :   if (!prototype_p (*node))
    5769              :     {
    5770            2 :       warning (OPT_Wattributes,
    5771              :                "%qE attribute requires prototypes with named arguments", name);
    5772            2 :       *no_add_attrs = true;
    5773              :     }
    5774              :   else
    5775              :     {
    5776      1127331 :       if (!stdarg_p (*node))
    5777              :         {
    5778            2 :           warning (OPT_Wattributes,
    5779              :                    "%qE attribute only applies to variadic functions", name);
    5780            2 :           *no_add_attrs = true;
    5781              :         }
    5782              :     }
    5783              : 
    5784      1127333 :   if (args)
    5785              :     {
    5786       375766 :       tree position = TREE_VALUE (args);
    5787       375766 :       if (position && TREE_CODE (position) != IDENTIFIER_NODE
    5788       375766 :           && TREE_CODE (position) != FUNCTION_DECL)
    5789       375762 :         position = default_conversion (position);
    5790              : 
    5791       375766 :       if (TREE_CODE (position) != INTEGER_CST
    5792       375766 :           || !INTEGRAL_TYPE_P (TREE_TYPE (position)))
    5793              :         {
    5794            6 :           warning (OPT_Wattributes,
    5795              :                    "requested position is not an integer constant");
    5796            6 :           *no_add_attrs = true;
    5797              :         }
    5798              :       else
    5799              :         {
    5800       375760 :           if (tree_int_cst_lt (position, integer_zero_node))
    5801              :             {
    5802            2 :               warning (OPT_Wattributes,
    5803              :                        "requested position is less than zero");
    5804            2 :               *no_add_attrs = true;
    5805              :             }
    5806              :         }
    5807              :     }
    5808              : 
    5809      1127333 :   return NULL_TREE;
    5810              : }
    5811              : 
    5812              : /* Handle a "target_version" attribute.  */
    5813              : 
    5814              : static tree
    5815            0 : handle_target_version_attribute (tree *node, tree name, tree args, int flags,
    5816              :                                   bool *no_add_attrs)
    5817              : {
    5818              :   /* Ensure we have a function declaration.  */
    5819            0 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    5820              :     {
    5821            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5822            0 :       *no_add_attrs = true;
    5823              :     }
    5824            0 :   else if (!targetm.target_option.valid_version_attribute_p (*node, name, args,
    5825              :                                                              flags))
    5826            0 :     *no_add_attrs = true;
    5827              : 
    5828            0 :   return NULL_TREE;
    5829              : }
    5830              : 
    5831              : /* Handle a "target_clones" attribute.  */
    5832              : 
    5833              : static tree
    5834          126 : handle_target_clones_attribute (tree *node, tree name, tree ARG_UNUSED (args),
    5835              :                           int ARG_UNUSED (flags), bool *no_add_attrs)
    5836              : {
    5837              :   /* Ensure we have a function declaration.  */
    5838          126 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    5839              :     {
    5840          451 :       for (tree t = args; t != NULL_TREE; t = TREE_CHAIN (t))
    5841              :         {
    5842          327 :           tree value = TREE_VALUE (t);
    5843          327 :           if (TREE_CODE (value) != STRING_CST)
    5844              :             {
    5845            2 :               error ("%qE attribute argument not a string constant", name);
    5846            2 :               *no_add_attrs = true;
    5847            2 :               return NULL_TREE;
    5848              :             }
    5849              :         }
    5850              : 
    5851          124 :       int num_defaults = 0;
    5852          124 :       auto_vec<string_slice> versions = get_clone_attr_versions
    5853              :                                           (args,
    5854              :                                            &num_defaults,
    5855          124 :                                            false);
    5856              : 
    5857          710 :       for (auto v : versions)
    5858          338 :         targetm.check_target_clone_version
    5859          338 :           (v, &DECL_SOURCE_LOCATION (*node));
    5860              : 
    5861              :       /* Lone target_clones version is always ignored for target attr semantics.
    5862              :          Only ignore under target_version semantics if it is a default
    5863              :          version.  */
    5864          125 :       if (versions.length () == 1
    5865              :           && (TARGET_HAS_FMV_TARGET_ATTRIBUTE || num_defaults == 1))
    5866              :         {
    5867            1 :           if (TARGET_HAS_FMV_TARGET_ATTRIBUTE)
    5868            1 :             warning (OPT_Wattributes,
    5869              :                      "single %<target_clones%> attribute is ignored");
    5870            1 :           *no_add_attrs = true;
    5871              :         }
    5872          124 :     }
    5873              :   else
    5874              :     {
    5875            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5876            0 :       *no_add_attrs = true;
    5877              :     }
    5878              :   return NULL_TREE;
    5879              : }
    5880              : 
    5881              : /* For handling "optimize" attribute. arguments as in
    5882              :    struct attribute_spec.handler.  */
    5883              : 
    5884              : static tree
    5885       347042 : handle_optimize_attribute (tree *node, tree name, tree args,
    5886              :                            int ARG_UNUSED (flags), bool *no_add_attrs)
    5887              : {
    5888              :   /* Ensure we have a function type.  */
    5889       347042 :   if (TREE_CODE (*node) != FUNCTION_DECL)
    5890              :     {
    5891            0 :       warning (OPT_Wattributes, "%qE attribute ignored", name);
    5892            0 :       *no_add_attrs = true;
    5893              :     }
    5894              :   else
    5895              :     {
    5896       347042 :       struct cl_optimization cur_opts;
    5897       347042 :       struct cl_target_option cur_target;
    5898       347042 :       tree old_opts = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node);
    5899       347042 :       tree old_target = DECL_FUNCTION_SPECIFIC_TARGET (*node);
    5900              : 
    5901              :       /* Save current options.  */
    5902       347042 :       cl_optimization_save (&cur_opts, &global_options, &global_options_set);
    5903       347042 :       cl_target_option_save (&cur_target, &global_options, &global_options_set);
    5904              : 
    5905       347042 :       tree prev_target_node
    5906              :         = old_target
    5907       347042 :             ? old_target
    5908       328319 :             : build_target_option_node (&global_options, &global_options_set);
    5909              : 
    5910              :       /* If we previously had some optimization options, use them as the
    5911              :          default.  */
    5912       347042 :       gcc_options *saved_global_options = NULL;
    5913              : 
    5914              :       /* When #pragma GCC optimize pragma is used, it modifies global_options
    5915              :          without calling targetm.override_options_after_change.  That can leave
    5916              :          target flags inconsistent for comparison.  */
    5917       347042 :       if (flag_checking && optimization_current_node == optimization_default_node)
    5918              :         {
    5919       290164 :           saved_global_options = XNEW (gcc_options);
    5920       290164 :           *saved_global_options = global_options;
    5921              :         }
    5922              : 
    5923       347042 :       if (old_opts)
    5924        65796 :         cl_optimization_restore (&global_options, &global_options_set,
    5925        65796 :                                  TREE_OPTIMIZATION (old_opts));
    5926              : 
    5927       347042 :       if (old_target)
    5928        18723 :         cl_target_option_restore (&global_options, &global_options_set,
    5929        18723 :                                   TREE_TARGET_OPTION (old_target));
    5930              : 
    5931              :       /* Parse options, and update the vector.  */
    5932       347042 :       parse_optimize_options (args, true);
    5933       347042 :       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)
    5934       347042 :         = build_optimization_node (&global_options, &global_options_set);
    5935       347042 :       tree target_node = build_target_option_node (&global_options,
    5936              :                                                    &global_options_set);
    5937       347042 :       if (prev_target_node != target_node)
    5938            0 :         DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
    5939              : 
    5940              :       /* Also update the cgraph_node, if it's already built.  */
    5941       347042 :       if (cgraph_node *cn = cgraph_node::get (*node))
    5942           12 :         cn->semantic_interposition = flag_semantic_interposition;
    5943              : 
    5944              :       /* Restore current options.  */
    5945       347042 :       cl_optimization_restore (&global_options, &global_options_set,
    5946              :                                &cur_opts);
    5947       347042 :       cl_target_option_restore (&global_options, &global_options_set,
    5948              :                                 &cur_target);
    5949              : 
    5950       347042 :       if (saved_global_options != NULL)
    5951              :         {
    5952       290164 :           if (!seen_error ())
    5953       290157 :             cl_optimization_compare (saved_global_options, &global_options);
    5954       290164 :           free (saved_global_options);
    5955              :         }
    5956              :     }
    5957              : 
    5958       347042 :   return NULL_TREE;
    5959              : }
    5960              : 
    5961              : /* Handle a "no_split_stack" attribute.  */
    5962              : 
    5963              : static tree
    5964          488 : handle_no_split_stack_attribute (tree *node, tree name,
    5965              :                                  tree ARG_UNUSED (args),
    5966              :                                  int ARG_UNUSED (flags),
    5967              :                                  bool *no_add_attrs)
    5968              : {
    5969          488 :   tree decl = *node;
    5970              : 
    5971          488 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    5972              :     {
    5973            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    5974              :                 "%qE attribute applies only to functions", name);
    5975            0 :       *no_add_attrs = true;
    5976              :     }
    5977          488 :   else if (DECL_INITIAL (decl))
    5978              :     {
    5979            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    5980              :                 "cannot set %qE attribute after definition", name);
    5981            0 :       *no_add_attrs = true;
    5982              :     }
    5983              : 
    5984          488 :   return NULL_TREE;
    5985              : }
    5986              : 
    5987              : /* Handle a "zero_call_used_regs" attribute; arguments as in
    5988              :    struct attribute_spec.handler.  */
    5989              : 
    5990              : static tree
    5991          100 : handle_zero_call_used_regs_attribute (tree *node, tree name, tree args,
    5992              :                                       int ARG_UNUSED (flags),
    5993              :                                       bool *no_add_attrs)
    5994              : {
    5995          100 :   tree decl = *node;
    5996          100 :   tree id = TREE_VALUE (args);
    5997              : 
    5998          100 :   if (TREE_CODE (decl) != FUNCTION_DECL)
    5999              :     {
    6000            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    6001              :                 "%qE attribute applies only to functions", name);
    6002            4 :       *no_add_attrs = true;
    6003            4 :       return NULL_TREE;
    6004              :     }
    6005              : 
    6006           96 :   if (TREE_CODE (id) != STRING_CST)
    6007              :     {
    6008            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    6009              :                 "%qE argument not a string", name);
    6010            4 :       *no_add_attrs = true;
    6011            4 :       return NULL_TREE;
    6012              :     }
    6013              : 
    6014          552 :   bool found = false;
    6015          552 :   for (unsigned int i = 0; zero_call_used_regs_opts[i].name != NULL; ++i)
    6016          548 :     if (strcmp (TREE_STRING_POINTER (id),
    6017          548 :                 zero_call_used_regs_opts[i].name) == 0)
    6018              :       {
    6019              :         found = true;
    6020              :         break;
    6021              :       }
    6022              : 
    6023           92 :   if (!found)
    6024              :     {
    6025            4 :       error_at (DECL_SOURCE_LOCATION (decl),
    6026              :                 "unrecognized %qE attribute argument %qs",
    6027            4 :                 name, TREE_STRING_POINTER (id));
    6028            4 :       *no_add_attrs = true;
    6029              :     }
    6030              : 
    6031              :   return NULL_TREE;
    6032              : }
    6033              : 
    6034              : /* Handle a "returns_nonnull" attribute; arguments as in
    6035              :    struct attribute_spec.handler.  */
    6036              : 
    6037              : static tree
    6038      1256286 : handle_returns_nonnull_attribute (tree *node, tree name, tree, int,
    6039              :                                   bool *no_add_attrs)
    6040              : {
    6041              :   // Even without a prototype we still have a return type we can check.
    6042      1256286 :   if (TREE_CODE (TREE_TYPE (*node)) != POINTER_TYPE)
    6043              :     {
    6044            4 :       error ("%qE attribute on a function not returning a pointer", name);
    6045            4 :       *no_add_attrs = true;
    6046              :     }
    6047      1256286 :   return NULL_TREE;
    6048              : }
    6049              : 
    6050              : /* Handle a "designated_init" attribute; arguments as in
    6051              :    struct attribute_spec.handler.  */
    6052              : 
    6053              : static tree
    6054           19 : handle_designated_init_attribute (tree *node, tree name, tree, int,
    6055              :                                   bool *no_add_attrs)
    6056              : {
    6057           19 :   if (TREE_CODE (*node) != RECORD_TYPE)
    6058              :     {
    6059            3 :       error ("%qE attribute is only valid on %<struct%> type", name);
    6060            3 :       *no_add_attrs = true;
    6061              :     }
    6062           19 :   return NULL_TREE;
    6063              : }
    6064              : 
    6065              : 
    6066              : /* Handle a "fallthrough" attribute; arguments as in struct
    6067              :    attribute_spec.handler.  */
    6068              : 
    6069              : tree
    6070          193 : handle_fallthrough_attribute (tree *, tree name, tree, int,
    6071              :                               bool *no_add_attrs)
    6072              : {
    6073          193 :   pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", name);
    6074          193 :   *no_add_attrs = true;
    6075          193 :   return NULL_TREE;
    6076              : }
    6077              : 
    6078              : /* Handle a "assume" attribute; arguments as in struct
    6079              :    attribute_spec.handler.  */
    6080              : 
    6081              : tree
    6082          203 : handle_assume_attribute (tree *, tree name, tree, int,
    6083              :                          bool *no_add_attrs)
    6084              : {
    6085          203 :   pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", name);
    6086          203 :   *no_add_attrs = true;
    6087          203 :   return NULL_TREE;
    6088              : }
    6089              : 
    6090              : /* Handle a "patchable_function_entry" attributes; arguments as in
    6091              :    struct attribute_spec.handler.  */
    6092              : 
    6093              : static tree
    6094           56 : handle_patchable_function_entry_attribute (tree *, tree name, tree args,
    6095              :                                            int, bool *no_add_attrs)
    6096              : {
    6097          108 :   for (; args; args = TREE_CHAIN (args))
    6098              :     {
    6099           80 :       tree val = TREE_VALUE (args);
    6100           80 :       if (val && TREE_CODE (val) != IDENTIFIER_NODE
    6101           80 :           && TREE_CODE (val) != FUNCTION_DECL)
    6102           80 :         val = default_conversion (val);
    6103              : 
    6104           80 :       if (!tree_fits_uhwi_p (val))
    6105              :         {
    6106           16 :           warning (OPT_Wattributes,
    6107              :                    "%qE attribute argument %qE is not an integer constant",
    6108              :                    name, val);
    6109           16 :           *no_add_attrs = true;
    6110           16 :           return NULL_TREE;
    6111              :         }
    6112              : 
    6113           64 :       if (tree_to_uhwi (val) > USHRT_MAX)
    6114              :         {
    6115           12 :           warning (OPT_Wattributes,
    6116              :                    "%qE attribute argument %qE exceeds %u",
    6117              :                    name, val, USHRT_MAX);
    6118           12 :           *no_add_attrs = true;
    6119           12 :           return NULL_TREE;
    6120              :         }
    6121              :     }
    6122              :   return NULL_TREE;
    6123              : }
    6124              : 
    6125              : /* Handle a "NSObject" attributes; arguments as in
    6126              :    struct attribute_spec.handler.  */
    6127              : 
    6128              : static tree
    6129            0 : handle_nsobject_attribute (tree *node, tree name, tree args,
    6130              :                            int /*flags*/, bool *no_add_attrs)
    6131              : {
    6132            0 :   *no_add_attrs = true;
    6133              : 
    6134              :   /* This attribute only applies to typedefs (or field decls for properties),
    6135              :      we drop it otherwise - but warn about this if enabled.  */
    6136            0 :   if (TREE_CODE (*node) != TYPE_DECL && TREE_CODE (*node) != FIELD_DECL)
    6137              :     {
    6138            0 :       warning (OPT_WNSObject_attribute, "%qE attribute may be put on a"
    6139              :                " typedef only; attribute is ignored", name);
    6140            0 :       return NULL_TREE;
    6141              :     }
    6142              : 
    6143              :   /* The original implementation only allowed pointers to records, however
    6144              :      recent implementations also allow void *.  */
    6145            0 :   tree type = TREE_TYPE (*node);
    6146            0 :   if (!type || !POINTER_TYPE_P (type)
    6147            0 :       || (TREE_CODE (TREE_TYPE (type)) != RECORD_TYPE
    6148            0 :           && !VOID_TYPE_P (TREE_TYPE (type))))
    6149              :     {
    6150            0 :       error ("%qE attribute is for pointer types only", name);
    6151            0 :       return NULL_TREE;
    6152              :     }
    6153              : 
    6154            0 :   tree t = tree_cons (name, args, TYPE_ATTRIBUTES (type));
    6155            0 :   TREE_TYPE (*node) = build_type_attribute_variant (type, t);
    6156              : 
    6157            0 :   return NULL_TREE;
    6158              : }
    6159              : 
    6160              : /* Handle a "objc_root_class" attributes; arguments as in
    6161              :    struct attribute_spec.handler.  */
    6162              : 
    6163              : static tree
    6164            0 : handle_objc_root_class_attribute (tree */*node*/, tree name, tree /*args*/,
    6165              :                                   int /*flags*/, bool *no_add_attrs)
    6166              : {
    6167              :   /* This has no meaning outside Objective-C.  */
    6168            0 :   if (!c_dialect_objc())
    6169            0 :     warning (OPT_Wattributes, "%qE is only applicable to Objective-C"
    6170              :              " class interfaces, attribute ignored", name);
    6171              : 
    6172            0 :   *no_add_attrs = true;
    6173            0 :   return NULL_TREE;
    6174              : }
    6175              : 
    6176              : /* Handle an "objc_nullability" attribute; arguments as in
    6177              :    struct attribute_spec.handler.  */
    6178              : 
    6179              : static tree
    6180            0 : handle_objc_nullability_attribute (tree *node, tree name, tree args,
    6181              :                                    int /*flags*/,
    6182              :                                    bool *no_add_attrs)
    6183              : {
    6184            0 :   *no_add_attrs = true;
    6185              : 
    6186            0 :   tree type = TREE_TYPE (*node);
    6187            0 :   if (TREE_CODE (*node) == FUNCTION_DECL)
    6188            0 :     type = TREE_TYPE (type);
    6189              : 
    6190            0 :   if (type && !POINTER_TYPE_P (type))
    6191              :     {
    6192            0 :       error ("%qE cannot be applied to non-pointer type %qT", name, type);
    6193            0 :       return NULL_TREE;
    6194              :     }
    6195              : 
    6196              :   /* We accept objc_nullability() with a single argument.
    6197              :      string: "unspecified", "nullable", "nonnull" or "resettable"
    6198              :      integer: 0 and 3 where the values have the same meaning as
    6199              :      the strings.  */
    6200            0 :   tree val = TREE_VALUE (args);
    6201            0 :   if (TREE_CODE (val) == INTEGER_CST)
    6202              :     {
    6203            0 :       val = default_conversion (val);
    6204            0 :       if (!tree_fits_uhwi_p (val) || tree_to_uhwi (val) > 3)
    6205            0 :         error ("%qE attribute argument %qE is not an integer constant"
    6206              :                " between 0 and 3", name, val);
    6207              :       else
    6208            0 :         *no_add_attrs = false; /* OK */
    6209              :     }
    6210            0 :   else if (TREE_CODE (val) == STRING_CST
    6211            0 :            && (strcmp (TREE_STRING_POINTER (val), "nullable") == 0
    6212            0 :               || strcmp (TREE_STRING_POINTER (val), "nonnull") == 0
    6213            0 :               || strcmp (TREE_STRING_POINTER (val), "unspecified") == 0
    6214            0 :               || strcmp (TREE_STRING_POINTER (val), "resettable") == 0))
    6215            0 :     *no_add_attrs = false; /* OK */
    6216            0 :   else if (val != error_mark_node)
    6217            0 :     error ("%qE attribute argument %qE is not recognized", name, val);
    6218              : 
    6219              :   return NULL_TREE;
    6220              : }
    6221              : 
    6222              : /* Handle a "tainted_args" attribute; arguments as in
    6223              :    struct attribute_spec.handler.  */
    6224              : 
    6225              : static tree
    6226          216 : handle_tainted_args_attribute (tree *node, tree name, tree, int,
    6227              :                                bool *no_add_attrs)
    6228              : {
    6229          216 :   if (TREE_CODE (*node) != FUNCTION_DECL
    6230           14 :       && TREE_CODE (*node) != FIELD_DECL)
    6231              :     {
    6232            4 :       warning (OPT_Wattributes, "%qE attribute ignored; valid only "
    6233              :                "for functions and function pointer fields",
    6234              :                name);
    6235            4 :       *no_add_attrs = true;
    6236            4 :       return NULL_TREE;
    6237              :     }
    6238              : 
    6239          212 :   if (TREE_CODE (*node) == FIELD_DECL
    6240          212 :       && !(TREE_CODE (TREE_TYPE (*node)) == POINTER_TYPE
    6241            6 :            && TREE_CODE (TREE_TYPE (TREE_TYPE (*node))) == FUNCTION_TYPE))
    6242              :     {
    6243            4 :       warning (OPT_Wattributes, "%qE attribute ignored;"
    6244              :                " field must be a function pointer",
    6245              :                name);
    6246            4 :       *no_add_attrs = true;
    6247            4 :       return NULL_TREE;
    6248              :     }
    6249              : 
    6250          208 :   *no_add_attrs = false; /* OK */
    6251              : 
    6252          208 :   return NULL_TREE;
    6253              : }
    6254              : 
    6255              : /* Attempt to partially validate a single attribute ATTR as if
    6256              :    it were to be applied to an entity OPER.  */
    6257              : 
    6258              : static bool
    6259         2834 : validate_attribute (location_t atloc, tree oper, tree attr)
    6260              : {
    6261              :   /* Determine whether the name of the attribute is valid
    6262              :      and fail with an error if not.  */
    6263         2834 :   tree atname = get_attribute_name (attr);
    6264         2834 :   if (!lookup_attribute_spec (atname))
    6265              :     {
    6266            8 :       if (atloc != UNKNOWN_LOCATION)
    6267            8 :         error_at (atloc, "unknown attribute %qE", atname);
    6268              :       return false;
    6269              :     }
    6270              : 
    6271         2826 :   tree args = TREE_VALUE (attr);
    6272         2826 :   if (!args)
    6273              :     return true;
    6274              : 
    6275              :   /* FIXME: Do some validation.  */
    6276         1639 :   const char *atstr = IDENTIFIER_POINTER (atname);
    6277         1639 :   if (!strcmp (atstr, "format"))
    6278              :     return true;
    6279              : 
    6280              :   /* Only when attribute arguments have been provided try to validate
    6281              :      the whole thing.  decl_attributes doesn't return an indication of
    6282              :      success or failure so proceed regardless.  */
    6283         1631 :   const char tmpname[] = "__builtin_has_attribute_tmp.";
    6284         1631 :   tree tmpid = get_identifier (tmpname);
    6285         1631 :   tree tmpdecl;
    6286         1631 :   if (!strcmp (atstr, "vector_size"))
    6287              :     {
    6288          176 :       tree type = TYPE_P (oper) ? oper : TREE_TYPE (oper);
    6289              :       /* Check for function type here since type_for_vector_size
    6290              :          strips it while looking for a function's return type.  */
    6291          176 :       if (FUNC_OR_METHOD_TYPE_P (type))
    6292              :         {
    6293            0 :           warning_at (atloc, OPT_Wattributes,
    6294              :                       "invalid operand type %qT for %qs", type, atstr);
    6295            0 :           return false;
    6296              :         }
    6297              : 
    6298          176 :       type = type_for_vector_size (type);
    6299          176 :       if (VECTOR_TYPE_P (type))
    6300          164 :         type = TREE_TYPE (type);
    6301              :       /* Avoid trying to apply attribute vector_size to OPER since
    6302              :          it's overly restrictive.  Simply make sure it has the right
    6303              :          type.  */
    6304          176 :       return type_valid_for_vector_size (type, atname, args, NULL);
    6305              :     }
    6306              : 
    6307         1455 :   if (TYPE_P (oper))
    6308          308 :     tmpdecl = build_decl (atloc, TYPE_DECL, tmpid, oper);
    6309         1147 :   else if (DECL_P (oper))
    6310          564 :     tmpdecl = build_decl (atloc, TREE_CODE (oper), tmpid, TREE_TYPE (oper));
    6311          583 :   else if (EXPR_P (oper))
    6312          583 :     tmpdecl = build_decl (atloc, TYPE_DECL, tmpid, TREE_TYPE (oper));
    6313              :   else
    6314              :     return false;
    6315              : 
    6316              :   /* Temporarily clear CURRENT_FUNCTION_DECL to make decl_attributes
    6317              :      believe the DECL declared above is at file scope.  (See bug 87526.)  */
    6318         1455 :   tree save_curfunc = current_function_decl;
    6319         1455 :   current_function_decl = NULL_TREE;
    6320         1455 :   if (DECL_P (tmpdecl))
    6321              :     {
    6322         1455 :       if (DECL_P (oper))
    6323              :         /* An alias cannot be a definition so declare the symbol extern.  */
    6324          564 :         DECL_EXTERNAL (tmpdecl) = true;
    6325              :       /* Attribute visibility only applies to symbols visible from other
    6326              :          translation units so make it "public."   */
    6327         1455 :       TREE_PUBLIC (tmpdecl) = TREE_PUBLIC (oper);
    6328              :     }
    6329         1455 :   decl_attributes (&tmpdecl, attr, 0);
    6330         1455 :   current_function_decl = save_curfunc;
    6331              : 
    6332              :   /* FIXME: Change decl_attributes to indicate success or failure (and
    6333              :      parameterize it to avoid failing with errors).  */
    6334         1455 :   return true;
    6335              : }
    6336              : 
    6337              : /* Return true if the DECL, EXPR, or TYPE t has been declared with
    6338              :    attribute ATTR.  For DECL, consider also its type.  For EXPR,
    6339              :    consider just its type.  */
    6340              : 
    6341              : bool
    6342         2835 : has_attribute (location_t atloc, tree t, tree attr, tree (*convert)(tree))
    6343              : {
    6344         2835 :   if (!attr || !t || t == error_mark_node)
    6345              :     return false;
    6346              : 
    6347         2834 :   if (!validate_attribute (atloc, t, attr))
    6348              :     return false;
    6349              : 
    6350         2774 :   tree type = NULL_TREE;
    6351         2774 :   tree expr = NULL_TREE;
    6352         2774 :   if (TYPE_P (t))
    6353              :     type = t;
    6354              :   else
    6355              :     {
    6356         2404 :       do
    6357              :         {
    6358              :           /* Determine the array element/member declaration from
    6359              :              a COMPONENT_REF and an INDIRECT_REF involving a refeence.  */
    6360         2404 :           STRIP_NOPS (t);
    6361         2404 :           tree_code code = TREE_CODE (t);
    6362         2404 :           if (code == INDIRECT_REF)
    6363              :             {
    6364          439 :               tree op0 = TREE_OPERAND (t, 0);
    6365          439 :               if (TREE_CODE (TREE_TYPE (op0)) == REFERENCE_TYPE)
    6366              :                 t = op0;
    6367              :               else
    6368              :                 break;
    6369              :             }
    6370         1965 :           else if (code == COMPONENT_REF)
    6371          160 :             t = TREE_OPERAND (t, 1);
    6372              :           else
    6373              :             break;
    6374              :         } while (true);
    6375              :       expr = t;
    6376              :     }
    6377              : 
    6378              :   /* Set to true when an attribute is found in the referenced entity
    6379              :      that matches the specified attribute.  */
    6380         2774 :   bool found_match = false;
    6381              : 
    6382         2774 :   tree atname = get_attribute_name (attr);
    6383         2774 :   const char *namestr = IDENTIFIER_POINTER (atname);
    6384              : 
    6385              :    /* Iterate once for a type and twice for a function or variable
    6386              :      declaration: once for the DECL and the second time for its
    6387              :      TYPE.  */
    6388         5475 :   for (bool done = false; !found_match && !done; )
    6389              :     {
    6390         3544 :       tree atlist;
    6391         3544 :       if (type)
    6392              :         {
    6393         1318 :           if (type == error_mark_node)
    6394              :             {
    6395              :               /* This could be a label.  FIXME: add support for labels.  */
    6396            0 :               warning_at (atloc, OPT_Wattributes,
    6397            0 :                           (TYPE_P (t)
    6398              :                            ? G_("%qs attribute not supported for %qT "
    6399              :                                 "in %<__builtin_has_attribute%>")
    6400              :                            : G_("%qs attribute not supported for %qE "
    6401              :                                 "in %<__builtin_has_attribute%>")),
    6402              :                           namestr, t);
    6403            0 :               return false;
    6404              :             }
    6405              : 
    6406              :           /* Clear EXPR to prevent considering it again below.  */
    6407         1318 :           atlist = TYPE_ATTRIBUTES (type);
    6408         1318 :           expr = NULL_TREE;
    6409         1318 :           done = true;
    6410              :         }
    6411         2226 :       else if (DECL_P (expr))
    6412              :         {
    6413              :           /* Set TYPE to the DECL's type to process it on the next
    6414              :              iteration.  */
    6415         1307 :           atlist = DECL_ATTRIBUTES (expr);
    6416         1307 :           type = TREE_TYPE (expr);
    6417              :         }
    6418              :       else
    6419              :         {
    6420          919 :           type = TREE_TYPE (expr);
    6421          919 :           atlist = TYPE_ATTRIBUTES (type);
    6422          919 :           done = true;
    6423              :         }
    6424              : 
    6425              :      /* True when an attribute with the sought name (though not necessarily
    6426              :          with the sought attributes) has been found on the attribute chain.  */
    6427         3544 :       bool found_attr = false;
    6428              : 
    6429              :       /* When clear, the first mismatched attribute argument results
    6430              :          in failure.  Otherwise, the first matched attribute argument
    6431              :          results in success.  */
    6432         3544 :       bool attr_nonnull = !strcmp ("nonnull", namestr);
    6433         3544 :       bool ignore_mismatches = attr_nonnull;
    6434              : 
    6435              :       /* Iterate over the instances of the sought attribute on the DECL or
    6436              :          TYPE (there may be multiple instances with different arguments).  */
    6437         3897 :       for (; (atlist = lookup_attribute (namestr, atlist));
    6438          353 :            found_attr = true, atlist = TREE_CHAIN (atlist))
    6439              :         {
    6440              :           /* If there are no arguments to match the result is true except
    6441              :              for nonnull where the attribute with no arguments must match.  */
    6442          992 :           if (!TREE_VALUE (attr))
    6443          449 :             return attr_nonnull ? !TREE_VALUE (atlist) : true;
    6444              : 
    6445              :           /* Attribute nonnull with no arguments subsumes all values of
    6446              :              the attribute.  FIXME: This is overly broad since it only
    6447              :              applies to pointer arguments, but querying non-pointer
    6448              :              arguments is diagnosed.  */
    6449          551 :           if (!TREE_VALUE (atlist) && attr_nonnull)
    6450              :             return true;
    6451              : 
    6452              :           /* Iterate over the DECL or TYPE attribute argument's values.  */
    6453          871 :           for (tree val = TREE_VALUE (atlist); val; val = TREE_CHAIN (val))
    6454              :             {
    6455              :               /* Iterate over the arguments in the sought attribute comparing
    6456              :                  their values to those specified for the DECL or TYPE.  */
    6457          538 :               for (tree arg = TREE_VALUE (attr); arg; arg = TREE_CHAIN (arg))
    6458              :                 {
    6459          518 :                   tree v1 = TREE_VALUE (val);
    6460          518 :                   tree v2 = TREE_VALUE (arg);
    6461          518 :                   if (v1 == v2)
    6462              :                     return true;
    6463              : 
    6464          394 :                   if (!v1 || !v2)
    6465              :                     break;
    6466              : 
    6467          394 :                   if (TREE_CODE (v1) == IDENTIFIER_NODE
    6468          390 :                       || TREE_CODE (v2) == IDENTIFIER_NODE)
    6469              :                     /* Two identifiers are the same if their values are
    6470              :                        equal (that's handled above).  Otherwise they are
    6471              :                        either not the same or oneis not an identifier.  */
    6472              :                     return false;
    6473              : 
    6474              :                   /* Convert to make them equality-comparable.  */
    6475          390 :                   v1 = convert (v1);
    6476          390 :                   v2 = convert (v2);
    6477              : 
    6478              :                   /* A positive value indicates equality, negative means
    6479              :                      "don't know."  */
    6480          390 :                   if (simple_cst_equal (v1, v2) == 1)
    6481              :                     return true;
    6482              : 
    6483          332 :                   if (!ignore_mismatches)
    6484              :                     break;
    6485              :                 }
    6486              :             }
    6487              :         }
    6488              : 
    6489         2905 :       if (!found_attr)
    6490              :         {
    6491              :           /* Some attributes are encoded directly in the tree node.  */
    6492         2574 :           if (!strcmp ("aligned", namestr))
    6493              :             {
    6494         1344 :               if (tree arg = TREE_VALUE (attr))
    6495              :                 {
    6496          996 :                   arg = convert (TREE_VALUE (arg));
    6497          996 :                   if (!tree_fits_uhwi_p (arg))
    6498              :                     /* Invalid argument.  */;
    6499          624 :                   else if (expr && DECL_P (expr)
    6500         1048 :                            && DECL_USER_ALIGN (expr))
    6501            0 :                     found_match = DECL_ALIGN_UNIT (expr) == tree_to_uhwi (arg);
    6502          992 :                   else if (type && TYPE_USER_ALIGN (type))
    6503          608 :                     found_match = TYPE_ALIGN_UNIT (type) == tree_to_uhwi (arg);
    6504              :                 }
    6505          348 :               else if (expr && DECL_P (expr))
    6506           14 :                 found_match = DECL_USER_ALIGN (expr);
    6507          334 :               else if (type)
    6508          334 :                 found_match = TYPE_USER_ALIGN (type);
    6509              :             }
    6510         1230 :           else if (!strcmp ("const", namestr))
    6511              :             {
    6512           24 :               if (expr && DECL_P (expr))
    6513           12 :                 found_match = TREE_READONLY (expr);
    6514              :             }
    6515         1206 :           else if (!strcmp ("noreturn", namestr))
    6516              :             {
    6517              :               /* C11 _Noreturn sets the volatile bit without attaching
    6518              :                  an attribute to the decl.  */
    6519            9 :               if (expr
    6520            1 :                   && DECL_P (expr)
    6521           10 :                   && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr)))
    6522            1 :                 found_match = TREE_THIS_VOLATILE (expr);
    6523              :             }
    6524         1197 :           else if (!strcmp ("pure", namestr))
    6525              :             {
    6526           26 :               if (expr && TREE_CODE (expr) == FUNCTION_DECL)
    6527           12 :                 found_match = DECL_PURE_P (expr);
    6528              :             }
    6529         1171 :           else if (!strcmp ("deprecated", namestr))
    6530              :             {
    6531            0 :               found_match = TREE_DEPRECATED (expr ? expr : type);
    6532            0 :               if (found_match)
    6533              :                 return true;
    6534              :             }
    6535         1171 :           else if (!strcmp ("vector_size", namestr))
    6536              :             {
    6537          200 :               if (!type || !VECTOR_TYPE_P (type))
    6538              :                 return false;
    6539              : 
    6540          120 :               if (tree arg = TREE_VALUE (attr))
    6541              :                 {
    6542              :                   /* Compare the vector size argument for equality.  */
    6543           88 :                   arg = convert (TREE_VALUE (arg));
    6544           88 :                   return tree_int_cst_equal (arg, TYPE_SIZE_UNIT (type)) == 1;
    6545              :                 }
    6546              :               else
    6547              :                 return true;
    6548              :             }
    6549          971 :           else if (!strcmp ("warn_if_not_aligned", namestr))
    6550              :             {
    6551           24 :               if (tree arg = TREE_VALUE (attr))
    6552              :                 {
    6553           24 :                   arg = convert (TREE_VALUE (arg));
    6554           24 :                   if (expr && DECL_P (expr))
    6555            0 :                     found_match = (DECL_WARN_IF_NOT_ALIGN (expr)
    6556            0 :                                    == tree_to_uhwi (arg) * BITS_PER_UNIT);
    6557           24 :                   else if (type)
    6558           24 :                     found_match = (TYPE_WARN_IF_NOT_ALIGN (type)
    6559           24 :                                    == tree_to_uhwi (arg) * BITS_PER_UNIT);
    6560              :                 }
    6561            0 :               else if (expr && DECL_P (expr))
    6562            0 :                 found_match = DECL_WARN_IF_NOT_ALIGN (expr);
    6563            0 :               else if (type)
    6564            0 :                 found_match = TYPE_WARN_IF_NOT_ALIGN (type);
    6565              :             }
    6566          947 :           else if (!strcmp ("transparent_union", namestr))
    6567              :             {
    6568           20 :               if (type)
    6569           20 :                 found_match = TYPE_TRANSPARENT_AGGR (type) != 0;
    6570              :             }
    6571          927 :           else if (!strcmp ("mode", namestr))
    6572              :             {
    6573              :               /* Finally issue a warning for attributes that cannot
    6574              :                  be supported in this context.  Attribute mode is not
    6575              :                  added to a symbol and cannot be determined from it.  */
    6576            4 :               warning_at (atloc, OPT_Wattributes,
    6577              :                           "%qs attribute not supported in "
    6578              :                           "%<__builtin_has_attribute%>", namestr);
    6579            4 :               break;
    6580              :             }
    6581              :         }
    6582              :     }
    6583              :   return found_match;
    6584              : }
        

Generated by: LCOV version 2.6-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.