LCOV - code coverage report
Current view: top level - gcc/c-family - c-attribs.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.1 % 2554 2173
Test Date: 2025-06-21 16:26:05 Functions: 92.0 % 138 127
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.1-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.