LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.3 % 8894 8387
Test Date: 2025-02-01 13:18:56 Functions: 97.4 % 230 224
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Process declarations and variables for -*- C++ -*- compiler.
       2                 :             :    Copyright (C) 1988-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Michael Tiemann (tiemann@cygnus.com)
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify
       8                 :             : it under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful,
      13                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :             : GNU General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* Process declarations and symbol lookup for C++ front end.
      23                 :             :    Also constructs types; the standard scalar types at initialization,
      24                 :             :    and structure, union, array and enum types when they are declared.  */
      25                 :             : 
      26                 :             : /* ??? not all decl nodes are given the most useful possible
      27                 :             :    line numbers.  For example, the CONST_DECLs for enum values.  */
      28                 :             : 
      29                 :             : #include "config.h"
      30                 :             : #include "system.h"
      31                 :             : #include "coretypes.h"
      32                 :             : #include "target.h"
      33                 :             : #include "c-family/c-target.h"
      34                 :             : #include "cp-tree.h"
      35                 :             : #include "timevar.h"
      36                 :             : #include "stringpool.h"
      37                 :             : #include "cgraph.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "varasm.h"
      40                 :             : #include "attribs.h"
      41                 :             : #include "flags.h"
      42                 :             : #include "tree-iterator.h"
      43                 :             : #include "decl.h"
      44                 :             : #include "intl.h"
      45                 :             : #include "toplev.h"
      46                 :             : #include "c-family/c-objc.h"
      47                 :             : #include "c-family/c-pragma.h"
      48                 :             : #include "c-family/c-ubsan.h"
      49                 :             : #include "cp/cp-name-hint.h"
      50                 :             : #include "debug.h"
      51                 :             : #include "plugin.h"
      52                 :             : #include "builtins.h"
      53                 :             : #include "gimplify.h"
      54                 :             : #include "asan.h"
      55                 :             : #include "gcc-rich-location.h"
      56                 :             : #include "langhooks.h"
      57                 :             : #include "context.h"  /* For 'g'.  */
      58                 :             : #include "omp-general.h"
      59                 :             : #include "omp-offload.h"  /* For offload_vars.  */
      60                 :             : #include "opts.h"
      61                 :             : #include "langhooks-def.h"  /* For lhd_simulate_record_decl  */
      62                 :             : #include "coroutines.h"
      63                 :             : #include "gcc-urlifier.h"
      64                 :             : #include "diagnostic-highlight-colors.h"
      65                 :             : #include "pretty-print-markup.h"
      66                 :             : 
      67                 :             : /* Possible cases of bad specifiers type used by bad_specifiers. */
      68                 :             : enum bad_spec_place {
      69                 :             :   BSP_VAR,    /* variable */
      70                 :             :   BSP_PARM,   /* parameter */
      71                 :             :   BSP_TYPE,   /* type */
      72                 :             :   BSP_FIELD   /* field */
      73                 :             : };
      74                 :             : 
      75                 :             : static const char *redeclaration_error_message (tree, tree);
      76                 :             : 
      77                 :             : static bool decl_jump_unsafe (tree);
      78                 :             : static void require_complete_types_for_parms (tree);
      79                 :             : static tree grok_reference_init (tree, tree, tree, int);
      80                 :             : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      81                 :             :                          int, int, int, bool, int, tree, location_t);
      82                 :             : static void check_static_variable_definition (tree, tree);
      83                 :             : static void record_unknown_type (tree, const char *);
      84                 :             : static int member_function_or_else (tree, tree, enum overload_flags);
      85                 :             : static tree local_variable_p_walkfn (tree *, int *, void *);
      86                 :             : static const char *tag_name (enum tag_types);
      87                 :             : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      88                 :             : static void maybe_deduce_size_from_array_init (tree, tree);
      89                 :             : static void layout_var_decl (tree);
      90                 :             : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      91                 :             : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      92                 :             : static void copy_type_enum (tree , tree);
      93                 :             : static void check_function_type (tree, tree);
      94                 :             : static void begin_destructor_body (void);
      95                 :             : static void record_key_method_defined (tree);
      96                 :             : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      97                 :             : static tree get_atexit_node (void);
      98                 :             : static tree get_dso_handle_node (void);
      99                 :             : static tree start_cleanup_fn (bool);
     100                 :             : static void end_cleanup_fn (void);
     101                 :             : static tree cp_make_fname_decl (location_t, tree, int);
     102                 :             : static void initialize_predefined_identifiers (void);
     103                 :             : static tree check_special_function_return_type
     104                 :             :        (special_function_kind, tree, tree, int, const location_t*);
     105                 :             : static tree push_cp_library_fn (enum tree_code, tree, int);
     106                 :             : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     107                 :             : static void store_parm_decls (tree);
     108                 :             : static void initialize_local_var (tree, tree, bool);
     109                 :             : static void expand_static_init (tree, tree);
     110                 :             : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     111                 :             : static bool identify_goto (tree, location_t, const location_t *,
     112                 :             :                            diagnostic_t, bool);
     113                 :             : 
     114                 :             : /* The following symbols are subsumed in the cp_global_trees array, and
     115                 :             :    listed here individually for documentation purposes.
     116                 :             : 
     117                 :             :    C++ extensions
     118                 :             :         tree wchar_decl_node;
     119                 :             : 
     120                 :             :         tree vtable_entry_type;
     121                 :             :         tree delta_type_node;
     122                 :             :         tree __t_desc_type_node;
     123                 :             : 
     124                 :             :         tree class_type_node;
     125                 :             :         tree unknown_type_node;
     126                 :             : 
     127                 :             :    Array type `vtable_entry_type[]'
     128                 :             : 
     129                 :             :         tree vtbl_type_node;
     130                 :             :         tree vtbl_ptr_type_node;
     131                 :             : 
     132                 :             :    Namespaces,
     133                 :             : 
     134                 :             :         tree std_node;
     135                 :             :         tree abi_node;
     136                 :             : 
     137                 :             :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     138                 :             :    one that the user will declare, but sufficient to be called
     139                 :             :    by routines that want to abort the program.
     140                 :             : 
     141                 :             :         tree abort_fndecl;
     142                 :             : 
     143                 :             :    Used by RTTI
     144                 :             :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     145                 :             :         tree tinfo_var_id;  */
     146                 :             : 
     147                 :             : tree cp_global_trees[CPTI_MAX];
     148                 :             : 
     149                 :             : /* A list of objects which have constructors or destructors
     150                 :             :    which reside in namespace scope.  The decl is stored in
     151                 :             :    the TREE_VALUE slot and the initializer is stored
     152                 :             :    in the TREE_PURPOSE slot.  */
     153                 :             : tree static_aggregates;
     154                 :             : 
     155                 :             : /* Like static_aggregates, but for thread_local variables.  */
     156                 :             : tree tls_aggregates;
     157                 :             : 
     158                 :             : /* A hash-map mapping from variable decls to the dynamic initializer for
     159                 :             :    the decl.  This is currently only used by OpenMP.  */
     160                 :             : decl_tree_map *dynamic_initializers;
     161                 :             : 
     162                 :             : /* -- end of C++ */
     163                 :             : 
     164                 :             : /* A node for the integer constant 2.  */
     165                 :             : 
     166                 :             : tree integer_two_node;
     167                 :             : 
     168                 :             : /* vector of static decls.  */
     169                 :             : vec<tree, va_gc> *static_decls;
     170                 :             : 
     171                 :             : /* vector of keyed classes.  */
     172                 :             : vec<tree, va_gc> *keyed_classes;
     173                 :             : 
     174                 :             : /* Used only for jumps to as-yet undefined labels, since jumps to
     175                 :             :    defined labels can have their validity checked immediately.  */
     176                 :             : 
     177                 :             : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     178                 :             :   struct named_label_use_entry *next;
     179                 :             :   /* The binding level to which this entry is *currently* attached.
     180                 :             :      This is initially the binding level in which the goto appeared,
     181                 :             :      but is modified as scopes are closed.  */
     182                 :             :   cp_binding_level *binding_level;
     183                 :             :   /* The head of the names list that was current when the goto appeared,
     184                 :             :      or the inner scope popped.  These are the decls that will *not* be
     185                 :             :      skipped when jumping to the label.  */
     186                 :             :   tree names_in_scope;
     187                 :             :   /* If the use is a possible destination of a computed goto, a vec of decls
     188                 :             :      that aren't destroyed, filled in by poplevel_named_label_1.  */
     189                 :             :   vec<tree,va_gc> *computed_goto;
     190                 :             :   /* The location of the goto, for error reporting.  */
     191                 :             :   location_t o_goto_locus;
     192                 :             :   /* True if an OpenMP structured block scope has been closed since
     193                 :             :      the goto appeared.  This means that the branch from the label will
     194                 :             :      illegally exit an OpenMP scope.  */
     195                 :             :   bool in_omp_scope;
     196                 :             : };
     197                 :             : 
     198                 :             : /* A list of all LABEL_DECLs in the function that have names.  Here so
     199                 :             :    we can clear out their names' definitions at the end of the
     200                 :             :    function, and so we can check the validity of jumps to these labels.  */
     201                 :             : 
     202                 :             : struct GTY((for_user)) named_label_entry {
     203                 :             : 
     204                 :             :   tree name;  /* Name of decl. */
     205                 :             : 
     206                 :             :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     207                 :             : 
     208                 :             :   named_label_entry *outer; /* Outer shadowed chain.  */
     209                 :             : 
     210                 :             :   /* The binding level to which the label is *currently* attached.
     211                 :             :      This is initially set to the binding level in which the label
     212                 :             :      is defined, but is modified as scopes are closed.  */
     213                 :             :   cp_binding_level *binding_level;
     214                 :             : 
     215                 :             :   /* The head of the names list that was current when the label was
     216                 :             :      defined, or the inner scope popped.  These are the decls that will
     217                 :             :      be skipped when jumping to the label.  */
     218                 :             :   tree names_in_scope;
     219                 :             : 
     220                 :             :   /* A vector of all decls from all binding levels that would be
     221                 :             :      crossed by a backward branch to the label.  */
     222                 :             :   vec<tree, va_gc> *bad_decls;
     223                 :             : 
     224                 :             :   /* A list of uses of the label, before the label is defined.  */
     225                 :             :   named_label_use_entry *uses;
     226                 :             : 
     227                 :             :   /* True if we've seen &&label.  Appalently we can't use TREE_ADDRESSABLE for
     228                 :             :      this, it has a more specific meaning for LABEL_DECL.  */
     229                 :             :   bool addressed;
     230                 :             : 
     231                 :             :   /* The following bits are set after the label is defined, and are
     232                 :             :      updated as scopes are popped.  They indicate that a jump to the
     233                 :             :      label will illegally enter a scope of the given flavor.  */
     234                 :             :   bool in_try_scope;
     235                 :             :   bool in_catch_scope;
     236                 :             :   bool in_omp_scope;
     237                 :             :   bool in_transaction_scope;
     238                 :             :   bool in_constexpr_if;
     239                 :             :   bool in_consteval_if;
     240                 :             :   bool in_stmt_expr;
     241                 :             : };
     242                 :             : 
     243                 :             : #define named_labels cp_function_chain->x_named_labels
     244                 :             : 
     245                 :             : /* The number of function bodies which we are currently processing.
     246                 :             :    (Zero if we are at namespace scope, one inside the body of a
     247                 :             :    function, two inside the body of a function in a local class, etc.)  */
     248                 :             : int function_depth;
     249                 :             : 
     250                 :             : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     251                 :             : bool flag_noexcept_type;
     252                 :             : 
     253                 :             : /* States indicating how grokdeclarator() should handle declspecs marked
     254                 :             :    with __attribute__((deprecated)).  An object declared as
     255                 :             :    __attribute__((deprecated)) suppresses warnings of uses of other
     256                 :             :    deprecated items.  */
     257                 :             : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     258                 :             : 
     259                 :             : 
     260                 :             : /* A list of VAR_DECLs whose type was incomplete at the time the
     261                 :             :    variable was declared.  */
     262                 :             : 
     263                 :             : struct GTY(()) incomplete_var {
     264                 :             :   tree decl;
     265                 :             :   tree incomplete_type;
     266                 :             : };
     267                 :             : 
     268                 :             : 
     269                 :             : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     270                 :             : 
     271                 :             : /* Returns the kind of template specialization we are currently
     272                 :             :    processing, given that it's declaration contained N_CLASS_SCOPES
     273                 :             :    explicit scope qualifications.  */
     274                 :             : 
     275                 :             : tmpl_spec_kind
     276                 :   213005857 : current_tmpl_spec_kind (int n_class_scopes)
     277                 :             : {
     278                 :   213005857 :   int n_template_parm_scopes = 0;
     279                 :   213005857 :   int seen_specialization_p = 0;
     280                 :   213005857 :   int innermost_specialization_p = 0;
     281                 :   213005857 :   cp_binding_level *b;
     282                 :             : 
     283                 :             :   /* Scan through the template parameter scopes.  */
     284                 :   213005857 :   for (b = current_binding_level;
     285                 :   266948762 :        b->kind == sk_template_parms;
     286                 :    53942905 :        b = b->level_chain)
     287                 :             :     {
     288                 :             :       /* If we see a specialization scope inside a parameter scope,
     289                 :             :          then something is wrong.  That corresponds to a declaration
     290                 :             :          like:
     291                 :             : 
     292                 :             :             template <class T> template <> ...
     293                 :             : 
     294                 :             :          which is always invalid since [temp.expl.spec] forbids the
     295                 :             :          specialization of a class member template if the enclosing
     296                 :             :          class templates are not explicitly specialized as well.  */
     297                 :    53942905 :       if (b->explicit_spec_p)
     298                 :             :         {
     299                 :      893290 :           if (n_template_parm_scopes == 0)
     300                 :             :             innermost_specialization_p = 1;
     301                 :             :           else
     302                 :        1133 :             seen_specialization_p = 1;
     303                 :             :         }
     304                 :    53049615 :       else if (seen_specialization_p == 1)
     305                 :             :         return tsk_invalid_member_spec;
     306                 :             : 
     307                 :    53942905 :       ++n_template_parm_scopes;
     308                 :             :     }
     309                 :             : 
     310                 :             :   /* Handle explicit instantiations.  */
     311                 :   213005857 :   if (processing_explicit_instantiation)
     312                 :             :     {
     313                 :     1955323 :       if (n_template_parm_scopes != 0)
     314                 :             :         /* We've seen a template parameter list during an explicit
     315                 :             :            instantiation.  For example:
     316                 :             : 
     317                 :             :              template <class T> template void f(int);
     318                 :             : 
     319                 :             :            This is erroneous.  */
     320                 :             :         return tsk_invalid_expl_inst;
     321                 :             :       else
     322                 :     1955323 :         return tsk_expl_inst;
     323                 :             :     }
     324                 :             : 
     325                 :   211050534 :   if (n_template_parm_scopes < n_class_scopes)
     326                 :             :     /* We've not seen enough template headers to match all the
     327                 :             :        specialized classes present.  For example:
     328                 :             : 
     329                 :             :          template <class T> void R<T>::S<T>::f(int);
     330                 :             : 
     331                 :             :        This is invalid; there needs to be one set of template
     332                 :             :        parameters for each class.  */
     333                 :             :     return tsk_insufficient_parms;
     334                 :   211050534 :   else if (n_template_parm_scopes == n_class_scopes)
     335                 :             :     /* We're processing a non-template declaration (even though it may
     336                 :             :        be a member of a template class.)  For example:
     337                 :             : 
     338                 :             :          template <class T> void S<T>::f(int);
     339                 :             : 
     340                 :             :        The `class T' matches the `S<T>', leaving no template headers
     341                 :             :        corresponding to the `f'.  */
     342                 :             :     return tsk_none;
     343                 :    45992876 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     344                 :             :     /* We've got too many template headers.  For example:
     345                 :             : 
     346                 :             :          template <> template <class T> void f (T);
     347                 :             : 
     348                 :             :        There need to be more enclosing classes.  */
     349                 :             :     return tsk_excessive_parms;
     350                 :             :   else
     351                 :             :     /* This must be a template.  It's of the form:
     352                 :             : 
     353                 :             :          template <class T> template <class U> void S<T>::f(U);
     354                 :             : 
     355                 :             :        This is a specialization if the innermost level was a
     356                 :             :        specialization; otherwise it's just a definition of the
     357                 :             :        template.  */
     358                 :    91580194 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     359                 :             : }
     360                 :             : 
     361                 :             : /* Exit the current scope.  */
     362                 :             : 
     363                 :             : void
     364                 :    82140991 : finish_scope (void)
     365                 :             : {
     366                 :    82140991 :   poplevel (0, 0, 0);
     367                 :    82140991 : }
     368                 :             : 
     369                 :             : /* When a label goes out of scope, check to see if that label was used
     370                 :             :    in a valid manner, and issue any appropriate warnings or errors.  */
     371                 :             : 
     372                 :             : static void
     373                 :       18697 : check_label_used (tree label)
     374                 :             : {
     375                 :       18697 :   if (!processing_template_decl)
     376                 :             :     {
     377                 :       18450 :       if (DECL_INITIAL (label) == NULL_TREE)
     378                 :             :         {
     379                 :           9 :           location_t location;
     380                 :             : 
     381                 :           9 :           error ("label %q+D used but not defined", label);
     382                 :           9 :           location = input_location;
     383                 :             :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     384                 :             :           /* Avoid crashing later.  */
     385                 :           9 :           define_label (location, DECL_NAME (label));
     386                 :             :         }
     387                 :             :       else
     388                 :       18441 :         warn_for_unused_label (label);
     389                 :             :     }
     390                 :       18697 : }
     391                 :             : 
     392                 :             : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     393                 :             : 
     394                 :             : static int
     395                 :      226928 : sort_labels (const void *a, const void *b)
     396                 :             : {
     397                 :      226928 :   tree label1 = *(tree const *) a;
     398                 :      226928 :   tree label2 = *(tree const *) b;
     399                 :             : 
     400                 :             :   /* DECL_UIDs can never be equal.  */
     401                 :      226928 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     402                 :             : }
     403                 :             : 
     404                 :             : /* At the end of a function, all labels declared within the function
     405                 :             :    go out of scope.  BLOCK is the top-level block for the
     406                 :             :    function.  */
     407                 :             : 
     408                 :             : static void
     409                 :   133156085 : pop_labels (tree block)
     410                 :             : {
     411                 :   133156085 :   if (!named_labels)
     412                 :   133152169 :     return;
     413                 :             : 
     414                 :             :   /* We need to add the labels to the block chain, so debug
     415                 :             :      information is emitted.  But, we want the order to be stable so
     416                 :             :      need to sort them first.  Otherwise the debug output could be
     417                 :             :      randomly ordered.  I guess it's mostly stable, unless the hash
     418                 :             :      table implementation changes.  */
     419                 :        3916 :   auto_vec<tree, 32> labels (named_labels->elements ());
     420                 :        3916 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     421                 :       22592 :   for (hash_table<named_label_hash>::iterator iter
     422                 :       45184 :          (named_labels->begin ()); iter != end; ++iter)
     423                 :             :     {
     424                 :       18676 :       named_label_entry *ent = *iter;
     425                 :             : 
     426                 :       18676 :       gcc_checking_assert (!ent->outer);
     427                 :       18676 :       if (ent->label_decl)
     428                 :       18502 :         labels.quick_push (ent->label_decl);
     429                 :       18676 :       ggc_free (ent);
     430                 :             :     }
     431                 :        3916 :   named_labels = NULL;
     432                 :        3916 :   labels.qsort (sort_labels);
     433                 :             : 
     434                 :       22418 :   while (labels.length ())
     435                 :             :     {
     436                 :       18502 :       tree label = labels.pop ();
     437                 :             : 
     438                 :       18502 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     439                 :       18502 :       BLOCK_VARS (block) = label;
     440                 :             : 
     441                 :       18502 :       check_label_used (label);
     442                 :             :     }
     443                 :        3916 : }
     444                 :             : 
     445                 :             : /* At the end of a block with local labels, restore the outer definition.  */
     446                 :             : 
     447                 :             : static void
     448                 :         195 : pop_local_label (tree id, tree label)
     449                 :             : {
     450                 :         195 :   check_label_used (label);
     451                 :         195 :   named_label_entry **slot = named_labels->find_slot_with_hash
     452                 :         195 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     453                 :         195 :   named_label_entry *ent = *slot;
     454                 :             : 
     455                 :         195 :   if (ent->outer)
     456                 :             :     ent = ent->outer;
     457                 :             :   else
     458                 :             :     {
     459                 :         186 :       ent = ggc_cleared_alloc<named_label_entry> ();
     460                 :         186 :       ent->name = id;
     461                 :             :     }
     462                 :         195 :   *slot = ent;
     463                 :         195 : }
     464                 :             : 
     465                 :             : /* The following two routines are used to interface to Objective-C++.
     466                 :             :    The binding level is purposely treated as an opaque type.  */
     467                 :             : 
     468                 :             : void *
     469                 :           0 : objc_get_current_scope (void)
     470                 :             : {
     471                 :           0 :   return current_binding_level;
     472                 :             : }
     473                 :             : 
     474                 :             : /* The following routine is used by the NeXT-style SJLJ exceptions;
     475                 :             :    variables get marked 'volatile' so as to not be clobbered by
     476                 :             :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     477                 :             :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     478                 :             :    shall be thusly marked.  */
     479                 :             : 
     480                 :             : void
     481                 :           0 : objc_mark_locals_volatile (void *enclosing_blk)
     482                 :             : {
     483                 :           0 :   cp_binding_level *scope;
     484                 :             : 
     485                 :           0 :   for (scope = current_binding_level;
     486                 :           0 :        scope && scope != enclosing_blk;
     487                 :           0 :        scope = scope->level_chain)
     488                 :             :     {
     489                 :           0 :       tree decl;
     490                 :             : 
     491                 :           0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     492                 :           0 :         objc_volatilize_decl (decl);
     493                 :             : 
     494                 :             :       /* Do not climb up past the current function.  */
     495                 :           0 :       if (scope->kind == sk_function_parms)
     496                 :             :         break;
     497                 :             :     }
     498                 :           0 : }
     499                 :             : 
     500                 :             : /* True if B is the level for the condition of a constexpr if.  */
     501                 :             : 
     502                 :             : static bool
     503                 :     1667448 : level_for_constexpr_if (cp_binding_level *b)
     504                 :             : {
     505                 :     1664770 :   return (b->kind == sk_cond && b->this_entity
     506                 :         261 :           && TREE_CODE (b->this_entity) == IF_STMT
     507                 :     1667709 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     508                 :             : }
     509                 :             : 
     510                 :             : /* True if B is the level for the condition of a consteval if.  */
     511                 :             : 
     512                 :             : static bool
     513                 :     1667424 : level_for_consteval_if (cp_binding_level *b)
     514                 :             : {
     515                 :     1664746 :   return (b->kind == sk_cond && b->this_entity
     516                 :         237 :           && TREE_CODE (b->this_entity) == IF_STMT
     517                 :     1667661 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     518                 :             : }
     519                 :             : 
     520                 :             : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
     521                 :             :    See [stmt.dcl]/2.  */
     522                 :             : 
     523                 :             : static bool
     524                 :          25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
     525                 :             : {
     526                 :          25 :   if (error_operand_p (t))
     527                 :             :     return false;
     528                 :             : 
     529                 :          19 :   return (VAR_P (t)
     530                 :          19 :           && decl_storage_duration (CONST_CAST_TREE (t)) == dk_auto
     531                 :          38 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
     532                 :             : }
     533                 :             : 
     534                 :             : /* Update data for defined and undefined labels when leaving a scope.  */
     535                 :             : 
     536                 :             : int
     537                 :      137858 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     538                 :             : {
     539                 :      137858 :   named_label_entry *ent = *slot;
     540                 :      137858 :   cp_binding_level *obl = bl->level_chain;
     541                 :             : 
     542                 :      137858 :   if (ent->binding_level == bl)
     543                 :             :     {
     544                 :        7691 :       tree decl;
     545                 :             : 
     546                 :             :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     547                 :             :          TREE_LISTs representing OVERLOADs, so be careful.  */
     548                 :       10936 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     549                 :        3318 :                                                      ? DECL_CHAIN (decl)
     550                 :          73 :                                                      : TREE_CHAIN (decl)))
     551                 :        3245 :         if (decl_jump_unsafe (decl))
     552                 :        1205 :           vec_safe_push (ent->bad_decls, decl);
     553                 :             : 
     554                 :        7691 :       ent->binding_level = obl;
     555                 :        7691 :       ent->names_in_scope = obl->names;
     556                 :        7691 :       switch (bl->kind)
     557                 :             :         {
     558                 :          42 :         case sk_try:
     559                 :          42 :           ent->in_try_scope = true;
     560                 :          42 :           break;
     561                 :          27 :         case sk_catch:
     562                 :          27 :           ent->in_catch_scope = true;
     563                 :          27 :           break;
     564                 :         269 :         case sk_omp:
     565                 :         269 :           ent->in_omp_scope = true;
     566                 :         269 :           break;
     567                 :           3 :         case sk_transaction:
     568                 :           3 :           ent->in_transaction_scope = true;
     569                 :           3 :           break;
     570                 :          33 :         case sk_stmt_expr:
     571                 :          33 :           ent->in_stmt_expr = true;
     572                 :          33 :           break;
     573                 :        2870 :         case sk_block:
     574                 :        2870 :           if (level_for_constexpr_if (bl->level_chain))
     575                 :          15 :             ent->in_constexpr_if = true;
     576                 :        2855 :           else if (level_for_consteval_if (bl->level_chain))
     577                 :          30 :             ent->in_consteval_if = true;
     578                 :             :           break;
     579                 :             :         default:
     580                 :             :           break;
     581                 :             :         }
     582                 :             :     }
     583                 :      130167 :   else if (ent->uses)
     584                 :             :     {
     585                 :             :       struct named_label_use_entry *use;
     586                 :             : 
     587                 :        7269 :       for (use = ent->uses; use ; use = use->next)
     588                 :        4051 :         if (use->binding_level == bl)
     589                 :             :           {
     590                 :        1734 :             if (auto &cg = use->computed_goto)
     591                 :             :               {
     592                 :          45 :                 if (bl->kind == sk_catch)
     593                 :           3 :                   vec_safe_push (cg, get_identifier ("catch"));
     594                 :          54 :                 for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
     595                 :           9 :                   if (automatic_var_with_nontrivial_dtor_p (d))
     596                 :           6 :                     vec_safe_push (cg, d);
     597                 :             :               }
     598                 :             : 
     599                 :        1734 :             use->binding_level = obl;
     600                 :        1734 :             use->names_in_scope = obl->names;
     601                 :        1734 :             if (bl->kind == sk_omp)
     602                 :          12 :               use->in_omp_scope = true;
     603                 :             :           }
     604                 :             :     }
     605                 :             : 
     606                 :      137858 :   return 1;
     607                 :             : }
     608                 :             : 
     609                 :             : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     610                 :             :    when errors were reported, except for -Werror-unused-but-set-*.  */
     611                 :             : static int unused_but_set_errorcount;
     612                 :             : 
     613                 :             : /* Exit a binding level.
     614                 :             :    Pop the level off, and restore the state of the identifier-decl mappings
     615                 :             :    that were in effect when this level was entered.
     616                 :             : 
     617                 :             :    If KEEP == 1, this level had explicit declarations, so
     618                 :             :    and create a "block" (a BLOCK node) for the level
     619                 :             :    to record its declarations and subblocks for symbol table output.
     620                 :             : 
     621                 :             :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     622                 :             :    so create a block as if KEEP were set and also clear out all
     623                 :             :    label names.
     624                 :             : 
     625                 :             :    If REVERSE is nonzero, reverse the order of decls before putting
     626                 :             :    them into the BLOCK.  */
     627                 :             : 
     628                 :             : tree
     629                 :   535309721 : poplevel (int keep, int reverse, int functionbody)
     630                 :             : {
     631                 :   535309721 :   tree link;
     632                 :             :   /* The chain of decls was accumulated in reverse order.
     633                 :             :      Put it into forward order, just for cleanliness.  */
     634                 :   535309721 :   tree decls;
     635                 :   535309721 :   tree subblocks;
     636                 :   535309721 :   tree block;
     637                 :   535309721 :   tree decl;
     638                 :   535309721 :   scope_kind kind;
     639                 :             : 
     640                 :   535309721 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     641                 :   535310015 :  restart:
     642                 :             : 
     643                 :   535310015 :   block = NULL_TREE;
     644                 :             : 
     645                 :   535310015 :   gcc_assert (current_binding_level->kind != sk_class
     646                 :             :               && current_binding_level->kind != sk_namespace);
     647                 :             : 
     648                 :   535310015 :   if (current_binding_level->kind == sk_cleanup)
     649                 :             :     functionbody = 0;
     650                 :   535310015 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     651                 :             : 
     652                 :   535310015 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     653                 :             : 
     654                 :             :   /* We used to use KEEP == 2 to indicate that the new block should go
     655                 :             :      at the beginning of the list of blocks at this binding level,
     656                 :             :      rather than the end.  This hack is no longer used.  */
     657                 :   535310015 :   gcc_assert (keep == 0 || keep == 1);
     658                 :             : 
     659                 :   535310015 :   if (current_binding_level->keep)
     660                 :     6782523 :     keep = 1;
     661                 :             : 
     662                 :             :   /* Any uses of undefined labels, and any defined labels, now operate
     663                 :             :      under constraints of next binding contour.  */
     664                 :   535310015 :   if (cfun && !functionbody && named_labels)
     665                 :       42591 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     666                 :      180449 :                    (current_binding_level);
     667                 :             : 
     668                 :             :   /* Get the decls in the order they were written.
     669                 :             :      Usually current_binding_level->names is in reverse order.
     670                 :             :      But parameter decls were previously put in forward order.  */
     671                 :             : 
     672                 :   535310015 :   decls = current_binding_level->names;
     673                 :   535310015 :   if (reverse)
     674                 :             :     {
     675                 :   286356290 :       decls = nreverse (decls);
     676                 :   286356290 :       current_binding_level->names = decls;
     677                 :             :     }
     678                 :             : 
     679                 :             :   /* If there were any declarations or structure tags in that level,
     680                 :             :      or if this level is a function body,
     681                 :             :      create a BLOCK to record them for the life of this function.  */
     682                 :   535310015 :   block = NULL_TREE;
     683                 :             :   /* Avoid function body block if possible.  */
     684                 :   567993744 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     685                 :             :     keep = 0;
     686                 :   502626541 :   else if (keep == 1 || functionbody)
     687                 :   165899570 :     block = make_node (BLOCK);
     688                 :   165899570 :   if (block != NULL_TREE)
     689                 :             :     {
     690                 :   165899570 :       BLOCK_VARS (block) = decls;
     691                 :   165899570 :       BLOCK_SUBBLOCKS (block) = subblocks;
     692                 :             :     }
     693                 :             : 
     694                 :             :   /* In each subblock, record that this is its superior.  */
     695                 :   535310015 :   if (keep >= 0)
     696                 :   600736398 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     697                 :    65426383 :       BLOCK_SUPERCONTEXT (link) = block;
     698                 :             : 
     699                 :             :   /* Before we remove the declarations first check for unused variables.  */
     700                 :   535310015 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     701                 :     6080787 :       && current_binding_level->kind != sk_template_parms
     702                 :     5172393 :       && !processing_template_decl)
     703                 :     6259127 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     704                 :             :       {
     705                 :             :         /* There are cases where D itself is a TREE_LIST.  See in
     706                 :             :            push_local_binding where the list of decls returned by
     707                 :             :            getdecls is built.  */
     708                 :     3250409 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     709                 :     3250409 :         decl = strip_using_decl (udecl);
     710                 :             : 
     711                 :     3250409 :         tree type = TREE_TYPE (decl);
     712                 :     3250409 :         if (VAR_P (decl)
     713                 :      361591 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     714                 :        2721 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     715                 :             :             /* For structured bindings, consider only real variables, not
     716                 :             :                subobjects.  */
     717                 :        2709 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     718                 :        2547 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     719                 :             :             /* Don't warn about name-independent declarations.  */
     720                 :         586 :             && !name_independent_decl_p (decl)
     721                 :         496 :             && type != error_mark_node
     722                 :     3253582 :             && (!CLASS_TYPE_P (type)
     723                 :          51 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     724                 :           3 :                 || lookup_attribute ("warn_unused",
     725                 :           3 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     726                 :             :           {
     727                 :         464 :             if (!TREE_USED (decl))
     728                 :             :               {
     729                 :         302 :                 if (TREE_CODE (udecl) == USING_DECL)
     730                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (udecl),
     731                 :             :                               OPT_Wunused_variable,
     732                 :             :                               "unused using-declaration %qD", udecl);
     733                 :         299 :                 else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     734                 :           3 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     735                 :             :                               OPT_Wunused_variable,
     736                 :             :                               "unused structured binding declaration");
     737                 :             :                 else
     738                 :         296 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     739                 :             :                               OPT_Wunused_variable, "unused variable %qD", decl);
     740                 :         302 :                 suppress_warning (decl, OPT_Wunused_variable);
     741                 :             :               }
     742                 :         162 :             else if (DECL_CONTEXT (decl) == current_function_decl
     743                 :             :                      // For -Wunused-but-set-variable leave references alone.
     744                 :         138 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     745                 :         300 :                      && errorcount == unused_but_set_errorcount)
     746                 :             :               {
     747                 :         129 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     748                 :          12 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     749                 :             :                               OPT_Wunused_but_set_variable, "structured "
     750                 :             :                               "binding declaration set but not used");
     751                 :             :                 else
     752                 :         117 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     753                 :             :                               OPT_Wunused_but_set_variable,
     754                 :             :                               "variable %qD set but not used", decl);
     755                 :         129 :                 unused_but_set_errorcount = errorcount;
     756                 :             :               }
     757                 :             :           }
     758                 :             :       }
     759                 :             : 
     760                 :             :   /* Remove declarations for all the DECLs in this level.  */
     761                 :  1094151487 :   for (link = decls; link; link = TREE_CHAIN (link))
     762                 :             :     {
     763                 :   558841472 :       tree name;
     764                 :   558841472 :       if (TREE_CODE (link) == TREE_LIST)
     765                 :             :         {
     766                 :      702471 :           decl = TREE_VALUE (link);
     767                 :      702471 :           name = TREE_PURPOSE (link);
     768                 :      702471 :           gcc_checking_assert (name);
     769                 :             :         }
     770                 :             :       else
     771                 :             :         {
     772                 :   558139001 :           decl = link;
     773                 :   558139001 :           name = DECL_NAME (decl);
     774                 :             :         }
     775                 :             : 
     776                 :             :       /* Remove the binding.  */
     777                 :   558841472 :       if (TREE_CODE (decl) == LABEL_DECL)
     778                 :         195 :         pop_local_label (name, decl);
     779                 :             :       else
     780                 :   558841277 :         pop_local_binding (name, decl);
     781                 :             :     }
     782                 :             : 
     783                 :             :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     784                 :   535310015 :   for (link = current_binding_level->type_shadowed;
     785                 :   729934304 :        link; link = TREE_CHAIN (link))
     786                 :   194624289 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     787                 :             : 
     788                 :             :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     789                 :             :      list if a `using' declaration put them there.  The debugging
     790                 :             :      back ends won't understand OVERLOAD, so we remove them here.
     791                 :             :      Because the BLOCK_VARS are (temporarily) shared with
     792                 :             :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     793                 :             :      popped all the bindings.  Also remove undeduced 'auto' decls,
     794                 :             :      which LTO doesn't understand, and can't have been used by anything.  */
     795                 :   535310015 :   if (block)
     796                 :             :     {
     797                 :   165899570 :       tree* d;
     798                 :             : 
     799                 :   435692337 :       for (d = &BLOCK_VARS (block); *d; )
     800                 :             :         {
     801                 :   269792767 :           if (TREE_CODE (*d) == TREE_LIST
     802                 :   269792767 :               || (!processing_template_decl
     803                 :    86101815 :                   && undeduced_auto_decl (*d)))
     804                 :      702499 :             *d = TREE_CHAIN (*d);
     805                 :             :           else
     806                 :   269090268 :             d = &DECL_CHAIN (*d);
     807                 :             :         }
     808                 :             :     }
     809                 :             : 
     810                 :             :   /* If the level being exited is the top level of a function,
     811                 :             :      check over all the labels.  */
     812                 :   535310015 :   if (functionbody)
     813                 :             :     {
     814                 :   133156085 :       if (block)
     815                 :             :         {
     816                 :             :           /* Since this is the top level block of a function, the vars are
     817                 :             :              the function's parameters.  Don't leave them in the BLOCK
     818                 :             :              because they are found in the FUNCTION_DECL instead.  */
     819                 :   100472611 :           BLOCK_VARS (block) = 0;
     820                 :   100472611 :           pop_labels (block);
     821                 :             :         }
     822                 :             :       else
     823                 :    32683474 :         pop_labels (subblocks);
     824                 :             :     }
     825                 :             : 
     826                 :   535310015 :   kind = current_binding_level->kind;
     827                 :   535310015 :   if (kind == sk_cleanup)
     828                 :             :     {
     829                 :         294 :       tree stmt;
     830                 :             : 
     831                 :             :       /* If this is a temporary binding created for a cleanup, then we'll
     832                 :             :          have pushed a statement list level.  Pop that, create a new
     833                 :             :          BIND_EXPR for the block, and insert it into the stream.  */
     834                 :         294 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     835                 :         294 :       stmt = c_build_bind_expr (input_location, block, stmt);
     836                 :         294 :       add_stmt (stmt);
     837                 :             :     }
     838                 :             : 
     839                 :   535310015 :   leave_scope ();
     840                 :   535310015 :   if (functionbody)
     841                 :             :     {
     842                 :             :       /* The current function is being defined, so its DECL_INITIAL
     843                 :             :          should be error_mark_node.  */
     844                 :   133156085 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     845                 :   165839559 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     846                 :   133156085 :       if (subblocks)
     847                 :             :         {
     848                 :    66773024 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
     849                 :             :             {
     850                 :     7650494 :               if (BLOCK_SUBBLOCKS (subblocks))
     851                 :      961909 :                 BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     852                 :             :             }
     853                 :             :           else
     854                 :    25033235 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     855                 :             :         }
     856                 :             :     }
     857                 :   402153930 :   else if (block)
     858                 :    65426959 :     current_binding_level->blocks
     859                 :   130853918 :       = block_chainon (current_binding_level->blocks, block);
     860                 :             : 
     861                 :             :   /* If we did not make a block for the level just exited,
     862                 :             :      any blocks made for inner levels
     863                 :             :      (since they cannot be recorded as subblocks in that level)
     864                 :             :      must be carried forward so they will later become subblocks
     865                 :             :      of something else.  */
     866                 :   336726971 :   else if (subblocks)
     867                 :           9 :     current_binding_level->blocks
     868                 :          18 :       = block_chainon (current_binding_level->blocks, subblocks);
     869                 :             : 
     870                 :             :   /* Each and every BLOCK node created here in `poplevel' is important
     871                 :             :      (e.g. for proper debugging information) so if we created one
     872                 :             :      earlier, mark it as "used".  */
     873                 :   535310015 :   if (block)
     874                 :   165899570 :     TREE_USED (block) = 1;
     875                 :             : 
     876                 :             :   /* All temporary bindings created for cleanups are popped silently.  */
     877                 :   535310015 :   if (kind == sk_cleanup)
     878                 :         294 :     goto restart;
     879                 :             : 
     880                 :  1070619442 :   return block;
     881                 :   535309721 : }
     882                 :             : 
     883                 :             : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
     884                 :             : /* Diagnose odr-used extern inline variables without definitions
     885                 :             :    in the current TU.  */
     886                 :             : 
     887                 :             : int
     888                 :      135687 : wrapup_namespace_globals ()
     889                 :             : {
     890                 :      135687 :   if (vec<tree, va_gc> *statics = static_decls)
     891                 :             :     {
     892                 :    13703284 :       for (tree decl : *statics)
     893                 :             :         {
     894                 :    13591612 :           if (warn_unused_function
     895                 :     1004357 :               && TREE_CODE (decl) == FUNCTION_DECL
     896                 :      759722 :               && DECL_INITIAL (decl) == 0
     897                 :        2486 :               && DECL_EXTERNAL (decl)
     898                 :        2486 :               && !TREE_PUBLIC (decl)
     899                 :          19 :               && !DECL_ARTIFICIAL (decl)
     900                 :          19 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
     901                 :    13591618 :               && !warning_suppressed_p (decl, OPT_Wunused_function))
     902                 :           6 :             warning_at (DECL_SOURCE_LOCATION (decl),
     903                 :             :                         OPT_Wunused_function,
     904                 :             :                         "%qF declared %<static%> but never defined", decl);
     905                 :             : 
     906                 :    13591612 :           if (VAR_P (decl)
     907                 :     4056037 :               && DECL_EXTERNAL (decl)
     908                 :     1946896 :               && DECL_INLINE_VAR_P (decl)
     909                 :    13591630 :               && DECL_ODR_USED (decl))
     910                 :           3 :             error_at (DECL_SOURCE_LOCATION (decl),
     911                 :             :                       "odr-used inline variable %qD is not defined", decl);
     912                 :             :         }
     913                 :             : 
     914                 :             :       /* Clear out the list, so we don't rescan next time.  */
     915                 :      111672 :       static_decls = NULL;
     916                 :             : 
     917                 :             :       /* Write out any globals that need to be output.  */
     918                 :      111672 :       return wrapup_global_declarations (statics->address (),
     919                 :      111672 :                                          statics->length ());
     920                 :             :     }
     921                 :             :   return 0;
     922                 :             : }
     923                 :             : 
     924                 :             : /* In C++, you don't have to write `struct S' to refer to `S'; you
     925                 :             :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
     926                 :             :    if the user had written `typedef struct S S'.  Create and return
     927                 :             :    the TYPE_DECL for TYPE.  */
     928                 :             : 
     929                 :             : tree
     930                 :   140136871 : create_implicit_typedef (tree name, tree type)
     931                 :             : {
     932                 :   140136871 :   tree decl;
     933                 :             : 
     934                 :   140136871 :   decl = build_decl (input_location, TYPE_DECL, name, type);
     935                 :   140136871 :   DECL_ARTIFICIAL (decl) = 1;
     936                 :             :   /* There are other implicit type declarations, like the one *within*
     937                 :             :      a class that allows you to write `S::S'.  We must distinguish
     938                 :             :      amongst these.  */
     939                 :   140136871 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
     940                 :   140136871 :   TYPE_NAME (type) = decl;
     941                 :   140136871 :   TYPE_STUB_DECL (type) = decl;
     942                 :             : 
     943                 :   140136871 :   return decl;
     944                 :             : }
     945                 :             : 
     946                 :             : /* Function-scope local entities that need discriminators.  Each entry
     947                 :             :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
     948                 :             :    smashed, so we cannot rely on DECL_NAME.  */
     949                 :             : 
     950                 :             : static GTY((deletable)) vec<tree, va_gc> *local_entities;
     951                 :             : 
     952                 :             : /* Determine the mangling discriminator of local DECL.  There are
     953                 :             :    generally very few of these in any particular function.  */
     954                 :             : 
     955                 :             : void
     956                 :      665522 : determine_local_discriminator (tree decl, tree name)
     957                 :             : {
     958                 :      665522 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     959                 :      665522 :   retrofit_lang_decl (decl);
     960                 :      665522 :   tree ctx = DECL_CONTEXT (decl);
     961                 :      665522 :   size_t nelts = vec_safe_length (local_entities);
     962                 :      665522 :   if (name == NULL_TREE)
     963                 :      665399 :     name = (TREE_CODE (decl) == TYPE_DECL
     964                 :     1076356 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
     965                 :     1200028 :             ? NULL_TREE : DECL_NAME (decl));
     966                 :    19457716 :   for (size_t i = 0; i < nelts; i += 2)
     967                 :             :     {
     968                 :    18792549 :       tree *pair = &(*local_entities)[i];
     969                 :    18792549 :       tree d = pair[0];
     970                 :    18792549 :       tree n = pair[1];
     971                 :    18792549 :       gcc_checking_assert (d != decl);
     972                 :    18792549 :       if (name == n
     973                 :     3435769 :           && TREE_CODE (decl) == TREE_CODE (d)
     974                 :    22228309 :           && ctx == DECL_CONTEXT (d))
     975                 :             :         {
     976                 :         355 :           tree disc = integer_one_node;
     977                 :         355 :           if (DECL_DISCRIMINATOR (d))
     978                 :         179 :             disc = build_int_cst (TREE_TYPE (disc),
     979                 :         179 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
     980                 :         355 :           DECL_DISCRIMINATOR (decl) = disc;
     981                 :             :           /* Replace the saved decl.  */
     982                 :         355 :           pair[0] = decl;
     983                 :         355 :           decl = NULL_TREE;
     984                 :         355 :           break;
     985                 :             :         }
     986                 :             :     }
     987                 :             : 
     988                 :      665522 :   if (decl)
     989                 :             :     {
     990                 :      665167 :       vec_safe_reserve (local_entities, 2);
     991                 :      665167 :       local_entities->quick_push (decl);
     992                 :      665167 :       local_entities->quick_push (name);
     993                 :             :     }
     994                 :      665522 : }
     995                 :             : 
     996                 :             : 
     997                 :             : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
     998                 :             : 
     999                 :             :    A non-template friend declaration with a requires-clause shall be a
    1000                 :             :    definition. A friend function template with a constraint that depends on a
    1001                 :             :    template parameter from an enclosing template shall be a definition. Such a
    1002                 :             :    constrained friend function or function template declaration does not
    1003                 :             :    declare the same function or function template as a declaration in any other
    1004                 :             :    scope.
    1005                 :             : 
    1006                 :             :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1007                 :             :    member function to avoid collisions.  */
    1008                 :             : 
    1009                 :             : bool
    1010                 :  1301420302 : member_like_constrained_friend_p (tree decl)
    1011                 :             : {
    1012                 :  1301420302 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1013                 :   401653893 :           && DECL_UNIQUE_FRIEND_P (decl)
    1014                 :    71738684 :           && DECL_FRIEND_CONTEXT (decl)
    1015                 :    31848822 :           && get_constraints (decl)
    1016                 :  1301591645 :           && (!DECL_TEMPLATE_INFO (decl)
    1017                 :      171343 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1018                 :         918 :               || (uses_outer_template_parms_in_constraints
    1019                 :         918 :                   (most_general_template (decl)))));
    1020                 :             : }
    1021                 :             : 
    1022                 :             : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1023                 :             :    requires clauses.  */
    1024                 :             : 
    1025                 :             : static bool
    1026                 :     8283152 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1027                 :             : {
    1028                 :             :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1029                 :             :      same function as a declaration in any other scope."  So no need to
    1030                 :             :      actually compare the requirements.  */
    1031                 :     8283152 :   if (member_like_constrained_friend_p (newfn)
    1032                 :     8283152 :       || member_like_constrained_friend_p (oldfn))
    1033                 :         107 :     return false;
    1034                 :             : 
    1035                 :             :   /* Compare only trailing requirements.  */
    1036                 :     8283045 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1037                 :     8283045 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1038                 :     8283045 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1039                 :             :     return false;
    1040                 :             : 
    1041                 :             :   /* Substitution is needed when friends are involved.  */
    1042                 :     8245551 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1043                 :     8245551 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1044                 :             : 
    1045                 :     8245551 :   return cp_tree_equal (reqs1, reqs2);
    1046                 :             : }
    1047                 :             : 
    1048                 :             : /* Two functions of the same name correspond [basic.scope.scope] if
    1049                 :             : 
    1050                 :             :    + both declare functions with the same non-object-parameter-type-list,
    1051                 :             :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1052                 :             :    specified in [temp.friend]), and, if both are non-static members, they have
    1053                 :             :    corresponding object parameters, or
    1054                 :             : 
    1055                 :             :    + both declare function templates with equivalent
    1056                 :             :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1057                 :             :    trailing requires-clauses (if any), and, if both are non-static members,
    1058                 :             :    they have corresponding object parameters.
    1059                 :             : 
    1060                 :             :    This is a subset of decls_match: it identifies declarations that cannot be
    1061                 :             :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1062                 :             : 
    1063                 :             : bool
    1064                 :    77365573 : fns_correspond (tree newdecl, tree olddecl)
    1065                 :             : {
    1066                 :    77365573 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1067                 :             :     return false;
    1068                 :             : 
    1069                 :    71883619 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1070                 :             :     {
    1071                 :    71864639 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1072                 :             :         return 0;
    1073                 :    16667939 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1074                 :    16667939 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1075                 :             :     }
    1076                 :             : 
    1077                 :    16686919 :   tree f1 = TREE_TYPE (newdecl);
    1078                 :    16686919 :   tree f2 = TREE_TYPE (olddecl);
    1079                 :             : 
    1080                 :    16686919 :   int rq1 = type_memfn_rqual (f1);
    1081                 :    16686919 :   int rq2 = type_memfn_rqual (f2);
    1082                 :             : 
    1083                 :             :   /* If only one is a non-static member function, ignore ref-quals.  */
    1084                 :    16686919 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1085                 :             :     rq1 = rq2;
    1086                 :             :   /* Two non-static member functions have corresponding object parameters if:
    1087                 :             :      + exactly one is an implicit object member function with no ref-qualifier
    1088                 :             :      and the types of their object parameters ([dcl.fct]), after removing
    1089                 :             :      top-level references, are the same, or
    1090                 :             :      + their object parameters have the same type.  */
    1091                 :             :   /* ??? We treat member functions of different classes as corresponding even
    1092                 :             :      though that means the object parameters have different types.  */
    1093                 :    16686919 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1094                 :           0 :     rq1 = rq2;
    1095                 :             : 
    1096                 :    16686919 :   bool types_match = rq1 == rq2;
    1097                 :             : 
    1098                 :    16686919 :   if (types_match)
    1099                 :             :     {
    1100                 :    16686919 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1101                 :    16686919 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1102                 :    16686919 :       types_match = compparms (p1, p2);
    1103                 :             :     }
    1104                 :             : 
    1105                 :             :   /* Two function declarations match if either has a requires-clause
    1106                 :             :      then both have a requires-clause and their constraints-expressions
    1107                 :             :      are equivalent.  */
    1108                 :    16686919 :   if (types_match && flag_concepts)
    1109                 :     2551508 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1110                 :             : 
    1111                 :             :   return types_match;
    1112                 :             : }
    1113                 :             : 
    1114                 :             : /* Subroutine of duplicate_decls: return truthvalue of whether
    1115                 :             :    or not types of these decls match.
    1116                 :             : 
    1117                 :             :    For C++, we must compare the parameter list so that `int' can match
    1118                 :             :    `int&' in a parameter position, but `int&' is not confused with
    1119                 :             :    `const int&'.  */
    1120                 :             : 
    1121                 :             : int
    1122                 :   885726202 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1123                 :             : {
    1124                 :   885726202 :   int types_match;
    1125                 :             : 
    1126                 :   885726202 :   if (newdecl == olddecl)
    1127                 :             :     return 1;
    1128                 :             : 
    1129                 :   885670222 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1130                 :             :     /* If the two DECLs are not even the same kind of thing, we're not
    1131                 :             :        interested in their types.  */
    1132                 :             :     return 0;
    1133                 :             : 
    1134                 :   436670615 :   gcc_assert (DECL_P (newdecl));
    1135                 :             : 
    1136                 :   436670615 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1137                 :             :     {
    1138                 :             :       /* Specializations of different templates are different functions
    1139                 :             :          even if they have the same type.  */
    1140                 :   242298453 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1141                 :   242298453 :                  ? DECL_TI_TEMPLATE (newdecl)
    1142                 :   242298453 :                  : NULL_TREE);
    1143                 :   242298453 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1144                 :   242298453 :                  ? DECL_TI_TEMPLATE (olddecl)
    1145                 :   242298453 :                  : NULL_TREE);
    1146                 :   242298453 :       if (t1 != t2)
    1147                 :             :         return 0;
    1148                 :             : 
    1149                 :   239827285 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1150                 :   242854077 :           && ! (DECL_EXTERN_C_P (newdecl)
    1151                 :     3026792 :                 && DECL_EXTERN_C_P (olddecl)))
    1152                 :             :         return 0;
    1153                 :             : 
    1154                 :             :       /* A new declaration doesn't match a built-in one unless it
    1155                 :             :          is also extern "C".  */
    1156                 :   221568504 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1157                 :   221568504 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1158                 :             :         return 0;
    1159                 :             : 
    1160                 :   220906896 :       tree f1 = TREE_TYPE (newdecl);
    1161                 :   220906896 :       tree f2 = TREE_TYPE (olddecl);
    1162                 :   220906896 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1163                 :             :         return 0;
    1164                 :             : 
    1165                 :             :       /* A declaration with deduced return type should use its pre-deduction
    1166                 :             :          type for declaration matching.  */
    1167                 :   220748253 :       tree r2 = fndecl_declared_return_type (olddecl);
    1168                 :   220748253 :       tree r1 = fndecl_declared_return_type (newdecl);
    1169                 :             : 
    1170                 :             :       /* For memchr et al, allow const void* return type (as specified by C++)
    1171                 :             :          when we expect void* (as in C).  */
    1172                 :   220748253 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1173                 :     6043671 :           && DECL_EXTERN_C_P (olddecl)
    1174                 :     3763856 :           && !same_type_p (r1, r2)
    1175                 :          70 :           && TREE_CODE (r1) == POINTER_TYPE
    1176                 :          15 :           && TREE_CODE (r2) == POINTER_TYPE
    1177                 :   220748265 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1178                 :             :         r2 = r1;
    1179                 :             : 
    1180                 :   220748253 :       tree p1 = TYPE_ARG_TYPES (f1);
    1181                 :   220748253 :       tree p2 = TYPE_ARG_TYPES (f2);
    1182                 :             : 
    1183                 :   220748253 :       if (same_type_p (r1, r2))
    1184                 :             :         {
    1185                 :   162106568 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1186                 :   162106538 :               && fndecl_built_in_p (olddecl))
    1187                 :             :             {
    1188                 :          50 :               types_match = self_promoting_args_p (p1);
    1189                 :          50 :               if (p1 == void_list_node)
    1190                 :           3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1191                 :             :             }
    1192                 :             :           else
    1193                 :   162106429 :             types_match =
    1194                 :   162106429 :               compparms (p1, p2)
    1195                 :    25228587 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1196                 :   187334789 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1197                 :     1179472 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1198                 :     1179472 :                                            TREE_TYPE (olddecl)) != 0);
    1199                 :             :         }
    1200                 :             :       else
    1201                 :             :         types_match = 0;
    1202                 :             : 
    1203                 :             :       /* Two function declarations match if either has a requires-clause
    1204                 :             :          then both have a requires-clause and their constraints-expressions
    1205                 :             :          are equivalent.  */
    1206                 :    25228401 :       if (types_match && flag_concepts)
    1207                 :     5731618 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1208                 :             : 
    1209                 :             :       /* The decls dont match if they correspond to two different versions
    1210                 :             :          of the same function.   Disallow extern "C" functions to be
    1211                 :             :          versions for now.  */
    1212                 :    25228401 :       if (types_match
    1213                 :    25177212 :           && !DECL_EXTERN_C_P (newdecl)
    1214                 :    19528398 :           && !DECL_EXTERN_C_P (olddecl)
    1215                 :    44753021 :           && targetm.target_option.function_versions (newdecl, olddecl))
    1216                 :             :         {
    1217                 :        8472 :           if (record_versions)
    1218                 :       16794 :             maybe_version_functions (newdecl, olddecl,
    1219                 :        8397 :                                      (!DECL_FUNCTION_VERSIONED (newdecl)
    1220                 :       15984 :                                       || !DECL_FUNCTION_VERSIONED (olddecl)));
    1221                 :        8472 :           return 0;
    1222                 :             :         }
    1223                 :             :     }
    1224                 :   194372162 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1225                 :             :     {
    1226                 :   193003655 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1227                 :             :         return 0;
    1228                 :             : 
    1229                 :    61846416 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1230                 :    61846416 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1231                 :             : 
    1232                 :    61846416 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1233                 :             :         return 0;
    1234                 :             : 
    1235                 :             :       /* Two template types match if they are the same. Otherwise, compare
    1236                 :             :          the underlying declarations.  */
    1237                 :    61846410 :       if (TREE_CODE (newres) == TYPE_DECL)
    1238                 :          30 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1239                 :             :       else
    1240                 :    61846380 :         types_match = decls_match (newres, oldres);
    1241                 :             :     }
    1242                 :             :   else
    1243                 :             :     {
    1244                 :             :       /* Need to check scope for variable declaration (VAR_DECL).
    1245                 :             :          For typedef (TYPE_DECL), scope is ignored.  */
    1246                 :     1368507 :       if (VAR_P (newdecl)
    1247                 :      917919 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1248                 :             :           /* [dcl.link]
    1249                 :             :              Two declarations for an object with C language linkage
    1250                 :             :              with the same name (ignoring the namespace that qualify
    1251                 :             :              it) that appear in different namespace scopes refer to
    1252                 :             :              the same object.  */
    1253                 :     1538663 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1254                 :             :         return 0;
    1255                 :             : 
    1256                 :     1198399 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1257                 :           3 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1258                 :     1198396 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1259                 :           0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1260                 :     1198396 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1261                 :             :         types_match = 0;
    1262                 :             :       else
    1263                 :     1198396 :         types_match = comptypes (TREE_TYPE (newdecl),
    1264                 :     1198396 :                                  TREE_TYPE (olddecl),
    1265                 :             :                                  COMPARE_REDECLARATION);
    1266                 :             :     }
    1267                 :             : 
    1268                 :             :   return types_match;
    1269                 :             : }
    1270                 :             : 
    1271                 :             : /* Mark DECL as versioned if it isn't already.  */
    1272                 :             : 
    1273                 :             : static void
    1274                 :       16884 : maybe_mark_function_versioned (tree decl)
    1275                 :             : {
    1276                 :       16884 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1277                 :             :     {
    1278                 :         954 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1279                 :             :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1280                 :             :          to include the version marker.  */
    1281                 :         954 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1282                 :          33 :         mangle_decl (decl);
    1283                 :             :     }
    1284                 :       16884 : }
    1285                 :             : 
    1286                 :             : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1287                 :             :    different versions adjust them and return true.
    1288                 :             :    If RECORD is set to true, record function versions.  */
    1289                 :             : 
    1290                 :             : bool
    1291                 :      149803 : maybe_version_functions (tree newdecl, tree olddecl, bool record)
    1292                 :             : {
    1293                 :      149803 :   if (!targetm.target_option.function_versions (newdecl, olddecl))
    1294                 :             :     return false;
    1295                 :             : 
    1296                 :        8424 :   maybe_mark_function_versioned (olddecl);
    1297                 :        8424 :   if (DECL_LOCAL_DECL_P (olddecl))
    1298                 :             :     {
    1299                 :          18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1300                 :          18 :       maybe_mark_function_versioned (olddecl);
    1301                 :             :     }
    1302                 :             : 
    1303                 :        8424 :   maybe_mark_function_versioned (newdecl);
    1304                 :        8424 :   if (DECL_LOCAL_DECL_P (newdecl))
    1305                 :             :     {
    1306                 :             :       /* Unfortunately, we can get here before pushdecl naturally calls
    1307                 :             :          push_local_extern_decl_alias, so we need to call it directly.  */
    1308                 :          18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1309                 :           6 :         push_local_extern_decl_alias (newdecl);
    1310                 :          18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1311                 :          18 :       maybe_mark_function_versioned (newdecl);
    1312                 :             :     }
    1313                 :             : 
    1314                 :        8424 :   if (record)
    1315                 :         837 :     cgraph_node::record_function_versions (olddecl, newdecl);
    1316                 :             : 
    1317                 :             :   return true;
    1318                 :             : }
    1319                 :             : 
    1320                 :             : /* If NEWDECL is `static' and an `extern' was seen previously,
    1321                 :             :    warn about it.  OLDDECL is the previous declaration.
    1322                 :             : 
    1323                 :             :    Note that this does not apply to the C++ case of declaring
    1324                 :             :    a variable `extern const' and then later `const'.
    1325                 :             : 
    1326                 :             :    Don't complain about built-in functions, since they are beyond
    1327                 :             :    the user's control.  */
    1328                 :             : 
    1329                 :             : void
    1330                 :    17350483 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1331                 :             : {
    1332                 :    17350483 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1333                 :    17328268 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1334                 :    13920554 :       || TREE_CODE (newdecl) == CONST_DECL
    1335                 :    13920554 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1336                 :    17350471 :     return;
    1337                 :             : 
    1338                 :             :   /* Don't get confused by static member functions; that's a different
    1339                 :             :      use of `static'.  */
    1340                 :    13920554 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1341                 :    13920554 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1342                 :             :     return;
    1343                 :             : 
    1344                 :             :   /* If the old declaration was `static', or the new one isn't, then
    1345                 :             :      everything is OK.  */
    1346                 :    13765878 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1347                 :             :     return;
    1348                 :             : 
    1349                 :             :   /* It's OK to declare a builtin function as `static'.  */
    1350                 :          12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1351                 :          12 :       && DECL_ARTIFICIAL (olddecl))
    1352                 :             :     return;
    1353                 :             : 
    1354                 :          12 :   auto_diagnostic_group d;
    1355                 :          12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1356                 :             :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1357                 :          12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1358                 :             :             "previous declaration of %qD", olddecl);
    1359                 :          12 : }
    1360                 :             : 
    1361                 :             : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1362                 :             :    function templates.  If their exception specifications do not
    1363                 :             :    match, issue a diagnostic.  */
    1364                 :             : 
    1365                 :             : static void
    1366                 :    16954772 : check_redeclaration_exception_specification (tree new_decl,
    1367                 :             :                                              tree old_decl)
    1368                 :             : {
    1369                 :    16954772 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1370                 :    16954772 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1371                 :             : 
    1372                 :             :   /* Two default specs are equivalent, don't force evaluation.  */
    1373                 :     5869009 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1374                 :    17099744 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1375                 :             :     return;
    1376                 :             : 
    1377                 :    16944811 :   if (!type_dependent_expression_p (old_decl))
    1378                 :             :     {
    1379                 :     9684504 :       maybe_instantiate_noexcept (new_decl);
    1380                 :     9684504 :       maybe_instantiate_noexcept (old_decl);
    1381                 :             :     }
    1382                 :    16944811 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1383                 :    16944811 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1384                 :             : 
    1385                 :             :   /* [except.spec]
    1386                 :             : 
    1387                 :             :      If any declaration of a function has an exception-specification,
    1388                 :             :      all declarations, including the definition and an explicit
    1389                 :             :      specialization, of that function shall have an
    1390                 :             :      exception-specification with the same set of type-ids.  */
    1391                 :    16944811 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1392                 :    13306581 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1393                 :    30251302 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1394                 :             :     {
    1395                 :         326 :       const char *const msg
    1396                 :             :         = G_("declaration of %qF has a different exception specifier");
    1397                 :         326 :       bool complained = true;
    1398                 :         326 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1399                 :         326 :       auto_diagnostic_group d;
    1400                 :             : 
    1401                 :             :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1402                 :         652 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1403                 :           1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1404                 :         328 :                          && (nothrow_spec_p (new_exceptions)
    1405                 :           1 :                              == nothrow_spec_p (old_exceptions)));
    1406                 :             : 
    1407                 :         326 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1408                 :         326 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1409                 :             :         /* Don't fuss about the C library; the C library functions are not
    1410                 :             :            specified to have exception specifications (just behave as if they
    1411                 :             :            have them), but some implementations include them.  */
    1412                 :         233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1413                 :          93 :       else if (!flag_exceptions)
    1414                 :             :         /* We used to silently permit mismatched eh specs with
    1415                 :             :            -fno-exceptions, so only complain if -pedantic.  */
    1416                 :           3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1417                 :          90 :       else if (!new_exceptions || global_new)
    1418                 :             :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1419                 :             :            flag for this; silence the warning by correcting the code.  */
    1420                 :          21 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1421                 :             :       else
    1422                 :          69 :         error_at (new_loc, msg, new_decl);
    1423                 :             : 
    1424                 :         326 :       if (complained)
    1425                 :          96 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1426                 :             :                 "from previous declaration %qF", old_decl);
    1427                 :             : 
    1428                 :             :       /* Copy the old exception specification if new_decl has none.  Unless the
    1429                 :             :          old decl is extern "C", as obscure code might depend on the type of
    1430                 :             :          the new declaration (e.g. noexcept-type19.C).  */
    1431                 :         326 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1432                 :          20 :         TREE_TYPE (new_decl)
    1433                 :          40 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1434                 :         326 :     }
    1435                 :             : }
    1436                 :             : 
    1437                 :             : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1438                 :             :    Otherwise issue diagnostics.  */
    1439                 :             : 
    1440                 :             : bool
    1441                 :    17350964 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1442                 :             : {
    1443                 :    17350964 :   old_decl = STRIP_TEMPLATE (old_decl);
    1444                 :    17350964 :   new_decl = STRIP_TEMPLATE (new_decl);
    1445                 :    17350964 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1446                 :    17328725 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1447                 :             :     return true;
    1448                 :    17328725 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1449                 :    17328725 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1450                 :             :     {
    1451                 :    17293440 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1452                 :             :         return true;
    1453                 :    33910316 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1454                 :    16955158 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1455                 :             :         return true;
    1456                 :             :     }
    1457                 :       35291 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1458                 :             :     {
    1459                 :             :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1460                 :             :          keyword.  */
    1461                 :          61 :       if (flag_implicit_constexpr
    1462                 :          61 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1463                 :           0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1464                 :             :         return true;
    1465                 :          61 :       if (fndecl_built_in_p (old_decl))
    1466                 :             :         {
    1467                 :             :           /* Hide a built-in declaration.  */
    1468                 :           0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1469                 :           0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1470                 :           0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1471                 :           0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1472                 :           0 :           return true;
    1473                 :             :         }
    1474                 :             :       /* 7.1.5 [dcl.constexpr]
    1475                 :             :          Note: An explicit specialization can differ from the template
    1476                 :             :          declaration with respect to the constexpr specifier.  */
    1477                 :          61 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1478                 :          61 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1479                 :             :         return true;
    1480                 :             : 
    1481                 :          42 :       const char *kind = "constexpr";
    1482                 :          42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1483                 :          72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1484                 :             :         kind = "consteval";
    1485                 :          42 :       auto_diagnostic_group d;
    1486                 :          42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1487                 :             :                 "redeclaration %qD differs in %qs "
    1488                 :             :                 "from previous declaration", new_decl,
    1489                 :             :                 kind);
    1490                 :          42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1491                 :             :               "previous declaration %qD", old_decl);
    1492                 :          42 :       return false;
    1493                 :          42 :     }
    1494                 :             :   return true;
    1495                 :             : }
    1496                 :             : 
    1497                 :             : /* DECL is a redeclaration of a function or function template.  If
    1498                 :             :    it does have default arguments issue a diagnostic.  Note: this
    1499                 :             :    function is used to enforce the requirements in C++11 8.3.6 about
    1500                 :             :    no default arguments in redeclarations.  */
    1501                 :             : 
    1502                 :             : static void
    1503                 :    10742786 : check_redeclaration_no_default_args (tree decl)
    1504                 :             : {
    1505                 :    10742786 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1506                 :             : 
    1507                 :    10742786 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1508                 :    31587155 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1509                 :    20844423 :     if (TREE_PURPOSE (t))
    1510                 :             :       {
    1511                 :          54 :         permerror (DECL_SOURCE_LOCATION (decl),
    1512                 :             :                    "redeclaration of %q#D may not have default "
    1513                 :             :                    "arguments", decl);
    1514                 :          54 :         return;
    1515                 :             :       }
    1516                 :             : }
    1517                 :             : 
    1518                 :             : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1519                 :             :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1520                 :             :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1521                 :             :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1522                 :             :    "If a friend declaration specifies a default argument expression, that
    1523                 :             :    declaration shall be a definition and shall be the only declaration of
    1524                 :             :    the function or function template in the translation unit."  */
    1525                 :             : 
    1526                 :             : static void
    1527                 :     5380894 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1528                 :             : {
    1529                 :    10419770 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1530                 :             :     return;
    1531                 :             : 
    1532                 :     1906700 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1533                 :      953350 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1534                 :     2556616 :        t1 && t1 != void_list_node;
    1535                 :     1603266 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1536                 :     2251128 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1537                 :     4389239 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1538                 :             :       {
    1539                 :          21 :         auto_diagnostic_group d;
    1540                 :          21 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1541                 :             :                        "friend declaration of %q#D specifies default "
    1542                 :             :                        "arguments and isn%'t the only declaration", newdecl))
    1543                 :          21 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1544                 :             :                   "previous declaration of %q#D", olddecl);
    1545                 :          21 :         return;
    1546                 :          21 :       }
    1547                 :             : }
    1548                 :             : 
    1549                 :             : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1550                 :             :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1551                 :             : 
    1552                 :             : static void
    1553                 :    16398737 : merge_attribute_bits (tree newdecl, tree olddecl)
    1554                 :             : {
    1555                 :    16398737 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1556                 :    16398737 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1557                 :    16398737 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1558                 :    16398737 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1559                 :    16398737 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1560                 :    16398737 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1561                 :    16398737 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1562                 :    16398737 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1563                 :    16398737 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1564                 :    16398737 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1565                 :    16398737 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1566                 :    16398737 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1567                 :    16398737 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1568                 :    16398737 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1569                 :    16398737 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1570                 :    16398737 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1571                 :    16398737 : }
    1572                 :             : 
    1573                 :             : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1574                 :             :                           && lookup_attribute ("gnu_inline",          \
    1575                 :             :                                                DECL_ATTRIBUTES (fn)))
    1576                 :             : 
    1577                 :             : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1578                 :             :    ambiguates olddecl.  Returns true if an error occurs.  */
    1579                 :             : 
    1580                 :             : static bool
    1581                 :   189595875 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1582                 :             : {
    1583                 :   189595875 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1584                 :   189595875 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1585                 :             :   /* Function template declarations can be differentiated by parameter
    1586                 :             :      and return type.  */
    1587                 :   189595875 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1588                 :   189595875 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1589                 :   189595875 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1590                 :             :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1591                 :             :     {
    1592                 :             :       /* ... and also by their template-heads and requires-clauses.  */
    1593                 :        3096 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1594                 :        3096 :           && function_requirements_equivalent_p (newres, oldres))
    1595                 :             :         {
    1596                 :           0 :           auto_diagnostic_group d;
    1597                 :           0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1598                 :           0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1599                 :             :                   "old declaration %q#D", olddecl);
    1600                 :           0 :           return true;
    1601                 :           0 :         }
    1602                 :             : 
    1603                 :             :       /* FIXME: The types are the same but the are differences
    1604                 :             :          in either the template heads or function requirements.
    1605                 :             :          We should be able to diagnose a set of common errors
    1606                 :             :          stemming from these declarations. For example:
    1607                 :             : 
    1608                 :             :            template<typename T> requires C void f(...);
    1609                 :             :            template<typename T> void f(...) requires C;
    1610                 :             : 
    1611                 :             :          These are functionally equivalent but not equivalent.  */
    1612                 :             :     }
    1613                 :             : 
    1614                 :             :   return false;
    1615                 :             : }
    1616                 :             : 
    1617                 :             : /* OLD_PARMS is the innermost set of template parameters for some template
    1618                 :             :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1619                 :             :    for a redeclaration of that template.  Merge the default arguments within
    1620                 :             :    these two sets of parameters.  CLASS_P is true iff the template in
    1621                 :             :    question is a class template.  */
    1622                 :             : 
    1623                 :             : bool
    1624                 :     7626426 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1625                 :             : {
    1626                 :     7626426 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1627                 :             :                        == TREE_VEC_LENGTH (old_parms));
    1628                 :    21569697 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1629                 :             :     {
    1630                 :    13943283 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1631                 :    13943283 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1632                 :    13943283 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1633                 :    13943283 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1634                 :    13943283 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1635                 :             :         return false;
    1636                 :    13943280 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1637                 :             :         {
    1638                 :           9 :           auto_diagnostic_group d;
    1639                 :           9 :           error ("redefinition of default argument for %q+#D", new_parm);
    1640                 :           9 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1641                 :             :                   "original definition appeared here");
    1642                 :           9 :           return false;
    1643                 :           9 :         }
    1644                 :    13943271 :       else if (new_default != NULL_TREE)
    1645                 :             :         /* Update the previous template parameters (which are the ones
    1646                 :             :            that will really count) with the new default value.  */
    1647                 :      187248 :         old_default = new_default;
    1648                 :    13756023 :       else if (class_p && old_default != NULL_TREE)
    1649                 :             :         /* Update the new parameters, too; they'll be used as the
    1650                 :             :            parameters for any members.  */
    1651                 :      936273 :         new_default = old_default;
    1652                 :             :     }
    1653                 :             :   return true;
    1654                 :             : }
    1655                 :             : 
    1656                 :             : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1657                 :             :    If the redeclaration is invalid, a diagnostic is issued, and the
    1658                 :             :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1659                 :             : 
    1660                 :             :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1661                 :             :    returned.
    1662                 :             : 
    1663                 :             :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1664                 :             :    if the old decl was hidden.
    1665                 :             : 
    1666                 :             :    Hidden decls can be anticipated builtins, injected friends, or
    1667                 :             :    (coming soon) injected from a local-extern decl.   */
    1668                 :             : 
    1669                 :             : tree
    1670                 :   320338828 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1671                 :             : {
    1672                 :   320338828 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1673                 :   320338828 :   int types_match = 0;
    1674                 :   320338828 :   int new_defines_function = 0;
    1675                 :   320338828 :   tree new_template_info;
    1676                 :   320338828 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1677                 :   320338828 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1678                 :             : 
    1679                 :   320338828 :   if (newdecl == olddecl)
    1680                 :             :     return olddecl;
    1681                 :             : 
    1682                 :   319510507 :   types_match = decls_match (newdecl, olddecl);
    1683                 :             : 
    1684                 :             :   /* If either the type of the new decl or the type of the old decl is an
    1685                 :             :      error_mark_node, then that implies that we have already issued an
    1686                 :             :      error (earlier) for some bogus type specification, and in that case,
    1687                 :             :      it is rather pointless to harass the user with yet more error message
    1688                 :             :      about the same declaration, so just pretend the types match here.  */
    1689                 :   319510507 :   if (TREE_TYPE (newdecl) == error_mark_node
    1690                 :   319510507 :       || TREE_TYPE (olddecl) == error_mark_node)
    1691                 :             :     return error_mark_node;
    1692                 :             : 
    1693                 :             :   /* Check for redeclaration and other discrepancies.  */
    1694                 :   319510481 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1695                 :   319510481 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1696                 :             :     {
    1697                 :     5906338 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1698                 :             :         {
    1699                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1700                 :             :              explicitly declared.  */
    1701                 :      180072 :           if (was_hidden)
    1702                 :             :             {
    1703                 :      180044 :               if (TREE_PUBLIC (newdecl)
    1704                 :      180044 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1705                 :          12 :                 warning_at (newdecl_loc,
    1706                 :             :                             OPT_Wbuiltin_declaration_mismatch,
    1707                 :             :                             "built-in function %qD declared as non-function",
    1708                 :             :                             newdecl);
    1709                 :      180044 :               return NULL_TREE;
    1710                 :             :             }
    1711                 :             : 
    1712                 :             :           /* If you declare a built-in or predefined function name as static,
    1713                 :             :              the old definition is overridden, but optionally warn this was a
    1714                 :             :              bad choice of name.  */
    1715                 :          28 :           if (! TREE_PUBLIC (newdecl))
    1716                 :             :             {
    1717                 :          56 :               warning_at (newdecl_loc,
    1718                 :             :                           OPT_Wshadow,
    1719                 :          28 :                           fndecl_built_in_p (olddecl)
    1720                 :             :                           ? G_("shadowing built-in function %q#D")
    1721                 :             :                           : G_("shadowing library function %q#D"), olddecl);
    1722                 :             :               /* Discard the old built-in function.  */
    1723                 :          28 :               return NULL_TREE;
    1724                 :             :             }
    1725                 :             :           /* If the built-in is not ansi, then programs can override
    1726                 :             :              it even globally without an error.  */
    1727                 :           0 :           else if (! fndecl_built_in_p (olddecl))
    1728                 :           0 :             warning_at (newdecl_loc, 0,
    1729                 :             :                         "library function %q#D redeclared as non-function %q#D",
    1730                 :             :                         olddecl, newdecl);
    1731                 :             :           else
    1732                 :           0 :             error_at (newdecl_loc,
    1733                 :             :                       "declaration of %q#D conflicts with built-in "
    1734                 :             :                       "declaration %q#D", newdecl, olddecl);
    1735                 :           0 :           return NULL_TREE;
    1736                 :             :         }
    1737                 :     5726266 :       else if (!types_match)
    1738                 :             :         {
    1739                 :             :           /* Avoid warnings redeclaring built-ins which have not been
    1740                 :             :              explicitly declared.  */
    1741                 :     2088036 :           if (was_hidden)
    1742                 :             :             {
    1743                 :      799345 :               tree t1, t2;
    1744                 :             : 
    1745                 :             :               /* A new declaration doesn't match a built-in one unless it
    1746                 :             :                  is also extern "C".  */
    1747                 :      799345 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1748                 :      799345 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1749                 :      799345 :               if (!DECL_EXTERN_C_P (newdecl))
    1750                 :             :                 return NULL_TREE;
    1751                 :             : 
    1752                 :      137737 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1753                 :      137737 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1754                 :      236468 :                    t1 || t2;
    1755                 :       98731 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1756                 :             :                 {
    1757                 :      236450 :                   if (!t1 || !t2)
    1758                 :             :                     break;
    1759                 :             :                   /* FILE, tm types are not known at the time
    1760                 :             :                      we create the builtins.  */
    1761                 :      734836 :                   for (unsigned i = 0;
    1762                 :      971124 :                        i < sizeof (builtin_structptr_types)
    1763                 :             :                            / sizeof (builtin_structptr_type);
    1764                 :             :                        ++i)
    1765                 :      872387 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    1766                 :             :                       {
    1767                 :      137551 :                         tree t = TREE_VALUE (t1);
    1768                 :             : 
    1769                 :      137551 :                         if (TYPE_PTR_P (t)
    1770                 :      275102 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    1771                 :      137551 :                             == get_identifier (builtin_structptr_types[i].str)
    1772                 :      275087 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    1773                 :             :                           {
    1774                 :      137536 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1775                 :             : 
    1776                 :      137536 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    1777                 :      137536 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    1778                 :      137536 :                             types_match = decls_match (newdecl, olddecl);
    1779                 :      137536 :                             if (types_match)
    1780                 :      137536 :                               return duplicate_decls (newdecl, olddecl,
    1781                 :      137536 :                                                       hiding, was_hidden);
    1782                 :           0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    1783                 :             :                           }
    1784                 :          15 :                         goto next_arg;
    1785                 :             :                       }
    1786                 :             : 
    1787                 :       98737 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1788                 :             :                     break;
    1789                 :       98731 :                 next_arg:;
    1790                 :             :                 }
    1791                 :             : 
    1792                 :         201 :               warning_at (newdecl_loc,
    1793                 :             :                           OPT_Wbuiltin_declaration_mismatch,
    1794                 :             :                           "declaration of %q#D conflicts with built-in "
    1795                 :             :                           "declaration %q#D", newdecl, olddecl);
    1796                 :             :             }
    1797                 :     1288691 :           else if ((DECL_EXTERN_C_P (newdecl)
    1798                 :          15 :                     && DECL_EXTERN_C_P (olddecl))
    1799                 :     2577367 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1800                 :     1288676 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    1801                 :             :             {
    1802                 :             :               /* Don't really override olddecl for __* prefixed builtins
    1803                 :             :                  except for __[^b]*_chk, the compiler might be using those
    1804                 :             :                  explicitly.  */
    1805                 :          15 :               if (fndecl_built_in_p (olddecl))
    1806                 :             :                 {
    1807                 :          15 :                   tree id = DECL_NAME (olddecl);
    1808                 :          15 :                   const char *name = IDENTIFIER_POINTER (id);
    1809                 :          15 :                   size_t len;
    1810                 :             : 
    1811                 :          15 :                   if (name[0] == '_'
    1812                 :          15 :                       && name[1] == '_'
    1813                 :          30 :                       && (startswith (name + 2, "builtin_")
    1814                 :           6 :                           || (len = strlen (name)) <= strlen ("___chk")
    1815                 :           6 :                           || memcmp (name + len - strlen ("_chk"),
    1816                 :             :                                      "_chk", strlen ("_chk") + 1) != 0))
    1817                 :             :                     {
    1818                 :          15 :                       if (DECL_INITIAL (newdecl))
    1819                 :             :                         {
    1820                 :           6 :                           error_at (newdecl_loc,
    1821                 :             :                                     "definition of %q#D ambiguates built-in "
    1822                 :             :                                     "declaration %q#D", newdecl, olddecl);
    1823                 :           6 :                           return error_mark_node;
    1824                 :             :                         }
    1825                 :           9 :                       auto_diagnostic_group d;
    1826                 :           9 :                       if (permerror (newdecl_loc,
    1827                 :             :                                      "new declaration %q#D ambiguates built-in"
    1828                 :             :                                      " declaration %q#D", newdecl, olddecl)
    1829                 :           9 :                           && flag_permissive)
    1830                 :           3 :                         inform (newdecl_loc,
    1831                 :             :                                 "ignoring the %q#D declaration", newdecl);
    1832                 :           9 :                       return flag_permissive ? olddecl : error_mark_node;
    1833                 :           9 :                     }
    1834                 :             :                 }
    1835                 :             : 
    1836                 :             :               /* A near match; override the builtin.  */
    1837                 :             : 
    1838                 :           0 :               if (TREE_PUBLIC (newdecl))
    1839                 :           0 :                 warning_at (newdecl_loc,
    1840                 :             :                             OPT_Wbuiltin_declaration_mismatch,
    1841                 :             :                             "new declaration %q#D ambiguates built-in "
    1842                 :             :                             "declaration %q#D", newdecl, olddecl);
    1843                 :             :               else
    1844                 :           0 :                 warning (OPT_Wshadow,
    1845                 :             :                          fndecl_built_in_p (olddecl)
    1846                 :             :                          ? G_("shadowing built-in function %q#D")
    1847                 :             :                          : G_("shadowing library function %q#D"), olddecl);
    1848                 :             :             }
    1849                 :             :           else
    1850                 :             :             /* Discard the old built-in function.  */
    1851                 :             :             return NULL_TREE;
    1852                 :             : 
    1853                 :             :           /* Replace the old RTL to avoid problems with inlining.  */
    1854                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    1855                 :             :         }
    1856                 :             :       else
    1857                 :             :         {
    1858                 :             :           /* Even if the types match, prefer the new declarations type
    1859                 :             :              for built-ins which have not been explicitly declared,
    1860                 :             :              for exception lists, etc...  */
    1861                 :     3638230 :           tree type = TREE_TYPE (newdecl);
    1862                 :     3638230 :           tree attribs = (*targetm.merge_type_attributes)
    1863                 :     3638230 :             (TREE_TYPE (olddecl), type);
    1864                 :             : 
    1865                 :     3638230 :           type = cp_build_type_attribute_variant (type, attribs);
    1866                 :     3638230 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    1867                 :             :         }
    1868                 :             : 
    1869                 :             :       /* If a function is explicitly declared "throw ()", propagate that to
    1870                 :             :          the corresponding builtin.  */
    1871                 :     3638431 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    1872                 :     3488507 :           && was_hidden
    1873                 :     3488464 :           && TREE_NOTHROW (newdecl)
    1874                 :     6878135 :           && !TREE_NOTHROW (olddecl))
    1875                 :             :         {
    1876                 :       28003 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    1877                 :       28003 :           tree tmpdecl = builtin_decl_explicit (fncode);
    1878                 :       28003 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    1879                 :       28003 :             TREE_NOTHROW (tmpdecl)  = 1;
    1880                 :             :         }
    1881                 :             : 
    1882                 :             :       /* Whether or not the builtin can throw exceptions has no
    1883                 :             :          bearing on this declarator.  */
    1884                 :     3638431 :       TREE_NOTHROW (olddecl) = 0;
    1885                 :             : 
    1886                 :     3638431 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    1887                 :             :         {
    1888                 :             :           /* If a builtin function is redeclared as `static', merge
    1889                 :             :              the declarations, but make the original one static.  */
    1890                 :           3 :           DECL_THIS_STATIC (olddecl) = 1;
    1891                 :           3 :           TREE_PUBLIC (olddecl) = 0;
    1892                 :             : 
    1893                 :             :           /* Make the old declaration consistent with the new one so
    1894                 :             :              that all remnants of the builtin-ness of this function
    1895                 :             :              will be banished.  */
    1896                 :           3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    1897                 :           3 :           COPY_DECL_RTL (newdecl, olddecl);
    1898                 :             :         }
    1899                 :             :     }
    1900                 :   313604143 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    1901                 :             :     {
    1902                 :             :       /* C++ Standard, 3.3, clause 4:
    1903                 :             :          "[Note: a namespace name or a class template name must be unique
    1904                 :             :          in its declarative region (7.3.2, clause 14). ]"  */
    1905                 :    77921484 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    1906                 :    77921463 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1907                 :             :         /* Namespace conflicts with not namespace.  */;
    1908                 :    45208247 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    1909                 :   123129698 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    1910                 :             :         /* Class template conflicts.  */;
    1911                 :    77921445 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    1912                 :    45208247 :                 && DECL_TEMPLATE_RESULT (olddecl)
    1913                 :    45208247 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    1914                 :   123129686 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    1915                 :    32672131 :                    && DECL_TEMPLATE_RESULT (newdecl)
    1916                 :    32672131 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    1917                 :             :         /* Variable template conflicts.  */;
    1918                 :    77921436 :       else if (concept_definition_p (olddecl)
    1919                 :   155842866 :                || concept_definition_p (newdecl))
    1920                 :             :         /* Concept conflicts.  */;
    1921                 :    77921424 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    1922                 :    45246874 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    1923                 :    77960063 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    1924                 :    32672138 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    1925                 :             :         {
    1926                 :             :           /* One is a function and the other is a template
    1927                 :             :              function.  */
    1928                 :    77880342 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    1929                 :             :             return NULL_TREE;
    1930                 :             : 
    1931                 :             :           /* There can only be one!  */
    1932                 :       57793 :           auto_diagnostic_group d;
    1933                 :       57793 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    1934                 :       57793 :               && check_raw_literal_operator (olddecl))
    1935                 :           3 :             error_at (newdecl_loc,
    1936                 :             :                       "literal operator %q#D conflicts with"
    1937                 :             :                       " raw literal operator", newdecl);
    1938                 :       57790 :           else if (check_raw_literal_operator (newdecl))
    1939                 :           3 :             error_at (newdecl_loc,
    1940                 :             :                       "raw literal operator %q#D conflicts with"
    1941                 :             :                       " literal operator template", newdecl);
    1942                 :             :           else
    1943                 :             :             return NULL_TREE;
    1944                 :             : 
    1945                 :           6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1946                 :           6 :           return error_mark_node;
    1947                 :       57793 :         }
    1948                 :       41082 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    1949                 :             :         /* A structured binding must be unique in its declarative region.  */;
    1950                 :       38777 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1951                 :       41079 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    1952                 :             :         /* One is an implicit typedef, that's ok.  */
    1953                 :             :         return NULL_TREE;
    1954                 :             : 
    1955                 :         147 :       auto_diagnostic_group d;
    1956                 :         147 :       error ("%q#D redeclared as different kind of entity", newdecl);
    1957                 :         147 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1958                 :             : 
    1959                 :         147 :       return error_mark_node;
    1960                 :         147 :     }
    1961                 :   235682659 :   else if (!types_match)
    1962                 :             :     {
    1963                 :   221940633 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    1964                 :             :         /* These are certainly not duplicate declarations; they're
    1965                 :             :            from different scopes.  */
    1966                 :             :         return NULL_TREE;
    1967                 :             : 
    1968                 :   221940579 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1969                 :             :         {
    1970                 :   189595893 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1971                 :   189595893 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1972                 :             : 
    1973                 :             :           /* The name of a class template may not be declared to refer to
    1974                 :             :              any other template, class, function, object, namespace, value,
    1975                 :             :              or type in the same scope.  */
    1976                 :   189595893 :           if (TREE_CODE (oldres) == TYPE_DECL
    1977                 :   189595887 :               || TREE_CODE (newres) == TYPE_DECL)
    1978                 :             :             {
    1979                 :           9 :               auto_diagnostic_group d;
    1980                 :           9 :               error_at (newdecl_loc,
    1981                 :             :                         "conflicting declaration of template %q#D", newdecl);
    1982                 :           9 :               inform (olddecl_loc,
    1983                 :             :                       "previous declaration %q#D", olddecl);
    1984                 :           9 :               return error_mark_node;
    1985                 :           9 :             }
    1986                 :             : 
    1987                 :   189595884 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    1988                 :   189595875 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    1989                 :             :             {
    1990                 :   189595875 :               if (duplicate_function_template_decls (newdecl, olddecl))
    1991                 :           0 :                 return error_mark_node;
    1992                 :             :               return NULL_TREE;
    1993                 :             :             }
    1994                 :             :           return NULL_TREE;
    1995                 :             :         }
    1996                 :    32344686 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1997                 :             :         {
    1998                 :    32344575 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    1999                 :             :             {
    2000                 :          57 :               auto_diagnostic_group d;
    2001                 :          57 :               error_at (newdecl_loc,
    2002                 :             :                         "conflicting declaration of C function %q#D",
    2003                 :             :                         newdecl);
    2004                 :          57 :               inform (olddecl_loc,
    2005                 :             :                       "previous declaration %q#D", olddecl);
    2006                 :          57 :               return error_mark_node;
    2007                 :          57 :             }
    2008                 :             :           /* For function versions, params and types match, but they
    2009                 :             :              are not ambiguous.  */
    2010                 :    32344518 :           else if ((!DECL_FUNCTION_VERSIONED (newdecl)
    2011                 :    32336670 :                     && !DECL_FUNCTION_VERSIONED (olddecl))
    2012                 :             :                    /* Let constrained hidden friends coexist for now, we'll
    2013                 :             :                       check satisfaction later.  */
    2014                 :    32336670 :                    && !member_like_constrained_friend_p (newdecl)
    2015                 :    32219820 :                    && !member_like_constrained_friend_p (olddecl)
    2016                 :             :                    // The functions have the same parameter types.
    2017                 :    32207089 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2018                 :    32207089 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2019                 :             :                    // And the same constraints.
    2020                 :    32344581 :                    && equivalently_constrained (newdecl, olddecl))
    2021                 :             :             {
    2022                 :          63 :               auto_diagnostic_group d;
    2023                 :          63 :               error_at (newdecl_loc,
    2024                 :             :                         "ambiguating new declaration of %q#D", newdecl);
    2025                 :          63 :               inform (olddecl_loc,
    2026                 :             :                       "old declaration %q#D", olddecl);
    2027                 :          63 :               return error_mark_node;
    2028                 :          63 :             }
    2029                 :             :           else
    2030                 :    32344455 :             return NULL_TREE;
    2031                 :             :         }
    2032                 :             :       else
    2033                 :             :         {
    2034                 :         111 :           auto_diagnostic_group d;
    2035                 :         111 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2036                 :         111 :           inform (olddecl_loc,
    2037                 :             :                   "previous declaration as %q#D", olddecl);
    2038                 :         111 :           return error_mark_node;
    2039                 :         111 :         }
    2040                 :             :     }
    2041                 :    13742026 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2042                 :    13742026 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2043                 :             :     {
    2044                 :             :       /* OMP UDRs are never duplicates. */
    2045                 :          27 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2046                 :          27 :       auto_diagnostic_group d;
    2047                 :          27 :       error_at (newdecl_loc,
    2048                 :             :                 "redeclaration of %<pragma omp declare reduction%>");
    2049                 :          27 :       inform (olddecl_loc,
    2050                 :             :               "previous %<pragma omp declare reduction%> declaration");
    2051                 :          27 :       return error_mark_node;
    2052                 :          27 :     }
    2053                 :    13741999 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2054                 :    13741999 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2055                 :         220 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2056                 :         220 :                      || (DECL_TI_TEMPLATE (newdecl)
    2057                 :         220 :                          != DECL_TI_TEMPLATE (olddecl))))
    2058                 :     9909167 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2059                 :      556294 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2060                 :      556294 :                         || (DECL_TI_TEMPLATE (olddecl)
    2061                 :      556294 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2062                 :             :     /* It's OK to have a template specialization and a non-template
    2063                 :             :        with the same type, or to have specializations of two
    2064                 :             :        different templates with the same type.  Note that if one is a
    2065                 :             :        specialization, and the other is an instantiation of the same
    2066                 :             :        template, that we do not exit at this point.  That situation
    2067                 :             :        can occur if we instantiate a template class, and then
    2068                 :             :        specialize one of its methods.  This situation is valid, but
    2069                 :             :        the declarations must be merged in the usual way.  */
    2070                 :             :     return NULL_TREE;
    2071                 :    13741999 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2072                 :    13741999 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2073                 :      556134 :                 && !DECL_USE_TEMPLATE (newdecl))
    2074                 :     9909167 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2075                 :          60 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2076                 :             :     /* One of the declarations is a template instantiation, and the
    2077                 :             :        other is not a template at all.  That's OK.  */
    2078                 :             :     return NULL_TREE;
    2079                 :    13741999 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2080                 :             :     {
    2081                 :             :       /* In [namespace.alias] we have:
    2082                 :             : 
    2083                 :             :            In a declarative region, a namespace-alias-definition can be
    2084                 :             :            used to redefine a namespace-alias declared in that declarative
    2085                 :             :            region to refer only to the namespace to which it already
    2086                 :             :            refers.
    2087                 :             : 
    2088                 :             :          Therefore, if we encounter a second alias directive for the same
    2089                 :             :          alias, we can just ignore the second directive.  */
    2090                 :          21 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2091                 :          21 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2092                 :          18 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2093                 :             :         return olddecl;
    2094                 :             : 
    2095                 :             :       /* Leave it to update_binding to merge or report error.  */
    2096                 :             :       return NULL_TREE;
    2097                 :             :     }
    2098                 :             :   else
    2099                 :             :     {
    2100                 :    13741978 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2101                 :    13741978 :       if (errmsg)
    2102                 :             :         {
    2103                 :         523 :           auto_diagnostic_group d;
    2104                 :         523 :           error_at (newdecl_loc, errmsg, newdecl);
    2105                 :         523 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2106                 :         523 :             inform (olddecl_loc,
    2107                 :         523 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2108                 :             :                     ? G_("%q#D previously defined here")
    2109                 :             :                     : G_("%q#D previously declared here"), olddecl);
    2110                 :         523 :           if (cxx_dialect >= cxx26
    2111                 :         138 :               && DECL_NAME (newdecl)
    2112                 :         138 :               && id_equal (DECL_NAME (newdecl), "_")
    2113                 :         536 :               && !name_independent_decl_p (newdecl))
    2114                 :             :             {
    2115                 :          13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2116                 :           2 :                 inform (newdecl_loc,
    2117                 :             :                         "parameter declaration is not name-independent");
    2118                 :          11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2119                 :             :                 {
    2120                 :           3 :                   if (at_namespace_scope_p ())
    2121                 :           2 :                     inform (newdecl_loc,
    2122                 :             :                             "structured binding at namespace scope is not "
    2123                 :             :                             "name-independent");
    2124                 :           1 :                   else if (TREE_STATIC (newdecl))
    2125                 :           1 :                     inform (newdecl_loc,
    2126                 :             :                             "static structured binding is not "
    2127                 :             :                             "name-independent");
    2128                 :           0 :                   else if (DECL_EXTERNAL (newdecl))
    2129                 :           0 :                     inform (newdecl_loc,
    2130                 :             :                             "extern structured binding is not "
    2131                 :             :                             "name-independent");
    2132                 :             :                 }
    2133                 :           8 :               else if (at_class_scope_p ()
    2134                 :             :                        && VAR_P (newdecl)
    2135                 :           8 :                        && TREE_STATIC (newdecl))
    2136                 :           0 :                 inform (newdecl_loc,
    2137                 :             :                         "static data member is not name-independent");
    2138                 :           8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2139                 :           3 :                 inform (newdecl_loc,
    2140                 :             :                         "variable at namespace scope is not name-independent");
    2141                 :           5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2142                 :           3 :                 inform (newdecl_loc,
    2143                 :             :                         "static variable is not name-independent");
    2144                 :           2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2145                 :           0 :                 inform (newdecl_loc,
    2146                 :             :                         "extern variable is not name-independent");
    2147                 :             :             }
    2148                 :         523 :           return error_mark_node;
    2149                 :         523 :         }
    2150                 :    13741455 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2151                 :     9908927 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2152                 :       11406 :                && !prototype_p (TREE_TYPE (olddecl))
    2153                 :    13741455 :                && prototype_p (TREE_TYPE (newdecl)))
    2154                 :             :         {
    2155                 :             :           /* Prototype decl follows defn w/o prototype.  */
    2156                 :           0 :           auto_diagnostic_group d;
    2157                 :           0 :           if (warning_at (newdecl_loc, 0,
    2158                 :             :                           "prototype specified for %q#D", newdecl))
    2159                 :           0 :             inform (olddecl_loc,
    2160                 :             :                     "previous non-prototype definition here");
    2161                 :           0 :         }
    2162                 :    13368214 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2163                 :    23650382 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2164                 :             :         {
    2165                 :             :           /* [dcl.link]
    2166                 :             :              If two declarations of the same function or object
    2167                 :             :              specify different linkage-specifications ..., the program
    2168                 :             :              is ill-formed.... Except for functions with C++ linkage,
    2169                 :             :              a function declaration without a linkage specification
    2170                 :             :              shall not precede the first linkage specification for
    2171                 :             :              that function.  A function can be declared without a
    2172                 :             :              linkage specification after an explicit linkage
    2173                 :             :              specification has been seen; the linkage explicitly
    2174                 :             :              specified in the earlier declaration is not affected by
    2175                 :             :              such a function declaration.
    2176                 :             : 
    2177                 :             :              DR 563 raises the question why the restrictions on
    2178                 :             :              functions should not also apply to objects.  Older
    2179                 :             :              versions of G++ silently ignore the linkage-specification
    2180                 :             :              for this example:
    2181                 :             : 
    2182                 :             :                namespace N {
    2183                 :             :                  extern int i;
    2184                 :             :                  extern "C" int i;
    2185                 :             :                }
    2186                 :             : 
    2187                 :             :              which is clearly wrong.  Therefore, we now treat objects
    2188                 :             :              like functions.  */
    2189                 :        1774 :           if (current_lang_depth () == 0)
    2190                 :             :             {
    2191                 :             :               /* There is no explicit linkage-specification, so we use
    2192                 :             :                  the linkage from the previous declaration.  */
    2193                 :        1768 :               retrofit_lang_decl (newdecl);
    2194                 :        1768 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2195                 :             :             }
    2196                 :             :           else
    2197                 :             :             {
    2198                 :           6 :               auto_diagnostic_group d;
    2199                 :           6 :               error_at (newdecl_loc,
    2200                 :             :                         "conflicting declaration of %q#D with %qL linkage",
    2201                 :           6 :                         newdecl, DECL_LANGUAGE (newdecl));
    2202                 :           6 :               inform (olddecl_loc,
    2203                 :             :                       "previous declaration with %qL linkage",
    2204                 :           6 :                       DECL_LANGUAGE (olddecl));
    2205                 :           6 :             }
    2206                 :             :         }
    2207                 :             : 
    2208                 :    13741455 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2209                 :             :         ;
    2210                 :    13164585 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2211                 :             :         {
    2212                 :             :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2213                 :    10944468 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2214                 :     9352582 :               && (/* grokfndecl passes member function templates too
    2215                 :             :                      as FUNCTION_DECLs.  */
    2216                 :     7915247 :                   DECL_TEMPLATE_INFO (olddecl)
    2217                 :             :                   /* C++11 8.3.6/6.
    2218                 :             :                      Default arguments for a member function of a class
    2219                 :             :                      template shall be specified on the initial declaration
    2220                 :             :                      of the member function within the class template.  */
    2221                 :      636155 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2222                 :             :             {
    2223                 :     7357237 :               check_redeclaration_no_default_args (newdecl);
    2224                 :             : 
    2225                 :     7357237 :               if (DECL_TEMPLATE_INFO (olddecl)
    2226                 :     7357237 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2227                 :             :                 {
    2228                 :     2035358 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2229                 :     2035358 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2230                 :     2035358 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2231                 :     2035358 :                   tree old_parms
    2232                 :     2035358 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2233                 :     2035358 :                   merge_default_template_args (new_parms, old_parms,
    2234                 :             :                                                /*class_p=*/false);
    2235                 :             :                 }
    2236                 :             :             }
    2237                 :             :           else
    2238                 :             :             {
    2239                 :     1995345 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2240                 :     1995345 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2241                 :     1995345 :               int i = 1;
    2242                 :             : 
    2243                 :     5387587 :               for (; t1 && t1 != void_list_node;
    2244                 :     3392242 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2245                 :     3393983 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2246                 :             :                   {
    2247                 :          39 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2248                 :          39 :                                           TREE_PURPOSE (t2)) == 1)
    2249                 :             :                       {
    2250                 :          12 :                         auto_diagnostic_group d;
    2251                 :          12 :                         if (permerror (newdecl_loc,
    2252                 :             :                                        "default argument given for parameter "
    2253                 :             :                                        "%d of %q#D", i, newdecl))
    2254                 :          12 :                           inform (olddecl_loc,
    2255                 :             :                                   "previous specification in %q#D here",
    2256                 :             :                                   olddecl);
    2257                 :          12 :                       }
    2258                 :             :                     else
    2259                 :             :                       {
    2260                 :          27 :                         auto_diagnostic_group d;
    2261                 :          27 :                         error_at (newdecl_loc,
    2262                 :             :                                   "default argument given for parameter %d "
    2263                 :             :                                   "of %q#D", i, newdecl);
    2264                 :          27 :                         inform (olddecl_loc,
    2265                 :             :                                 "previous specification in %q#D here",
    2266                 :             :                                 olddecl);
    2267                 :          27 :                       }
    2268                 :             :                   }
    2269                 :             : 
    2270                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2271                 :             :                  argument expression, that declaration... shall be the only
    2272                 :             :                  declaration of the function or function template in the
    2273                 :             :                  translation unit."  */
    2274                 :     1995345 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2275                 :             :             }
    2276                 :             :         }
    2277                 :             :     }
    2278                 :             : 
    2279                 :             :   /* Do not merge an implicit typedef with an explicit one.  In:
    2280                 :             : 
    2281                 :             :        class A;
    2282                 :             :        ...
    2283                 :             :        typedef class A A __attribute__ ((foo));
    2284                 :             : 
    2285                 :             :      the attribute should apply only to the typedef.  */
    2286                 :    17379886 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2287                 :    17379886 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2288                 :       22218 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2289                 :             :     return NULL_TREE;
    2290                 :             : 
    2291                 :    17350549 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2292                 :             :     return NULL_TREE;
    2293                 :             : 
    2294                 :    17350537 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2295                 :          30 :     return error_mark_node;
    2296                 :             : 
    2297                 :    17350507 :   if (modules_p ()
    2298                 :       76521 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2299                 :    17393856 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2300                 :             :     {
    2301                 :       43349 :       if (!module_may_redeclare (olddecl, newdecl))
    2302                 :          24 :         return error_mark_node;
    2303                 :             : 
    2304                 :       43325 :       if (!hiding)
    2305                 :             :         {
    2306                 :             :           /* The old declaration should match the exportingness of the new
    2307                 :             :              declaration.  But hidden friend declarations just keep the
    2308                 :             :              exportingness of the old declaration; see CWG2588.  */
    2309                 :       39381 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2310                 :       39381 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2311                 :       39339 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2312                 :             :               /* Typedefs are not entities and so are OK to be redeclared
    2313                 :             :                  as exported: see [module.interface]/p6.  */
    2314                 :       39591 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2315                 :             :             {
    2316                 :         198 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2317                 :         198 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2318                 :             :                 {
    2319                 :          15 :                   auto_diagnostic_group d;
    2320                 :          15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2321                 :          15 :                   inform (olddecl_loc,
    2322                 :             :                           "previously declared here without exporting");
    2323                 :          15 :                 }
    2324                 :             :             }
    2325                 :       39183 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2326                 :       17391 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2327                 :             :         }
    2328                 :             :     }
    2329                 :             : 
    2330                 :             :   /* We have committed to returning OLDDECL at this point.  */
    2331                 :             : 
    2332                 :             :   /* If new decl is `static' and an `extern' was seen previously,
    2333                 :             :      warn about it.  */
    2334                 :    17350483 :   warn_extern_redeclared_static (newdecl, olddecl);
    2335                 :             : 
    2336                 :             :   /* True to merge attributes between the declarations, false to
    2337                 :             :      set OLDDECL's attributes to those of NEWDECL (for template
    2338                 :             :      explicit specializations that specify their own attributes
    2339                 :             :      independent of those specified for the primary template).  */
    2340                 :    17350483 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2341                 :    13547313 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2342                 :    17906762 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2343                 :             : 
    2344                 :    17350483 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2345                 :             :     {
    2346                 :    13547313 :       if (merge_attr)
    2347                 :             :         {
    2348                 :    12991239 :           {
    2349                 :    12991239 :             auto_diagnostic_group d;
    2350                 :    12991239 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2351                 :          36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2352                 :             :                       ? G_("previous definition of %qD here")
    2353                 :             :                       : G_("previous declaration of %qD here"), olddecl);
    2354                 :    12991239 :           }
    2355                 :             : 
    2356                 :             :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2357                 :             :              specify the noreturn attribute if any declaration of that function
    2358                 :             :              specifies the noreturn attribute.  */
    2359                 :    12991239 :           tree a;
    2360                 :    12991239 :           if (TREE_THIS_VOLATILE (newdecl)
    2361                 :      105374 :               && !TREE_THIS_VOLATILE (olddecl)
    2362                 :             :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2363                 :          76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2364                 :          54 :               && cxx11_attribute_p (a)
    2365                 :    12991260 :               && get_attribute_namespace (a) == NULL_TREE)
    2366                 :             :             {
    2367                 :           9 :               auto_diagnostic_group d;
    2368                 :           9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2369                 :             :                         "but its first declaration was not", newdecl);
    2370                 :           9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2371                 :           9 :             }
    2372                 :             :         }
    2373                 :             : 
    2374                 :             :       /* Now that functions must hold information normally held
    2375                 :             :          by field decls, there is extra work to do so that
    2376                 :             :          declaration information does not get destroyed during
    2377                 :             :          definition.  */
    2378                 :    13547313 :       if (DECL_VINDEX (olddecl))
    2379                 :      158082 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2380                 :    13547313 :       if (DECL_CONTEXT (olddecl))
    2381                 :    13547313 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2382                 :    13547313 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2383                 :    13547313 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2384                 :    13547313 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2385                 :    13547313 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2386                 :    13547313 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2387                 :    13547313 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2388                 :    13547313 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2389                 :    13547313 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2390                 :    13547313 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2391                 :    13547313 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2392                 :    13547313 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2393                 :     2414547 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2394                 :     4829094 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2395                 :    13547313 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2396                 :             : 
    2397                 :    13547313 :       duplicate_contracts (newdecl, olddecl);
    2398                 :             : 
    2399                 :             :       /* Optionally warn about more than one declaration for the same
    2400                 :             :          name, but don't warn about a function declaration followed by a
    2401                 :             :          definition.  */
    2402                 :          27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2403                 :          27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2404                 :             :           /* Don't warn about extern decl followed by definition.  */
    2405                 :          27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2406                 :             :           /* Don't warn if at least one is/was hidden.  */
    2407                 :          27 :           && !(hiding || was_hidden)
    2408                 :             :           /* Don't warn about declaration followed by specialization.  */
    2409                 :    13547325 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2410                 :           9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2411                 :             :         {
    2412                 :           6 :           auto_diagnostic_group d;
    2413                 :           6 :           if (warning_at (newdecl_loc,
    2414                 :             :                           OPT_Wredundant_decls,
    2415                 :             :                           "redundant redeclaration of %qD in same scope",
    2416                 :             :                           newdecl))
    2417                 :           6 :             inform (olddecl_loc,
    2418                 :             :                     "previous declaration of %qD", olddecl);
    2419                 :           6 :         }
    2420                 :             : 
    2421                 :             :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2422                 :             :          first declaration of the function or, for an explicit specialization
    2423                 :             :          of a function template, the first declaration of that
    2424                 :             :          specialization.  */
    2425                 :    13547313 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2426                 :      556134 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2427                 :             :         {
    2428                 :    12991239 :           if (DECL_DELETED_FN (newdecl))
    2429                 :             :             {
    2430                 :          21 :               auto_diagnostic_group d;
    2431                 :          21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2432                 :             :                            "is not first declaration", newdecl))
    2433                 :          21 :                 inform (olddecl_loc,
    2434                 :             :                         "previous declaration of %qD", olddecl);
    2435                 :          21 :             }
    2436                 :    12991239 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2437                 :    12991239 :           if (DECL_DELETED_FN (olddecl)
    2438                 :           6 :               && DECL_INITIAL (olddecl)
    2439                 :    12991245 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2440                 :           3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2441                 :             :         }
    2442                 :             :     }
    2443                 :             : 
    2444                 :             :   /* Deal with C++: must preserve virtual function table size.  */
    2445                 :    17350483 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2446                 :             :     {
    2447                 :       22215 :       tree newtype = TREE_TYPE (newdecl);
    2448                 :       22215 :       tree oldtype = TREE_TYPE (olddecl);
    2449                 :             : 
    2450                 :       22215 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2451                 :       44430 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2452                 :       55500 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2453                 :       18500 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2454                 :             : 
    2455                 :       22215 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2456                 :             :     }
    2457                 :             : 
    2458                 :             :   /* Copy all the DECL_... slots specified in the new decl except for
    2459                 :             :      any that we copy here from the old type.  */
    2460                 :    17350483 :   if (merge_attr)
    2461                 :    16794409 :     DECL_ATTRIBUTES (newdecl)
    2462                 :    33588818 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2463                 :             :   else
    2464                 :      556074 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2465                 :             : 
    2466                 :    17350483 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2467                 :             :     {
    2468                 :     3407714 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2469                 :     3407714 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2470                 :     3407714 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2471                 :             : 
    2472                 :             :       /* The new decl should not already have gathered any
    2473                 :             :          specializations.  */
    2474                 :     3407714 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2475                 :             : 
    2476                 :             :       /* Make sure the contracts are equivalent.  */
    2477                 :     3407714 :       duplicate_contracts (newdecl, olddecl);
    2478                 :             : 
    2479                 :             :       /* Remove contracts from old_result so they aren't appended to
    2480                 :             :          old_result by the merge function.  */
    2481                 :     3407714 :       remove_contract_attributes (old_result);
    2482                 :             : 
    2483                 :     3407714 :       DECL_ATTRIBUTES (old_result)
    2484                 :     3407714 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2485                 :             : 
    2486                 :     3407714 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2487                 :             :         {
    2488                 :     3407684 :           if (DECL_SOURCE_LOCATION (newdecl)
    2489                 :     3407684 :               != DECL_SOURCE_LOCATION (olddecl))
    2490                 :             :             {
    2491                 :             :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2492                 :             :                  later declarations of a function template.  */
    2493                 :     3385549 :               check_redeclaration_no_default_args (newdecl);
    2494                 :             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2495                 :             :                  argument expression, that declaration... shall be the only
    2496                 :             :                  declaration of the function or function template in the
    2497                 :             :                  translation unit."  */
    2498                 :     3385549 :               check_no_redeclaration_friend_default_args
    2499                 :     3385549 :                 (old_result, new_result);
    2500                 :             : 
    2501                 :     3385549 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2502                 :     3385549 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2503                 :     3385549 :               merge_default_template_args (new_parms, old_parms,
    2504                 :             :                                            /*class_p=*/false);
    2505                 :             :             }
    2506                 :     3407684 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2507                 :     2812696 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2508                 :             : 
    2509                 :     3407684 :           check_default_args (newdecl);
    2510                 :             : 
    2511                 :     6815356 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2512                 :     3407684 :               && DECL_INITIAL (new_result))
    2513                 :             :             {
    2514                 :          24 :               if (DECL_INITIAL (old_result))
    2515                 :          12 :                 DECL_UNINLINABLE (old_result) = 1;
    2516                 :             :               else
    2517                 :          12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2518                 :          24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2519                 :          72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2520                 :          24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2521                 :          48 :               DECL_INTERFACE_KNOWN (old_result)
    2522                 :          24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2523                 :          24 :               DECL_DECLARED_INLINE_P (old_result)
    2524                 :          24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2525                 :          24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2526                 :          24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2527                 :             :             }
    2528                 :             :           else
    2529                 :             :             {
    2530                 :     3407660 :               DECL_DECLARED_INLINE_P (old_result)
    2531                 :     3407660 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2532                 :     3407660 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2533                 :     3407660 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2534                 :     3407660 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2535                 :             : 
    2536                 :     3407660 :               merge_attribute_bits (new_result, old_result);
    2537                 :             :             }
    2538                 :             :         }
    2539                 :             : 
    2540                 :             :       /* Propagate purviewness and importingness as with
    2541                 :             :          set_instantiating_module.  */
    2542                 :     3407714 :       if (modules_p () && DECL_LANG_SPECIFIC (new_result))
    2543                 :             :         {
    2544                 :       22445 :           if (DECL_MODULE_PURVIEW_P (new_result))
    2545                 :       12159 :             DECL_MODULE_PURVIEW_P (old_result) = true;
    2546                 :       22445 :           if (!DECL_MODULE_IMPORT_P (new_result))
    2547                 :       22445 :             DECL_MODULE_IMPORT_P (old_result) = false;
    2548                 :             :         }
    2549                 :             : 
    2550                 :             :       /* If the new declaration is a definition, update the file and
    2551                 :             :          line information on the declaration, and also make
    2552                 :             :          the old declaration the same definition.  */
    2553                 :     3407714 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2554                 :             :         {
    2555                 :     5213198 :           DECL_SOURCE_LOCATION (olddecl)
    2556                 :     5213198 :             = DECL_SOURCE_LOCATION (old_result)
    2557                 :     2606599 :             = DECL_SOURCE_LOCATION (newdecl);
    2558                 :     2606599 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2559                 :     2606599 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2560                 :             :             {
    2561                 :     2606599 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2562                 :     9279385 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2563                 :     6672786 :                 DECL_CONTEXT (p) = old_result;
    2564                 :             : 
    2565                 :     5213198 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2566                 :          14 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2567                 :             :             }
    2568                 :             :         }
    2569                 :             : 
    2570                 :     3407714 :       return olddecl;
    2571                 :             :     }
    2572                 :             : 
    2573                 :    13942769 :   if (types_match)
    2574                 :             :     {
    2575                 :    13942568 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2576                 :    13547112 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2577                 :             : 
    2578                 :             :       /* Automatically handles default parameters.  */
    2579                 :    13942568 :       tree oldtype = TREE_TYPE (olddecl);
    2580                 :    13942568 :       tree newtype;
    2581                 :             : 
    2582                 :             :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2583                 :             :          at newdecl, which will be ggc_freed.  */
    2584                 :    13942568 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2585                 :             :         {
    2586                 :             :           /* But NEWTYPE might have an attribute, honor that.  */
    2587                 :       22215 :           tree tem = TREE_TYPE (newdecl);
    2588                 :       22215 :           newtype = oldtype;
    2589                 :             : 
    2590                 :       22215 :           if (TYPE_USER_ALIGN (tem))
    2591                 :             :             {
    2592                 :          21 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2593                 :           6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2594                 :          21 :               TYPE_USER_ALIGN (newtype) = true;
    2595                 :             :             }
    2596                 :             : 
    2597                 :             :           /* And remove the new type from the variants list.  */
    2598                 :       22215 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2599                 :             :             {
    2600                 :          30 :               tree remove = TREE_TYPE (newdecl);
    2601                 :          30 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2602                 :             :                 {
    2603                 :           9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2604                 :             :                   /* If remove is the main variant, no need to remove that
    2605                 :             :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2606                 :             :                      variants, e.g. created for aligned attribute, might still
    2607                 :             :                      refer to the newdecl TYPE_DECL though, so remove that one
    2608                 :             :                      in that case.  */
    2609                 :           9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2610                 :           6 :                     if (orig != remove)
    2611                 :           6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2612                 :           0 :                            t = TYPE_MAIN_VARIANT (t))
    2613                 :           6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2614                 :             :                           {
    2615                 :          12 :                             TYPE_NEXT_VARIANT (t)
    2616                 :           6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2617                 :           6 :                             break;
    2618                 :             :                           }
    2619                 :             :                 }
    2620                 :             :               else
    2621                 :          21 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2622                 :           0 :                      t = TYPE_NEXT_VARIANT (t))
    2623                 :          21 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2624                 :             :                     {
    2625                 :          21 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2626                 :          21 :                       break;
    2627                 :             :                     }
    2628                 :             :             }
    2629                 :             :         }
    2630                 :    13920353 :       else if (merge_attr)
    2631                 :    13364279 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2632                 :             :       else
    2633                 :      556074 :         newtype = TREE_TYPE (newdecl);
    2634                 :             : 
    2635                 :    13942568 :       if (VAR_P (newdecl))
    2636                 :             :         {
    2637                 :      373241 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2638                 :             :           /* For already initialized vars, TREE_READONLY could have been
    2639                 :             :              cleared in cp_finish_decl, because the var needs runtime
    2640                 :             :              initialization or destruction.  Make sure not to set
    2641                 :             :              TREE_READONLY on it again.  */
    2642                 :      373241 :           if (DECL_INITIALIZED_P (olddecl)
    2643                 :        1213 :               && !DECL_EXTERNAL (olddecl)
    2644                 :      373326 :               && !TREE_READONLY (olddecl))
    2645                 :          30 :             TREE_READONLY (newdecl) = 0;
    2646                 :      373241 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2647                 :      746482 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2648                 :      373241 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2649                 :      373241 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2650                 :      100522 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2651                 :      746482 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2652                 :      373241 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2653                 :      373241 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2654                 :      373241 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2655                 :      746482 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2656                 :      373241 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2657                 :             : 
    2658                 :             :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2659                 :      373241 :           if (DECL_LANG_SPECIFIC (olddecl)
    2660                 :      742877 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2661                 :             :             {
    2662                 :             :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2663                 :          41 :               retrofit_lang_decl (newdecl);
    2664                 :          41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2665                 :             :             }
    2666                 :             :         }
    2667                 :             : 
    2668                 :             :       /* An explicit specialization of a function template or of a member
    2669                 :             :          function of a class template can be declared transaction_safe
    2670                 :             :          independently of whether the corresponding template entity is declared
    2671                 :             :          transaction_safe. */
    2672                 :        1120 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2673                 :        1018 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2674                 :          50 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2675                 :          50 :           && tx_safe_fn_type_p (newtype)
    2676                 :    13942568 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2677                 :           0 :         newtype = tx_unsafe_fn_variant (newtype);
    2678                 :             : 
    2679                 :    13942568 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2680                 :             : 
    2681                 :    13942568 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2682                 :    13547112 :         check_default_args (newdecl);
    2683                 :             : 
    2684                 :             :       /* Lay the type out, unless already done.  */
    2685                 :    13942568 :       if (! same_type_p (newtype, oldtype)
    2686                 :         366 :           && TREE_TYPE (newdecl) != error_mark_node
    2687                 :    13942934 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2688                 :         285 :         layout_type (TREE_TYPE (newdecl));
    2689                 :             : 
    2690                 :    13942568 :       if ((VAR_P (newdecl)
    2691                 :    13569327 :            || TREE_CODE (newdecl) == PARM_DECL
    2692                 :    13569327 :            || TREE_CODE (newdecl) == RESULT_DECL
    2693                 :    13569327 :            || TREE_CODE (newdecl) == FIELD_DECL
    2694                 :    13569327 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2695                 :    13964783 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2696                 :      240510 :         layout_decl (newdecl, 0);
    2697                 :             : 
    2698                 :             :       /* Merge deprecatedness.  */
    2699                 :    13942568 :       if (TREE_DEPRECATED (newdecl))
    2700                 :       11447 :         TREE_DEPRECATED (olddecl) = 1;
    2701                 :             : 
    2702                 :             :       /* Merge unavailability.  */
    2703                 :    13942568 :       if (TREE_UNAVAILABLE (newdecl))
    2704                 :           3 :         TREE_UNAVAILABLE (olddecl) = 1;
    2705                 :             : 
    2706                 :             :       /* Preserve function specific target and optimization options */
    2707                 :    13942568 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2708                 :             :         {
    2709                 :    13547112 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2710                 :    13547112 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2711                 :           0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2712                 :           0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2713                 :             : 
    2714                 :    13547112 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2715                 :    13547112 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2716                 :          31 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2717                 :          31 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2718                 :             : 
    2719                 :    13547112 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2720                 :    13392145 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2721                 :             :         }
    2722                 :             :       else
    2723                 :             :         {
    2724                 :             :           /* Merge the const type qualifier.  */
    2725                 :      395456 :           if (TREE_READONLY (newdecl))
    2726                 :       36565 :             TREE_READONLY (olddecl) = 1;
    2727                 :             :           /* Merge the volatile type qualifier.  */
    2728                 :      395456 :           if (TREE_THIS_VOLATILE (newdecl))
    2729                 :           5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2730                 :             :         }
    2731                 :             : 
    2732                 :             :       /* Merge the initialization information.  */
    2733                 :    13942568 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2734                 :    13942568 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2735                 :             :         {
    2736                 :      168403 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2737                 :      168403 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2738                 :      168403 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2739                 :             :             {
    2740                 :       11325 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2741                 :       11325 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2742                 :             :             }
    2743                 :             :         }
    2744                 :             : 
    2745                 :    13942568 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2746                 :             :         {
    2747                 :    13547112 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2748                 :    13547112 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2749                 :    13547112 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2750                 :    13547112 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2751                 :       50703 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2752                 :    13547112 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2753                 :    13547112 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2754                 :    13547112 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    2755                 :    13547112 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    2756                 :             : 
    2757                 :    13547112 :           if (merge_attr)
    2758                 :    12991038 :             merge_attribute_bits (newdecl, olddecl);
    2759                 :             :           else
    2760                 :             :             {
    2761                 :             :               /* Merge the noreturn bit.  */
    2762                 :      556074 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2763                 :      556074 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2764                 :      556074 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2765                 :      556074 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    2766                 :      556074 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    2767                 :             :             }
    2768                 :             :           /* Keep the old RTL.  */
    2769                 :    13547112 :           COPY_DECL_RTL (olddecl, newdecl);
    2770                 :             :         }
    2771                 :      395456 :       else if (VAR_P (newdecl)
    2772                 :      395456 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    2773                 :             :         {
    2774                 :             :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    2775                 :             :              declaration was for an incomplete object and the new
    2776                 :             :              declaration is not since many attributes of the RTL will
    2777                 :             :              change.  */
    2778                 :      373167 :           COPY_DECL_RTL (olddecl, newdecl);
    2779                 :             :         }
    2780                 :             :     }
    2781                 :             :   /* If cannot merge, then use the new type and qualifiers,
    2782                 :             :      and don't preserve the old rtl.  */
    2783                 :             :   else
    2784                 :             :     {
    2785                 :             :       /* Clean out any memory we had of the old declaration.  */
    2786                 :         201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    2787                 :         201 :       if (oldstatic)
    2788                 :           0 :         TREE_VALUE (oldstatic) = error_mark_node;
    2789                 :             : 
    2790                 :         201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    2791                 :         201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2792                 :         201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2793                 :         201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2794                 :         201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    2795                 :             :     }
    2796                 :             : 
    2797                 :             :   /* Merge the storage class information.  */
    2798                 :    13942769 :   merge_weak (newdecl, olddecl);
    2799                 :             : 
    2800                 :    13942769 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    2801                 :    13942769 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    2802                 :    13942769 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    2803                 :    13942769 :   if (! DECL_EXTERNAL (olddecl))
    2804                 :       26817 :     DECL_EXTERNAL (newdecl) = 0;
    2805                 :    13942769 :   if (! DECL_COMDAT (olddecl))
    2806                 :     5615042 :     DECL_COMDAT (newdecl) = 0;
    2807                 :             : 
    2808                 :    13942769 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    2809                 :             :     {
    2810                 :          75 :       if (!DECL_LOCAL_DECL_P (olddecl))
    2811                 :             :         /* This can happen if olddecl was brought in from the
    2812                 :             :            enclosing namespace via a using-decl.  The new decl is
    2813                 :             :            then not a block-scope extern at all.  */
    2814                 :           3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    2815                 :             :       else
    2816                 :             :         {
    2817                 :          72 :           retrofit_lang_decl (newdecl);
    2818                 :          72 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    2819                 :          72 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    2820                 :          72 :           if (alias != error_mark_node)
    2821                 :             :             {
    2822                 :          69 :               DECL_ATTRIBUTES (alias)
    2823                 :          69 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    2824                 :          69 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2825                 :          39 :                 merge_attribute_bits (newdecl, alias);
    2826                 :             :             }
    2827                 :             :         }
    2828                 :             :     }
    2829                 :             : 
    2830                 :    13942769 :   new_template_info = NULL_TREE;
    2831                 :    13942769 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    2832                 :             :     {
    2833                 :    13916989 :       bool new_redefines_gnu_inline = false;
    2834                 :             : 
    2835                 :    13916989 :       if (new_defines_function
    2836                 :    13916989 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    2837                 :        1230 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    2838                 :     8638745 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    2839                 :           0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    2840                 :             :                       == FUNCTION_DECL))))
    2841                 :        2460 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    2842                 :             : 
    2843                 :             :       if (!new_redefines_gnu_inline)
    2844                 :             :         {
    2845                 :    13916914 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    2846                 :    13916914 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    2847                 :    13916914 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    2848                 :             :         }
    2849                 :             : 
    2850                 :    13916989 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    2851                 :             :         {
    2852                 :    13916915 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    2853                 :    13916915 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    2854                 :    13916915 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    2855                 :             : 
    2856                 :             :           /* If the OLDDECL is an instantiation and/or specialization,
    2857                 :             :              then the NEWDECL must be too.  But, it may not yet be marked
    2858                 :             :              as such if the caller has created NEWDECL, but has not yet
    2859                 :             :              figured out that it is a redeclaration.  */
    2860                 :    13916915 :           if (!DECL_USE_TEMPLATE (newdecl))
    2861                 :    13360567 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    2862                 :             : 
    2863                 :    13916915 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2864                 :    13360617 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    2865                 :    26721234 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    2866                 :             :         }
    2867                 :             : 
    2868                 :             :       /* Don't really know how much of the language-specific
    2869                 :             :          values we should copy from old to new.  */
    2870                 :    13916989 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    2871                 :             : 
    2872                 :    13916989 :       if (LANG_DECL_HAS_MIN (newdecl))
    2873                 :             :         {
    2874                 :    13916989 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    2875                 :    13916989 :           if (DECL_TEMPLATE_INFO (newdecl))
    2876                 :             :             {
    2877                 :      567485 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    2878                 :      567485 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2879                 :      567485 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2880                 :             :                 /* Remember the presence of explicit specialization args.  */
    2881                 :     1112154 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    2882                 :     1112154 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    2883                 :             :             }
    2884                 :             : 
    2885                 :             :           /* We don't want to copy template info from a non-templated friend
    2886                 :             :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    2887                 :    13916989 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    2888                 :             :                                || !non_templated_friend_p (olddecl));
    2889                 :    13916989 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    2890                 :             :         }
    2891                 :             : 
    2892                 :    13916989 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    2893                 :             :         {
    2894                 :             :           /* Only functions have these fields.  */
    2895                 :    13547313 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    2896                 :    13547313 :           DECL_BEFRIENDING_CLASSES (newdecl)
    2897                 :    13547313 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    2898                 :    13547313 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    2899                 :             :           /* DECL_THUNKS is only valid for virtual functions,
    2900                 :             :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    2901                 :    13547313 :           if (DECL_VIRTUAL_P (newdecl))
    2902                 :      638480 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    2903                 :    25817666 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    2904                 :       91640 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    2905                 :             :         }
    2906                 :      369676 :       else if (VAR_P (newdecl))
    2907                 :             :         {
    2908                 :             :           /* Only variables have this field.  */
    2909                 :      369602 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    2910                 :         194 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    2911                 :             :         }
    2912                 :             :     }
    2913                 :             : 
    2914                 :    13942769 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2915                 :             :     {
    2916                 :    13547313 :       tree parm;
    2917                 :             : 
    2918                 :             :       /* Merge parameter attributes. */
    2919                 :    13547313 :       tree oldarg, newarg;
    2920                 :    13547313 :       for (oldarg = DECL_ARGUMENTS(olddecl), newarg = DECL_ARGUMENTS(newdecl);
    2921                 :    38640896 :            oldarg && newarg;
    2922                 :    25093583 :            oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
    2923                 :             :         {
    2924                 :    25093583 :           DECL_ATTRIBUTES (newarg)
    2925                 :    25093583 :             = (*targetm.merge_decl_attributes) (oldarg, newarg);
    2926                 :    25093583 :           DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    2927                 :             :         }
    2928                 :             : 
    2929                 :    13547313 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2930                 :    13547313 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    2931                 :             :         {
    2932                 :             :           /* If newdecl is not a specialization, then it is not a
    2933                 :             :              template-related function at all.  And that means that we
    2934                 :             :              should have exited above, returning 0.  */
    2935                 :      556074 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    2936                 :             : 
    2937                 :      556074 :           if (DECL_ODR_USED (olddecl))
    2938                 :             :             /* From [temp.expl.spec]:
    2939                 :             : 
    2940                 :             :                If a template, a member template or the member of a class
    2941                 :             :                template is explicitly specialized then that
    2942                 :             :                specialization shall be declared before the first use of
    2943                 :             :                that specialization that would cause an implicit
    2944                 :             :                instantiation to take place, in every translation unit in
    2945                 :             :                which such a use occurs.  */
    2946                 :           0 :             error ("explicit specialization of %qD after first use",
    2947                 :             :                       olddecl);
    2948                 :             : 
    2949                 :      556074 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    2950                 :      556074 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    2951                 :     1111995 :                                    && DECL_DECLARED_INLINE_P (newdecl));
    2952                 :             : 
    2953                 :             :           /* Don't propagate visibility from the template to the
    2954                 :             :              specialization here.  We'll do that in determine_visibility if
    2955                 :             :              appropriate.  */
    2956                 :      556074 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    2957                 :             : 
    2958                 :             :           /* [temp.expl.spec/14] We don't inline explicit specialization
    2959                 :             :              just because the primary template says so.  */
    2960                 :      556074 :           gcc_assert (!merge_attr);
    2961                 :             : 
    2962                 :      556074 :           DECL_DECLARED_INLINE_P (olddecl)
    2963                 :      556074 :             = DECL_DECLARED_INLINE_P (newdecl);
    2964                 :             : 
    2965                 :      556074 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2966                 :      556074 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    2967                 :             : 
    2968                 :      556074 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    2969                 :             :         }
    2970                 :    12991239 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    2971                 :             :         {
    2972                 :             :           /* Never inline re-defined extern inline functions.
    2973                 :             :              FIXME: this could be better handled by keeping both
    2974                 :             :              function as separate declarations.  */
    2975                 :          75 :           DECL_UNINLINABLE (newdecl) = 1;
    2976                 :             :         }
    2977                 :             :       else
    2978                 :             :         {
    2979                 :    12991164 :           if (DECL_PENDING_INLINE_P (olddecl))
    2980                 :             :             {
    2981                 :           6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    2982                 :           6 :               DECL_PENDING_INLINE_INFO (newdecl)
    2983                 :          12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    2984                 :             :             }
    2985                 :    12991158 :           else if (DECL_PENDING_INLINE_P (newdecl))
    2986                 :             :             ;
    2987                 :    12991158 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    2988                 :    12991158 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    2989                 :    25982316 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    2990                 :             : 
    2991                 :    12991164 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    2992                 :             : 
    2993                 :    38973492 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    2994                 :    25982328 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    2995                 :             : 
    2996                 :    25982328 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2997                 :    12991164 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2998                 :    12991164 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2999                 :    25600057 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3000                 :             :         }
    3001                 :             : 
    3002                 :             :       /* Preserve abstractness on cloned [cd]tors.  */
    3003                 :    13547313 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3004                 :             : 
    3005                 :             :       /* Update newdecl's parms to point at olddecl.  */
    3006                 :    44111397 :       for (parm = DECL_ARGUMENTS (newdecl); parm;
    3007                 :    30564084 :            parm = DECL_CHAIN (parm))
    3008                 :    30564084 :         DECL_CONTEXT (parm) = olddecl;
    3009                 :             : 
    3010                 :    13547313 :       if (! types_match)
    3011                 :             :         {
    3012                 :         201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3013                 :         201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3014                 :         201 :           COPY_DECL_RTL (newdecl, olddecl);
    3015                 :             :         }
    3016                 :    13547313 :       if (! types_match || new_defines_function)
    3017                 :             :         {
    3018                 :             :           /* These are the final DECL_ARGUMENTS that will be used within the
    3019                 :             :              body; update any references to old DECL_ARGUMENTS in the
    3020                 :             :              contracts, if present.  */
    3021                 :     8640176 :           if (tree contracts = DECL_CONTRACTS (newdecl))
    3022                 :         132 :             remap_contracts (olddecl, newdecl, contracts, true);
    3023                 :             : 
    3024                 :             :           /* These need to be copied so that the names are available.
    3025                 :             :              Note that if the types do match, we'll preserve inline
    3026                 :             :              info and other bits, but if not, we won't.  */
    3027                 :     8640176 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3028                 :     8640176 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3029                 :             : 
    3030                 :             :           /* In some cases, duplicate_contracts will remove contracts from
    3031                 :             :              OLDDECL, to avoid duplications. Sometimes, the contracts end up
    3032                 :             :              shared. If we removed them, re-add them.  */
    3033                 :     8640176 :           if (!DECL_CONTRACTS (olddecl))
    3034                 :     8640129 :             copy_contract_attributes (olddecl, newdecl);
    3035                 :             :         }
    3036                 :             :       /* If redeclaring a builtin function, it stays built in
    3037                 :             :          if newdecl is a gnu_inline definition, or if newdecl is just
    3038                 :             :          a declaration.  */
    3039                 :    13547313 :       if (fndecl_built_in_p (olddecl)
    3040                 :    13603352 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3041                 :             :         {
    3042                 :     3619377 :           copy_decl_built_in_function (newdecl, olddecl);
    3043                 :             :           /* If we're keeping the built-in definition, keep the rtl,
    3044                 :             :              regardless of declaration matches.  */
    3045                 :     3619377 :           COPY_DECL_RTL (olddecl, newdecl);
    3046                 :     3619377 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3047                 :             :             {
    3048                 :     3619371 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3049                 :     3619371 :               if (builtin_decl_explicit_p (fncode))
    3050                 :             :                 {
    3051                 :             :                   /* A compatible prototype of these builtin functions
    3052                 :             :                      is seen, assume the runtime implements it with
    3053                 :             :                      the expected semantics.  */
    3054                 :     3619371 :                   switch (fncode)
    3055                 :             :                     {
    3056                 :       10079 :                     case BUILT_IN_STPCPY:
    3057                 :       10079 :                       set_builtin_decl_implicit_p (fncode, true);
    3058                 :       10079 :                       break;
    3059                 :     3609292 :                     default:
    3060                 :     3609292 :                       set_builtin_decl_declared_p (fncode, true);
    3061                 :     3609292 :                       break;
    3062                 :             :                     }
    3063                 :             :                 }
    3064                 :             : 
    3065                 :     3619371 :               copy_attributes_to_builtin (newdecl);
    3066                 :             :             }
    3067                 :             :         }
    3068                 :    13547313 :       if (new_defines_function)
    3069                 :             :         /* If defining a function declared with other language
    3070                 :             :            linkage, use the previously declared language linkage.  */
    3071                 :     8639975 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3072                 :     4907338 :       else if (types_match)
    3073                 :             :         {
    3074                 :     4907137 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3075                 :             :           /* Don't clear out the arguments if we're just redeclaring a
    3076                 :             :              function.  */
    3077                 :     4907137 :           if (DECL_ARGUMENTS (olddecl))
    3078                 :             :             {
    3079                 :             :               /* If we removed contracts from previous definition, re-attach
    3080                 :             :                  them. Otherwise, rewrite the contracts so they match the
    3081                 :             :                  parameters of the new declaration.  */
    3082                 :     1200195 :               if (DECL_INITIAL (olddecl)
    3083                 :       11218 :                   && DECL_CONTRACTS (newdecl)
    3084                 :     1200206 :                   && !DECL_CONTRACTS (olddecl))
    3085                 :          10 :                 copy_contract_attributes (olddecl, newdecl);
    3086                 :             :               else
    3087                 :             :                 {
    3088                 :             :                   /* Temporarily undo the re-contexting of parameters so we can
    3089                 :             :                      actually remap parameters.  The inliner won't replace
    3090                 :             :                      parameters if we don't do this.  */
    3091                 :     1200185 :                   tree args = DECL_ARGUMENTS (newdecl);
    3092                 :     4493567 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3093                 :     3293382 :                     DECL_CONTEXT (p) = newdecl;
    3094                 :             : 
    3095                 :             :                   /* Save new argument names for use in contracts parsing,
    3096                 :             :                      unless we've already started parsing the body of olddecl
    3097                 :             :                      (particular issues arise when newdecl is from a prior
    3098                 :             :                      friend decl with no argument names, see
    3099                 :             :                      modules/contracts-tpl-friend-1).  */
    3100                 :     1200185 :                   if (tree contracts = DECL_CONTRACTS (olddecl))
    3101                 :          29 :                     remap_contracts (newdecl, olddecl, contracts, true);
    3102                 :             : 
    3103                 :             :                   /* And reverse this operation again. */
    3104                 :     4493567 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    3105                 :     3293382 :                     DECL_CONTEXT (p) = olddecl;
    3106                 :             :                 }
    3107                 :             : 
    3108                 :     1200195 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3109                 :             :             }
    3110                 :             :         }
    3111                 :             :     }
    3112                 :      395456 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3113                 :           0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3114                 :             : 
    3115                 :             :   /* Now preserve various other info from the definition.  */
    3116                 :    13942769 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3117                 :    13942769 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3118                 :    13942769 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3119                 :    13942769 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3120                 :             : 
    3121                 :             :   /* Warn about conflicting visibility specifications.  */
    3122                 :    13942769 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3123                 :     4854508 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3124                 :    13943298 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3125                 :             :     {
    3126                 :          12 :       auto_diagnostic_group d;
    3127                 :          12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3128                 :             :                       "%qD: visibility attribute ignored because it "
    3129                 :             :                       "conflicts with previous declaration", newdecl))
    3130                 :          12 :         inform (olddecl_loc,
    3131                 :             :                 "previous declaration of %qD", olddecl);
    3132                 :          12 :     }
    3133                 :             :   /* Choose the declaration which specified visibility.  */
    3134                 :    13942769 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3135                 :             :     {
    3136                 :     4854508 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3137                 :     4854508 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3138                 :             :     }
    3139                 :             :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3140                 :             :      so keep this behavior.  */
    3141                 :    13942769 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3142                 :             :     {
    3143                 :           4 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3144                 :           4 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3145                 :             :     }
    3146                 :             :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3147                 :    13942769 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3148                 :             :     {
    3149                 :          54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3150                 :          54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3151                 :             :     }
    3152                 :    13942715 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3153                 :    13942715 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3154                 :           3 :     DECL_USER_ALIGN (newdecl) = 1;
    3155                 :             : 
    3156                 :    13942769 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3157                 :    27885538 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3158                 :    13942769 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3159                 :           0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3160                 :             :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3161                 :    13942769 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3162                 :           0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3163                 :             : 
    3164                 :             :   /* Merge module entity mapping information.  */
    3165                 :    13942769 :   if (DECL_LANG_SPECIFIC (olddecl)
    3166                 :    27859792 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3167                 :    13916771 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3168                 :             :     {
    3169                 :         252 :       retrofit_lang_decl (newdecl);
    3170                 :         252 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3171                 :         252 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3172                 :             :     }
    3173                 :             : 
    3174                 :             :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3175                 :             :      with that from NEWDECL below.  */
    3176                 :    13942769 :   if (DECL_LANG_SPECIFIC (olddecl))
    3177                 :             :     {
    3178                 :    13917023 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3179                 :             :                            != DECL_LANG_SPECIFIC (newdecl));
    3180                 :    13917023 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3181                 :             :     }
    3182                 :             : 
    3183                 :             :   /* Merge the USED information.  */
    3184                 :    13942769 :   if (TREE_USED (olddecl))
    3185                 :      468351 :     TREE_USED (newdecl) = 1;
    3186                 :    13474418 :   else if (TREE_USED (newdecl))
    3187                 :          54 :     TREE_USED (olddecl) = 1;
    3188                 :             : 
    3189                 :    13942769 :   if (VAR_P (newdecl))
    3190                 :             :     {
    3191                 :      373241 :       if (DECL_READ_P (olddecl))
    3192                 :       33407 :         DECL_READ_P (newdecl) = 1;
    3193                 :      339834 :       else if (DECL_READ_P (newdecl))
    3194                 :           3 :         DECL_READ_P (olddecl) = 1;
    3195                 :             :     }
    3196                 :             : 
    3197                 :    13942769 :   if (DECL_PRESERVE_P (olddecl))
    3198                 :          48 :     DECL_PRESERVE_P (newdecl) = 1;
    3199                 :    13942721 :   else if (DECL_PRESERVE_P (newdecl))
    3200                 :          63 :     DECL_PRESERVE_P (olddecl) = 1;
    3201                 :             : 
    3202                 :             :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3203                 :             :      to olddecl and deleted.  */
    3204                 :    13942769 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3205                 :    27490082 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3206                 :             :     {
    3207                 :             :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3208                 :         258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3209                 :             :       /* newdecl will be purged after copying to olddecl and is no longer
    3210                 :             :          a version.  */
    3211                 :         258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3212                 :             :     }
    3213                 :             : 
    3214                 :    13942769 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3215                 :             :     {
    3216                 :    13547313 :       int function_size;
    3217                 :    13547313 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3218                 :             : 
    3219                 :    13547313 :       function_size = sizeof (struct tree_decl_common);
    3220                 :             : 
    3221                 :    13547313 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3222                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3223                 :             :               function_size - sizeof (struct tree_common));
    3224                 :             : 
    3225                 :    13547313 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3226                 :             :               (char *) newdecl + sizeof (struct tree_decl_common),
    3227                 :             :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3228                 :             : 
    3229                 :             :       /* Preserve symtab node mapping.  */
    3230                 :    13547313 :       olddecl->decl_with_vis.symtab_node = snode;
    3231                 :             : 
    3232                 :    13547313 :       if (new_template_info)
    3233                 :             :         /* If newdecl is a template instantiation, it is possible that
    3234                 :             :            the following sequence of events has occurred:
    3235                 :             : 
    3236                 :             :            o A friend function was declared in a class template.  The
    3237                 :             :            class template was instantiated.
    3238                 :             : 
    3239                 :             :            o The instantiation of the friend declaration was
    3240                 :             :            recorded on the instantiation list, and is newdecl.
    3241                 :             : 
    3242                 :             :            o Later, however, instantiate_class_template called pushdecl
    3243                 :             :            on the newdecl to perform name injection.  But, pushdecl in
    3244                 :             :            turn called duplicate_decls when it discovered that another
    3245                 :             :            declaration of a global function with the same name already
    3246                 :             :            existed.
    3247                 :             : 
    3248                 :             :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3249                 :             : 
    3250                 :             :            If we're going to do that, we'd better make sure that
    3251                 :             :            olddecl, and not newdecl, is on the list of
    3252                 :             :            instantiations so that if we try to do the instantiation
    3253                 :             :            again we won't get the clobbered declaration.  */
    3254                 :      567470 :         reregister_specialization (newdecl,
    3255                 :             :                                    new_template_info,
    3256                 :             :                                    olddecl);
    3257                 :             :     }
    3258                 :             :   else
    3259                 :             :     {
    3260                 :      395456 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3261                 :             : 
    3262                 :      395456 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3263                 :             :               (char *) newdecl + sizeof (struct tree_common),
    3264                 :             :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3265                 :             : 
    3266                 :      395456 :       switch (TREE_CODE (newdecl))
    3267                 :             :         {
    3268                 :      395456 :         case LABEL_DECL:
    3269                 :      395456 :         case VAR_DECL:
    3270                 :      395456 :         case RESULT_DECL:
    3271                 :      395456 :         case PARM_DECL:
    3272                 :      395456 :         case FIELD_DECL:
    3273                 :      395456 :         case TYPE_DECL:
    3274                 :      395456 :         case CONST_DECL:
    3275                 :      395456 :           {
    3276                 :      395456 :             struct symtab_node *snode = NULL;
    3277                 :             : 
    3278                 :      395456 :             if (VAR_P (newdecl)
    3279                 :      395456 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3280                 :           3 :                     || DECL_EXTERNAL (olddecl)))
    3281                 :      373241 :               snode = symtab_node::get (olddecl);
    3282                 :      395456 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3283                 :             :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3284                 :             :                     size - sizeof (struct tree_decl_common)
    3285                 :      395456 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3286                 :      395456 :             if (VAR_P (newdecl))
    3287                 :      373241 :               olddecl->decl_with_vis.symtab_node = snode;
    3288                 :             :           }
    3289                 :             :           break;
    3290                 :           0 :         default:
    3291                 :           0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3292                 :             :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3293                 :             :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3294                 :           0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3295                 :           0 :           break;
    3296                 :             :         }
    3297                 :             :     }
    3298                 :             : 
    3299                 :    13942769 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3300                 :             :     {
    3301                 :    13920554 :       if (DECL_EXTERNAL (olddecl)
    3302                 :             :           || TREE_PUBLIC (olddecl)
    3303                 :    13920554 :           || TREE_STATIC (olddecl))
    3304                 :             :         {
    3305                 :             :           /* Merge the section attribute.
    3306                 :             :              We want to issue an error if the sections conflict but that must be
    3307                 :             :              done later in decl_attributes since we are called before attributes
    3308                 :             :              are assigned.  */
    3309                 :    13920554 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3310                 :           7 :             set_decl_section_name (olddecl, newdecl);
    3311                 :             : 
    3312                 :    13920554 :           if (DECL_ONE_ONLY (newdecl))
    3313                 :             :             {
    3314                 :           0 :               struct symtab_node *oldsym, *newsym;
    3315                 :           0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3316                 :           0 :                 oldsym = cgraph_node::get_create (olddecl);
    3317                 :             :               else
    3318                 :           0 :                 oldsym = varpool_node::get_create (olddecl);
    3319                 :           0 :               newsym = symtab_node::get (newdecl);
    3320                 :           0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3321                 :             :             }
    3322                 :             :         }
    3323                 :             : 
    3324                 :    13920554 :       if (VAR_P (newdecl)
    3325                 :    13920554 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3326                 :             :         {
    3327                 :         383 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3328                 :         383 :           if (!processing_template_decl)
    3329                 :         368 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3330                 :             :         }
    3331                 :             :     }
    3332                 :             : 
    3333                 :    13942769 :   DECL_UID (olddecl) = olddecl_uid;
    3334                 :             : 
    3335                 :             :   /* NEWDECL contains the merged attribute lists.
    3336                 :             :      Update OLDDECL to be the same.  */
    3337                 :    13942769 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3338                 :             : 
    3339                 :             :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3340                 :             :     so that encode_section_info has a chance to look at the new decl
    3341                 :             :     flags and attributes.  */
    3342                 :    13942769 :   if (DECL_RTL_SET_P (olddecl)
    3343                 :    13942769 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3344                 :           0 :           || (VAR_P (olddecl)
    3345                 :           0 :               && TREE_STATIC (olddecl))))
    3346                 :           0 :     make_decl_rtl (olddecl);
    3347                 :             : 
    3348                 :             :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3349                 :             :      declaration of a member results in a call to duplicate_decls,
    3350                 :             :      freeing these nodes represents in a significant savings.
    3351                 :             : 
    3352                 :             :      Before releasing the node, be sore to remove function from symbol
    3353                 :             :      table that might have been inserted there to record comdat group.
    3354                 :             :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3355                 :             :      structure is shared in between newdecl and oldecl.  */
    3356                 :    13942769 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3357                 :    13547313 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3358                 :    13942769 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3359                 :             :     {
    3360                 :    13920554 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3361                 :    13920554 :       if (snode)
    3362                 :         390 :         snode->remove ();
    3363                 :             :     }
    3364                 :             : 
    3365                 :    13942769 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3366                 :             :     {
    3367                 :    13547313 :       tree clone;
    3368                 :    14044226 :       FOR_EACH_CLONE (clone, olddecl)
    3369                 :             :         {
    3370                 :      496913 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3371                 :      496913 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3372                 :             :         }
    3373                 :             :     }
    3374                 :             : 
    3375                 :             :   /* Remove the associated constraints for newdecl, if any, before
    3376                 :             :      reclaiming memory. */
    3377                 :    13942769 :   if (flag_concepts)
    3378                 :     3135470 :     remove_constraints (newdecl);
    3379                 :             : 
    3380                 :             :   /* And similarly for any module tracking data.  */
    3381                 :    13942769 :   if (modules_p ())
    3382                 :       54052 :     remove_defining_module (newdecl);
    3383                 :             : 
    3384                 :    13942769 :   ggc_free (newdecl);
    3385                 :             : 
    3386                 :    13942769 :   return olddecl;
    3387                 :             : }
    3388                 :             : 
    3389                 :             : /* Return zero if the declaration NEWDECL is valid
    3390                 :             :    when the declaration OLDDECL (assumed to be for the same name)
    3391                 :             :    has already been seen.
    3392                 :             :    Otherwise return an error message format string with a %s
    3393                 :             :    where the identifier should go.  */
    3394                 :             : 
    3395                 :             : static const char *
    3396                 :    13741978 : redeclaration_error_message (tree newdecl, tree olddecl)
    3397                 :             : {
    3398                 :    13742014 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3399                 :             :     {
    3400                 :             :       /* Because C++ can put things into name space for free,
    3401                 :             :          constructs like "typedef struct foo { ... } foo"
    3402                 :             :          would look like an erroneous redeclaration.  */
    3403                 :       51588 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3404                 :             :         return NULL;
    3405                 :             :       else
    3406                 :             :         return G_("redefinition of %q#D");
    3407                 :             :     }
    3408                 :    13690426 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3409                 :             :     {
    3410                 :             :       /* If this is a pure function, its olddecl will actually be
    3411                 :             :          the original initialization to `0' (which we force to call
    3412                 :             :          abort()).  Don't complain about redefinition in this case.  */
    3413                 :    19818334 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3414                 :     9909185 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3415                 :             :         return NULL;
    3416                 :             : 
    3417                 :             :       /* If both functions come from different namespaces, this is not
    3418                 :             :          a redeclaration - this is a conflict with a used function.  */
    3419                 :    19818304 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3420                 :     1527603 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3421                 :     9909155 :           && ! decls_match (olddecl, newdecl))
    3422                 :             :         return G_("%qD conflicts with used function");
    3423                 :             : 
    3424                 :             :       /* We'll complain about linkage mismatches in
    3425                 :             :          warn_extern_redeclared_static.  */
    3426                 :             : 
    3427                 :             :       /* Defining the same name twice is no good.  */
    3428                 :     9909152 :       if (decl_defined_p (olddecl)
    3429                 :     9909152 :           && decl_defined_p (newdecl))
    3430                 :             :         {
    3431                 :         303 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3432                 :             :             return G_("%q#D not declared in class");
    3433                 :         441 :           else if (!GNU_INLINE_P (olddecl)
    3434                 :         387 :                    || GNU_INLINE_P (newdecl))
    3435                 :         222 :             return G_("redefinition of %q#D");
    3436                 :             :         }
    3437                 :             : 
    3438                 :    10550911 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3439                 :             :         {
    3440                 :      597394 :           bool olda = GNU_INLINE_P (olddecl);
    3441                 :      597394 :           bool newa = GNU_INLINE_P (newdecl);
    3442                 :             : 
    3443                 :      597394 :           if (olda != newa)
    3444                 :             :             {
    3445                 :          15 :               if (newa)
    3446                 :             :                 return G_("%q+D redeclared inline with "
    3447                 :             :                           "%<gnu_inline%> attribute");
    3448                 :             :               else
    3449                 :             :                 return G_("%q+D redeclared inline without "
    3450                 :             :                           "%<gnu_inline%> attribute");
    3451                 :             :             }
    3452                 :             :         }
    3453                 :             : 
    3454                 :             :       /* [class.compare.default]: A definition of a comparison operator as
    3455                 :             :          defaulted that appears in a class shall be the first declaration of
    3456                 :             :          that function.  */
    3457                 :     9908915 :       special_function_kind sfk = special_function_p (olddecl);
    3458                 :     9908915 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3459                 :             :         return G_("comparison operator %q+D defaulted after "
    3460                 :             :                   "its first declaration");
    3461                 :             : 
    3462                 :     9908912 :       check_abi_tag_redeclaration
    3463                 :     9908912 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3464                 :     9908912 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3465                 :             : 
    3466                 :     9908912 :       return NULL;
    3467                 :             :     }
    3468                 :     3781259 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3469                 :             :     {
    3470                 :     3407753 :       tree nt, ot;
    3471                 :             : 
    3472                 :     3407753 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3473                 :             :         return G_("redefinition of %q#D");
    3474                 :             : 
    3475                 :     3407747 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3476                 :          36 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3477                 :          36 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3478                 :             : 
    3479                 :     3407711 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3480                 :             :         return NULL;
    3481                 :             : 
    3482                 :     3407699 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3483                 :     3407699 :       if (DECL_TEMPLATE_INFO (nt))
    3484                 :      484356 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3485                 :     3407699 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3486                 :     3407699 :       if (DECL_TEMPLATE_INFO (ot))
    3487                 :     3407699 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3488                 :     6014337 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3489                 :     3407738 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3490                 :          15 :         return G_("redefinition of %q#D");
    3491                 :             : 
    3492                 :     4601485 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3493                 :             :         {
    3494                 :      753925 :           bool olda = GNU_INLINE_P (ot);
    3495                 :      753925 :           bool newa = GNU_INLINE_P (nt);
    3496                 :             : 
    3497                 :      753925 :           if (olda != newa)
    3498                 :             :             {
    3499                 :           0 :               if (newa)
    3500                 :             :                 return G_("%q+D redeclared inline with "
    3501                 :             :                           "%<gnu_inline%> attribute");
    3502                 :             :               else
    3503                 :             :                 return G_("%q+D redeclared inline without "
    3504                 :             :                           "%<gnu_inline%> attribute");
    3505                 :             :             }
    3506                 :             :         }
    3507                 :             : 
    3508                 :             :       /* Core issue #226 (C++11):
    3509                 :             : 
    3510                 :             :            If a friend function template declaration specifies a
    3511                 :             :            default template-argument, that declaration shall be a
    3512                 :             :            definition and shall be the only declaration of the
    3513                 :             :            function template in the translation unit.  */
    3514                 :     3407684 :       if ((cxx_dialect != cxx98)
    3515                 :     3391971 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3516                 :     3615167 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3517                 :             :                                        /*is_primary=*/true,
    3518                 :             :                                        /*is_partial=*/false,
    3519                 :             :                                        /*is_friend_decl=*/2))
    3520                 :             :         return G_("redeclaration of friend %q#D "
    3521                 :             :                   "may not have default template arguments");
    3522                 :             : 
    3523                 :     3407681 :       return NULL;
    3524                 :             :     }
    3525                 :      373506 :   else if (VAR_P (newdecl)
    3526                 :      373422 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3527                 :      373422 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3528                 :      373553 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3529                 :          44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3530                 :          41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3531                 :             :     {
    3532                 :             :       /* Only variables can be thread-local, and all declarations must
    3533                 :             :          agree on this property.  */
    3534                 :           6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3535                 :             :         return G_("thread-local declaration of %q#D follows "
    3536                 :             :                   "non-thread-local declaration");
    3537                 :             :       else
    3538                 :           3 :         return G_("non-thread-local declaration of %q#D follows "
    3539                 :             :                   "thread-local declaration");
    3540                 :             :     }
    3541                 :      373500 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3542                 :             :     {
    3543                 :             :       /* The objects have been declared at namespace scope.  If either
    3544                 :             :          is a member of an anonymous union, then this is an invalid
    3545                 :             :          redeclaration.  For example:
    3546                 :             : 
    3547                 :             :            int i;
    3548                 :             :            union { int i; };
    3549                 :             : 
    3550                 :             :            is invalid.  */
    3551                 :      373350 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3552                 :      746769 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3553                 :             :         return G_("redeclaration of %q#D");
    3554                 :             :       /* If at least one declaration is a reference, there is no
    3555                 :             :          conflict.  For example:
    3556                 :             : 
    3557                 :             :            int i = 3;
    3558                 :             :            extern int i;
    3559                 :             : 
    3560                 :             :          is valid.  */
    3561                 :      373416 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3562                 :             :         return NULL;
    3563                 :             : 
    3564                 :             :       /* Static data member declared outside a class definition
    3565                 :             :          if the variable is defined within the class with constexpr
    3566                 :             :          specifier is declaration rather than definition (and
    3567                 :             :          deprecated).  */
    3568                 :        2806 :       if (cxx_dialect >= cxx17
    3569                 :        2737 :           && VAR_P (olddecl)
    3570                 :        2681 :           && DECL_CLASS_SCOPE_P (olddecl)
    3571                 :        2649 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3572                 :        5443 :           && !DECL_INITIAL (newdecl))
    3573                 :             :         {
    3574                 :        2637 :           DECL_EXTERNAL (newdecl) = 1;
    3575                 :             :           /* For now, only warn with explicit -Wdeprecated.  */
    3576                 :        2637 :           if (OPTION_SET_P (warn_deprecated))
    3577                 :             :             {
    3578                 :          40 :               auto_diagnostic_group d;
    3579                 :          40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3580                 :             :                                 "redundant redeclaration of %<constexpr%> "
    3581                 :             :                                 "static data member %qD", newdecl))
    3582                 :           4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3583                 :             :                           "previous declaration of %qD", olddecl);
    3584                 :          40 :             }
    3585                 :        2637 :           return NULL;
    3586                 :             :         }
    3587                 :             : 
    3588                 :             :       /* Reject two definitions.  */
    3589                 :             :       return G_("redefinition of %q#D");
    3590                 :             :     }
    3591                 :             :   else
    3592                 :             :     {
    3593                 :             :       /* Objects declared with block scope:  */
    3594                 :             :       /* Reject two definitions, and reject a definition
    3595                 :             :          together with an external reference.  */
    3596                 :          69 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3597                 :             :         return G_("redeclaration of %q#D");
    3598                 :             :       return NULL;
    3599                 :             :     }
    3600                 :             : }
    3601                 :             : 
    3602                 :             : 
    3603                 :             : /* Hash and equality functions for the named_label table.  */
    3604                 :             : 
    3605                 :             : hashval_t
    3606                 :       68829 : named_label_hash::hash (const value_type entry)
    3607                 :             : {
    3608                 :       68829 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3609                 :             : }
    3610                 :             : 
    3611                 :             : bool
    3612                 :       70455 : named_label_hash::equal (const value_type entry, compare_type name)
    3613                 :             : {
    3614                 :       70455 :   return name == entry->name;
    3615                 :             : }
    3616                 :             : 
    3617                 :             : /* Look for a label named ID in the current function.  If one cannot
    3618                 :             :    be found, create one.  Return the named_label_entry, or NULL on
    3619                 :             :    failure.  */
    3620                 :             : 
    3621                 :             : static named_label_entry *
    3622                 :       20882 : lookup_label_1 (tree id, bool making_local_p)
    3623                 :             : {
    3624                 :       20882 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3625                 :             : 
    3626                 :             :   /* You can't use labels at global scope.  */
    3627                 :       20882 :   if (current_function_decl == NULL_TREE)
    3628                 :             :     {
    3629                 :           3 :       error ("label %qE referenced outside of any function", id);
    3630                 :           3 :       return NULL;
    3631                 :             :     }
    3632                 :             : 
    3633                 :       20879 :   if (!named_labels)
    3634                 :        3925 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3635                 :             : 
    3636                 :       20879 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3637                 :       20879 :   named_label_entry **slot
    3638                 :       20879 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3639                 :       20879 :   named_label_entry *old = *slot;
    3640                 :             : 
    3641                 :       20879 :   if (old && old->label_decl)
    3642                 :             :     {
    3643                 :        2182 :       if (!making_local_p)
    3644                 :             :         return old;
    3645                 :             : 
    3646                 :           9 :       if (old->binding_level == current_binding_level)
    3647                 :             :         {
    3648                 :           0 :           auto_diagnostic_group d;
    3649                 :           0 :           error ("local label %qE conflicts with existing label", id);
    3650                 :           0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3651                 :           0 :           return NULL;
    3652                 :           0 :         }
    3653                 :             :     }
    3654                 :             : 
    3655                 :             :   /* We are making a new decl, create or reuse the named_label_entry  */
    3656                 :       18715 :   named_label_entry *ent = NULL;
    3657                 :          21 :   if (old && !old->label_decl)
    3658                 :             :     ent = old;
    3659                 :             :   else
    3660                 :             :     {
    3661                 :       18694 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3662                 :       18694 :       ent->name = id;
    3663                 :       18694 :       ent->outer = old;
    3664                 :       18694 :       *slot = ent;
    3665                 :             :     }
    3666                 :             : 
    3667                 :             :   /* Now create the LABEL_DECL.  */
    3668                 :       18706 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3669                 :             : 
    3670                 :       18706 :   DECL_CONTEXT (decl) = current_function_decl;
    3671                 :       18706 :   SET_DECL_MODE (decl, VOIDmode);
    3672                 :       18706 :   if (making_local_p)
    3673                 :             :     {
    3674                 :         195 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3675                 :         195 :       DECL_CHAIN (decl) = current_binding_level->names;
    3676                 :         195 :       current_binding_level->names = decl;
    3677                 :             :     }
    3678                 :             : 
    3679                 :       18706 :   ent->label_decl = decl;
    3680                 :             : 
    3681                 :       18706 :   return ent;
    3682                 :       20882 : }
    3683                 :             : 
    3684                 :             : /* Wrapper for lookup_label_1.  */
    3685                 :             : 
    3686                 :             : tree
    3687                 :        1764 : lookup_label (tree id)
    3688                 :             : {
    3689                 :        1764 :   named_label_entry *ent = lookup_label_1 (id, false);
    3690                 :        1764 :   return ent ? ent->label_decl : NULL_TREE;
    3691                 :             : }
    3692                 :             : 
    3693                 :             : /* Remember that we've seen &&ID.  */
    3694                 :             : 
    3695                 :             : void
    3696                 :         220 : mark_label_addressed (tree id)
    3697                 :             : {
    3698                 :         220 :   named_label_entry *ent = lookup_label_1 (id, false);
    3699                 :         220 :   ent->addressed = true;
    3700                 :         220 : }
    3701                 :             : 
    3702                 :             : tree
    3703                 :         195 : declare_local_label (tree id)
    3704                 :             : {
    3705                 :         195 :   named_label_entry *ent = lookup_label_1 (id, true);
    3706                 :         195 :   return ent ? ent->label_decl : NULL_TREE;
    3707                 :             : }
    3708                 :             : 
    3709                 :             : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3710                 :             : 
    3711                 :             : static bool
    3712                 :       13233 : decl_jump_unsafe (tree decl)
    3713                 :             : {
    3714                 :             :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3715                 :             :      with automatic storage duration is not in scope to a point where it is
    3716                 :             :      in scope is ill-formed unless the variable has scalar type, class type
    3717                 :             :      with a trivial default constructor and a trivial destructor, a
    3718                 :             :      cv-qualified version of one of these types, or an array of one of the
    3719                 :             :      preceding types and is declared without an initializer (8.5).  */
    3720                 :       13233 :   tree type = TREE_TYPE (decl);
    3721                 :             : 
    3722                 :       13233 :   return (type != error_mark_node
    3723                 :             :           && VAR_P (decl)
    3724                 :       13215 :           && !TREE_STATIC (decl)
    3725                 :       25219 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3726                 :       10739 :               || variably_modified_type_p (type, NULL_TREE)));
    3727                 :             : }
    3728                 :             : 
    3729                 :             : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    3730                 :             :    to the user.  */
    3731                 :             : 
    3732                 :             : static bool
    3733                 :         268 : identify_goto (tree decl, location_t loc, const location_t *locus,
    3734                 :             :                diagnostic_t diag_kind, bool computed)
    3735                 :             : {
    3736                 :         268 :   if (computed)
    3737                 :          25 :     diag_kind = DK_WARNING;
    3738                 :         268 :   bool complained
    3739                 :         355 :     = emit_diagnostic (diag_kind, loc, 0,
    3740                 :             :                        decl ? G_("jump to label %qD")
    3741                 :             :                        : G_("jump to case label"), decl);
    3742                 :         268 :   if (complained && locus)
    3743                 :             :     {
    3744                 :         181 :       if (computed)
    3745                 :          25 :         inform (*locus, "  as a possible target of computed goto");
    3746                 :             :       else
    3747                 :         156 :         inform (*locus, "  from here");
    3748                 :             :     }
    3749                 :         268 :   return complained;
    3750                 :             : }
    3751                 :             : 
    3752                 :             : /* Check that a single previously seen jump to a newly defined label
    3753                 :             :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    3754                 :             :    the jump context; NAMES are the names in scope in LEVEL at the jump
    3755                 :             :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    3756                 :             :    is a vec of decls if the jump is a computed goto.  Returns
    3757                 :             :    true if all is well.  */
    3758                 :             : 
    3759                 :             : static bool
    3760                 :     1689227 : check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
    3761                 :             :                        bool exited_omp, const location_t *locus,
    3762                 :             :                        vec<tree,va_gc> *computed)
    3763                 :             : {
    3764                 :     1689227 :   auto_diagnostic_group d;
    3765                 :     1689227 :   cp_binding_level *b;
    3766                 :     1689227 :   bool complained = false;
    3767                 :     1689227 :   int identified = 0;
    3768                 :     1689227 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    3769                 :     1689227 :   bool saw_ceif = false, saw_se = false;
    3770                 :             : 
    3771                 :     1689227 :   if (exited_omp)
    3772                 :             :     {
    3773                 :          12 :       complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3774                 :             :                                   computed);
    3775                 :          12 :       if (complained)
    3776                 :          12 :         inform (input_location, "  exits OpenMP structured block");
    3777                 :             :       saw_omp = true;
    3778                 :             :       identified = 2;
    3779                 :             :     }
    3780                 :             : 
    3781                 :     5043268 :   for (b = current_binding_level; b ; b = b->level_chain)
    3782                 :             :     {
    3783                 :     3354041 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    3784                 :             : 
    3785                 :     3364023 :       for (new_decls = b->names; new_decls != old_decls;
    3786                 :       10383 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    3787                 :         401 :                         : TREE_CHAIN (new_decls)))
    3788                 :             :         {
    3789                 :        9982 :           bool problem = decl_jump_unsafe (new_decls);
    3790                 :        9982 :           if (! problem)
    3791                 :        9937 :             continue;
    3792                 :             : 
    3793                 :          45 :           if (!identified)
    3794                 :             :             {
    3795                 :          45 :               complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3796                 :             :                                           computed);
    3797                 :          45 :               identified = 2;
    3798                 :             :             }
    3799                 :          45 :           if (complained)
    3800                 :          45 :             inform (DECL_SOURCE_LOCATION (new_decls),
    3801                 :             :                     "  crosses initialization of %q#D", new_decls);
    3802                 :             :         }
    3803                 :             : 
    3804                 :     3354041 :       if (b == level)
    3805                 :             :         break;
    3806                 :             : 
    3807                 :     1664814 :       const char *inf = NULL;
    3808                 :     1664814 :       location_t loc = input_location;
    3809                 :     1664814 :       switch (b->kind)
    3810                 :             :         {
    3811                 :           3 :         case sk_try:
    3812                 :           3 :           if (!saw_eh)
    3813                 :             :             inf = G_("  enters %<try%> block");
    3814                 :             :           saw_eh = true;
    3815                 :             :           break;
    3816                 :             : 
    3817                 :           9 :         case sk_catch:
    3818                 :           9 :           if (!saw_eh)
    3819                 :             :             inf = G_("  enters %<catch%> block");
    3820                 :             :           saw_eh = true;
    3821                 :             :           break;
    3822                 :             : 
    3823                 :         102 :         case sk_omp:
    3824                 :         102 :           if (!saw_omp)
    3825                 :             :             inf = G_("  enters OpenMP structured block");
    3826                 :             :           saw_omp = true;
    3827                 :             :           break;
    3828                 :             : 
    3829                 :           3 :         case sk_transaction:
    3830                 :           3 :           if (!saw_tm)
    3831                 :             :             inf = G_("  enters synchronized or atomic statement");
    3832                 :             :           saw_tm = true;
    3833                 :             :           break;
    3834                 :             : 
    3835                 :          12 :         case sk_stmt_expr:
    3836                 :          12 :           if (!saw_se)
    3837                 :             :             inf = G_("  enters statement expression");
    3838                 :             :           saw_se = true;
    3839                 :             :           break;
    3840                 :             : 
    3841                 :     1664581 :         case sk_block:
    3842                 :     1664581 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    3843                 :             :             {
    3844                 :           9 :               inf = G_("  enters %<constexpr if%> statement");
    3845                 :           9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3846                 :             :               saw_cxif = true;
    3847                 :             :             }
    3848                 :     1664572 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    3849                 :             :             {
    3850                 :          18 :               inf = G_("  enters %<consteval if%> statement");
    3851                 :          18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3852                 :             :               saw_ceif = true;
    3853                 :             :             }
    3854                 :             :           break;
    3855                 :             : 
    3856                 :             :         default:
    3857                 :             :           break;
    3858                 :             :         }
    3859                 :             : 
    3860                 :             :       if (inf)
    3861                 :             :         {
    3862                 :         135 :           if (identified < 2)
    3863                 :         135 :             complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3864                 :             :                                         computed);
    3865                 :         135 :           identified = 2;
    3866                 :         135 :           if (complained)
    3867                 :         135 :             inform (loc, inf);
    3868                 :             :         }
    3869                 :             :     }
    3870                 :             : 
    3871                 :     1689227 :   if (!vec_safe_is_empty (computed))
    3872                 :             :     {
    3873                 :           9 :       if (!identified)
    3874                 :           6 :         complained = identify_goto (decl, input_location, locus, DK_ERROR,
    3875                 :             :                                     computed);
    3876                 :           9 :       identified = 2;
    3877                 :           9 :       if (complained)
    3878                 :          18 :         for (tree d : computed)
    3879                 :             :           {
    3880                 :           9 :             if (DECL_P (d))
    3881                 :           6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    3882                 :           3 :             else if (d == get_identifier ("catch"))
    3883                 :           3 :               inform (*locus, "  does not clean up handled exception");
    3884                 :             :           }
    3885                 :             :     }
    3886                 :             : 
    3887                 :     3378454 :   return !identified;
    3888                 :     1689227 : }
    3889                 :             : 
    3890                 :             : static void
    3891                 :        1109 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    3892                 :             : {
    3893                 :        1109 :   check_previous_goto_1 (decl, use->binding_level,
    3894                 :        1109 :                          use->names_in_scope, use->in_omp_scope,
    3895                 :        1109 :                          &use->o_goto_locus, use->computed_goto);
    3896                 :        1109 : }
    3897                 :             : 
    3898                 :             : static bool
    3899                 :     1688118 : check_switch_goto (cp_binding_level* level)
    3900                 :             : {
    3901                 :     1688118 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    3902                 :     1688118 :                                 false, NULL, nullptr);
    3903                 :             : }
    3904                 :             : 
    3905                 :             : /* Check that a new jump to a label ENT is OK.  COMPUTED is true
    3906                 :             :    if this is a possible target of a computed goto.  */
    3907                 :             : 
    3908                 :             : void
    3909                 :        1654 : check_goto_1 (named_label_entry *ent, bool computed)
    3910                 :             : {
    3911                 :        1654 :   auto_diagnostic_group d;
    3912                 :        1654 :   tree decl = ent->label_decl;
    3913                 :             : 
    3914                 :             :   /* If the label hasn't been defined yet, defer checking.  */
    3915                 :        1654 :   if (! DECL_INITIAL (decl))
    3916                 :             :     {
    3917                 :             :       /* Don't bother creating another use if the last goto had the
    3918                 :             :          same data, and will therefore create the same set of errors.  */
    3919                 :        1262 :       if (ent->uses
    3920                 :         240 :           && ent->uses->names_in_scope == current_binding_level->names)
    3921                 :             :         return;
    3922                 :             : 
    3923                 :        1118 :       named_label_use_entry *new_use
    3924                 :        1118 :         = ggc_alloc<named_label_use_entry> ();
    3925                 :        1118 :       new_use->binding_level = current_binding_level;
    3926                 :        1118 :       new_use->names_in_scope = current_binding_level->names;
    3927                 :        1118 :       new_use->o_goto_locus = input_location;
    3928                 :        1118 :       new_use->in_omp_scope = false;
    3929                 :        1118 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    3930                 :             : 
    3931                 :        1118 :       new_use->next = ent->uses;
    3932                 :        1118 :       ent->uses = new_use;
    3933                 :        1118 :       return;
    3934                 :             :     }
    3935                 :             : 
    3936                 :         392 :   bool saw_catch = false, complained = false;
    3937                 :         392 :   int identified = 0;
    3938                 :         392 :   tree bad;
    3939                 :         392 :   unsigned ix;
    3940                 :             : 
    3941                 :         383 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    3942                 :         377 :       || ent->in_constexpr_if || ent->in_consteval_if
    3943                 :         371 :       || ent->in_omp_scope || ent->in_stmt_expr
    3944                 :         757 :       || !vec_safe_is_empty (ent->bad_decls))
    3945                 :             :     {
    3946                 :          33 :       diagnostic_t diag_kind = DK_PERMERROR;
    3947                 :          33 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    3948                 :          18 :           || ent->in_consteval_if || ent->in_transaction_scope
    3949                 :          12 :           || ent->in_omp_scope || ent->in_stmt_expr)
    3950                 :          27 :         diag_kind = DK_ERROR;
    3951                 :          33 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3952                 :             :                                   &input_location, diag_kind, computed);
    3953                 :          33 :       identified = 1 + (diag_kind == DK_ERROR);
    3954                 :             :     }
    3955                 :             : 
    3956                 :         398 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    3957                 :             :     {
    3958                 :           6 :       bool problem = decl_jump_unsafe (bad);
    3959                 :             : 
    3960                 :           6 :       if (problem && DECL_ARTIFICIAL (bad))
    3961                 :             :         {
    3962                 :             :           /* Can't skip init of __exception_info.  */
    3963                 :           0 :           if (identified == 1)
    3964                 :             :             {
    3965                 :           0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3966                 :             :                                           &input_location, DK_ERROR, computed);
    3967                 :           0 :               identified = 2;
    3968                 :             :             }
    3969                 :           0 :           if (complained)
    3970                 :           0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    3971                 :             :           saw_catch = true;
    3972                 :             :         }
    3973                 :           6 :       else if (complained)
    3974                 :           6 :         inform (DECL_SOURCE_LOCATION (bad),
    3975                 :             :                 "  skips initialization of %q#D", bad);
    3976                 :             :     }
    3977                 :             : 
    3978                 :         392 :   if (complained)
    3979                 :             :     {
    3980                 :          33 :       if (ent->in_try_scope)
    3981                 :           9 :         inform (input_location, "  enters %<try%> block");
    3982                 :          24 :       else if (ent->in_catch_scope && !saw_catch)
    3983                 :           3 :         inform (input_location, "  enters %<catch%> block");
    3984                 :          21 :       else if (ent->in_transaction_scope)
    3985                 :           3 :         inform (input_location, "  enters synchronized or atomic statement");
    3986                 :          18 :       else if (ent->in_constexpr_if)
    3987                 :           3 :         inform (input_location, "  enters %<constexpr if%> statement");
    3988                 :          15 :       else if (ent->in_consteval_if)
    3989                 :           3 :         inform (input_location, "  enters %<consteval if%> statement");
    3990                 :          12 :       else if (ent->in_stmt_expr)
    3991                 :           3 :         inform (input_location, "  enters statement expression");
    3992                 :             :     }
    3993                 :             : 
    3994                 :         392 :   if (ent->in_omp_scope)
    3995                 :             :     {
    3996                 :           3 :       if (complained)
    3997                 :           3 :         inform (input_location, "  enters OpenMP structured block");
    3998                 :             :     }
    3999                 :         389 :   else if (flag_openmp)
    4000                 :          69 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4001                 :             :       {
    4002                 :          42 :         if (b == ent->binding_level)
    4003                 :             :           break;
    4004                 :          36 :         if (b->kind == sk_omp)
    4005                 :             :           {
    4006                 :          21 :             if (identified < 2)
    4007                 :             :               {
    4008                 :          42 :                 complained = identify_goto (decl,
    4009                 :          21 :                                             DECL_SOURCE_LOCATION (decl),
    4010                 :             :                                             &input_location, DK_ERROR,
    4011                 :             :                                             computed);
    4012                 :          21 :                 identified = 2;
    4013                 :             :               }
    4014                 :          21 :             if (complained)
    4015                 :          21 :               inform (input_location, "  exits OpenMP structured block");
    4016                 :             :             break;
    4017                 :             :           }
    4018                 :             :       }
    4019                 :             : 
    4020                 :             :   /* Warn if a computed goto might involve a local variable going out of scope
    4021                 :             :      without being cleaned up.  */
    4022                 :         392 :   if (computed)
    4023                 :             :     {
    4024                 :          59 :       auto level = ent->binding_level;
    4025                 :          59 :       auto names = ent->names_in_scope;
    4026                 :          59 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4027                 :             :         {
    4028                 :          99 :           if (b->kind == sk_catch)
    4029                 :             :             {
    4030                 :           6 :               if (!identified)
    4031                 :             :                 {
    4032                 :           6 :                   complained
    4033                 :           6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4034                 :             :                                      &input_location, DK_ERROR, computed);
    4035                 :           6 :                   identified = 2;
    4036                 :             :                 }
    4037                 :           6 :               if (complained)
    4038                 :           6 :                 inform (input_location,
    4039                 :             :                         "  does not clean up handled exception");
    4040                 :             :             }
    4041                 :          99 :           tree end = b == level ? names : NULL_TREE;
    4042                 :         115 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4043                 :             :             {
    4044                 :          16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4045                 :             :                 {
    4046                 :          10 :                   if (!identified)
    4047                 :             :                     {
    4048                 :          10 :                       complained
    4049                 :          10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4050                 :             :                                          &input_location, DK_ERROR, computed);
    4051                 :          10 :                       identified = 2;
    4052                 :             :                     }
    4053                 :          10 :                   if (complained)
    4054                 :          10 :                     inform (DECL_SOURCE_LOCATION (d),
    4055                 :             :                             "  does not destroy %qD", d);
    4056                 :             :                 }
    4057                 :             :             }
    4058                 :          99 :           if (b == level)
    4059                 :             :             break;
    4060                 :          40 :         }
    4061                 :             :     }
    4062                 :        1654 : }
    4063                 :             : 
    4064                 :             : /* Check that a new jump to a label DECL is OK.  Called by
    4065                 :             :    finish_goto_stmt.  */
    4066                 :             : 
    4067                 :             : void
    4068                 :        1620 : check_goto (tree decl)
    4069                 :             : {
    4070                 :        1620 :   if (!named_labels)
    4071                 :             :     return;
    4072                 :        1605 :   if (TREE_CODE (decl) != LABEL_DECL)
    4073                 :             :     {
    4074                 :             :       /* We don't know where a computed goto is jumping,
    4075                 :             :          so check all addressable labels.  */
    4076                 :         276 :       for (auto iter = named_labels->begin ();
    4077                 :         374 :            iter != named_labels->end ();
    4078                 :         178 :            ++iter)
    4079                 :             :         {
    4080                 :         178 :           auto ent = *iter;
    4081                 :         178 :           if (ent->addressed)
    4082                 :         147 :             check_goto_1 (ent, true);
    4083                 :             :         }
    4084                 :             :     }
    4085                 :             :   else
    4086                 :             :     {
    4087                 :        1507 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4088                 :        1507 :       named_label_entry **slot
    4089                 :        1507 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4090                 :        1507 :       named_label_entry *ent = *slot;
    4091                 :        1507 :       check_goto_1 (ent, false);
    4092                 :             :     }
    4093                 :             : }
    4094                 :             : 
    4095                 :             : /* Check that a return is ok wrt OpenMP structured blocks.
    4096                 :             :    Called by finish_return_stmt.  Returns true if all is well.  */
    4097                 :             : 
    4098                 :             : bool
    4099                 :       90960 : check_omp_return (void)
    4100                 :             : {
    4101                 :      370420 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4102                 :      279460 :     if (b->kind == sk_omp)
    4103                 :             :       {
    4104                 :          15 :         error ("invalid exit from OpenMP structured block");
    4105                 :          15 :         return false;
    4106                 :             :       }
    4107                 :      279445 :     else if (b->kind == sk_function_parms)
    4108                 :             :       break;
    4109                 :             :   return true;
    4110                 :             : }
    4111                 :             : 
    4112                 :             : /* Define a label, specifying the location in the source file.
    4113                 :             :    Return the LABEL_DECL node for the label.  */
    4114                 :             : 
    4115                 :             : tree
    4116                 :       18703 : define_label (location_t location, tree name)
    4117                 :             : {
    4118                 :       18703 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4119                 :             : 
    4120                 :             :   /* After labels, make any new cleanups in the function go into their
    4121                 :             :      own new (temporary) binding contour.  */
    4122                 :       18703 :   for (cp_binding_level *p = current_binding_level;
    4123                 :       26808 :        p->kind != sk_function_parms;
    4124                 :        8105 :        p = p->level_chain)
    4125                 :        8105 :     p->more_cleanups_ok = 0;
    4126                 :             : 
    4127                 :       18703 :   named_label_entry *ent = lookup_label_1 (name, false);
    4128                 :       18703 :   tree decl = ent->label_decl;
    4129                 :             : 
    4130                 :       18703 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4131                 :             :     {
    4132                 :           6 :       error ("duplicate label %qD", decl);
    4133                 :           6 :       return error_mark_node;
    4134                 :             :     }
    4135                 :             :   else
    4136                 :             :     {
    4137                 :             :       /* Mark label as having been defined.  */
    4138                 :       18697 :       DECL_INITIAL (decl) = error_mark_node;
    4139                 :             :       /* Say where in the source.  */
    4140                 :       18697 :       DECL_SOURCE_LOCATION (decl) = location;
    4141                 :             : 
    4142                 :       18697 :       ent->binding_level = current_binding_level;
    4143                 :       18697 :       ent->names_in_scope = current_binding_level->names;
    4144                 :             : 
    4145                 :       19806 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4146                 :        1109 :         check_previous_goto (decl, use);
    4147                 :       18697 :       ent->uses = NULL;
    4148                 :             :     }
    4149                 :             : 
    4150                 :       18697 :   return decl;
    4151                 :       18703 : }
    4152                 :             : 
    4153                 :             : struct cp_switch
    4154                 :             : {
    4155                 :             :   cp_binding_level *level;
    4156                 :             :   struct cp_switch *next;
    4157                 :             :   /* The SWITCH_STMT being built.  */
    4158                 :             :   tree switch_stmt;
    4159                 :             :   /* A splay-tree mapping the low element of a case range to the high
    4160                 :             :      element, or NULL_TREE if there is no high element.  Used to
    4161                 :             :      determine whether or not a new case label duplicates an old case
    4162                 :             :      label.  We need a tree, rather than simply a hash table, because
    4163                 :             :      of the GNU case range extension.  */
    4164                 :             :   splay_tree cases;
    4165                 :             :   /* Remember whether a default: case label has been seen.  */
    4166                 :             :   bool has_default_p;
    4167                 :             :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4168                 :             :   bool break_stmt_seen_p;
    4169                 :             :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4170                 :             :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4171                 :             :   bool in_loop_body_p;
    4172                 :             : };
    4173                 :             : 
    4174                 :             : /* A stack of the currently active switch statements.  The innermost
    4175                 :             :    switch statement is on the top of the stack.  There is no need to
    4176                 :             :    mark the stack for garbage collection because it is only active
    4177                 :             :    during the processing of the body of a function, and we never
    4178                 :             :    collect at that point.  */
    4179                 :             : 
    4180                 :             : static struct cp_switch *switch_stack;
    4181                 :             : 
    4182                 :             : /* Called right after a switch-statement condition is parsed.
    4183                 :             :    SWITCH_STMT is the switch statement being parsed.  */
    4184                 :             : 
    4185                 :             : void
    4186                 :      423468 : push_switch (tree switch_stmt)
    4187                 :             : {
    4188                 :      423468 :   struct cp_switch *p = XNEW (struct cp_switch);
    4189                 :      423468 :   p->level = current_binding_level;
    4190                 :      423468 :   p->next = switch_stack;
    4191                 :      423468 :   p->switch_stmt = switch_stmt;
    4192                 :      423468 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4193                 :      423468 :   p->has_default_p = false;
    4194                 :      423468 :   p->break_stmt_seen_p = false;
    4195                 :      423468 :   p->in_loop_body_p = false;
    4196                 :      423468 :   switch_stack = p;
    4197                 :      423468 : }
    4198                 :             : 
    4199                 :             : void
    4200                 :      423468 : pop_switch (void)
    4201                 :             : {
    4202                 :      423468 :   struct cp_switch *cs = switch_stack;
    4203                 :             : 
    4204                 :             :   /* Emit warnings as needed.  */
    4205                 :      423468 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4206                 :      423468 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4207                 :      423468 :   const bool bool_cond_p
    4208                 :      423468 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4209                 :      423468 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4210                 :      423468 :   if (!processing_template_decl)
    4211                 :      270755 :     c_do_switch_warnings (cs->cases, switch_location,
    4212                 :      270755 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4213                 :             :                           bool_cond_p);
    4214                 :             : 
    4215                 :             :   /* For the benefit of block_may_fallthru remember if the switch body
    4216                 :             :      case labels cover all possible values and if there are break; stmts.  */
    4217                 :      423468 :   if (cs->has_default_p
    4218                 :      423468 :       || (!processing_template_decl
    4219                 :       33496 :           && c_switch_covers_all_cases_p (cs->cases,
    4220                 :       33496 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4221                 :      330129 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4222                 :      423468 :   if (!cs->break_stmt_seen_p)
    4223                 :      205589 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4224                 :             :   /* Now that we're done with the switch warnings, set the switch type
    4225                 :             :      to the type of the condition if the index type was of scoped enum type.
    4226                 :             :      (Such types don't participate in the integer promotions.)  We do this
    4227                 :             :      because of bit-fields whose declared type is a scoped enum type:
    4228                 :             :      gimplification will use the lowered index type, but convert the
    4229                 :             :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4230                 :             :      and verify_gimple_switch doesn't accept that.  */
    4231                 :      423468 :   if (is_bitfield_expr_with_lowered_type (cond))
    4232                 :          13 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4233                 :      423468 :   gcc_assert (!cs->in_loop_body_p);
    4234                 :      423468 :   splay_tree_delete (cs->cases);
    4235                 :      423468 :   switch_stack = switch_stack->next;
    4236                 :      423468 :   free (cs);
    4237                 :      423468 : }
    4238                 :             : 
    4239                 :             : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4240                 :             :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4241                 :             :    in switch_stack we've seen a BREAK_STMT.  */
    4242                 :             : 
    4243                 :             : void
    4244                 :     3321273 : note_break_stmt (void)
    4245                 :             : {
    4246                 :     3321273 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4247                 :     1403467 :     switch_stack->break_stmt_seen_p = true;
    4248                 :     3321273 : }
    4249                 :             : 
    4250                 :             : /* Note the start of processing of an iteration statement's body.
    4251                 :             :    The note_break_stmt function will do nothing while processing it.
    4252                 :             :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4253                 :             : 
    4254                 :             : bool
    4255                 :    14611636 : note_iteration_stmt_body_start (void)
    4256                 :             : {
    4257                 :    14611636 :   if (!switch_stack)
    4258                 :             :     return false;
    4259                 :      108615 :   bool ret = switch_stack->in_loop_body_p;
    4260                 :      108615 :   switch_stack->in_loop_body_p = true;
    4261                 :      108615 :   return ret;
    4262                 :             : }
    4263                 :             : 
    4264                 :             : /* Note the end of processing of an iteration statement's body.  */
    4265                 :             : 
    4266                 :             : void
    4267                 :    14611636 : note_iteration_stmt_body_end (bool prev)
    4268                 :             : {
    4269                 :    14611636 :   if (switch_stack)
    4270                 :      108615 :     switch_stack->in_loop_body_p = prev;
    4271                 :    14611636 : }
    4272                 :             : 
    4273                 :             : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4274                 :             :    condition.  Note that if TYPE and VALUE are already integral we don't
    4275                 :             :    really do the conversion because the language-independent
    4276                 :             :    warning/optimization code will work better that way.  */
    4277                 :             : 
    4278                 :             : static tree
    4279                 :     3375990 : case_conversion (tree type, tree value)
    4280                 :             : {
    4281                 :     3375990 :   if (value == NULL_TREE)
    4282                 :             :     return value;
    4283                 :             : 
    4284                 :     1450898 :   value = mark_rvalue_use (value);
    4285                 :             : 
    4286                 :     1450898 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4287                 :     1437105 :     type = type_promotes_to (type);
    4288                 :             : 
    4289                 :     1450898 :   tree ovalue = value;
    4290                 :             :   /* The constant-expression VALUE shall be a converted constant expression
    4291                 :             :      of the adjusted type of the switch condition, which doesn't allow
    4292                 :             :      narrowing conversions.  */
    4293                 :     1450898 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4294                 :             : 
    4295                 :     1450898 :   if (cxx_dialect >= cxx11
    4296                 :     1450898 :       && (SCOPED_ENUM_P (type)
    4297                 :     1434402 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4298                 :             :     /* Use the converted value.  */;
    4299                 :             :   else
    4300                 :             :     /* The already integral case.  */
    4301                 :             :     value = ovalue;
    4302                 :             : 
    4303                 :     1450898 :   return cxx_constant_value (value);
    4304                 :             : }
    4305                 :             : 
    4306                 :             : /* Note that we've seen a definition of a case label, and complain if this
    4307                 :             :    is a bad place for one.  */
    4308                 :             : 
    4309                 :             : tree
    4310                 :     3128365 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4311                 :             : {
    4312                 :     3128365 :   tree cond, r;
    4313                 :     3128365 :   cp_binding_level *p;
    4314                 :     3128365 :   tree type;
    4315                 :             : 
    4316                 :     3128365 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4317                 :      330093 :     switch_stack->has_default_p = true;
    4318                 :             : 
    4319                 :     3128365 :   if (processing_template_decl)
    4320                 :             :     {
    4321                 :     1440247 :       tree label;
    4322                 :             : 
    4323                 :             :       /* For templates, just add the case label; we'll do semantic
    4324                 :             :          analysis at instantiation-time.  */
    4325                 :     1440247 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4326                 :     1440247 :       return add_stmt (build_case_label (low_value, high_value, label));
    4327                 :             :     }
    4328                 :             : 
    4329                 :             :   /* Find the condition on which this switch statement depends.  */
    4330                 :     1688118 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4331                 :     1688118 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4332                 :           0 :     cond = TREE_VALUE (cond);
    4333                 :             : 
    4334                 :     1688118 :   if (!check_switch_goto (switch_stack->level))
    4335                 :          87 :     return error_mark_node;
    4336                 :             : 
    4337                 :     1688031 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4338                 :     1688031 :   if (type == error_mark_node)
    4339                 :             :     return error_mark_node;
    4340                 :             : 
    4341                 :     1687995 :   low_value = case_conversion (type, low_value);
    4342                 :     1687995 :   high_value = case_conversion (type, high_value);
    4343                 :             : 
    4344                 :     1687995 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4345                 :             : 
    4346                 :             :   /* After labels, make any new cleanups in the function go into their
    4347                 :             :      own new (temporary) binding contour.  */
    4348                 :     1687995 :   for (p = current_binding_level;
    4349                 :     7121150 :        p->kind != sk_function_parms;
    4350                 :     5433155 :        p = p->level_chain)
    4351                 :     5433155 :     p->more_cleanups_ok = 0;
    4352                 :             : 
    4353                 :             :   return r;
    4354                 :             : }
    4355                 :             : 
    4356                 :             : struct typename_info {
    4357                 :             :   tree scope;
    4358                 :             :   tree name;
    4359                 :             :   tree template_id;
    4360                 :             :   bool enum_p;
    4361                 :             :   bool class_p;
    4362                 :             : };
    4363                 :             : 
    4364                 :             : struct typename_hasher : ggc_ptr_hash<tree_node>
    4365                 :             : {
    4366                 :             :   typedef typename_info *compare_type;
    4367                 :             : 
    4368                 :             :   /* Hash a TYPENAME_TYPE.  */
    4369                 :             : 
    4370                 :             :   static hashval_t
    4371                 :   364121945 :   hash (tree context, tree fullname)
    4372                 :             :   {
    4373                 :   364121945 :     hashval_t hash = 0;
    4374                 :   364121945 :     hash = iterative_hash_object (context, hash);
    4375                 :   364121945 :     hash = iterative_hash_object (fullname, hash);
    4376                 :   364121945 :     return hash;
    4377                 :             :   }
    4378                 :             : 
    4379                 :             :   static hashval_t
    4380                 :    52924662 :   hash (const typename_info *ti)
    4381                 :             :   {
    4382                 :    52924662 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4383                 :             :   }
    4384                 :             : 
    4385                 :             :   static hashval_t
    4386                 :   311197283 :   hash (tree t)
    4387                 :             :   {
    4388                 :   311197283 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4389                 :             :   }
    4390                 :             : 
    4391                 :             :   /* Compare two TYPENAME_TYPEs.  */
    4392                 :             : 
    4393                 :             :   static bool
    4394                 :   361071501 :   equal (tree t1, const typename_info *t2)
    4395                 :             :   {
    4396                 :   361071501 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4397                 :   106928845 :             && TYPE_CONTEXT (t1) == t2->scope
    4398                 :    26574542 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4399                 :    26564581 :             && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
    4400                 :   387636028 :             && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
    4401                 :             :   }
    4402                 :             : };
    4403                 :             : 
    4404                 :             : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4405                 :             :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4406                 :             : 
    4407                 :             :    Returns the new TYPENAME_TYPE.  */
    4408                 :             : 
    4409                 :             : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4410                 :             : 
    4411                 :             : tree
    4412                 :    52924662 : build_typename_type (tree context, tree name, tree fullname,
    4413                 :             :                      enum tag_types tag_type)
    4414                 :             : {
    4415                 :    52924662 :   typename_info ti;
    4416                 :             : 
    4417                 :    52924662 :   if (typename_htab == NULL)
    4418                 :       18286 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4419                 :             : 
    4420                 :    52924662 :   ti.scope = FROB_CONTEXT (context);
    4421                 :    52924662 :   ti.name = name;
    4422                 :    52924662 :   ti.template_id = fullname;
    4423                 :    52924662 :   ti.enum_p = tag_type == enum_type;
    4424                 :    52924662 :   ti.class_p = (tag_type == class_type
    4425                 :             :                 || tag_type == record_type
    4426                 :    52924662 :                 || tag_type == union_type);
    4427                 :    52924662 :   hashval_t hash = typename_hasher::hash (&ti);
    4428                 :             : 
    4429                 :             :   /* See if we already have this type.  */
    4430                 :    52924662 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4431                 :    52924662 :   tree t = *e;
    4432                 :    52924662 :   if (*e)
    4433                 :             :     t = *e;
    4434                 :             :   else
    4435                 :             :     {
    4436                 :             :       /* Build the TYPENAME_TYPE.  */
    4437                 :    26360159 :       t = cxx_make_type (TYPENAME_TYPE);
    4438                 :    26360159 :       TYPE_CONTEXT (t) = ti.scope;
    4439                 :    26360159 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4440                 :    26360159 :       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
    4441                 :    26360159 :       TYPENAME_IS_CLASS_P (t) = ti.class_p;
    4442                 :             : 
    4443                 :             :       /* Build the corresponding TYPE_DECL.  */
    4444                 :    26360159 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4445                 :    26360159 :       TYPE_NAME (t) = d;
    4446                 :    26360159 :       TYPE_STUB_DECL (t) = d;
    4447                 :    26360159 :       DECL_CONTEXT (d) = ti.scope;
    4448                 :    26360159 :       DECL_ARTIFICIAL (d) = 1;
    4449                 :             : 
    4450                 :             :       /* Store it in the hash table.  */
    4451                 :    26360159 :       *e = t;
    4452                 :             : 
    4453                 :             :       /* TYPENAME_TYPEs must always be compared structurally, because
    4454                 :             :          they may or may not resolve down to another type depending on
    4455                 :             :          the currently open classes. */
    4456                 :    26360159 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    4457                 :             :     }
    4458                 :             : 
    4459                 :    52924662 :   return t;
    4460                 :             : }
    4461                 :             : 
    4462                 :             : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    4463                 :             :    provided to name the type.  Returns an appropriate type, unless an
    4464                 :             :    error occurs, in which case error_mark_node is returned.  If we
    4465                 :             :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    4466                 :             :    return that, rather than the _TYPE it corresponds to, in other
    4467                 :             :    cases we look through the type decl.  If TF_ERROR is set, complain
    4468                 :             :    about errors, otherwise be quiet.  */
    4469                 :             : 
    4470                 :             : tree
    4471                 :   158251738 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    4472                 :             :                     tsubst_flags_t complain)
    4473                 :             : {
    4474                 :   158251738 :   tree fullname;
    4475                 :   158251738 :   tree t;
    4476                 :   158251738 :   bool want_template;
    4477                 :             : 
    4478                 :   158251738 :   if (name == error_mark_node
    4479                 :   158251736 :       || context == NULL_TREE
    4480                 :   158251736 :       || context == error_mark_node)
    4481                 :             :     return error_mark_node;
    4482                 :             : 
    4483                 :   158251723 :   if (TYPE_P (name))
    4484                 :             :     {
    4485                 :           0 :       if (!(TYPE_LANG_SPECIFIC (name)
    4486                 :           0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    4487                 :           0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    4488                 :           0 :         name = TYPE_IDENTIFIER (name);
    4489                 :             :       else
    4490                 :             :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    4491                 :           0 :         name = build_nt (TEMPLATE_ID_EXPR,
    4492                 :           0 :                          CLASSTYPE_TI_TEMPLATE (name),
    4493                 :           0 :                          CLASSTYPE_TI_ARGS (name));
    4494                 :             :     }
    4495                 :   158251723 :   else if (TREE_CODE (name) == TYPE_DECL)
    4496                 :           0 :     name = DECL_NAME (name);
    4497                 :             : 
    4498                 :   158251723 :   fullname = name;
    4499                 :             : 
    4500                 :   158251723 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    4501                 :             :     {
    4502                 :     5301210 :       name = TREE_OPERAND (name, 0);
    4503                 :     5301210 :       if (DECL_TYPE_TEMPLATE_P (name))
    4504                 :           0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    4505                 :     5301210 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    4506                 :             :         {
    4507                 :           0 :           if (complain & tf_error)
    4508                 :           0 :             error ("%qD is not a type", name);
    4509                 :           0 :           return error_mark_node;
    4510                 :             :         }
    4511                 :             :     }
    4512                 :   158251723 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    4513                 :             :     {
    4514                 :           0 :       if (complain & tf_error)
    4515                 :           0 :         error ("%qD used without template arguments", name);
    4516                 :           0 :       return error_mark_node;
    4517                 :             :     }
    4518                 :   158251723 :   else if (is_overloaded_fn (name))
    4519                 :             :     {
    4520                 :           3 :       if (complain & tf_error)
    4521                 :           3 :         error ("%qD is a function, not a type", name);
    4522                 :           3 :       return error_mark_node;
    4523                 :             :     }
    4524                 :   158251720 :   gcc_assert (identifier_p (name));
    4525                 :   158251720 :   gcc_assert (TYPE_P (context));
    4526                 :             : 
    4527                 :   158251720 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    4528                 :             :     /* This can happen for C++17 variadic using (c++/88986).  */;
    4529                 :   146993271 :   else if (!MAYBE_CLASS_TYPE_P (context))
    4530                 :             :     {
    4531                 :           6 :       if (complain & tf_error)
    4532                 :           6 :         error ("%q#T is not a class", context);
    4533                 :           6 :       return error_mark_node;
    4534                 :             :     }
    4535                 :             : 
    4536                 :             :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    4537                 :             :      dependent base class of CONTEXT.  But look inside it anyway
    4538                 :             :      if CONTEXT is a currently open scope, in case it refers to a
    4539                 :             :      member of the current instantiation or a non-dependent base;
    4540                 :             :      lookup will stop when we hit a dependent base.  */
    4541                 :   158251714 :   if (!dependent_scope_p (context))
    4542                 :             :     {
    4543                 :             :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    4544                 :             :          (as per [temp.res.general]/3), unless
    4545                 :             :            - the tag corresponds to a class-key or 'enum' so
    4546                 :             :              [basic.lookup.elab] applies, or
    4547                 :             :            - the tag corresponds to scope_type or tf_qualifying_scope is
    4548                 :             :              set so [basic.lookup.qual]/1 applies.
    4549                 :             :          TODO: If we'd set/track the scope_type tag thoroughly on all
    4550                 :             :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    4551                 :             :          tf_qualifying_scope flag.  */
    4552                 :   218392798 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    4553                 :   109196399 :         || (complain & tf_qualifying_scope);
    4554                 :   109196399 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    4555                 :             :     }
    4556                 :             :   else
    4557                 :             :     t = NULL_TREE;
    4558                 :             : 
    4559                 :   174090148 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    4560                 :    49056281 :     return build_typename_type (context, name, fullname, tag_type);
    4561                 :             : 
    4562                 :   109195433 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    4563                 :             : 
    4564                 :   109195433 :   if (!t)
    4565                 :             :     {
    4566                 :    15837468 :       if (complain & tf_error)
    4567                 :             :         {
    4568                 :         232 :           if (!COMPLETE_TYPE_P (context))
    4569                 :          18 :             cxx_incomplete_type_error (NULL_TREE, context);
    4570                 :             :           else
    4571                 :         427 :             error (want_template ? G_("no class template named %q#T in %q#T")
    4572                 :             :                    : G_("no type named %q#T in %q#T"), name, context);
    4573                 :             :         }
    4574                 :    15837468 :       return error_mark_node;
    4575                 :             :     }
    4576                 :             : 
    4577                 :             :   /* Pull out the template from an injected-class-name (or multiple).  */
    4578                 :    93357965 :   if (want_template)
    4579                 :     3969217 :     t = maybe_get_template_decl_from_type_decl (t);
    4580                 :             : 
    4581                 :    93357965 :   if (TREE_CODE (t) == TREE_LIST)
    4582                 :             :     {
    4583                 :           3 :       if (complain & tf_error)
    4584                 :             :         {
    4585                 :           3 :           auto_diagnostic_group d;
    4586                 :           3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    4587                 :           3 :           print_candidates (t);
    4588                 :           3 :         }
    4589                 :           3 :       return error_mark_node;
    4590                 :             :     }
    4591                 :             : 
    4592                 :    93357962 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    4593                 :             :     {
    4594                 :           6 :       if (complain & tf_error)
    4595                 :           6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    4596                 :             :                context, name, t);
    4597                 :           6 :       return error_mark_node;
    4598                 :             :     }
    4599                 :    93357956 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    4600                 :             :     {
    4601                 :          15 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    4602                 :          33 :           && DECL_TYPE_TEMPLATE_P (t))
    4603                 :             :         /* The caller permits this typename-specifier to name a template
    4604                 :             :            (because it appears in a CTAD-enabled context).  */;
    4605                 :             :       else
    4606                 :             :         {
    4607                 :          23 :           if (complain & tf_error)
    4608                 :          17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    4609                 :             :                    context, name, t);
    4610                 :          23 :           return error_mark_node;
    4611                 :             :         }
    4612                 :             :     }
    4613                 :             : 
    4614                 :    93357933 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    4615                 :             :                                             context, complain))
    4616                 :          45 :     return error_mark_node;
    4617                 :             : 
    4618                 :    93357888 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    4619                 :           4 :     return make_template_placeholder (t);
    4620                 :             : 
    4621                 :    93357884 :   if (want_template)
    4622                 :             :     {
    4623                 :     3969211 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    4624                 :             :                                  NULL_TREE, context,
    4625                 :             :                                  complain | tf_user);
    4626                 :     3969211 :       if (t == error_mark_node)
    4627                 :             :         return error_mark_node;
    4628                 :     3969206 :       t = TYPE_NAME (t);
    4629                 :             :     }
    4630                 :             : 
    4631                 :    93357879 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    4632                 :     3246955 :     t = TREE_TYPE (t);
    4633                 :             : 
    4634                 :    93357879 :   maybe_record_typedef_use (t);
    4635                 :             : 
    4636                 :    93357879 :   return t;
    4637                 :             : }
    4638                 :             : 
    4639                 :             : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    4640                 :             :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    4641                 :             :    in which case error_mark_node is returned.
    4642                 :             : 
    4643                 :             :    If PARM_LIST is non-NULL, also make sure that the template parameter
    4644                 :             :    list of TEMPLATE_DECL matches.
    4645                 :             : 
    4646                 :             :    If COMPLAIN zero, don't complain about any errors that occur.  */
    4647                 :             : 
    4648                 :             : tree
    4649                 :       74132 : make_unbound_class_template (tree context, tree name, tree parm_list,
    4650                 :             :                              tsubst_flags_t complain)
    4651                 :             : {
    4652                 :       74132 :   if (TYPE_P (name))
    4653                 :           0 :     name = TYPE_IDENTIFIER (name);
    4654                 :       74132 :   else if (DECL_P (name))
    4655                 :           0 :     name = DECL_NAME (name);
    4656                 :       74132 :   gcc_assert (identifier_p (name));
    4657                 :             : 
    4658                 :       74132 :   if (!dependent_type_p (context)
    4659                 :       74132 :       || currently_open_class (context))
    4660                 :             :     {
    4661                 :       22949 :       tree tmpl = NULL_TREE;
    4662                 :             : 
    4663                 :       22949 :       if (MAYBE_CLASS_TYPE_P (context))
    4664                 :       22943 :         tmpl = lookup_field (context, name, 0, false);
    4665                 :             : 
    4666                 :       22943 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    4667                 :           3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    4668                 :             : 
    4669                 :       22937 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    4670                 :             :         {
    4671                 :          12 :           if (complain & tf_error)
    4672                 :           9 :             error ("no class template named %q#T in %q#T", name, context);
    4673                 :          12 :           return error_mark_node;
    4674                 :             :         }
    4675                 :             : 
    4676                 :       22937 :       if (parm_list
    4677                 :       22937 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    4678                 :             :         {
    4679                 :           0 :           if (complain & tf_error)
    4680                 :             :             {
    4681                 :           0 :               auto_diagnostic_group d;
    4682                 :           0 :               error ("template parameters do not match template %qD", tmpl);
    4683                 :           0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    4684                 :             :                       "%qD declared here", tmpl);
    4685                 :           0 :             }
    4686                 :           0 :           return error_mark_node;
    4687                 :             :         }
    4688                 :             : 
    4689                 :       22937 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    4690                 :             :                                           complain))
    4691                 :           0 :         return error_mark_node;
    4692                 :             : 
    4693                 :             :       return tmpl;
    4694                 :             :     }
    4695                 :             : 
    4696                 :       51183 :   return make_unbound_class_template_raw (context, name, parm_list);
    4697                 :             : }
    4698                 :             : 
    4699                 :             : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    4700                 :             : 
    4701                 :             : tree
    4702                 :       51252 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    4703                 :             : {
    4704                 :             :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    4705                 :       51252 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    4706                 :       51252 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    4707                 :       51252 :   TREE_TYPE (t) = NULL_TREE;
    4708                 :       51252 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    4709                 :             : 
    4710                 :             :   /* Build the corresponding TEMPLATE_DECL.  */
    4711                 :       51252 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    4712                 :       51252 :   TYPE_NAME (t) = d;
    4713                 :       51252 :   TYPE_STUB_DECL (t) = d;
    4714                 :       51252 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    4715                 :       51252 :   DECL_ARTIFICIAL (d) = 1;
    4716                 :       51252 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    4717                 :             : 
    4718                 :       51252 :   return t;
    4719                 :             : }
    4720                 :             : 
    4721                 :             : 
    4722                 :             : 
    4723                 :             : /* Push the declarations of builtin types into the global namespace.
    4724                 :             :    RID_INDEX is the index of the builtin type in the array
    4725                 :             :    RID_POINTERS.  NAME is the name used when looking up the builtin
    4726                 :             :    type.  TYPE is the _TYPE node for the builtin type.
    4727                 :             : 
    4728                 :             :    The calls to set_global_binding below should be
    4729                 :             :    eliminated.  Built-in types should not be looked up name; their
    4730                 :             :    names are keywords that the parser can recognize.  However, there
    4731                 :             :    is code in c-common.cc that uses identifier_global_value to look up
    4732                 :             :    built-in types by name.  */
    4733                 :             : 
    4734                 :             : void
    4735                 :     3805849 : record_builtin_type (enum rid rid_index,
    4736                 :             :                      const char* name,
    4737                 :             :                      tree type)
    4738                 :             : {
    4739                 :     3805849 :   tree decl = NULL_TREE;
    4740                 :             : 
    4741                 :     3805849 :   if (name)
    4742                 :             :     {
    4743                 :     2228351 :       tree tname = get_identifier (name);
    4744                 :     2228351 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    4745                 :     2228351 :       DECL_ARTIFICIAL (tdecl) = 1;
    4746                 :     2228351 :       set_global_binding (tdecl);
    4747                 :     2228351 :       decl = tdecl;
    4748                 :             :     }
    4749                 :             : 
    4750                 :     3805849 :   if ((int) rid_index < (int) RID_MAX)
    4751                 :     2321145 :     if (tree rname = ridpointers[(int) rid_index])
    4752                 :     1764381 :       if (!decl || DECL_NAME (decl) != rname)
    4753                 :             :         {
    4754                 :     1299116 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    4755                 :     1299116 :           DECL_ARTIFICIAL (rdecl) = 1;
    4756                 :     1299116 :           set_global_binding (rdecl);
    4757                 :     1299116 :           if (!decl)
    4758                 :             :             decl = rdecl;
    4759                 :             :         }
    4760                 :             : 
    4761                 :     3527467 :   if (decl)
    4762                 :             :     {
    4763                 :     3249085 :       if (!TYPE_NAME (type))
    4764                 :     2692321 :         TYPE_NAME (type) = decl;
    4765                 :     3249085 :       debug_hooks->type_decl (decl, 0);
    4766                 :             :     }
    4767                 :     3805849 : }
    4768                 :             : 
    4769                 :             : /* Push a type into the namespace so that the back ends ignore it.  */
    4770                 :             : 
    4771                 :             : static void
    4772                 :      278382 : record_unknown_type (tree type, const char* name)
    4773                 :             : {
    4774                 :      278382 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    4775                 :             :                                     TYPE_DECL, get_identifier (name), type));
    4776                 :             :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    4777                 :      278382 :   DECL_IGNORED_P (decl) = 1;
    4778                 :      278382 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    4779                 :      278382 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    4780                 :      278382 :   SET_TYPE_ALIGN (type, 1);
    4781                 :      278382 :   TYPE_USER_ALIGN (type) = 0;
    4782                 :      278382 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    4783                 :      278382 : }
    4784                 :             : 
    4785                 :             : /* Create all the predefined identifiers.  */
    4786                 :             : 
    4787                 :             : static void
    4788                 :       92794 : initialize_predefined_identifiers (void)
    4789                 :             : {
    4790                 :       92794 :   struct predefined_identifier
    4791                 :             :   {
    4792                 :             :     const char *name; /* Name.  */
    4793                 :             :     tree *node;  /* Node to store it in.  */
    4794                 :             :     cp_identifier_kind kind;  /* Kind of identifier.  */
    4795                 :             :   };
    4796                 :             : 
    4797                 :             :   /* A table of identifiers to create at startup.  */
    4798                 :       92794 :   static const predefined_identifier predefined_identifiers[] = {
    4799                 :             :     {"C++", &lang_name_cplusplus, cik_normal},
    4800                 :             :     {"C", &lang_name_c, cik_normal},
    4801                 :             :     /* Some of these names have a trailing space so that it is
    4802                 :             :        impossible for them to conflict with names written by users.  */
    4803                 :             :     {"__ct ", &ctor_identifier, cik_ctor},
    4804                 :             :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    4805                 :             :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    4806                 :             :     {"__dt ", &dtor_identifier, cik_dtor},
    4807                 :             :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    4808                 :             :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    4809                 :             :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    4810                 :             :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    4811                 :             :     {"__in_chrg", &in_charge_identifier, cik_normal},
    4812                 :             :     {"__as_base ", &as_base_identifier, cik_normal},
    4813                 :             :     {"this", &this_identifier, cik_normal},
    4814                 :             :     {"__delta", &delta_identifier, cik_normal},
    4815                 :             :     {"__pfn", &pfn_identifier, cik_normal},
    4816                 :             :     {"_vptr", &vptr_identifier, cik_normal},
    4817                 :             :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    4818                 :             :     {"::", &global_identifier, cik_normal},
    4819                 :             :       /* The demangler expects anonymous namespaces to be called
    4820                 :             :          something starting with '_GLOBAL__N_'.  It no longer needs
    4821                 :             :          to be unique to the TU.  */
    4822                 :             :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    4823                 :             :     {"auto", &auto_identifier, cik_normal},
    4824                 :             :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    4825                 :             :     {"initializer_list", &init_list_identifier, cik_normal},
    4826                 :             :     {"__for_range ", &for_range__identifier, cik_normal},
    4827                 :             :     {"__for_begin ", &for_begin__identifier, cik_normal},
    4828                 :             :     {"__for_end ", &for_end__identifier, cik_normal},
    4829                 :             :     {"__for_range", &for_range_identifier, cik_normal},
    4830                 :             :     {"__for_begin", &for_begin_identifier, cik_normal},
    4831                 :             :     {"__for_end", &for_end_identifier, cik_normal},
    4832                 :             :     {"abi_tag", &abi_tag_identifier, cik_normal},
    4833                 :             :     {"aligned", &aligned_identifier, cik_normal},
    4834                 :             :     {"begin", &begin_identifier, cik_normal},
    4835                 :             :     {"end", &end_identifier, cik_normal},
    4836                 :             :     {"get", &get__identifier, cik_normal},
    4837                 :             :     {"gnu", &gnu_identifier, cik_normal},
    4838                 :             :     {"tuple_element", &tuple_element_identifier, cik_normal},
    4839                 :             :     {"tuple_size", &tuple_size_identifier, cik_normal},
    4840                 :             :     {"type", &type_identifier, cik_normal},
    4841                 :             :     {"value", &value_identifier, cik_normal},
    4842                 :             :     {"_FUN", &fun_identifier, cik_normal},
    4843                 :             :     {"__closure", &closure_identifier, cik_normal},
    4844                 :             :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    4845                 :             :     {"heap ", &heap_identifier, cik_normal},
    4846                 :             :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    4847                 :             :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    4848                 :             :     {"heap []", &heap_vec_identifier, cik_normal},
    4849                 :             :     {"omp", &omp_identifier, cik_normal},
    4850                 :             :     {"internal ", &internal_identifier, cik_normal},
    4851                 :             :     {NULL, NULL, cik_normal}
    4852                 :             :   };
    4853                 :             : 
    4854                 :     4454112 :   for (const predefined_identifier *pid = predefined_identifiers;
    4855                 :     4454112 :        pid->name; ++pid)
    4856                 :             :     {
    4857                 :     4361318 :       *pid->node = get_identifier (pid->name);
    4858                 :             :       /* Some of these identifiers already have a special kind.  */
    4859                 :     4361318 :       if (pid->kind != cik_normal)
    4860                 :      742352 :         set_identifier_kind (*pid->node, pid->kind);
    4861                 :             :     }
    4862                 :       92794 : }
    4863                 :             : 
    4864                 :             : /* Build a specific variant of operator new.  */
    4865                 :             : 
    4866                 :             : static void
    4867                 :      165242 : cxx_build_operator_new (tree newtype)
    4868                 :             : {
    4869                 :      165242 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4870                 :      165242 :   DECL_IS_MALLOC (opnew) = 1;
    4871                 :      165242 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4872                 :      165242 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4873                 :      165242 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4874                 :      165242 :   DECL_IS_MALLOC (opnew) = 1;
    4875                 :      165242 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4876                 :      165242 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4877                 :      165242 : }
    4878                 :             : 
    4879                 :             : /* Build a specific variant of operator delete.  */
    4880                 :             : 
    4881                 :             : static void
    4882                 :      311328 : cxx_build_operator_delete (tree deltype)
    4883                 :             : {
    4884                 :      311328 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4885                 :      311328 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4886                 :      311328 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4887                 :      311328 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4888                 :      311328 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4889                 :      311328 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4890                 :      311328 : }
    4891                 :             : 
    4892                 :             : /* Declare all variants of operator new and delete.  */
    4893                 :             : 
    4894                 :             : static void
    4895                 :       92794 : cxx_init_operator_new_delete_decls (void)
    4896                 :             : {
    4897                 :       92794 :   tree newattrs, extvisattr;
    4898                 :       92794 :   tree newtype, deltype;
    4899                 :       92794 :   tree ptr_ftype_sizetype;
    4900                 :       92794 :   tree new_eh_spec;
    4901                 :       92794 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    4902                 :             :                                                   ptr_type_node, NULL_TREE);
    4903                 :       92794 :   void_ftype_ptr
    4904                 :       92794 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    4905                 :             : 
    4906                 :       92794 :   ptr_ftype_sizetype
    4907                 :       92794 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    4908                 :       92794 :   if (cxx_dialect == cxx98)
    4909                 :             :     {
    4910                 :       13744 :       tree bad_alloc_id;
    4911                 :       13744 :       tree bad_alloc_type_node;
    4912                 :       13744 :       tree bad_alloc_decl;
    4913                 :             : 
    4914                 :       13744 :       push_nested_namespace (std_node);
    4915                 :       13744 :       bad_alloc_id = get_identifier ("bad_alloc");
    4916                 :       13744 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    4917                 :       13744 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    4918                 :       13744 :       bad_alloc_decl
    4919                 :       13744 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    4920                 :       13744 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    4921                 :       13744 :       pop_nested_namespace (std_node);
    4922                 :             : 
    4923                 :       13744 :       new_eh_spec
    4924                 :       13744 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    4925                 :             :     }
    4926                 :             :   else
    4927                 :       79050 :     new_eh_spec = noexcept_false_spec;
    4928                 :             : 
    4929                 :       92794 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    4930                 :             :                                 NULL_TREE);
    4931                 :       92794 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    4932                 :             :                         build_tree_list (NULL_TREE, integer_one_node),
    4933                 :             :                         extvisattr);
    4934                 :       92794 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    4935                 :       92794 :   newtype = build_exception_variant (newtype, new_eh_spec);
    4936                 :       92794 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    4937                 :       92794 :   deltype = build_exception_variant (deltype, empty_except_spec);
    4938                 :       92794 :   cxx_build_operator_new (newtype);
    4939                 :       92794 :   cxx_build_operator_delete (deltype);
    4940                 :       92794 :   if (flag_sized_deallocation)
    4941                 :             :     {
    4942                 :             :       /* Also push the sized deallocation variants:
    4943                 :             :            void operator delete(void*, std::size_t) throw();
    4944                 :             :            void operator delete[](void*, std::size_t) throw();  */
    4945                 :       73643 :       tree void_ftype_ptr_size
    4946                 :       73643 :         = build_function_type_list (void_type_node, ptr_type_node,
    4947                 :             :                                     size_type_node, NULL_TREE);
    4948                 :       73643 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    4949                 :             :                                                  extvisattr);
    4950                 :       73643 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4951                 :       73643 :       cxx_build_operator_delete (deltype);
    4952                 :             :     }
    4953                 :             : 
    4954                 :       92794 :   if (aligned_new_threshold)
    4955                 :             :     {
    4956                 :       72448 :       push_nested_namespace (std_node);
    4957                 :       72448 :       tree align_id = get_identifier ("align_val_t");
    4958                 :       72448 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    4959                 :             :                                     NULL_TREE, /*scoped*/true, NULL);
    4960                 :       72448 :       pop_nested_namespace (std_node);
    4961                 :             : 
    4962                 :             :       /* operator new (size_t, align_val_t); */
    4963                 :       72448 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    4964                 :             :                                           align_type_node, NULL_TREE);
    4965                 :       72448 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    4966                 :       72448 :       newtype = build_exception_variant (newtype, new_eh_spec);
    4967                 :       72448 :       cxx_build_operator_new (newtype);
    4968                 :             : 
    4969                 :             :       /* operator delete (void *, align_val_t); */
    4970                 :       72448 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    4971                 :             :                                           align_type_node, NULL_TREE);
    4972                 :       72448 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4973                 :       72448 :       deltype = build_exception_variant (deltype, empty_except_spec);
    4974                 :       72448 :       cxx_build_operator_delete (deltype);
    4975                 :             : 
    4976                 :       72448 :       if (flag_sized_deallocation)
    4977                 :             :         {
    4978                 :             :           /* operator delete (void *, size_t, align_val_t); */
    4979                 :       72443 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    4980                 :             :                                               size_type_node, align_type_node,
    4981                 :             :                                               NULL_TREE);
    4982                 :       72443 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4983                 :       72443 :           deltype = build_exception_variant (deltype, empty_except_spec);
    4984                 :       72443 :           cxx_build_operator_delete (deltype);
    4985                 :             :         }
    4986                 :             :     }
    4987                 :       92794 : }
    4988                 :             : 
    4989                 :             : /* Create the predefined scalar types of C,
    4990                 :             :    and some nodes representing standard constants (0, 1, (void *)0).
    4991                 :             :    Initialize the global binding level.
    4992                 :             :    Make definitions for built-in primitive functions.  */
    4993                 :             : 
    4994                 :             : void
    4995                 :       92794 : cxx_init_decl_processing (void)
    4996                 :             : {
    4997                 :       92794 :   tree void_ftype;
    4998                 :             : 
    4999                 :             :   /* Create all the identifiers we need.  */
    5000                 :       92794 :   initialize_predefined_identifiers ();
    5001                 :             : 
    5002                 :             :   /* Create the global variables.  */
    5003                 :       92794 :   push_to_top_level ();
    5004                 :             : 
    5005                 :       92794 :   current_function_decl = NULL_TREE;
    5006                 :       92794 :   current_binding_level = NULL;
    5007                 :             :   /* Enter the global namespace.  */
    5008                 :       92794 :   gcc_assert (global_namespace == NULL_TREE);
    5009                 :       92794 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5010                 :             :                                       void_type_node);
    5011                 :       92794 :   TREE_PUBLIC (global_namespace) = true;
    5012                 :       92794 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5013                 :       92794 :   DECL_CONTEXT (global_namespace)
    5014                 :       92794 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5015                 :             :   /* Remember whether we want the empty class passing ABI change warning
    5016                 :             :      in this TU.  */
    5017                 :       92794 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5018                 :       93857 :     = warn_abi && abi_version_crosses (12);
    5019                 :       92794 :   debug_hooks->register_main_translation_unit
    5020                 :       92794 :     (DECL_CONTEXT (global_namespace));
    5021                 :       92794 :   begin_scope (sk_namespace, global_namespace);
    5022                 :       92794 :   current_namespace = global_namespace;
    5023                 :             : 
    5024                 :       92794 :   if (flag_visibility_ms_compat)
    5025                 :           6 :     default_visibility = VISIBILITY_HIDDEN;
    5026                 :             : 
    5027                 :             :   /* Initially, C.  */
    5028                 :       92794 :   current_lang_name = lang_name_c;
    5029                 :             : 
    5030                 :             :   /* Create the `std' namespace.  */
    5031                 :       92794 :   push_namespace (get_identifier ("std"));
    5032                 :       92794 :   std_node = current_namespace;
    5033                 :       92794 :   pop_namespace ();
    5034                 :             : 
    5035                 :       92794 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5036                 :             : 
    5037                 :       92794 :   c_common_nodes_and_builtins ();
    5038                 :             : 
    5039                 :       92794 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5040                 :       92794 :   tree decl
    5041                 :       92794 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5042                 :             :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5043                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5044                 :       92794 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5045                 :             : 
    5046                 :             :   /* The concrete return type of __builtin_source_location is
    5047                 :             :      const std::source_location::__impl*, but we can't form the type
    5048                 :             :      at this point.  So we initially declare it with an auto return
    5049                 :             :      type which we then "deduce" from require_deduced_type upon first use.  */
    5050                 :       92794 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5051                 :       92794 :   decl = add_builtin_function ("__builtin_source_location",
    5052                 :             :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5053                 :             :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5054                 :       92794 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5055                 :             : 
    5056                 :       92794 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5057                 :             :                                                         NULL_TREE);
    5058                 :       92794 :   decl
    5059                 :       92794 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5060                 :             :                             bool_vaftype,
    5061                 :             :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5062                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5063                 :       92794 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5064                 :             : 
    5065                 :       92794 :   decl
    5066                 :       92794 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5067                 :             :                             bool_vaftype,
    5068                 :             :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5069                 :             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5070                 :       92794 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5071                 :             : 
    5072                 :       92794 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    5073                 :             : 
    5074                 :             :   /* Guess at the initial static decls size.  */
    5075                 :       92794 :   vec_alloc (static_decls, 500);
    5076                 :             : 
    5077                 :             :   /* ... and keyed classes.  */
    5078                 :       92794 :   vec_alloc (keyed_classes, 100);
    5079                 :             : 
    5080                 :       92794 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5081                 :       92794 :   truthvalue_type_node = boolean_type_node;
    5082                 :       92794 :   truthvalue_false_node = boolean_false_node;
    5083                 :       92794 :   truthvalue_true_node = boolean_true_node;
    5084                 :             : 
    5085                 :       92794 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5086                 :       92794 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5087                 :       92794 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5088                 :       92794 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5089                 :             :                                             NULL_TREE);
    5090                 :             : 
    5091                 :             : #if 0
    5092                 :             :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5093                 :             : #endif
    5094                 :             : 
    5095                 :       92794 :   delta_type_node = ptrdiff_type_node;
    5096                 :       92794 :   vtable_index_type = ptrdiff_type_node;
    5097                 :             : 
    5098                 :       92794 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5099                 :       92794 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5100                 :             : 
    5101                 :             :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5102                 :             :      is in the identifier table, so we can use identifier equality to
    5103                 :             :      find it.  */
    5104                 :       92794 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5105                 :             :                                     void_ftype);
    5106                 :             : 
    5107                 :             :   /* C++ extensions */
    5108                 :             : 
    5109                 :       92794 :   unknown_type_node = make_node (LANG_TYPE);
    5110                 :       92794 :   record_unknown_type (unknown_type_node, "unknown type");
    5111                 :             : 
    5112                 :             :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5113                 :       92794 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5114                 :             : 
    5115                 :             :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5116                 :             :      result.  */
    5117                 :       92794 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5118                 :       92794 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5119                 :             : 
    5120                 :       92794 :   init_list_type_node = make_node (LANG_TYPE);
    5121                 :       92794 :   record_unknown_type (init_list_type_node, "init list");
    5122                 :             : 
    5123                 :             :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5124                 :       92794 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5125                 :             : 
    5126                 :       92794 :   {
    5127                 :             :     /* Make sure we get a unique function type, so we can give
    5128                 :             :        its pointer type a name.  (This wins for gdb.) */
    5129                 :       92794 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5130                 :       92794 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5131                 :       92794 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5132                 :       92794 :     layout_type (vfunc_type);
    5133                 :             : 
    5134                 :       92794 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5135                 :             :   }
    5136                 :       92794 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5137                 :             : 
    5138                 :       92794 :   vtbl_type_node
    5139                 :       92794 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5140                 :       92794 :   layout_type (vtbl_type_node);
    5141                 :       92794 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5142                 :       92794 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5143                 :       92794 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5144                 :       92794 :   layout_type (vtbl_ptr_type_node);
    5145                 :       92794 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5146                 :             : 
    5147                 :       92794 :   push_namespace (get_identifier ("__cxxabiv1"));
    5148                 :       92794 :   abi_node = current_namespace;
    5149                 :       92794 :   pop_namespace ();
    5150                 :             : 
    5151                 :       92794 :   any_targ_node = make_node (LANG_TYPE);
    5152                 :       92794 :   record_unknown_type (any_targ_node, "any type");
    5153                 :             : 
    5154                 :             :   /* Now, C++.  */
    5155                 :       92794 :   current_lang_name = lang_name_cplusplus;
    5156                 :             : 
    5157                 :       92794 :   if (aligned_new_threshold > 1
    5158                 :       92794 :       && !pow2p_hwi (aligned_new_threshold))
    5159                 :             :     {
    5160                 :           0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5161                 :             :              aligned_new_threshold);
    5162                 :           0 :       aligned_new_threshold = 1;
    5163                 :             :     }
    5164                 :       92794 :   if (aligned_new_threshold == -1)
    5165                 :      113126 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5166                 :       92794 :   if (aligned_new_threshold == 1)
    5167                 :       72445 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5168                 :             : 
    5169                 :             :   /* Ensure attribs.cc is initialized.  */
    5170                 :       92794 :   init_attributes ();
    5171                 :       92794 :   cxx_init_operator_new_delete_decls ();
    5172                 :             : 
    5173                 :             :   /* C++-specific nullptr initialization.  */
    5174                 :       92794 :   if (abi_version_at_least (9))
    5175                 :       92623 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5176                 :       92794 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5177                 :             : 
    5178                 :       92794 :   if (! supports_one_only ())
    5179                 :           0 :     flag_weak = 0;
    5180                 :             : 
    5181                 :       92794 :   abort_fndecl
    5182                 :       92794 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5183                 :             :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5184                 :       92794 :   if (flag_weak)
    5185                 :             :     /* If no definition is available, resolve references to NULL.  */
    5186                 :       92764 :     declare_weak (abort_fndecl);
    5187                 :             : 
    5188                 :             :   /* Perform other language dependent initializations.  */
    5189                 :       92794 :   init_class_processing ();
    5190                 :       92794 :   init_rtti_processing ();
    5191                 :       92794 :   init_template_processing ();
    5192                 :             : 
    5193                 :       92794 :   if (flag_exceptions)
    5194                 :       91718 :     init_exception_processing ();
    5195                 :             : 
    5196                 :       92794 :   if (flag_contracts)
    5197                 :         143 :     init_terminate_fn ();
    5198                 :             : 
    5199                 :       92794 :   if (modules_p ())
    5200                 :        3996 :     init_modules (parse_in);
    5201                 :             : 
    5202                 :       92794 :   make_fname_decl = cp_make_fname_decl;
    5203                 :       92794 :   start_fname_decls ();
    5204                 :             : 
    5205                 :             :   /* Show we use EH for cleanups.  */
    5206                 :       92794 :   if (flag_exceptions)
    5207                 :       91718 :     using_eh_for_cleanups ();
    5208                 :             : 
    5209                 :             :   /* Check that the hardware interference sizes are at least
    5210                 :             :      alignof(max_align_t), as required by the standard.  */
    5211                 :       92794 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5212                 :       92794 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5213                 :             :     {
    5214                 :           0 :       if (param_destruct_interfere_size < max_align)
    5215                 :           0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5216                 :             :                "%d", param_destruct_interfere_size, max_align);
    5217                 :           0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5218                 :           0 :         warning (OPT_Winterference_size,
    5219                 :             :                  "%<--param destructive-interference-size=%d%> "
    5220                 :             :                  "is less than %<--param l1-cache-line-size=%d%>",
    5221                 :             :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5222                 :             :     }
    5223                 :       92794 :   else if (param_destruct_interfere_size)
    5224                 :             :     /* Assume the internal value is OK.  */;
    5225                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5226                 :           0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5227                 :             :   /* else leave it unset.  */
    5228                 :             : 
    5229                 :       92794 :   if (OPTION_SET_P (param_construct_interfere_size))
    5230                 :             :     {
    5231                 :           0 :       if (param_construct_interfere_size < max_align)
    5232                 :           0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5233                 :             :                "%d", param_construct_interfere_size, max_align);
    5234                 :           0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5235                 :           0 :                && param_l1_cache_line_size >= max_align)
    5236                 :           0 :         warning (OPT_Winterference_size,
    5237                 :             :                  "%<--param constructive-interference-size=%d%> "
    5238                 :             :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5239                 :             :                  param_construct_interfere_size, param_l1_cache_line_size);
    5240                 :             :     }
    5241                 :       92794 :   else if (param_construct_interfere_size)
    5242                 :             :     /* Assume the internal value is OK.  */;
    5243                 :           0 :   else if (param_l1_cache_line_size >= max_align)
    5244                 :           0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5245                 :       92794 : }
    5246                 :             : 
    5247                 :             : /* Enter an abi node in global-module context.  returns a cookie to
    5248                 :             :    give to pop_abi_namespace.  */
    5249                 :             : 
    5250                 :             : unsigned
    5251                 :       57792 : push_abi_namespace (tree node)
    5252                 :             : {
    5253                 :       57792 :   push_nested_namespace (node);
    5254                 :       57792 :   push_visibility ("default", 2);
    5255                 :       57792 :   unsigned flags = module_kind;
    5256                 :       57792 :   module_kind = 0;
    5257                 :       57792 :   return flags;
    5258                 :             : }
    5259                 :             : 
    5260                 :             : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5261                 :             :    you.  */
    5262                 :             : 
    5263                 :             : void
    5264                 :       57792 : pop_abi_namespace (unsigned flags, tree node)
    5265                 :             : {
    5266                 :       57792 :   module_kind = flags;
    5267                 :       57792 :   pop_visibility (2);
    5268                 :       57792 :   pop_nested_namespace (node);
    5269                 :       57792 : }
    5270                 :             : 
    5271                 :             : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5272                 :             :    the decl, LOC is the location to give the decl, NAME is the
    5273                 :             :    initialization string and TYPE_DEP indicates whether NAME depended
    5274                 :             :    on the type of the function. We make use of that to detect
    5275                 :             :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5276                 :             :    at the point of first use, so we mustn't push the decl now.  */
    5277                 :             : 
    5278                 :             : static tree
    5279                 :      105599 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5280                 :             : {
    5281                 :      105599 :   tree domain = NULL_TREE;
    5282                 :      105599 :   tree init = NULL_TREE;
    5283                 :             : 
    5284                 :      105599 :   if (!(type_dep && current_function_decl && in_template_context))
    5285                 :             :     {
    5286                 :       28812 :       const char *name = NULL;
    5287                 :       28812 :       bool release_name = false;
    5288                 :             : 
    5289                 :       28812 :       if (current_function_decl == NULL_TREE)
    5290                 :             :         name = "top level";
    5291                 :       28798 :       else if (type_dep == 0)
    5292                 :             :         {
    5293                 :             :           /* __FUNCTION__ */
    5294                 :         576 :           name = fname_as_string (type_dep);
    5295                 :         576 :           release_name = true;
    5296                 :             :         }
    5297                 :             :       else
    5298                 :             :         {
    5299                 :             :           /* __PRETTY_FUNCTION__ */
    5300                 :       28222 :           gcc_checking_assert (type_dep == 1);
    5301                 :       28222 :           name = cxx_printable_name (current_function_decl, 2);
    5302                 :             :         }
    5303                 :             : 
    5304                 :       28812 :       size_t length = strlen (name);
    5305                 :       28812 :       domain = build_index_type (size_int (length));
    5306                 :       28812 :       init = build_string (length + 1, name);
    5307                 :       28812 :       if (release_name)
    5308                 :         576 :         free (const_cast<char *> (name));
    5309                 :             :     }
    5310                 :             : 
    5311                 :      105599 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5312                 :      105599 :   type = build_cplus_array_type (type, domain);
    5313                 :             : 
    5314                 :      105599 :   if (init)
    5315                 :       28812 :     TREE_TYPE (init) = type;
    5316                 :             :   else
    5317                 :       76787 :     init = error_mark_node;
    5318                 :             : 
    5319                 :      105599 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5320                 :             : 
    5321                 :      105599 :   TREE_READONLY (decl) = 1;
    5322                 :      105599 :   DECL_ARTIFICIAL (decl) = 1;
    5323                 :      105599 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5324                 :      105599 :   TREE_STATIC (decl) = 1;
    5325                 :             : 
    5326                 :      105599 :   TREE_USED (decl) = 1;
    5327                 :             : 
    5328                 :      105599 :   SET_DECL_VALUE_EXPR (decl, init);
    5329                 :      105599 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5330                 :             :   /* For decl_constant_var_p.  */
    5331                 :      105599 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5332                 :             : 
    5333                 :      105599 :   if (current_function_decl)
    5334                 :             :     {
    5335                 :      105585 :       DECL_CONTEXT (decl) = current_function_decl;
    5336                 :      105585 :       decl = pushdecl_outermost_localscope (decl);
    5337                 :      105585 :       if (decl != error_mark_node)
    5338                 :      105582 :         add_decl_expr (decl);
    5339                 :             :     }
    5340                 :             :   else
    5341                 :             :     {
    5342                 :          14 :       DECL_THIS_STATIC (decl) = true;
    5343                 :          14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5344                 :             :     }
    5345                 :             : 
    5346                 :      105599 :   return decl;
    5347                 :             : }
    5348                 :             : 
    5349                 :             : /* Install DECL as a builtin function at current global scope.  Return
    5350                 :             :    the new decl (if we found an existing version).  Also installs it
    5351                 :             :    into ::std, if it's not '_*'.  */
    5352                 :             : 
    5353                 :             : tree
    5354                 :   207483921 : cxx_builtin_function (tree decl)
    5355                 :             : {
    5356                 :   207483921 :   retrofit_lang_decl (decl);
    5357                 :             : 
    5358                 :   207483921 :   DECL_ARTIFICIAL (decl) = 1;
    5359                 :   207483921 :   SET_DECL_LANGUAGE (decl, lang_c);
    5360                 :             :   /* Runtime library routines are, by definition, available in an
    5361                 :             :      external shared object.  */
    5362                 :   207483921 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5363                 :   207483921 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5364                 :             : 
    5365                 :   207483921 :   tree id = DECL_NAME (decl);
    5366                 :   207483921 :   const char *name = IDENTIFIER_POINTER (id);
    5367                 :   207483921 :   bool hiding = false;
    5368                 :   207483921 :   if (name[0] != '_' || name[1] != '_')
    5369                 :             :     /* In the user's namespace, it must be declared before use.  */
    5370                 :             :     hiding = true;
    5371                 :   173844683 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5372                 :   173844683 :            && !startswith (name + 2, "builtin_")
    5373                 :   195436382 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5374                 :             :                            "_chk", strlen ("_chk") + 1))
    5375                 :             :     /* Treat __*_chk fortification functions as anticipated as well,
    5376                 :             :        unless they are __builtin_*_chk.  */
    5377                 :             :     hiding = true;
    5378                 :             : 
    5379                 :             :   /* All builtins that don't begin with an '_' should additionally
    5380                 :             :      go in the 'std' namespace.  */
    5381                 :   207483921 :   if (name[0] != '_')
    5382                 :             :     {
    5383                 :    33512383 :       tree std_decl = copy_decl (decl);
    5384                 :             : 
    5385                 :    33512383 :       push_nested_namespace (std_node);
    5386                 :    33512383 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    5387                 :    33512383 :       pushdecl (std_decl, hiding);
    5388                 :    33512383 :       pop_nested_namespace (std_node);
    5389                 :             :     }
    5390                 :             : 
    5391                 :   207483921 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5392                 :   207483921 :   decl = pushdecl (decl, hiding);
    5393                 :             : 
    5394                 :   207483921 :   return decl;
    5395                 :             : }
    5396                 :             : 
    5397                 :             : /* Like cxx_builtin_function, but guarantee the function is added to the global
    5398                 :             :    scope.  This is to allow function specific options to add new machine
    5399                 :             :    dependent builtins when the target ISA changes via attribute((target(...)))
    5400                 :             :    which saves space on program startup if the program does not use non-generic
    5401                 :             :    ISAs.  */
    5402                 :             : 
    5403                 :             : tree
    5404                 :      667512 : cxx_builtin_function_ext_scope (tree decl)
    5405                 :             : {
    5406                 :      667512 :   push_nested_namespace (global_namespace);
    5407                 :      667512 :   decl = cxx_builtin_function (decl);
    5408                 :      667512 :   pop_nested_namespace (global_namespace);
    5409                 :             : 
    5410                 :      667512 :   return decl;
    5411                 :             : }
    5412                 :             : 
    5413                 :             : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5414                 :             : 
    5415                 :             : tree
    5416                 :           0 : cxx_simulate_builtin_function_decl (tree decl)
    5417                 :             : {
    5418                 :           0 :   retrofit_lang_decl (decl);
    5419                 :             : 
    5420                 :           0 :   DECL_ARTIFICIAL (decl) = 1;
    5421                 :           0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    5422                 :           0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5423                 :           0 :   return pushdecl (decl);
    5424                 :             : }
    5425                 :             : 
    5426                 :             : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    5427                 :             :    function.  Not called directly.  */
    5428                 :             : 
    5429                 :             : static tree
    5430                 :     1492913 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    5431                 :             :                   int ecf_flags)
    5432                 :             : {
    5433                 :     1492913 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    5434                 :     1492913 :   DECL_EXTERNAL (fn) = 1;
    5435                 :     1492913 :   TREE_PUBLIC (fn) = 1;
    5436                 :     1492913 :   DECL_ARTIFICIAL (fn) = 1;
    5437                 :     1492913 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    5438                 :     1492913 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    5439                 :     1492913 :   SET_DECL_LANGUAGE (fn, lang_c);
    5440                 :             :   /* Runtime library routines are, by definition, available in an
    5441                 :             :      external shared object.  */
    5442                 :     1492913 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    5443                 :     1492913 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    5444                 :     1492913 :   set_call_expr_flags (fn, ecf_flags);
    5445                 :     1492913 :   return fn;
    5446                 :             : }
    5447                 :             : 
    5448                 :             : /* Returns the _DECL for a library function with C++ linkage.  */
    5449                 :             : 
    5450                 :             : static tree
    5451                 :     1044942 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    5452                 :             :                      int ecf_flags)
    5453                 :             : {
    5454                 :     1044942 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    5455                 :     1044942 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    5456                 :     1044942 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    5457                 :     1044942 :   return fn;
    5458                 :             : }
    5459                 :             : 
    5460                 :             : /* Like build_library_fn, but takes a C string instead of an
    5461                 :             :    IDENTIFIER_NODE.  */
    5462                 :             : 
    5463                 :             : tree
    5464                 :       98523 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5465                 :             : {
    5466                 :       98523 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    5467                 :             : }
    5468                 :             : 
    5469                 :             : /* Like build_cp_library_fn, but takes a C string instead of an
    5470                 :             :    IDENTIFIER_NODE.  */
    5471                 :             : 
    5472                 :             : tree
    5473                 :       91802 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5474                 :             : {
    5475                 :       91802 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    5476                 :       91802 :                               ecf_flags);
    5477                 :             : }
    5478                 :             : 
    5479                 :             : /* Like build_library_fn, but also pushes the function so that we will
    5480                 :             :    be able to find it via get_global_binding.  Also, the function
    5481                 :             :    may throw exceptions listed in RAISES.  */
    5482                 :             : 
    5483                 :             : tree
    5484                 :      349448 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    5485                 :             : {
    5486                 :      349448 :   if (raises)
    5487                 :       39102 :     type = build_exception_variant (type, raises);
    5488                 :             : 
    5489                 :      349448 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    5490                 :      349448 :   return pushdecl_top_level (fn);
    5491                 :             : }
    5492                 :             : 
    5493                 :             : /* Like build_cp_library_fn, but also pushes the function so that it
    5494                 :             :    will be found by normal lookup.  */
    5495                 :             : 
    5496                 :             : static tree
    5497                 :      953140 : push_cp_library_fn (enum tree_code operator_code, tree type,
    5498                 :             :                     int ecf_flags)
    5499                 :             : {
    5500                 :      953140 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    5501                 :             :                                  operator_code, type, ecf_flags);
    5502                 :      953140 :   pushdecl (fn);
    5503                 :      953140 :   if (flag_tm)
    5504                 :        3028 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    5505                 :      953140 :   return fn;
    5506                 :             : }
    5507                 :             : 
    5508                 :             : /* Like push_library_fn, but also note that this function throws
    5509                 :             :    and does not return.  Used for __throw_foo and the like.  */
    5510                 :             : 
    5511                 :             : tree
    5512                 :      102470 : push_throw_library_fn (tree name, tree type)
    5513                 :             : {
    5514                 :      102470 :   tree fn = push_library_fn (name, type, NULL_TREE,
    5515                 :             :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    5516                 :      102470 :   return fn;
    5517                 :             : }
    5518                 :             : 
    5519                 :             : /* When we call finish_struct for an anonymous union, we create
    5520                 :             :    default copy constructors and such.  But, an anonymous union
    5521                 :             :    shouldn't have such things; this function undoes the damage to the
    5522                 :             :    anonymous union type T.
    5523                 :             : 
    5524                 :             :    (The reason that we create the synthesized methods is that we don't
    5525                 :             :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    5526                 :             :    The first is an anonymous union; the second is just an ordinary
    5527                 :             :    union type.)  */
    5528                 :             : 
    5529                 :             : void
    5530                 :       89436 : fixup_anonymous_aggr (tree t)
    5531                 :             : {
    5532                 :             :   /* Wipe out memory of synthesized methods.  */
    5533                 :       89436 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    5534                 :       89436 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    5535                 :       89436 :   TYPE_HAS_COPY_CTOR (t) = 0;
    5536                 :       89436 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    5537                 :       89436 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    5538                 :       89436 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    5539                 :             : 
    5540                 :             :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    5541                 :             :      invalid members.  */
    5542                 :      466790 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    5543                 :             :     {
    5544                 :      377354 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    5545                 :           0 :         *prev_p = DECL_CHAIN (probe);
    5546                 :             :       else
    5547                 :      377354 :         prev_p = &DECL_CHAIN (probe);
    5548                 :             : 
    5549                 :      377354 :       if (DECL_ARTIFICIAL (probe)
    5550                 :      377354 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    5551                 :       41176 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    5552                 :      133660 :         continue;
    5553                 :             : 
    5554                 :      243694 :       if (TREE_CODE (probe) != FIELD_DECL
    5555                 :      243694 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    5556                 :             :         {
    5557                 :             :           /* We already complained about static data members in
    5558                 :             :              finish_static_data_member_decl.  */
    5559                 :          66 :           if (!VAR_P (probe))
    5560                 :             :             {
    5561                 :          51 :               auto_diagnostic_group d;
    5562                 :          51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    5563                 :          51 :                              TREE_CODE (t) == UNION_TYPE
    5564                 :             :                              ? "%q#D invalid; an anonymous union may "
    5565                 :             :                              "only have public non-static data members"
    5566                 :             :                              : "%q#D invalid; an anonymous struct may "
    5567                 :             :                              "only have public non-static data members", probe))
    5568                 :             :                 {
    5569                 :          51 :                   static bool hint;
    5570                 :          51 :                   if (flag_permissive && !hint)
    5571                 :             :                     {
    5572                 :           6 :                       hint = true;
    5573                 :           6 :                       inform (DECL_SOURCE_LOCATION (probe),
    5574                 :             :                               "this flexibility is deprecated and will be "
    5575                 :             :                               "removed");
    5576                 :             :                     }
    5577                 :             :                 }
    5578                 :          51 :             }
    5579                 :             :         }
    5580                 :             :       }
    5581                 :             : 
    5582                 :             :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    5583                 :       89436 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    5584                 :       89436 :   unsigned store = 0;
    5585                 :      198663 :   for (tree elt : vec)
    5586                 :      109227 :     if (!is_overloaded_fn (elt))
    5587                 :      109206 :       (*vec)[store++] = elt;
    5588                 :       89436 :   vec_safe_truncate (vec, store);
    5589                 :             : 
    5590                 :             :   /* Wipe RTTI info.  */
    5591                 :       89436 :   CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
    5592                 :             : 
    5593                 :             :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    5594                 :             :      assignment operators (because they cannot have these methods themselves).
    5595                 :             :      For anonymous unions this is already checked because they are not allowed
    5596                 :             :      in any union, otherwise we have to check it.  */
    5597                 :       89436 :   if (TREE_CODE (t) != UNION_TYPE)
    5598                 :             :     {
    5599                 :       19451 :       tree field, type;
    5600                 :             : 
    5601                 :       19451 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    5602                 :             :         {
    5603                 :           9 :           error_at (location_of (t), "anonymous struct with base classes");
    5604                 :             :           /* Avoid ICE after error on anon-struct9.C.  */
    5605                 :           9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    5606                 :             :         }
    5607                 :             : 
    5608                 :       87970 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5609                 :       68519 :         if (TREE_CODE (field) == FIELD_DECL)
    5610                 :             :           {
    5611                 :       48967 :             type = TREE_TYPE (field);
    5612                 :       48967 :             if (CLASS_TYPE_P (type))
    5613                 :             :               {
    5614                 :          61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    5615                 :           6 :                   error ("member %q+#D with constructor not allowed "
    5616                 :             :                          "in anonymous aggregate", field);
    5617                 :          61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5618                 :           0 :                   error ("member %q+#D with destructor not allowed "
    5619                 :             :                          "in anonymous aggregate", field);
    5620                 :          61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    5621                 :           0 :                   error ("member %q+#D with copy assignment operator "
    5622                 :             :                          "not allowed in anonymous aggregate", field);
    5623                 :             :               }
    5624                 :             :           }
    5625                 :             :     }
    5626                 :       89436 : }
    5627                 :             : 
    5628                 :             : /* Warn for an attribute located at LOCATION that appertains to the
    5629                 :             :    class type CLASS_TYPE that has not been properly placed after its
    5630                 :             :    class-key, in it class-specifier.  */
    5631                 :             : 
    5632                 :             : void
    5633                 :          84 : warn_misplaced_attr_for_class_type (location_t location,
    5634                 :             :                                     tree class_type)
    5635                 :             : {
    5636                 :          84 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    5637                 :             : 
    5638                 :          84 :   auto_diagnostic_group d;
    5639                 :          84 :   if (warning_at (location, OPT_Wattributes,
    5640                 :             :                   "attribute ignored in declaration "
    5641                 :             :                   "of %q#T", class_type))
    5642                 :          84 :     inform (location,
    5643                 :             :             "attribute for %q#T must follow the %qs keyword",
    5644                 :             :             class_type, class_key_or_enum_as_string (class_type));
    5645                 :          84 : }
    5646                 :             : 
    5647                 :             : /* Returns the cv-qualifiers that apply to the type specified
    5648                 :             :    by the DECLSPECS.  */
    5649                 :             : 
    5650                 :             : static int
    5651                 :   867807897 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    5652                 :             : {
    5653                 :   867807897 :   int type_quals = TYPE_UNQUALIFIED;
    5654                 :             : 
    5655                 :   867807897 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5656                 :    95837015 :     type_quals |= TYPE_QUAL_CONST;
    5657                 :   867807897 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5658                 :     1516255 :     type_quals |= TYPE_QUAL_VOLATILE;
    5659                 :   867807897 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5660                 :          34 :     type_quals |= TYPE_QUAL_RESTRICT;
    5661                 :             : 
    5662                 :   867807897 :   return type_quals;
    5663                 :             : }
    5664                 :             : 
    5665                 :             : /* Make sure that a declaration with no declarator is well-formed, i.e.
    5666                 :             :    just declares a tagged type or anonymous union.
    5667                 :             : 
    5668                 :             :    Returns the type declared; or NULL_TREE if none.  */
    5669                 :             : 
    5670                 :             : tree
    5671                 :    30810527 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    5672                 :             :                 bool explicit_type_instantiation_p)
    5673                 :             : {
    5674                 :    30810527 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    5675                 :    30810527 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    5676                 :             :   /* If a class, struct, or enum type is declared by the DECLSPECS
    5677                 :             :      (i.e, if a class-specifier, enum-specifier, or non-typename
    5678                 :             :      elaborated-type-specifier appears in the DECLSPECS),
    5679                 :             :      DECLARED_TYPE is set to the corresponding type.  */
    5680                 :    30810527 :   tree declared_type = NULL_TREE;
    5681                 :    30810527 :   bool error_p = false;
    5682                 :             : 
    5683                 :    30810527 :   if (declspecs->multiple_types_p)
    5684                 :          26 :     error_at (smallest_type_location (declspecs),
    5685                 :             :               "multiple types in one declaration");
    5686                 :    30810501 :   else if (declspecs->redefined_builtin_type)
    5687                 :             :     {
    5688                 :          21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    5689                 :          21 :       if (!in_system_header_at (loc))
    5690                 :           9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    5691                 :             :                    declspecs->redefined_builtin_type);
    5692                 :          21 :       return NULL_TREE;
    5693                 :             :     }
    5694                 :             : 
    5695                 :    30810506 :   if (declspecs->type
    5696                 :    30810491 :       && TYPE_P (declspecs->type)
    5697                 :    61448013 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    5698                 :    30636250 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    5699                 :     1575921 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    5700                 :             :     declared_type = declspecs->type;
    5701                 :      174298 :   else if (declspecs->type == error_mark_node)
    5702                 :        1462 :     error_p = true;
    5703                 :             : 
    5704                 :    30810506 :   if (type_uses_auto (declared_type))
    5705                 :             :     {
    5706                 :           8 :       error_at (declspecs->locations[ds_type_spec],
    5707                 :             :                 "%<auto%> can only be specified for variables "
    5708                 :             :                 "or function declarations");
    5709                 :           8 :       return error_mark_node;
    5710                 :             :     }
    5711                 :             : 
    5712                 :    30810498 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    5713                 :             :     declared_type = NULL_TREE;
    5714                 :             : 
    5715                 :    30810498 :   if (!declared_type && !saw_friend && !error_p)
    5716                 :          88 :     permerror (input_location, "declaration does not declare anything");
    5717                 :             :   /* Check for an anonymous union.  */
    5718                 :    30636173 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    5719                 :    89022954 :            && TYPE_UNNAMED_P (declared_type))
    5720                 :             :     {
    5721                 :             :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    5722                 :             :          can be omitted only when declaring a class (clause 9) or
    5723                 :             :          enumeration (7.2), that is, when the decl-specifier-seq contains
    5724                 :             :          either a class-specifier, an elaborated-type-specifier with
    5725                 :             :          a class-key (9.1), or an enum-specifier.  In these cases and
    5726                 :             :          whenever a class-specifier or enum-specifier is present in the
    5727                 :             :          decl-specifier-seq, the identifiers in these specifiers are among
    5728                 :             :          the names being declared by the declaration (as class-name,
    5729                 :             :          enum-names, or enumerators, depending on the syntax).  In such
    5730                 :             :          cases, and except for the declaration of an unnamed bit-field (9.6),
    5731                 :             :          the decl-specifier-seq shall introduce one or more names into the
    5732                 :             :          program, or shall redeclare a name introduced by a previous
    5733                 :             :          declaration.  [Example:
    5734                 :             :              enum { };                  // ill-formed
    5735                 :             :              typedef class { };         // ill-formed
    5736                 :             :          --end example]  */
    5737                 :       89442 :       if (saw_typedef)
    5738                 :             :         {
    5739                 :           6 :           error_at (declspecs->locations[ds_typedef],
    5740                 :             :                     "missing type-name in typedef-declaration");
    5741                 :           6 :           return NULL_TREE;
    5742                 :             :         }
    5743                 :       89436 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    5744                 :       89436 :       SET_ANON_AGGR_TYPE_P (declared_type);
    5745                 :             : 
    5746                 :       89436 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    5747                 :       19451 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    5748                 :             :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    5749                 :             :     }
    5750                 :             : 
    5751                 :             :   else
    5752                 :             :     {
    5753                 :    30720968 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    5754                 :           9 :         error_at (declspecs->locations[ds_inline],
    5755                 :             :                   "%<inline%> can only be specified for functions");
    5756                 :    30720959 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    5757                 :           3 :         error_at (declspecs->locations[ds_virtual],
    5758                 :             :                   "%<virtual%> can only be specified for functions");
    5759                 :    30720956 :       else if (saw_friend
    5760                 :    30720956 :                && (!current_class_type
    5761                 :     1569520 :                    || current_scope () != current_class_type))
    5762                 :           0 :         error_at (declspecs->locations[ds_friend],
    5763                 :             :                   "%<friend%> can only be specified inside a class");
    5764                 :    30720956 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    5765                 :           3 :         error_at (declspecs->locations[ds_explicit],
    5766                 :             :                   "%<explicit%> can only be specified for constructors");
    5767                 :    30720953 :       else if (declspecs->storage_class)
    5768                 :           3 :         error_at (declspecs->locations[ds_storage_class],
    5769                 :             :                   "a storage class can only be specified for objects "
    5770                 :             :                   "and functions");
    5771                 :    30720950 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5772                 :           9 :         error_at (declspecs->locations[ds_const],
    5773                 :             :                   "%<const%> can only be specified for objects and "
    5774                 :             :                   "functions");
    5775                 :    30720941 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5776                 :           3 :         error_at (declspecs->locations[ds_volatile],
    5777                 :             :                   "%<volatile%> can only be specified for objects and "
    5778                 :             :                   "functions");
    5779                 :    30720938 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5780                 :           3 :         error_at (declspecs->locations[ds_restrict],
    5781                 :             :                   "%<__restrict%> can only be specified for objects and "
    5782                 :             :                   "functions");
    5783                 :    30720935 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    5784                 :           3 :         error_at (declspecs->locations[ds_thread],
    5785                 :             :                   "%<__thread%> can only be specified for objects "
    5786                 :             :                   "and functions");
    5787                 :    30720932 :       else if (saw_typedef)
    5788                 :          24 :         warning_at (declspecs->locations[ds_typedef], 0,
    5789                 :             :                     "%<typedef%> was ignored in this declaration");
    5790                 :    30720908 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    5791                 :           9 :         error_at (declspecs->locations[ds_constexpr],
    5792                 :             :                   "%qs cannot be used for type declarations", "constexpr");
    5793                 :    30720899 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5794                 :           3 :         error_at (declspecs->locations[ds_constinit],
    5795                 :             :                   "%qs cannot be used for type declarations", "constinit");
    5796                 :    30720896 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    5797                 :           3 :         error_at (declspecs->locations[ds_consteval],
    5798                 :             :                   "%qs cannot be used for type declarations", "consteval");
    5799                 :             :     }
    5800                 :             : 
    5801                 :    30810492 :   if (declspecs->attributes && warn_attributes && declared_type)
    5802                 :             :     {
    5803                 :          31 :       location_t loc;
    5804                 :          25 :       if (!CLASS_TYPE_P (declared_type)
    5805                 :          56 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    5806                 :             :         /* For a non-template class, use the name location.  */
    5807                 :          22 :         loc = location_of (declared_type);
    5808                 :             :       else
    5809                 :             :         /* For a template class (an explicit instantiation), use the
    5810                 :             :            current location.  */
    5811                 :           9 :         loc = input_location;
    5812                 :             : 
    5813                 :          31 :       if (explicit_type_instantiation_p)
    5814                 :             :         /* [dcl.attr.grammar]/4:
    5815                 :             : 
    5816                 :             :                No attribute-specifier-seq shall appertain to an explicit
    5817                 :             :                instantiation.  */
    5818                 :             :         {
    5819                 :           6 :           auto_diagnostic_group d;
    5820                 :           6 :           if (warning_at (loc, OPT_Wattributes,
    5821                 :             :                           "attribute ignored in explicit instantiation %q#T",
    5822                 :             :                           declared_type))
    5823                 :           6 :             inform (loc,
    5824                 :             :                     "no attribute can be applied to "
    5825                 :             :                     "an explicit instantiation");
    5826                 :           6 :         }
    5827                 :             :       else
    5828                 :          25 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    5829                 :             :     }
    5830                 :             : 
    5831                 :    30810492 :   if (declspecs->std_attributes
    5832                 :          59 :       && declared_type
    5833                 :    30810548 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    5834                 :             :     {
    5835                 :          56 :       auto_diagnostic_group d;
    5836                 :          56 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    5837                 :             :                       "attribute ignored"))
    5838                 :          56 :         inform (declspecs->locations[ds_std_attribute],
    5839                 :             :                 "an attribute that appertains to a type-specifier is ignored");
    5840                 :          56 :     }
    5841                 :             : 
    5842                 :             :   /* Diagnose invalid application of contracts, if any.  */
    5843                 :    30810492 :   if (find_contract (declspecs->attributes))
    5844                 :           1 :     diagnose_misapplied_contracts (declspecs->attributes);
    5845                 :             :   else
    5846                 :    30810491 :     diagnose_misapplied_contracts (declspecs->std_attributes);
    5847                 :             : 
    5848                 :             :   return declared_type;
    5849                 :             : }
    5850                 :             : 
    5851                 :             : /* Called when a declaration is seen that contains no names to declare.
    5852                 :             :    If its type is a reference to a structure, union or enum inherited
    5853                 :             :    from a containing scope, shadow that tag name for the current scope
    5854                 :             :    with a forward reference.
    5855                 :             :    If its type defines a new named structure or union
    5856                 :             :    or defines an enum, it is valid but we need not do anything here.
    5857                 :             :    Otherwise, it is an error.
    5858                 :             : 
    5859                 :             :    C++: may have to grok the declspecs to learn about static,
    5860                 :             :    complain for anonymous unions.
    5861                 :             : 
    5862                 :             :    Returns the TYPE declared -- or NULL_TREE if none.  */
    5863                 :             : 
    5864                 :             : tree
    5865                 :    27029370 : shadow_tag (cp_decl_specifier_seq *declspecs)
    5866                 :             : {
    5867                 :    27029370 :   tree t = check_tag_decl (declspecs,
    5868                 :             :                            /*explicit_type_instantiation_p=*/false);
    5869                 :             : 
    5870                 :    27029370 :   if (!t)
    5871                 :             :     return NULL_TREE;
    5872                 :             : 
    5873                 :    27027901 :   t = maybe_process_partial_specialization (t);
    5874                 :    27027901 :   if (t == error_mark_node)
    5875                 :             :     return NULL_TREE;
    5876                 :             : 
    5877                 :             :   /* This is where the variables in an anonymous union are
    5878                 :             :      declared.  An anonymous union declaration looks like:
    5879                 :             :      union { ... } ;
    5880                 :             :      because there is no declarator after the union, the parser
    5881                 :             :      sends that declaration here.  */
    5882                 :    27026756 :   if (ANON_AGGR_TYPE_P (t))
    5883                 :             :     {
    5884                 :         245 :       fixup_anonymous_aggr (t);
    5885                 :             : 
    5886                 :         245 :       if (TYPE_FIELDS (t))
    5887                 :             :         {
    5888                 :         245 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    5889                 :             :                                       declspecs, NORMAL, 0, NULL);
    5890                 :         245 :           finish_anon_union (decl);
    5891                 :             :         }
    5892                 :             :     }
    5893                 :             : 
    5894                 :             :   return t;
    5895                 :             : }
    5896                 :             : 
    5897                 :             : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    5898                 :             : 
    5899                 :             : tree
    5900                 :   319277559 : groktypename (cp_decl_specifier_seq *type_specifiers,
    5901                 :             :               const cp_declarator *declarator,
    5902                 :             :               bool is_template_arg)
    5903                 :             : {
    5904                 :   319277559 :   tree attrs;
    5905                 :   319277559 :   tree type;
    5906                 :   638555118 :   enum decl_context context
    5907                 :   319277559 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    5908                 :   319277559 :   attrs = type_specifiers->attributes;
    5909                 :   319277559 :   type_specifiers->attributes = NULL_TREE;
    5910                 :   319277559 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    5911                 :   319277559 :   if (attrs && type != error_mark_node)
    5912                 :             :     {
    5913                 :         577 :       if (CLASS_TYPE_P (type))
    5914                 :           6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    5915                 :             :                  "outside of definition", type);
    5916                 :         571 :       else if (MAYBE_CLASS_TYPE_P (type))
    5917                 :             :         /* A template type parameter or other dependent type.  */
    5918                 :           9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    5919                 :             :                  "type %qT without an associated declaration", type);
    5920                 :             :       else
    5921                 :         562 :         cplus_decl_attributes (&type, attrs, 0);
    5922                 :             :     }
    5923                 :   319277559 :   return type;
    5924                 :             : }
    5925                 :             : 
    5926                 :             : /* Process a DECLARATOR for a function-scope or namespace-scope
    5927                 :             :    variable or function declaration.
    5928                 :             :    (Function definitions go through start_function; class member
    5929                 :             :    declarations appearing in the body of the class go through
    5930                 :             :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    5931                 :             :    If an error occurs, the error_mark_node is returned instead.
    5932                 :             : 
    5933                 :             :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    5934                 :             :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    5935                 :             :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    5936                 :             :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    5937                 :             :    implicitly initialized via a default constructor.  It can also be
    5938                 :             :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    5939                 :             :    mark the new decl as DECL_DECOMPOSITION_P.
    5940                 :             : 
    5941                 :             :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    5942                 :             :    declaration.
    5943                 :             : 
    5944                 :             :    The scope represented by the context of the returned DECL is pushed
    5945                 :             :    (if it is not the global namespace) and is assigned to
    5946                 :             :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    5947                 :             :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    5948                 :             : 
    5949                 :             : tree
    5950                 :   107438751 : start_decl (const cp_declarator *declarator,
    5951                 :             :             cp_decl_specifier_seq *declspecs,
    5952                 :             :             int initialized,
    5953                 :             :             tree attributes,
    5954                 :             :             tree prefix_attributes,
    5955                 :             :             tree *pushed_scope_p)
    5956                 :             : {
    5957                 :   107438751 :   tree decl;
    5958                 :   107438751 :   tree context;
    5959                 :   107438751 :   bool was_public;
    5960                 :   107438751 :   int flags;
    5961                 :   107438751 :   bool alias;
    5962                 :   107438751 :   tree initial;
    5963                 :             : 
    5964                 :   107438751 :   *pushed_scope_p = NULL_TREE;
    5965                 :             : 
    5966                 :   107438751 :   if (prefix_attributes != error_mark_node)
    5967                 :   107438749 :     attributes = attr_chainon (attributes, prefix_attributes);
    5968                 :             : 
    5969                 :   107438751 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    5970                 :             :                          &attributes);
    5971                 :             : 
    5972                 :   107438751 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    5973                 :   107438751 :       || decl == error_mark_node
    5974                 :   107436637 :       || prefix_attributes == error_mark_node)
    5975                 :        2116 :     return error_mark_node;
    5976                 :             : 
    5977                 :   107436635 :   context = CP_DECL_CONTEXT (decl);
    5978                 :   107436635 :   if (context != global_namespace)
    5979                 :    16533845 :     *pushed_scope_p = push_scope (context);
    5980                 :             : 
    5981                 :   107436635 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    5982                 :             :     {
    5983                 :           9 :       error_at (DECL_SOURCE_LOCATION (decl),
    5984                 :             :                 "typedef %qD is initialized (use %qs instead)",
    5985                 :             :                 decl, "decltype");
    5986                 :           9 :       return error_mark_node;
    5987                 :             :     }
    5988                 :             : 
    5989                 :             :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    5990                 :             :      with attribute validation.  */
    5991                 :   107436626 :   initial = DECL_INITIAL (decl);
    5992                 :             : 
    5993                 :   107436626 :   if (initialized)
    5994                 :             :     {
    5995                 :    47324891 :       if (! toplevel_bindings_p ()
    5996                 :    47324891 :           && DECL_EXTERNAL (decl))
    5997                 :           3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    5998                 :             :                  decl);
    5999                 :    47324891 :       DECL_EXTERNAL (decl) = 0;
    6000                 :    47324891 :       if (toplevel_bindings_p ())
    6001                 :     3985011 :         TREE_STATIC (decl) = 1;
    6002                 :             :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6003                 :             :          even though we might not yet have the initializer expression.  */
    6004                 :    47324891 :       if (!DECL_INITIAL (decl))
    6005                 :    46996318 :         DECL_INITIAL (decl) = error_mark_node;
    6006                 :             :     }
    6007                 :   107436626 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6008                 :             : 
    6009                 :   107436626 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6010                 :        3865 :     record_key_method_defined (decl);
    6011                 :             : 
    6012                 :             :   /* If this is a typedef that names the class for linkage purposes
    6013                 :             :      (7.1.3p8), apply any attributes directly to the type.  */
    6014                 :   107436626 :   if (TREE_CODE (decl) == TYPE_DECL
    6015                 :    18710924 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    6016                 :   114859233 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    6017                 :             :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6018                 :             :   else
    6019                 :             :     flags = 0;
    6020                 :             : 
    6021                 :             :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6022                 :   107436626 :   cplus_decl_attributes (&decl, attributes, flags);
    6023                 :             : 
    6024                 :             :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6025                 :             :      assist with attribute validation.  */
    6026                 :   107436626 :   DECL_INITIAL (decl) = initial;
    6027                 :             : 
    6028                 :             :   /* Dllimported symbols cannot be defined.  Static data members (which
    6029                 :             :      can be initialized in-class and dllimported) go through grokfield,
    6030                 :             :      not here, so we don't need to exclude those decls when checking for
    6031                 :             :      a definition.  */
    6032                 :   107436626 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6033                 :             :     {
    6034                 :           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6035                 :             :                 "definition of %q#D is marked %<dllimport%>", decl);
    6036                 :           0 :       DECL_DLLIMPORT_P (decl) = 0;
    6037                 :             :     }
    6038                 :             : 
    6039                 :             :   /* If #pragma weak was used, mark the decl weak now.  */
    6040                 :   107436626 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6041                 :    41042640 :     maybe_apply_pragma_weak (decl);
    6042                 :             : 
    6043                 :   107436626 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6044                 :    35714746 :       && DECL_DECLARED_INLINE_P (decl)
    6045                 :     1705377 :       && DECL_UNINLINABLE (decl)
    6046                 :   107436626 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6047                 :             :     {
    6048                 :           0 :       auto_urlify_attributes sentinel;
    6049                 :           0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6050                 :             :                   "inline function %qD given attribute %qs", decl, "noinline");
    6051                 :           0 :     }
    6052                 :             : 
    6053                 :   107436626 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6054                 :             :     {
    6055                 :      726049 :       bool this_tmpl = (current_template_depth
    6056                 :      726049 :                         > template_class_depth (context));
    6057                 :      726049 :       if (VAR_P (decl))
    6058                 :             :         {
    6059                 :      369590 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6060                 :      369590 :           if (field == NULL_TREE
    6061                 :      369590 :               || !(VAR_P (field) || variable_template_p (field)))
    6062                 :           7 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6063                 :      369583 :           else if (variable_template_p (field)
    6064                 :      369583 :                    && (DECL_LANG_SPECIFIC (decl)
    6065                 :         105 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6066                 :             :             /* OK, specialization was already checked.  */;
    6067                 :      369520 :           else if (variable_template_p (field) && !this_tmpl)
    6068                 :             :             {
    6069                 :           3 :               auto_diagnostic_group d;
    6070                 :           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6071                 :             :                         "non-member-template declaration of %qD", decl);
    6072                 :           3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6073                 :             :                       "member template declaration here");
    6074                 :           3 :               return error_mark_node;
    6075                 :           3 :             }
    6076                 :             :           else
    6077                 :             :             {
    6078                 :      369517 :               if (variable_template_p (field))
    6079                 :          39 :                 field = DECL_TEMPLATE_RESULT (field);
    6080                 :             : 
    6081                 :      369517 :               if (DECL_CONTEXT (field) != context)
    6082                 :             :                 {
    6083                 :           3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6084                 :           3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6085                 :             :                                "to be defined as %<%T::%D%>",
    6086                 :           3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6087                 :           3 :                                context, DECL_NAME (decl));
    6088                 :           3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6089                 :             :                 }
    6090                 :             :               /* Static data member are tricky; an in-class initialization
    6091                 :             :                  still doesn't provide a definition, so the in-class
    6092                 :             :                  declaration will have DECL_EXTERNAL set, but will have an
    6093                 :             :                  initialization.  Thus, duplicate_decls won't warn
    6094                 :             :                  about this situation, and so we check here.  */
    6095                 :      369517 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6096                 :           9 :                 error ("duplicate initialization of %qD", decl);
    6097                 :      369517 :               field = duplicate_decls (decl, field);
    6098                 :      369517 :               if (field == error_mark_node)
    6099                 :             :                 return error_mark_node;
    6100                 :      369461 :               else if (field)
    6101                 :      369461 :                 decl = field;
    6102                 :             :             }
    6103                 :             :         }
    6104                 :             :       else
    6105                 :             :         {
    6106                 :      356472 :           tree field = check_classfn (context, decl,
    6107                 :             :                                       this_tmpl
    6108                 :          13 :                                       ? current_template_parms
    6109                 :             :                                       : NULL_TREE);
    6110                 :      356387 :           if (field && field != error_mark_node
    6111                 :      712846 :               && duplicate_decls (decl, field))
    6112                 :      356386 :             decl = field;
    6113                 :             :         }
    6114                 :             : 
    6115                 :             :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6116                 :      725990 :       DECL_IN_AGGR_P (decl) = 0;
    6117                 :             :       /* Do not mark DECL as an explicit specialization if it was not
    6118                 :             :          already marked as an instantiation; a declaration should
    6119                 :             :          never be marked as a specialization unless we know what
    6120                 :             :          template is being specialized.  */
    6121                 :      725990 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6122                 :             :         {
    6123                 :      354905 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6124                 :      354905 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6125                 :      334344 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6126                 :      334344 :                                   && DECL_DECLARED_INLINE_P (decl));
    6127                 :             :           else
    6128                 :       20561 :             DECL_COMDAT (decl) = false;
    6129                 :             : 
    6130                 :             :           /* [temp.expl.spec] An explicit specialization of a static data
    6131                 :             :              member of a template is a definition if the declaration
    6132                 :             :              includes an initializer; otherwise, it is a declaration.
    6133                 :             : 
    6134                 :             :              We check for processing_specialization so this only applies
    6135                 :             :              to the new specialization syntax.  */
    6136                 :      354905 :           if (!initialized && processing_specialization)
    6137                 :      354712 :             DECL_EXTERNAL (decl) = 1;
    6138                 :             :         }
    6139                 :             : 
    6140                 :     1080771 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6141                 :             :           /* Aliases are definitions. */
    6142                 :      726047 :           && !alias)
    6143                 :             :         {
    6144                 :          30 :           if (DECL_VIRTUAL_P (decl) || !flag_contracts)
    6145                 :          11 :             permerror (declarator->id_loc,
    6146                 :             :                        "declaration of %q#D outside of class is not definition",
    6147                 :             :                        decl);
    6148                 :          19 :           else if (flag_contract_strict_declarations)
    6149                 :           4 :             warning_at (declarator->id_loc, OPT_fcontract_strict_declarations_,
    6150                 :             :                         "declaration of %q#D outside of class is not definition",
    6151                 :             :                         decl);
    6152                 :             :         }
    6153                 :             :     }
    6154                 :             : 
    6155                 :             :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6156                 :   107436567 :   if (initialized == SD_DECOMPOSITION)
    6157                 :      138588 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6158                 :             : 
    6159                 :   107436567 :   was_public = TREE_PUBLIC (decl);
    6160                 :             : 
    6161                 :   178917094 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6162                 :   107765158 :       && current_function_decl)
    6163                 :             :     {
    6164                 :             :       /* A function-scope decl of some namespace-scope decl.  */
    6165                 :       35617 :       DECL_LOCAL_DECL_P (decl) = true;
    6166                 :       35617 :       if (named_module_attach_p ())
    6167                 :           3 :         error_at (declarator->id_loc,
    6168                 :             :                   "block-scope extern declaration %q#D must not be"
    6169                 :             :                   " attached to a named module", decl);
    6170                 :             :     }
    6171                 :             : 
    6172                 :             :   /* Enter this declaration into the symbol table.  Don't push the plain
    6173                 :             :      VAR_DECL for a variable template.  */
    6174                 :   107436567 :   if (!template_parm_scope_p ()
    6175                 :   107436567 :       || !VAR_P (decl))
    6176                 :   104891045 :     decl = maybe_push_decl (decl);
    6177                 :             : 
    6178                 :   107436567 :   if (processing_template_decl)
    6179                 :    66388802 :     decl = push_template_decl (decl);
    6180                 :             : 
    6181                 :   107436567 :   if (decl == error_mark_node)
    6182                 :             :     return error_mark_node;
    6183                 :             : 
    6184                 :   107436188 :   if (VAR_P (decl)
    6185                 :    53010700 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6186                 :       65534 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6187                 :             :       /* But not templated variables.  */
    6188                 :   107463061 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6189                 :             :     {
    6190                 :             :       /* This is a const variable with implicit 'static'.  Set
    6191                 :             :          DECL_THIS_STATIC so we can tell it from variables that are
    6192                 :             :          !TREE_PUBLIC because of the anonymous namespace.  */
    6193                 :       26873 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6194                 :       26873 :       DECL_THIS_STATIC (decl) = 1;
    6195                 :             :     }
    6196                 :             : 
    6197                 :    59119813 :   if (current_function_decl && VAR_P (decl)
    6198                 :    48101344 :       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
    6199                 :   112268808 :       && cxx_dialect < cxx23)
    6200                 :             :     {
    6201                 :     2785372 :       bool ok = false;
    6202                 :     2785372 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6203                 :          20 :         error_at (DECL_SOURCE_LOCATION (decl),
    6204                 :             :                   "%qD defined %<thread_local%> in %qs function only "
    6205                 :             :                   "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6206                 :          10 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6207                 :             :                   ? "consteval" : "constexpr");
    6208                 :     2785362 :       else if (TREE_STATIC (decl))
    6209                 :          76 :         error_at (DECL_SOURCE_LOCATION (decl),
    6210                 :             :                   "%qD defined %<static%> in %qs function only available "
    6211                 :             :                   "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6212                 :          38 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6213                 :             :                   ? "consteval" : "constexpr");
    6214                 :             :       else
    6215                 :             :         ok = true;
    6216                 :          48 :       if (!ok)
    6217                 :          48 :         cp_function_chain->invalid_constexpr = true;
    6218                 :             :     }
    6219                 :             : 
    6220                 :   107436188 :   if (!processing_template_decl && VAR_P (decl))
    6221                 :     5121242 :     start_decl_1 (decl, initialized);
    6222                 :             : 
    6223                 :   107436185 :   return decl;
    6224                 :             : }
    6225                 :             : 
    6226                 :             : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6227                 :             :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6228                 :             :    variable is initialized via an implicitly-called constructor.)
    6229                 :             :    This function must be called for ordinary variables (including, for
    6230                 :             :    example, implicit instantiations of templates), but must not be
    6231                 :             :    called for template declarations.  */
    6232                 :             : 
    6233                 :             : void
    6234                 :     5128661 : start_decl_1 (tree decl, bool initialized)
    6235                 :             : {
    6236                 :     5128661 :   gcc_checking_assert (!processing_template_decl);
    6237                 :             : 
    6238                 :     5128661 :   if (error_operand_p (decl))
    6239                 :             :     return;
    6240                 :             : 
    6241                 :     5128646 :   gcc_checking_assert (VAR_P (decl));
    6242                 :             : 
    6243                 :     5128646 :   tree type = TREE_TYPE (decl);
    6244                 :     5128646 :   bool complete_p = COMPLETE_TYPE_P (type);
    6245                 :     5128646 :   bool aggregate_definition_p
    6246                 :     5128646 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6247                 :             : 
    6248                 :             :   /* If an explicit initializer is present, or if this is a definition
    6249                 :             :      of an aggregate, then we need a complete type at this point.
    6250                 :             :      (Scalars are always complete types, so there is nothing to
    6251                 :             :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6252                 :             :      are issued below.  */
    6253                 :     3261043 :   if ((initialized || aggregate_definition_p)
    6254                 :     4107864 :       && !complete_p
    6255                 :     4131251 :       && COMPLETE_TYPE_P (complete_type (type)))
    6256                 :             :     {
    6257                 :      324691 :       complete_p = true;
    6258                 :             :       /* We will not yet have set TREE_READONLY on DECL if the type
    6259                 :             :          was "const", but incomplete, before this point.  But, now, we
    6260                 :             :          have a complete type, so we can try again.  */
    6261                 :      324691 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6262                 :             :     }
    6263                 :             : 
    6264                 :     5128643 :   if (initialized)
    6265                 :             :     /* Is it valid for this decl to have an initializer at all?  */
    6266                 :             :     {
    6267                 :             :       /* Don't allow initializations for incomplete types except for
    6268                 :             :          arrays which might be completed by the initialization.  */
    6269                 :     3508094 :       if (complete_p)
    6270                 :             :         ;                       /* A complete type is ok.  */
    6271                 :      545290 :       else if (type_uses_auto (type))
    6272                 :             :         ;                       /* An auto type is ok.  */
    6273                 :       59542 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6274                 :             :         {
    6275                 :          24 :           auto_diagnostic_group d;
    6276                 :          24 :           error ("variable %q#D has initializer but incomplete type", decl);
    6277                 :          42 :           maybe_suggest_missing_header (input_location,
    6278                 :          24 :                                         TYPE_IDENTIFIER (type),
    6279                 :          24 :                                         CP_TYPE_CONTEXT (type));
    6280                 :          24 :           type = TREE_TYPE (decl) = error_mark_node;
    6281                 :          24 :         }
    6282                 :       59518 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6283                 :             :         {
    6284                 :           0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6285                 :           0 :             error ("elements of array %q#D have incomplete type", decl);
    6286                 :             :           /* else we already gave an error in start_decl.  */
    6287                 :             :         }
    6288                 :             :     }
    6289                 :     1620549 :   else if (aggregate_definition_p && !complete_p)
    6290                 :             :     {
    6291                 :         224 :       if (type_uses_auto (type))
    6292                 :          64 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6293                 :             :       else
    6294                 :             :         {
    6295                 :         160 :           auto_diagnostic_group d;
    6296                 :         160 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6297                 :             :                  decl);
    6298                 :         275 :           maybe_suggest_missing_header (input_location,
    6299                 :         160 :                                         TYPE_IDENTIFIER (type),
    6300                 :         160 :                                         CP_TYPE_CONTEXT (type));
    6301                 :             :           /* Change the type so that assemble_variable will give
    6302                 :             :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6303                 :         160 :           type = TREE_TYPE (decl) = error_mark_node;
    6304                 :         160 :         }
    6305                 :             :     }
    6306                 :             : 
    6307                 :             :   /* Create a new scope to hold this declaration if necessary.
    6308                 :             :      Whether or not a new scope is necessary cannot be determined
    6309                 :             :      until after the type has been completed; if the type is a
    6310                 :             :      specialization of a class template it is not until after
    6311                 :             :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6312                 :             :      will be set correctly.  */
    6313                 :     5128643 :   maybe_push_cleanup_level (type);
    6314                 :             : }
    6315                 :             : 
    6316                 :             : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6317                 :             :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6318                 :             : 
    6319                 :             : tree
    6320                 :         239 : do_aggregate_paren_init (tree init, tree type)
    6321                 :             : {
    6322                 :         239 :   tree val = TREE_VALUE (init);
    6323                 :             : 
    6324                 :         239 :   if (TREE_CHAIN (init) == NULL_TREE)
    6325                 :             :     {
    6326                 :             :       /* If the list has a single element and it's a string literal,
    6327                 :             :          then it's the initializer for the array as a whole.  */
    6328                 :         124 :       if (TREE_CODE (type) == ARRAY_TYPE
    6329                 :         124 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6330                 :         155 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6331                 :             :              == STRING_CST)
    6332                 :             :         return val;
    6333                 :             :       /* Handle non-standard extensions like compound literals.  This also
    6334                 :             :          prevents triggering aggregate parenthesized-initialization in
    6335                 :             :          compiler-generated code for =default.  */
    6336                 :          97 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6337                 :          97 :                                                           TREE_TYPE (val)))
    6338                 :             :         return val;
    6339                 :             :     }
    6340                 :             : 
    6341                 :         187 :   init = build_constructor_from_list (init_list_type_node, init);
    6342                 :         187 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6343                 :         187 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6344                 :         187 :   return init;
    6345                 :             : }
    6346                 :             : 
    6347                 :             : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6348                 :             :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6349                 :             :    but will be set to a new CLEANUP_STMT if a temporary is created
    6350                 :             :    that must be destroyed subsequently.
    6351                 :             : 
    6352                 :             :    Returns an initializer expression to use to initialize DECL, or
    6353                 :             :    NULL if the initialization can be performed statically.
    6354                 :             : 
    6355                 :             :    Quotes on semantics can be found in ARM 8.4.3.  */
    6356                 :             : 
    6357                 :             : static tree
    6358                 :      285949 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6359                 :             : {
    6360                 :      285949 :   if (init == NULL_TREE)
    6361                 :             :     {
    6362                 :          15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6363                 :           3 :            || DECL_IN_AGGR_P (decl) == 0)
    6364                 :          18 :           && ! DECL_THIS_EXTERN (decl))
    6365                 :          15 :         error_at (DECL_SOURCE_LOCATION (decl),
    6366                 :             :                   "%qD declared as reference but not initialized", decl);
    6367                 :          15 :       return NULL_TREE;
    6368                 :             :     }
    6369                 :             : 
    6370                 :      285934 :   tree ttype = TREE_TYPE (type);
    6371                 :      285934 :   if (TREE_CODE (init) == TREE_LIST)
    6372                 :             :     {
    6373                 :             :       /* This handles (C++20 only) code like
    6374                 :             : 
    6375                 :             :            const A& r(1, 2, 3);
    6376                 :             : 
    6377                 :             :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    6378                 :        1202 :       if (TREE_TYPE (init) == NULL_TREE
    6379                 :        1202 :           && CP_AGGREGATE_TYPE_P (ttype)
    6380                 :          54 :           && !DECL_DECOMPOSITION_P (decl)
    6381                 :        1253 :           && (cxx_dialect >= cxx20))
    6382                 :             :         {
    6383                 :             :           /* We don't know yet if we should treat const A& r(1) as
    6384                 :             :              const A& r{1}.  */
    6385                 :          33 :           if (list_length (init) == 1)
    6386                 :             :             {
    6387                 :          12 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    6388                 :          12 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    6389                 :             :                                                       tf_warning_or_error);
    6390                 :             :             }
    6391                 :             :           /* If the list had more than one element, the code is ill-formed
    6392                 :             :              pre-C++20, so we can build a constructor right away.  */
    6393                 :             :           else
    6394                 :          21 :             init = do_aggregate_paren_init (init, ttype);
    6395                 :             :         }
    6396                 :             :       else
    6397                 :        1169 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    6398                 :             :                                                 tf_warning_or_error);
    6399                 :             :     }
    6400                 :             : 
    6401                 :      285934 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    6402                 :      285934 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    6403                 :             :     /* Note: default conversion is only called in very special cases.  */
    6404                 :          12 :     init = decay_conversion (init, tf_warning_or_error);
    6405                 :             : 
    6406                 :             :   /* check_initializer handles this for non-reference variables, but for
    6407                 :             :      references we need to do it here or the initializer will get the
    6408                 :             :      incomplete array type and confuse later calls to
    6409                 :             :      cp_complete_array_type.  */
    6410                 :      285934 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    6411                 :        9401 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    6412                 :      286017 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    6413                 :          50 :           || TREE_CODE (init) == STRING_CST))
    6414                 :             :     {
    6415                 :          33 :       cp_complete_array_type (&ttype, init, false);
    6416                 :          33 :       if (ttype != TREE_TYPE (type))
    6417                 :          33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    6418                 :             :     }
    6419                 :             : 
    6420                 :             :   /* Convert INIT to the reference type TYPE.  This may involve the
    6421                 :             :      creation of a temporary, whose lifetime must be the same as that
    6422                 :             :      of the reference.  If so, a DECL_EXPR for the temporary will be
    6423                 :             :      added just after the DECL_EXPR for DECL.  That's why we don't set
    6424                 :             :      DECL_INITIAL for local references (instead assigning to them
    6425                 :             :      explicitly); we need to allow the temporary to be initialized
    6426                 :             :      first.  */
    6427                 :      285934 :   return initialize_reference (type, init, flags,
    6428                 :      285934 :                                tf_warning_or_error);
    6429                 :             : }
    6430                 :             : 
    6431                 :             : /* Designated initializers in arrays are not supported in GNU C++.
    6432                 :             :    The parser cannot detect this error since it does not know whether
    6433                 :             :    a given brace-enclosed initializer is for a class type or for an
    6434                 :             :    array.  This function checks that CE does not use a designated
    6435                 :             :    initializer.  If it does, an error is issued.  Returns true if CE
    6436                 :             :    is valid, i.e., does not have a designated initializer.  */
    6437                 :             : 
    6438                 :             : bool
    6439                 :    32580098 : check_array_designated_initializer (constructor_elt *ce,
    6440                 :             :                                     unsigned HOST_WIDE_INT index)
    6441                 :             : {
    6442                 :             :   /* Designated initializers for array elements are not supported.  */
    6443                 :    32580098 :   if (ce->index)
    6444                 :             :     {
    6445                 :             :       /* The parser only allows identifiers as designated
    6446                 :             :          initializers.  */
    6447                 :    20785094 :       if (ce->index == error_mark_node)
    6448                 :             :         {
    6449                 :           0 :           error ("name used in a GNU-style designated "
    6450                 :             :                  "initializer for an array");
    6451                 :           0 :           return false;
    6452                 :             :         }
    6453                 :    20785094 :       else if (identifier_p (ce->index))
    6454                 :             :         {
    6455                 :          17 :           error ("name %qD used in a GNU-style designated "
    6456                 :             :                  "initializer for an array", ce->index);
    6457                 :          17 :           return false;
    6458                 :             :         }
    6459                 :             : 
    6460                 :    20785077 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    6461                 :             :                                                   ce->index, true);
    6462                 :    20785077 :       if (ce_index
    6463                 :    20785074 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    6464                 :    41570148 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    6465                 :             :               == INTEGER_CST))
    6466                 :             :         {
    6467                 :             :           /* A C99 designator is OK if it matches the current index.  */
    6468                 :    20785071 :           if (wi::to_wide (ce_index) == index)
    6469                 :             :             {
    6470                 :    20785065 :               ce->index = ce_index;
    6471                 :    20785065 :               return true;
    6472                 :             :             }
    6473                 :             :           else
    6474                 :           6 :             sorry ("non-trivial designated initializers not supported");
    6475                 :             :         }
    6476                 :             :       else
    6477                 :           6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    6478                 :             :                   "C99 designator %qE is not an integral constant-expression",
    6479                 :             :                   ce->index);
    6480                 :             : 
    6481                 :          12 :       return false;
    6482                 :             :     }
    6483                 :             : 
    6484                 :             :   return true;
    6485                 :             : }
    6486                 :             : 
    6487                 :             : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    6488                 :             :    array until we finish parsing the initializer.  If that's the
    6489                 :             :    situation we're in, update DECL accordingly.  */
    6490                 :             : 
    6491                 :             : static void
    6492                 :    51464651 : maybe_deduce_size_from_array_init (tree decl, tree init)
    6493                 :             : {
    6494                 :    51464651 :   tree type = TREE_TYPE (decl);
    6495                 :             : 
    6496                 :    51464651 :   if (TREE_CODE (type) == ARRAY_TYPE
    6497                 :      743905 :       && TYPE_DOMAIN (type) == NULL_TREE
    6498                 :    51940939 :       && TREE_CODE (decl) != TYPE_DECL)
    6499                 :             :     {
    6500                 :             :       /* do_default is really a C-ism to deal with tentative definitions.
    6501                 :             :          But let's leave it here to ease the eventual merge.  */
    6502                 :      476288 :       int do_default = !DECL_EXTERNAL (decl);
    6503                 :      476288 :       tree initializer = init ? init : DECL_INITIAL (decl);
    6504                 :      476288 :       int failure = 0;
    6505                 :             : 
    6506                 :             :       /* Check that there are no designated initializers in INIT, as
    6507                 :             :          those are not supported in GNU C++, and as the middle-end
    6508                 :             :          will crash if presented with a non-numeric designated
    6509                 :             :          initializer.  */
    6510                 :      476288 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    6511                 :             :         {
    6512                 :       87844 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    6513                 :       87844 :           constructor_elt *ce;
    6514                 :       87844 :           HOST_WIDE_INT i, j = 0;
    6515                 :    10169758 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    6516                 :             :             {
    6517                 :    10084351 :               if (instantiation_dependent_expression_p (ce->index))
    6518                 :    51464651 :                 return;
    6519                 :    10084345 :               if (!check_array_designated_initializer (ce, j))
    6520                 :           2 :                 failure = 1;
    6521                 :             :               /* If an un-designated initializer is type-dependent, we can't
    6522                 :             :                  check brace elision yet.  */
    6523                 :    10084345 :               if (ce->index == NULL_TREE
    6524                 :    10084345 :                   && type_dependent_expression_p (ce->value))
    6525                 :             :                 return;
    6526                 :    10081914 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    6527                 :         169 :                 j += RAW_DATA_LENGTH (ce->value);
    6528                 :             :               else
    6529                 :    10081745 :                 ++j;
    6530                 :             :             }
    6531                 :             :         }
    6532                 :             : 
    6533                 :       85407 :       if (failure)
    6534                 :           2 :         TREE_TYPE (decl) = error_mark_node;
    6535                 :             :       else
    6536                 :             :         {
    6537                 :      473849 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    6538                 :             :                                             do_default);
    6539                 :      473849 :           if (failure == 1)
    6540                 :             :             {
    6541                 :          33 :               error_at (cp_expr_loc_or_loc (initializer,
    6542                 :          30 :                                          DECL_SOURCE_LOCATION (decl)),
    6543                 :             :                         "initializer fails to determine size of %qD", decl);
    6544                 :             :             }
    6545                 :      473819 :           else if (failure == 2)
    6546                 :             :             {
    6547                 :          30 :               if (do_default)
    6548                 :             :                 {
    6549                 :           6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    6550                 :             :                             "array size missing in %qD", decl);
    6551                 :             :                 }
    6552                 :             :               /* If a `static' var's size isn't known, make it extern as
    6553                 :             :                  well as static, so it does not get allocated.  If it's not
    6554                 :             :                  `static', then don't mark it extern; finish_incomplete_decl
    6555                 :             :                  will give it a default size and it will get allocated.  */
    6556                 :          24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    6557                 :           0 :                 DECL_EXTERNAL (decl) = 1;
    6558                 :             :             }
    6559                 :      473789 :           else if (failure == 3)
    6560                 :             :             {
    6561                 :           6 :               error_at (DECL_SOURCE_LOCATION (decl),
    6562                 :             :                         "zero-size array %qD", decl);
    6563                 :             :             }
    6564                 :             :         }
    6565                 :             : 
    6566                 :      473851 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    6567                 :             : 
    6568                 :      473851 :       relayout_decl (decl);
    6569                 :             :     }
    6570                 :             : }
    6571                 :             : 
    6572                 :             : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    6573                 :             :    any appropriate error messages regarding the layout.  */
    6574                 :             : 
    6575                 :             : static void
    6576                 :    43370024 : layout_var_decl (tree decl)
    6577                 :             : {
    6578                 :    43370024 :   tree type;
    6579                 :             : 
    6580                 :    43370024 :   type = TREE_TYPE (decl);
    6581                 :    43370024 :   if (type == error_mark_node)
    6582                 :             :     return;
    6583                 :             : 
    6584                 :             :   /* If we haven't already laid out this declaration, do so now.
    6585                 :             :      Note that we must not call complete type for an external object
    6586                 :             :      because it's type might involve templates that we are not
    6587                 :             :      supposed to instantiate yet.  (And it's perfectly valid to say
    6588                 :             :      `extern X x' for some incomplete type `X'.)  */
    6589                 :    43369976 :   if (!DECL_EXTERNAL (decl))
    6590                 :    35130413 :     complete_type (type);
    6591                 :    43369976 :   if (!DECL_SIZE (decl)
    6592                 :     2003416 :       && TREE_TYPE (decl) != error_mark_node
    6593                 :    45373392 :       && complete_or_array_type_p (type))
    6594                 :     1966289 :     layout_decl (decl, 0);
    6595                 :             : 
    6596                 :    43369976 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    6597                 :             :     {
    6598                 :             :       /* An automatic variable with an incomplete type: that is an error.
    6599                 :             :          Don't talk about array types here, since we took care of that
    6600                 :             :          message in grokdeclarator.  */
    6601                 :          17 :       error_at (DECL_SOURCE_LOCATION (decl),
    6602                 :             :                 "storage size of %qD isn%'t known", decl);
    6603                 :          17 :       TREE_TYPE (decl) = error_mark_node;
    6604                 :             :     }
    6605                 :             : #if 0
    6606                 :             :   /* Keep this code around in case we later want to control debug info
    6607                 :             :      based on whether a type is "used".  (jason 1999-11-11) */
    6608                 :             : 
    6609                 :             :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    6610                 :             :     /* Let debugger know it should output info for this type.  */
    6611                 :             :     note_debug_info_needed (ttype);
    6612                 :             : 
    6613                 :             :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    6614                 :             :     note_debug_info_needed (DECL_CONTEXT (decl));
    6615                 :             : #endif
    6616                 :             : 
    6617                 :    78500389 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    6618                 :    21669147 :       && DECL_SIZE (decl) != NULL_TREE
    6619                 :    64873437 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    6620                 :             :     {
    6621                 :           6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6622                 :           6 :           && !DECL_LOCAL_DECL_P (decl))
    6623                 :           0 :         constant_expression_warning (DECL_SIZE (decl));
    6624                 :             :       else
    6625                 :             :         {
    6626                 :           6 :           error_at (DECL_SOURCE_LOCATION (decl),
    6627                 :             :                     "storage size of %qD isn%'t constant", decl);
    6628                 :           6 :           TREE_TYPE (decl) = error_mark_node;
    6629                 :           6 :           type = error_mark_node;
    6630                 :             :         }
    6631                 :             :     }
    6632                 :             : 
    6633                 :             :   /* If the final element initializes a flexible array field, adjust
    6634                 :             :      the size of the DECL with the initializer based on whether the
    6635                 :             :      DECL is a union or a structure.  */
    6636                 :    43369976 :   if (type != error_mark_node
    6637                 :    43369970 :       && DECL_INITIAL (decl)
    6638                 :    21596166 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    6639                 :     3488498 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    6640                 :     2919900 :       && DECL_SIZE (decl) != NULL_TREE
    6641                 :     2919900 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6642                 :     2919900 :       && COMPLETE_TYPE_P (type)
    6643                 :     2919900 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    6644                 :    46289876 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    6645                 :             :     {
    6646                 :     2919900 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    6647                 :     2919900 :       if (elt.index)
    6648                 :             :         {
    6649                 :     2718942 :           tree itype = TREE_TYPE (elt.index);
    6650                 :     2718942 :           tree vtype = TREE_TYPE (elt.value);
    6651                 :     2718942 :           if (TREE_CODE (itype) == ARRAY_TYPE
    6652                 :       46772 :               && TYPE_DOMAIN (itype) == NULL
    6653                 :         272 :               && TREE_CODE (vtype) == ARRAY_TYPE
    6654                 :     2719214 :               && COMPLETE_TYPE_P (vtype))
    6655                 :             :             {
    6656                 :             :               /* For a structure, add the size of the initializer to the DECL's
    6657                 :             :                  size.  */
    6658                 :         272 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    6659                 :             :                 {
    6660                 :         257 :                   DECL_SIZE (decl)
    6661                 :         257 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    6662                 :             :                                   TYPE_SIZE (vtype));
    6663                 :         257 :                   DECL_SIZE_UNIT (decl)
    6664                 :         514 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    6665                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6666                 :             :                 }
    6667                 :             :               /* For a union, the DECL's size is the maximum of the current size
    6668                 :             :                  and the size of the initializer.  */
    6669                 :             :               else
    6670                 :             :                 {
    6671                 :          15 :                   DECL_SIZE (decl)
    6672                 :          15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    6673                 :             :                                   TYPE_SIZE (vtype));
    6674                 :          15 :                   DECL_SIZE_UNIT (decl)
    6675                 :          30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    6676                 :             :                                   TYPE_SIZE_UNIT (vtype));
    6677                 :             :                 }
    6678                 :             :             }
    6679                 :             :         }
    6680                 :             :     }
    6681                 :             : }
    6682                 :             : 
    6683                 :             : /* If a local static variable is declared in an inline function, or if
    6684                 :             :    we have a weak definition, we must endeavor to create only one
    6685                 :             :    instance of the variable at link-time.  */
    6686                 :             : 
    6687                 :             : void
    6688                 :    47847145 : maybe_commonize_var (tree decl)
    6689                 :             : {
    6690                 :             :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    6691                 :             :      bindings.  */
    6692                 :    47847145 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    6693                 :             :     return;
    6694                 :             : 
    6695                 :             :   /* Static data in a function with comdat linkage also has comdat
    6696                 :             :      linkage.  */
    6697                 :    43163605 :   if ((TREE_STATIC (decl)
    6698                 :    21079740 :        && DECL_FUNCTION_SCOPE_P (decl)
    6699                 :      128585 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    6700                 :    85521134 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    6701                 :             :     {
    6702                 :    16952575 :       if (flag_weak)
    6703                 :             :         {
    6704                 :             :           /* With weak symbols, we simply make the variable COMDAT;
    6705                 :             :              that will cause copies in multiple translations units to
    6706                 :             :              be merged.  */
    6707                 :    16952548 :           comdat_linkage (decl);
    6708                 :             :         }
    6709                 :             :       else
    6710                 :             :         {
    6711                 :          27 :           if (DECL_INITIAL (decl) == NULL_TREE
    6712                 :          27 :               || DECL_INITIAL (decl) == error_mark_node)
    6713                 :             :             {
    6714                 :             :               /* Without weak symbols, we can use COMMON to merge
    6715                 :             :                  uninitialized variables.  */
    6716                 :          24 :               TREE_PUBLIC (decl) = 1;
    6717                 :          24 :               DECL_COMMON (decl) = 1;
    6718                 :             :             }
    6719                 :             :           else
    6720                 :             :             {
    6721                 :             :               /* While for initialized variables, we must use internal
    6722                 :             :                  linkage -- which means that multiple copies will not
    6723                 :             :                  be merged.  */
    6724                 :           3 :               TREE_PUBLIC (decl) = 0;
    6725                 :           3 :               DECL_COMMON (decl) = 0;
    6726                 :           3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    6727                 :           3 :               const char *msg;
    6728                 :           3 :               if (DECL_INLINE_VAR_P (decl))
    6729                 :             :                 msg = G_("sorry: semantics of inline variable "
    6730                 :             :                          "%q#D are wrong (you%'ll wind up with "
    6731                 :             :                          "multiple copies)");
    6732                 :             :               else
    6733                 :             :                 msg = G_("sorry: semantics of inline function "
    6734                 :             :                          "static data %q#D are wrong (you%'ll wind "
    6735                 :             :                          "up with multiple copies)");
    6736                 :           3 :               auto_diagnostic_group d;
    6737                 :           3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6738                 :             :                               msg, decl))
    6739                 :           3 :                 inform (DECL_SOURCE_LOCATION (decl),
    6740                 :             :                         "you can work around this by removing the initializer");
    6741                 :           3 :             }
    6742                 :             :         }
    6743                 :             :     }
    6744                 :             : }
    6745                 :             : 
    6746                 :             : /* Issue an error message if DECL is an uninitialized const variable.
    6747                 :             :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    6748                 :             :    context from potential_constant_expression.  Returns true if all is well,
    6749                 :             :    false otherwise.  */
    6750                 :             : 
    6751                 :             : bool
    6752                 :     5957983 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    6753                 :             :                                    tsubst_flags_t complain)
    6754                 :             : {
    6755                 :     5957983 :   tree type = strip_array_types (TREE_TYPE (decl));
    6756                 :             : 
    6757                 :             :   /* ``Unless explicitly declared extern, a const object does not have
    6758                 :             :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    6759                 :             :      7.1.6 */
    6760                 :     5957983 :   if (VAR_P (decl)
    6761                 :     5957983 :       && !TYPE_REF_P (type)
    6762                 :     5937064 :       && (CP_TYPE_CONST_P (type)
    6763                 :             :           /* C++20 permits trivial default initialization in constexpr
    6764                 :             :              context (P1331R2).  */
    6765                 :     4930555 :           || (cxx_dialect < cxx20
    6766                 :     2786756 :               && (constexpr_context_p
    6767                 :     2490114 :                   || var_in_constexpr_fn (decl))))
    6768                 :     7372186 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    6769                 :             :     {
    6770                 :      624337 :       tree field = default_init_uninitialized_part (type);
    6771                 :      624337 :       if (!field)
    6772                 :             :         return true;
    6773                 :             : 
    6774                 :      112917 :       auto_diagnostic_group d;
    6775                 :      112917 :       bool show_notes = true;
    6776                 :             : 
    6777                 :      112917 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    6778                 :             :         {
    6779                 :      109181 :           if (CP_TYPE_CONST_P (type))
    6780                 :             :             {
    6781                 :          90 :               if (complain & tf_error)
    6782                 :          84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    6783                 :             :                                         "uninitialized %<const %D%>", decl);
    6784                 :             :             }
    6785                 :             :           else
    6786                 :             :             {
    6787                 :      109091 :               if (!is_instantiation_of_constexpr (current_function_decl)
    6788                 :      109091 :                   && (complain & tf_error))
    6789                 :          21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    6790                 :             :                           "uninitialized variable %qD in %<constexpr%> "
    6791                 :             :                           "function", decl);
    6792                 :             :               else
    6793                 :             :                 show_notes = false;
    6794                 :      109091 :               cp_function_chain->invalid_constexpr = true;
    6795                 :             :             }
    6796                 :             :         }
    6797                 :        3736 :       else if (complain & tf_error)
    6798                 :           2 :         error_at (DECL_SOURCE_LOCATION (decl),
    6799                 :             :                   "uninitialized variable %qD in %<constexpr%> context",
    6800                 :             :                   decl);
    6801                 :             : 
    6802                 :      112917 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    6803                 :             :         {
    6804                 :          62 :           tree defaulted_ctor;
    6805                 :             : 
    6806                 :          62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    6807                 :             :                   "%q#T has no user-provided default constructor", type);
    6808                 :          62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    6809                 :          62 :           if (defaulted_ctor)
    6810                 :          33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    6811                 :             :                     "constructor is not user-provided because it is "
    6812                 :             :                     "explicitly defaulted in the class body");
    6813                 :          62 :           inform (DECL_SOURCE_LOCATION (field),
    6814                 :             :                   "and the implicitly-defined constructor does not "
    6815                 :             :                   "initialize %q#D", field);
    6816                 :             :         }
    6817                 :             : 
    6818                 :      112917 :       return false;
    6819                 :      112917 :     }
    6820                 :             : 
    6821                 :             :   return true;
    6822                 :             : }
    6823                 :             : 
    6824                 :             : /* Structure holding the current initializer being processed by reshape_init.
    6825                 :             :    CUR is a pointer to the current element being processed, END is a pointer
    6826                 :             :    after the last element present in the initializer and RAW_IDX is index into
    6827                 :             :    RAW_DATA_CST if that is CUR elt.  */
    6828                 :             : struct reshape_iter
    6829                 :             : {
    6830                 :             :   constructor_elt *cur;
    6831                 :             :   constructor_elt *end;
    6832                 :             :   unsigned raw_idx;
    6833                 :             : };
    6834                 :             : 
    6835                 :             : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    6836                 :             : 
    6837                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6838                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    6839                 :             :    initialized as if for an aggregate class.  If there are no more such fields,
    6840                 :             :    the return value will be NULL.  */
    6841                 :             : 
    6842                 :             : tree
    6843                 :    12687644 : next_aggregate_field (tree field)
    6844                 :             : {
    6845                 :    12687644 :   while (field
    6846                 :    43345051 :          && (TREE_CODE (field) != FIELD_DECL
    6847                 :     8140781 :              || DECL_UNNAMED_BIT_FIELD (field)
    6848                 :     8140653 :              || (DECL_ARTIFICIAL (field)
    6849                 :             :                  /* In C++17, aggregates can have bases.  */
    6850                 :       63838 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    6851                 :    30657407 :     field = DECL_CHAIN (field);
    6852                 :             : 
    6853                 :    12687644 :   return field;
    6854                 :             : }
    6855                 :             : 
    6856                 :             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6857                 :             :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    6858                 :             :    to a subobject.  If there are no more such fields, the return value will be
    6859                 :             :    NULL.  */
    6860                 :             : 
    6861                 :             : tree
    6862                 :    49892142 : next_subobject_field (tree field)
    6863                 :             : {
    6864                 :    49892142 :   while (field
    6865                 :   588055718 :          && (TREE_CODE (field) != FIELD_DECL
    6866                 :    23035317 :              || DECL_UNNAMED_BIT_FIELD (field)
    6867                 :    23035237 :              || (DECL_ARTIFICIAL (field)
    6868                 :     6492049 :                  && !DECL_FIELD_IS_BASE (field)
    6869                 :     1634521 :                  && !DECL_VIRTUAL_P (field))))
    6870                 :   538163576 :     field = DECL_CHAIN (field);
    6871                 :             : 
    6872                 :    49892142 :   return field;
    6873                 :             : }
    6874                 :             : 
    6875                 :             : /* Return true for [dcl.init.list] direct-list-initialization from
    6876                 :             :    single element of enumeration with a fixed underlying type.  */
    6877                 :             : 
    6878                 :             : bool
    6879                 :   110915482 : is_direct_enum_init (tree type, tree init)
    6880                 :             : {
    6881                 :   110915482 :   if (cxx_dialect >= cxx17
    6882                 :   108953545 :       && TREE_CODE (type) == ENUMERAL_TYPE
    6883                 :     5647238 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    6884                 :     3240379 :       && TREE_CODE (init) == CONSTRUCTOR
    6885                 :      383599 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    6886                 :      189649 :       && CONSTRUCTOR_NELTS (init) == 1
    6887                 :         218 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    6888                 :             :       /* DR 2374: The single element needs to be implicitly
    6889                 :             :          convertible to the underlying type of the enum.  */
    6890                 :         218 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    6891                 :   110915698 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    6892                 :         216 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    6893                 :         216 :                           CONSTRUCTOR_ELT (init, 0)->value,
    6894                 :             :                           LOOKUP_IMPLICIT, tf_none))
    6895                 :             :     return true;
    6896                 :             :   return false;
    6897                 :             : }
    6898                 :             : 
    6899                 :             : /* Helper function for reshape_init*.  Split first element of
    6900                 :             :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    6901                 :             :    to true if the whole d->cur has been consumed.  */
    6902                 :             : 
    6903                 :             : static tree
    6904                 :    16867663 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    6905                 :             : {
    6906                 :    16867663 :   *inc_cur = true;
    6907                 :    16867663 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    6908                 :             :     return NULL_TREE;
    6909                 :       28431 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    6910                 :       28431 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    6911                 :       28305 :     *inc_cur = false;
    6912                 :             :   else
    6913                 :         126 :     d->raw_idx = 0;
    6914                 :             :   return ret;
    6915                 :             : }
    6916                 :             : 
    6917                 :             : /* Wrapper around that which for RAW_DATA_CST in INIT
    6918                 :             :    (as well as in D->cur->value) peels off the first element
    6919                 :             :    of the raw data and returns it, otherwise increments
    6920                 :             :    D->cur and returns INIT.  */
    6921                 :             : 
    6922                 :             : static tree
    6923                 :    16867647 : consume_init (tree init, reshape_iter *d)
    6924                 :             : {
    6925                 :    16867647 :   bool inc_cur;
    6926                 :    16867647 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    6927                 :       28431 :     init = raw_init;
    6928                 :    16867647 :   if (inc_cur)
    6929                 :    16839342 :     d->cur++;
    6930                 :    16867647 :   return init;
    6931                 :             : }
    6932                 :             : 
    6933                 :             : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    6934                 :             :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    6935                 :             :    INTEGER_CST representing the size of the array minus one (the maximum index),
    6936                 :             :    or NULL_TREE if the array was declared without specifying the size. D is
    6937                 :             :    the iterator within the constructor.  */
    6938                 :             : 
    6939                 :             : static tree
    6940                 :      354838 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    6941                 :             :                       tree first_initializer_p, bool vector_p,
    6942                 :             :                       tsubst_flags_t complain)
    6943                 :             : {
    6944                 :      354838 :   tree new_init;
    6945                 :      354838 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    6946                 :      354838 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    6947                 :      354838 :   unsigned HOST_WIDE_INT index;
    6948                 :             : 
    6949                 :             :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    6950                 :             :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    6951                 :             :      to build a new one.  But don't reuse if not complaining; if this is
    6952                 :             :      tentative, we might also reshape to another type (95319).  */
    6953                 :      354838 :   bool reuse = (first_initializer_p
    6954                 :      310056 :                 && (complain & tf_error)
    6955                 :      308837 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    6956                 :      616956 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    6957                 :       97466 :   if (reuse)
    6958                 :             :     new_init = first_initializer_p;
    6959                 :             :   else
    6960                 :       97466 :     new_init = build_constructor (init_list_type_node, NULL);
    6961                 :             : 
    6962                 :      354838 :   if (sized_array_p)
    6963                 :             :     {
    6964                 :      253522 :       poly_uint64 midx;
    6965                 :             :       /* Minus 1 is used for zero sized arrays.  */
    6966                 :      253522 :       if (integer_all_onesp (max_index))
    6967                 :          24 :         return new_init;
    6968                 :             : 
    6969                 :      253498 :       if (tree_fits_poly_uint64_p (max_index))
    6970                 :      253498 :         midx = tree_to_poly_uint64 (max_index);
    6971                 :             :       /* sizetype is sign extended, not zero extended.  */
    6972                 :             :       else
    6973                 :           0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    6974                 :             : 
    6975                 :             :       /* For VLA vectors, we restict the number of elements in the constructor
    6976                 :             :          to lower bound of the VLA elements.  */
    6977                 :      253498 :       max_index_cst = constant_lower_bound (midx);
    6978                 :             :     }
    6979                 :             : 
    6980                 :      354814 :   constructor_elt *first_cur = d->cur;
    6981                 :             :   /* Loop until there are no more initializers.  */
    6982                 :    12292469 :   for (index = 0;
    6983                 :    12292469 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    6984                 :             :        ++index)
    6985                 :             :     {
    6986                 :    11937837 :       tree elt_init;
    6987                 :    11937837 :       constructor_elt *old_cur = d->cur;
    6988                 :    11937837 :       unsigned int old_raw_idx = d->raw_idx;
    6989                 :    11937837 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    6990                 :             : 
    6991                 :    11937837 :       if (d->cur->index)
    6992                 :     1345732 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    6993                 :    11937837 :       check_array_designated_initializer (d->cur, index);
    6994                 :    11937837 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    6995                 :       30356 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    6996                 :       10233 :               || is_byte_access_type (elt_type))
    6997                 :       20123 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    6998                 :        1751 :           && (!sized_array_p || index < max_index_cst)
    6999                 :    11939576 :           && !vector_p)
    7000                 :             :         {
    7001                 :         419 :           elt_init = d->cur->value;
    7002                 :         419 :           unsigned int off = d->raw_idx;
    7003                 :         419 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7004                 :         419 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7005                 :             :             {
    7006                 :         410 :               d->cur++;
    7007                 :         410 :               d->raw_idx = 0;
    7008                 :             :             }
    7009                 :             :           else
    7010                 :             :             {
    7011                 :           9 :               len = max_index_cst - index + 1;
    7012                 :           9 :               d->raw_idx += len;
    7013                 :             :             }
    7014                 :         419 :           if (!reuse || off || d->cur == old_cur)
    7015                 :             :             {
    7016                 :          25 :               elt_init = copy_node (elt_init);
    7017                 :          25 :               RAW_DATA_LENGTH (elt_init) = len;
    7018                 :          25 :               RAW_DATA_POINTER (elt_init) += off;
    7019                 :             :             }
    7020                 :         419 :           TREE_TYPE (elt_init) = elt_type;
    7021                 :             :         }
    7022                 :             :       else
    7023                 :    11937418 :         elt_init = reshape_init_r (elt_type, d,
    7024                 :             :                                    /*first_initializer_p=*/NULL_TREE,
    7025                 :             :                                    complain);
    7026                 :    11937837 :       if (elt_init == error_mark_node)
    7027                 :             :         return error_mark_node;
    7028                 :    11937658 :       tree idx = size_int (index);
    7029                 :    11937658 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7030                 :             :         {
    7031                 :             :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7032                 :             :              ctor had to be split.  */
    7033                 :          66 :           new_init = build_constructor (init_list_type_node, NULL);
    7034                 :          66 :           if (index)
    7035                 :             :             {
    7036                 :          66 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7037                 :          66 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7038                 :          66 :                       (d->cur - first_cur)
    7039                 :             :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7040                 :          66 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7041                 :             :                 {
    7042                 :             :                   unsigned int j;
    7043                 :             :                   tree nidx, nval;
    7044                 :           4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7045                 :             :                                             j, nidx, nval)
    7046                 :           4 :                     if (nidx)
    7047                 :             :                       {
    7048                 :           4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7049                 :           4 :                         (void) nval;
    7050                 :           4 :                         break;
    7051                 :             :                       }
    7052                 :             :                 }
    7053                 :             :             }
    7054                 :             :           reuse = false;
    7055                 :             :         }
    7056                 :    11937592 :       if (reuse)
    7057                 :             :         {
    7058                 :    10395296 :           old_cur->index = idx;
    7059                 :    10395296 :           old_cur->value = elt_init;
    7060                 :             :         }
    7061                 :             :       else
    7062                 :     1542362 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7063                 :             :                                 idx, elt_init);
    7064                 :    11937658 :       if (!TREE_CONSTANT (elt_init))
    7065                 :      132052 :         TREE_CONSTANT (new_init) = false;
    7066                 :             : 
    7067                 :             :       /* This can happen with an invalid initializer (c++/54501).  */
    7068                 :    11937658 :       if (d->cur == old_cur
    7069                 :       29799 :           && !sized_array_p
    7070                 :       11802 :           && d->raw_idx == old_raw_idx)
    7071                 :             :         break;
    7072                 :             : 
    7073                 :    11937655 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7074                 :         419 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7075                 :             :     }
    7076                 :             : 
    7077                 :             :   return new_init;
    7078                 :             : }
    7079                 :             : 
    7080                 :             : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7081                 :             :    Parameters are the same of reshape_init_r.  */
    7082                 :             : 
    7083                 :             : static tree
    7084                 :      314025 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7085                 :             :                     tsubst_flags_t complain)
    7086                 :             : {
    7087                 :      314025 :   tree max_index = NULL_TREE;
    7088                 :             : 
    7089                 :      314025 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7090                 :             : 
    7091                 :      314025 :   if (TYPE_DOMAIN (type))
    7092                 :      212754 :     max_index = array_type_nelts_minus_one (type);
    7093                 :             : 
    7094                 :      314025 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7095                 :      314025 :                                first_initializer_p, false, complain);
    7096                 :             : }
    7097                 :             : 
    7098                 :             : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7099                 :             :    Parameters are the same of reshape_init_r.  */
    7100                 :             : 
    7101                 :             : static tree
    7102                 :       40813 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7103                 :             : {
    7104                 :       40813 :   tree max_index = NULL_TREE;
    7105                 :             : 
    7106                 :       40813 :   gcc_assert (VECTOR_TYPE_P (type));
    7107                 :             : 
    7108                 :       40813 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7109                 :             :     {
    7110                 :           0 :       tree value = d->cur->value;
    7111                 :           0 :       if (!same_type_p (TREE_TYPE (value), type))
    7112                 :             :         {
    7113                 :           0 :           if (complain & tf_error)
    7114                 :           0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7115                 :           0 :                    TREE_TYPE (d->cur->value), type);
    7116                 :           0 :           value = error_mark_node;
    7117                 :             :         }
    7118                 :           0 :       ++d->cur;
    7119                 :           0 :       return value;
    7120                 :             :     }
    7121                 :             : 
    7122                 :             :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7123                 :       40813 :   if (VECTOR_TYPE_P (type))
    7124                 :       40813 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7125                 :             : 
    7126                 :       40813 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7127                 :       40813 :                                NULL_TREE, true, complain);
    7128                 :             : }
    7129                 :             : 
    7130                 :             : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7131                 :             :    INIT, in isolation from any designator or other initializers.  */
    7132                 :             : 
    7133                 :             : static tree
    7134                 :      497787 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7135                 :             : {
    7136                 :             :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7137                 :             :      calling reshape_init, but this way can just live on the stack.  */
    7138                 :      497787 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7139                 :      497787 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7140                 :      497787 :   return reshape_init_r (type, &iter,
    7141                 :             :                          /*first_initializer_p=*/NULL_TREE,
    7142                 :      497787 :                          complain);
    7143                 :             : }
    7144                 :             : 
    7145                 :             : /* Subroutine of reshape_init_r, processes the initializers for classes
    7146                 :             :    or union. Parameters are the same of reshape_init_r.  */
    7147                 :             : 
    7148                 :             : static tree
    7149                 :     3215727 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7150                 :             :                     tsubst_flags_t complain)
    7151                 :             : {
    7152                 :     3215727 :   tree field;
    7153                 :     3215727 :   tree new_init;
    7154                 :             : 
    7155                 :     3215727 :   gcc_assert (CLASS_TYPE_P (type));
    7156                 :             : 
    7157                 :             :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7158                 :     3215727 :   new_init = build_constructor (init_list_type_node, NULL);
    7159                 :             : 
    7160                 :     3215727 :   int binfo_idx = -1;
    7161                 :     3215727 :   tree binfo = TYPE_BINFO (type);
    7162                 :     3215727 :   tree base_binfo = NULL_TREE;
    7163                 :     3215727 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7164                 :             :     {
    7165                 :             :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7166                 :             :          deduction.  In this case we need to look through the binfo because a
    7167                 :             :          template doesn't have base fields.  */
    7168                 :         327 :       binfo_idx = 0;
    7169                 :         327 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7170                 :             :     }
    7171                 :          67 :   if (base_binfo)
    7172                 :             :     field = base_binfo;
    7173                 :             :   else
    7174                 :     3215660 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7175                 :             : 
    7176                 :     3215727 :   if (!field)
    7177                 :             :     {
    7178                 :             :       /* [dcl.init.aggr]
    7179                 :             : 
    7180                 :             :         An initializer for an aggregate member that is an
    7181                 :             :         empty class shall have the form of an empty
    7182                 :             :         initializer-list {}.  */
    7183                 :         324 :       if (!first_initializer_p)
    7184                 :             :         {
    7185                 :         270 :           if (complain & tf_error)
    7186                 :          13 :             error ("initializer for %qT must be brace-enclosed", type);
    7187                 :         270 :           return error_mark_node;
    7188                 :             :         }
    7189                 :             :       return new_init;
    7190                 :             :     }
    7191                 :             : 
    7192                 :             :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7193                 :             :   tree last_was_pack_expansion = NULL_TREE;
    7194                 :             : 
    7195                 :             :   /* Loop through the initializable fields, gathering initializers.  */
    7196                 :     9817779 :   while (d->cur != d->end)
    7197                 :             :     {
    7198                 :     6710275 :       tree field_init;
    7199                 :     6710275 :       constructor_elt *old_cur = d->cur;
    7200                 :     6710275 :       unsigned old_raw_idx = d->raw_idx;
    7201                 :     6710275 :       bool direct_desig = false;
    7202                 :             : 
    7203                 :             :       /* Handle C++20 designated initializers.  */
    7204                 :     6710275 :       if (d->cur->index)
    7205                 :             :         {
    7206                 :      497947 :           if (d->cur->index == error_mark_node)
    7207                 :             :             return error_mark_node;
    7208                 :             : 
    7209                 :      497941 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7210                 :             :             {
    7211                 :             :               /* We already reshaped this; we should have returned early from
    7212                 :             :                  reshape_init.  */
    7213                 :           0 :               gcc_checking_assert (false);
    7214                 :             :               if (field != d->cur->index)
    7215                 :             :                 {
    7216                 :             :                   if (tree id = DECL_NAME (d->cur->index))
    7217                 :             :                     gcc_checking_assert (d->cur->index
    7218                 :             :                                          == get_class_binding (type, id));
    7219                 :             :                   field = d->cur->index;
    7220                 :             :                 }
    7221                 :             :             }
    7222                 :      497941 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7223                 :             :             {
    7224                 :      497935 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7225                 :      497935 :               field = get_class_binding (type, d->cur->index);
    7226                 :      497935 :               direct_desig = true;
    7227                 :             :             }
    7228                 :             :           else
    7229                 :             :             {
    7230                 :           6 :               if (complain & tf_error)
    7231                 :           6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7232                 :             :                        " for class %qT", d->cur->index, type);
    7233                 :           6 :               return error_mark_node;
    7234                 :             :             }
    7235                 :             : 
    7236                 :      497935 :           if (!field && ANON_AGGR_TYPE_P (type))
    7237                 :             :             /* Apparently the designator isn't for a member of this anonymous
    7238                 :             :                struct, so head back to the enclosing class.  */
    7239                 :             :             break;
    7240                 :             : 
    7241                 :      497932 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    7242                 :             :             {
    7243                 :          18 :               if (complain & tf_error)
    7244                 :             :                 {
    7245                 :           6 :                   if (field && TREE_CODE (field) == TREE_LIST)
    7246                 :             :                     {
    7247                 :           3 :                       auto_diagnostic_group g;
    7248                 :           3 :                       error ("request for member %qD is ambiguous",