LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.8 % 9815 9304
Test Date: 2026-11-14 16:39:50 Functions: 98.0 % 244 239
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for the C++ compiler.
       2              :    Copyright (C) 1988-2026 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 "contracts.h"
      64              : #include "gcc-urlifier.h"
      65              : #include "diagnostic-highlight-colors.h"
      66              : #include "pretty-print-markup.h"
      67              : 
      68              : /* Possible cases of bad specifiers type used by bad_specifiers. */
      69              : enum bad_spec_place {
      70              :   BSP_VAR,    /* variable */
      71              :   BSP_PARM,   /* parameter */
      72              :   BSP_TYPE,   /* type */
      73              :   BSP_FIELD   /* field */
      74              : };
      75              : 
      76              : static const char *redeclaration_error_message (tree, tree);
      77              : 
      78              : static bool decl_jump_unsafe (tree);
      79              : static bool decl_instrument_init_bypass_p (tree);
      80              : static void require_complete_types_for_parms (tree);
      81              : static tree grok_reference_init (tree, tree, tree, int);
      82              : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      83              :                          int, int, int, bool, int, tree, location_t);
      84              : static void check_static_variable_definition (tree, tree);
      85              : static void record_unknown_type (tree, const char *);
      86              : static int member_function_or_else (tree, tree, enum overload_flags);
      87              : static tree local_variable_p_walkfn (tree *, int *, void *);
      88              : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      89              : static void maybe_deduce_size_from_array_init (tree, tree);
      90              : static void layout_var_decl (tree);
      91              : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      92              : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      93              : static void copy_type_enum (tree , tree);
      94              : static void check_function_type (tree, tree);
      95              : static void begin_destructor_body (void);
      96              : static void record_key_method_defined (tree);
      97              : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      98              : static tree get_atexit_node (void);
      99              : static tree get_dso_handle_node (void);
     100              : static tree start_cleanup_fn (tree, bool, bool);
     101              : static void end_cleanup_fn (void);
     102              : static tree cp_make_fname_decl (location_t, tree, int);
     103              : static void initialize_predefined_identifiers (void);
     104              : static tree check_special_function_return_type
     105              :        (special_function_kind, tree, tree, int, const cp_declarator**,
     106              :         const location_t*);
     107              : static tree push_cp_library_fn (enum tree_code, tree, int);
     108              : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     109              : static void store_parm_decls (tree);
     110              : static void initialize_local_var (tree, tree, bool);
     111              : static void expand_static_init (tree, tree);
     112              : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     113              : static bool identify_goto (tree, location_t, const location_t *,
     114              :                            enum diagnostics::kind, bool);
     115              : 
     116              : /* The following symbols are subsumed in the cp_global_trees array, and
     117              :    listed here individually for documentation purposes.
     118              : 
     119              :    C++ extensions
     120              :         tree wchar_decl_node;
     121              : 
     122              :         tree vtable_entry_type;
     123              :         tree delta_type_node;
     124              :         tree __t_desc_type_node;
     125              : 
     126              :         tree class_type_node;
     127              :         tree unknown_type_node;
     128              : 
     129              :    Array type `vtable_entry_type[]'
     130              : 
     131              :         tree vtbl_type_node;
     132              :         tree vtbl_ptr_type_node;
     133              : 
     134              :    Namespaces,
     135              : 
     136              :         tree std_node;
     137              :         tree std_meta_node;
     138              :         tree abi_node;
     139              : 
     140              :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     141              :    one that the user will declare, but sufficient to be called
     142              :    by routines that want to abort the program.
     143              : 
     144              :         tree abort_fndecl;
     145              : 
     146              :    Used by RTTI
     147              :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     148              :         tree tinfo_var_id;  */
     149              : 
     150              : tree cp_global_trees[CPTI_MAX];
     151              : 
     152              : /* A list of objects which have constructors or destructors
     153              :    which reside in namespace scope.  The decl is stored in
     154              :    the TREE_VALUE slot and the initializer is stored
     155              :    in the TREE_PURPOSE slot.  */
     156              : tree static_aggregates;
     157              : 
     158              : /* Like static_aggregates, but for thread_local variables.  */
     159              : tree tls_aggregates;
     160              : 
     161              : /* A hash-map mapping from variable decls to the dynamic initializer for
     162              :    the decl.  This is currently only used by OpenMP.  */
     163              : decl_tree_map *dynamic_initializers;
     164              : 
     165              : /* -- end of C++ */
     166              : 
     167              : /* A node for the integer constant 2.  */
     168              : 
     169              : tree integer_two_node;
     170              : 
     171              : /* vector of static decls.  */
     172              : vec<tree, va_gc> *static_decls;
     173              : 
     174              : /* vector of keyed classes.  */
     175              : vec<tree, va_gc> *keyed_classes;
     176              : 
     177              : /* Used in the direct_goto vector of named_label_use_entry for
     178              :    addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
     179              :    for forward jumps.  */
     180              : 
     181              : struct GTY(()) named_label_fwd_direct_goto {
     182              :   tree *GTY((skip)) direct_goto;
     183              : };
     184              : 
     185              : /* Used in the direct_goto vector of named_label_use_entry for
     186              :    addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
     187              :    for backward jumps.  */
     188              : 
     189              : struct GTY(()) named_label_bck_direct_goto {
     190              :   tree *GTY((skip)) direct_goto;
     191              :   /* Number of the decl_instrument_init_bypass_p decls in bad_decls vector
     192              :      at the time this backward goto has been seen.  */
     193              :   unsigned n_bad_decls;
     194              : };
     195              : 
     196              : /* Used only for jumps to as-yet undefined labels, since jumps to
     197              :    defined labels can have their validity checked immediately.  */
     198              : 
     199              : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     200              :   struct named_label_use_entry *next;
     201              :   /* The binding level to which this entry is *currently* attached.
     202              :      This is initially the binding level in which the goto appeared,
     203              :      but is modified as scopes are closed.  */
     204              :   cp_binding_level *binding_level;
     205              :   /* The head of the names list that was current when the goto appeared,
     206              :      or the inner scope popped.  These are the decls that will *not* be
     207              :      skipped when jumping to the label.  */
     208              :   tree names_in_scope;
     209              :   /* If the use is a possible destination of a computed goto, a vec of decls
     210              :      that aren't destroyed, filled in by poplevel_named_label_1.  */
     211              :   vec<tree, va_gc> *computed_goto;
     212              :   /* If the use is a destination of normal goto, a vec of addresses of
     213              :      LABEL_DECLs that might need changing for !!flag_auto_var_init
     214              :      forward jumps across vacuous initializers.  */
     215              :   vec<named_label_fwd_direct_goto, va_gc> *direct_goto;
     216              :   /* The location of the goto, for error reporting.  */
     217              :   location_t o_goto_locus;
     218              :   /* True if an OpenMP structured block scope has been closed since
     219              :      the goto appeared.  This means that the branch from the label will
     220              :      illegally exit an OpenMP scope.  */
     221              :   bool in_omp_scope;
     222              : };
     223              : 
     224              : /* A list of all LABEL_DECLs in the function that have names.  Here so
     225              :    we can clear out their names' definitions at the end of the
     226              :    function, and so we can check the validity of jumps to these labels.  */
     227              : 
     228              : struct GTY((for_user)) named_label_entry {
     229              : 
     230              :   tree name;  /* Name of decl. */
     231              : 
     232              :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     233              : 
     234              :   named_label_entry *outer; /* Outer shadowed chain.  */
     235              : 
     236              :   /* The binding level to which the label is *currently* attached.
     237              :      This is initially set to the binding level in which the label
     238              :      is defined, but is modified as scopes are closed.  */
     239              :   cp_binding_level *binding_level;
     240              : 
     241              :   /* The head of the names list that was current when the label was
     242              :      defined, or the inner scope popped.  These are the decls that will
     243              :      be skipped when jumping to the label.  */
     244              :   tree names_in_scope;
     245              : 
     246              :   /* A vector of all decls from all binding levels that would be
     247              :      crossed by a backward branch to the label.  */
     248              :   vec<tree, va_gc> *bad_decls;
     249              : 
     250              :   /* A list of uses of the label, before the label is defined.  */
     251              :   named_label_use_entry *uses;
     252              : 
     253              :   /* If the use is a destination of normal goto, a vec of addresses of
     254              :      LABEL_DECLs that might need changing for !!flag_auto_var_init
     255              :      backward jumps across vacuous initializers.  */
     256              :   vec<named_label_bck_direct_goto, va_gc> *direct_goto;
     257              : 
     258              :   /* True if we've seen &&label.  Apparently we can't use TREE_ADDRESSABLE for
     259              :      this, it has a more specific meaning for LABEL_DECL.  */
     260              :   bool addressed : 1;
     261              : 
     262              :   /* The following bits are set after the label is defined, and are
     263              :      updated as scopes are popped.  They indicate that a jump to the
     264              :      label will illegally enter a scope of the given flavor.  */
     265              :   bool in_try_scope : 1;
     266              :   bool in_catch_scope : 1;
     267              :   bool in_omp_scope : 1;
     268              :   bool in_transaction_scope : 1;
     269              :   bool in_constexpr_if : 1;
     270              :   bool in_consteval_if : 1;
     271              :   bool in_stmt_expr : 1;
     272              : 
     273              :   /* True if bad_decls chain contains any decl_jump_unsafe decls
     274              :      (rather than just decl_instrument_init_bypass_p).  */
     275              :   bool has_bad_decls : 1;
     276              : };
     277              : 
     278              : #define named_labels cp_function_chain->x_named_labels
     279              : 
     280              : /* The number of function bodies which we are currently processing.
     281              :    (Zero if we are at namespace scope, one inside the body of a
     282              :    function, two inside the body of a function in a local class, etc.)  */
     283              : int function_depth;
     284              : 
     285              : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     286              : bool flag_noexcept_type;
     287              : 
     288              : /* States indicating how grokdeclarator() should handle declspecs marked
     289              :    with __attribute__((deprecated)).  An object declared as
     290              :    __attribute__((deprecated)) suppresses warnings of uses of other
     291              :    deprecated items.  */
     292              : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     293              : 
     294              : 
     295              : /* A list of VAR_DECLs whose type was incomplete at the time the
     296              :    variable was declared.  */
     297              : 
     298              : struct GTY(()) incomplete_var {
     299              :   tree decl;
     300              :   tree incomplete_type;
     301              : };
     302              : 
     303              : 
     304              : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     305              : 
     306              : /* Returns the kind of template specialization we are currently
     307              :    processing, given that it's declaration contained N_CLASS_SCOPES
     308              :    explicit scope qualifications.  */
     309              : 
     310              : tmpl_spec_kind
     311    258032856 : current_tmpl_spec_kind (int n_class_scopes)
     312              : {
     313    258032856 :   int n_template_parm_scopes = 0;
     314    258032856 :   int seen_specialization_p = 0;
     315    258032856 :   int innermost_specialization_p = 0;
     316    258032856 :   cp_binding_level *b;
     317              : 
     318              :   /* Scan through the template parameter scopes.  */
     319    258032856 :   for (b = current_binding_level;
     320    321889181 :        b->kind == sk_template_parms;
     321     63856325 :        b = b->level_chain)
     322              :     {
     323              :       /* If we see a specialization scope inside a parameter scope,
     324              :          then something is wrong.  That corresponds to a declaration
     325              :          like:
     326              : 
     327              :             template <class T> template <> ...
     328              : 
     329              :          which is always invalid since [temp.expl.spec] forbids the
     330              :          specialization of a class member template if the enclosing
     331              :          class templates are not explicitly specialized as well.  */
     332     63856325 :       if (b->explicit_spec_p)
     333              :         {
     334      1525623 :           if (n_template_parm_scopes == 0)
     335              :             innermost_specialization_p = 1;
     336              :           else
     337         1133 :             seen_specialization_p = 1;
     338              :         }
     339     62330702 :       else if (seen_specialization_p == 1)
     340              :         return tsk_invalid_member_spec;
     341              : 
     342     63856325 :       ++n_template_parm_scopes;
     343              :     }
     344              : 
     345              :   /* Handle explicit instantiations.  */
     346    258032856 :   if (processing_explicit_instantiation)
     347              :     {
     348      2010750 :       if (n_template_parm_scopes != 0)
     349              :         /* We've seen a template parameter list during an explicit
     350              :            instantiation.  For example:
     351              : 
     352              :              template <class T> template void f(int);
     353              : 
     354              :            This is erroneous.  */
     355              :         return tsk_invalid_expl_inst;
     356              :       else
     357      2010750 :         return tsk_expl_inst;
     358              :     }
     359              : 
     360    256022106 :   if (n_template_parm_scopes < n_class_scopes)
     361              :     /* We've not seen enough template headers to match all the
     362              :        specialized classes present.  For example:
     363              : 
     364              :          template <class T> void R<T>::S<T>::f(int);
     365              : 
     366              :        This is invalid; there needs to be one set of template
     367              :        parameters for each class.  */
     368              :     return tsk_insufficient_parms;
     369    256022106 :   else if (n_template_parm_scopes == n_class_scopes)
     370              :     /* We're processing a non-template declaration (even though it may
     371              :        be a member of a template class.)  For example:
     372              : 
     373              :          template <class T> void S<T>::f(int);
     374              : 
     375              :        The `class T' matches the `S<T>', leaving no template headers
     376              :        corresponding to the `f'.  */
     377              :     return tsk_none;
     378     55555541 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     379              :     /* We've got too many template headers.  For example:
     380              : 
     381              :          template <> template <class T> void f (T);
     382              : 
     383              :        There need to be more enclosing classes.  */
     384              :     return tsk_excessive_parms;
     385              :   else
     386              :     /* This must be a template.  It's of the form:
     387              : 
     388              :          template <class T> template <class U> void S<T>::f(U);
     389              : 
     390              :        This is a specialization if the innermost level was a
     391              :        specialization; otherwise it's just a definition of the
     392              :        template.  */
     393     55555541 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     394              : }
     395              : 
     396              : /* Exit the current scope.  */
     397              : 
     398              : void
     399    101234925 : finish_scope (void)
     400              : {
     401    101234925 :   poplevel (0, 0, 0);
     402    101234925 : }
     403              : 
     404              : /* When a label goes out of scope, check to see if that label was used
     405              :    in a valid manner, and issue any appropriate warnings or errors.  */
     406              : 
     407              : static void
     408        21156 : check_label_used (tree label)
     409              : {
     410        21156 :   if (!processing_template_decl)
     411              :     {
     412        20847 :       if (DECL_INITIAL (label) == NULL_TREE)
     413              :         {
     414            9 :           location_t location;
     415              : 
     416            9 :           error ("label %q+D used but not defined", label);
     417            9 :           location = input_location;
     418              :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     419              :           /* Avoid crashing later.  */
     420            9 :           define_label (location, DECL_NAME (label));
     421              :         }
     422              :       else
     423        20838 :         warn_for_unused_label (label);
     424              :     }
     425        21156 : }
     426              : 
     427              : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     428              : 
     429              : static int
     430       237748 : sort_labels (const void *a, const void *b)
     431              : {
     432       237748 :   tree label1 = *(tree const *) a;
     433       237748 :   tree label2 = *(tree const *) b;
     434              : 
     435              :   /* DECL_UIDs can never be equal.  */
     436       237748 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     437              : }
     438              : 
     439              : static void adjust_backward_goto (named_label_entry *, tree_stmt_iterator);
     440              : static named_label_entry *lookup_label_1 (tree, bool);
     441              : 
     442              : /* Helper of pop_labels, called through cp_walk_tree.  Adjust
     443              :    LABEL_EXPRs of named labels, if they are targets of backwards
     444              :    gotos jumping across vacuous initialization for
     445              :    !!flag_auto_var_init.  */
     446              : 
     447              : static tree
     448         2909 : adjust_backward_gotos (tree *tp, int *walk_subtrees, void *data)
     449              : {
     450         2909 :   tree t = *tp;
     451         2909 :   switch (TREE_CODE (t))
     452              :     {
     453            3 :     case LABEL_EXPR:
     454              :       /* In rare cases LABEL_EXPR can appear as the only substatement
     455              :          of some other statement, e.g. if body etc.  In that case, we know
     456              :          there can't be an older if (0) wrapper with artificial initializers
     457              :          before it.  Replace the LABEL_EXPR statement with a STATEMENT_LIST
     458              :          and insert the LABEL_EXPR into it, later on if (0) will be added
     459              :          before that.  */
     460            3 :       if (DECL_NAME (LABEL_EXPR_LABEL (t)))
     461              :         {
     462            3 :           named_label_entry *ent
     463            3 :             = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (t)), false);
     464            3 :           if (ent->direct_goto)
     465              :             {
     466            3 :               *tp = alloc_stmt_list ();
     467            3 :               append_to_statement_list_force (t, tp);
     468            3 :               adjust_backward_goto (ent, tsi_last (*tp));
     469              :             }
     470              :         }
     471            3 :       *walk_subtrees = 0;
     472            3 :       break;
     473          141 :     case STATEMENT_LIST:
     474          141 :       {
     475          141 :         tree_stmt_iterator i;
     476          141 :         *walk_subtrees = 0;
     477              :         /* In the common case, LABEL_EXPRs appear inside of a STATEMENT_LIST.
     478              :            In that case pass the stmt iterator to adjust_backward_goto, so
     479              :            that it can insert if (0) wrapper artificial initializers before
     480              :            it or reuse the existing ones.  */
     481          915 :         for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
     482          774 :           if (TREE_CODE (tsi_stmt (i)) != LABEL_EXPR)
     483          737 :             cp_walk_tree (tsi_stmt_ptr (i), adjust_backward_gotos,
     484              :                           data, (hash_set<tree> *) data);
     485           37 :           else if (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))))
     486              :             {
     487           16 :               named_label_entry *ent
     488           16 :                 = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))),
     489              :                                   false);
     490           16 :               if (ent->direct_goto)
     491           16 :                 adjust_backward_goto (ent, i);
     492              :             }
     493          141 :         break;
     494              :       }
     495         2765 :     default:
     496         2765 :       if (TYPE_P (t))
     497            4 :         *walk_subtrees = 0;
     498              :     }
     499         2909 :   return NULL_TREE;
     500              : }
     501              : 
     502              : /* At the end of a function, all labels declared within the function
     503              :    go out of scope.  BLOCK is the top-level block for the
     504              :    function.  */
     505              : 
     506              : static void
     507    167100697 : pop_labels (tree block)
     508              : {
     509    167100697 :   if (!named_labels)
     510    167095941 :     return;
     511              : 
     512              :   /* We need to add the labels to the block chain, so debug
     513              :      information is emitted.  But, we want the order to be stable so
     514              :      need to sort them first.  Otherwise the debug output could be
     515              :      randomly ordered.  I guess it's mostly stable, unless the hash
     516              :      table implementation changes.  */
     517         4756 :   auto_vec<tree, 32> labels (named_labels->elements ());
     518         4756 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     519              : 
     520         4756 :   if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
     521          733 :       && !processing_template_decl)
     522              :     {
     523         4009 :       for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     524              :         {
     525         2607 :           named_label_entry *ent = *iter;
     526         2607 :           if (ent->direct_goto)
     527              :             {
     528            4 :               hash_set<tree> pset;
     529            4 :               cp_walk_tree (&DECL_SAVED_TREE (current_function_decl),
     530              :                             adjust_backward_gotos, &pset, &pset);
     531            4 :               break;
     532            4 :             }
     533              :         }
     534              :     }
     535              : 
     536        25879 :   for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     537              :     {
     538        21123 :       named_label_entry *ent = *iter;
     539              : 
     540        21123 :       gcc_checking_assert (!ent->outer);
     541        21123 :       if (ent->label_decl)
     542        20937 :         labels.quick_push (ent->label_decl);
     543        21123 :       ggc_free (ent);
     544              :     }
     545         4756 :   named_labels = NULL;
     546         4756 :   labels.qsort (sort_labels);
     547              : 
     548        25693 :   while (labels.length ())
     549              :     {
     550        20937 :       tree label = labels.pop ();
     551              : 
     552        20937 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     553        20937 :       BLOCK_VARS (block) = label;
     554              : 
     555        20937 :       check_label_used (label);
     556              :     }
     557         4756 : }
     558              : 
     559              : /* At the end of a block with local labels, restore the outer definition.  */
     560              : 
     561              : static void
     562          219 : pop_local_label (tree id, tree label)
     563              : {
     564          219 :   check_label_used (label);
     565          219 :   named_label_entry **slot = named_labels->find_slot_with_hash
     566          219 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     567          219 :   named_label_entry *ent = *slot;
     568              : 
     569          219 :   if (ent->outer)
     570              :     ent = ent->outer;
     571              :   else
     572              :     {
     573          198 :       ent = ggc_cleared_alloc<named_label_entry> ();
     574          198 :       ent->name = id;
     575              :     }
     576          219 :   *slot = ent;
     577          219 : }
     578              : 
     579              : /* The following two routines are used to interface to Objective-C++.
     580              :    The binding level is purposely treated as an opaque type.  */
     581              : 
     582              : void *
     583            0 : objc_get_current_scope (void)
     584              : {
     585            0 :   return current_binding_level;
     586              : }
     587              : 
     588              : /* The following routine is used by the NeXT-style SJLJ exceptions;
     589              :    variables get marked 'volatile' so as to not be clobbered by
     590              :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     591              :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     592              :    shall be thusly marked.  */
     593              : 
     594              : void
     595            0 : objc_mark_locals_volatile (void *enclosing_blk)
     596              : {
     597            0 :   cp_binding_level *scope;
     598              : 
     599            0 :   for (scope = current_binding_level;
     600            0 :        scope && scope != enclosing_blk;
     601            0 :        scope = scope->level_chain)
     602              :     {
     603            0 :       tree decl;
     604              : 
     605            0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     606            0 :         objc_volatilize_decl (decl);
     607              : 
     608              :       /* Do not climb up past the current function.  */
     609            0 :       if (scope->kind == sk_function_parms)
     610              :         break;
     611              :     }
     612            0 : }
     613              : 
     614              : /* True if B is the level for the condition of a constexpr if.  */
     615              : 
     616              : static bool
     617      1802500 : level_for_constexpr_if (cp_binding_level *b)
     618              : {
     619      1798357 :   return (b->kind == sk_cond && b->this_entity
     620          302 :           && TREE_CODE (b->this_entity) == IF_STMT
     621      1802802 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     622              : }
     623              : 
     624              : /* True if B is the level for the condition of a consteval if.  */
     625              : 
     626              : static bool
     627      1802476 : level_for_consteval_if (cp_binding_level *b)
     628              : {
     629      1798333 :   return (b->kind == sk_cond && b->this_entity
     630          278 :           && TREE_CODE (b->this_entity) == IF_STMT
     631      1802754 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     632              : }
     633              : 
     634              : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
     635              :    See [stmt.dcl]/2.  */
     636              : 
     637              : static bool
     638           25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
     639              : {
     640           25 :   if (error_operand_p (t))
     641              :     return false;
     642              : 
     643           19 :   return (VAR_P (t)
     644           19 :           && decl_storage_duration (const_cast<tree> (t)) == dk_auto
     645           38 :           && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
     646              : }
     647              : 
     648              : /* Update data for defined and undefined labels when leaving a scope.  */
     649              : 
     650              : int
     651       158065 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     652              : {
     653       158065 :   named_label_entry *ent = *slot;
     654       158065 :   cp_binding_level *obl = bl->level_chain;
     655              : 
     656       158065 :   if (ent->binding_level == bl)
     657              :     {
     658        10394 :       tree decl;
     659              : 
     660              :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     661              :          TREE_LISTs representing OVERLOADs, so be careful.  */
     662        15357 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     663         5036 :                                                      ? DECL_CHAIN (decl)
     664           73 :                                                      : TREE_CHAIN (decl)))
     665         4963 :         if (decl_jump_unsafe (decl))
     666              :           {
     667         1909 :             vec_safe_push (ent->bad_decls, decl);
     668         1909 :             ent->has_bad_decls = true;
     669              :           }
     670         3054 :         else if (decl_instrument_init_bypass_p (decl))
     671          443 :           vec_safe_push (ent->bad_decls, decl);
     672              : 
     673        10394 :       ent->binding_level = obl;
     674        10394 :       ent->names_in_scope = obl->names;
     675        10394 :       switch (bl->kind)
     676              :         {
     677           42 :         case sk_try:
     678           42 :           ent->in_try_scope = true;
     679           42 :           break;
     680           27 :         case sk_catch:
     681           27 :           ent->in_catch_scope = true;
     682           27 :           break;
     683          324 :         case sk_omp:
     684          324 :           ent->in_omp_scope = true;
     685          324 :           break;
     686            3 :         case sk_transaction:
     687            3 :           ent->in_transaction_scope = true;
     688            3 :           break;
     689           45 :         case sk_stmt_expr:
     690           45 :           ent->in_stmt_expr = true;
     691           45 :           break;
     692         4191 :         case sk_block:
     693         4191 :           if (level_for_constexpr_if (obl))
     694           15 :             ent->in_constexpr_if = true;
     695         4176 :           else if (level_for_consteval_if (obl))
     696           30 :             ent->in_consteval_if = true;
     697              :           break;
     698              :         default:
     699              :           break;
     700              :         }
     701              :     }
     702       147671 :   else if (ent->uses)
     703              :     {
     704              :       struct named_label_use_entry *use;
     705              : 
     706        23031 :       for (use = ent->uses; use ; use = use->next)
     707        15620 :         if (use->binding_level == bl)
     708              :           {
     709         6051 :             if (auto &cg = use->computed_goto)
     710              :               {
     711           57 :                 if (bl->kind == sk_catch)
     712            3 :                   vec_safe_push (cg, get_identifier ("catch"));
     713           66 :                 for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
     714            9 :                   if (automatic_var_with_nontrivial_dtor_p (d))
     715            6 :                     vec_safe_push (cg, d);
     716              :               }
     717              : 
     718         6051 :             use->binding_level = obl;
     719         6051 :             use->names_in_scope = obl->names;
     720         6051 :             if (bl->kind == sk_omp)
     721           12 :               use->in_omp_scope = true;
     722              :           }
     723              :     }
     724              : 
     725       158065 :   return 1;
     726              : }
     727              : 
     728              : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     729              :    when errors were reported, except for -Werror-unused-but-set-*.  */
     730              : static int unused_but_set_errorcount;
     731              : 
     732              : /* Exit a binding level.
     733              :    Pop the level off, and restore the state of the identifier-decl mappings
     734              :    that were in effect when this level was entered.
     735              : 
     736              :    If KEEP == 1, this level had explicit declarations, so
     737              :    and create a "block" (a BLOCK node) for the level
     738              :    to record its declarations and subblocks for symbol table output.
     739              : 
     740              :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     741              :    so create a block as if KEEP were set and also clear out all
     742              :    label names.
     743              : 
     744              :    If REVERSE is nonzero, reverse the order of decls before putting
     745              :    them into the BLOCK.  */
     746              : 
     747              : tree
     748    703085409 : poplevel (int keep, int reverse, int functionbody)
     749              : {
     750    703085409 :   tree link;
     751              :   /* The chain of decls was accumulated in reverse order.
     752              :      Put it into forward order, just for cleanliness.  */
     753    703085409 :   tree decls;
     754    703085409 :   tree subblocks;
     755    703085409 :   tree block;
     756    703085409 :   tree decl;
     757    703085409 :   scope_kind kind;
     758              : 
     759    703085409 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     760    703085696 :  restart:
     761              : 
     762    703085696 :   block = NULL_TREE;
     763              : 
     764    703085696 :   gcc_assert (current_binding_level->kind != sk_class
     765              :               && current_binding_level->kind != sk_namespace);
     766              : 
     767    703085696 :   if (current_binding_level->kind == sk_cleanup)
     768              :     functionbody = 0;
     769    703085696 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     770              : 
     771    703085696 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     772              : 
     773              :   /* We used to use KEEP == 2 to indicate that the new block should go
     774              :      at the beginning of the list of blocks at this binding level,
     775              :      rather than the end.  This hack is no longer used.  */
     776    703085696 :   gcc_assert (keep == 0 || keep == 1);
     777              : 
     778    703085696 :   if (current_binding_level->keep)
     779      8651808 :     keep = 1;
     780              : 
     781              :   /* Any uses of undefined labels, and any defined labels, now operate
     782              :      under constraints of next binding contour.  */
     783    703085696 :   if (cfun && !functionbody && named_labels)
     784        44194 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     785       202259 :                    (current_binding_level);
     786              : 
     787              :   /* Get the decls in the order they were written.
     788              :      Usually current_binding_level->names is in reverse order.
     789              :      But parameter decls were previously put in forward order.  */
     790              : 
     791    703085696 :   decls = current_binding_level->names;
     792    703085696 :   if (reverse)
     793              :     {
     794    386511859 :       decls = nreverse (decls);
     795    386511859 :       current_binding_level->names = decls;
     796              :     }
     797              : 
     798              :   /* If there were any declarations or structure tags in that level,
     799              :      or if this level is a function body,
     800              :      create a BLOCK to record them for the life of this function.  */
     801    703085696 :   block = NULL_TREE;
     802              :   /* Avoid function body block if possible.  */
     803    745681223 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     804              :     keep = 0;
     805    660490437 :   else if (keep == 1 || functionbody)
     806    211033213 :     block = make_node (BLOCK);
     807    211033213 :   if (block != NULL_TREE)
     808              :     {
     809    211033213 :       BLOCK_VARS (block) = decls;
     810    211033213 :       BLOCK_SUBBLOCKS (block) = subblocks;
     811              :     }
     812              : 
     813              :   /* In each subblock, record that this is its superior.  */
     814    703085696 :   if (keep >= 0)
     815    789612736 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     816     86527040 :       BLOCK_SUPERCONTEXT (link) = block;
     817              : 
     818              :   /* Before we remove the declarations first check for unused variables.  */
     819    703085696 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     820      6794173 :       && current_binding_level->kind != sk_template_parms
     821      5728214 :       && !processing_template_decl)
     822      6569357 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     823              :       {
     824              :         /* There are cases where D itself is a TREE_LIST.  See in
     825              :            push_local_binding where the list of decls returned by
     826              :            getdecls is built.  */
     827      3327834 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     828      3327834 :         decl = strip_using_decl (udecl);
     829              : 
     830      3327834 :         tree type = TREE_TYPE (decl);
     831      3327834 :         if (VAR_P (decl)
     832       388623 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     833         3625 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     834              :             /* For structured bindings, consider only real variables, not
     835              :                subobjects.  */
     836         3613 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     837         3390 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     838              :             /* Don't warn about name-independent declarations.  */
     839          911 :             && !name_independent_decl_p (decl)
     840          755 :             && type != error_mark_node
     841      3332168 :             && (!CLASS_TYPE_P (type)
     842           51 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     843            3 :                 || lookup_attribute ("warn_unused",
     844            3 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     845              :           {
     846          721 :             if (!TREE_USED (decl))
     847              :               {
     848          317 :                 if (TREE_CODE (udecl) == USING_DECL)
     849            3 :                   warning_at (DECL_SOURCE_LOCATION (udecl),
     850            3 :                               OPT_Wunused_variable,
     851              :                               "unused using-declaration %qD", udecl);
     852          314 :                 else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     853            3 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     854            3 :                               OPT_Wunused_variable,
     855              :                               "unused structured binding declaration");
     856              :                 else
     857          311 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     858          311 :                               OPT_Wunused_variable, "unused variable %qD", decl);
     859          317 :                 suppress_warning (decl, OPT_Wunused_variable);
     860              :               }
     861          404 :             else if (DECL_CONTEXT (decl) == current_function_decl
     862              :                      // For -Wunused-but-set-variable leave references alone.
     863          380 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     864          784 :                      && errorcount == unused_but_set_errorcount)
     865              :               {
     866          371 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     867           12 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     868           12 :                               OPT_Wunused_but_set_variable_, "structured "
     869              :                               "binding declaration set but not used");
     870              :                 else
     871          359 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     872          359 :                               OPT_Wunused_but_set_variable_,
     873              :                               "variable %qD set but not used", decl);
     874          371 :                 unused_but_set_errorcount = errorcount;
     875              :               }
     876              :           }
     877              :       }
     878              : 
     879              :   /* Remove declarations for all the DECLs in this level.  */
     880   1419595757 :   for (link = decls; link; link = TREE_CHAIN (link))
     881              :     {
     882    716510061 :       tree name;
     883    716510061 :       if (TREE_CODE (link) == TREE_LIST)
     884              :         {
     885     13824034 :           decl = TREE_VALUE (link);
     886     13824034 :           name = TREE_PURPOSE (link);
     887     13824034 :           gcc_checking_assert (name);
     888              :         }
     889              :       else
     890              :         {
     891    702686027 :           decl = link;
     892    702686027 :           name = DECL_NAME (decl);
     893              :         }
     894              : 
     895              :       /* Remove the binding.  */
     896    716510061 :       if (TREE_CODE (decl) == LABEL_DECL)
     897          219 :         pop_local_label (name, decl);
     898              :       else
     899    716509842 :         pop_local_binding (name, decl);
     900              :     }
     901              : 
     902              :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     903    703085696 :   for (link = current_binding_level->type_shadowed;
     904    957280968 :        link; link = TREE_CHAIN (link))
     905    254195272 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     906              : 
     907              :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     908              :      list if a `using' declaration put them there.  The debugging
     909              :      back ends won't understand OVERLOAD, so we remove them here.
     910              :      Because the BLOCK_VARS are (temporarily) shared with
     911              :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     912              :      popped all the bindings.  Also remove undeduced 'auto' decls,
     913              :      which LTO doesn't understand, and can't have been used by anything.  */
     914    703085696 :   if (block)
     915              :     {
     916    211033213 :       tree* d;
     917              : 
     918    555317821 :       for (d = &BLOCK_VARS (block); *d; )
     919              :         {
     920    344284608 :           if (TREE_CODE (*d) == TREE_LIST
     921    344284608 :               || (!processing_template_decl
     922    108920976 :                   && undeduced_auto_decl (*d)))
     923     13824086 :             *d = TREE_CHAIN (*d);
     924              :           else
     925    330460522 :             d = &DECL_CHAIN (*d);
     926              :         }
     927              :     }
     928              : 
     929              :   /* If the level being exited is the top level of a function,
     930              :      check over all the labels.  */
     931    703085696 :   if (functionbody)
     932              :     {
     933    167100697 :       if (block)
     934              :         {
     935              :           /* Since this is the top level block of a function, the vars are
     936              :              the function's parameters.  Don't leave them in the BLOCK
     937              :              because they are found in the FUNCTION_DECL instead.  */
     938    124505438 :           BLOCK_VARS (block) = 0;
     939    124505438 :           pop_labels (block);
     940              :         }
     941              :       else
     942     42595259 :         pop_labels (subblocks);
     943              :     }
     944              : 
     945    703085696 :   kind = current_binding_level->kind;
     946    703085696 :   if (kind == sk_cleanup)
     947              :     {
     948          287 :       tree stmt;
     949              : 
     950              :       /* If this is a temporary binding created for a cleanup, then we'll
     951              :          have pushed a statement list level.  Pop that, create a new
     952              :          BIND_EXPR for the block, and insert it into the stream.  */
     953          287 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     954          287 :       stmt = c_build_bind_expr (input_location, block, stmt);
     955          287 :       add_stmt (stmt);
     956              :     }
     957              : 
     958    703085696 :   leave_scope ();
     959    703085696 :   if (functionbody)
     960              :     {
     961              :       /* The current function is being defined, so its DECL_INITIAL
     962              :          should be error_mark_node.  */
     963    167100697 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     964    209695956 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     965    167100697 :       if (subblocks)
     966              :         {
     967     81064649 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
     968     52933511 :               && BLOCK_SUBBLOCKS (subblocks))
     969      1386537 :             BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     970              :           else
     971     41208990 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     972              :         }
     973              :     }
     974    535984999 :   else if (block)
     975     86527775 :     current_binding_level->blocks
     976    173055550 :       = block_chainon (current_binding_level->blocks, block);
     977              : 
     978              :   /* If we did not make a block for the level just exited,
     979              :      any blocks made for inner levels
     980              :      (since they cannot be recorded as subblocks in that level)
     981              :      must be carried forward so they will later become subblocks
     982              :      of something else.  */
     983    449457224 :   else if (subblocks)
     984           18 :     current_binding_level->blocks
     985           36 :       = block_chainon (current_binding_level->blocks, subblocks);
     986              : 
     987              :   /* Each and every BLOCK node created here in `poplevel' is important
     988              :      (e.g. for proper debugging information) so if we created one
     989              :      earlier, mark it as "used".  */
     990    703085696 :   if (block)
     991    211033213 :     TREE_USED (block) = 1;
     992              : 
     993              :   /* All temporary bindings created for cleanups are popped silently.  */
     994    703085696 :   if (kind == sk_cleanup)
     995          287 :     goto restart;
     996              : 
     997   1406170818 :   return block;
     998    703085409 : }
     999              : 
    1000              : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
    1001              : /* Diagnose odr-used extern inline variables without definitions
    1002              :    in the current TU.  */
    1003              : 
    1004              : int
    1005       146284 : wrapup_namespace_globals ()
    1006              : {
    1007       146284 :   if (vec<tree, va_gc> *statics = static_decls)
    1008              :     {
    1009     18242570 :       for (tree decl : *statics)
    1010              :         {
    1011              :           /* Rewrite the REFLECT_EXPR with 0 so that the ME can process it.  */
    1012     18122807 :           if (flag_reflection && DECL_INITIAL (decl))
    1013       307423 :             rewrite_null_reflection (DECL_INITIAL (decl));
    1014              : 
    1015     18122807 :           if (warn_unused_function
    1016      1014867 :               && TREE_CODE (decl) == FUNCTION_DECL
    1017       765494 :               && DECL_INITIAL (decl) == 0
    1018         7625 :               && DECL_EXTERNAL (decl)
    1019         7613 :               && !TREE_PUBLIC (decl)
    1020           34 :               && !DECL_ARTIFICIAL (decl)
    1021           34 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    1022            9 :               && !warning_suppressed_p (decl, OPT_Wunused)
    1023     19137674 :               && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
    1024              :                              "%qF declared %<static%> but never defined",
    1025              :                              decl))
    1026            6 :                 suppress_warning (decl, OPT_Wunused);
    1027              : 
    1028     18122807 :           if (VAR_P (decl)
    1029      5969419 :               && DECL_EXTERNAL (decl)
    1030              :               /* We mark consteval-only variables DECL_EXTERNAL, but
    1031              :                   extern constexpr inline std::meta::info i{};
    1032              :                  is a definition (the extern is redundant).  */
    1033      2043454 :               && !DECL_INITIAL (decl)
    1034      2042283 :               && DECL_INLINE_VAR_P (decl)
    1035     18122836 :               && DECL_ODR_USED (decl))
    1036            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    1037              :                       "odr-used inline variable %qD is not defined", decl);
    1038              :         }
    1039              : 
    1040              :       /* Clear out the list, so we don't rescan next time.  */
    1041       119763 :       static_decls = NULL;
    1042              : 
    1043              :       /* Write out any globals that need to be output.  */
    1044       119763 :       return wrapup_global_declarations (statics->address (),
    1045       119763 :                                          statics->length ());
    1046              :     }
    1047              :   return 0;
    1048              : }
    1049              : 
    1050              : /* In C++, you don't have to write `struct S' to refer to `S'; you
    1051              :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
    1052              :    if the user had written `typedef struct S S'.  Create and return
    1053              :    the TYPE_DECL for TYPE.  */
    1054              : 
    1055              : tree
    1056    187854871 : create_implicit_typedef (tree name, tree type)
    1057              : {
    1058    187854871 :   tree decl;
    1059              : 
    1060    187854871 :   decl = build_decl (input_location, TYPE_DECL, name, type);
    1061    187854871 :   DECL_ARTIFICIAL (decl) = 1;
    1062              :   /* There are other implicit type declarations, like the one *within*
    1063              :      a class that allows you to write `S::S'.  We must distinguish
    1064              :      amongst these.  */
    1065    187854871 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
    1066    187854871 :   TYPE_NAME (type) = decl;
    1067    187854871 :   TYPE_STUB_DECL (type) = decl;
    1068              : 
    1069    187854871 :   return decl;
    1070              : }
    1071              : 
    1072              : /* Function-scope local entities that need discriminators.  Each entry
    1073              :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
    1074              :    smashed, so we cannot rely on DECL_NAME.  */
    1075              : 
    1076              : static GTY((deletable)) vec<tree, va_gc> *local_entities;
    1077              : 
    1078              : /* Determine the mangling discriminator of local DECL.  There are
    1079              :    generally very few of these in any particular function.  */
    1080              : 
    1081              : void
    1082       760583 : determine_local_discriminator (tree decl, tree name)
    1083              : {
    1084       760583 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    1085       760583 :   retrofit_lang_decl (decl);
    1086       760583 :   tree ctx = DECL_CONTEXT (decl);
    1087       760583 :   size_t nelts = vec_safe_length (local_entities);
    1088       760583 :   if (name == NULL_TREE)
    1089       760314 :     name = (TREE_CODE (decl) == TYPE_DECL
    1090      1239479 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
    1091      1375630 :             ? NULL_TREE : DECL_NAME (decl));
    1092     22511382 :   for (size_t i = 0; i < nelts; i += 2)
    1093              :     {
    1094     21751479 :       tree *pair = &(*local_entities)[i];
    1095     21751479 :       tree d = pair[0];
    1096     21751479 :       tree n = pair[1];
    1097     21751479 :       gcc_checking_assert (d != decl);
    1098     21751479 :       if (name == n
    1099      3902708 :           && TREE_CODE (decl) == TREE_CODE (d)
    1100     25654178 :           && ctx == DECL_CONTEXT (d))
    1101              :         {
    1102          680 :           tree disc = integer_one_node;
    1103          680 :           if (DECL_DISCRIMINATOR (d))
    1104          375 :             disc = build_int_cst (TREE_TYPE (disc),
    1105          375 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
    1106          680 :           DECL_DISCRIMINATOR (decl) = disc;
    1107              :           /* Replace the saved decl.  */
    1108          680 :           pair[0] = decl;
    1109          680 :           decl = NULL_TREE;
    1110          680 :           break;
    1111              :         }
    1112              :     }
    1113              : 
    1114       760583 :   if (decl)
    1115              :     {
    1116       759903 :       vec_safe_reserve (local_entities, 2);
    1117       759903 :       local_entities->quick_push (decl);
    1118       759903 :       local_entities->quick_push (name);
    1119              :     }
    1120       760583 : }
    1121              : 
    1122              : 
    1123              : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
    1124              : 
    1125              :    A non-template friend declaration with a requires-clause shall be a
    1126              :    definition. A friend function template with a constraint that depends on a
    1127              :    template parameter from an enclosing template shall be a definition. Such a
    1128              :    constrained friend function or function template declaration does not
    1129              :    declare the same function or function template as a declaration in any other
    1130              :    scope.
    1131              : 
    1132              :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1133              :    member function to avoid collisions.  */
    1134              : 
    1135              : bool
    1136   2580458051 : member_like_constrained_friend_p (tree decl)
    1137              : {
    1138   2580458051 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1139    887027310 :           && DECL_UNIQUE_FRIEND_P (decl)
    1140    293479972 :           && DECL_FRIEND_CONTEXT (decl)
    1141    129047195 :           && get_constraints (decl)
    1142     18761458 :           && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
    1143   2589816858 :           && (!DECL_TEMPLATE_INFO (decl)
    1144      9358807 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1145         8561 :               || (uses_outer_template_parms_in_constraints
    1146         8561 :                   (most_general_template (decl)))));
    1147              : }
    1148              : 
    1149              : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1150              :    requires clauses.  */
    1151              : 
    1152              : static bool
    1153     72473178 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1154              : {
    1155              :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1156              :      same function as a declaration in any other scope."  So no need to
    1157              :      actually compare the requirements.  */
    1158     72473178 :   if (member_like_constrained_friend_p (newfn)
    1159     72473178 :       || member_like_constrained_friend_p (oldfn))
    1160              :     return false;
    1161              : 
    1162              :   /* Compare only trailing requirements.  */
    1163     72473057 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1164     72473057 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1165     72473057 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1166              :     return false;
    1167              : 
    1168              :   /* Substitution is needed when friends are involved.  */
    1169     72337806 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1170     72337806 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1171              : 
    1172     72337806 :   return cp_tree_equal (reqs1, reqs2);
    1173              : }
    1174              : 
    1175              : /* Two functions of the same name correspond [basic.scope.scope] if
    1176              : 
    1177              :    + both declare functions with the same non-object-parameter-type-list,
    1178              :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1179              :    specified in [temp.friend]), and, if both are non-static members, they have
    1180              :    corresponding object parameters, or
    1181              : 
    1182              :    + both declare function templates with equivalent
    1183              :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1184              :    trailing requires-clauses (if any), and, if both are non-static members,
    1185              :    they have corresponding object parameters.
    1186              : 
    1187              :    This is a subset of decls_match: it identifies declarations that cannot be
    1188              :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1189              : 
    1190              : bool
    1191   1571150778 : fns_correspond (tree newdecl, tree olddecl)
    1192              : {
    1193   1571150778 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1194              :     return false;
    1195              : 
    1196   1460760540 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1197              :     {
    1198   1459396809 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1199              :         return 0;
    1200    346950917 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1201    346950917 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1202              :     }
    1203              : 
    1204    348314648 :   tree f1 = TREE_TYPE (newdecl);
    1205    348314648 :   tree f2 = TREE_TYPE (olddecl);
    1206              : 
    1207    348314648 :   int rq1 = type_memfn_rqual (f1);
    1208    348314648 :   int rq2 = type_memfn_rqual (f2);
    1209              : 
    1210              :   /* If only one is a non-static member function, ignore ref-quals.  */
    1211    348314648 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1212              :     rq1 = rq2;
    1213              :   /* Two non-static member functions have corresponding object parameters if:
    1214              :      + exactly one is an implicit object member function with no ref-qualifier
    1215              :      and the types of their object parameters ([dcl.fct]), after removing
    1216              :      top-level references, are the same, or
    1217              :      + their object parameters have the same type.  */
    1218              :   /* ??? We treat member functions of different classes as corresponding even
    1219              :      though that means the object parameters have different types.  */
    1220    348314648 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1221            0 :     rq1 = rq2;
    1222              : 
    1223    348314648 :   bool types_match = rq1 == rq2;
    1224              : 
    1225    348314648 :   if (types_match)
    1226              :     {
    1227    348314648 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1228    348314648 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1229    348314648 :       types_match = compparms (p1, p2);
    1230              :     }
    1231              : 
    1232              :   /* Two function declarations match if either has a requires-clause
    1233              :      then both have a requires-clause and their constraints-expressions
    1234              :      are equivalent.  */
    1235    348314648 :   if (types_match && flag_concepts)
    1236     42934067 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1237              : 
    1238              :   return types_match;
    1239              : }
    1240              : 
    1241              : /* Subroutine of duplicate_decls: return truthvalue of whether
    1242              :    or not types of these decls match.
    1243              : 
    1244              :    For C++, we must compare the parameter list so that `int' can match
    1245              :    `int&' in a parameter position, but `int&' is not confused with
    1246              :    `const int&'.  */
    1247              : 
    1248              : int
    1249    820052234 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1250              : {
    1251    870418524 :   int types_match;
    1252              : 
    1253    870418524 :   if (newdecl == olddecl)
    1254              :     return 1;
    1255              : 
    1256    870300126 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1257              :     /* If the two DECLs are not even the same kind of thing, we're not
    1258              :        interested in their types.  */
    1259              :     return 0;
    1260              : 
    1261    459098194 :   gcc_assert (DECL_P (newdecl));
    1262              : 
    1263    459098194 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1264              :     {
    1265              :       /* Specializations of different templates are different functions
    1266              :          even if they have the same type.  */
    1267    303374570 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1268    303374570 :                  ? DECL_TI_TEMPLATE (newdecl)
    1269       649639 :                  : NULL_TREE);
    1270    303374570 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1271    303374570 :                  ? DECL_TI_TEMPLATE (olddecl)
    1272      4141869 :                  : NULL_TREE);
    1273    303374570 :       if (t1 != t2)
    1274              :         return 0;
    1275              : 
    1276    299882257 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1277    299882257 :           && ! (DECL_EXTERN_C_P (newdecl)
    1278      3004900 :                 && DECL_EXTERN_C_P (olddecl)))
    1279              :         return 0;
    1280              : 
    1281              :       /* A new declaration doesn't match a built-in one unless it
    1282              :          is also extern "C".  */
    1283    278034105 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1284    278034105 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1285              :         return 0;
    1286              : 
    1287    277372215 :       tree f1 = TREE_TYPE (newdecl);
    1288    277372215 :       tree f2 = TREE_TYPE (olddecl);
    1289    277372215 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1290              :         return 0;
    1291              : 
    1292              :       /* A declaration with deduced return type should use its pre-deduction
    1293              :          type for declaration matching.  */
    1294    277193303 :       tree r2 = fndecl_declared_return_type (olddecl);
    1295    277193303 :       tree r1 = fndecl_declared_return_type (newdecl);
    1296              : 
    1297              :       /* For memchr et al, allow const void* return type (as specified by C++)
    1298              :          when we expect void* (as in C).  */
    1299    277193303 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1300      6622127 :           && DECL_EXTERN_C_P (olddecl)
    1301      4083250 :           && !same_type_p (r1, r2)
    1302           70 :           && TREE_CODE (r1) == POINTER_TYPE
    1303           15 :           && TREE_CODE (r2) == POINTER_TYPE
    1304    277193315 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1305              :         r2 = r1;
    1306              : 
    1307    277193303 :       tree p1 = TYPE_ARG_TYPES (f1);
    1308    277193303 :       tree p2 = TYPE_ARG_TYPES (f2);
    1309              : 
    1310    277193303 :       if (same_type_p (r1, r2))
    1311              :         {
    1312    177614607 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1313    177614575 :               && fndecl_built_in_p (olddecl))
    1314              :             {
    1315           50 :               types_match = self_promoting_args_p (p1);
    1316           50 :               if (p1 == void_list_node)
    1317            3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1318              :             }
    1319              :           else
    1320    177614469 :             types_match =
    1321    177614469 :               compparms (p1, p2)
    1322     30024693 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1323    207638766 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1324      1250261 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1325      1250261 :                                            TREE_TYPE (olddecl)) != 0);
    1326              :         }
    1327              :       else
    1328              :         types_match = 0;
    1329              : 
    1330              :       /* Two function declarations match if either has a requires-clause
    1331              :          then both have a requires-clause and their constraints-expressions
    1332              :          are equivalent.  */
    1333     30024326 :       if (types_match && flag_concepts)
    1334     29539079 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1335              : 
    1336              :       /* The decls dont match if they correspond to two different versions
    1337              :          of the same function.   Disallow extern "C" functions to be
    1338              :          versions for now.  */
    1339     30024326 :       if (types_match
    1340     29822062 :           && !DECL_EXTERN_C_P (newdecl)
    1341     21450610 :           && !DECL_EXTERN_C_P (olddecl)
    1342     51471147 :           && disjoint_version_decls (newdecl, olddecl))
    1343              :         {
    1344         8880 :           if (record_versions)
    1345         8793 :             maybe_version_functions (newdecl, olddecl);
    1346              :           return 0;
    1347              :         }
    1348              :     }
    1349    155723624 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1350              :     {
    1351    153905823 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1352              :         return 0;
    1353              : 
    1354     50367854 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1355     50367854 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1356              : 
    1357     50367854 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1358              :         return 0;
    1359              : 
    1360              :       /* Two template types match if they are the same. Otherwise, compare
    1361              :          the underlying declarations.  */
    1362     50367845 :       if (TREE_CODE (newres) == TYPE_DECL)
    1363         1555 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1364              :       else
    1365              :         types_match = decls_match (newres, oldres);
    1366              :     }
    1367              :   else
    1368              :     {
    1369              :       /* Need to check scope for variable declaration (VAR_DECL).
    1370              :          For typedef (TYPE_DECL), scope is ignored.  */
    1371      1817801 :       if (VAR_P (newdecl)
    1372      1218071 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1373              :           /* [dcl.link]
    1374              :              Two declarations for an object with C language linkage
    1375              :              with the same name (ignoring the namespace that qualify
    1376              :              it) that appear in different namespace scopes refer to
    1377              :              the same object.  */
    1378      2009863 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1379              :         return 0;
    1380              : 
    1381      1625787 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1382            0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1383      1625787 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1384            0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1385      1625787 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1386              :         types_match = 0;
    1387              :       else
    1388      1625787 :         types_match = comptypes (TREE_TYPE (newdecl),
    1389      1625787 :                                  TREE_TYPE (olddecl),
    1390              :                                  COMPARE_REDECLARATION);
    1391              :     }
    1392              : 
    1393              :   return types_match;
    1394              : }
    1395              : 
    1396              : /* Mark DECL as versioned if it isn't already.  */
    1397              : 
    1398              : void
    1399        17676 : maybe_mark_function_versioned (tree decl)
    1400              : {
    1401        17676 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1402              :     {
    1403              :       /* We need to insert function version now to make sure the correct
    1404              :          pre-mangled assembler name is recorded.  */
    1405         1068 :       cgraph_node *node = cgraph_node::get_create (decl);
    1406              : 
    1407         1068 :       if (!node->function_version ())
    1408         1068 :         node->insert_new_function_version ();
    1409              : 
    1410         1068 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1411              :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1412              :          to include the version marker.  */
    1413         1068 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1414         1062 :         mangle_decl (decl);
    1415              :     }
    1416        17676 : }
    1417              : 
    1418              : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1419              :    different versions adjust them, record function versions, and return
    1420              :    true.  */
    1421              : 
    1422              : bool
    1423       207636 : maybe_version_functions (tree newdecl, tree olddecl)
    1424              : {
    1425       207636 :   if (!disjoint_version_decls (newdecl, olddecl))
    1426              :     return false;
    1427              : 
    1428         8820 :   maybe_mark_function_versioned (olddecl);
    1429         8820 :   if (DECL_LOCAL_DECL_P (olddecl))
    1430              :     {
    1431           18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1432           18 :       maybe_mark_function_versioned (olddecl);
    1433              :     }
    1434              : 
    1435         8820 :   maybe_mark_function_versioned (newdecl);
    1436         8820 :   if (DECL_LOCAL_DECL_P (newdecl))
    1437              :     {
    1438              :       /* Unfortunately, we can get here before pushdecl naturally calls
    1439              :          push_local_extern_decl_alias, so we need to call it directly.  */
    1440           18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1441            6 :         push_local_extern_decl_alias (newdecl);
    1442           18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1443           18 :       maybe_mark_function_versioned (newdecl);
    1444              :     }
    1445              : 
    1446              :   /* Add the new version to the function version structure.  */
    1447         8820 :   cgraph_node *fn_node = cgraph_node::get_create (olddecl);
    1448         8820 :   cgraph_function_version_info *fn_v = fn_node->function_version ();
    1449         8820 :   if (!fn_v)
    1450           15 :     fn_v = fn_node->insert_new_function_version ();
    1451              : 
    1452         8820 :   cgraph_node::add_function_version (fn_v, newdecl);
    1453              : 
    1454         8820 :   return true;
    1455              : }
    1456              : 
    1457              : /* If NEWDECL is `static' and an `extern' was seen previously,
    1458              :    warn about it.  OLDDECL is the previous declaration.
    1459              : 
    1460              :    Note that this does not apply to the C++ case of declaring
    1461              :    a variable `extern const' and then later `const'.
    1462              : 
    1463              :    Don't complain about built-in functions, since they are beyond
    1464              :    the user's control.  */
    1465              : 
    1466              : void
    1467     20313467 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1468              : {
    1469     20313467 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1470              :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1471              :       || TREE_CODE (newdecl) == CONST_DECL
    1472              :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1473     20313455 :     return;
    1474              : 
    1475              :   /* Don't get confused by static member functions; that's a different
    1476              :      use of `static'.  */
    1477              :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1478     15614465 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1479              :     return;
    1480              : 
    1481              :   /* If the old declaration was `static', or the new one isn't, then
    1482              :      everything is OK.  */
    1483     15947787 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1484              :     return;
    1485              : 
    1486              :   /* It's OK to declare a builtin function as `static'.  */
    1487           12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1488           12 :       && DECL_ARTIFICIAL (olddecl))
    1489              :     return;
    1490              : 
    1491           12 :   auto_diagnostic_group d;
    1492           12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1493              :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1494           12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1495              :             "previous declaration of %qD", olddecl);
    1496           12 : }
    1497              : 
    1498              : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1499              :    function templates.  If their exception specifications do not
    1500              :    match, issue a diagnostic.  */
    1501              : 
    1502              : static void
    1503     19749390 : check_redeclaration_exception_specification (tree new_decl,
    1504              :                                              tree old_decl)
    1505              : {
    1506     19749390 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1507     19749390 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1508              : 
    1509              :   /* Two default specs are equivalent, don't force evaluation.  */
    1510      7624947 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1511     19895286 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1512              :     return;
    1513              : 
    1514     19739453 :   if (!type_dependent_expression_p (old_decl))
    1515              :     {
    1516     12113568 :       maybe_instantiate_noexcept (new_decl);
    1517     12113568 :       maybe_instantiate_noexcept (old_decl);
    1518              :     }
    1519     19739453 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1520     19739453 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1521              : 
    1522              :   /* [except.spec]
    1523              : 
    1524              :      If any declaration of a function has an exception-specification,
    1525              :      all declarations, including the definition and an explicit
    1526              :      specialization, of that function shall have an
    1527              :      exception-specification with the same set of type-ids.  */
    1528     19739453 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1529     15779265 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1530     35518627 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1531              :     {
    1532          329 :       const char *const msg
    1533              :         = G_("declaration of %qF has a different exception specifier");
    1534          329 :       bool complained = true;
    1535          329 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1536          329 :       auto_diagnostic_group d;
    1537              : 
    1538              :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1539          658 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1540            1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1541          331 :                          && (nothrow_spec_p (new_exceptions)
    1542            1 :                              == nothrow_spec_p (old_exceptions)));
    1543              : 
    1544          329 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1545          329 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1546              :         /* Don't fuss about the C library; the C library functions are not
    1547              :            specified to have exception specifications (just behave as if they
    1548              :            have them), but some implementations include them.  */
    1549          233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1550           96 :       else if (!flag_exceptions)
    1551              :         /* We used to silently permit mismatched eh specs with
    1552              :            -fno-exceptions, so only complain if -pedantic.  */
    1553            3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1554           93 :       else if (!new_exceptions || global_new)
    1555              :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1556              :            flag for this; silence the warning by correcting the code.  */
    1557           18 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1558              :       else
    1559           75 :         error_at (new_loc, msg, new_decl);
    1560              : 
    1561          329 :       if (complained)
    1562           99 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1563              :                 "from previous declaration %qF", old_decl);
    1564              : 
    1565              :       /* Copy the old exception specification if new_decl has none.  Unless the
    1566              :          old decl is extern "C", as obscure code might depend on the type of
    1567              :          the new declaration (e.g. noexcept-type19.C).  */
    1568          329 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1569           17 :         TREE_TYPE (new_decl)
    1570           34 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1571          329 :     }
    1572              : }
    1573              : 
    1574              : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1575              :    Otherwise issue diagnostics.  */
    1576              : 
    1577              : bool
    1578     20313993 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1579              : {
    1580     20313993 :   old_decl = STRIP_TEMPLATE (old_decl);
    1581     20313993 :   new_decl = STRIP_TEMPLATE (new_decl);
    1582     20313993 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1583     20262599 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1584              :     return true;
    1585     20262599 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1586     20262599 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1587              :     {
    1588     20111037 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1589              :         return true;
    1590     39499610 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1591     19749805 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1592              :         return true;
    1593              :     }
    1594       151568 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1595              :     {
    1596              :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1597              :          keyword.  */
    1598           71 :       if (flag_implicit_constexpr
    1599           71 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1600            0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1601              :         return true;
    1602           71 :       if (fndecl_built_in_p (old_decl))
    1603              :         {
    1604              :           /* Hide a built-in declaration.  */
    1605            0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1606            0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1607            0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1608            0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1609              :           return true;
    1610              :         }
    1611              :       /* 7.1.5 [dcl.constexpr]
    1612              :          Note: An explicit specialization can differ from the template
    1613              :          declaration with respect to the constexpr specifier.  */
    1614           71 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1615           71 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1616              :         return true;
    1617              : 
    1618           42 :       const char *kind = "constexpr";
    1619           42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1620           72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1621              :         kind = "consteval";
    1622           42 :       auto_diagnostic_group d;
    1623           42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1624              :                 "redeclaration %qD differs in %qs "
    1625              :                 "from previous declaration", new_decl,
    1626              :                 kind);
    1627           42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1628              :               "previous declaration %qD", old_decl);
    1629           42 :       return false;
    1630           42 :     }
    1631              :   return true;
    1632              : }
    1633              : 
    1634              : /* DECL is a redeclaration of a function or function template.  If
    1635              :    it does have default arguments issue a diagnostic.  Note: this
    1636              :    function is used to enforce the requirements in C++11 8.3.6 about
    1637              :    no default arguments in redeclarations.  */
    1638              : 
    1639              : static void
    1640     11832093 : check_redeclaration_no_default_args (tree decl)
    1641              : {
    1642     11832093 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1643              : 
    1644     11832093 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1645     34786703 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1646     22954667 :     if (TREE_PURPOSE (t))
    1647              :       {
    1648           57 :         permerror (DECL_SOURCE_LOCATION (decl),
    1649              :                    "redeclaration of %q#D may not have default "
    1650              :                    "arguments", decl);
    1651           57 :         return;
    1652              :       }
    1653              : }
    1654              : 
    1655              : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1656              :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1657              :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1658              :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1659              :    "If a friend declaration specifies a default argument expression, that
    1660              :    declaration shall be a definition and shall be the only declaration of
    1661              :    the function or function template in the translation unit."  */
    1662              : 
    1663              : static void
    1664      7393183 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1665              : {
    1666     14066917 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1667              :     return;
    1668              : 
    1669      1853624 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1670      1853624 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1671      4901823 :        t1 && t1 != void_list_node;
    1672      3048199 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1673      4333742 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1674      8698541 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1675              :       {
    1676           36 :         auto_diagnostic_group d;
    1677           36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1678              :                        "friend declaration of %q#D specifies default "
    1679              :                        "arguments and isn%'t the only declaration", newdecl))
    1680           36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1681              :                   "previous declaration of %q#D", olddecl);
    1682           36 :         return;
    1683           36 :       }
    1684              : }
    1685              : 
    1686              : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1687              :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1688              : 
    1689              : static void
    1690     19182699 : merge_attribute_bits (tree newdecl, tree olddecl)
    1691              : {
    1692     19182699 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1693     19182699 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1694     19182699 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1695     19182699 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1696     19182699 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1697     19182699 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1698     19182699 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1699     19182699 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1700     19182699 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1701     19182699 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1702     19182699 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1703     19182699 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1704     19182699 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1705     19182699 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1706     19182699 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1707     19182699 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1708     19182699 :   DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    1709     19182699 :   DECL_NO_LIMIT_STACK (olddecl) |= DECL_NO_LIMIT_STACK (newdecl);
    1710     38365398 :   DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    1711     19182699 :     |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    1712     38365398 :   DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl)
    1713     19182699 :     |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl);
    1714     19182699 :   DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
    1715     19182699 :   DECL_IS_NOVOPS (olddecl) |= DECL_IS_NOVOPS (newdecl);
    1716     19182699 : }
    1717              : 
    1718              : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1719              :                           && lookup_attribute ("gnu_inline",          \
    1720              :                                                DECL_ATTRIBUTES (fn)))
    1721              : 
    1722              : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1723              :    ambiguates olddecl.  Returns true if an error occurs.  */
    1724              : 
    1725              : static bool
    1726    149767936 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1727              : {
    1728    149767936 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1729    149767936 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1730              :   /* Function template declarations can be differentiated by parameter
    1731              :      and return type.  */
    1732    149767936 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1733    149767936 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1734    149767936 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1735              :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1736              :     {
    1737              :       /* ... and also by their template-heads and requires-clauses.  */
    1738         7371 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1739         7371 :           && function_requirements_equivalent_p (newres, oldres))
    1740              :         {
    1741            0 :           auto_diagnostic_group d;
    1742            0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1743            0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1744              :                   "old declaration %q#D", olddecl);
    1745            0 :           return true;
    1746            0 :         }
    1747              : 
    1748              :       /* FIXME: The types are the same but the are differences
    1749              :          in either the template heads or function requirements.
    1750              :          We should be able to diagnose a set of common errors
    1751              :          stemming from these declarations. For example:
    1752              : 
    1753              :            template<typename T> requires C void f(...);
    1754              :            template<typename T> void f(...) requires C;
    1755              : 
    1756              :          These are functionally equivalent but not equivalent.  */
    1757              :     }
    1758              : 
    1759              :   return false;
    1760              : }
    1761              : 
    1762              : /* OLD_PARMS is the innermost set of template parameters for some template
    1763              :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1764              :    for a redeclaration of that template.  Merge the default arguments within
    1765              :    these two sets of parameters.  OLDDECL is the origin of OLD_PARMS.  */
    1766              : 
    1767              : bool
    1768      9255619 : merge_default_template_args (tree new_parms, tree old_parms, tree olddecl)
    1769              : {
    1770      9255619 :   bool class_p = DECL_IMPLICIT_TYPEDEF_P (STRIP_TEMPLATE (olddecl));
    1771              : 
    1772      9255619 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1773              :                        == TREE_VEC_LENGTH (old_parms));
    1774     26136122 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1775              :     {
    1776     16880527 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1777     16880527 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1778     16880527 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1779     16880527 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1780     16880527 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1781              :         return false;
    1782       238255 :       if (new_default != NULL_TREE && old_default != NULL_TREE
    1783     16881629 :           && !(redefinable_import_p (olddecl)
    1784          542 :                && cp_tree_equal (new_default, old_default)))
    1785              :         {
    1786           21 :           auto_diagnostic_group d;
    1787           21 :           error ("redefinition of default argument for %q+#D", new_parm);
    1788           21 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1789              :                   "original definition appeared here");
    1790           21 :           return false;
    1791           21 :         }
    1792     16880503 :       else if (new_default != NULL_TREE)
    1793              :         /* Update the previous template parameters (which are the ones
    1794              :            that will really count) with the new default value.  */
    1795       238234 :         old_default = new_default;
    1796     16642269 :       else if (class_p && old_default != NULL_TREE)
    1797              :         /* Update the new parameters, too; they'll be used as the
    1798              :            parameters for any members.  */
    1799      1032311 :         new_default = old_default;
    1800              :     }
    1801              :   return true;
    1802              : }
    1803              : 
    1804              : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
    1805              :    Merge parameter attributes and names between NEWDECL and OLDDECL.
    1806              :    NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
    1807              :    duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
    1808              :    push_local_extern_decl_alias.  */
    1809              : 
    1810              : void
    1811     15614654 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
    1812              :                       bool types_match, bool extern_alias)
    1813              : {
    1814     15614654 :   tree oldarg, newarg, type = NULL_TREE;
    1815     15614654 :   tree first_user_parm = NULL_TREE;
    1816     15614654 :   if (extern_alias)
    1817          189 :     first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
    1818     15614654 :   for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
    1819     43778748 :        oldarg && newarg;
    1820     28164094 :        oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
    1821              :     {
    1822     28164094 :       DECL_ATTRIBUTES (newarg)
    1823     28164094 :         = (*targetm.merge_decl_attributes) (oldarg, newarg);
    1824     28164094 :       if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
    1825     28164163 :           && !lookup_attribute (NULL, "indeterminate",
    1826           69 :                                 DECL_ATTRIBUTES (oldarg)))
    1827              :         {
    1828           18 :           auto_diagnostic_group d;
    1829           18 :           error_at (DECL_SOURCE_LOCATION (newarg),
    1830              :                     "%<indeterminate%> attribute not specified for parameter "
    1831              :                     "%qD on the first declaration of its function", newarg);
    1832           18 :           inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
    1833           18 :         }
    1834              :       /* ??? Should attributes propagate out from a block extern?  If so,
    1835              :          we should do that for the function itself, not just parameters.  */
    1836     28164094 :       if (!extern_alias || flag_reflection)
    1837     28163927 :         DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1838     28164094 :       if (!flag_reflection)
    1839     27750456 :         continue;
    1840              :       /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
    1841              :          if the local extern has a default argument for that parameter.  */
    1842       413638 :       if (extern_alias)
    1843              :         {
    1844           36 :           if (newarg == first_user_parm)
    1845           12 :             type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1846           24 :           else if (type)
    1847           24 :             type = TREE_CHAIN (type);
    1848           72 :           if (type && TREE_PURPOSE (type))
    1849            4 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1850              :         }
    1851              :       else
    1852              :         {
    1853              :           /* Otherwise propagate the flag.  */
    1854       413602 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
    1855            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
    1856       413602 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
    1857            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1858              :         }
    1859              :       /* Merge names for std::meta::has_identifier and
    1860              :          std::meta::{,u8}identifier_of purposes.  If they are different and
    1861              :          both oldarg and newarg are named, add flag to force that
    1862              :          std::meta::has_identifier returns false.  If one is named and one is
    1863              :          unnamed, if neither is a olddecl nor newdecl is definition, propagate
    1864              :          DECL_NAME to both.  Otherwise stash the old name into "old parm name"
    1865              :          artificial attribute.  */
    1866       413638 :       if (DECL_NAME (oldarg) != DECL_NAME (newarg))
    1867              :         {
    1868        46174 :           if (DECL_NAME (oldarg) && DECL_NAME (newarg))
    1869              :             {
    1870              :               /* Different names.  */
    1871        10402 :               MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1872        10402 :               MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1873              :             }
    1874        35772 :           else if (!new_defines_function
    1875        35772 :                    && types_match
    1876        35772 :                    && DECL_INITIAL (olddecl) == NULL_TREE)
    1877              :             {
    1878              :               /* For 2 non-definitions with matching types, one is named and
    1879              :                  one unnamed, propagate name to both.  */
    1880         6756 :               if (DECL_NAME (oldarg))
    1881         5664 :                 DECL_NAME (newarg) = DECL_NAME (oldarg);
    1882              :               else
    1883         1092 :                 DECL_NAME (oldarg) = DECL_NAME (newarg);
    1884              :             }
    1885              :           /* Depending on which PARM_DECL we'll keep, look at the other
    1886              :              PARM_DECL's name.  */
    1887        29016 :           else if (tree name = ((new_defines_function || !types_match)
    1888        29016 :                                 ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
    1889              :             {
    1890          236 :               tree opn = lookup_attribute ("old parm name",
    1891          236 :                                            DECL_ATTRIBUTES (oldarg));
    1892          236 :               if (opn)
    1893              :                 {
    1894            4 :                   if (TREE_VALUE (TREE_VALUE (opn)) == name)
    1895              :                     /* Name already in "old parm name" attribute.  */;
    1896              :                   else
    1897              :                     {
    1898              :                       /* Different names.  */
    1899            0 :                       MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1900            0 :                       MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1901              :                     }
    1902              :                 }
    1903              :               else
    1904              :                 {
    1905              :                   /* Save name into attribute.  */
    1906          232 :                   DECL_ATTRIBUTES (newarg)
    1907          232 :                     = tree_cons (get_identifier ("old parm name"),
    1908              :                                  tree_cons (NULL_TREE, name, NULL_TREE),
    1909          232 :                                  DECL_ATTRIBUTES (newarg));
    1910          232 :                   DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1911              :                 }
    1912              :             }
    1913        28780 :           else if (extern_alias)
    1914            2 :             DECL_NAME (newarg) = DECL_NAME (oldarg);
    1915              :         }
    1916              :     }
    1917     15614654 : }
    1918              : 
    1919              : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1920              :    If the redeclaration is invalid, a diagnostic is issued, and the
    1921              :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1922              : 
    1923              :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1924              :    returned.
    1925              : 
    1926              :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1927              :    if the old decl was hidden.
    1928              : 
    1929              :    Hidden decls can be anticipated builtins, injected friends, or
    1930              :    (coming soon) injected from a local-extern decl.   */
    1931              : 
    1932              : tree
    1933    335480704 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1934              : {
    1935    335626325 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1936    335626325 :   int types_match = 0;
    1937    335626325 :   int new_defines_function = 0;
    1938    335626325 :   tree new_template_info;
    1939    335626325 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1940    335626325 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1941              : 
    1942    335626325 :   if (newdecl == olddecl)
    1943              :     return olddecl;
    1944              : 
    1945    334782797 :   types_match = decls_match (newdecl, olddecl);
    1946              : 
    1947              :   /* If either the type of the new decl or the type of the old decl is an
    1948              :      error_mark_node, then that implies that we have already issued an
    1949              :      error (earlier) for some bogus type specification, and in that case,
    1950              :      it is rather pointless to harass the user with yet more error message
    1951              :      about the same declaration, so just pretend the types match here.  */
    1952    334782797 :   if (TREE_TYPE (newdecl) == error_mark_node
    1953    334782797 :       || TREE_TYPE (olddecl) == error_mark_node)
    1954              :     return error_mark_node;
    1955              : 
    1956    334782768 :   bool mod_redefinable = redefinable_import_p (olddecl);
    1957              : 
    1958              :   /* Check for redeclaration and other discrepancies.  */
    1959    334782768 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1960    334782768 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1961              :     {
    1962      6387355 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1963              :         {
    1964              :           /* Avoid warnings redeclaring built-ins which have not been
    1965              :              explicitly declared.  */
    1966       196841 :           if (was_hidden)
    1967              :             {
    1968       196683 :               if (TREE_PUBLIC (newdecl)
    1969       196683 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1970           18 :                 warning_at (newdecl_loc,
    1971           18 :                             OPT_Wbuiltin_declaration_mismatch,
    1972              :                             "built-in function %qD declared as non-function",
    1973              :                             newdecl);
    1974              :               return NULL_TREE;
    1975              :             }
    1976              : 
    1977              :           /* If you declare a built-in or predefined function name as static,
    1978              :              the old definition is overridden, but optionally warn this was a
    1979              :              bad choice of name.  */
    1980          158 :           if (! TREE_PUBLIC (newdecl))
    1981              :             {
    1982          158 :               warning_at (newdecl_loc,
    1983          158 :                           OPT_Wshadow,
    1984          158 :                           fndecl_built_in_p (olddecl)
    1985              :                           ? G_("shadowing built-in function %q#D")
    1986              :                           : G_("shadowing library function %q#D"), olddecl);
    1987              :               /* Discard the old built-in function.  */
    1988          158 :               return NULL_TREE;
    1989              :             }
    1990              :           /* If the built-in is not ansi, then programs can override
    1991              :              it even globally without an error.  */
    1992            0 :           else if (! fndecl_built_in_p (olddecl))
    1993            0 :             warning_at (newdecl_loc, 0,
    1994              :                         "library function %q#D redeclared as non-function %q#D",
    1995              :                         olddecl, newdecl);
    1996              :           else
    1997            0 :             error_at (newdecl_loc,
    1998              :                       "declaration of %q#D conflicts with built-in "
    1999              :                       "declaration %q#D", newdecl, olddecl);
    2000              :           return NULL_TREE;
    2001              :         }
    2002      6190514 :       else if (!types_match)
    2003              :         {
    2004              :           /* Avoid warnings redeclaring built-ins which have not been
    2005              :              explicitly declared.  */
    2006      2230326 :           if (was_hidden)
    2007              :             {
    2008       807712 :               tree t1, t2;
    2009              : 
    2010              :               /* A new declaration doesn't match a built-in one unless it
    2011              :                  is also extern "C".  */
    2012       807712 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    2013       807712 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    2014       807712 :               if (!DECL_EXTERN_C_P (newdecl))
    2015              :                 return NULL_TREE;
    2016              : 
    2017       145822 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2018       145822 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2019       250912 :                    t1 || t2;
    2020       105090 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2021              :                 {
    2022       250894 :                   if (!t1 || !t2)
    2023              :                     break;
    2024              :                   /* FILE, tm types are not known at the time
    2025              :                      we create the builtins.  */
    2026       772849 :                   for (unsigned i = 0;
    2027      1023581 :                        i < sizeof (builtin_structptr_types)
    2028              :                            / sizeof (builtin_structptr_type);
    2029              :                        ++i)
    2030       918485 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    2031              :                       {
    2032       145636 :                         tree t = TREE_VALUE (t1);
    2033              : 
    2034       145636 :                         if (TYPE_PTR_P (t)
    2035       291272 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    2036       145636 :                             == get_identifier (builtin_structptr_types[i].str)
    2037       291257 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    2038              :                           {
    2039       145621 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2040              : 
    2041       145621 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    2042       145621 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    2043       145621 :                             types_match = decls_match (newdecl, olddecl);
    2044       145621 :                             if (types_match)
    2045              :                               return duplicate_decls (newdecl, olddecl,
    2046              :                                                       hiding, was_hidden);
    2047            0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    2048              :                           }
    2049           15 :                         goto next_arg;
    2050              :                       }
    2051              : 
    2052       105096 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2053              :                     break;
    2054       105090 :                 next_arg:;
    2055              :                 }
    2056              : 
    2057          201 :               warning_at (newdecl_loc,
    2058          201 :                           OPT_Wbuiltin_declaration_mismatch,
    2059              :                           "declaration of %q#D conflicts with built-in "
    2060              :                           "declaration %q#D", newdecl, olddecl);
    2061              :             }
    2062      1422614 :           else if ((DECL_EXTERN_C_P (newdecl)
    2063           15 :                     && DECL_EXTERN_C_P (olddecl))
    2064      2845213 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2065      1422599 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    2066              :             {
    2067              :               /* Don't really override olddecl for __* prefixed builtins
    2068              :                  except for __[^b]*_chk, the compiler might be using those
    2069              :                  explicitly.  */
    2070           15 :               if (fndecl_built_in_p (olddecl))
    2071              :                 {
    2072           15 :                   tree id = DECL_NAME (olddecl);
    2073           15 :                   const char *name = IDENTIFIER_POINTER (id);
    2074           15 :                   size_t len;
    2075              : 
    2076           15 :                   if (name[0] == '_'
    2077           15 :                       && name[1] == '_'
    2078           30 :                       && (startswith (name + 2, "builtin_")
    2079            6 :                           || (len = strlen (name)) <= strlen ("___chk")
    2080            6 :                           || memcmp (name + len - strlen ("_chk"),
    2081              :                                      "_chk", strlen ("_chk") + 1) != 0))
    2082              :                     {
    2083           15 :                       if (DECL_INITIAL (newdecl))
    2084              :                         {
    2085            6 :                           error_at (newdecl_loc,
    2086              :                                     "definition of %q#D ambiguates built-in "
    2087              :                                     "declaration %q#D", newdecl, olddecl);
    2088            6 :                           return error_mark_node;
    2089              :                         }
    2090            9 :                       auto_diagnostic_group d;
    2091            9 :                       if (permerror (newdecl_loc,
    2092              :                                      "new declaration %q#D ambiguates built-in"
    2093              :                                      " declaration %q#D", newdecl, olddecl)
    2094            9 :                           && flag_permissive)
    2095            3 :                         inform (newdecl_loc,
    2096              :                                 "ignoring the %q#D declaration", newdecl);
    2097            9 :                       return flag_permissive ? olddecl : error_mark_node;
    2098            9 :                     }
    2099              :                 }
    2100              : 
    2101              :               /* A near match; override the builtin.  */
    2102              : 
    2103            0 :               if (TREE_PUBLIC (newdecl))
    2104            0 :                 warning_at (newdecl_loc,
    2105            0 :                             OPT_Wbuiltin_declaration_mismatch,
    2106              :                             "new declaration %q#D ambiguates built-in "
    2107              :                             "declaration %q#D", newdecl, olddecl);
    2108              :               else
    2109            0 :                 warning (OPT_Wshadow,
    2110              :                          fndecl_built_in_p (olddecl)
    2111              :                          ? G_("shadowing built-in function %q#D")
    2112              :                          : G_("shadowing library function %q#D"), olddecl);
    2113              :             }
    2114              :           else
    2115              :             /* Discard the old built-in function.  */
    2116              :             return NULL_TREE;
    2117              : 
    2118              :           /* Replace the old RTL to avoid problems with inlining.  */
    2119          201 :           COPY_DECL_RTL (newdecl, olddecl);
    2120              :         }
    2121              :       else
    2122              :         {
    2123              :           /* Even if the types match, prefer the new declarations type
    2124              :              for built-ins which have not been explicitly declared,
    2125              :              for exception lists, etc...  */
    2126      3960188 :           tree type = TREE_TYPE (newdecl);
    2127      3960188 :           tree attribs = (*targetm.merge_type_attributes)
    2128      3960188 :             (TREE_TYPE (olddecl), type);
    2129              : 
    2130      3960188 :           type = cp_build_type_attribute_variant (type, attribs);
    2131      3960188 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    2132              :         }
    2133              : 
    2134              :       /* If a function is explicitly declared "throw ()", propagate that to
    2135              :          the corresponding builtin.  */
    2136      3960389 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    2137      3791728 :           && was_hidden
    2138      3791685 :           && TREE_NOTHROW (newdecl)
    2139      7486400 :           && !TREE_NOTHROW (olddecl))
    2140              :         {
    2141        27924 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    2142        27924 :           tree tmpdecl = builtin_decl_explicit (fncode);
    2143        27924 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    2144        27924 :             TREE_NOTHROW (tmpdecl)  = 1;
    2145              :         }
    2146              : 
    2147              :       /* Whether or not the builtin can throw exceptions has no
    2148              :          bearing on this declarator.  */
    2149      3960389 :       TREE_NOTHROW (olddecl) = 0;
    2150              : 
    2151      3960389 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    2152              :         {
    2153              :           /* If a builtin function is redeclared as `static', merge
    2154              :              the declarations, but make the original one static.  */
    2155            3 :           DECL_THIS_STATIC (olddecl) = 1;
    2156            3 :           TREE_PUBLIC (olddecl) = 0;
    2157              : 
    2158              :           /* Make the old declaration consistent with the new one so
    2159              :              that all remnants of the builtin-ness of this function
    2160              :              will be banished.  */
    2161            3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2162            3 :           COPY_DECL_RTL (newdecl, olddecl);
    2163              :         }
    2164              :     }
    2165    328395413 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2166              :     {
    2167              :       /* C++ Standard, 3.3, clause 4:
    2168              :          "[Note: a namespace name or a class template name must be unique
    2169              :          in its declarative region (7.3.2, clause 14). ]"  */
    2170     73282440 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    2171     73282413 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    2172              :         /* Namespace conflicts with not namespace.  */;
    2173     35854676 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    2174    109137077 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    2175              :         /* Class template conflicts.  */;
    2176     73282395 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    2177     35854676 :                 && DECL_TEMPLATE_RESULT (olddecl)
    2178     35854676 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    2179    109137065 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    2180     37378944 :                    && DECL_TEMPLATE_RESULT (newdecl)
    2181     37378944 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    2182              :         /* Variable template conflicts.  */;
    2183     73282386 :       else if (concept_definition_p (olddecl)
    2184    146564766 :                || concept_definition_p (newdecl))
    2185              :         /* Concept conflicts.  */;
    2186     73282374 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    2187     35893726 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    2188     73321436 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    2189     37378957 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    2190              :         {
    2191              :           /* One is a function and the other is a template
    2192              :              function.  */
    2193     73233584 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    2194              :             return NULL_TREE;
    2195              : 
    2196              :           /* There can only be one!  */
    2197        57619 :           auto_diagnostic_group d;
    2198        57619 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    2199        57619 :               && check_raw_literal_operator (olddecl))
    2200            3 :             error_at (newdecl_loc,
    2201              :                       "literal operator %q#D conflicts with"
    2202              :                       " raw literal operator", newdecl);
    2203        57616 :           else if (check_raw_literal_operator (newdecl))
    2204            3 :             error_at (newdecl_loc,
    2205              :                       "raw literal operator %q#D conflicts with"
    2206              :                       " literal operator template", newdecl);
    2207              :           else
    2208              :             return NULL_TREE;
    2209              : 
    2210            6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2211            6 :           return error_mark_node;
    2212        57619 :         }
    2213        48790 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    2214              :         /* A structured binding must be unique in its declarative region.  */;
    2215        39215 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2216        48787 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    2217              :         /* One is an implicit typedef, that's ok.  */
    2218              :         return NULL_TREE;
    2219              : 
    2220          153 :       auto_diagnostic_group d;
    2221          153 :       error ("%q#D redeclared as different kind of entity", newdecl);
    2222          153 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2223              : 
    2224          153 :       return error_mark_node;
    2225          153 :     }
    2226    255112973 :   else if (!types_match)
    2227              :     {
    2228    238725472 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    2229              :         /* These are certainly not duplicate declarations; they're
    2230              :            from different scopes.  */
    2231              :         return NULL_TREE;
    2232              : 
    2233    238724828 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2234              :         {
    2235    149769012 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    2236    149769012 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    2237              : 
    2238              :           /* The name of a class template may not be declared to refer to
    2239              :              any other template, class, function, object, namespace, value,
    2240              :              or type in the same scope.  */
    2241    149769012 :           if (TREE_CODE (oldres) == TYPE_DECL
    2242    149767948 :               || TREE_CODE (newres) == TYPE_DECL)
    2243              :             {
    2244              :               /* E.g. cstddef __byte_operand.  Alternatively we could find a
    2245              :                  mergeable definition in lookup_elaborated_type, but we'd still
    2246              :                  need to push it into scope in the current TU.  */
    2247         1067 :               if (mod_redefinable
    2248         2125 :                   && (DECL_IMPLICIT_TYPEDEF_P (oldres)
    2249         1058 :                       == DECL_IMPLICIT_TYPEDEF_P (newres)))
    2250         1052 :                 goto return_old;
    2251              : 
    2252           15 :               auto_diagnostic_group d;
    2253           15 :               error_at (newdecl_loc,
    2254              :                         "conflicting declaration of template %q#D", newdecl);
    2255           15 :               inform (olddecl_loc,
    2256              :                       "previous declaration %q#D", olddecl);
    2257           15 :               return error_mark_node;
    2258           15 :             }
    2259              : 
    2260    149767945 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    2261    149767936 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    2262              :             {
    2263    149767936 :               if (duplicate_function_template_decls (newdecl, olddecl))
    2264            0 :                 return error_mark_node;
    2265              :               return NULL_TREE;
    2266              :             }
    2267              :           return NULL_TREE;
    2268              :         }
    2269     88955816 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2270              :         {
    2271     88955056 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2272              :             {
    2273           57 :               auto_diagnostic_group d;
    2274           57 :               error_at (newdecl_loc,
    2275              :                         "conflicting declaration of C function %q#D",
    2276              :                         newdecl);
    2277           57 :               inform (olddecl_loc,
    2278              :                       "previous declaration %q#D", olddecl);
    2279           57 :               return error_mark_node;
    2280           57 :             }
    2281              :           /* For function versions, params and types match, but they
    2282              :              are not ambiguous.  */
    2283     88954999 :           else if (((!DECL_FUNCTION_VERSIONED (newdecl)
    2284     88946665 :                      && !DECL_FUNCTION_VERSIONED (olddecl))
    2285         8379 :                     || !same_type_p (fndecl_declared_return_type (newdecl),
    2286              :                                      fndecl_declared_return_type (olddecl)))
    2287              :                    /* Let constrained hidden friends coexist for now, we'll
    2288              :                       check satisfaction later.  */
    2289     88946620 :                    && !member_like_constrained_friend_p (newdecl)
    2290     81396819 :                    && !member_like_constrained_friend_p (olddecl)
    2291              :                    // The functions have the same parameter types.
    2292     79655580 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2293     79655580 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2294              :                    // And the same constraints.
    2295     88955068 :                    && equivalently_constrained (newdecl, olddecl))
    2296              :             {
    2297           69 :               auto_diagnostic_group d;
    2298           69 :               error_at (newdecl_loc,
    2299              :                         "ambiguating new declaration of %q#D", newdecl);
    2300           69 :               inform (olddecl_loc,
    2301              :                       "old declaration %q#D", olddecl);
    2302           69 :               return error_mark_node;
    2303           69 :             }
    2304              :           else
    2305              :             return NULL_TREE;
    2306              :         }
    2307          760 :       else if (mod_redefinable
    2308          606 :                && TREE_CODE (newdecl) == TYPE_DECL
    2309         1964 :                && (DECL_IMPLICIT_TYPEDEF_P (newdecl)
    2310          602 :                    == DECL_IMPLICIT_TYPEDEF_P (olddecl)))
    2311              :         /* Can also get here with e.g. typedef class {...} foo.  */
    2312          602 :         goto return_old;
    2313          158 :       else if (mod_redefinable
    2314            4 :                && TREE_CODE (newdecl) == VAR_DECL
    2315            4 :                && undeduced_auto_decl (newdecl)
    2316          162 :                && !undeduced_auto_decl (olddecl))
    2317              :         /* We don't have fndecl_declared_return_type for vars.  */
    2318            4 :         goto return_old;
    2319              :       else
    2320              :         {
    2321          154 :           auto_diagnostic_group d;
    2322          154 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2323          154 :           inform (olddecl_loc,
    2324              :                   "previous declaration as %q#D", olddecl);
    2325          154 :           return error_mark_node;
    2326          154 :         }
    2327              :     }
    2328     16387501 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2329     16387501 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2330              :     {
    2331              :       /* OMP UDRs are never duplicates. */
    2332           33 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2333           33 :       auto_diagnostic_group d;
    2334           33 :       error_at (newdecl_loc,
    2335              :                 "redeclaration of %<pragma omp declare reduction%>");
    2336           33 :       inform (olddecl_loc,
    2337              :               "previous %<pragma omp declare reduction%> declaration");
    2338           33 :       return error_mark_node;
    2339           33 :     }
    2340     16387468 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2341     16387468 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2342          281 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2343          281 :                      || (DECL_TI_TEMPLATE (newdecl)
    2344          281 :                          != DECL_TI_TEMPLATE (olddecl))))
    2345     11654361 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2346       567014 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2347       567014 :                         || (DECL_TI_TEMPLATE (olddecl)
    2348       567014 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2349              :     /* It's OK to have a template specialization and a non-template
    2350              :        with the same type, or to have specializations of two
    2351              :        different templates with the same type.  Note that if one is a
    2352              :        specialization, and the other is an instantiation of the same
    2353              :        template, that we do not exit at this point.  That situation
    2354              :        can occur if we instantiate a template class, and then
    2355              :        specialize one of its methods.  This situation is valid, but
    2356              :        the declarations must be merged in the usual way.  */
    2357              :     return NULL_TREE;
    2358     16387468 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2359     16387468 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2360       649275 :                 && !DECL_USE_TEMPLATE (newdecl))
    2361     11654361 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2362        82542 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2363              :     /* One of the declarations is a template instantiation, and the
    2364              :        other is not a template at all.  That's OK.  */
    2365              :     return NULL_TREE;
    2366     16387468 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2367              :     {
    2368              :       /* In [namespace.alias] we have:
    2369              : 
    2370              :            In a declarative region, a namespace-alias-definition can be
    2371              :            used to redefine a namespace-alias declared in that declarative
    2372              :            region to refer only to the namespace to which it already
    2373              :            refers.
    2374              : 
    2375              :          Therefore, if we encounter a second alias directive for the same
    2376              :          alias, we can just ignore the second directive.  */
    2377           31 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2378           31 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2379           28 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2380           22 :         goto return_old;
    2381              : 
    2382              :       /* Leave it to update_binding to merge or report error.  */
    2383              :       return NULL_TREE;
    2384              :     }
    2385              :   /* Check if the two decls are non-mergeable versioned decls.  */
    2386     16387437 :   else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2387              :            && diagnose_versioned_decls (olddecl, newdecl))
    2388              :     return error_mark_node;
    2389              :   else
    2390              :     {
    2391     16387437 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2392     16387437 :       if (errmsg)
    2393              :         {
    2394          621 :           auto_diagnostic_group d;
    2395          621 :           error_at (newdecl_loc, errmsg, newdecl);
    2396          621 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2397          621 :             inform (olddecl_loc,
    2398          621 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2399              :                     ? G_("%q#D previously defined here")
    2400              :                     : G_("%q#D previously declared here"), olddecl);
    2401          621 :           if (cxx_dialect >= cxx26
    2402          147 :               && DECL_NAME (newdecl)
    2403          147 :               && id_equal (DECL_NAME (newdecl), "_")
    2404          634 :               && !name_independent_decl_p (newdecl))
    2405              :             {
    2406           13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2407            2 :                 inform (newdecl_loc,
    2408              :                         "parameter declaration is not name-independent");
    2409           11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2410              :                 {
    2411            3 :                   if (at_namespace_scope_p ())
    2412            2 :                     inform (newdecl_loc,
    2413              :                             "structured binding at namespace scope is not "
    2414              :                             "name-independent");
    2415            1 :                   else if (TREE_STATIC (newdecl))
    2416            1 :                     inform (newdecl_loc,
    2417              :                             "static structured binding is not "
    2418              :                             "name-independent");
    2419            0 :                   else if (DECL_EXTERNAL (newdecl))
    2420            0 :                     inform (newdecl_loc,
    2421              :                             "extern structured binding is not "
    2422              :                             "name-independent");
    2423              :                 }
    2424            8 :               else if (at_class_scope_p ()
    2425            0 :                        && VAR_P (newdecl)
    2426            8 :                        && TREE_STATIC (newdecl))
    2427            0 :                 inform (newdecl_loc,
    2428              :                         "static data member is not name-independent");
    2429            8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2430            3 :                 inform (newdecl_loc,
    2431              :                         "variable at namespace scope is not name-independent");
    2432            5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2433            3 :                 inform (newdecl_loc,
    2434              :                         "static variable is not name-independent");
    2435            2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2436            0 :                 inform (newdecl_loc,
    2437              :                         "extern variable is not name-independent");
    2438              :             }
    2439          621 :           return error_mark_node;
    2440          621 :         }
    2441     16386816 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2442     11654121 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2443        19877 :                && !prototype_p (TREE_TYPE (olddecl))
    2444     16386816 :                && prototype_p (TREE_TYPE (newdecl)))
    2445              :         {
    2446              :           /* Prototype decl follows defn w/o prototype.  */
    2447            0 :           auto_diagnostic_group d;
    2448            0 :           if (warning_at (newdecl_loc, 0,
    2449              :                           "prototype specified for %q#D", newdecl))
    2450            0 :             inform (olddecl_loc,
    2451              :                     "previous non-prototype definition here");
    2452            0 :         }
    2453     15874702 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2454     28040937 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2455              :         {
    2456              :           /* [dcl.link]
    2457              :              If two declarations of the same function or object
    2458              :              specify different linkage-specifications ..., the program
    2459              :              is ill-formed.... Except for functions with C++ linkage,
    2460              :              a function declaration without a linkage specification
    2461              :              shall not precede the first linkage specification for
    2462              :              that function.  A function can be declared without a
    2463              :              linkage specification after an explicit linkage
    2464              :              specification has been seen; the linkage explicitly
    2465              :              specified in the earlier declaration is not affected by
    2466              :              such a function declaration.
    2467              : 
    2468              :              DR 563 raises the question why the restrictions on
    2469              :              functions should not also apply to objects.  Older
    2470              :              versions of G++ silently ignore the linkage-specification
    2471              :              for this example:
    2472              : 
    2473              :                namespace N {
    2474              :                  extern int i;
    2475              :                  extern "C" int i;
    2476              :                }
    2477              : 
    2478              :              which is clearly wrong.  Therefore, we now treat objects
    2479              :              like functions.  */
    2480         1782 :           if (current_lang_depth () == 0)
    2481              :             {
    2482              :               /* There is no explicit linkage-specification, so we use
    2483              :                  the linkage from the previous declaration.  */
    2484         1770 :               retrofit_lang_decl (newdecl);
    2485         1770 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2486              :             }
    2487              :           else
    2488              :             {
    2489           12 :               auto_diagnostic_group d;
    2490           12 :               error_at (newdecl_loc,
    2491              :                         "conflicting declaration of %q#D with %qL linkage",
    2492           12 :                         newdecl, DECL_LANGUAGE (newdecl));
    2493           12 :               inform (olddecl_loc,
    2494              :                       "previous declaration with %qL linkage",
    2495           12 :                       DECL_LANGUAGE (olddecl));
    2496           12 :             }
    2497              :         }
    2498              : 
    2499     16386816 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2500              :         ;
    2501     15716314 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2502              :         {
    2503              :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2504     13840399 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2505     11004574 :               && (/* grokfndecl passes member function templates too
    2506              :                      as FUNCTION_DECLs.  */
    2507      8347433 :                   DECL_TEMPLATE_INFO (olddecl)
    2508              :                   /* C++11 8.3.6/6.
    2509              :                      Default arguments for a member function of a class
    2510              :                      template shall be specified on the initial declaration
    2511              :                      of the member function within the class template.  */
    2512       702700 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2513              :             {
    2514      7723950 :               if (!mod_redefinable)
    2515      7723064 :                 check_redeclaration_no_default_args (newdecl);
    2516              : 
    2517      7723950 :               if (DECL_TEMPLATE_INFO (olddecl)
    2518      7723950 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2519              :                 {
    2520      2310558 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2521      2310558 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2522      2310558 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2523      2310558 :                   tree old_parms
    2524      2310558 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2525      2310558 :                   merge_default_template_args (new_parms, old_parms, olddecl);
    2526              :                 }
    2527              :             }
    2528              :           else
    2529              :             {
    2530      3280624 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2531      3280624 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2532      3280624 :               int i = 1;
    2533              : 
    2534     11822266 :               for (; t1 && t1 != void_list_node;
    2535      5261018 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2536      5262871 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2537              :                   {
    2538          111 :                     if (!cp_tree_equal (TREE_PURPOSE (t1),
    2539          111 :                                         TREE_PURPOSE (t2)))
    2540              :                       {
    2541           30 :                         auto_diagnostic_group d;
    2542           30 :                         error_at (newdecl_loc,
    2543              :                                   "default argument given for parameter %d "
    2544              :                                   "of %q#D", i, newdecl);
    2545           30 :                         inform (olddecl_loc,
    2546              :                                 "previous specification in %q#D here",
    2547              :                                 olddecl);
    2548           30 :                       }
    2549           81 :                     else if (!mod_redefinable)
    2550              :                       {
    2551           24 :                         auto_diagnostic_group d;
    2552           24 :                         if (permerror (newdecl_loc,
    2553              :                                        "default argument given for parameter "
    2554              :                                        "%d of %q#D", i, newdecl))
    2555           24 :                           inform (olddecl_loc,
    2556              :                                   "previous specification in %q#D here",
    2557              :                                   olddecl);
    2558           24 :                       }
    2559              :                   }
    2560              : 
    2561              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2562              :                  argument expression, that declaration... shall be the only
    2563              :                  declaration of the function or function template in the
    2564              :                  translation unit."  */
    2565      3280624 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2566              :             }
    2567              :         }
    2568              :     }
    2569              : 
    2570              :   /* Do not merge an implicit typedef with an explicit one.  In:
    2571              : 
    2572              :        class A;
    2573              :        ...
    2574              :        typedef class A A __attribute__ ((foo));
    2575              : 
    2576              :      the attribute should apply only to the typedef.  */
    2577     20347205 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2578     20347205 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2579        50380 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2580              :     return NULL_TREE;
    2581              : 
    2582     20313533 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2583              :     return NULL_TREE;
    2584              : 
    2585     20313521 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2586           30 :     return error_mark_node;
    2587              : 
    2588     20313491 :   if (modules_p ()
    2589        74893 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2590     20360133 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2591              :     {
    2592        46642 :       if (!module_may_redeclare (olddecl, newdecl))
    2593           24 :         return error_mark_node;
    2594              : 
    2595        46618 :       if (!hiding)
    2596              :         {
    2597              :           /* The old declaration should match the exportingness of the new
    2598              :              declaration.  But hidden friend declarations just keep the
    2599              :              exportingness of the old declaration; see CWG2588.  */
    2600        41946 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2601        41946 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2602        41822 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2603              :               /* Typedefs are not entities and so are OK to be redeclared
    2604              :                  as exported: see [module.interface]/p6.  */
    2605        42137 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2606              :             {
    2607          179 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2608          179 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2609              :                 {
    2610           15 :                   auto_diagnostic_group d;
    2611           15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2612           15 :                   inform (olddecl_loc,
    2613              :                           "previously declared here without exporting");
    2614           15 :                 }
    2615              :             }
    2616        41767 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2617        10476 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2618              :         }
    2619              :     }
    2620              : 
    2621              :   /* We have committed to returning OLDDECL at this point.  */
    2622              : 
    2623              :   /* If new decl is `static' and an `extern' was seen previously,
    2624              :      warn about it.  */
    2625     20313467 :   warn_extern_redeclared_static (newdecl, olddecl);
    2626              : 
    2627              :   /* True to merge attributes between the declarations, false to
    2628              :      set OLDDECL's attributes to those of NEWDECL (for template
    2629              :      explicit specializations that specify their own attributes
    2630              :      independent of those specified for the primary template).  */
    2631     20313467 :   bool merge_attr;
    2632     40626934 :   merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2633     15614465 :                 || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2634     20880466 :                 || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2635              : 
    2636     20313467 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2637              :     {
    2638     15614465 :       if (merge_attr)
    2639              :         {
    2640     15047732 :           {
    2641     15047732 :             auto_diagnostic_group d;
    2642     15047732 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2643           36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2644              :                       ? G_("previous definition of %qD here")
    2645              :                       : G_("previous declaration of %qD here"), olddecl);
    2646     15047732 :           }
    2647              : 
    2648              :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2649              :              specify the noreturn attribute if any declaration of that function
    2650              :              specifies the noreturn attribute.  */
    2651     15047732 :           tree a;
    2652     15047732 :           if (TREE_THIS_VOLATILE (newdecl)
    2653        98289 :               && !TREE_THIS_VOLATILE (olddecl)
    2654              :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2655           76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2656           54 :               && cxx11_attribute_p (a)
    2657     15047753 :               && get_attribute_namespace (a) == NULL_TREE)
    2658              :             {
    2659            9 :               auto_diagnostic_group d;
    2660            9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2661              :                         "but its first declaration was not", newdecl);
    2662            9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2663            9 :             }
    2664              :         }
    2665              : 
    2666              :       /* Now that functions must hold information normally held
    2667              :          by field decls, there is extra work to do so that
    2668              :          declaration information does not get destroyed during
    2669              :          definition.  */
    2670     15614465 :       if (DECL_VINDEX (olddecl))
    2671       158892 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2672     15614465 :       if (DECL_CONTEXT (olddecl))
    2673     15614465 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2674     15614465 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2675     15614465 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2676     15614465 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2677     15614465 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2678     15614465 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2679     15614465 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2680     15614465 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2681     15614465 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2682     15614465 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2683     15614465 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2684     15614465 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2685      2777291 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2686      5554582 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2687     15614465 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2688              : 
    2689     15614465 :       if (new_defines_function && mod_redefinable
    2690     15614465 :           && DECL_INITIAL (olddecl))
    2691              :         {
    2692         4082 :           if (GNU_INLINE_P (STRIP_TEMPLATE (olddecl))
    2693         2297 :               && !GNU_INLINE_P (STRIP_TEMPLATE (newdecl)))
    2694              :             /* Normal out-of-line redefinition of gnu_inline.  */
    2695              :             mod_redefinable = false;
    2696              :           else
    2697              :             new_defines_function = false;
    2698              :         }
    2699              : 
    2700     15614465 :       check_redecl_contract (newdecl, olddecl);
    2701              : 
    2702              :       /* Optionally warn about more than one declaration for the same
    2703              :          name, but don't warn about a function declaration followed by a
    2704              :          definition.  */
    2705           27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2706           27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2707              :           /* Don't warn about extern decl followed by definition.  */
    2708           27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2709              :           /* Don't warn if at least one is/was hidden.  */
    2710           27 :           && !(hiding || was_hidden)
    2711              :           /* Don't warn about declaration followed by specialization.  */
    2712     15614477 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2713            9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2714              :         {
    2715            6 :           auto_diagnostic_group d;
    2716            6 :           if (warning_at (newdecl_loc,
    2717            6 :                           OPT_Wredundant_decls,
    2718              :                           "redundant redeclaration of %qD in same scope",
    2719              :                           newdecl))
    2720            6 :             inform (olddecl_loc,
    2721              :                     "previous declaration of %qD", olddecl);
    2722            6 :         }
    2723              : 
    2724              :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2725              :          first declaration of the function or, for an explicit specialization
    2726              :          of a function template, the first declaration of that
    2727              :          specialization.  */
    2728     15614465 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2729       649275 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2730              :         {
    2731     15047732 :           if (DECL_DELETED_FN (newdecl)
    2732     15047732 :               && !(mod_redefinable
    2733           22 :                    && DECL_DELETED_FN (olddecl)))
    2734              :             {
    2735           21 :               auto_diagnostic_group d;
    2736           21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2737              :                            "is not first declaration", newdecl))
    2738           21 :                 inform (olddecl_loc,
    2739              :                         "previous declaration of %qD", olddecl);
    2740           21 :             }
    2741     15047732 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2742     15047732 :           if (DECL_DELETED_FN (olddecl)
    2743           28 :               && DECL_INITIAL (olddecl)
    2744     15047738 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2745            3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2746              :         }
    2747              :     }
    2748              : 
    2749              :   /* Deal with C++: must preserve virtual function table size.  */
    2750     20313467 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2751              :     {
    2752        50377 :       tree newtype = TREE_TYPE (newdecl);
    2753        50377 :       tree oldtype = TREE_TYPE (olddecl);
    2754              : 
    2755        50377 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2756       100754 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2757       138669 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2758        46223 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2759              : 
    2760        50377 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2761              :     }
    2762              : 
    2763              :   /* Copy all the DECL_... slots specified in the new decl except for
    2764              :      any that we copy here from the old type.  */
    2765     20313467 :   if (merge_attr)
    2766     19746734 :     DECL_ATTRIBUTES (newdecl)
    2767     39493468 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2768              :   else
    2769       566733 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2770              : 
    2771              :   /* Transfer purviewness and importingness to the old decl.  */
    2772     20313467 :   transfer_defining_module (olddecl, newdecl);
    2773              : 
    2774     20313467 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2775              :     {
    2776      4136511 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2777      4136511 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2778      4136511 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2779              : 
    2780              :       /* The new decl should not already have gathered any
    2781              :          specializations.  */
    2782      4136511 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2783              : 
    2784              :       /* Make sure the contracts are equivalent.  */
    2785      4136511 :       check_redecl_contract (newdecl, olddecl);
    2786              : 
    2787      4136511 :       DECL_ATTRIBUTES (old_result)
    2788      4136511 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2789              : 
    2790      4136511 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2791              :         {
    2792      4135150 :           if (DECL_SOURCE_LOCATION (newdecl)
    2793      4135150 :               != DECL_SOURCE_LOCATION (olddecl))
    2794              :             {
    2795              :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2796              :                  later declarations of a function template.  */
    2797      4112559 :               if (!mod_redefinable)
    2798      4109029 :                 check_redeclaration_no_default_args (newdecl);
    2799              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2800              :                  argument expression, that declaration... shall be the only
    2801              :                  declaration of the function or function template in the
    2802              :                  translation unit."  */
    2803      4112559 :               check_no_redeclaration_friend_default_args
    2804      4112559 :                 (old_result, new_result);
    2805              : 
    2806      4112559 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2807      4112559 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2808      4112559 :               merge_default_template_args (new_parms, old_parms, olddecl);
    2809              :             }
    2810      4135150 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2811      3028070 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2812              : 
    2813      4135150 :           check_default_args (newdecl);
    2814              : 
    2815      8270288 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2816      4135150 :               && DECL_INITIAL (new_result))
    2817              :             {
    2818           24 :               mod_redefinable = false;
    2819           24 :               if (DECL_INITIAL (old_result))
    2820           12 :                 DECL_UNINLINABLE (old_result) = 1;
    2821              :               else
    2822           12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2823           24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2824           72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2825           24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2826           48 :               DECL_INTERFACE_KNOWN (old_result)
    2827           24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2828           24 :               DECL_DECLARED_INLINE_P (old_result)
    2829           24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2830           24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2831           24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2832              :             }
    2833              :           else
    2834              :             {
    2835      4135126 :               DECL_DECLARED_INLINE_P (old_result)
    2836      4135126 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2837      4135126 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2838      4135126 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2839      4135126 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2840              : 
    2841      4135126 :               merge_attribute_bits (new_result, old_result);
    2842              :             }
    2843              :         }
    2844              : 
    2845              :       /* If the new declaration is a definition, update the file and
    2846              :          line information on the declaration, and also make
    2847              :          the old declaration the same definition.  */
    2848      4136511 :       if (DECL_INITIAL (new_result) != NULL_TREE
    2849      4136511 :           && !(DECL_INITIAL (old_result)
    2850              :                && mod_redefinable))
    2851              :         {
    2852      5611744 :           DECL_SOURCE_LOCATION (olddecl)
    2853      5611744 :             = DECL_SOURCE_LOCATION (old_result)
    2854      2805872 :             = DECL_SOURCE_LOCATION (newdecl);
    2855      2805872 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2856      2805872 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2857              :             {
    2858      2805872 :               update_contract_arguments (new_result, old_result);
    2859              : 
    2860      2805872 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2861     10108616 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2862      7302744 :                 DECL_CONTEXT (p) = old_result;
    2863              : 
    2864      5611744 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2865           18 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2866              :             }
    2867              :         }
    2868              : 
    2869              :       /* FIXME we can't goto return_old here without removing newdecl from more
    2870              :          hash tables.  */
    2871              :       return olddecl;
    2872              :     }
    2873              : 
    2874     16176956 :   if (types_match)
    2875              :     {
    2876     16176755 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2877     15614264 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2878              : 
    2879              :       /* Automatically handles default parameters.  */
    2880     16176755 :       tree oldtype = TREE_TYPE (olddecl);
    2881     16176755 :       tree newtype;
    2882              : 
    2883              :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2884              :          at newdecl, which will be ggc_freed.  */
    2885     16176755 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2886              :         {
    2887              :           /* But NEWTYPE might have an attribute, honor that.  */
    2888        50377 :           tree tem = TREE_TYPE (newdecl);
    2889        50377 :           newtype = oldtype;
    2890              : 
    2891        50377 :           if (TYPE_USER_ALIGN (tem))
    2892              :             {
    2893           70 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2894            6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2895           70 :               TYPE_USER_ALIGN (newtype) = true;
    2896              :             }
    2897              : 
    2898              :           /* And remove the new type from the variants list.  */
    2899        50377 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2900              :             {
    2901           24 :               tree remove = TREE_TYPE (newdecl);
    2902           24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2903              :                 {
    2904            9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2905              :                   /* If remove is the main variant, no need to remove that
    2906              :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2907              :                      variants, e.g. created for aligned attribute, might still
    2908              :                      refer to the newdecl TYPE_DECL though, so remove that one
    2909              :                      in that case.  */
    2910            9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2911            6 :                     if (orig != remove)
    2912            6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2913            0 :                            t = TYPE_MAIN_VARIANT (t))
    2914            6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2915              :                           {
    2916           12 :                             TYPE_NEXT_VARIANT (t)
    2917            6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2918            6 :                             break;
    2919              :                           }
    2920              :                 }
    2921              :               else
    2922           15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2923            0 :                      t = TYPE_NEXT_VARIANT (t))
    2924           15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2925              :                     {
    2926           15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2927           15 :                       break;
    2928              :                     }
    2929              :             }
    2930              :         }
    2931     16126378 :       else if (merge_attr)
    2932     15559645 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2933              :       else
    2934       566733 :         newtype = TREE_TYPE (newdecl);
    2935              : 
    2936     16176755 :       if (VAR_P (newdecl))
    2937              :         {
    2938       512114 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2939              :           /* For already initialized vars, TREE_READONLY could have been
    2940              :              cleared in cp_finish_decl, because the var needs runtime
    2941              :              initialization or destruction.  Make sure not to set
    2942              :              TREE_READONLY on it again.  */
    2943       512114 :           if (DECL_INITIALIZED_P (olddecl)
    2944         1958 :               && !DECL_EXTERNAL (olddecl)
    2945       512875 :               && !TREE_READONLY (olddecl))
    2946          167 :             TREE_READONLY (newdecl) = 0;
    2947       512114 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2948      1024228 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2949       512114 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2950       512114 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2951       108266 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2952      1024228 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2953       512114 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2954       512114 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2955       512114 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2956      1024228 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2957       512114 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2958              : 
    2959              :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2960       512114 :           if (DECL_LANG_SPECIFIC (olddecl)
    2961      1020630 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2962              :             {
    2963              :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2964           41 :               retrofit_lang_decl (newdecl);
    2965           41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2966              :             }
    2967              :         }
    2968              : 
    2969              :       /* An explicit specialization of a function template or of a member
    2970              :          function of a class template can be declared transaction_safe
    2971              :          independently of whether the corresponding template entity is declared
    2972              :          transaction_safe. */
    2973         1207 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2974         1072 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2975           78 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2976           54 :           && tx_safe_fn_type_p (newtype)
    2977     16176755 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2978            0 :         newtype = tx_unsafe_fn_variant (newtype);
    2979              : 
    2980     16176755 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2981              : 
    2982     16176755 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2983     15614264 :         check_default_args (newdecl);
    2984              : 
    2985              :       /* Lay the type out, unless already done.  */
    2986     16176755 :       if (! same_type_p (newtype, oldtype)
    2987          370 :           && TREE_TYPE (newdecl) != error_mark_node
    2988     16177125 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2989          287 :         layout_type (TREE_TYPE (newdecl));
    2990              : 
    2991     16176755 :       if ((VAR_P (newdecl)
    2992     15664641 :            || TREE_CODE (newdecl) == PARM_DECL
    2993     15664641 :            || TREE_CODE (newdecl) == RESULT_DECL
    2994     15664641 :            || TREE_CODE (newdecl) == FIELD_DECL
    2995     15664641 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2996     16227132 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2997       395507 :         layout_decl (newdecl, 0);
    2998              : 
    2999              :       /* Merge deprecatedness.  */
    3000     16176755 :       if (TREE_DEPRECATED (newdecl))
    3001        11661 :         TREE_DEPRECATED (olddecl) = 1;
    3002              : 
    3003              :       /* Merge unavailability.  */
    3004     16176755 :       if (TREE_UNAVAILABLE (newdecl))
    3005            3 :         TREE_UNAVAILABLE (olddecl) = 1;
    3006              : 
    3007              :       /* Preserve function specific target and optimization options */
    3008     16176755 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3009              :         {
    3010     15614264 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    3011     15614264 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    3012            0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    3013            0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    3014              : 
    3015     15614264 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    3016     15614264 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    3017           55 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    3018           55 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    3019              : 
    3020     15614264 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    3021     15082847 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    3022              :         }
    3023              :       else
    3024              :         {
    3025              :           /* Merge the const type qualifier.  */
    3026       562491 :           if (TREE_READONLY (newdecl))
    3027       153038 :             TREE_READONLY (olddecl) = 1;
    3028              :           /* Merge the volatile type qualifier.  */
    3029       562491 :           if (TREE_THIS_VOLATILE (newdecl))
    3030            5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    3031              :         }
    3032              : 
    3033              :       /* Merge the initialization information.  */
    3034     16176755 :       if (DECL_INITIAL (olddecl) != NULL_TREE
    3035     16176755 :           && (DECL_INITIAL (newdecl) == NULL_TREE
    3036         2325 :               || mod_redefinable))
    3037              :         {
    3038       190104 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    3039       190104 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    3040       190104 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3041              :             {
    3042        19793 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    3043        19793 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    3044              :             }
    3045              :         }
    3046              : 
    3047     16176755 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3048              :         {
    3049     15614264 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    3050     15614264 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    3051     15614264 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    3052     15614264 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    3053        56982 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    3054     15614264 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    3055     15614264 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    3056     15614264 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    3057     15614264 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    3058              : 
    3059     15614264 :           if (merge_attr)
    3060     15047531 :             merge_attribute_bits (newdecl, olddecl);
    3061              :           else
    3062              :             {
    3063              :               /* Merge the noreturn bit.  */
    3064       566733 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3065       566733 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3066       566733 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3067       566733 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    3068       566733 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    3069              :             }
    3070              :           /* Keep the old RTL.  */
    3071     15614264 :           COPY_DECL_RTL (olddecl, newdecl);
    3072              :         }
    3073       562491 :       else if (VAR_P (newdecl)
    3074       562491 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    3075              :         {
    3076              :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    3077              :              declaration was for an incomplete object and the new
    3078              :              declaration is not since many attributes of the RTL will
    3079              :              change.  */
    3080       512040 :           COPY_DECL_RTL (olddecl, newdecl);
    3081              :         }
    3082              :     }
    3083              :   /* If cannot merge, then use the new type and qualifiers,
    3084              :      and don't preserve the old rtl.  */
    3085              :   else
    3086              :     {
    3087              :       /* Clean out any memory we had of the old declaration.  */
    3088          201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    3089          201 :       if (oldstatic)
    3090            0 :         TREE_VALUE (oldstatic) = error_mark_node;
    3091              : 
    3092          201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    3093          201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3094          201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3095          201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3096          201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    3097              :     }
    3098              : 
    3099              :   /* Merge the storage class information.  */
    3100     16176956 :   merge_weak (newdecl, olddecl);
    3101              : 
    3102     16176956 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    3103     16176956 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3104     16176956 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    3105     16176956 :   if (! DECL_EXTERNAL (olddecl))
    3106        55757 :     DECL_EXTERNAL (newdecl) = 0;
    3107     16176956 :   if (! DECL_COMDAT (olddecl))
    3108      6959010 :     DECL_COMDAT (newdecl) = 0;
    3109              : 
    3110     16176956 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    3111              :     {
    3112           78 :       if (!DECL_LOCAL_DECL_P (olddecl))
    3113              :         /* This can happen if olddecl was brought in from the
    3114              :            enclosing namespace via a using-decl.  The new decl is
    3115              :            then not a block-scope extern at all.  */
    3116            3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    3117              :       else
    3118              :         {
    3119           75 :           retrofit_lang_decl (newdecl);
    3120           75 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    3121           75 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    3122           75 :           if (alias != error_mark_node)
    3123              :             {
    3124           72 :               DECL_ATTRIBUTES (alias)
    3125           72 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    3126           72 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3127           42 :                 merge_attribute_bits (newdecl, alias);
    3128              :             }
    3129              :         }
    3130              :     }
    3131              : 
    3132     16176956 :   new_template_info = NULL_TREE;
    3133     16176956 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    3134              :     {
    3135     16122990 :       bool new_redefines_gnu_inline = false;
    3136              : 
    3137     16122990 :       if (new_defines_function
    3138     16122990 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    3139         1241 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    3140      9407774 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    3141            0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    3142              :                       == FUNCTION_DECL))))
    3143         2482 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    3144              : 
    3145              :       if (!new_redefines_gnu_inline)
    3146              :         {
    3147     16122912 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    3148     16122912 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    3149     16122912 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    3150              :         }
    3151              : 
    3152     16122990 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    3153              :         {
    3154     16122926 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    3155     16122926 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    3156     16122926 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    3157              : 
    3158              :           /* If the OLDDECL is an instantiation and/or specialization,
    3159              :              then the NEWDECL must be too.  But, it may not yet be marked
    3160              :              as such if the caller has created NEWDECL, but has not yet
    3161              :              figured out that it is a redeclaration.  */
    3162     16122926 :           if (!DECL_USE_TEMPLATE (newdecl))
    3163     15473034 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    3164              : 
    3165     16122926 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3166     15555564 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    3167     31111128 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    3168              :         }
    3169              : 
    3170              :       /* Don't really know how much of the language-specific
    3171              :          values we should copy from old to new.  */
    3172     16122990 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    3173              : 
    3174     16122990 :       if (LANG_DECL_HAS_MIN (newdecl))
    3175              :         {
    3176     16122990 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    3177     16122990 :           if (DECL_TEMPLATE_INFO (newdecl))
    3178              :             {
    3179       649925 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    3180       649925 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3181       649925 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3182              :                 /* Remember the presence of explicit specialization args.  */
    3183      1133472 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    3184      1133472 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    3185              :             }
    3186              : 
    3187              :           /* We don't want to copy template info from a non-templated friend
    3188              :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    3189     16122990 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    3190              :                                || !non_templated_friend_p (olddecl));
    3191     16122990 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    3192              :         }
    3193              : 
    3194     16122990 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    3195              :         {
    3196              :           /* Only functions have these fields.  */
    3197     15614465 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    3198     15614465 :           DECL_BEFRIENDING_CLASSES (newdecl)
    3199     15614465 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    3200     15614465 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    3201              :           /* DECL_THUNKS is only valid for virtual functions,
    3202              :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    3203     15614465 :           if (DECL_VIRTUAL_P (newdecl))
    3204       633120 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    3205     29962690 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    3206       382439 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    3207              :         }
    3208       508525 :       else if (VAR_P (newdecl))
    3209              :         {
    3210              :           /* Only variables have this field.  */
    3211       508461 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    3212          198 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    3213              :         }
    3214              :     }
    3215              : 
    3216     16176956 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3217              :     {
    3218     15614465 :       merge_decl_arguments (newdecl, olddecl, new_defines_function,
    3219              :                             types_match, false);
    3220              : 
    3221     15614465 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3222     15614465 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    3223              :         {
    3224              :           /* If newdecl is not a specialization, then it is not a
    3225              :              template-related function at all.  And that means that we
    3226              :              should have exited above, returning 0.  */
    3227       566733 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    3228              : 
    3229       566733 :           if (DECL_ODR_USED (olddecl))
    3230              :             /* From [temp.expl.spec]:
    3231              : 
    3232              :                If a template, a member template or the member of a class
    3233              :                template is explicitly specialized then that
    3234              :                specialization shall be declared before the first use of
    3235              :                that specialization that would cause an implicit
    3236              :                instantiation to take place, in every translation unit in
    3237              :                which such a use occurs.  */
    3238            0 :             error ("explicit specialization of %qD after first use",
    3239              :                       olddecl);
    3240              : 
    3241       566733 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    3242       566733 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    3243      1133313 :                                    && DECL_NONGNU_INLINE_P (newdecl));
    3244              : 
    3245              :           /* Don't propagate visibility from the template to the
    3246              :              specialization here.  We'll do that in determine_visibility if
    3247              :              appropriate.  */
    3248       566733 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    3249              : 
    3250              :           /* [temp.expl.spec/14] We don't inline explicit specialization
    3251              :              just because the primary template says so.  */
    3252       566733 :           gcc_assert (!merge_attr);
    3253              : 
    3254       566733 :           DECL_DECLARED_INLINE_P (olddecl)
    3255       566733 :             = DECL_DECLARED_INLINE_P (newdecl);
    3256              : 
    3257       566733 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3258       566733 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    3259              : 
    3260       566733 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    3261              :         }
    3262     15047732 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    3263              :         {
    3264              :           /* Never inline re-defined extern inline functions.
    3265              :              FIXME: this could be better handled by keeping both
    3266              :              function as separate declarations.  */
    3267           78 :           DECL_UNINLINABLE (newdecl) = 1;
    3268              :         }
    3269              :       else
    3270              :         {
    3271     15047654 :           if (DECL_PENDING_INLINE_P (olddecl))
    3272              :             {
    3273            6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    3274            6 :               DECL_PENDING_INLINE_INFO (newdecl)
    3275           12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    3276              :             }
    3277     15047648 :           else if (DECL_PENDING_INLINE_P (newdecl))
    3278              :             ;
    3279     15047648 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    3280     15047648 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    3281     30095296 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    3282              : 
    3283     15047654 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    3284              : 
    3285     45142962 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3286     30095308 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3287              : 
    3288     30095308 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3289     15047654 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3290     15047654 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3291     29618030 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3292              :         }
    3293              : 
    3294              :       /* Preserve abstractness on cloned [cd]tors.  */
    3295     15614465 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3296              : 
    3297              :       /* Update newdecl's parms to point at olddecl.  */
    3298     49646371 :       for (tree parm = DECL_ARGUMENTS (newdecl); parm;
    3299     34031906 :            parm = DECL_CHAIN (parm))
    3300     34031906 :         DECL_CONTEXT (parm) = olddecl;
    3301              : 
    3302     15614465 :       if (! types_match)
    3303              :         {
    3304          201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3305          201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3306          201 :           COPY_DECL_RTL (newdecl, olddecl);
    3307              :         }
    3308     15614465 :       if (! types_match || new_defines_function)
    3309              :         {
    3310              :           /* Update the contracts to reflect the new parameter names. */
    3311      9409216 :           update_contract_arguments (newdecl, olddecl);
    3312              : 
    3313              :           /* Mark the old PARM_DECLs in case std::meta::parameters_of has
    3314              :              been called on the old declaration and reflections of those
    3315              :              arguments are held across this point and used later.
    3316              :              Such PARM_DECLs are no longer present in
    3317              :              DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain.  */
    3318      9409216 :           for (tree oldarg = DECL_ARGUMENTS (olddecl);
    3319     32989309 :                oldarg; oldarg = DECL_CHAIN (oldarg))
    3320     23580093 :             OLD_PARM_DECL_P (oldarg) = 1;
    3321              : 
    3322              :           /* These need to be copied so that the names are available.
    3323              :              Note that if the types do match, we'll preserve inline
    3324              :              info and other bits, but if not, we won't.  */
    3325      9409216 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3326      9409216 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3327              :         }
    3328              :       /* If redeclaring a builtin function, it stays built in
    3329              :          if newdecl is a gnu_inline definition, or if newdecl is just
    3330              :          a declaration.  */
    3331     15614465 :       if (fndecl_built_in_p (olddecl)
    3332     15671213 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3333              :         {
    3334      4045792 :           copy_decl_built_in_function (newdecl, olddecl);
    3335              :           /* If we're keeping the built-in definition, keep the rtl,
    3336              :              regardless of declaration matches.  */
    3337      4045792 :           COPY_DECL_RTL (olddecl, newdecl);
    3338      4045792 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3339              :             {
    3340      4045786 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3341      4045786 :               if (builtin_decl_explicit_p (fncode))
    3342              :                 {
    3343              :                   /* A compatible prototype of these builtin functions
    3344              :                      is seen, assume the runtime implements it with
    3345              :                      the expected semantics.  */
    3346      4045786 :                   switch (fncode)
    3347              :                     {
    3348        10059 :                     case BUILT_IN_STPCPY:
    3349        10059 :                       set_builtin_decl_implicit_p (fncode, true);
    3350        10059 :                       break;
    3351      4035727 :                     default:
    3352      4035727 :                       set_builtin_decl_declared_p (fncode, true);
    3353      4035727 :                       break;
    3354              :                     }
    3355              :                 }
    3356              : 
    3357      4045786 :               copy_attributes_to_builtin (newdecl);
    3358              :             }
    3359              :         }
    3360     15614465 :       if (new_defines_function)
    3361              :         /* If defining a function declared with other language
    3362              :            linkage, use the previously declared language linkage.  */
    3363      9409015 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3364      6205450 :       else if (types_match)
    3365              :         {
    3366      6205249 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3367              :           /* Don't clear out the arguments if we're just redeclaring a
    3368              :              function.  */
    3369      6205249 :           if (DECL_ARGUMENTS (olddecl))
    3370      2122347 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3371              :         }
    3372              :     }
    3373       562491 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3374            0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3375              : 
    3376              :   /* Now preserve various other info from the definition.  */
    3377     16176956 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3378     16176956 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3379     16176956 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3380     16176956 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3381              : 
    3382              :   /* Warn about conflicting visibility specifications.  */
    3383     16176956 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3384      5635099 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3385     16188770 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3386              :     {
    3387           12 :       auto_diagnostic_group d;
    3388           12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3389              :                       "%qD: visibility attribute ignored because it "
    3390              :                       "conflicts with previous declaration", newdecl))
    3391           12 :         inform (olddecl_loc,
    3392              :                 "previous declaration of %qD", olddecl);
    3393           12 :     }
    3394              :   /* Choose the declaration which specified visibility.  */
    3395     16176956 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3396              :     {
    3397      5635099 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3398      5635099 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3399              :     }
    3400              :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3401              :      so keep this behavior.  */
    3402     16176956 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3403              :     {
    3404           10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3405           10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3406              :     }
    3407              :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3408     16176956 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3409              :     {
    3410           54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3411           54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3412              :     }
    3413     16176902 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3414     16176902 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3415            3 :     DECL_USER_ALIGN (newdecl) = 1;
    3416              : 
    3417     16176956 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3418     32353912 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3419     16176956 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3420            0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3421              :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3422     16176956 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3423            0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3424              : 
    3425              :   /* Merge module entity mapping information.  */
    3426     16176956 :   if (DECL_LANG_SPECIFIC (olddecl)
    3427     32300397 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3428     16118860 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3429              :     {
    3430         4581 :       retrofit_lang_decl (newdecl);
    3431         4581 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3432         4581 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3433              :     }
    3434              : 
    3435              :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3436              :      with that from NEWDECL below.  */
    3437     16176956 :   if (DECL_LANG_SPECIFIC (olddecl))
    3438              :     {
    3439     16123441 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3440              :                            != DECL_LANG_SPECIFIC (newdecl));
    3441     16123441 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3442              :     }
    3443              : 
    3444              :   /* Merge the USED information.  */
    3445     16176956 :   if (TREE_USED (olddecl))
    3446       507117 :     TREE_USED (newdecl) = 1;
    3447     15669839 :   else if (TREE_USED (newdecl))
    3448           62 :     TREE_USED (olddecl) = 1;
    3449              : 
    3450     16176956 :   if (VAR_P (newdecl))
    3451              :     {
    3452       512114 :       if (DECL_READ_P (olddecl))
    3453        43860 :         DECL_READ_P (newdecl) = 1;
    3454       468254 :       else if (DECL_READ_P (newdecl))
    3455            3 :         DECL_READ_P (olddecl) = 1;
    3456              :     }
    3457              : 
    3458     16176956 :   if (DECL_PRESERVE_P (olddecl))
    3459           48 :     DECL_PRESERVE_P (newdecl) = 1;
    3460     16176908 :   else if (DECL_PRESERVE_P (newdecl))
    3461           75 :     DECL_PRESERVE_P (olddecl) = 1;
    3462              : 
    3463              :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3464              :      to olddecl and deleted.  */
    3465     16176956 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3466     31791421 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3467              :     {
    3468              :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3469          258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3470              :       /* newdecl will be purged after copying to olddecl and is no longer
    3471              :          a version.  */
    3472          258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3473              :     }
    3474              : 
    3475     16176956 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3476              :     {
    3477     15614465 :       int function_size;
    3478     15614465 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3479              : 
    3480     15614465 :       function_size = sizeof (struct tree_decl_common);
    3481              : 
    3482     15614465 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3483              :               (char *) newdecl + sizeof (struct tree_common),
    3484              :               function_size - sizeof (struct tree_common));
    3485              : 
    3486     15614465 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3487              :               (char *) newdecl + sizeof (struct tree_decl_common),
    3488              :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3489              : 
    3490              :       /* Preserve symtab node mapping.  */
    3491     15614465 :       olddecl->decl_with_vis.symtab_node = snode;
    3492              : 
    3493     15614465 :       if (new_template_info)
    3494              :         /* If newdecl is a template instantiation, it is possible that
    3495              :            the following sequence of events has occurred:
    3496              : 
    3497              :            o A friend function was declared in a class template.  The
    3498              :            class template was instantiated.
    3499              : 
    3500              :            o The instantiation of the friend declaration was
    3501              :            recorded on the instantiation list, and is newdecl.
    3502              : 
    3503              :            o Later, however, instantiate_class_template called pushdecl
    3504              :            on the newdecl to perform name injection.  But, pushdecl in
    3505              :            turn called duplicate_decls when it discovered that another
    3506              :            declaration of a global function with the same name already
    3507              :            existed.
    3508              : 
    3509              :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3510              : 
    3511              :            If we're going to do that, we'd better make sure that
    3512              :            olddecl, and not newdecl, is on the list of
    3513              :            instantiations so that if we try to do the instantiation
    3514              :            again we won't get the clobbered declaration.  */
    3515       649574 :         reregister_specialization (newdecl,
    3516              :                                    new_template_info,
    3517              :                                    olddecl);
    3518              :     }
    3519              :   else
    3520              :     {
    3521       562491 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3522              : 
    3523       562491 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3524              :               (char *) newdecl + sizeof (struct tree_common),
    3525              :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3526              : 
    3527       562491 :       switch (TREE_CODE (newdecl))
    3528              :         {
    3529       562491 :         case LABEL_DECL:
    3530       562491 :         case VAR_DECL:
    3531       562491 :         case RESULT_DECL:
    3532       562491 :         case PARM_DECL:
    3533       562491 :         case FIELD_DECL:
    3534       562491 :         case TYPE_DECL:
    3535       562491 :         case CONST_DECL:
    3536       562491 :           {
    3537       562491 :             struct symtab_node *snode = NULL;
    3538              : 
    3539       562491 :             if (VAR_P (newdecl)
    3540       562491 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3541            3 :                     || DECL_EXTERNAL (olddecl)))
    3542       512114 :               snode = symtab_node::get (olddecl);
    3543       562491 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3544              :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3545              :                     size - sizeof (struct tree_decl_common)
    3546       562491 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3547       562491 :             if (VAR_P (newdecl))
    3548       512114 :               olddecl->decl_with_vis.symtab_node = snode;
    3549              :           }
    3550              :           break;
    3551            0 :         default:
    3552            0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3553              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3554              :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3555            0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3556            0 :           break;
    3557              :         }
    3558              :     }
    3559              : 
    3560     16176956 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3561              :     {
    3562     16126579 :       if (DECL_EXTERNAL (olddecl)
    3563       513492 :           || TREE_PUBLIC (olddecl)
    3564     16126649 :           || TREE_STATIC (olddecl))
    3565              :         {
    3566              :           /* Merge the section attribute.
    3567              :              We want to issue an error if the sections conflict but that must be
    3568              :              done later in decl_attributes since we are called before attributes
    3569              :              are assigned.  */
    3570     16126579 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3571            7 :             set_decl_section_name (olddecl, newdecl);
    3572              : 
    3573     16126579 :           if (DECL_ONE_ONLY (newdecl))
    3574              :             {
    3575            0 :               struct symtab_node *oldsym, *newsym;
    3576            0 :               oldsym = symtab_node::get_create (olddecl);
    3577            0 :               newsym = symtab_node::get (newdecl);
    3578            0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3579              :             }
    3580              :         }
    3581              : 
    3582     16126579 :       if (VAR_P (newdecl)
    3583     16126579 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3584              :         {
    3585          418 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3586          418 :           if (!processing_template_decl)
    3587          385 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3588              :         }
    3589              :     }
    3590              : 
    3591     16176956 :   DECL_UID (olddecl) = olddecl_uid;
    3592              : 
    3593              :   /* NEWDECL contains the merged attribute lists.
    3594              :      Update OLDDECL to be the same.  */
    3595     16176956 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3596              : 
    3597              :   /* NEWDECL's TLS model was chosen for NEWDECL alone, which may not have
    3598              :      been weak until merge_weak.  */
    3599     16176956 :   if (VAR_P (olddecl)
    3600       512114 :       && CP_DECL_THREAD_LOCAL_P (olddecl)
    3601          459 :       && DECL_WEAK (olddecl)
    3602     16176968 :       && !processing_template_decl)
    3603           12 :     weak_decl_tls_model (olddecl);
    3604              : 
    3605              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3606              :     so that encode_section_info has a chance to look at the new decl
    3607              :     flags and attributes.  */
    3608     16176956 :   if (DECL_RTL_SET_P (olddecl)
    3609     16176971 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3610           15 :           || (VAR_P (olddecl)
    3611           15 :               && TREE_STATIC (olddecl))))
    3612           15 :     make_decl_rtl (olddecl);
    3613              : 
    3614              :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3615              :      declaration of a member results in a call to duplicate_decls,
    3616              :      freeing these nodes represents in a significant savings.
    3617              : 
    3618              :      Before releasing the node, be sore to remove function from symbol
    3619              :      table that might have been inserted there to record comdat group.
    3620              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3621              :      structure is shared in between newdecl and oldecl.  */
    3622     16176956 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3623     15614465 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3624     16176956 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3625              :     {
    3626     16126579 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3627     16126579 :       if (snode)
    3628          413 :         snode->remove ();
    3629              :     }
    3630              : 
    3631     16176956 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3632              :     {
    3633     15614465 :       tree clone;
    3634     16156486 :       FOR_EACH_CLONE (clone, olddecl)
    3635              :         {
    3636       542021 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3637       542021 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3638              :         }
    3639              :     }
    3640              : 
    3641       562491 :  return_old:
    3642              :   /* Remove the associated constraints for newdecl, if any, before
    3643              :      reclaiming memory. */
    3644     16178636 :   if (flag_concepts)
    3645     15913306 :     remove_constraints (newdecl);
    3646              : 
    3647     16178636 :   if (flag_contracts)
    3648              :     /* Remove the specifiers, and then remove the decl from the lookup.  */
    3649      1565552 :     remove_decl_with_fn_contracts_specifiers (newdecl);
    3650              : 
    3651              :   /* And similarly for any module tracking data.  */
    3652     16178636 :   if (modules_p ())
    3653        53017 :     remove_defining_module (newdecl);
    3654              : 
    3655     16178636 :   ggc_free (newdecl);
    3656              : 
    3657     16178636 :   return olddecl;
    3658              : }
    3659              : 
    3660              : /* Return zero if the declaration NEWDECL is valid
    3661              :    when the declaration OLDDECL (assumed to be for the same name)
    3662              :    has already been seen.
    3663              :    Otherwise return an error message format string with a %s
    3664              :    where the identifier should go.  */
    3665              : 
    3666              : static const char *
    3667     16387437 : redeclaration_error_message (tree newdecl, tree olddecl)
    3668              : {
    3669     16387940 :   if (redefinable_import_p (olddecl))
    3670              :     return NULL;
    3671              : 
    3672     16379504 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3673              :     {
    3674              :       /* Because C++ can put things into name space for free,
    3675              :          constructs like "typedef struct foo { ... } foo"
    3676              :          would look like an erroneous redeclaration.  */
    3677        84552 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3678              :         return NULL;
    3679              :       else
    3680            0 :         return G_("redefinition of %q#D");
    3681              :     }
    3682     16294952 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3683              :     {
    3684              :       /* If this is a pure function, its olddecl will actually be
    3685              :          the original initialization to `0' (which we force to call
    3686              :          abort()).  Don't complain about redefinition in this case.  */
    3687     23302318 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3688     11651177 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3689              :         return NULL;
    3690              : 
    3691              :       /* If both functions come from different namespaces, this is not
    3692              :          a redeclaration - this is a conflict with a used function.  */
    3693     23302288 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3694      2844940 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3695     11651147 :           && ! decls_match (olddecl, newdecl))
    3696              :         return G_("%qD conflicts with used function");
    3697              : 
    3698              :       /* We'll complain about linkage mismatches in
    3699              :          warn_extern_redeclared_static.  */
    3700              : 
    3701              :       /* Defining the same name twice is no good.  */
    3702     11651144 :       if (decl_defined_p (olddecl)
    3703     11651144 :           && decl_defined_p (newdecl))
    3704              :         {
    3705          303 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3706              :             return G_("%q#D not declared in class");
    3707          441 :           else if (!GNU_INLINE_P (olddecl)
    3708          387 :                    || GNU_INLINE_P (newdecl))
    3709              :             return G_("redefinition of %q#D");
    3710              :         }
    3711              : 
    3712     13513210 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3713              :         {
    3714      1810857 :           bool olda = GNU_INLINE_P (olddecl);
    3715      1810857 :           bool newa = GNU_INLINE_P (newdecl);
    3716              : 
    3717      1810857 :           if (olda != newa)
    3718              :             {
    3719           15 :               if (newa)
    3720              :                 return G_("%q+D redeclared inline with "
    3721              :                           "%<gnu_inline%> attribute");
    3722              :               else
    3723            9 :                 return G_("%q+D redeclared inline without "
    3724              :                           "%<gnu_inline%> attribute");
    3725              :             }
    3726              :         }
    3727              : 
    3728              :       /* [class.compare.default]: A definition of a comparison operator as
    3729              :          defaulted that appears in a class shall be the first declaration of
    3730              :          that function.  */
    3731     11650907 :       special_function_kind sfk = special_function_p (olddecl);
    3732     11650907 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3733              :         return G_("comparison operator %q+D defaulted after "
    3734              :                   "its first declaration");
    3735              : 
    3736     11650904 :       check_abi_tag_redeclaration
    3737     11650904 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3738     11650904 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3739              : 
    3740     11650904 :       return NULL;
    3741              :     }
    3742      4643793 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3743              :     {
    3744      4132153 :       tree nt, ot;
    3745              : 
    3746      4132153 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3747              :         return G_("redefinition of %q#D");
    3748              : 
    3749      4132147 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3750          503 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3751          503 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3752              : 
    3753      4131644 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3754              :         return NULL;
    3755              : 
    3756      4131632 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3757      4131632 :       if (DECL_TEMPLATE_INFO (nt))
    3758       993032 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3759      4131632 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3760      4131632 :       if (DECL_TEMPLATE_INFO (ot))
    3761      4131632 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3762      6937234 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3763      4131671 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3764              :         return G_("redefinition of %q#D");
    3765              : 
    3766      6710370 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3767              :         {
    3768      1879720 :           bool olda = GNU_INLINE_P (ot);
    3769      1879720 :           bool newa = GNU_INLINE_P (nt);
    3770              : 
    3771      1879720 :           if (olda != newa)
    3772              :             {
    3773            0 :               if (newa)
    3774              :                 return G_("%q+D redeclared inline with "
    3775              :                           "%<gnu_inline%> attribute");
    3776              :               else
    3777            0 :                 return G_("%q+D redeclared inline without "
    3778              :                           "%<gnu_inline%> attribute");
    3779              :             }
    3780              :         }
    3781              : 
    3782              :       /* Core issue #226 (C++11):
    3783              : 
    3784              :            If a friend function template declaration specifies a
    3785              :            default template-argument, that declaration shall be a
    3786              :            definition and shall be the only declaration of the
    3787              :            function template in the translation unit.  */
    3788      4131617 :       if ((cxx_dialect != cxx98)
    3789      4115803 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3790      4340553 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3791              :                                        /*is_primary=*/true,
    3792              :                                        /*is_partial=*/false,
    3793              :                                        /*is_friend_decl=*/2))
    3794            3 :         return G_("redeclaration of friend %q#D "
    3795              :                   "may not have default template arguments");
    3796              : 
    3797              :       return NULL;
    3798              :     }
    3799       511640 :   else if (VAR_P (newdecl)
    3800       511556 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3801       511556 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3802       511687 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3803           44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3804           41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3805              :     {
    3806              :       /* Only variables can be thread-local, and all declarations must
    3807              :          agree on this property.  */
    3808            6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3809              :         return G_("thread-local declaration of %q#D follows "
    3810              :                   "non-thread-local declaration");
    3811              :       else
    3812            3 :         return G_("non-thread-local declaration of %q#D follows "
    3813              :                   "thread-local declaration");
    3814              :     }
    3815       511634 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3816              :     {
    3817              :       /* The objects have been declared at namespace scope.  If either
    3818              :          is a member of an anonymous union, then this is an invalid
    3819              :          redeclaration.  For example:
    3820              : 
    3821              :            int i;
    3822              :            union { int i; };
    3823              : 
    3824              :            is invalid.  */
    3825       511400 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3826      1022869 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3827              :         return G_("redeclaration of %q#D");
    3828              :       /* If at least one declaration is a reference, there is no
    3829              :          conflict.  For example:
    3830              : 
    3831              :            int i = 3;
    3832              :            extern int i;
    3833              : 
    3834              :          is valid.  */
    3835       511466 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3836              :         return NULL;
    3837              : 
    3838              :       /* Static data member declared outside a class definition
    3839              :          if the variable is defined within the class with constexpr
    3840              :          specifier is declaration rather than definition (and
    3841              :          deprecated).  */
    3842         2827 :       if (cxx_dialect >= cxx17
    3843         2754 :           && VAR_P (olddecl)
    3844         2698 :           && DECL_CLASS_SCOPE_P (olddecl)
    3845         2656 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3846         5471 :           && !DECL_INITIAL (newdecl))
    3847              :         {
    3848         2644 :           DECL_EXTERNAL (newdecl) = 1;
    3849              :           /* For now, only warn with explicit -Wdeprecated.  */
    3850         2644 :           if (OPTION_SET_P (warn_deprecated))
    3851              :             {
    3852           40 :               auto_diagnostic_group d;
    3853           40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3854              :                                 "redundant redeclaration of %<constexpr%> "
    3855              :                                 "static data member %qD", newdecl))
    3856            4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3857              :                           "previous declaration of %qD", olddecl);
    3858           40 :             }
    3859              :           return NULL;
    3860              :         }
    3861              : 
    3862              :       /* Reject two definitions.  */
    3863              :       return G_("redefinition of %q#D");
    3864              :     }
    3865              :   else
    3866              :     {
    3867              :       /* Objects declared with block scope:  */
    3868              :       /* Reject two definitions, and reject a definition
    3869              :          together with an external reference.  */
    3870          153 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3871          153 :         return G_("redeclaration of %q#D");
    3872              :       return NULL;
    3873              :     }
    3874              : }
    3875              : 
    3876              : 
    3877              : /* Hash and equality functions for the named_label table.  */
    3878              : 
    3879              : hashval_t
    3880        80147 : named_label_hash::hash (const value_type entry)
    3881              : {
    3882        80147 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3883              : }
    3884              : 
    3885              : bool
    3886        77057 : named_label_hash::equal (const value_type entry, compare_type name)
    3887              : {
    3888        77057 :   return name == entry->name;
    3889              : }
    3890              : 
    3891              : /* Look for a label named ID in the current function.  If one cannot
    3892              :    be found, create one.  Return the named_label_entry, or NULL on
    3893              :    failure.  */
    3894              : 
    3895              : static named_label_entry *
    3896        24671 : lookup_label_1 (tree id, bool making_local_p)
    3897              : {
    3898        24671 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3899              : 
    3900              :   /* You can't use labels at global scope.  */
    3901        24671 :   if (current_function_decl == NULL_TREE)
    3902              :     {
    3903            3 :       error ("label %qE referenced outside of any function", id);
    3904            3 :       return NULL;
    3905              :     }
    3906              : 
    3907        24668 :   if (!named_labels)
    3908         4765 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3909              : 
    3910        24668 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3911        24668 :   named_label_entry **slot
    3912        24668 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3913        24668 :   named_label_entry *old = *slot;
    3914              : 
    3915        24668 :   if (old && old->label_decl)
    3916              :     {
    3917         3524 :       if (!making_local_p)
    3918              :         return old;
    3919              : 
    3920           21 :       if (old->binding_level == current_binding_level)
    3921              :         {
    3922            0 :           auto_diagnostic_group d;
    3923            0 :           error ("local label %qE conflicts with existing label", id);
    3924            0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3925            0 :           return NULL;
    3926            0 :         }
    3927              :     }
    3928              : 
    3929              :   /* We are making a new decl, create or reuse the named_label_entry  */
    3930        21186 :   named_label_entry *ent = NULL;
    3931           33 :   if (old && !old->label_decl)
    3932              :     ent = old;
    3933              :   else
    3934              :     {
    3935        21153 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3936        21153 :       ent->name = id;
    3937        21153 :       ent->outer = old;
    3938        21153 :       *slot = ent;
    3939              :     }
    3940              : 
    3941              :   /* Now create the LABEL_DECL.  */
    3942        21165 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3943              : 
    3944        21165 :   DECL_CONTEXT (decl) = current_function_decl;
    3945        21165 :   SET_DECL_MODE (decl, VOIDmode);
    3946        21165 :   if (making_local_p)
    3947              :     {
    3948          219 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3949          219 :       DECL_CHAIN (decl) = current_binding_level->names;
    3950          219 :       current_binding_level->names = decl;
    3951              :     }
    3952              : 
    3953        21165 :   ent->label_decl = decl;
    3954              : 
    3955        21165 :   return ent;
    3956        24671 : }
    3957              : 
    3958              : /* Wrapper for lookup_label_1.  */
    3959              : 
    3960              : tree
    3961         3009 : lookup_label (tree id)
    3962              : {
    3963         3009 :   named_label_entry *ent = lookup_label_1 (id, false);
    3964         3009 :   return ent ? ent->label_decl : NULL_TREE;
    3965              : }
    3966              : 
    3967              : /* Remember that we've seen &&ID.  */
    3968              : 
    3969              : void
    3970          262 : mark_label_addressed (tree id)
    3971              : {
    3972          262 :   named_label_entry *ent = lookup_label_1 (id, false);
    3973          262 :   ent->addressed = true;
    3974          262 : }
    3975              : 
    3976              : tree
    3977          219 : declare_local_label (tree id)
    3978              : {
    3979          219 :   named_label_entry *ent = lookup_label_1 (id, true);
    3980          219 :   return ent ? ent->label_decl : NULL_TREE;
    3981              : }
    3982              : 
    3983              : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3984              : 
    3985              : static bool
    3986      2994752 : decl_jump_unsafe (tree decl)
    3987              : {
    3988              :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3989              :      with automatic storage duration is not in scope to a point where it is
    3990              :      in scope is ill-formed unless the variable has scalar type, class type
    3991              :      with a trivial default constructor and a trivial destructor, a
    3992              :      cv-qualified version of one of these types, or an array of one of the
    3993              :      preceding types and is declared without an initializer (8.5).  */
    3994      2994752 :   tree type = TREE_TYPE (decl);
    3995              : 
    3996      2994752 :   return (type != error_mark_node
    3997      2994734 :           && VAR_P (decl)
    3998        15102 :           && !TREE_STATIC (decl)
    3999      3009718 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    4000        13012 :               || variably_modified_type_p (type, NULL_TREE)));
    4001              : }
    4002              : 
    4003              : /* Returns true if decl is an automatic variable with vacuous initialization
    4004              :    except when it is [[indeterminate]] or [[gnu::uninitialized]].
    4005              :    Jumps across such initialization need to be instrumented for
    4006              :    !!flag_auto_var_init.  */
    4007              : 
    4008              : static bool
    4009      2992789 : decl_instrument_init_bypass_p (tree decl)
    4010              : {
    4011      2992789 :   tree type = TREE_TYPE (decl);
    4012              : 
    4013      2992789 :   return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4014      2230561 :           && !processing_template_decl
    4015      2230315 :           && type != error_mark_node
    4016      2230309 :           && VAR_P (decl)
    4017         1078 :           && !TREE_STATIC (decl)
    4018         1057 :           && !DECL_EXTERNAL (decl)
    4019         2086 :           && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    4020         1043 :                || variably_modified_type_p (type, NULL_TREE))
    4021         1043 :           && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
    4022         1043 :           && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
    4023      2993832 :           && !DECL_HAS_VALUE_EXPR_P (decl));
    4024              : }
    4025              : 
    4026              : /* Build .DEFERRED_INIT call for DECL.  */
    4027              : 
    4028              : static tree
    4029          142 : build_deferred_init_call (tree decl)
    4030              : {
    4031          142 :   tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    4032          284 :   tree init_type_arg = build_int_cst (integer_type_node,
    4033          142 :                                       (int) flag_auto_var_init);
    4034          142 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    4035          142 :   tree decl_name;
    4036              : 
    4037          142 :   if (DECL_NAME (decl))
    4038          142 :     decl_name = build_string_literal (DECL_NAME (decl));
    4039              :   else
    4040              :     {
    4041            0 :       char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
    4042            0 :       sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
    4043            0 :       decl_name = build_string_literal (decl_name_anonymous);
    4044              :     }
    4045              : 
    4046          142 :   tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
    4047          142 :                                             TREE_TYPE (decl), 3,
    4048              :                                             decl_size_arg, init_type_arg,
    4049              :                                             decl_name);
    4050          142 :   tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
    4051          142 :   return build_stmt (loc, EXPR_STMT, ret);
    4052              : }
    4053              : 
    4054              : /* Emit before ITER (and any labels/case labels before it) code like
    4055              :    if (0)
    4056              :      {
    4057              :        l1:
    4058              :         v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
    4059              :         v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
    4060              :         v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
    4061              :         v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
    4062              :      }
    4063              :    and return l1 label, or if it already exists, assert it has the
    4064              :    .DEFERRED_INIT calls for the right decls in the right order and
    4065              :    amend it, either by adding extra labels in between or further
    4066              :    ,DEFERRED_INIT calls before the first label and extra label before
    4067              :    that.  If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
    4068              :    of adding a label.  DECLS points to an array of NDECLS VAR_DECLs
    4069              :    which should be initialized.  */
    4070              : 
    4071              : static tree
    4072          129 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
    4073              :                                tree *decls, unsigned ndecls)
    4074              : {
    4075          129 :   tree lab = NULL_TREE;
    4076          193 :   for (; !tsi_end_p (iter); tsi_prev (&iter))
    4077              :     {
    4078          187 :       switch (TREE_CODE (tsi_stmt (iter)))
    4079              :         {
    4080           64 :         case LABEL_EXPR:
    4081           64 :         case CASE_LABEL_EXPR:
    4082           64 :         case DEBUG_BEGIN_STMT:
    4083           64 :           continue;
    4084              :         default:
    4085              :           break;
    4086              :         }
    4087              :       break;
    4088              :     }
    4089          129 :   if (!tsi_end_p (iter)
    4090          123 :       && TREE_CODE (tsi_stmt (iter)) == IF_STMT
    4091          206 :       && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
    4092              :     {
    4093              :       /* Found IF_STMT added for this or some adjacent
    4094              :          LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
    4095              :          The decls are ordered so that we can always reuse it.  Sometimes
    4096              :          by no modifications at all and just returning the right label
    4097              :          which was added already before, sometimes by adding a label in
    4098              :          between two previously added .DEFERRED_INIT calls and sometimes
    4099              :          by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
    4100              :          before that) before the statements in IF_STMT body.  */
    4101           71 :       tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
    4102           71 :       iter = tsi_last (then_clause);
    4103           71 :       bool add = false;
    4104          452 :       for (unsigned int i = 0; i < ndecls; ++i)
    4105              :         {
    4106          310 :           tree decl = decls[i];
    4107          310 :           if (!add)
    4108              :             {
    4109              :               /* Skip over labels/case labels after .DEFERRED_INIT for the
    4110              :                  DECL we are looking for.  */
    4111          399 :               while (!tsi_end_p (iter)
    4112          399 :                      && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
    4113          286 :                          || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
    4114           26 :                              && !case_label)))
    4115          119 :                 tsi_prev (&iter);
    4116          280 :               if (tsi_end_p (iter))
    4117              :                 {
    4118              :                   /* Reached the start, we'll need to prepend further
    4119              :                      statements.  */
    4120           20 :                   add = true;
    4121           20 :                   iter = tsi_start (then_clause);
    4122              :                 }
    4123              :               else
    4124              :                 {
    4125              :                   /* Found something, assert it is .DEFERRED_INIT for
    4126              :                      DECL.  */
    4127          260 :                   tree t = tsi_stmt (iter);
    4128          260 :                   gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
    4129          260 :                   t = EXPR_STMT_EXPR (t);
    4130          260 :                   gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
    4131              :                                        && TREE_OPERAND (t, 0) == decl
    4132              :                                        && (TREE_CODE (TREE_OPERAND (t, 1))
    4133              :                                            == CALL_EXPR));
    4134          260 :                   t = TREE_OPERAND (t, 1);
    4135          260 :                   gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
    4136              :                                        && (CALL_EXPR_IFN (t)
    4137              :                                            == IFN_DEFERRED_INIT));
    4138          260 :                   tsi_prev (&iter);
    4139              :                 }
    4140              :             }
    4141          280 :           if (add)
    4142              :             {
    4143              :               /* If reached the start in this or some earlier iteration,
    4144              :                  prepend .DEFERRED_INIT call for DECL.  */
    4145           50 :               tree t = build_deferred_init_call (decl);
    4146           50 :               STMT_IS_FULL_EXPR_P (t) = 1;
    4147           50 :               tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4148              :             }
    4149              :         }
    4150           71 :       if (!add)
    4151              :         {
    4152              :           /* If .DEFERRED_INIT calls for all the decls were already there,
    4153              :              skip over case labels and if we find a LABEL_EXPR, return
    4154              :              its label.  */
    4155           63 :           while (!tsi_end_p (iter)
    4156           63 :                  && !case_label
    4157          117 :                  && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
    4158           12 :             tsi_prev (&iter);
    4159           51 :           if (tsi_end_p (iter))
    4160              :             {
    4161              :               /* Only case labels were found and we are looking for normal
    4162              :                  label, we'll need to add it.  */
    4163            0 :               add = true;
    4164            0 :               iter = tsi_start (then_clause);
    4165              :             }
    4166           51 :           else if (!case_label
    4167           51 :                    && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
    4168              :             /* Return existing label.  */
    4169           21 :             lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
    4170              :           else
    4171              :             {
    4172              :               /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR.  */
    4173           30 :               gcc_checking_assert (case_label
    4174              :                                    || (TREE_CODE (tsi_stmt (iter))
    4175              :                                        == EXPR_STMT));
    4176           30 :               add = true;
    4177           30 :               tsi_next (&iter);
    4178           30 :               gcc_checking_assert (!tsi_end_p (iter));
    4179              :             }
    4180              :         }
    4181           21 :       if (add)
    4182              :         {
    4183           50 :           tree t;
    4184           50 :           if (case_label)
    4185              :             t = case_label;
    4186              :           else
    4187              :             {
    4188           41 :               lab = create_artificial_label (UNKNOWN_LOCATION);
    4189           41 :               t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
    4190              :             }
    4191           50 :           tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4192              :         }
    4193              :     }
    4194              :   else
    4195              :     {
    4196              :       /* No IF_STMT created by this function found.  Create it all
    4197              :          from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
    4198              :          followed by .DEFERRED_INIT calls inside of a new if (0).  */
    4199           58 :       tree new_then = push_stmt_list ();
    4200           58 :       if (!case_label)
    4201              :         {
    4202           23 :           lab = create_artificial_label (UNKNOWN_LOCATION);
    4203           23 :           add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
    4204              :         }
    4205              :       else
    4206           35 :         add_stmt (case_label);
    4207          150 :       for (unsigned int i = ndecls; i; --i)
    4208           92 :         add_stmt (build_deferred_init_call (decls[i - 1]));
    4209           58 :       new_then = pop_stmt_list (new_then);
    4210           58 :       tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
    4211              :                           new_then, void_node, NULL_TREE);
    4212           58 :       IF_STMT_VACUOUS_INIT_P (stmt) = 1;
    4213           58 :       if (tsi_end_p (iter))
    4214              :         {
    4215            6 :           iter = tsi_start (iter.container);
    4216            6 :           tsi_link_before (&iter, stmt, TSI_SAME_STMT);
    4217              :         }
    4218              :       else
    4219           52 :         tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
    4220              :     }
    4221          129 :   return lab;
    4222              : }
    4223              : 
    4224              : /* Adjust backward gotos to named label ENT if they jump over vacuous
    4225              :    initializers if !!flag_auto_var_init.  ITER is the location of
    4226              :    LABEL_EXPR for that named label.  */
    4227              : 
    4228              : static void
    4229           19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
    4230              : {
    4231           19 :   auto_vec<tree, 4> decls;
    4232           19 :   unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
    4233           19 :   tree decl;
    4234          107 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
    4235           88 :     if (!decl_jump_unsafe (decl))
    4236              :       {
    4237           88 :         gcc_checking_assert (decl_instrument_init_bypass_p (decl));
    4238           88 :         decls.safe_push (decl);
    4239          176 :         if (decls.length () == max_cnt)
    4240              :           break;
    4241              :       }
    4242           19 :   named_label_bck_direct_goto *dgoto;
    4243           19 :   unsigned last = 0;
    4244           19 :   tree lab = NULL_TREE;
    4245          103 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
    4246              :     {
    4247           46 :       if (dgoto->n_bad_decls != last)
    4248              :         {
    4249           40 :           last = dgoto->n_bad_decls;
    4250           80 :           lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
    4251              :                                                decls.address (), last);
    4252              :         }
    4253           46 :       *dgoto->direct_goto = lab;
    4254              :     }
    4255           19 : }
    4256              : 
    4257              : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    4258              :    to the user.  */
    4259              : 
    4260              : static bool
    4261          289 : identify_goto (tree decl, location_t loc, const location_t *locus,
    4262              :                enum diagnostics::kind diag_kind, bool computed)
    4263              : {
    4264          289 :   if (computed)
    4265           43 :     diag_kind = diagnostics::kind::warning;
    4266          289 :   auto_diagnostic_group d;
    4267          289 :   bool complained
    4268          376 :     = emit_diagnostic (diag_kind, loc, 0,
    4269              :                        decl ? G_("jump to label %qD")
    4270              :                        : G_("jump to case label"), decl);
    4271          289 :   if (complained && locus)
    4272              :     {
    4273          202 :       if (computed)
    4274           43 :         inform (*locus, "  as a possible target of computed goto");
    4275              :       else
    4276          159 :         inform (*locus, "  from here");
    4277              :     }
    4278          578 :   return complained;
    4279          289 : }
    4280              : 
    4281              : /* Check that a single previously seen jump to a newly defined label
    4282              :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    4283              :    the jump context; NAMES are the names in scope in LEVEL at the jump
    4284              :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    4285              :    is a vec of decls if the jump is a computed goto.  DIRECT_GOTO is a
    4286              :    vec of pointers to LABEL_DECLs that might need adjusting if vacuous
    4287              :    initializations are crossed for !!flag_auto_var_init.  CASE_LABEL is
    4288              :    CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
    4289              :    Returns non-zero if all is well, 2 if any vacuous initializers were
    4290              :    crossed.  */
    4291              : 
    4292              : static int
    4293      1828291 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
    4294              :                        bool exited_omp, const location_t *locus,
    4295              :                        vec<tree, va_gc> *computed,
    4296              :                        vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
    4297              :                        tree case_label)
    4298              : {
    4299      1828291 :   auto_diagnostic_group d;
    4300      1828291 :   cp_binding_level *b;
    4301      1828291 :   bool complained = false;
    4302      1828291 :   int identified = 0;
    4303      1828291 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    4304      1828291 :   bool saw_ceif = false, saw_se = false;
    4305      1828291 :   auto_vec<tree> vacuous_decls;
    4306      1828291 :   bool vacuous_inits = false;
    4307              : 
    4308      1828291 :   if (exited_omp)
    4309              :     {
    4310           12 :       complained = identify_goto (decl, input_location, locus,
    4311              :                                   diagnostics::kind::error,
    4312              :                                   computed);
    4313           12 :       if (complained)
    4314           12 :         inform (input_location, "  exits OpenMP structured block");
    4315              :       saw_omp = true;
    4316              :       identified = 2;
    4317              :     }
    4318              : 
    4319      3626878 :   for (b = current_binding_level; b ; b = b->level_chain)
    4320              :     {
    4321      3626878 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    4322              : 
    4323      6616389 :       for (new_decls = b->names; new_decls != old_decls;
    4324      5968320 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    4325      2978809 :                         : TREE_CHAIN (new_decls)))
    4326              :         {
    4327      2989511 :           bool problem = decl_jump_unsafe (new_decls);
    4328      2989511 :           if (! problem)
    4329              :             {
    4330      2989463 :               if (decl_instrument_init_bypass_p (new_decls))
    4331              :                 {
    4332          328 :                   if (direct_goto || case_label)
    4333          257 :                     vacuous_decls.safe_push (new_decls);
    4334              :                   vacuous_inits = true;
    4335              :                 }
    4336      2989463 :               continue;
    4337              :             }
    4338              : 
    4339           48 :           if (!identified)
    4340              :             {
    4341           48 :               complained = identify_goto (decl, input_location, locus,
    4342              :                                           diagnostics::kind::error,
    4343              :                                           computed);
    4344           48 :               identified = 2;
    4345              :             }
    4346           48 :           if (complained)
    4347           48 :             inform (DECL_SOURCE_LOCATION (new_decls),
    4348              :                     "  crosses initialization of %q#D", new_decls);
    4349              :         }
    4350              : 
    4351      3626878 :       if (b == level)
    4352              :         break;
    4353              : 
    4354      1798587 :       const char *inf = NULL;
    4355      1798587 :       location_t loc = input_location;
    4356      1798587 :       switch (b->kind)
    4357              :         {
    4358            3 :         case sk_try:
    4359            3 :           if (!saw_eh)
    4360              :             inf = G_("  enters %<try%> block");
    4361              :           saw_eh = true;
    4362              :           break;
    4363              : 
    4364            9 :         case sk_catch:
    4365            9 :           if (!saw_eh)
    4366              :             inf = G_("  enters %<catch%> block");
    4367              :           saw_eh = true;
    4368              :           break;
    4369              : 
    4370          102 :         case sk_omp:
    4371          102 :           if (!saw_omp)
    4372              :             inf = G_("  enters OpenMP structured block");
    4373              :           saw_omp = true;
    4374              :           break;
    4375              : 
    4376            3 :         case sk_transaction:
    4377            3 :           if (!saw_tm)
    4378              :             inf = G_("  enters synchronized or atomic statement");
    4379              :           saw_tm = true;
    4380              :           break;
    4381              : 
    4382           18 :         case sk_stmt_expr:
    4383           18 :           if (!saw_se)
    4384              :             inf = G_("  enters statement expression");
    4385              :           saw_se = true;
    4386              :           break;
    4387              : 
    4388      1798312 :         case sk_block:
    4389      1798312 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    4390              :             {
    4391            9 :               inf = G_("  enters %<constexpr if%> statement");
    4392            9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4393              :               saw_cxif = true;
    4394              :             }
    4395      1798303 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    4396              :             {
    4397           18 :               inf = G_("  enters %<consteval if%> statement");
    4398           18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4399              :               saw_ceif = true;
    4400              :             }
    4401              :           break;
    4402              : 
    4403              :         default:
    4404              :           break;
    4405              :         }
    4406              : 
    4407           27 :       if (inf)
    4408              :         {
    4409          141 :           if (identified < 2)
    4410          141 :             complained = identify_goto (decl, input_location, locus,
    4411              :                                         diagnostics::kind::error,
    4412              :                                         computed);
    4413          141 :           identified = 2;
    4414          141 :           if (complained)
    4415          141 :             inform (loc, inf);
    4416              :         }
    4417              :     }
    4418              : 
    4419      1828291 :   if (!vec_safe_is_empty (computed))
    4420              :     {
    4421            9 :       if (!identified)
    4422            6 :         complained = identify_goto (decl, input_location, locus,
    4423              :                                     diagnostics::kind::error,
    4424              :                                     computed);
    4425            9 :       identified = 2;
    4426            9 :       if (complained)
    4427           18 :         for (tree d : computed)
    4428              :           {
    4429            9 :             if (DECL_P (d))
    4430            6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    4431            3 :             else if (d == get_identifier ("catch"))
    4432            3 :               inform (*locus, "  does not clean up handled exception");
    4433              :           }
    4434              :     }
    4435              : 
    4436      1828383 :   if (!vacuous_decls.is_empty () && !seen_error ())
    4437              :     {
    4438           89 :       tree_stmt_iterator iter = tsi_last (cur_stmt_list);
    4439           89 :       if (case_label)
    4440              :         {
    4441           44 :           gcc_checking_assert (tsi_stmt (iter) == case_label);
    4442           44 :           tsi_delink (&iter);
    4443           44 :           iter = tsi_last (cur_stmt_list);
    4444              :         }
    4445           89 :       tree lab = maybe_add_deferred_init_calls (iter, case_label,
    4446              :                                                 vacuous_decls.address (),
    4447              :                                                 vacuous_decls.length ());
    4448           89 :       if (lab)
    4449              :         {
    4450              :           unsigned int i;
    4451              :           named_label_fwd_direct_goto *dgoto;
    4452          179 :           FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
    4453           45 :             *dgoto->direct_goto = lab;
    4454              :         }
    4455              :     }
    4456              : 
    4457      1828291 :   if (identified)
    4458              :     return 0;
    4459      1828084 :   return vacuous_inits ? 2 : 1;
    4460      1828291 : }
    4461              : 
    4462              : static void
    4463         2145 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    4464              : {
    4465         2145 :   check_previous_goto_1 (decl, use->binding_level,
    4466              :                          use->names_in_scope, use->in_omp_scope,
    4467         2145 :                          &use->o_goto_locus, use->computed_goto,
    4468              :                          use->direct_goto, NULL_TREE);
    4469         2145 :   vec_free (use->direct_goto);
    4470         2145 : }
    4471              : 
    4472              : static int
    4473      1826146 : check_switch_goto (cp_binding_level *level, tree case_label)
    4474              : {
    4475      1826146 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    4476      1826146 :                                 false, NULL, nullptr, nullptr, case_label);
    4477              : }
    4478              : 
    4479              : /* Check that a new jump to a label ENT is OK.  DECLP is a pointer
    4480              :    to a LABEL_DECL for direct gotos and NULL for computed gotos.  */
    4481              : 
    4482              : void
    4483         2887 : check_goto_1 (named_label_entry *ent, tree *declp)
    4484              : {
    4485         2887 :   auto_diagnostic_group d;
    4486         2887 :   tree decl = ent->label_decl;
    4487         2887 :   bool computed = declp == NULL;
    4488              : 
    4489              :   /* If the label hasn't been defined yet, defer checking.  */
    4490         2887 :   if (! DECL_INITIAL (decl))
    4491              :     {
    4492              :       /* Don't bother creating another use if the last goto had the
    4493              :          same data, and will therefore create the same set of errors.  */
    4494         2217 :       if (ent->uses
    4495          661 :           && ent->uses->binding_level == current_binding_level
    4496           63 :           && ent->uses->names_in_scope == current_binding_level->names)
    4497              :         {
    4498           63 :           if (declp
    4499           57 :               && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4500           12 :               && !processing_template_decl)
    4501           10 :             vec_safe_push (ent->uses->direct_goto,
    4502           10 :                            named_label_fwd_direct_goto { declp });
    4503              :           return;
    4504              :         }
    4505              : 
    4506         2154 :       named_label_use_entry *new_use
    4507         2154 :         = ggc_alloc<named_label_use_entry> ();
    4508         2154 :       new_use->binding_level = current_binding_level;
    4509         2154 :       new_use->names_in_scope = current_binding_level->names;
    4510         2154 :       new_use->o_goto_locus = input_location;
    4511         2154 :       new_use->in_omp_scope = false;
    4512         2154 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    4513         2154 :       new_use->direct_goto = nullptr;
    4514         2154 :       if (declp
    4515         2063 :           && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4516          369 :           && !processing_template_decl)
    4517          312 :         vec_safe_push (new_use->direct_goto,
    4518          312 :                        named_label_fwd_direct_goto { declp });
    4519              : 
    4520         2154 :       new_use->next = ent->uses;
    4521         2154 :       ent->uses = new_use;
    4522         2154 :       return;
    4523              :     }
    4524              : 
    4525          670 :   bool saw_catch = false, complained = false;
    4526          670 :   int identified = 0;
    4527          670 :   tree bad;
    4528          670 :   unsigned ix;
    4529          670 :   unsigned n_bad_decls = 0;
    4530              : 
    4531          670 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    4532          655 :       || ent->in_constexpr_if || ent->in_consteval_if
    4533          649 :       || ent->in_omp_scope || ent->in_stmt_expr
    4534          631 :       || ent->has_bad_decls)
    4535              :     {
    4536           45 :       enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
    4537           45 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    4538           30 :           || ent->in_consteval_if || ent->in_transaction_scope
    4539           24 :           || ent->in_omp_scope || ent->in_stmt_expr)
    4540           39 :         diag_kind = diagnostics::kind::error;
    4541           45 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4542              :                                   &input_location, diag_kind, computed);
    4543           45 :       identified = 1 + (diag_kind == diagnostics::kind::error);
    4544              :     }
    4545              : 
    4546          860 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    4547              :     {
    4548          190 :       bool problem = decl_jump_unsafe (bad);
    4549          190 :       if (!problem)
    4550              :         {
    4551          184 :           gcc_checking_assert (decl_instrument_init_bypass_p (bad));
    4552          184 :           n_bad_decls++;
    4553          184 :           continue;
    4554              :         }
    4555              : 
    4556            6 :       if (DECL_ARTIFICIAL (bad))
    4557              :         {
    4558              :           /* Can't skip init of __exception_info.  */
    4559            0 :           if (identified == 1)
    4560              :             {
    4561            0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4562              :                                           &input_location,
    4563              :                                           diagnostics::kind::error,
    4564              :                                           computed);
    4565            0 :               identified = 2;
    4566              :             }
    4567            0 :           if (complained)
    4568            0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    4569              :           saw_catch = true;
    4570              :         }
    4571            6 :       else if (complained)
    4572            6 :         inform (DECL_SOURCE_LOCATION (bad),
    4573              :                 "  skips initialization of %q#D", bad);
    4574              :     }
    4575              : 
    4576          670 :   if (complained)
    4577              :     {
    4578           45 :       if (ent->in_try_scope)
    4579            9 :         inform (input_location, "  enters %<try%> block");
    4580           36 :       else if (ent->in_catch_scope && !saw_catch)
    4581            3 :         inform (input_location, "  enters %<catch%> block");
    4582           33 :       else if (ent->in_transaction_scope)
    4583            3 :         inform (input_location, "  enters synchronized or atomic statement");
    4584           30 :       else if (ent->in_constexpr_if)
    4585            3 :         inform (input_location, "  enters %<constexpr if%> statement");
    4586           27 :       else if (ent->in_consteval_if)
    4587            3 :         inform (input_location, "  enters %<consteval if%> statement");
    4588           24 :       else if (ent->in_stmt_expr)
    4589           15 :         inform (input_location, "  enters statement expression");
    4590              :     }
    4591              : 
    4592          670 :   if (ent->in_omp_scope)
    4593              :     {
    4594            3 :       if (complained)
    4595            3 :         inform (input_location, "  enters OpenMP structured block");
    4596              :     }
    4597          667 :   else if (flag_openmp)
    4598           42 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4599              :       {
    4600           42 :         if (b == ent->binding_level)
    4601              :           break;
    4602           36 :         if (b->kind == sk_omp)
    4603              :           {
    4604           21 :             if (identified < 2)
    4605              :               {
    4606           42 :                 complained = identify_goto (decl,
    4607           21 :                                             DECL_SOURCE_LOCATION (decl),
    4608              :                                             &input_location,
    4609              :                                             diagnostics::kind::error,
    4610              :                                             computed);
    4611           21 :                 identified = 2;
    4612              :               }
    4613           21 :             if (complained)
    4614           21 :               inform (input_location, "  exits OpenMP structured block");
    4615              :             break;
    4616              :           }
    4617              :       }
    4618              : 
    4619              :   /* Warn if a computed goto might involve a local variable going out of scope
    4620              :      without being cleaned up.  */
    4621          670 :   if (computed)
    4622              :     {
    4623           80 :       auto level = ent->binding_level;
    4624           80 :       auto names = ent->names_in_scope;
    4625           80 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4626              :         {
    4627          138 :           if (b->kind == sk_catch)
    4628              :             {
    4629            6 :               if (!identified)
    4630              :                 {
    4631            6 :                   complained
    4632            6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4633              :                                      &input_location, diagnostics::kind::error,
    4634              :                                      computed);
    4635            6 :                   identified = 2;
    4636              :                 }
    4637            6 :               if (complained)
    4638            6 :                 inform (input_location,
    4639              :                         "  does not clean up handled exception");
    4640              :             }
    4641          138 :           tree end = b == level ? names : NULL_TREE;
    4642          154 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4643              :             {
    4644           16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4645              :                 {
    4646           10 :                   if (!identified)
    4647              :                     {
    4648           10 :                       complained
    4649           10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4650              :                                          &input_location, diagnostics::kind::error,
    4651              :                                          computed);
    4652           10 :                       identified = 2;
    4653              :                     }
    4654           10 :                   if (complained)
    4655           10 :                     inform (DECL_SOURCE_LOCATION (d),
    4656              :                             "  does not destroy %qD", d);
    4657              :                 }
    4658              :             }
    4659          138 :           if (b == level)
    4660              :             break;
    4661           58 :         }
    4662              :     }
    4663              : 
    4664          670 :   if (n_bad_decls && declp)
    4665           46 :     vec_safe_push (ent->direct_goto,
    4666           46 :                    named_label_bck_direct_goto { declp, n_bad_decls });
    4667         2887 : }
    4668              : 
    4669              : /* Check that a new jump to a label *DECLP is OK.  Called by
    4670              :    finish_goto_stmt.  */
    4671              : 
    4672              : void
    4673         2847 : check_goto (tree *declp)
    4674              : {
    4675         2847 :   if (!named_labels)
    4676              :     return;
    4677         2832 :   tree decl = *declp;
    4678         2832 :   if (TREE_CODE (decl) != LABEL_DECL)
    4679              :     {
    4680              :       /* We don't know where a computed goto is jumping,
    4681              :          so check all addressable labels.  */
    4682          330 :       for (auto iter = named_labels->begin ();
    4683          452 :            iter != named_labels->end ();
    4684          208 :            ++iter)
    4685              :         {
    4686          208 :           auto ent = *iter;
    4687          208 :           if (ent->addressed)
    4688          177 :             check_goto_1 (ent, NULL);
    4689              :         }
    4690              :     }
    4691              :   else
    4692              :     {
    4693         2710 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4694         2710 :       named_label_entry **slot
    4695         2710 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4696         2710 :       named_label_entry *ent = *slot;
    4697         2710 :       check_goto_1 (ent, declp);
    4698              :     }
    4699              : }
    4700              : 
    4701              : /* Check that a return is ok wrt OpenMP structured blocks.
    4702              :    Called by finish_return_stmt.  Returns true if all is well.  */
    4703              : 
    4704              : bool
    4705       287292 : check_omp_return (void)
    4706              : {
    4707       852442 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4708       852442 :     if (b->kind == sk_omp)
    4709              :       {
    4710           15 :         error ("invalid exit from OpenMP structured block");
    4711           15 :         return false;
    4712              :       }
    4713       852427 :     else if (b->kind == sk_function_parms)
    4714              :       break;
    4715              :   return true;
    4716              : }
    4717              : 
    4718              : /* Define a label, specifying the location in the source file.
    4719              :    Return the LABEL_DECL node for the label.  */
    4720              : 
    4721              : tree
    4722        21162 : define_label (location_t location, tree name)
    4723              : {
    4724        21162 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4725              : 
    4726              :   /* After labels, make any new cleanups in the function go into their
    4727              :      own new (temporary) binding contour.  */
    4728        21162 :   for (cp_binding_level *p = current_binding_level;
    4729        32018 :        p->kind != sk_function_parms;
    4730        10856 :        p = p->level_chain)
    4731        10856 :     p->more_cleanups_ok = 0;
    4732              : 
    4733        21162 :   named_label_entry *ent = lookup_label_1 (name, false);
    4734        21162 :   tree decl = ent->label_decl;
    4735              : 
    4736        21162 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4737              :     {
    4738            6 :       error ("duplicate label %qD", decl);
    4739            6 :       return error_mark_node;
    4740              :     }
    4741              :   else
    4742              :     {
    4743              :       /* Mark label as having been defined.  */
    4744        21156 :       DECL_INITIAL (decl) = error_mark_node;
    4745              :       /* Say where in the source.  */
    4746        21156 :       DECL_SOURCE_LOCATION (decl) = location;
    4747              : 
    4748        21156 :       ent->binding_level = current_binding_level;
    4749        21156 :       ent->names_in_scope = current_binding_level->names;
    4750              : 
    4751        23301 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4752         2145 :         check_previous_goto (decl, use);
    4753        21156 :       ent->uses = NULL;
    4754              :     }
    4755              : 
    4756        21156 :   return decl;
    4757        21162 : }
    4758              : 
    4759              : struct cp_switch
    4760              : {
    4761              :   cp_binding_level *level;
    4762              :   struct cp_switch *next;
    4763              :   /* The SWITCH_STMT being built.  */
    4764              :   tree switch_stmt;
    4765              :   /* A splay-tree mapping the low element of a case range to the high
    4766              :      element, or NULL_TREE if there is no high element.  Used to
    4767              :      determine whether or not a new case label duplicates an old case
    4768              :      label.  We need a tree, rather than simply a hash table, because
    4769              :      of the GNU case range extension.  */
    4770              :   splay_tree cases;
    4771              :   /* Remember whether a default: case label has been seen.  */
    4772              :   bool has_default_p;
    4773              :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4774              :   bool break_stmt_seen_p;
    4775              :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4776              :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4777              :   bool in_loop_body_p;
    4778              : };
    4779              : 
    4780              : /* A stack of the currently active switch statements.  The innermost
    4781              :    switch statement is on the top of the stack.  There is no need to
    4782              :    mark the stack for garbage collection because it is only active
    4783              :    during the processing of the body of a function, and we never
    4784              :    collect at that point.  */
    4785              : 
    4786              : static struct cp_switch *switch_stack;
    4787              : 
    4788              : /* Called right after a switch-statement condition is parsed.
    4789              :    SWITCH_STMT is the switch statement being parsed.  */
    4790              : 
    4791              : void
    4792       735389 : push_switch (tree switch_stmt)
    4793              : {
    4794       735389 :   struct cp_switch *p = XNEW (struct cp_switch);
    4795       735389 :   p->level = current_binding_level;
    4796       735389 :   p->next = switch_stack;
    4797       735389 :   p->switch_stmt = switch_stmt;
    4798       735389 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4799       735389 :   p->has_default_p = false;
    4800       735389 :   p->break_stmt_seen_p = false;
    4801       735389 :   p->in_loop_body_p = false;
    4802       735389 :   switch_stack = p;
    4803       735389 : }
    4804              : 
    4805              : void
    4806       735389 : pop_switch (void)
    4807              : {
    4808       735389 :   struct cp_switch *cs = switch_stack;
    4809              : 
    4810              :   /* Emit warnings as needed.  */
    4811       735389 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4812       735389 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4813       735389 :   const bool bool_cond_p
    4814       735389 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4815       735389 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4816       735389 :   if (!processing_template_decl)
    4817       301677 :     c_do_switch_warnings (cs->cases, switch_location,
    4818       301677 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4819              :                           bool_cond_p);
    4820              : 
    4821              :   /* For the benefit of block_may_fallthru remember if the switch body
    4822              :      case labels cover all possible values and if there are break; stmts.  */
    4823       735389 :   if (cs->has_default_p
    4824       735389 :       || (!processing_template_decl
    4825        42571 :           && c_switch_covers_all_cases_p (cs->cases,
    4826        42571 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4827       546876 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4828       735389 :   if (!cs->break_stmt_seen_p)
    4829       382264 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4830              :   /* Now that we're done with the switch warnings, set the switch type
    4831              :      to the type of the condition if the index type was of scoped enum type.
    4832              :      (Such types don't participate in the integer promotions.)  We do this
    4833              :      because of bit-fields whose declared type is a scoped enum type:
    4834              :      gimplification will use the lowered index type, but convert the
    4835              :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4836              :      and verify_gimple_switch doesn't accept that.  */
    4837       735389 :   if (is_bitfield_expr_with_lowered_type (cond))
    4838        33174 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4839       735389 :   gcc_assert (!cs->in_loop_body_p);
    4840       735389 :   splay_tree_delete (cs->cases);
    4841       735389 :   switch_stack = switch_stack->next;
    4842       735389 :   free (cs);
    4843       735389 : }
    4844              : 
    4845              : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4846              :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4847              :    in switch_stack we've seen a BREAK_STMT.  */
    4848              : 
    4849              : void
    4850      4892098 : note_break_stmt (void)
    4851              : {
    4852      4892098 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4853      2756842 :     switch_stack->break_stmt_seen_p = true;
    4854      4892098 : }
    4855              : 
    4856              : /* Note the start of processing of an iteration statement's body.
    4857              :    The note_break_stmt function will do nothing while processing it.
    4858              :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4859              : 
    4860              : bool
    4861     18458511 : note_iteration_stmt_body_start (void)
    4862              : {
    4863     18458511 :   if (!switch_stack)
    4864              :     return false;
    4865       194865 :   bool ret = switch_stack->in_loop_body_p;
    4866       194865 :   switch_stack->in_loop_body_p = true;
    4867       194865 :   return ret;
    4868              : }
    4869              : 
    4870              : /* Note the end of processing of an iteration statement's body.  */
    4871              : 
    4872              : void
    4873     18458511 : note_iteration_stmt_body_end (bool prev)
    4874              : {
    4875     18458511 :   if (switch_stack)
    4876       194865 :     switch_stack->in_loop_body_p = prev;
    4877     18458511 : }
    4878              : 
    4879              : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4880              :    condition.  Note that if TYPE and VALUE are already integral we don't
    4881              :    really do the conversion because the language-independent
    4882              :    warning/optimization code will work better that way.  */
    4883              : 
    4884              : static tree
    4885      3651956 : case_conversion (tree type, tree value)
    4886              : {
    4887      3651956 :   if (value == NULL_TREE)
    4888              :     return value;
    4889              : 
    4890      1567045 :   value = mark_rvalue_use (value);
    4891              : 
    4892      1567045 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4893      1120563 :     type = type_promotes_to (type);
    4894              : 
    4895      1567045 :   tree ovalue = value;
    4896              :   /* The constant-expression VALUE shall be a converted constant expression
    4897              :      of the adjusted type of the switch condition, which doesn't allow
    4898              :      narrowing conversions.  */
    4899      1567045 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4900              : 
    4901      1567045 :   if (cxx_dialect >= cxx11
    4902      1567045 :       && (SCOPED_ENUM_P (type)
    4903      1117454 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4904              :     /* Use the converted value.  */;
    4905              :   else
    4906              :     /* The already integral case.  */
    4907              :     value = ovalue;
    4908              : 
    4909      1567045 :   return cxx_constant_value (value);
    4910              : }
    4911              : 
    4912              : /* Note that we've seen a definition of a case label, and complain if this
    4913              :    is a bad place for one.  */
    4914              : 
    4915              : tree
    4916      5981316 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4917              : {
    4918      5981316 :   tree cond, r;
    4919      5981316 :   cp_binding_level *p;
    4920      5981316 :   tree type;
    4921              : 
    4922      5981316 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4923       546840 :     switch_stack->has_default_p = true;
    4924              : 
    4925      5981316 :   if (processing_template_decl)
    4926              :     {
    4927      4155215 :       tree label;
    4928              : 
    4929              :       /* For templates, just add the case label; we'll do semantic
    4930              :          analysis at instantiation-time.  But diagnose case labels
    4931              :          in expansion statements with switch outside of it here.  */
    4932      4155215 :       if (in_expansion_stmt)
    4933           39 :         for (cp_binding_level *b = current_binding_level;
    4934           78 :              b != switch_stack->level; b = b->level_chain)
    4935           63 :           if (b->kind == sk_template_for && b->this_entity)
    4936              :             {
    4937           24 :               auto_diagnostic_group d;
    4938           24 :               error ("jump to case label");
    4939           24 :               inform (EXPR_LOCATION (b->this_entity),
    4940              :                       "  enters %<template for%> statement");
    4941           24 :               return error_mark_node;
    4942           24 :             }
    4943      4155191 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4944      4155191 :       return add_stmt (build_case_label (low_value, high_value, label));
    4945              :     }
    4946              : 
    4947              :   /* Find the condition on which this switch statement depends.  */
    4948      1826101 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4949      1826101 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4950            0 :     cond = TREE_VALUE (cond);
    4951              : 
    4952      1826101 :   int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
    4953      1826101 :   if (!chk_switch_goto)
    4954           87 :     return error_mark_node;
    4955              : 
    4956      1826014 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4957      1826014 :   if (type == error_mark_node)
    4958              :     return error_mark_node;
    4959              : 
    4960      1825978 :   low_value = case_conversion (type, low_value);
    4961      1825978 :   high_value = case_conversion (type, high_value);
    4962              : 
    4963      1825978 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4964              : 
    4965      1825978 :   if (r != error_mark_node && chk_switch_goto == 2)
    4966           45 :     check_switch_goto (switch_stack->level, r);
    4967              : 
    4968              :   /* After labels, make any new cleanups in the function go into their
    4969              :      own new (temporary) binding contour.  */
    4970      1825978 :   for (p = current_binding_level;
    4971      7669865 :        p->kind != sk_function_parms;
    4972      5843887 :        p = p->level_chain)
    4973      5843887 :     p->more_cleanups_ok = 0;
    4974              : 
    4975              :   return r;
    4976              : }
    4977              : 
    4978              : struct typename_info {
    4979              :   tree scope;
    4980              :   tree name;
    4981              :   tree template_id;
    4982              :   tag_types tag_type;
    4983              : };
    4984              : 
    4985              : struct typename_hasher : ggc_ptr_hash<tree_node>
    4986              : {
    4987              :   typedef typename_info *compare_type;
    4988              : 
    4989              :   /* Hash a TYPENAME_TYPE.  */
    4990              : 
    4991              :   static hashval_t
    4992    442323553 :   hash (tree context, tree fullname)
    4993              :   {
    4994    442323553 :     hashval_t hash = 0;
    4995    442323553 :     hash = iterative_hash_hashval_t (TYPE_HASH (context), hash);
    4996              :     /* FULLNAME could be a template-id, so use iterative_hash_template_arg here.
    4997              :        And might as well set comparing_specializations for stronger hashing.  */
    4998    442323553 :     ++comparing_specializations;
    4999    442323553 :     hash = iterative_hash_template_arg (fullname, hash);
    5000    442323553 :     --comparing_specializations;
    5001    442323553 :     return hash;
    5002              :   }
    5003              : 
    5004              :   static hashval_t
    5005     65028230 :   hash (const typename_info *ti)
    5006              :   {
    5007     65028230 :     return typename_hasher::hash (ti->scope, ti->template_id);
    5008              :   }
    5009              : 
    5010              :   static hashval_t
    5011    377295323 :   hash (tree t)
    5012              :   {
    5013    377295323 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    5014              :   }
    5015              : 
    5016              :   /* Compare two TYPENAME_TYPEs.  */
    5017              : 
    5018              :   static bool
    5019    450889531 :   equal (tree t1, const typename_info *t2)
    5020              :   {
    5021    450889531 :     return (TYPE_IDENTIFIER (t1) == t2->name
    5022    152289276 :             && TYPE_CONTEXT (t1) == t2->scope
    5023     33991074 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    5024    484169044 :             && get_typename_tag (t1) == t2->tag_type);
    5025              :   }
    5026              : };
    5027              : 
    5028              : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    5029              :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    5030              : 
    5031              :    Returns the new TYPENAME_TYPE.  */
    5032              : 
    5033              : static GTY (()) hash_table<typename_hasher> *typename_htab;
    5034              : 
    5035              : tree
    5036     65028230 : build_typename_type (tree context, tree name, tree fullname,
    5037              :                      enum tag_types tag_type)
    5038              : {
    5039     65028230 :   typename_info ti;
    5040              : 
    5041     65028230 :   if (typename_htab == NULL)
    5042        20053 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    5043              : 
    5044     65028230 :   ti.scope = FROB_CONTEXT (context);
    5045     65028230 :   ti.name = name;
    5046     65028230 :   ti.template_id = fullname;
    5047     65028230 :   ti.tag_type = tag_type;
    5048     65028230 :   hashval_t hash = typename_hasher::hash (&ti);
    5049              : 
    5050              :   /* See if we already have this type.  */
    5051     65028230 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    5052     65028230 :   tree t = *e;
    5053     65028230 :   if (*e)
    5054              :     t = *e;
    5055              :   else
    5056              :     {
    5057              :       /* Build the TYPENAME_TYPE.  */
    5058     32776899 :       t = cxx_make_type (TYPENAME_TYPE);
    5059     32776899 :       TYPE_CONTEXT (t) = ti.scope;
    5060     32776899 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    5061     32776899 :       set_typename_tag (t, ti.tag_type);
    5062              : 
    5063              :       /* Build the corresponding TYPE_DECL.  */
    5064     32776899 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    5065     32776899 :       TYPE_NAME (t) = d;
    5066     32776899 :       TYPE_STUB_DECL (t) = d;
    5067     32776899 :       DECL_CONTEXT (d) = ti.scope;
    5068     32776899 :       DECL_ARTIFICIAL (d) = 1;
    5069              : 
    5070              :       /* Store it in the hash table.  */
    5071     32776899 :       *e = t;
    5072              : 
    5073              :       /* TYPENAME_TYPEs must always be compared structurally, because
    5074              :          they may or may not resolve down to another type depending on
    5075              :          the currently open classes. */
    5076     32776899 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    5077              :     }
    5078              : 
    5079     65028230 :   return t;
    5080              : }
    5081              : 
    5082              : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    5083              :    provided to name the type.  Returns an appropriate type, unless an
    5084              :    error occurs, in which case error_mark_node is returned.  If we
    5085              :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    5086              :    return that, rather than the _TYPE it corresponds to, in other
    5087              :    cases we look through the type decl.  If TF_ERROR is set, complain
    5088              :    about errors, otherwise be quiet.  */
    5089              : 
    5090              : tree
    5091    275846289 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    5092              :                     tsubst_flags_t complain)
    5093              : {
    5094    275846289 :   tree fullname;
    5095    275846289 :   tree t;
    5096    275846289 :   bool want_template;
    5097              : 
    5098    275846289 :   if (name == error_mark_node
    5099    275846283 :       || context == NULL_TREE
    5100    275846283 :       || context == error_mark_node)
    5101              :     return error_mark_node;
    5102              : 
    5103    275846267 :   if (TYPE_P (name))
    5104              :     {
    5105            0 :       if (!(TYPE_LANG_SPECIFIC (name)
    5106            0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    5107            0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    5108            0 :         name = TYPE_IDENTIFIER (name);
    5109              :       else
    5110              :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    5111            0 :         name = build_nt (TEMPLATE_ID_EXPR,
    5112            0 :                          CLASSTYPE_TI_TEMPLATE (name),
    5113            0 :                          CLASSTYPE_TI_ARGS (name));
    5114              :     }
    5115    275846267 :   else if (TREE_CODE (name) == TYPE_DECL)
    5116            0 :     name = DECL_NAME (name);
    5117              : 
    5118    275846267 :   fullname = name;
    5119              : 
    5120    275846267 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    5121              :     {
    5122      5396211 :       name = TREE_OPERAND (name, 0);
    5123      5396211 :       if (DECL_TYPE_TEMPLATE_P (name))
    5124            0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    5125      5396211 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    5126              :         {
    5127            0 :           if (complain & tf_error)
    5128            0 :             error ("%qD is not a type", name);
    5129            0 :           return error_mark_node;
    5130              :         }
    5131              :     }
    5132    275846267 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    5133              :     {
    5134            0 :       if (complain & tf_error)
    5135            0 :         error ("%qD used without template arguments", name);
    5136            0 :       return error_mark_node;
    5137              :     }
    5138    275846267 :   else if (is_overloaded_fn (name))
    5139              :     {
    5140            3 :       if (complain & tf_error)
    5141            3 :         error ("%qD is a function, not a type", name);
    5142            3 :       return error_mark_node;
    5143              :     }
    5144    275846264 :   gcc_assert (identifier_p (name));
    5145    275846264 :   gcc_assert (TYPE_P (context));
    5146              : 
    5147    275846264 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    5148              :     /* This can happen for C++17 variadic using (c++/88986).  */;
    5149    262434594 :   else if (!MAYBE_CLASS_TYPE_P (context))
    5150              :     {
    5151            6 :       if (complain & tf_error)
    5152            6 :         error ("%q#T is not a class", context);
    5153            6 :       return error_mark_node;
    5154              :     }
    5155              : 
    5156              :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    5157              :      dependent base class of CONTEXT.  But look inside it anyway
    5158              :      if CONTEXT is a currently open scope, in case it refers to a
    5159              :      member of the current instantiation or a non-dependent base;
    5160              :      lookup will stop when we hit a dependent base.  */
    5161    275846258 :   if (!dependent_scope_p (context))
    5162              :     {
    5163              :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    5164              :          (as per [temp.res.general]/3), unless
    5165              :            - the tag corresponds to a class-key or 'enum' so
    5166              :              [basic.lookup.elab] applies, or
    5167              :            - the tag corresponds to scope_type or tf_qualifying_scope is
    5168              :              set so [basic.lookup.qual]/1 applies, or
    5169              :            - we're inside a base-specifier so [class.derived.general]/2 applies;
    5170              :              the tag will already be class_type in that case.
    5171              :          TODO: If we'd set/track the scope_type tag thoroughly on all
    5172              :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    5173              :          tf_qualifying_scope flag.  */
    5174    431415264 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    5175    215707632 :         || (complain & tf_qualifying_scope);
    5176    215707632 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    5177              :     }
    5178              :   else
    5179              :     t = NULL_TREE;
    5180              : 
    5181    275846258 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    5182     60139647 :     return build_typename_type (context, name, fullname, tag_type);
    5183              : 
    5184    215706611 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    5185              : 
    5186    215706611 :   if (!t)
    5187              :     {
    5188     19607495 :       if (complain & tf_error)
    5189              :         {
    5190          223 :           if (!COMPLETE_TYPE_P (context))
    5191           18 :             cxx_incomplete_type_error (NULL_TREE, context);
    5192              :           else
    5193          409 :             error (want_template ? G_("no class template named %q#T in %q#T")
    5194              :                    : G_("no type named %q#T in %q#T"), name, context);
    5195              :         }
    5196     19607495 :       return error_mark_node;
    5197              :     }
    5198              : 
    5199              :   /* Pull out the template from an injected-class-name (or multiple).  */
    5200    196099116 :   if (want_template)
    5201      3439278 :     t = maybe_get_template_decl_from_type_decl (t);
    5202              : 
    5203    196099116 :   if (TREE_CODE (t) == TREE_LIST)
    5204              :     {
    5205            3 :       if (complain & tf_error)
    5206              :         {
    5207            3 :           auto_diagnostic_group d;
    5208            3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    5209            3 :           print_candidates (input_location, t);
    5210            3 :         }
    5211            3 :       return error_mark_node;
    5212              :     }
    5213              : 
    5214    196099113 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    5215              :     {
    5216            6 :       if (complain & tf_error)
    5217            6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    5218              :                context, name, t);
    5219            6 :       return error_mark_node;
    5220              :     }
    5221    196099107 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    5222              :     {
    5223         2187 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    5224         4377 :           && DECL_TYPE_TEMPLATE_P (t))
    5225              :         /* The caller permits this typename-specifier to name a template
    5226              :            (because it appears in a CTAD-enabled context).  */;
    5227              :       else
    5228              :         {
    5229           23 :           if (complain & tf_error)
    5230           17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    5231              :                    context, name, t);
    5232           23 :           return error_mark_node;
    5233              :         }
    5234              :     }
    5235              : 
    5236    196099084 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    5237              :                                             context, complain))
    5238           42 :     return error_mark_node;
    5239              : 
    5240    196099042 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    5241         2176 :     return make_template_placeholder (t);
    5242              : 
    5243    196096866 :   if (want_template)
    5244              :     {
    5245      3439272 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    5246              :                                  NULL_TREE, context,
    5247              :                                  complain | tf_user);
    5248      3439272 :       if (t == error_mark_node)
    5249              :         return error_mark_node;
    5250      3439267 :       t = TYPE_NAME (t);
    5251              :     }
    5252              : 
    5253    196096861 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    5254      2382750 :     t = TREE_TYPE (t);
    5255              : 
    5256    196096861 :   maybe_record_typedef_use (t);
    5257              : 
    5258    196096861 :   return t;
    5259              : }
    5260              : 
    5261              : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    5262              :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    5263              :    in which case error_mark_node is returned.
    5264              : 
    5265              :    If PARM_LIST is non-NULL, also make sure that the template parameter
    5266              :    list of TEMPLATE_DECL matches.
    5267              : 
    5268              :    If COMPLAIN zero, don't complain about any errors that occur.  */
    5269              : 
    5270              : tree
    5271       186133 : make_unbound_class_template (tree context, tree name, tree parm_list,
    5272              :                              tsubst_flags_t complain)
    5273              : {
    5274       186133 :   if (TYPE_P (name))
    5275            0 :     name = TYPE_IDENTIFIER (name);
    5276       186133 :   else if (DECL_P (name))
    5277            0 :     name = DECL_NAME (name);
    5278       186133 :   gcc_assert (identifier_p (name));
    5279              : 
    5280       186133 :   if (!dependent_type_p (context)
    5281       186133 :       || currently_open_class (context))
    5282              :     {
    5283        92152 :       tree tmpl = NULL_TREE;
    5284              : 
    5285        92152 :       if (MAYBE_CLASS_TYPE_P (context))
    5286        92146 :         tmpl = lookup_field (context, name, 0, false);
    5287              : 
    5288        92146 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    5289            3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    5290              : 
    5291        92140 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    5292              :         {
    5293           12 :           if (complain & tf_error)
    5294            9 :             error ("no class template named %q#T in %q#T", name, context);
    5295           12 :           return error_mark_node;
    5296              :         }
    5297              : 
    5298        92140 :       if (parm_list
    5299        92140 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    5300              :         {
    5301            0 :           if (complain & tf_error)
    5302              :             {
    5303            0 :               auto_diagnostic_group d;
    5304            0 :               error ("template parameters do not match template %qD", tmpl);
    5305            0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    5306              :                       "%qD declared here", tmpl);
    5307            0 :             }
    5308            0 :           return error_mark_node;
    5309              :         }
    5310              : 
    5311        92140 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    5312              :                                           complain))
    5313            0 :         return error_mark_node;
    5314              : 
    5315              :       return tmpl;
    5316              :     }
    5317              : 
    5318        93981 :   return make_unbound_class_template_raw (context, name, parm_list);
    5319              : }
    5320              : 
    5321              : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    5322              : 
    5323              : tree
    5324        94033 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    5325              : {
    5326              :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    5327        94033 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    5328        94033 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    5329        94033 :   TREE_TYPE (t) = NULL_TREE;
    5330        94033 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    5331              : 
    5332              :   /* Build the corresponding TEMPLATE_DECL.  */
    5333        94033 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    5334        94033 :   TYPE_NAME (t) = d;
    5335        94033 :   TYPE_STUB_DECL (t) = d;
    5336        94033 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    5337        94033 :   DECL_ARTIFICIAL (d) = 1;
    5338        94033 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    5339              : 
    5340        94033 :   return t;
    5341              : }
    5342              : 
    5343              : 
    5344              : 
    5345              : /* Push the declarations of builtin types into the global namespace.
    5346              :    RID_INDEX is the index of the builtin type in the array
    5347              :    RID_POINTERS.  NAME is the name used when looking up the builtin
    5348              :    type.  TYPE is the _TYPE node for the builtin type.
    5349              : 
    5350              :    The calls to set_global_binding below should be
    5351              :    eliminated.  Built-in types should not be looked up name; their
    5352              :    names are keywords that the parser can recognize.  However, there
    5353              :    is code in c-common.cc that uses identifier_global_value to look up
    5354              :    built-in types by name.  */
    5355              : 
    5356              : void
    5357      4187768 : record_builtin_type (enum rid rid_index,
    5358              :                      const char* name,
    5359              :                      tree type)
    5360              : {
    5361      4187768 :   tree decl = NULL_TREE;
    5362              : 
    5363      4187768 :   if (name)
    5364              :     {
    5365      2471295 :       tree tname = get_identifier (name);
    5366      2471295 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    5367      2471295 :       DECL_ARTIFICIAL (tdecl) = 1;
    5368      2471295 :       set_global_binding (tdecl);
    5369      2471295 :       decl = tdecl;
    5370              :     }
    5371              : 
    5372      4187768 :   if ((int) rid_index < (int) RID_MAX)
    5373      2570896 :     if (tree rname = ridpointers[(int) rid_index])
    5374      1965082 :       if (!decl || DECL_NAME (decl) != rname)
    5375              :         {
    5376      1413566 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    5377      1413566 :           DECL_ARTIFICIAL (rdecl) = 1;
    5378      1413566 :           set_global_binding (rdecl);
    5379      1413566 :           if (!decl)
    5380              :             decl = rdecl;
    5381              :         }
    5382              : 
    5383      3884861 :   if (decl)
    5384              :     {
    5385      3581954 :       if (!TYPE_NAME (type))
    5386      2976140 :         TYPE_NAME (type) = decl;
    5387      3581954 :       debug_hooks->type_decl (decl, 0);
    5388              :     }
    5389      4187768 : }
    5390              : 
    5391              : /* Push a type into the namespace so that the back ends ignore it.  */
    5392              : 
    5393              : static void
    5394       302907 : record_unknown_type (tree type, const char* name)
    5395              : {
    5396       302907 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    5397              :                                     TYPE_DECL, get_identifier (name), type));
    5398              :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    5399       302907 :   DECL_IGNORED_P (decl) = 1;
    5400       302907 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    5401       302907 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    5402       302907 :   SET_TYPE_ALIGN (type, 1);
    5403       302907 :   TYPE_USER_ALIGN (type) = 0;
    5404       302907 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    5405       302907 : }
    5406              : 
    5407              : /* Create all the predefined identifiers.  */
    5408              : 
    5409              : static void
    5410       100969 : initialize_predefined_identifiers (void)
    5411              : {
    5412       100969 :   struct predefined_identifier
    5413              :   {
    5414              :     const char *name; /* Name.  */
    5415              :     tree *node;  /* Node to store it in.  */
    5416              :     cp_identifier_kind kind;  /* Kind of identifier.  */
    5417              :   };
    5418              : 
    5419              :   /* A table of identifiers to create at startup.  */
    5420       100969 :   static const predefined_identifier predefined_identifiers[] = {
    5421              :     {"C++", &lang_name_cplusplus, cik_normal},
    5422              :     {"C", &lang_name_c, cik_normal},
    5423              :     /* Some of these names have a trailing space so that it is
    5424              :        impossible for them to conflict with names written by users.  */
    5425              :     {"__ct ", &ctor_identifier, cik_ctor},
    5426              :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    5427              :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    5428              :     {"__dt ", &dtor_identifier, cik_dtor},
    5429              :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    5430              :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    5431              :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    5432              :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    5433              :     {"__in_chrg", &in_charge_identifier, cik_normal},
    5434              :     {"__as_base ", &as_base_identifier, cik_normal},
    5435              :     {"this", &this_identifier, cik_normal},
    5436              :     {"__delta", &delta_identifier, cik_normal},
    5437              :     {"__pfn", &pfn_identifier, cik_normal},
    5438              :     {"_vptr", &vptr_identifier, cik_normal},
    5439              :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    5440              :     {"::", &global_identifier, cik_normal},
    5441              :       /* The demangler expects anonymous namespaces to be called
    5442              :          something starting with '_GLOBAL__N_'.  It no longer needs
    5443              :          to be unique to the TU.  */
    5444              :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    5445              :     {"auto", &auto_identifier, cik_normal},
    5446              :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    5447              :     {"initializer_list", &init_list_identifier, cik_normal},
    5448              :     {"__for_range ", &for_range__identifier, cik_normal},
    5449              :     {"__for_begin ", &for_begin__identifier, cik_normal},
    5450              :     {"__for_end ", &for_end__identifier, cik_normal},
    5451              :     {"__for_range", &for_range_identifier, cik_normal},
    5452              :     {"__for_begin", &for_begin_identifier, cik_normal},
    5453              :     {"__for_end", &for_end_identifier, cik_normal},
    5454              :     {"abi_tag", &abi_tag_identifier, cik_normal},
    5455              :     {"aligned", &aligned_identifier, cik_normal},
    5456              :     {"begin", &begin_identifier, cik_normal},
    5457              :     {"end", &end_identifier, cik_normal},
    5458              :     {"get", &get__identifier, cik_normal},
    5459              :     {"gnu", &gnu_identifier, cik_normal},
    5460              :     {"tuple_element", &tuple_element_identifier, cik_normal},
    5461              :     {"tuple_size", &tuple_size_identifier, cik_normal},
    5462              :     {"type", &type_identifier, cik_normal},
    5463              :     {"value", &value_identifier, cik_normal},
    5464              :     {"_FUN", &fun_identifier, cik_normal},
    5465              :     {"__closure", &closure_identifier, cik_normal},
    5466              :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    5467              :     {"heap ", &heap_identifier, cik_normal},
    5468              :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    5469              :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    5470              :     {"heap []", &heap_vec_identifier, cik_normal},
    5471              :     {"omp", &omp_identifier, cik_normal},
    5472              :     {"internal ", &internal_identifier, cik_normal},
    5473              :     {"annotation ", &annotation_identifier, cik_normal},
    5474              :     {NULL, NULL, cik_normal}
    5475              :   };
    5476              : 
    5477      4947481 :   for (const predefined_identifier *pid = predefined_identifiers;
    5478      4947481 :        pid->name; ++pid)
    5479              :     {
    5480      4846512 :       *pid->node = get_identifier (pid->name);
    5481              :       /* Some of these identifiers already have a special kind.  */
    5482      4846512 :       if (pid->kind != cik_normal)
    5483       807752 :         set_identifier_kind (*pid->node, pid->kind);
    5484              :     }
    5485       100969 : }
    5486              : 
    5487              : /* Build a specific variant of operator new.  */
    5488              : 
    5489              : static void
    5490       180501 : cxx_build_operator_new (tree newtype)
    5491              : {
    5492       180501 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    5493       180501 :   DECL_IS_MALLOC (opnew) = 1;
    5494       180501 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5495       180501 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5496       180501 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    5497       180501 :   DECL_IS_MALLOC (opnew) = 1;
    5498       180501 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5499       180501 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5500       180501 : }
    5501              : 
    5502              : /* Build a specific variant of operator delete.  */
    5503              : 
    5504              : static void
    5505       340890 : cxx_build_operator_delete (tree deltype)
    5506              : {
    5507       340890 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    5508       340890 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5509       340890 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5510       340890 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    5511       340890 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5512       340890 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5513       340890 : }
    5514              : 
    5515              : /* Declare all variants of operator new and delete.  */
    5516              : 
    5517              : static void
    5518       100969 : cxx_init_operator_new_delete_decls (void)
    5519              : {
    5520       100969 :   tree newattrs, extvisattr;
    5521       100969 :   tree newtype, deltype;
    5522       100969 :   tree ptr_ftype_sizetype;
    5523       100969 :   tree new_eh_spec;
    5524       100969 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    5525              :                                                   ptr_type_node, NULL_TREE);
    5526       100969 :   void_ftype_ptr
    5527       100969 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    5528              : 
    5529       100969 :   ptr_ftype_sizetype
    5530       100969 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    5531       100969 :   if (cxx_dialect == cxx98)
    5532              :     {
    5533        14320 :       tree bad_alloc_id;
    5534        14320 :       tree bad_alloc_type_node;
    5535        14320 :       tree bad_alloc_decl;
    5536              : 
    5537        14320 :       push_nested_namespace (std_node);
    5538        14320 :       bad_alloc_id = get_identifier ("bad_alloc");
    5539        14320 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    5540        14320 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    5541        14320 :       bad_alloc_decl
    5542        14320 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    5543        14320 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    5544        14320 :       TREE_PUBLIC (bad_alloc_decl) = true;
    5545        14320 :       pop_nested_namespace (std_node);
    5546              : 
    5547        14320 :       new_eh_spec
    5548        14320 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    5549              :     }
    5550              :   else
    5551        86649 :     new_eh_spec = noexcept_false_spec;
    5552              : 
    5553       100969 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    5554              :                                 NULL_TREE);
    5555       100969 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    5556              :                         build_tree_list (NULL_TREE, integer_one_node),
    5557              :                         extvisattr);
    5558       100969 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    5559       100969 :   newtype = build_exception_variant (newtype, new_eh_spec);
    5560       100969 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    5561       100969 :   deltype = build_exception_variant (deltype, empty_except_spec);
    5562       100969 :   cxx_build_operator_new (newtype);
    5563       100969 :   cxx_build_operator_delete (deltype);
    5564       100969 :   if (flag_sized_deallocation)
    5565              :     {
    5566              :       /* Also push the sized deallocation variants:
    5567              :            void operator delete(void*, std::size_t) throw();
    5568              :            void operator delete[](void*, std::size_t) throw();  */
    5569        80864 :       tree void_ftype_ptr_size
    5570        80864 :         = build_function_type_list (void_type_node, ptr_type_node,
    5571              :                                     size_type_node, NULL_TREE);
    5572        80864 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    5573              :                                                  extvisattr);
    5574        80864 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5575        80864 :       cxx_build_operator_delete (deltype);
    5576              :     }
    5577              : 
    5578       100969 :   if (aligned_new_threshold)
    5579              :     {
    5580        79532 :       push_nested_namespace (std_node);
    5581        79532 :       tree align_id = get_identifier ("align_val_t");
    5582        79532 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    5583              :                                     NULL_TREE, /*scoped*/true, NULL);
    5584        79532 :       pop_nested_namespace (std_node);
    5585              : 
    5586              :       /* operator new (size_t, align_val_t); */
    5587        79532 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    5588              :                                           align_type_node, NULL_TREE);
    5589        79532 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    5590        79532 :       newtype = build_exception_variant (newtype, new_eh_spec);
    5591        79532 :       cxx_build_operator_new (newtype);
    5592              : 
    5593              :       /* operator delete (void *, align_val_t); */
    5594        79532 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    5595              :                                           align_type_node, NULL_TREE);
    5596        79532 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5597        79532 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5598        79532 :       cxx_build_operator_delete (deltype);
    5599              : 
    5600        79532 :       if (flag_sized_deallocation)
    5601              :         {
    5602              :           /* operator delete (void *, size_t, align_val_t); */
    5603        79525 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    5604              :                                               size_type_node, align_type_node,
    5605              :                                               NULL_TREE);
    5606        79525 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5607        79525 :           deltype = build_exception_variant (deltype, empty_except_spec);
    5608        79525 :           cxx_build_operator_delete (deltype);
    5609              :         }
    5610              :     }
    5611       100969 : }
    5612              : 
    5613              : /* Create the predefined scalar types of C,
    5614              :    and some nodes representing standard constants (0, 1, (void *)0).
    5615              :    Initialize the global binding level.
    5616              :    Make definitions for built-in primitive functions.  */
    5617              : 
    5618              : void
    5619       100969 : cxx_init_decl_processing (void)
    5620              : {
    5621       100969 :   tree void_ftype;
    5622              : 
    5623              :   /* Create all the identifiers we need.  */
    5624       100969 :   initialize_predefined_identifiers ();
    5625              : 
    5626              :   /* Create the global variables.  */
    5627       100969 :   push_to_top_level ();
    5628              : 
    5629       100969 :   current_function_decl = NULL_TREE;
    5630       100969 :   current_binding_level = NULL;
    5631              :   /* Enter the global namespace.  */
    5632       100969 :   gcc_assert (global_namespace == NULL_TREE);
    5633       100969 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5634              :                                       void_type_node);
    5635       100969 :   TREE_PUBLIC (global_namespace) = true;
    5636       100969 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5637       100969 :   DECL_CONTEXT (global_namespace)
    5638       100969 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5639              :   /* Remember whether we want the empty class passing ABI change warning
    5640              :      in this TU.  */
    5641       100969 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5642       126429 :     = warn_abi && abi_version_crosses (12);
    5643       100969 :   debug_hooks->register_main_translation_unit
    5644       100969 :     (DECL_CONTEXT (global_namespace));
    5645       100969 :   begin_scope (sk_namespace, global_namespace);
    5646       100969 :   current_namespace = global_namespace;
    5647              : 
    5648       100969 :   if (flag_visibility_ms_compat)
    5649            6 :     default_visibility = VISIBILITY_HIDDEN;
    5650              : 
    5651              :   /* Initially, C.  */
    5652       100969 :   current_lang_name = lang_name_c;
    5653              : 
    5654              :   /* Create the `std' namespace.  */
    5655       100969 :   push_namespace (get_identifier ("std"));
    5656       100969 :   std_node = current_namespace;
    5657       100969 :   pop_namespace ();
    5658              : 
    5659       100969 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5660              : 
    5661       100969 :   c_common_nodes_and_builtins ();
    5662              : 
    5663              :   /* Call the target stack_protect_guard hook if the stack protection
    5664              :      guard is declared as a global symbol.  */
    5665       100969 :   if (targetm.stack_protect_guard_symbol_p ())
    5666           24 :     pushdecl (targetm.stack_protect_guard ());
    5667              : 
    5668       100969 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5669       100969 :   tree decl
    5670       100969 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5671              :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5672              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5673       100969 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5674              : 
    5675              :   /* The concrete return type of __builtin_source_location is
    5676              :      const std::source_location::__impl*, but we can't form the type
    5677              :      at this point.  So we initially declare it with an auto return
    5678              :      type which we then "deduce" from require_deduced_type upon first use.  */
    5679       100969 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5680       100969 :   decl = add_builtin_function ("__builtin_source_location",
    5681              :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5682              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5683       100969 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5684              : 
    5685       100969 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5686              :                                                         NULL_TREE);
    5687       100969 :   decl
    5688       100969 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5689              :                             bool_vaftype,
    5690              :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5691              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5692       100969 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5693              : 
    5694       100969 :   decl
    5695       100969 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5696              :                             bool_vaftype,
    5697              :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5698              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5699       100969 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5700              : 
    5701       100969 :   if (cxx_dialect >= cxx26)
    5702              :     {
    5703        25693 :       tree void_ptrintftype
    5704        25693 :         = build_function_type_list (void_type_node, ptr_type_node,
    5705              :                                     integer_type_node, NULL_TREE);
    5706        25693 :       decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
    5707              :                                    void_ptrintftype,
    5708              :                                    CP_BUILT_IN_EH_PTR_ADJUST_REF,
    5709              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5710        25693 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5711              : 
    5712              :       /* Similar case to __builtin_source_location above.  The concrete
    5713              :          return type is std::exception_ptr, but we can't form the type
    5714              :          at this point, so it is deduced later.  */
    5715        25693 :       decl = add_builtin_function ("__builtin_current_exception",
    5716              :                                    auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
    5717              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5718        25693 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5719              : 
    5720        25693 :       tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
    5721        25693 :       decl = add_builtin_function ("__builtin_uncaught_exceptions",
    5722              :                                    int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
    5723              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5724        25693 :       set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
    5725              :     }
    5726              : 
    5727       100969 :   decl
    5728       100969 :     = add_builtin_function ("__builtin_is_string_literal",
    5729              :                             bool_vaftype,
    5730              :                             CP_BUILT_IN_IS_STRING_LITERAL,
    5731              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5732       100969 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5733              : 
    5734       100969 :   tree void_vaintftype = build_varargs_function_type_list (void_type_node,
    5735              :                                                            integer_type_node,
    5736              :                                                            NULL_TREE);
    5737       100969 :   decl = add_builtin_function ("__builtin_constexpr_diag",
    5738              :                                void_vaintftype,
    5739              :                                CP_BUILT_IN_CONSTEXPR_DIAG,
    5740              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5741       100969 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5742              : 
    5743       100969 :   decl = add_builtin_function ("__builtin_is_within_lifetime",
    5744              :                                bool_vaftype, CP_BUILT_IN_IS_WITHIN_LIFETIME,
    5745              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5746       100969 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5747       100969 :   SET_DECL_IMMEDIATE_FUNCTION_P (decl);
    5748              : 
    5749       100969 :   tree void_vaftype = build_varargs_function_type_list (void_type_node,
    5750              :                                                         NULL_TREE);
    5751       100969 :   decl = add_builtin_function ("__builtin_start_lifetime",
    5752              :                                void_vaftype, CP_BUILT_IN_START_LIFETIME,
    5753              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5754       100969 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5755              : 
    5756       100969 :   integer_two_node = build_int_cst (integer_type_node, 2);
    5757              : 
    5758              :   /* Guess at the initial static decls size.  */
    5759       100969 :   vec_alloc (static_decls, 500);
    5760              : 
    5761              :   /* ... and keyed classes.  */
    5762       100969 :   vec_alloc (keyed_classes, 100);
    5763              : 
    5764       100969 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5765       100969 :   truthvalue_type_node = boolean_type_node;
    5766       100969 :   truthvalue_false_node = boolean_false_node;
    5767       100969 :   truthvalue_true_node = boolean_true_node;
    5768              : 
    5769       100969 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5770       100969 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5771       100969 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5772       100969 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5773              :                                             NULL_TREE);
    5774              : 
    5775              : #if 0
    5776              :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5777              : #endif
    5778              : 
    5779       100969 :   delta_type_node = ptrdiff_type_node;
    5780       100969 :   vtable_index_type = ptrdiff_type_node;
    5781              : 
    5782       100969 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5783       100969 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5784              : 
    5785              :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5786              :      is in the identifier table, so we can use identifier equality to
    5787              :      find it.  */
    5788       100969 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5789              :                                     void_ftype);
    5790              : 
    5791              :   /* C++ extensions */
    5792              : 
    5793       100969 :   unknown_type_node = make_node (LANG_TYPE);
    5794       100969 :   record_unknown_type (unknown_type_node, "unknown type");
    5795              : 
    5796              :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5797       100969 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5798              : 
    5799              :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5800              :      result.  */
    5801       100969 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5802       100969 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5803              : 
    5804       100969 :   init_list_type_node = make_node (LANG_TYPE);
    5805       100969 :   record_unknown_type (init_list_type_node, "init list");
    5806              : 
    5807              :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5808       100969 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5809              : 
    5810       100969 :   {
    5811              :     /* Make sure we get a unique function type, so we can give
    5812              :        its pointer type a name.  (This wins for gdb.) */
    5813       100969 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5814       100969 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5815       100969 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5816       100969 :     layout_type (vfunc_type);
    5817              : 
    5818       100969 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5819              :   }
    5820       100969 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5821              : 
    5822       100969 :   vtbl_type_node
    5823       100969 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5824       100969 :   layout_type (vtbl_type_node);
    5825       100969 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5826       100969 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5827       100969 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5828       100969 :   layout_type (vtbl_ptr_type_node);
    5829       100969 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5830              : 
    5831       100969 :   push_namespace (get_identifier ("__cxxabiv1"));
    5832       100969 :   abi_node = current_namespace;
    5833       100969 :   pop_namespace ();
    5834              : 
    5835       100969 :   any_targ_node = make_node (LANG_TYPE);
    5836       100969 :   record_unknown_type (any_targ_node, "any type");
    5837              : 
    5838              :   /* Now, C++.  */
    5839       100969 :   current_lang_name = lang_name_cplusplus;
    5840              : 
    5841       100969 :   if (aligned_new_threshold > 1
    5842       100969 :       && !pow2p_hwi (aligned_new_threshold))
    5843              :     {
    5844            0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5845              :              aligned_new_threshold);
    5846            0 :       aligned_new_threshold = 1;
    5847              :     }
    5848       100969 :   if (aligned_new_threshold == -1)
    5849       122392 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5850       100969 :   if (aligned_new_threshold == 1)
    5851        79529 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5852              : 
    5853              :   /* Ensure attribs.cc is initialized.  */
    5854       100969 :   init_attributes ();
    5855       100969 :   cxx_init_operator_new_delete_decls ();
    5856              : 
    5857              :   /* C++-specific nullptr initialization.  */
    5858       100969 :   if (abi_version_at_least (9))
    5859       100798 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5860       100969 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5861              : 
    5862       100969 :   if (! supports_one_only ())
    5863            0 :     flag_weak = 0;
    5864              : 
    5865       100969 :   abort_fndecl
    5866       100969 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5867              :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5868       100969 :   if (flag_weak)
    5869              :     /* If no definition is available, resolve references to NULL.  */
    5870       100939 :     declare_weak (abort_fndecl);
    5871              : 
    5872              :   /* Perform other language dependent initializations.  */
    5873       100969 :   init_class_processing ();
    5874       100969 :   init_rtti_processing ();
    5875       100969 :   init_template_processing ();
    5876              : 
    5877       100969 :   if (flag_exceptions)
    5878        99709 :     init_exception_processing ();
    5879              : 
    5880       100969 :   if (flag_contracts)
    5881        25740 :     init_contracts ();
    5882              : 
    5883       100969 :   if (modules_p ())
    5884         5036 :     init_modules (parse_in);
    5885              : 
    5886       100969 :   if (flag_reflection)
    5887         1368 :     init_reflection ();
    5888              : 
    5889       100969 :   make_fname_decl = cp_make_fname_decl;
    5890       100969 :   start_fname_decls ();
    5891              : 
    5892              :   /* Show we use EH for cleanups.  */
    5893       100969 :   if (flag_exceptions)
    5894        99709 :     using_eh_for_cleanups ();
    5895              : 
    5896              :   /* Check that the hardware interference sizes are at least
    5897              :      alignof(max_align_t), as required by the standard.  */
    5898       100969 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5899       100969 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5900              :     {
    5901            0 :       if (param_destruct_interfere_size < max_align)
    5902            0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5903              :                "%d", param_destruct_interfere_size, max_align);
    5904            0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5905            0 :         warning (OPT_Winterference_size,
    5906              :                  "%<--param destructive-interference-size=%d%> "
    5907              :                  "is less than %<--param l1-cache-line-size=%d%>",
    5908              :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5909              :     }
    5910       100969 :   else if (param_destruct_interfere_size)
    5911              :     /* Assume the internal value is OK.  */;
    5912            0 :   else if (param_l1_cache_line_size >= max_align)
    5913            0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5914              :   /* else leave it unset.  */
    5915              : 
    5916       100969 :   if (OPTION_SET_P (param_construct_interfere_size))
    5917              :     {
    5918            0 :       if (param_construct_interfere_size < max_align)
    5919            0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5920              :                "%d", param_construct_interfere_size, max_align);
    5921            0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5922            0 :                && param_l1_cache_line_size >= max_align)
    5923            0 :         warning (OPT_Winterference_size,
    5924              :                  "%<--param constructive-interference-size=%d%> "
    5925              :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5926              :                  param_construct_interfere_size, param_l1_cache_line_size);
    5927              :     }
    5928       100969 :   else if (param_construct_interfere_size)
    5929              :     /* Assume the internal value is OK.  */;
    5930            0 :   else if (param_l1_cache_line_size >= max_align)
    5931            0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5932       100969 : }
    5933              : 
    5934              : /* Enter an abi node in global-module context.  returns a cookie to
    5935              :    give to pop_abi_namespace.  */
    5936              : 
    5937              : unsigned
    5938        58942 : push_abi_namespace (tree node)
    5939              : {
    5940        58942 :   push_nested_namespace (node);
    5941        58942 :   push_visibility ("default", 2);
    5942        58942 :   unsigned flags = module_kind;
    5943        58942 :   module_kind = 0;
    5944        58942 :   return flags;
    5945              : }
    5946              : 
    5947              : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5948              :    you.  */
    5949              : 
    5950              : void
    5951        58942 : pop_abi_namespace (unsigned flags, tree node)
    5952              : {
    5953        58942 :   module_kind = flags;
    5954        58942 :   pop_visibility (2);
    5955        58942 :   pop_nested_namespace (node);
    5956        58942 : }
    5957              : 
    5958              : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5959              :    the decl, LOC is the location to give the decl, NAME is the
    5960              :    initialization string and TYPE_DEP indicates whether NAME depended
    5961              :    on the type of the function. We make use of that to detect
    5962              :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5963              :    at the point of first use, so we mustn't push the decl now.  */
    5964              : 
    5965              : static tree
    5966       245439 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5967              : {
    5968       245439 :   tree domain = NULL_TREE;
    5969       245439 :   tree init = NULL_TREE;
    5970              : 
    5971       245439 :   if (!(type_dep && current_function_decl && in_template_context))
    5972              :     {
    5973        60674 :       const char *name = NULL;
    5974        60674 :       bool release_name = false;
    5975              : 
    5976        60674 :       if (current_function_decl == NULL_TREE)
    5977              :         name = "top level";
    5978        60660 :       else if (type_dep == 0)
    5979              :         {
    5980              :           /* __FUNCTION__ */
    5981          838 :           name = fname_as_string (type_dep);
    5982          838 :           release_name = true;
    5983              :         }
    5984              :       else
    5985              :         {
    5986              :           /* __PRETTY_FUNCTION__ */
    5987        59822 :           gcc_checking_assert (type_dep == 1);
    5988        59822 :           name = cxx_printable_name (current_function_decl, 2);
    5989              :         }
    5990              : 
    5991        60660 :       if (!release_name)
    5992              :         {
    5993        59836 :           cpp_string cstr = { 0, 0 }, strname;
    5994        59836 :           strname.text
    5995        59836 :             = const_cast <unsigned char *> ((const unsigned char *) name);
    5996        59836 :           strname.len = strlen (name) + 1;
    5997        59836 :           if (cpp_translate_string (parse_in, &strname, &cstr, CPP_STRING,
    5998              :                                     false))
    5999              :             {
    6000        59836 :               name = (const char *) cstr.text;
    6001        59836 :               release_name = true;
    6002              :             }
    6003              :         }
    6004              : 
    6005        60674 :       size_t length = strlen (name);
    6006        60674 :       domain = build_index_type (size_int (length));
    6007        60674 :       init = build_string (length + 1, name);
    6008        60674 :       if (release_name)
    6009        60674 :         free (const_cast<char *> (name));
    6010              :     }
    6011              : 
    6012       245439 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    6013       245439 :   type = build_cplus_array_type (type, domain);
    6014              : 
    6015       245439 :   if (init)
    6016        60674 :     TREE_TYPE (init) = type;
    6017              :   else
    6018       184765 :     init = error_mark_node;
    6019              : 
    6020       245439 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    6021              : 
    6022       245439 :   TREE_READONLY (decl) = 1;
    6023       245439 :   DECL_ARTIFICIAL (decl) = 1;
    6024       245439 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    6025       245439 :   TREE_STATIC (decl) = 1;
    6026              : 
    6027       245439 :   TREE_USED (decl) = 1;
    6028              : 
    6029       245439 :   SET_DECL_VALUE_EXPR (decl, init);
    6030       245439 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    6031              :   /* For decl_constant_var_p.  */
    6032       245439 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    6033              : 
    6034       245439 :   if (current_function_decl)
    6035              :     {
    6036       245425 :       DECL_CONTEXT (decl) = current_function_decl;
    6037       245425 :       decl = pushdecl_outermost_localscope (decl);
    6038       245425 :       if (decl != error_mark_node)
    6039       245422 :         add_decl_expr (decl);
    6040              :       else
    6041            3 :         gcc_assert (seen_error ());
    6042              :     }
    6043              :   else
    6044              :     {
    6045           14 :       DECL_THIS_STATIC (decl) = true;
    6046           14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    6047              :     }
    6048              : 
    6049       245439 :   return decl;
    6050              : }
    6051              : 
    6052              : /* Install DECL as a builtin function at current global scope.  Return
    6053              :    the new decl (if we found an existing version).  Also installs it
    6054              :    into ::std, if it's not '_*'.  */
    6055              : 
    6056              : tree
    6057    235004867 : cxx_builtin_function (tree decl)
    6058              : {
    6059    235004867 :   retrofit_lang_decl (decl);
    6060              : 
    6061    235004867 :   DECL_ARTIFICIAL (decl) = 1;
    6062    235004867 :   SET_DECL_LANGUAGE (decl, lang_c);
    6063              :   /* Runtime library routines are, by definition, available in an
    6064              :      external shared object.  */
    6065    235004867 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    6066    235004867 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    6067              : 
    6068    235004867 :   tree id = DECL_NAME (decl);
    6069    235004867 :   const char *name = IDENTIFIER_POINTER (id);
    6070    235004867 :   bool hiding = false;
    6071    235004867 :   if (name[0] != '_' || name[1] != '_')
    6072              :     /* In the user's namespace, it must be declared before use.  */
    6073              :     hiding = true;
    6074    197352887 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    6075    197352887 :            && !startswith (name + 2, "builtin_")
    6076    220796903 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    6077              :                            "_chk", strlen ("_chk") + 1))
    6078              :     /* Treat __*_chk fortification functions as anticipated as well,
    6079              :        unless they are __builtin_*_chk.  */
    6080              :     hiding = true;
    6081              : 
    6082              :   /* All builtins that don't begin with an '_' should additionally
    6083              :      go in the 'std' namespace.  */
    6084    235004867 :   if (name[0] != '_')
    6085              :     {
    6086     37514795 :       tree std_decl = copy_decl (decl);
    6087              : 
    6088     37514795 :       push_nested_namespace (std_node);
    6089     37514795 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    6090     37514795 :       pushdecl (std_decl, hiding);
    6091     37514795 :       pop_nested_namespace (std_node);
    6092              :     }
    6093              : 
    6094    235004867 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6095    235004867 :   decl = pushdecl (decl, hiding);
    6096              : 
    6097    235004867 :   return decl;
    6098              : }
    6099              : 
    6100              : /* Like cxx_builtin_function, but guarantee the function is added to the global
    6101              :    scope.  This is to allow function specific options to add new machine
    6102              :    dependent builtins when the target ISA changes via attribute((target(...)))
    6103              :    which saves space on program startup if the program does not use non-generic
    6104              :    ISAs.  */
    6105              : 
    6106              : tree
    6107       832322 : cxx_builtin_function_ext_scope (tree decl)
    6108              : {
    6109       832322 :   push_nested_namespace (global_namespace);
    6110       832322 :   decl = cxx_builtin_function (decl);
    6111       832322 :   pop_nested_namespace (global_namespace);
    6112              : 
    6113       832322 :   return decl;
    6114              : }
    6115              : 
    6116              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    6117              : 
    6118              : tree
    6119            0 : cxx_simulate_builtin_function_decl (tree decl)
    6120              : {
    6121            0 :   retrofit_lang_decl (decl);
    6122              : 
    6123            0 :   DECL_ARTIFICIAL (decl) = 1;
    6124            0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    6125            0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6126            0 :   return pushdecl (decl);
    6127              : }
    6128              : 
    6129              : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    6130              :    function.  Not called directly.  */
    6131              : 
    6132              : static tree
    6133      1628488 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    6134              :                   int ecf_flags)
    6135              : {
    6136      1628488 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    6137      1628488 :   DECL_EXTERNAL (fn) = 1;
    6138      1628488 :   TREE_PUBLIC (fn) = 1;
    6139      1628488 :   DECL_ARTIFICIAL (fn) = 1;
    6140      1628488 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    6141      1628488 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    6142      1628488 :   SET_DECL_LANGUAGE (fn, lang_c);
    6143              :   /* Runtime library routines are, by definition, available in an
    6144              :      external shared object.  */
    6145      1628488 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    6146      1628488 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    6147      1628488 :   set_call_expr_flags (fn, ecf_flags);
    6148      1628488 :   return fn;
    6149              : }
    6150              : 
    6151              : /* Returns the _DECL for a library function with C++ linkage.  */
    6152              : 
    6153              : static tree
    6154      1142755 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    6155              :                      int ecf_flags)
    6156              : {
    6157      1142755 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    6158      1142755 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    6159      1142755 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    6160      1142755 :   return fn;
    6161              : }
    6162              : 
    6163              : /* Like build_library_fn, but takes a C string instead of an
    6164              :    IDENTIFIER_NODE.  */
    6165              : 
    6166              : tree
    6167       105992 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6168              : {
    6169       105992 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    6170              : }
    6171              : 
    6172              : /* Like build_cp_library_fn, but takes a C string instead of an
    6173              :    IDENTIFIER_NODE.  */
    6174              : 
    6175              : tree
    6176        99973 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6177              : {
    6178        99973 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    6179        99973 :                               ecf_flags);
    6180              : }
    6181              : 
    6182              : /* Like build_library_fn, but also pushes the function so that we will
    6183              :    be able to find it via get_global_binding.  Also, the function
    6184              :    may throw exceptions listed in RAISES.  */
    6185              : 
    6186              : tree
    6187       379741 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    6188              : {
    6189       379741 :   if (raises)
    6190        42660 :     type = build_exception_variant (type, raises);
    6191              : 
    6192       379741 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    6193       379741 :   return pushdecl_top_level (fn);
    6194              : }
    6195              : 
    6196              : /* Like build_cp_library_fn, but also pushes the function so that it
    6197              :    will be found by normal lookup.  */
    6198              : 
    6199              : static tree
    6200      1042782 : push_cp_library_fn (enum tree_code operator_code, tree type,
    6201              :                     int ecf_flags)
    6202              : {
    6203      1042782 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    6204              :                                  operator_code, type, ecf_flags);
    6205      1042782 :   pushdecl (fn);
    6206      1042782 :   if (flag_tm)
    6207         2980 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    6208      1042782 :   return fn;
    6209              : }
    6210              : 
    6211              : /* Like push_library_fn, but also note that this function throws
    6212              :    and does not return.  Used for __throw_foo and the like.  */
    6213              : 
    6214              : tree
    6215       110685 : push_throw_library_fn (tree name, tree type)
    6216              : {
    6217       110685 :   tree fn = push_library_fn (name, type, NULL_TREE,
    6218              :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    6219       110685 :   return fn;
    6220              : }
    6221              : 
    6222              : /* When we call finish_struct for an anonymous union, we create
    6223              :    default copy constructors and such.  But, an anonymous union
    6224              :    shouldn't have such things; this function undoes the damage to the
    6225              :    anonymous union type T.
    6226              : 
    6227              :    (The reason that we create the synthesized methods is that we don't
    6228              :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    6229              :    The first is an anonymous union; the second is just an ordinary
    6230              :    union type.)  */
    6231              : 
    6232              : void
    6233       178511 : fixup_anonymous_aggr (tree t)
    6234              : {
    6235              :   /* Wipe out memory of synthesized methods.  */
    6236       178511 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    6237       178511 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    6238       178511 :   TYPE_HAS_COPY_CTOR (t) = 0;
    6239       178511 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    6240       178511 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    6241       178511 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    6242              : 
    6243              :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    6244              :      invalid members.  */
    6245      1044138 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    6246              :     {
    6247       865627 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    6248            0 :         *prev_p = DECL_CHAIN (probe);
    6249              :       else
    6250       865627 :         prev_p = &DECL_CHAIN (probe);
    6251              : 
    6252       865627 :       if (DECL_ARTIFICIAL (probe)
    6253       865627 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    6254        78028 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    6255       293685 :         continue;
    6256              : 
    6257       571942 :       if (TREE_CODE (probe) != FIELD_DECL
    6258       571888 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    6259              :         {
    6260              :           /* We already complained about static data members in
    6261              :              finish_static_data_member_decl.  */
    6262           66 :           if (!VAR_P (probe))
    6263              :             {
    6264           51 :               auto_diagnostic_group d;
    6265           51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    6266           51 :                              TREE_CODE (t) == UNION_TYPE
    6267              :                              ? "%q#D invalid; an anonymous union may "
    6268              :                              "only have public non-static data members"
    6269              :                              : "%q#D invalid; an anonymous struct may "
    6270              :                              "only have public non-static data members", probe))
    6271              :                 {
    6272           51 :                   static bool hint;
    6273           51 :                   if (flag_permissive && !hint)
    6274              :                     {
    6275            6 :                       hint = true;
    6276            6 :                       inform (DECL_SOURCE_LOCATION (probe),
    6277              :                               "this flexibility is deprecated and will be "
    6278              :                               "removed");
    6279              :                     }
    6280              :                 }
    6281           51 :             }
    6282              :         }
    6283              :       }
    6284              : 
    6285              :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    6286       178511 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    6287       178511 :   unsigned store = 0;
    6288       530342 :   for (tree elt : vec)
    6289       351831 :     if (!is_overloaded_fn (elt))
    6290       351810 :       (*vec)[store++] = elt;
    6291       178511 :   vec_safe_truncate (vec, store);
    6292              : 
    6293              :   /* Wipe RTTI info.  */
    6294       178511 :   SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
    6295              : 
    6296              :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    6297              :      assignment operators (because they cannot have these methods themselves).
    6298              :      For anonymous unions this is already checked because they are not allowed
    6299              :      in any union, otherwise we have to check it.  */
    6300       178511 :   if (TREE_CODE (t) != UNION_TYPE)
    6301              :     {
    6302        38021 :       tree field, type;
    6303              : 
    6304        38021 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    6305              :         {
    6306            9 :           error_at (location_of (t), "anonymous struct with base classes");
    6307              :           /* Avoid ICE after error on anon-struct9.C.  */
    6308            9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    6309              :         }
    6310              : 
    6311       152928 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6312       114907 :         if (TREE_CODE (field) == FIELD_DECL)
    6313              :           {
    6314        76785 :             type = TREE_TYPE (field);
    6315        76785 :             if (CLASS_TYPE_P (type))
    6316              :               {
    6317           61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    6318            6 :                   error ("member %q+#D with constructor not allowed "
    6319              :                          "in anonymous aggregate", field);
    6320           61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6321            0 :                   error ("member %q+#D with destructor not allowed "
    6322              :                          "in anonymous aggregate", field);
    6323           61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    6324            0 :                   error ("member %q+#D with copy assignment operator "
    6325              :                          "not allowed in anonymous aggregate", field);
    6326              :               }
    6327              :           }
    6328              :     }
    6329       178511 : }
    6330              : 
    6331              : /* Warn for an attribute located at LOCATION that appertains to the
    6332              :    class type CLASS_TYPE that has not been properly placed after its
    6333              :    class-key, in it class-specifier.  */
    6334              : 
    6335              : void
    6336          117 : warn_misplaced_attr_for_class_type (location_t location,
    6337              :                                     tree class_type)
    6338              : {
    6339          117 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    6340              : 
    6341          117 :   auto_diagnostic_group d;
    6342          117 :   if (warning_at (location, OPT_Wattributes,
    6343              :                   "attribute ignored in declaration "
    6344              :                   "of %q#T", class_type))
    6345          117 :     inform (location,
    6346              :             "attribute for %q#T must follow the %qs keyword",
    6347              :             class_type, class_key_or_enum_as_string (class_type));
    6348          117 : }
    6349              : 
    6350              : /* Returns the cv-qualifiers that apply to the type specified
    6351              :    by the DECLSPECS.  */
    6352              : 
    6353              : static cv_qualifier
    6354   1075342802 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    6355              : {
    6356   1075342802 :   auto type_quals = TYPE_UNQUALIFIED;
    6357              : 
    6358   1075342802 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6359    110994239 :     type_quals |= TYPE_QUAL_CONST;
    6360   1075342802 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6361      1788580 :     type_quals |= TYPE_QUAL_VOLATILE;
    6362   1075342802 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6363           34 :     type_quals |= TYPE_QUAL_RESTRICT;
    6364              : 
    6365   1075342802 :   return type_quals;
    6366              : }
    6367              : 
    6368              : /* Make sure that a declaration with no declarator is well-formed, i.e.
    6369              :    just declares a tagged type or anonymous union.
    6370              : 
    6371              :    Returns the type declared; or NULL_TREE if none.  */
    6372              : 
    6373              : tree
    6374     38662904 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    6375              :                 bool explicit_type_instantiation_p)
    6376              : {
    6377     38662904 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    6378     38662904 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    6379              :   /* If a class, struct, or enum type is declared by the DECLSPECS
    6380              :      (i.e, if a class-specifier, enum-specifier, or non-typename
    6381              :      elaborated-type-specifier appears in the DECLSPECS),
    6382              :      DECLARED_TYPE is set to the corresponding type.  */
    6383     38662904 :   tree declared_type = NULL_TREE;
    6384     38662904 :   bool error_p = false;
    6385              : 
    6386     38662904 :   if (declspecs->multiple_types_p)
    6387           26 :     error_at (smallest_type_location (declspecs),
    6388              :               "multiple types in one declaration");
    6389     38662878 :   else if (declspecs->redefined_builtin_type)
    6390              :     {
    6391           21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    6392           21 :       if (!in_system_header_at (loc))
    6393            9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    6394              :                    declspecs->redefined_builtin_type);
    6395              :       return NULL_TREE;
    6396              :     }
    6397              : 
    6398     38662883 :   if (declspecs->type
    6399     38662868 :       && TYPE_P (declspecs->type)
    6400     76946196 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    6401     38282254 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    6402      1926823 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    6403              :     declared_type = declspecs->type;
    6404       380674 :   else if (declspecs->type == error_mark_node)
    6405         1496 :     error_p = true;
    6406              : 
    6407     38662883 :   if (type_uses_auto (declared_type))
    6408              :     {
    6409            8 :       error_at (declspecs->locations[ds_type_spec],
    6410              :                 "%<auto%> can only be specified for variables "
    6411              :                 "or function declarations");
    6412            8 :       return error_mark_node;
    6413              :     }
    6414              : 
    6415     38662875 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    6416              :     declared_type = NULL_TREE;
    6417              : 
    6418     38662875 :   if (!declared_type && !saw_friend && !error_p)
    6419           91 :     permerror (input_location, "declaration does not declare anything");
    6420              :   /* Check for an anonymous union.  */
    6421     38282174 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    6422    111554211 :            && TYPE_UNNAMED_P (declared_type))
    6423              :     {
    6424              :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    6425              :          can be omitted only when declaring a class (clause 9) or
    6426              :          enumeration (7.2), that is, when the decl-specifier-seq contains
    6427              :          either a class-specifier, an elaborated-type-specifier with
    6428              :          a class-key (9.1), or an enum-specifier.  In these cases and
    6429              :          whenever a class-specifier or enum-specifier is present in the
    6430              :          decl-specifier-seq, the identifiers in these specifiers are among
    6431              :          the names being declared by the declaration (as class-name,
    6432              :          enum-names, or enumerators, depending on the syntax).  In such
    6433              :          cases, and except for the declaration of an unnamed bit-field (9.6),
    6434              :          the decl-specifier-seq shall introduce one or more names into the
    6435              :          program, or shall redeclare a name introduced by a previous
    6436              :          declaration.  [Example:
    6437              :              enum { };                  // ill-formed
    6438              :              typedef class { };         // ill-formed
    6439              :          --end example]  */
    6440       178517 :       if (saw_typedef)
    6441              :         {
    6442            6 :           error_at (declspecs->locations[ds_typedef],
    6443              :                     "missing type-name in typedef-declaration");
    6444            6 :           return NULL_TREE;
    6445              :         }
    6446       178511 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    6447       178511 :       SET_ANON_AGGR_TYPE_P (declared_type);
    6448              : 
    6449       178511 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    6450        38021 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    6451        38021 :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    6452              :     }
    6453              : 
    6454              :   else
    6455              :     {
    6456     38484267 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    6457            9 :         error_at (declspecs->locations[ds_inline],
    6458              :                   "%<inline%> can only be specified for functions");
    6459     38484258 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    6460            3 :         error_at (declspecs->locations[ds_virtual],
    6461              :                   "%<virtual%> can only be specified for functions");
    6462     38484255 :       else if (saw_friend
    6463     38484255 :                && (!current_class_type
    6464      2169311 :                    || current_scope () != current_class_type))
    6465            0 :         error_at (declspecs->locations[ds_friend],
    6466              :                   "%<friend%> can only be specified inside a class");
    6467     38484255 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    6468            3 :         error_at (declspecs->locations[ds_explicit],
    6469              :                   "%<explicit%> can only be specified for constructors");
    6470     38484252 :       else if (declspecs->storage_class)
    6471            3 :         error_at (declspecs->locations[ds_storage_class],
    6472              :                   "a storage class can only be specified for objects "
    6473              :                   "and functions");
    6474     38484249 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6475            9 :         error_at (declspecs->locations[ds_const],
    6476              :                   "%<const%> can only be specified for objects and "
    6477              :                   "functions");
    6478     38484240 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6479            3 :         error_at (declspecs->locations[ds_volatile],
    6480              :                   "%<volatile%> can only be specified for objects and "
    6481              :                   "functions");
    6482     38484237 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6483            3 :         error_at (declspecs->locations[ds_restrict],
    6484              :                   "%<__restrict%> can only be specified for objects and "
    6485              :                   "functions");
    6486     38484234 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    6487            3 :         error_at (declspecs->locations[ds_thread],
    6488              :                   "%<__thread%> can only be specified for objects "
    6489              :                   "and functions");
    6490     38484231 :       else if (saw_typedef)
    6491           24 :         warning_at (declspecs->locations[ds_typedef], 0,
    6492              :                     "%<typedef%> was ignored in this declaration");
    6493     38484207 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    6494            9 :         error_at (declspecs->locations[ds_constexpr],
    6495              :                   "%qs cannot be used for type declarations", "constexpr");
    6496     38484198 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    6497            3 :         error_at (declspecs->locations[ds_constinit],
    6498              :                   "%qs cannot be used for type declarations", "constinit");
    6499     38484195 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    6500            3 :         error_at (declspecs->locations[ds_consteval],
    6501              :                   "%qs cannot be used for type declarations", "consteval");
    6502              :     }
    6503              : 
    6504     38662869 :   if (declspecs->attributes && warn_attributes && declared_type)
    6505              :     {
    6506           30 :       location_t loc;
    6507           24 :       if (!CLASS_TYPE_P (declared_type)
    6508           54 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    6509              :         /* For a non-template class, use the name location.  */
    6510           21 :         loc = location_of (declared_type);
    6511              :       else
    6512              :         /* For a template class (an explicit instantiation), use the
    6513              :            current location.  */
    6514            9 :         loc = input_location;
    6515              : 
    6516           30 :       if (explicit_type_instantiation_p)
    6517              :         /* [dcl.attr.grammar]/4:
    6518              : 
    6519              :                No attribute-specifier-seq shall appertain to an explicit
    6520              :                instantiation.  */
    6521              :         {
    6522            6 :           auto_diagnostic_group d;
    6523            6 :           if (warning_at (loc, OPT_Wattributes,
    6524              :                           "attribute ignored in explicit instantiation %q#T",
    6525              :                           declared_type))
    6526            6 :             inform (loc,
    6527              :                     "no attribute can be applied to "
    6528              :                     "an explicit instantiation");
    6529            6 :         }
    6530              :       else
    6531           24 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    6532              :     }
    6533              : 
    6534     38662869 :   if (declspecs->std_attributes
    6535           93 :       && declared_type
    6536     38662959 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    6537              :     {
    6538           90 :       auto_diagnostic_group d;
    6539           90 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    6540              :                       "attribute ignored"))
    6541           90 :         inform (declspecs->locations[ds_std_attribute],
    6542              :                 "an attribute that appertains to a type-specifier is ignored");
    6543           90 :     }
    6544              : 
    6545              :   return declared_type;
    6546              : }
    6547              : 
    6548              : /* Called when a declaration is seen that contains no names to declare.
    6549              :    If its type is a reference to a structure, union or enum inherited
    6550              :    from a containing scope, shadow that tag name for the current scope
    6551              :    with a forward reference.
    6552              :    If its type defines a new named structure or union
    6553              :    or defines an enum, it is valid but we need not do anything here.
    6554              :    Otherwise, it is an error.
    6555              : 
    6556              :    C++: may have to grok the declspecs to learn about static,
    6557              :    complain for anonymous unions.
    6558              : 
    6559              :    Returns the TYPE declared -- or NULL_TREE if none.  */
    6560              : 
    6561              : tree
    6562     33881284 : shadow_tag (cp_decl_specifier_seq *declspecs)
    6563              : {
    6564     33881284 :   tree t = check_tag_decl (declspecs,
    6565              :                            /*explicit_type_instantiation_p=*/false);
    6566              : 
    6567     33881284 :   if (!t)
    6568              :     return NULL_TREE;
    6569              : 
    6570     33879772 :   t = maybe_process_partial_specialization (t);
    6571     33879772 :   if (t == error_mark_node)
    6572              :     return NULL_TREE;
    6573              : 
    6574              :   /* This is where the variables in an anonymous union are
    6575              :      declared.  An anonymous union declaration looks like:
    6576              :      union { ... } ;
    6577              :      because there is no declarator after the union, the parser
    6578              :      sends that declaration here.  */
    6579     33877861 :   if (ANON_AGGR_TYPE_P (t))
    6580              :     {
    6581          392 :       fixup_anonymous_aggr (t);
    6582              : 
    6583          392 :       if (TYPE_FIELDS (t))
    6584              :         {
    6585          392 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    6586              :                                       declspecs, NORMAL, 0, NULL);
    6587          392 :           finish_anon_union (decl);
    6588              :         }
    6589              :     }
    6590              : 
    6591              :   return t;
    6592              : }
    6593              : 
    6594              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    6595              : 
    6596              : tree
    6597    420581750 : groktypename (cp_decl_specifier_seq *type_specifiers,
    6598              :               const cp_declarator *declarator,
    6599              :               bool is_template_arg)
    6600              : {
    6601    420581750 :   tree attrs;
    6602    420581750 :   tree type;
    6603     69683642 :   enum decl_context context
    6604    420581750 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    6605    420581750 :   attrs = type_specifiers->attributes;
    6606    420581750 :   type_specifiers->attributes = NULL_TREE;
    6607    420581750 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    6608    420581750 :   if (attrs && type != error_mark_node)
    6609              :     {
    6610          673 :       if (CLASS_TYPE_P (type))
    6611            6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    6612              :                  "outside of definition", type);
    6613          667 :       else if (MAYBE_CLASS_TYPE_P (type))
    6614              :         /* A template type parameter or other dependent type.  */
    6615            9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    6616              :                  "type %qT without an associated declaration", type);
    6617              :       else
    6618          658 :         cplus_decl_attributes (&type, attrs, 0);
    6619              :     }
    6620    420581750 :   return type;
    6621              : }
    6622              : 
    6623              : /* Process a DECLARATOR for a function-scope or namespace-scope
    6624              :    variable or function declaration.
    6625              :    (Function definitions go through start_function; class member
    6626              :    declarations appearing in the body of the class go through
    6627              :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    6628              :    If an error occurs, the error_mark_node is returned instead.
    6629              : 
    6630              :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    6631              :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    6632              :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    6633              :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    6634              :    implicitly initialized via a default constructor.  It can also be
    6635              :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    6636              :    mark the new decl as DECL_DECOMPOSITION_P.
    6637              : 
    6638              :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    6639              :    declaration.
    6640              : 
    6641              :    The scope represented by the context of the returned DECL is pushed
    6642              :    (if it is not the global namespace) and is assigned to
    6643              :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    6644              :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    6645              : 
    6646              : tree
    6647    132081235 : start_decl (const cp_declarator *declarator,
    6648              :             cp_decl_specifier_seq *declspecs,
    6649              :             int initialized,
    6650              :             tree attributes,
    6651              :             tree prefix_attributes,
    6652              :             tree *pushed_scope_p)
    6653              : {
    6654    132081235 :   tree decl;
    6655    132081235 :   tree context;
    6656    132081235 :   bool was_public;
    6657    132081235 :   int flags;
    6658    132081235 :   bool alias;
    6659    132081235 :   tree initial;
    6660              : 
    6661    132081235 :   *pushed_scope_p = NULL_TREE;
    6662              : 
    6663    132081235 :   if (prefix_attributes != error_mark_node)
    6664    132081233 :     attributes = attr_chainon (attributes, prefix_attributes);
    6665              : 
    6666    132081235 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    6667              :                          &attributes);
    6668              : 
    6669    132081235 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    6670    132081235 :       || decl == error_mark_node
    6671    132079080 :       || prefix_attributes == error_mark_node)
    6672         2157 :     return error_mark_node;
    6673              : 
    6674    132079078 :   context = CP_DECL_CONTEXT (decl);
    6675    132079078 :   if (context != global_namespace)
    6676     23106607 :     *pushed_scope_p = push_scope (context);
    6677              : 
    6678    132079078 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    6679              :     {
    6680           27 :       error_at (DECL_SOURCE_LOCATION (decl),
    6681              :                 "typedef %qD is initialized (use %qs instead)",
    6682              :                 decl, "decltype");
    6683           27 :       return error_mark_node;
    6684              :     }
    6685              : 
    6686    132079051 :   if (flag_contracts
    6687     14864457 :       && TREE_CODE (decl) == FUNCTION_DECL
    6688      4168867 :       && !processing_template_decl
    6689      3373742 :       && DECL_RESULT (decl)
    6690    135446263 :       && is_auto (TREE_TYPE (DECL_RESULT (decl))))
    6691           36 :     if (tree specs = get_fn_contract_specifiers (decl))
    6692           12 :       for (tree ca : tree_vec_range (specs))
    6693            9 :         if (POSTCONDITION_P (ca) && POSTCONDITION_IDENTIFIER (ca))
    6694              :           {
    6695            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    6696              :                       "postconditions with deduced result name types must only"
    6697              :                       " appear on function definitions");
    6698            3 :             return error_mark_node;
    6699              :           }
    6700              :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    6701              :      with attribute validation.  */
    6702    132079048 :   initial = DECL_INITIAL (decl);
    6703              : 
    6704    132079048 :   if (initialized)
    6705              :     {
    6706     64151283 :       if (! toplevel_bindings_p ()
    6707     64151283 :           && DECL_EXTERNAL (decl))
    6708            3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6709              :                  decl);
    6710     64151283 :       DECL_EXTERNAL (decl) = 0;
    6711     64151283 :       if (toplevel_bindings_p ())
    6712      7667584 :         TREE_STATIC (decl) = 1;
    6713              :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6714              :          even though we might not yet have the initializer expression.  */
    6715     64151283 :       if (!DECL_INITIAL (decl))
    6716     63564153 :         DECL_INITIAL (decl) = error_mark_node;
    6717              :     }
    6718    132079048 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6719              : 
    6720    132079048 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6721         3984 :     record_key_method_defined (decl);
    6722              : 
    6723              :   /* If this is a typedef that names the class for linkage purposes
    6724              :      (7.1.3p8), apply any attributes directly to the type.  */
    6725    132079048 :   if (TREE_CODE (decl) == TYPE_DECL
    6726    132079048 :       && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
    6727              :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6728              :   else
    6729              :     flags = 0;
    6730              : 
    6731              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6732    132079048 :   cplus_decl_attributes (&decl, attributes, flags);
    6733              : 
    6734              :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6735              :      assist with attribute validation.  */
    6736    132079048 :   DECL_INITIAL (decl) = initial;
    6737              : 
    6738              :   /* Dllimported symbols cannot be defined.  Static data members (which
    6739              :      can be initialized in-class and dllimported) go through grokfield,
    6740              :      not here, so we don't need to exclude those decls when checking for
    6741              :      a definition.  */
    6742    132079048 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6743              :     {
    6744            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6745              :                 "definition of %q#D is marked %<dllimport%>", decl);
    6746            0 :       DECL_DLLIMPORT_P (decl) = 0;
    6747              :     }
    6748              : 
    6749              :   /* If #pragma weak was used, mark the decl weak now.  */
    6750    132079048 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6751     48124566 :     maybe_apply_pragma_weak (decl);
    6752              : 
    6753    132079048 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6754     39033156 :       && DECL_DECLARED_INLINE_P (decl)
    6755      3533632 :       && DECL_UNINLINABLE (decl)
    6756    132079048 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6757              :     {
    6758            0 :       auto_urlify_attributes sentinel;
    6759            0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6760              :                   "inline function %qD given attribute %qs", decl, "noinline");
    6761            0 :     }
    6762              : 
    6763    132079048 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6764              :     {
    6765       867505 :       bool this_tmpl = (current_template_depth
    6766       867505 :                         > template_class_depth (context));
    6767       867505 :       if (VAR_P (decl))
    6768              :         {
    6769       507790 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6770       507790 :           if (field == NULL_TREE
    6771       507790 :               || !(VAR_P (field) || variable_template_p (field)))
    6772            6 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6773       507784 :           else if (variable_template_p (field)
    6774       507784 :                    && (DECL_LANG_SPECIFIC (decl)
    6775          149 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6776              :             /* OK, specialization was already checked.  */;
    6777       507713 :           else if (variable_template_p (field) && !this_tmpl)
    6778              :             {
    6779            3 :               auto_diagnostic_group d;
    6780            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6781              :                         "non-member-template declaration of %qD", decl);
    6782            3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6783              :                       "member template declaration here");
    6784            3 :               return error_mark_node;
    6785            3 :             }
    6786              :           else
    6787              :             {
    6788       507710 :               if (variable_template_p (field))
    6789           75 :                 field = DECL_TEMPLATE_RESULT (field);
    6790              : 
    6791       507710 :               if (DECL_CONTEXT (field) != context)
    6792              :                 {
    6793            3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6794            3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6795              :                                "to be defined as %<%T::%D%>",
    6796            3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6797            3 :                                context, DECL_NAME (decl));
    6798            3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6799              :                 }
    6800              : 
    6801       507710 :               if (modules_p () && !module_may_redeclare (field))
    6802           30 :                 return error_mark_node;
    6803              : 
    6804              :               /* Static data member are tricky; an in-class initialization
    6805              :                  still doesn't provide a definition, so the in-class
    6806              :                  declaration will have DECL_EXTERNAL set, but will have an
    6807              :                  initialization.  Thus, duplicate_decls won't warn
    6808              :                  about this situation, and so we check here.  */
    6809       507680 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6810            9 :                 error ("duplicate initialization of %qD", decl);
    6811       507680 :               field = duplicate_decls (decl, field);
    6812       507680 :               if (field == error_mark_node)
    6813              :                 return error_mark_node;
    6814       507624 :               else if (field)
    6815       507624 :                 decl = field;
    6816              :             }
    6817              :         }
    6818              :       else
    6819              :         {
    6820       359727 :           tree field = check_classfn (context, decl,
    6821              :                                       this_tmpl
    6822           12 :                                       ? current_template_parms
    6823              :                                       : NULL_TREE);
    6824       359640 :           if (field && field != error_mark_node
    6825       719355 :               && duplicate_decls (decl, field))
    6826       359640 :             decl = field;
    6827              :         }
    6828              : 
    6829              :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6830       867416 :       DECL_IN_AGGR_P (decl) = 0;
    6831              :       /* Do not mark DECL as an explicit specialization if it was not
    6832              :          already marked as an instantiation; a declaration should
    6833              :          never be marked as a specialization unless we know what
    6834              :          template is being specialized.  */
    6835       867416 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6836              :         {
    6837       357745 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6838       357745 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6839       337082 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6840       337082 :                                   && DECL_NONGNU_INLINE_P (decl));
    6841              :           else
    6842        20663 :             DECL_COMDAT (decl) = false;
    6843              : 
    6844              :           /* [temp.expl.spec] An explicit specialization of a static data
    6845              :              member of a template is a definition if the declaration
    6846              :              includes an initializer; otherwise, it is a declaration.
    6847              : 
    6848              :              We check for processing_specialization so this only applies
    6849              :              to the new specialization syntax.  */
    6850       357745 :           if (!initialized && processing_specialization)
    6851       357541 :             DECL_EXTERNAL (decl) = 1;
    6852              :         }
    6853              : 
    6854      1225005 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6855              :           /* Aliases are definitions. */
    6856       867452 :           && !alias)
    6857              :         {
    6858            9 :           permerror (declarator->id_loc,
    6859              :                        "declaration of %q#D outside of class is not definition",
    6860              :                        decl);
    6861              :         }
    6862              :     }
    6863              : 
    6864              :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6865    132078959 :   if (initialized == SD_DECOMPOSITION)
    6866       491177 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6867              : 
    6868    132078959 :   was_public = TREE_PUBLIC (decl);
    6869              : 
    6870    225134572 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6871    132665965 :       && current_function_decl)
    6872              :     {
    6873              :       /* A function-scope decl of some namespace-scope decl.  */
    6874        62591 :       DECL_LOCAL_DECL_P (decl) = true;
    6875        62591 :       if (named_module_attach_p ())
    6876            3 :         error_at (declarator->id_loc,
    6877              :                   "block-scope extern declaration %q#D must not be"
    6878              :                   " attached to a named module", decl);
    6879              :     }
    6880              : 
    6881              :   /* Enter this declaration into the symbol table.  Don't push the plain
    6882              :      VAR_DECL for a variable template.  */
    6883    132078959 :   if (!template_parm_scope_p ()
    6884    132078959 :       || !VAR_P (decl))
    6885    127746221 :     decl = maybe_push_decl (decl);
    6886              : 
    6887    132078959 :   if (processing_template_decl)
    6888     83946249 :     decl = push_template_decl (decl);
    6889              : 
    6890    132078959 :   if (decl == error_mark_node)
    6891              :     return error_mark_node;
    6892              : 
    6893    132078510 :   if (VAR_P (decl)
    6894     70452152 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6895        70672 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6896              :       /* But not templated variables.  */
    6897    132110006 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6898              :     {
    6899              :       /* This is a const variable with implicit 'static'.  Set
    6900              :          DECL_THIS_STATIC so we can tell it from variables that are
    6901              :          !TREE_PUBLIC because of the anonymous namespace.  */
    6902        31496 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6903        31496 :       DECL_THIS_STATIC (decl) = 1;
    6904              :     }
    6905              : 
    6906     74712383 :   if (current_function_decl && VAR_P (decl)
    6907     61967772 :       && maybe_constexpr_fn (current_function_decl)
    6908    148303429 :       && cxx_dialect < cxx23)
    6909              :     {
    6910     12682029 :       bool ok = false;
    6911     12682029 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6912              :         {
    6913            9 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6914           18 :             error_at (DECL_SOURCE_LOCATION (decl),
    6915              :                       "%qD defined %<thread_local%> in %qs function only "
    6916              :                       "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6917            9 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6918              :                       ? "consteval" : "constexpr");
    6919              :         }
    6920     12682020 :       else if (TREE_STATIC (decl))
    6921              :         {
    6922           74 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6923           72 :             error_at (DECL_SOURCE_LOCATION (decl),
    6924              :                       "%qD defined %<static%> in %qs function only available "
    6925              :                       "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6926           36 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6927              :                       ? "consteval" : "constexpr");
    6928              :         }
    6929              :       else
    6930              :         ok = true;
    6931           45 :       if (!ok)
    6932           83 :         cp_function_chain->invalid_constexpr = true;
    6933              :     }
    6934              : 
    6935    132078510 :   if (!processing_template_decl && VAR_P (decl))
    6936      8802525 :     start_decl_1 (decl, initialized);
    6937              : 
    6938    132078507 :   return decl;
    6939              : }
    6940              : 
    6941              : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6942              :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6943              :    variable is initialized via an implicitly-called constructor.)
    6944              :    This function must be called for ordinary variables (including, for
    6945              :    example, implicit instantiations of templates), but must not be
    6946              :    called for template declarations.  */
    6947              : 
    6948              : void
    6949      8813746 : start_decl_1 (tree decl, bool initialized)
    6950              : {
    6951      8813746 :   gcc_checking_assert (!processing_template_decl);
    6952              : 
    6953      8813746 :   if (error_operand_p (decl))
    6954              :     return;
    6955              : 
    6956      8813731 :   gcc_checking_assert (VAR_P (decl));
    6957              : 
    6958      8813731 :   tree type = TREE_TYPE (decl);
    6959      8813731 :   bool complete_p = COMPLETE_TYPE_P (type);
    6960      8813731 :   bool aggregate_definition_p
    6961      8813731 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6962              : 
    6963              :   /* If an explicit initializer is present, or if this is a definition
    6964              :      of an aggregate, then we need a complete type at this point.
    6965              :      (Scalars are always complete types, so there is nothing to
    6966              :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6967              :      are issued below.  */
    6968      4574718 :   if ((initialized || aggregate_definition_p)
    6969      7773920 :       && !complete_p
    6970      6235036 :       && COMPLETE_TYPE_P (complete_type (type)))
    6971              :     {
    6972       340186 :       complete_p = true;
    6973              :       /* We will not yet have set TREE_READONLY on DECL if the type
    6974              :          was "const", but incomplete, before this point.  But, now, we
    6975              :          have a complete type, so we can try again.  */
    6976       340186 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6977              :     }
    6978              : 
    6979      8813728 :   if (initialized)
    6980              :     /* Is it valid for this decl to have an initializer at all?  */
    6981              :     {
    6982              :       /* Don't allow initializations for incomplete types except for
    6983              :          arrays which might be completed by the initialization.  */
    6984      7003986 :       if (complete_p)
    6985              :         ;                       /* A complete type is ok.  */
    6986      1319891 :       else if (type_uses_auto (type))
    6987              :         ;                       /* An auto type is ok.  */
    6988       123067 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6989              :         {
    6990           27 :           auto_diagnostic_group d;
    6991           27 :           error ("variable %q#D has initializer but incomplete type", decl);
    6992           48 :           maybe_suggest_missing_header (input_location,
    6993           27 :                                         TYPE_IDENTIFIER (type),
    6994           27 :                                         CP_TYPE_CONTEXT (type));
    6995           27 :           type = TREE_TYPE (decl) = error_mark_node;
    6996           27 :         }
    6997       123040 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6998              :         {
    6999            0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7000            0 :             error ("elements of array %q#D have incomplete type", decl);
    7001              :           /* else we already gave an error in start_decl.  */
    7002              :         }
    7003              :     }
    7004      1809742 :   else if (aggregate_definition_p && !complete_p)
    7005              :     {
    7006          238 :       if (type_uses_auto (type))
    7007           71 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    7008              :       else
    7009              :         {
    7010          167 :           auto_diagnostic_group d;
    7011          167 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    7012              :                  decl);
    7013          289 :           maybe_suggest_missing_header (input_location,
    7014          167 :                                         TYPE_IDENTIFIER (type),
    7015          167 :                                         CP_TYPE_CONTEXT (type));
    7016              :           /* Change the type so that assemble_variable will give
    7017              :              DECL an rtl we can live with: (mem (const_int 0)).  */
    7018          167 :           type = TREE_TYPE (decl) = error_mark_node;
    7019          167 :         }
    7020              :     }
    7021              : 
    7022              :   /* Create a new scope to hold this declaration if necessary.
    7023              :      Whether or not a new scope is necessary cannot be determined
    7024              :      until after the type has been completed; if the type is a
    7025              :      specialization of a class template it is not until after
    7026              :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    7027              :      will be set correctly.  */
    7028      8813728 :   maybe_push_cleanup_level (type);
    7029              : }
    7030              : 
    7031              : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    7032              :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    7033              : 
    7034              : tree
    7035          309 : do_aggregate_paren_init (tree init, tree type)
    7036              : {
    7037          309 :   tree val = TREE_VALUE (init);
    7038              : 
    7039          309 :   if (TREE_CHAIN (init) == NULL_TREE)
    7040              :     {
    7041              :       /* If the list has a single element and it's a string literal,
    7042              :          then it's the initializer for the array as a whole.  */
    7043          193 :       if (TREE_CODE (type) == ARRAY_TYPE
    7044          193 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    7045          239 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    7046              :              == STRING_CST)
    7047              :         return val;
    7048              :       /* Handle non-standard extensions like compound literals.  This also
    7049              :          prevents triggering aggregate parenthesized-initialization in
    7050              :          compiler-generated code for =default.  */
    7051          154 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    7052          154 :                                                           TREE_TYPE (val)))
    7053              :         return val;
    7054              :     }
    7055              : 
    7056          208 :   init = build_constructor_from_list (init_list_type_node, init);
    7057          208 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    7058          208 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    7059          208 :   return init;
    7060              : }
    7061              : 
    7062              : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    7063              :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    7064              :    but will be set to a new CLEANUP_STMT if a temporary is created
    7065              :    that must be destroyed subsequently.
    7066              : 
    7067              :    Returns an initializer expression to use to initialize DECL, or
    7068              :    NULL if the initialization can be performed statically.
    7069              : 
    7070              :    Quotes on semantics can be found in ARM 8.4.3.  */
    7071              : 
    7072              : static tree
    7073       385582 : grok_reference_init (tree decl, tree type, tree init, int flags)
    7074              : {
    7075       385582 :   if (init == NULL_TREE)
    7076              :     {
    7077           15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    7078            3 :            || DECL_IN_AGGR_P (decl) == 0)
    7079           18 :           && ! DECL_THIS_EXTERN (decl))
    7080           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    7081              :                   "%qD declared as reference but not initialized", decl);
    7082              :       return NULL_TREE;
    7083              :     }
    7084              : 
    7085       385567 :   tree ttype = TREE_TYPE (type);
    7086       385567 :   if (TREE_CODE (init) == TREE_LIST)
    7087              :     {
    7088              :       /* This handles (C++20 only) code like
    7089              : 
    7090              :            const A& r(1, 2, 3);
    7091              : 
    7092              :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    7093         1262 :       if (TREE_TYPE (init) == NULL_TREE
    7094         1262 :           && CP_AGGREGATE_TYPE_P (ttype)
    7095          102 :           && !DECL_DECOMPOSITION_P (decl)
    7096         1361 :           && (cxx_dialect >= cxx20))
    7097              :         {
    7098              :           /* We don't know yet if we should treat const A& r(1) as
    7099              :              const A& r{1}.  */
    7100           93 :           if (list_length (init) == 1)
    7101              :             {
    7102           72 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    7103           72 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    7104              :                                                       tf_warning_or_error);
    7105              :             }
    7106              :           /* If the list had more than one element, the code is ill-formed
    7107              :              pre-C++20, so we can build a constructor right away.  */
    7108              :           else
    7109           21 :             init = do_aggregate_paren_init (init, ttype);
    7110              :         }
    7111              :       else
    7112         1169 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    7113              :                                                 tf_warning_or_error);
    7114              :     }
    7115              : 
    7116       385567 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    7117       385567 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    7118              :     /* Note: default conversion is only called in very special cases.  */
    7119           12 :     init = decay_conversion (init, tf_warning_or_error);
    7120              : 
    7121              :   /* check_initializer handles this for non-reference variables, but for
    7122              :      references we need to do it here or the initializer will get the
    7123              :      incomplete array type and confuse later calls to
    7124              :      cp_complete_array_type.  */
    7125       385567 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    7126        22539 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    7127       385650 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    7128           50 :           || TREE_CODE (init) == STRING_CST))
    7129              :     {
    7130           33 :       cp_complete_array_type (&ttype, init, false);
    7131           33 :       if (ttype != TREE_TYPE (type))
    7132           33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    7133              :     }
    7134              : 
    7135              :   /* Convert INIT to the reference type TYPE.  This may involve the
    7136              :      creation of a temporary, whose lifetime must be the same as that
    7137              :      of the reference.  If so, a DECL_EXPR for the temporary will be
    7138              :      added just after the DECL_EXPR for DECL.  That's why we don't set
    7139              :      DECL_INITIAL for local references (instead assigning to them
    7140              :      explicitly); we need to allow the temporary to be initialized
    7141              :      first.  */
    7142       385567 :   return initialize_reference (type, init, flags,
    7143       385567 :                                tf_warning_or_error);
    7144              : }
    7145              : 
    7146              : /* Designated initializers in arrays are not supported in GNU C++.
    7147              :    The parser cannot detect this error since it does not know whether
    7148              :    a given brace-enclosed initializer is for a class type or for an
    7149              :    array.  This function checks that CE does not use a designated
    7150              :    initializer.  If it does, an error is issued.  Returns true if CE
    7151              :    is valid, i.e., does not have a designated initializer.  */
    7152              : 
    7153              : bool
    7154    156242862 : check_array_designated_initializer (constructor_elt *ce,
    7155              :                                     unsigned HOST_WIDE_INT index)
    7156              : {
    7157              :   /* Designated initializers for array elements are not supported.  */
    7158    156242862 :   if (ce->index)
    7159              :     {
    7160              :       /* The parser only allows identifiers as designated
    7161              :          initializers.  */
    7162    105473821 :       if (ce->index == error_mark_node)
    7163              :         {
    7164            0 :           error ("name used in a GNU-style designated "
    7165              :                  "initializer for an array");
    7166            0 :           return false;
    7167              :         }
    7168    105473821 :       else if (identifier_p (ce->index))
    7169              :         {
    7170           22 :           error ("name %qD used in a GNU-style designated "
    7171              :                  "initializer for an array", ce->index);
    7172           22 :           ce->index = error_mark_node;
    7173           22 :           return false;
    7174              :         }
    7175              : 
    7176    105473799 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    7177              :                                                   ce->index, true);
    7178    105473799 :       if (ce_index
    7179    105473796 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    7180    210947592 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    7181              :               == INTEGER_CST))
    7182              :         {
    7183              :           /* A C99 designator is OK if it matches the current index.  */
    7184    105473793 :           if (wi::to_wide (ce_index) == index)
    7185              :             {
    7186    105473787 :               ce->index = ce_index;
    7187    105473787 :               return true;
    7188              :             }
    7189              :           else
    7190            6 :             sorry ("non-trivial designated initializers not supported");
    7191              :         }
    7192              :       else
    7193            6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    7194              :                   "C99 designator %qE is not an integral constant-expression",
    7195              :                   ce->index);
    7196              : 
    7197              :       return false;
    7198              :     }
    7199              : 
    7200              :   return true;
    7201              : }
    7202              : 
    7203              : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    7204              :    array until we finish parsing the initializer.  If that's the
    7205              :    situation we're in, update DECL accordingly.  */
    7206              : 
    7207              : static void
    7208     76422295 : maybe_deduce_size_from_array_init (tree decl, tree init)
    7209              : {
    7210     76422295 :   tree type = TREE_TYPE (decl);
    7211              : 
    7212     76422295 :   if (TREE_CODE (type) == ARRAY_TYPE
    7213       984564 :       && TYPE_DOMAIN (type) == NULL_TREE
    7214     77046653 :       && TREE_CODE (decl) != TYPE_DECL)
    7215              :     {
    7216              :       /* do_default is really a C-ism to deal with tentative definitions.
    7217              :          But let's leave it here to ease the eventual merge.  */
    7218       624358 :       int do_default = !DECL_EXTERNAL (decl);
    7219       624358 :       tree initializer = init ? init : DECL_INITIAL (decl);
    7220       624358 :       int failure = 0;
    7221              : 
    7222              :       /* Check that there are no designated initializers in INIT, as
    7223              :          those are not supported in GNU C++, and as the middle-end
    7224              :          will crash if presented with a non-numeric designated
    7225              :          initializer.  */
    7226       624358 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    7227              :         {
    7228       149081 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    7229       149081 :           constructor_elt *ce;
    7230       149081 :           HOST_WIDE_INT i, j = 0;
    7231     49021699 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    7232              :             {
    7233     48873665 :               if (instantiation_dependent_expression_p (ce->index))
    7234     76422295 :                 return;
    7235     48873659 :               if (!check_array_designated_initializer (ce, j))
    7236            1 :                 failure = 1;
    7237              :               /* If an un-designated initializer is type-dependent, we can't
    7238              :                  check brace elision yet.  */
    7239     48873659 :               if (ce->index == NULL_TREE
    7240     48873659 :                   && type_dependent_expression_p (ce->value))
    7241              :                 return;
    7242     48872618 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7243          210 :                 j += RAW_DATA_LENGTH (ce->value);
    7244              :               else
    7245     48872408 :                 ++j;
    7246              :             }
    7247              :         }
    7248              : 
    7249       148034 :       if (failure)
    7250            1 :         TREE_TYPE (decl) = error_mark_node;
    7251              :       else
    7252              :         {
    7253       623310 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    7254              :                                             do_default);
    7255       623310 :           if (failure == 1)
    7256              :             {
    7257           33 :               error_at (cp_expr_loc_or_loc (initializer,
    7258           30 :                                          DECL_SOURCE_LOCATION (decl)),
    7259              :                         "initializer fails to determine size of %qD", decl);
    7260              :             }
    7261       623280 :           else if (failure == 2)
    7262              :             {
    7263           30 :               if (do_default)
    7264              :                 {
    7265            6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    7266              :                             "array size missing in %qD", decl);
    7267              :                 }
    7268              :               /* If a `static' var's size isn't known, make it extern as
    7269              :                  well as static, so it does not get allocated.  If it's not
    7270              :                  `static', then don't mark it extern; finish_incomplete_decl
    7271              :                  will give it a default size and it will get allocated.  */
    7272           24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    7273            0 :                 DECL_EXTERNAL (decl) = 1;
    7274              :             }
    7275       623250 :           else if (failure == 3)
    7276              :             {
    7277            6 :               error_at (DECL_SOURCE_LOCATION (decl),
    7278              :                         "zero-size array %qD", decl);
    7279              :             }
    7280              :         }
    7281              : 
    7282       623311 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    7283              : 
    7284       623311 :       relayout_decl (decl);
    7285              : 
    7286              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    7287       623311 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7288              :         {
    7289          212 :           tree tmpl = template_for_substitution (decl);
    7290          212 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    7291           50 :             TREE_TYPE (tmpl) = TREE_TYPE (decl);
    7292              :         }
    7293              :     }
    7294              : }
    7295              : 
    7296              : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    7297              :    any appropriate error messages regarding the layout.  */
    7298              : 
    7299              : static void
    7300     65279306 : layout_var_decl (tree decl)
    7301              : {
    7302     65279306 :   tree type;
    7303              : 
    7304     65279306 :   type = TREE_TYPE (decl);
    7305     65279306 :   if (type == error_mark_node)
    7306              :     return;
    7307              : 
    7308              :   /* If we haven't already laid out this declaration, do so now.
    7309              :      Note that we must not call complete type for an external object
    7310              :      because it's type might involve templates that we are not
    7311              :      supposed to instantiate yet.  (And it's perfectly valid to say
    7312              :      `extern X x' for some incomplete type `X'.)  */
    7313     65279259 :   if (!DECL_EXTERNAL (decl))
    7314     54798581 :     complete_type (type);
    7315     65279259 :   if (!DECL_SIZE (decl)
    7316       626496 :       && TREE_TYPE (decl) != error_mark_node
    7317     65905755 :       && complete_or_array_type_p (type))
    7318       473125 :     layout_decl (decl, 0);
    7319              : 
    7320     65279259 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    7321              :     {
    7322              :       /* An automatic variable with an incomplete type: that is an error.
    7323              :          Don't talk about array types here, since we took care of that
    7324              :          message in grokdeclarator.  */
    7325           17 :       error_at (DECL_SOURCE_LOCATION (decl),
    7326              :                 "storage size of %qD isn%'t known", decl);
    7327           17 :       TREE_TYPE (decl) = error_mark_node;
    7328              :     }
    7329              : #if 0
    7330              :   /* Keep this code around in case we later want to control debug info
    7331              :      based on whether a type is "used".  (jason 1999-11-11) */
    7332              : 
    7333              :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    7334              :     /* Let debugger know it should output info for this type.  */
    7335              :     note_debug_info_needed (ttype);
    7336              : 
    7337              :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    7338              :     note_debug_info_needed (DECL_CONTEXT (decl));
    7339              : #endif
    7340              : 
    7341    120077840 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    7342     40148612 :       && DECL_SIZE (decl) != NULL_TREE
    7343    105142015 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    7344              :     {
    7345            6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7346            6 :           && !DECL_LOCAL_DECL_P (decl))
    7347            0 :         constant_expression_warning (DECL_SIZE (decl));
    7348              :       else
    7349              :         {
    7350            6 :           error_at (DECL_SOURCE_LOCATION (decl),
    7351              :                     "storage size of %qD isn%'t constant", decl);
    7352            6 :           TREE_TYPE (decl) = error_mark_node;
    7353            6 :           type = error_mark_node;
    7354              :         }
    7355              :     }
    7356              : 
    7357              :   /* If the final element initializes a flexible array field, adjust
    7358              :      the size of the DECL with the initializer based on whether the
    7359              :      DECL is a union or a structure.  */
    7360     65279259 :   if (type != error_mark_node
    7361     65279253 :       && DECL_INITIAL (decl)
    7362     38589913 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    7363      5302382 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    7364      3566849 :       && DECL_SIZE (decl) != NULL_TREE
    7365      3566849 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7366      3566849 :       && COMPLETE_TYPE_P (type)
    7367      3566849 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    7368     68846108 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    7369              :     {
    7370      3566849 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    7371      3566849 :       if (elt.index)
    7372              :         {
    7373      1345473 :           tree itype = TREE_TYPE (elt.index);
    7374      1345473 :           tree vtype = TREE_TYPE (elt.value);
    7375      1345473 :           if (TREE_CODE (itype) == ARRAY_TYPE
    7376        85357 :               && TYPE_DOMAIN (itype) == NULL
    7377          275 :               && TREE_CODE (vtype) == ARRAY_TYPE
    7378      1345748 :               && COMPLETE_TYPE_P (vtype))
    7379              :             {
    7380              :               /* For a structure, add the size of the initializer to the DECL's
    7381              :                  size.  */
    7382          275 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    7383              :                 {
    7384          260 :                   DECL_SIZE (decl)
    7385          260 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    7386              :                                   TYPE_SIZE (vtype));
    7387          260 :                   DECL_SIZE_UNIT (decl)
    7388          520 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    7389              :                                   TYPE_SIZE_UNIT (vtype));
    7390              :                 }
    7391              :               /* For a union, the DECL's size is the maximum of the current size
    7392              :                  and the size of the initializer.  */
    7393              :               else
    7394              :                 {
    7395           15 :                   DECL_SIZE (decl)
    7396           15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    7397              :                                   TYPE_SIZE (vtype));
    7398           15 :                   DECL_SIZE_UNIT (decl)
    7399           30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    7400              :                                   TYPE_SIZE_UNIT (vtype));
    7401              :                 }
    7402              :             }
    7403              :         }
    7404              :     }
    7405              : }
    7406              : 
    7407              : /* If a local static variable is declared in an inline function, or if
    7408              :    we have a weak definition, we must endeavor to create only one
    7409              :    instance of the variable at link-time.  */
    7410              : 
    7411              : void
    7412     80388968 : maybe_commonize_var (tree decl)
    7413              : {
    7414              :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    7415              :      bindings.  */
    7416     80388968 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    7417              :     return;
    7418              : 
    7419              :   /* Static data in a function with comdat linkage also has comdat
    7420              :      linkage.  */
    7421     75055648 :   if ((TREE_STATIC (decl)
    7422     49657091 :        && DECL_FUNCTION_SCOPE_P (decl)
    7423       141260 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    7424    174544982 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    7425              :     {
    7426     43522309 :       if (flag_weak)
    7427              :         {
    7428              :           /* With weak symbols, we simply make the variable COMDAT;
    7429              :              that will cause copies in multiple translations units to
    7430              :              be merged.  */
    7431     43522282 :           comdat_linkage (decl);
    7432              :         }
    7433              :       else
    7434              :         {
    7435           27 :           if (DECL_INITIAL (decl) == NULL_TREE
    7436           27 :               || DECL_INITIAL (decl) == error_mark_node)
    7437              :             {
    7438              :               /* Without weak symbols, we can use COMMON to merge
    7439              :                  uninitialized variables.  */
    7440           24 :               TREE_PUBLIC (decl) = 1;
    7441           24 :               DECL_COMMON (decl) = 1;
    7442              :             }
    7443              :           else
    7444              :             {
    7445              :               /* While for initialized variables, we must use internal
    7446              :                  linkage -- which means that multiple copies will not
    7447              :                  be merged.  */
    7448            3 :               TREE_PUBLIC (decl) = 0;
    7449            3 :               DECL_COMMON (decl) = 0;
    7450            3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    7451            3 :               const char *msg;
    7452            3 :               if (DECL_INLINE_VAR_P (decl))
    7453              :                 msg = G_("sorry: semantics of inline variable "
    7454              :                          "%q#D are wrong (you%'ll wind up with "
    7455              :                          "multiple copies)");
    7456              :               else
    7457              :                 msg = G_("sorry: semantics of inline function "
    7458              :                          "static data %q#D are wrong (you%'ll wind "
    7459              :                          "up with multiple copies)");
    7460            3 :               auto_diagnostic_group d;
    7461            3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    7462              :                               msg, decl))
    7463            3 :                 inform (DECL_SOURCE_LOCATION (decl),
    7464              :                         "you can work around this by removing the initializer");
    7465            3 :             }
    7466              :         }
    7467              :     }
    7468              : }
    7469              : 
    7470              : /* Issue an error message if DECL is an uninitialized const variable.
    7471              :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    7472              :    context from potential_constant_expression.  Returns true if all is well,
    7473              :    false otherwise.  */
    7474              : 
    7475              : bool
    7476      9307549 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    7477              :                                    tsubst_flags_t complain)
    7478              : {
    7479      9307549 :   tree type = strip_array_types (TREE_TYPE (decl));
    7480              : 
    7481              :   /* ``Unless explicitly declared extern, a const object does not have
    7482              :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    7483              :      7.1.6 */
    7484      9307549 :   if (VAR_P (decl)
    7485      9307549 :       && !TYPE_REF_P (type)
    7486      9259015 :       && (CP_TYPE_CONST_P (type)
    7487              :           /* C++20 permits trivial default initialization in constexpr
    7488              :              context (P1331R2).  */
    7489      7203070 :           || (cxx_dialect < cxx20
    7490       139061 :               && (constexpr_context_p
    7491       124074 :                   || var_in_constexpr_fn (decl))))
    7492     11380597 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    7493              :     {
    7494       661410 :       tree field = default_init_uninitialized_part (type);
    7495       661410 :       if (!field)
    7496              :         return true;
    7497              : 
    7498         5130 :       auto_diagnostic_group d;
    7499         5130 :       bool show_notes = true;
    7500              : 
    7501         5130 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    7502              :         {
    7503          188 :           if (CP_TYPE_CONST_P (type))
    7504              :             {
    7505           90 :               if (complain & tf_error)
    7506           84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    7507              :                                         "uninitialized %<const %D%>", decl);
    7508              :             }
    7509              :           else
    7510              :             {
    7511           98 :               if (!is_instantiation_of_constexpr (current_function_decl)
    7512           98 :                   && (complain & tf_error))
    7513           21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    7514              :                           "uninitialized variable %qD in %<constexpr%> "
    7515              :                           "function", decl);
    7516              :               else
    7517              :                 show_notes = false;
    7518           98 :               cp_function_chain->invalid_constexpr = true;
    7519              :             }
    7520              :         }
    7521         4942 :       else if (complain & tf_error)
    7522            2 :         error_at (DECL_SOURCE_LOCATION (decl),
    7523              :                   "uninitialized variable %qD in %<constexpr%> context",
    7524              :                   decl);
    7525              : 
    7526         5130 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    7527              :         {
    7528           62 :           tree defaulted_ctor;
    7529              : 
    7530           62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    7531              :                   "%q#T has no user-provided default constructor", type);
    7532           62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    7533           62 :           if (defaulted_ctor)
    7534           33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    7535              :                     "constructor is not user-provided because it is "
    7536              :                     "explicitly defaulted in the class body");
    7537           62 :           inform (DECL_SOURCE_LOCATION (field),
    7538              :                   "and the implicitly-defined constructor does not "
    7539              :                   "initialize %q#D", field);
    7540              :         }
    7541              : 
    7542         5130 :       return false;
    7543         5130 :     }
    7544              : 
    7545              :   return true;
    7546              : }
    7547              : 
    7548              : /* Structure holding the current initializer being processed by reshape_init.
    7549              :    CUR is a pointer to the current element being processed, END is a pointer
    7550              :    after the last element present in the initializer and RAW_IDX is index into
    7551              :    RAW_DATA_CST if that is CUR elt.  */
    7552              : struct reshape_iter
    7553              : {
    7554              :   constructor_elt *cur;
    7555              :   constructor_elt *end;
    7556              :   unsigned raw_idx;
    7557              : };
    7558              : 
    7559              : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    7560              : static tree reshape_single_init (tree, tree, tsubst_flags_t);
    7561              : 
    7562              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7563              :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    7564              :    initialized as if for an aggregate class.  If there are no more such fields,
    7565              :    the return value will be NULL.  */
    7566              : 
    7567              : tree
    7568     15654377 : next_aggregate_field (tree field)
    7569              : {
    7570     15654377 :   while (field
    7571     64884587 :          && (TREE_CODE (field) != FIELD_DECL
    7572      9817777 :              || DECL_UNNAMED_BIT_FIELD (field)
    7573      9817616 :              || (DECL_ARTIFICIAL (field)
    7574              :                  /* In C++17, aggregates can have bases.  */
    7575       216543 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    7576     49230210 :     field = DECL_CHAIN (field);
    7577              : 
    7578     15654377 :   return field;
    7579              : }
    7580              : 
    7581              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7582              :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    7583              :    to a subobject.  If there are no more such fields, the return value will be
    7584              :    NULL.  */
    7585              : 
    7586              : tree
    7587     67424592 : next_subobject_field (tree field)
    7588              : {
    7589     67424592 :   while (field
    7590    879505734 :          && (TREE_CODE (field) != FIELD_DECL
    7591     30048339 :              || DECL_UNNAMED_BIT_FIELD (field)
    7592     30048200 :              || (DECL_ARTIFICIAL (field)
    7593      8326251 :                  && !DECL_FIELD_IS_BASE (field)
    7594      1799828 :                  && !DECL_VIRTUAL_P (field))))
    7595    812081142 :     field = DECL_CHAIN (field);
    7596              : 
    7597     67424592 :   return field;
    7598              : }
    7599              : 
    7600              : /* Return true for [dcl.init.list] direct-list-initialization from
    7601              :    single element of enumeration with a fixed underlying type.  */
    7602              : 
    7603              : bool
    7604    188849566 : is_direct_enum_init (tree type, tree init)
    7605              : {
    7606    188849566 :   if (cxx_dialect >= cxx17
    7607    186794947 :       && TREE_CODE (type) == ENUMERAL_TYPE
    7608      7641644 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    7609      5241700 :       && TREE_CODE (init) == CONSTRUCTOR
    7610       452942 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    7611       230626 :       && CONSTRUCTOR_NELTS (init) == 1
    7612          223 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    7613              :       /* DR 2374: The single element needs to be implicitly
    7614              :          convertible to the underlying type of the enum.  */
    7615          223 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    7616    188849787 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    7617          221 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    7618          221 :                           CONSTRUCTOR_ELT (init, 0)->value,
    7619              :                           LOOKUP_IMPLICIT, tf_none))
    7620              :     return true;
    7621              :   return false;
    7622              : }
    7623              : 
    7624              : /* Helper function for reshape_init*.  Split first element of
    7625              :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    7626              :    to true if the whole d->cur has been consumed.  */
    7627              : 
    7628              : static tree
    7629     62687217 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    7630              : {
    7631     62687217 :   *inc_cur = true;
    7632     62687217 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    7633              :     return NULL_TREE;
    7634        30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    7635        30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    7636        30588 :     *inc_cur = false;
    7637              :   else
    7638          132 :     d->raw_idx = 0;
    7639              :   return ret;
    7640              : }
    7641              : 
    7642              : /* Wrapper around that which for RAW_DATA_CST in INIT
    7643              :    (as well as in D->cur->value) peels off the first element
    7644              :    of the raw data and returns it, otherwise increments
    7645              :    D->cur and returns INIT.  */
    7646              : 
    7647              : static tree
    7648     62687200 : consume_init (tree init, reshape_iter *d)
    7649              : {
    7650     62687200 :   bool inc_cur;
    7651     62687200 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7652        30720 :     init = raw_init;
    7653     62687200 :   if (inc_cur)
    7654     62656612 :     d->cur++;
    7655     62687200 :   return init;
    7656              : }
    7657              : 
    7658              : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    7659              :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    7660              :    INTEGER_CST representing the size of the array minus one (the maximum index),
    7661              :    or NULL_TREE if the array was declared without specifying the size. D is
    7662              :    the iterator within the constructor.  */
    7663              : 
    7664              : static tree
    7665       468773 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    7666              :                       tree first_initializer_p, bool vector_p,
    7667              :                       tsubst_flags_t complain)
    7668              : {
    7669       468773 :   tree new_init;
    7670       468773 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    7671       468773 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    7672       468773 :   unsigned HOST_WIDE_INT index;
    7673              : 
    7674              :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    7675              :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    7676              :      to build a new one.  But don't reuse if not complaining; if this is
    7677              :      tentative, we might also reshape to another type (95319).  */
    7678       468773 :   bool reuse = (first_initializer_p
    7679       409722 :                 && (complain & tf_error)
    7680       408437 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    7681       812973 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    7682       128333 :   if (reuse)
    7683              :     new_init = first_initializer_p;
    7684              :   else
    7685       128333 :     new_init = build_constructor (init_list_type_node, NULL);
    7686              : 
    7687       468773 :   if (sized_array_p)
    7688              :     {
    7689       279375 :       poly_uint64 midx;
    7690              :       /* Minus 1 is used for zero sized arrays.  */
    7691       279375 :       if (integer_all_onesp (max_index))
    7692           24 :         return new_init;
    7693              : 
    7694       279351 :       if (tree_fits_poly_uint64_p (max_index))
    7695       279351 :         midx = tree_to_poly_uint64 (max_index);
    7696              :       /* sizetype is sign extended, not zero extended.  */
    7697              :       else
    7698            0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    7699              : 
    7700              :       /* For VLA vectors, we restrict the number of elements in the constructor
    7701              :          to lower bound of the VLA elements.  */
    7702       279351 :       max_index_cst = constant_lower_bound (midx);
    7703              :     }
    7704              : 
    7705       468749 :   constructor_elt *first_cur = d->cur;
    7706              :   /* Loop until there are no more initializers.  */
    7707     57106748 :   for (index = 0;
    7708     57106748 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    7709              :        ++index)
    7710              :     {
    7711     56638180 :       tree elt_init;
    7712     56638180 :       constructor_elt *old_cur = d->cur;
    7713     56638180 :       unsigned int old_raw_idx = d->raw_idx;
    7714     56638180 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    7715              : 
    7716     56638180 :       if (d->cur->index)
    7717      5896888 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7718     56638180 :       check_array_designated_initializer (d->cur, index);
    7719     56638180 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7720        32752 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7721        10233 :               || is_byte_access_type (elt_type))
    7722        22519 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7723         1858 :           && (!sized_array_p || index < max_index_cst)
    7724     56640026 :           && !vector_p)
    7725              :         {
    7726          526 :           elt_init = d->cur->value;
    7727          526 :           unsigned int off = d->raw_idx;
    7728          526 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7729          526 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7730              :             {
    7731          517 :               d->cur++;
    7732          517 :               d->raw_idx = 0;
    7733              :             }
    7734              :           else
    7735              :             {
    7736            9 :               len = max_index_cst - index + 1;
    7737            9 :               d->raw_idx += len;
    7738              :             }
    7739          526 :           if (!reuse || off || d->cur == old_cur)
    7740              :             {
    7741           27 :               elt_init = copy_node (elt_init);
    7742           27 :               RAW_DATA_LENGTH (elt_init) = len;
    7743           27 :               RAW_DATA_POINTER (elt_init) += off;
    7744              :             }
    7745          526 :           TREE_TYPE (elt_init) = elt_type;
    7746              :         }
    7747     56637654 :       else if (d->cur->index)
    7748              :         {
    7749      5896663 :           elt_init = reshape_single_init (elt_type, d->cur->value, complain);
    7750      5896663 :           d->cur++;
    7751              :         }
    7752              :       else
    7753     50740991 :         elt_init = reshape_init_r (elt_type, d,
    7754              :                                    /*first_initializer_p=*/NULL_TREE,
    7755              :                                    complain);
    7756     56638180 :       if (elt_init == error_mark_node)
    7757              :         return error_mark_node;
    7758     56638002 :       tree idx = size_int (index);
    7759     56638002 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7760              :         {
    7761              :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7762              :              ctor had to be split.  */
    7763           72 :           new_init = build_constructor (init_list_type_node, NULL);
    7764           72 :           if (index)
    7765              :             {
    7766           72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7767           72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7768           72 :                       (d->cur - first_cur)
    7769              :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7770           72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7771              :                 {
    7772              :                   unsigned int j;
    7773              :                   tree nidx, nval;
    7774            4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7775              :                                             j, nidx, nval)
    7776            4 :                     if (nidx)
    7777              :                       {
    7778            4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7779            4 :                         (void) nval;
    7780            4 :                         break;
    7781              :                       }
    7782              :                 }
    7783              :             }
    7784              :           reuse = false;
    7785              :         }
    7786     56637934 :       if (reuse)
    7787              :         {
    7788     55117112 :           old_cur->index = idx;
    7789     55117112 :           old_cur->value = elt_init;
    7790              :         }
    7791              :       else
    7792      1520890 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7793              :                                 idx, elt_init);
    7794     56638002 :       if (!TREE_CONSTANT (elt_init))
    7795       196788 :         TREE_CONSTANT (new_init) = false;
    7796              : 
    7797              :       /* This can happen with an invalid initializer (c++/54501).  */
    7798     56638002 :       if (d->cur == old_cur
    7799        32082 :           && !sized_array_p
    7800        14085 :           && d->raw_idx == old_raw_idx)
    7801              :         break;
    7802              : 
    7803     56637999 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7804          526 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7805              :     }
    7806              : 
    7807              :   return new_init;
    7808              : }
    7809              : 
    7810              : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7811              :    Parameters are the same of reshape_init_r.  */
    7812              : 
    7813              : static tree
    7814       418867 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7815              :                     tsubst_flags_t complain)
    7816              : {
    7817       418867 :   tree max_index = NULL_TREE;
    7818              : 
    7819       418867 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7820              : 
    7821       418867 :   if (TYPE_DOMAIN (type))
    7822       229515 :     max_index = array_type_nelts_minus_one (type);
    7823              : 
    7824       418867 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7825       418867 :                                first_initializer_p, false, complain);
    7826              : }
    7827              : 
    7828              : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7829              :    Parameters are the same of reshape_init_r.  */
    7830              : 
    7831              : static tree
    7832        49906 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7833              : {
    7834        49906 :   tree max_index = NULL_TREE;
    7835              : 
    7836        49906 :   gcc_assert (VECTOR_TYPE_P (type));
    7837              : 
    7838        49906 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7839              :     {
    7840            0 :       tree value = d->cur->value;
    7841            0 :       if (!same_type_p (TREE_TYPE (value), type))
    7842              :         {
    7843            0 :           if (complain & tf_error)
    7844            0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7845            0 :                    TREE_TYPE (d->cur->value), type);
    7846            0 :           value = error_mark_node;
    7847              :         }
    7848            0 :       ++d->cur;
    7849            0 :       return value;
    7850              :     }
    7851              : 
    7852              :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7853        49906 :   if (VECTOR_TYPE_P (type))
    7854        49906 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7855              : 
    7856        49906 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7857        49906 :                                NULL_TREE, true, complain);
    7858              : }
    7859              : 
    7860              : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7861              :    INIT, in isolation from any designator or other initializers.  */
    7862              : 
    7863              : static tree
    7864      6548753 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7865              : {
    7866              :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7867              :      calling reshape_init, but this way can just live on the stack.  */
    7868      6548753 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7869      6548753 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7870      6548753 :   return reshape_init_r (type, &iter,
    7871              :                          /*first_initializer_p=*/NULL_TREE,
    7872      6548753 :                          complain);
    7873              : }
    7874              : 
    7875              : /* Subroutine of reshape_init_r, processes the initializers for classes
    7876              :    or union. Parameters are the same of reshape_init_r.  */
    7877              : 
    7878              : static tree
    7879      3774138 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7880              :                     tsubst_flags_t complain)
    7881              : {
    7882      3774138 :   tree field;
    7883      3774138 :   tree new_init;
    7884              : 
    7885      3774138 :   gcc_assert (CLASS_TYPE_P (type));
    7886              : 
    7887              :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7888      3774138 :   new_init = build_constructor (init_list_type_node, NULL);
    7889              : 
    7890      3774138 :   int binfo_idx = -1;
    7891      3774138 :   tree binfo = TYPE_BINFO (type);
    7892      3774138 :   tree base_binfo = NULL_TREE;
    7893      3774138 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7894              :     {
    7895              :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7896              :          deduction.  In this case we need to look through the binfo because a
    7897              :          template doesn't have base fields.  */
    7898         2781 :       binfo_idx = 0;
    7899         2781 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7900              :     }
    7901           86 :   if (base_binfo)
    7902              :     field = base_binfo;
    7903              :   else
    7904      3774052 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7905              : 
    7906      3774052 :   if (!field)
    7907              :     {
    7908              :       /* [dcl.init.aggr]
    7909              : 
    7910              :         An initializer for an aggregate member that is an
    7911              :         empty class shall have the form of an empty
    7912              :         initializer-list {}.  */
    7913          322 :       if (!first_initializer_p)
    7914              :         {
    7915          268 :           if (complain & tf_error)
    7916           13 :             error ("initializer for %qT must be brace-enclosed", type);
    7917          268 :           return error_mark_node;
    7918              :         }
    7919              :       return new_init;
    7920              :     }
    7921              : 
    7922              :   /* For C++29 designated initializers we do modify d->cur->index in place
    7923              :      to cache name lookup results.  Make sure to undo it before returning.  */
    7924      3773816 :   struct designator_undo {
    7925              :     constructor_elt *start, *end;
    7926      3773877 :     void undo ()
    7927              :     {
    7928      3774028 :       while (start != end)
    7929              :         {
    7930          151 :           start->index = DECL_NAME (start->index);
    7931          151 :           ++start;
    7932              :         }
    7933      3773877 :       start = end = nullptr;
    7934      3773877 :     }
    7935      3773816 :     ~designator_undo () { undo (); }
    7936      3773816 :   } desig_undo = { nullptr, nullptr };
    7937              : 
    7938              :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7939      3773816 :   tree last_was_pack_expansion = NULL_TREE;
    7940      3773816 :   bool first_desig = true;
    7941              : 
    7942              :   /* Loop through the initializable fields, gathering initializers.  */
    7943     11286742 :   while (d->cur != d->end)
    7944              :     {
    7945      7620859 :       tree field_init;
    7946      7620859 :       constructor_elt *old_cur = d->cur;
    7947      7620859 :       unsigned old_raw_idx = d->raw_idx;
    7948      7620859 :       bool direct_desig = false;
    7949              : 
    7950              :       /* Handle C++20 designated initializers.  */
    7951      7620859 :       if (d->cur->index)
    7952              :         {
    7953       652426 :           if (d->cur->index == error_mark_node)
    7954              :             return error_mark_node;
    7955              : 
    7956       652419 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7957              :             {
    7958          181 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7959          181 :               direct_desig = true;
    7960          181 :               field = d->cur->index;
    7961              :             }
    7962       652238 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7963              :             {
    7964       652232 :               if (first_desig && cxx_dialect >= cxx20)
    7965              :                 {
    7966       309168 :                   if (CONSTRUCTOR_NELTS (new_init))
    7967              :                     {
    7968          117 :                       constructor_elt *last
    7969          117 :                         = &CONSTRUCTOR_ELTS (new_init)->last ();
    7970          117 :                       if (last->index == NULL_TREE
    7971          117 :                           || TREE_CODE (last->index) != FIELD_DECL
    7972          234 :                           || !DECL_FIELD_IS_BASE (last->index))
    7973              :                         {
    7974           25 :                           if (complain & tf_error)
    7975           25 :                             error ("last non-designated initializer clause "
    7976              :                                    "does not appertain to a base class "
    7977              :                                    "subobject");
    7978           25 :                           return error_mark_node;
    7979              :                         }
    7980              :                     }
    7981              :                   first_desig = false;
    7982              :                 }
    7983       652207 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7984       652207 :               field = get_class_binding (type, d->cur->index);
    7985       652207 :               direct_desig = true;
    7986       652207 :               if (!field && cxx_dialect >= cxx29)
    7987           44 :                 field = lookup_member (type, d->cur->index, /*protect=*/2,
    7988              :                                        /*want_type=*/false, complain);
    7989              :             }
    7990              :           else
    7991              :             {
    7992            6 :               if (complain & tf_error)
    7993            6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7994              :                        " for class %qT", d->cur->index, type);
    7995            6 :               return error_mark_node;
    7996              :             }
    7997              : 
    7998          257 :           if (!field && ANON_AGGR_TYPE_P (type))
    7999              :             /* Apparently the designator isn't for a member of this anonymous
    8000              :                struct, so head back to the enclosing class.  */
    8001              :             break;
    8002              : 
    8003       652385 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    8004              :             {
    8005           43 :               if (complain & tf_error)
    8006              :                 {
    8007           28 :                   if (field && TREE_CODE (field) == TREE_LIST)
    8008              :                     {
    8009            5 :                       auto_diagnostic_group g;
    8010            5 :                       error ("request for member %qD is ambiguous",
    8011            5 :                              d->cur->index);
    8012            5 :                       print_candidates (input_location, field);
    8013            5 :                     }
    8014              :                   else
    8015           23 :                     error ("%qT has no non-static data member named %qD", type,
    8016           23 :                            d->cur->index);
    8017              :                 }
    8018           43 :               return error_mark_node;
    8019              :             }
    8020              : 
    8021              :           /* If the element is an anonymous union object and the initializer
    8022              :              list is a designated-initializer-list, the anonymous union object
    8023              :              is initialized by the designated-initializer-list { D }, where D
    8024              :              is the designated-initializer-clause naming a member of the
    8025              :              anonymous union object.  */
    8026       652342 :           tree ictx = DECL_CONTEXT (field);
    8027       652342 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    8028              :             {
    8029              :               /* Find the anon aggr that is a direct member of TYPE.  */
    8030          266 :               while (ANON_AGGR_TYPE_P (ictx))
    8031              :                 {
    8032          154 :                   tree cctx = TYPE_CONTEXT (ictx);
    8033          154 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    8034          140 :                     goto found;
    8035              :                   ictx = cctx;
    8036              :                 }
    8037              : 
    8038              :               /* In C++29 a designator can name a member of a base; in that
    8039              :                  case, go through the designators and replace ids with _DECLs
    8040              :                  to record the lookup for the most-derived class.  */
    8041          112 :               if (cxx_dialect >= cxx29)
    8042              :                 {
    8043          110 :                   tree ibinfo = lookup_base (type, ictx, ba_unique, NULL,
    8044              :                                              complain);
    8045          110 :                   if (!ibinfo)
    8046              :                     /* The designator names a field outside this base class,
    8047              :                        so we're done.  */
    8048              :                     break;
    8049           61 :                   else if (ibinfo != error_mark_node)
    8050              :                     {
    8051           74 :                       while (BINFO_INHERITANCE_CHAIN (ibinfo) != binfo)
    8052              :                         ibinfo = BINFO_INHERITANCE_CHAIN (ibinfo);
    8053           61 :                       ictx = TREE_TYPE (ibinfo);
    8054              : 
    8055           61 :                       desig_undo.undo ();
    8056              : 
    8057           61 :                       if (d->cur->index != field)
    8058              :                         {
    8059           47 :                           d->cur->index = field;
    8060           47 :                           desig_undo.start = d->cur;
    8061              :                         }
    8062           61 :                       constructor_elt *e = d->cur + 1;
    8063          228 :                       for (; e != d->end; ++e)
    8064              :                         {
    8065          173 :                           if (e->index == NULL_TREE
    8066          173 :                               || e->index == error_mark_node)
    8067              :                             break;
    8068          167 :                           if (desig_undo.start)
    8069              :                             {
    8070          104 :                               gcc_assert (TREE_CODE (e->index)
    8071              :                                           == IDENTIFIER_NODE);
    8072          104 :                               field = lookup_member (type, e->index,
    8073              :                                                      /*protect=*/2,
    8074              :                                                      /*want_type=*/false,
    8075              :                                                      tf_none);
    8076          104 :                               if (!field || TREE_CODE (field) != FIELD_DECL)
    8077              :                                 break;
    8078              :                             }
    8079              :                           else
    8080              :                             {
    8081           63 :                               gcc_assert (TREE_CODE (e->index) == FIELD_DECL);
    8082              :                               field = e->index;
    8083              :                             }
    8084              : 
    8085          167 :                           if (desig_undo.start)
    8086          104 :                             e->index = field;
    8087              :                         }
    8088           61 :                       if (desig_undo.start)
    8089           47 :                         desig_undo.end = e;
    8090           61 :                       goto found;
    8091              :                     }
    8092              :                 }
    8093              : 
    8094              :               /* Not found, e.g. FIELD is a member of a base class.  */
    8095            2 :               if (complain & tf_error)
    8096            2 :                 error ("%qD is not a direct member of %qT", field, type);
    8097            2 :               return error_mark_node;
    8098              : 
    8099          201 :             found:
    8100              :               /* Now find the TYPE member with that anon aggr type.  */
    8101          201 :               tree aafield = TYPE_FIELDS (type);
    8102         1622 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    8103         1622 :                 if (TREE_TYPE (aafield) == ictx)
    8104              :                   break;
    8105            0 :               gcc_assert (aafield);
    8106              :               field = aafield;
    8107              :               direct_desig = false;
    8108              :             }
    8109              :         }
    8110              : 
    8111              :       /* If we processed all the member of the class, we are done.  */
    8112      7620523 :       if (!field)
    8113              :         break;
    8114              : 
    8115     15240478 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    8116      7620249 :                                  ? field : NULL_TREE);
    8117           20 :       if (last_was_pack_expansion)
    8118              :         /* Each non-trailing aggregate element that is a pack expansion is
    8119              :            assumed to correspond to no elements of the initializer list.  */
    8120           20 :         goto continue_;
    8121              : 
    8122      7620229 :       if (direct_desig)
    8123              :         {
    8124              :           /* The designated field F is initialized from this one element.
    8125              : 
    8126              :              Note that we don't want to do this if we found the designator
    8127              :              inside an anon aggr above; we use the normal code to implement:
    8128              : 
    8129              :              "If the element is an anonymous union member and the initializer
    8130              :              list is a brace-enclosed designated- initializer-list, the element
    8131              :              is initialized by the designated-initializer-list { D }, where D
    8132              :              is the designated- initializer-clause naming a member of the
    8133              :              anonymous union member."  */
    8134       652090 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    8135       652090 :           field_init = reshape_single_init (TREE_TYPE (field),
    8136              :                                             d->cur->value, complain);
    8137       652090 :           d->cur++;
    8138              :         }
    8139              :       else
    8140      6968139 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    8141              :                                      /*first_initializer_p=*/NULL_TREE,
    8142              :                                      complain);
    8143              : 
    8144      7620229 :       if (field_init == error_mark_node)
    8145              :         return error_mark_node;
    8146              : 
    8147      7619939 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    8148              :         {
    8149              :           /* This can happen with an invalid initializer for a flexible
    8150              :              array member (c++/54441).  */
    8151            0 :           if (complain & tf_error)
    8152            0 :             error ("invalid initializer for %q#D", field);
    8153            0 :           return error_mark_node;
    8154              :         }
    8155              : 
    8156      7619939 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    8157              : 
    8158              :       /* [dcl.init.aggr]
    8159              : 
    8160              :         When a union  is  initialized with a brace-enclosed
    8161              :         initializer, the braces shall only contain an
    8162              :         initializer for the first member of the union.  */
    8163      7619939 :       if (TREE_CODE (type) == UNION_TYPE)
    8164              :         break;
    8165              : 
    8166      7512906 :     continue_:
    8167      7512926 :       if (base_binfo)
    8168              :         {
    8169          101 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    8170              :             field = base_binfo;
    8171              :           else
    8172           38 :             field = next_aggregate_field (TYPE_FIELDS (type));
    8173              :         }
    8174              :       else
    8175      7512825 :         field = next_aggregate_field (DECL_CHAIN (field));
    8176              :     }
    8177              : 
    8178              :   /* A trailing aggregate element that is a pack expansion is assumed to
    8179              :      correspond to all remaining elements of the initializer list (if any).  */
    8180      3773443 :   if (last_was_pack_expansion)
    8181              :     {
    8182           17 :       tree init = d->cur->value;
    8183           17 :       bool inc_cur;
    8184           17 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    8185            0 :         init = raw_init;
    8186           17 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    8187              :                               last_was_pack_expansion, init);
    8188           49 :       while (d->cur != d->end)
    8189           32 :         d->cur++;
    8190              :     }
    8191              : 
    8192              :   return new_init;
    8193      3773816 : }
    8194              : 
    8195              : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    8196              :    designators are not valid; either complain or return true to indicate
    8197              :    that reshape_init_r should return error_mark_node.  */
    8198              : 
    8199              : static bool
    8200       249795 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    8201              : {
    8202       249795 :   if (d->cur->index)
    8203              :     {
    8204           30 :       if (complain & tf_error)
    8205           45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    8206              :                   "C99 designator %qE outside aggregate initializer",
    8207              :                   d->cur->index);
    8208              :       else
    8209              :         return true;
    8210              :     }
    8211              :   return false;
    8212              : }
    8213              : 
    8214              : /* Subroutine of reshape_init, which processes a single initializer (part of
    8215              :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    8216              :    iterator within the CONSTRUCTOR which points to the initializer to process.
    8217              :    If this is the first initializer of the outermost CONSTRUCTOR node,
    8218              :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    8219              : 
    8220              : static tree
    8221     68740350 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    8222              :                 tsubst_flags_t complain)
    8223              : {
    8224     68740350 :   tree init = d->cur->value;
    8225              : 
    8226     68740350 :   if (error_operand_p (init))
    8227          130 :     return error_mark_node;
    8228              : 
    8229      4482340 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    8230     68989836 :       && has_designator_problem (d, complain))
    8231            0 :     return error_mark_node;
    8232              : 
    8233     68740220 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    8234              : 
    8235     68740220 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    8236              :     {
    8237              :       /* A complex type can be initialized from one or two initializers,
    8238              :          but braces are not elided.  */
    8239          672 :       init = consume_init (init, d);
    8240          672 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    8241              :         {
    8242            9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    8243              :             {
    8244            0 :               if (complain & tf_error)
    8245            0 :                 error ("too many initializers for %qT", type);
    8246              :               else
    8247            0 :                 return error_mark_node;
    8248              :             }
    8249              :         }
    8250          663 :       else if (first_initializer_p && d->cur != d->end)
    8251              :         {
    8252           36 :           if (error_operand_p (d->cur->value)
    8253           36 :               || has_designator_problem (d, complain))
    8254            0 :             return error_mark_node;
    8255           36 :           vec<constructor_elt, va_gc> *v = 0;
    8256           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8257           36 :           init = consume_init (d->cur->value, d);
    8258           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8259           36 :           init = build_constructor (init_list_type_node, v);
    8260              :         }
    8261              :       return init;
    8262              :     }
    8263              : 
    8264              :   /* If we have a designator, d doesn't initialize TYPE directly, it
    8265              :      initializes an element, with brace elision if !first_initializer_p.  But
    8266              :      if TYPE is non-aggregate (and we didn't already return error_mark_node),
    8267              :      we should have errored about the designator in has_designator_problem, so
    8268              :      now ignore it for error recovery.  */
    8269     68739548 :   if (d->cur->index)
    8270              :     {
    8271              :       /* Deliberately not CP_AGGREGATE_TYPE_P to get a better diagnostic for
    8272              :          trying to designate a member of a non-aggregate class.  */
    8273       366407 :       if (AGGREGATE_TYPE_P (type) || gnu_vector_type_p (type))
    8274       366401 :         goto skip_single;
    8275              :       else
    8276            6 :         gcc_checking_assert (seen_error ());
    8277              :     }
    8278              : 
    8279              :   /* A non-aggregate type is always initialized with a single
    8280              :      initializer.  */
    8281    136687593 :   if (!CP_AGGREGATE_TYPE_P (type)
    8282              :       /* As is an array with dependent bound, which we can see
    8283              :          during C++20 aggregate CTAD.  */
    8284     74006805 :       || (cxx_dialect >= cxx20
    8285      5592045 :           && TREE_CODE (type) == ARRAY_TYPE
    8286       452835 :           && uses_template_parms (TYPE_DOMAIN (type))))
    8287              :     {
    8288              :       /* It is invalid to initialize a non-aggregate type with a
    8289              :          brace-enclosed initializer before C++0x.
    8290              :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    8291              :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    8292              :          a CONSTRUCTOR (with a record type).  */
    8293     62680799 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    8294              :           /* Don't complain about a capture-init.  */
    8295       302551 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    8296     62972620 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    8297              :         {
    8298       291782 :           if (SCALAR_TYPE_P (type))
    8299              :             {
    8300          490 :               if (cxx_dialect < cxx11)
    8301              :                 {
    8302           16 :                   if (complain & tf_error)
    8303           16 :                     error ("braces around scalar initializer for type %qT",
    8304              :                            type);
    8305           16 :                   init = error_mark_node;
    8306              :                 }
    8307          474 :               else if (first_initializer_p
    8308          474 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    8309          296 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    8310              :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    8311              :                 {
    8312           13 :                   if (complain & tf_error)
    8313           13 :                     error ("too many braces around scalar initializer "
    8314              :                            "for type %qT", type);
    8315           13 :                   init = error_mark_node;
    8316              :                 }
    8317              :             }
    8318              :           else
    8319       291292 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8320              :         }
    8321     62680799 :       return consume_init (init, d);
    8322              :     }
    8323              : 
    8324              :   /* "If T is a class type and the initializer list has a single element of
    8325              :      type cv U, where U is T or a class derived from T, the object is
    8326              :      initialized from that element."  Even if T is an aggregate.  */
    8327      5668660 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    8328      5190306 :       && first_initializer_p
    8329      3494105 :       && d->end - d->cur == 1
    8330       604267 :       && TREE_CODE (init) != RAW_DATA_CST
    8331      6296615 :       && reference_related_p (type, TREE_TYPE (init)))
    8332              :     {
    8333          426 :       d->cur++;
    8334          426 :       return init;
    8335              :     }
    8336              : 
    8337              :   /* [dcl.init.aggr]
    8338              : 
    8339              :      All implicit type conversions (clause _conv_) are considered when
    8340              :      initializing the aggregate member with an initializer from an
    8341              :      initializer-list.  If the initializer can initialize a member,
    8342              :      the member is initialized.  Otherwise, if the member is itself a
    8343              :      non-empty subaggregate, brace elision is assumed and the
    8344              :      initializer is considered for the initialization of the first
    8345              :      member of the subaggregate.  */
    8346      2445364 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    8347              :       /* But don't try this for the first initializer, since that would be
    8348              :          looking through the outermost braces; A a2 = { a1 }; is not a
    8349              :          valid aggregate initialization.  */
    8350      3246624 :       && !first_initializer_p
    8351      5708937 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    8352        11358 :           || can_convert_arg (type, TREE_TYPE (init),
    8353        11358 :                               TREE_CODE (init) == RAW_DATA_CST
    8354      5691922 :                               ? build_int_cst (integer_type_node,
    8355         1606 :                                                *(const unsigned char *)
    8356         1606 :                                                RAW_DATA_POINTER (init))
    8357              :                               : init,
    8358              :                               LOOKUP_NORMAL, complain)))
    8359         5693 :     return consume_init (init, d);
    8360              : 
    8361      6052630 :  skip_single:
    8362              : 
    8363              :   /* [dcl.init.string]
    8364              : 
    8365              :       A char array (whether plain char, signed char, or unsigned char)
    8366              :       can be initialized by a string-literal (optionally enclosed in
    8367              :       braces); a wchar_t array can be initialized by a wide
    8368              :       string-literal (optionally enclosed in braces).  */
    8369      6052630 :   if (TREE_CODE (type) == ARRAY_TYPE
    8370      6052630 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    8371              :     {
    8372       111525 :       tree str_init = init;
    8373       111525 :       tree stripped_str_init = stripped_init;
    8374       111525 :       reshape_iter stripd = {};
    8375              : 
    8376              :       /* Strip one level of braces if and only if they enclose a single
    8377              :          element (as allowed by [dcl.init.string]).  */
    8378       111525 :       if (!first_initializer_p
    8379         2780 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    8380       113151 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    8381              :         {
    8382          399 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    8383          399 :           str_init = stripd.cur->value;
    8384          399 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    8385              :         }
    8386              : 
    8387              :       /* If it's a string literal, then it's the initializer for the array
    8388              :          as a whole. Otherwise, continue with normal initialization for
    8389              :          array types (one value per array element).  */
    8390       111525 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    8391              :         {
    8392           72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    8393         1062 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    8394          990 :             return error_mark_node;
    8395          990 :           d->cur++;
    8396          990 :           return str_init;
    8397              :         }
    8398              :     }
    8399              : 
    8400              :   /* The following cases are about aggregates. If we are not within a full
    8401              :      initializer already, and there is not a CONSTRUCTOR, it means that there
    8402              :      is a missing set of braces (that is, we are processing the case for
    8403              :      which reshape_init exists).  */
    8404      6051640 :   bool braces_elided_p = false;
    8405      6051640 :   if (!first_initializer_p)
    8406              :     {
    8407      1819414 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR && !d->cur->index)
    8408              :         {
    8409      1808746 :           tree init_type = TREE_TYPE (init);
    8410      1808746 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    8411              :             /* There is no need to call reshape_init for pointer-to-member
    8412              :                function initializers, as they are always constructed correctly
    8413              :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    8414              :                which is missing outermost braces.  We should warn below, and
    8415              :                one of the routines below will wrap it in additional { }.  */;
    8416              :           /* For a nested compound literal, proceed to specialized routines,
    8417              :              to handle initialization of arrays and similar.  */
    8418      1808737 :           else if (COMPOUND_LITERAL_P (stripped_init))
    8419            8 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8420              :           /* A CONSTRUCTOR of the target's type is a previously
    8421              :              digested initializer.  */
    8422      1808729 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    8423              :             {
    8424            0 :               ++d->cur;
    8425            0 :               return init;
    8426              :             }
    8427              :           else
    8428              :             {
    8429              :               /* Something that hasn't been reshaped yet.  */
    8430      1808729 :               ++d->cur;
    8431      1808729 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8432      1808729 :               return reshape_init (type, init, complain);
    8433              :             }
    8434              :         }
    8435              : 
    8436        10685 :       if (complain & tf_warning)
    8437         9495 :         warning (OPT_Wmissing_braces,
    8438              :                  "missing braces around initializer for %qT",
    8439              :                  type);
    8440              :       braces_elided_p = true;
    8441              :     }
    8442              : 
    8443              :   /* Dispatch to specialized routines.  */
    8444      4242911 :   tree new_init;
    8445      4242911 :   if (CLASS_TYPE_P (type))
    8446      3774138 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    8447       468773 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    8448       418867 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    8449        49906 :   else if (VECTOR_TYPE_P (type))
    8450        49906 :     new_init = reshape_init_vector (type, d, complain);
    8451              :   else
    8452            0 :     gcc_unreachable ();
    8453              : 
    8454      4242911 :   if (braces_elided_p
    8455        10685 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    8456        10408 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    8457              : 
    8458              :   return new_init;
    8459              : }
    8460              : 
    8461              : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    8462              :    brace-enclosed aggregate initializer.
    8463              : 
    8464              :    INIT is the CONSTRUCTOR containing the list of initializers describing
    8465              :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    8466              :    It may not presently match the shape of the TYPE; for example:
    8467              : 
    8468              :      struct S { int a; int b; };
    8469              :      struct S a[] = { 1, 2, 3, 4 };
    8470              : 
    8471              :    Here INIT will hold a vector of four elements, rather than a
    8472              :    vector of two elements, each itself a vector of two elements.  This
    8473              :    routine transforms INIT from the former form into the latter.  The
    8474              :    revised CONSTRUCTOR node is returned.  */
    8475              : 
    8476              : tree
    8477     12705990 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    8478              : {
    8479     12705990 :   vec<constructor_elt, va_gc> *v;
    8480     12705990 :   reshape_iter d;
    8481     12705990 :   tree new_init;
    8482              : 
    8483     12705990 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    8484              : 
    8485     12705990 :   v = CONSTRUCTOR_ELTS (init);
    8486              : 
    8487              :   /* An empty constructor does not need reshaping, and it is always a valid
    8488              :      initializer.  */
    8489     12705990 :   if (vec_safe_is_empty (v))
    8490              :     return init;
    8491              : 
    8492      4483646 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    8493              :     /* Already reshaped.  */
    8494              :     return init;
    8495              : 
    8496              :   /* Brace elision is not performed for a CONSTRUCTOR representing
    8497              :      parenthesized aggregate initialization.  */
    8498      4483497 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    8499              :     {
    8500          849 :       tree elt = (*v)[0].value;
    8501              :       /* If we're initializing a char array from a string-literal that is
    8502              :          enclosed in braces, unwrap it here.  */
    8503          849 :       if (TREE_CODE (type) == ARRAY_TYPE
    8504          277 :           && vec_safe_length (v) == 1
    8505          149 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    8506          888 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    8507           34 :         return elt;
    8508              :       return init;
    8509              :     }
    8510              : 
    8511              :   /* Handle [dcl.init.list] direct-list-initialization from
    8512              :      single element of enumeration with a fixed underlying type.  */
    8513      4482648 :   if (is_direct_enum_init (type, init))
    8514              :     {
    8515          181 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    8516          181 :       type = cv_unqualified (type);
    8517          181 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    8518              :         {
    8519          166 :           warning_sentinel w (warn_useless_cast);
    8520          166 :           warning_sentinel w2 (warn_ignored_qualifiers);
    8521          166 :           return cp_build_c_cast (input_location, type, elt,
    8522              :                                   tf_warning_or_error);
    8523          166 :         }
    8524              :       else
    8525           15 :         return error_mark_node;
    8526              :     }
    8527              : 
    8528              :   /* Recurse on this CONSTRUCTOR.  */
    8529      4482467 :   d.cur = &(*v)[0];
    8530      4482467 :   d.end = d.cur + v->length ();
    8531      4482467 :   d.raw_idx = 0;
    8532              : 
    8533      4482467 :   new_init = reshape_init_r (type, &d, init, complain);
    8534      4482467 :   if (new_init == error_mark_node)
    8535              :     return error_mark_node;
    8536              : 
    8537              :   /* Make sure all the element of the constructor were used. Otherwise,
    8538              :      issue an error about exceeding initializers.  */
    8539      4481792 :   if (d.cur != d.end)
    8540              :     {
    8541          207 :       if (complain & tf_error)
    8542           64 :         error ("too many initializers for %qT", type);
    8543          207 :       return error_mark_node;
    8544              :     }
    8545              : 
    8546      4481585 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    8547      4481585 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8548       619600 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    8549      4481585 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    8550      4481585 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8551        74605 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    8552              :                          /* The old extension allows brace elision
    8553              :                             (128532).  */
    8554              :                          || cxx_dialect < cxx20
    8555              :                          || seen_error ());
    8556              : 
    8557              :   return new_init;
    8558              : }
    8559              : 
    8560              : /* Verify array initializer.  Returns true if errors have been reported.  */
    8561              : 
    8562              : bool
    8563      1028526 : check_array_initializer (tree decl, tree type, tree init)
    8564              : {
    8565      1028526 :   tree element_type = TREE_TYPE (type);
    8566              : 
    8567              :   /* Structured binding when initialized with an array type needs
    8568              :      to have complete type.  */
    8569      1028526 :   if (decl
    8570      1010880 :       && DECL_DECOMPOSITION_P (decl)
    8571        10451 :       && DECL_DECOMP_IS_BASE (decl)
    8572      1038977 :       && !COMPLETE_TYPE_P (type))
    8573              :     {
    8574            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    8575              :                 "structured binding has incomplete type %qT", type);
    8576            0 :       TREE_TYPE (decl) = error_mark_node;
    8577            0 :       return true;
    8578              :     }
    8579              : 
    8580              :   /* The array type itself need not be complete, because the
    8581              :      initializer may tell us how many elements are in the array.
    8582              :      But, the elements of the array must be complete.  */
    8583      1028526 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    8584              :     {
    8585           15 :       if (decl)
    8586            9 :         error_at (DECL_SOURCE_LOCATION (decl),
    8587              :                   "elements of array %q#D have incomplete type", decl);
    8588              :       else
    8589            6 :         error ("elements of array %q#T have incomplete type", type);
    8590              :       return true;
    8591              :     }
    8592              : 
    8593      1028511 :   location_t loc = (decl ? location_of (decl) : input_location);
    8594      1028511 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    8595              :     return true;
    8596              : 
    8597              :   /* A compound literal can't have variable size.  */
    8598      1028511 :   if (init && !decl
    8599      1028511 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    8600        17637 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    8601              :     {
    8602            3 :       error ("variable-sized compound literal");
    8603            3 :       return true;
    8604              :     }
    8605              :   return false;
    8606              : }
    8607              : 
    8608              : /* Subroutine of check_initializer; args are passed down from that function.
    8609              :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    8610              : 
    8611              : static tree
    8612      3255724 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    8613              : {
    8614      3255724 :   gcc_assert (stmts_are_full_exprs_p ());
    8615      3255724 :   if (init)
    8616      2654005 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    8617      3255724 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    8618              : }
    8619              : 
    8620              : /* Verify INIT (the initializer for DECL), and record the
    8621              :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    8622              :    grok_reference_init.
    8623              : 
    8624              :    If the return value is non-NULL, it is an expression that must be
    8625              :    evaluated dynamically to initialize DECL.  */
    8626              : 
    8627              : static tree
    8628     58444836 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    8629              : {
    8630     58444836 :   tree type;
    8631     58444836 :   tree init_code = NULL;
    8632     58444836 :   tree core_type;
    8633              : 
    8634              :   /* Things that are going to be initialized need to have complete
    8635              :      type.  */
    8636     58444836 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    8637              : 
    8638     58444836 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    8639              :     {
    8640              :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    8641              :          it doesn't have storage to be initialized.  */
    8642          708 :       gcc_assert (init == NULL_TREE);
    8643              :       return NULL_TREE;
    8644              :     }
    8645              : 
    8646     58444128 :   if (type == error_mark_node)
    8647              :     /* We will have already complained.  */
    8648              :     return NULL_TREE;
    8649              : 
    8650     58444128 :   if (TREE_CODE (type) == ARRAY_TYPE)
    8651              :     {
    8652      1010880 :       if (check_array_initializer (decl, type, init))
    8653              :         return NULL_TREE;
    8654              :     }
    8655     57433248 :   else if (!COMPLETE_TYPE_P (type))
    8656              :     {
    8657           37 :       error_at (DECL_SOURCE_LOCATION (decl),
    8658              :                 "%q#D has incomplete type", decl);
    8659           37 :       TREE_TYPE (decl) = error_mark_node;
    8660           37 :       return NULL_TREE;
    8661              :     }
    8662              :   else
    8663              :     /* There is no way to make a variable-sized class type in GNU C++.  */
    8664     57433211 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    8665              : 
    8666     58444082 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    8667              :     {
    8668      2930736 :       int init_len = CONSTRUCTOR_NELTS (init);
    8669      2930736 :       if (SCALAR_TYPE_P (type))
    8670              :         {
    8671        75652 :           if (init_len == 0)
    8672              :             {
    8673        42697 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8674        42697 :               init = build_zero_init (type, NULL_TREE, false);
    8675              :             }
    8676        32955 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    8677              :             {
    8678           12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8679              :                         "scalar object %qD requires one element in "
    8680              :                         "initializer", decl);
    8681            6 :               TREE_TYPE (decl) = error_mark_node;
    8682            6 :               return NULL_TREE;
    8683              :             }
    8684              :         }
    8685              :     }
    8686              : 
    8687     58444076 :   if (TREE_CODE (decl) == CONST_DECL)
    8688              :     {
    8689            0 :       gcc_assert (!TYPE_REF_P (type));
    8690              : 
    8691            0 :       DECL_INITIAL (decl) = init;
    8692              : 
    8693            0 :       gcc_assert (init != NULL_TREE);
    8694              :       init = NULL_TREE;
    8695              :     }
    8696     58444076 :   else if (!init && DECL_REALLY_EXTERN (decl))
    8697              :     ;
    8698     58444076 :   else if (flag_openmp
    8699       195873 :            && VAR_P (decl)
    8700       195873 :            && DECL_LANG_SPECIFIC (decl)
    8701       112381 :            && DECL_OMP_DECLARE_MAPPER_P (decl)
    8702     58444076 :            && TREE_CODE (init) == OMP_DECLARE_MAPPER)
    8703              :     return NULL_TREE;
    8704      4346504 :   else if (init || type_build_ctor_call (type)
    8705     62188858 :            || TYPE_REF_P (type))
    8706              :     {
    8707     54699309 :       if (TYPE_REF_P (type))
    8708              :         {
    8709       385582 :           init = grok_reference_init (decl, type, init, flags);
    8710       385582 :           flags |= LOOKUP_ALREADY_DIGESTED;
    8711              :         }
    8712     54313727 :       else if (!init)
    8713       601722 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8714              :                                            tf_warning_or_error);
    8715              :       /* Do not reshape constructors of vectors (they don't need to be
    8716              :          reshaped.  */
    8717     53712005 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    8718              :         {
    8719      2887650 :           if (is_std_init_list (type))
    8720              :             {
    8721          410 :               init = perform_implicit_conversion (type, init,
    8722              :                                                   tf_warning_or_error);
    8723          410 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8724              :             }
    8725      2887240 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    8726              :             {
    8727              :               /* Don't reshape if the class has constructors.  */
    8728       451174 :               if (cxx_dialect == cxx98)
    8729            6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8730              :                           "in C++98 %qD must be initialized by "
    8731              :                           "constructor, not by %<{...}%>",
    8732              :                           decl);
    8733              :             }
    8734      2436066 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    8735              :             {
    8736            0 :               error ("opaque vector types cannot be initialized");
    8737            0 :               init = error_mark_node;
    8738              :             }
    8739              :           else
    8740              :             {
    8741      2436066 :               init = reshape_init (type, init, tf_warning_or_error);
    8742      2436066 :               flags |= LOOKUP_NO_NARROWING;
    8743              :             }
    8744              :         }
    8745              :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    8746              :          is initialized as follows..."  So handle things like
    8747              : 
    8748              :           int a[](1, 2, 3);
    8749              : 
    8750              :          which is permitted in C++20 by P0960.  */
    8751     50824355 :       else if (TREE_CODE (init) == TREE_LIST
    8752       769415 :                && TREE_TYPE (init) == NULL_TREE
    8753       769415 :                && TREE_CODE (type) == ARRAY_TYPE
    8754          182 :                && !DECL_DECOMPOSITION_P (decl)
    8755     50824507 :                && (cxx_dialect >= cxx20))
    8756          142 :         init = do_aggregate_paren_init (init, type);
    8757     50824213 :       else if (TREE_CODE (init) == TREE_LIST
    8758       769273 :                && TREE_TYPE (init) != unknown_type_node
    8759     51593486 :                && !MAYBE_CLASS_TYPE_P (type))
    8760              :         {
    8761       132061 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8762              : 
    8763              :           /* We get here with code like `int a (2);' */
    8764       132061 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    8765              :                                                   tf_warning_or_error);
    8766              :         }
    8767              : 
    8768              :       /* If DECL has an array type without a specific bound, deduce the
    8769              :          array size from the initializer.  */
    8770     54699309 :       maybe_deduce_size_from_array_init (decl, init);
    8771     54699309 :       type = TREE_TYPE (decl);
    8772     54699309 :       if (type == error_mark_node)
    8773              :         return NULL_TREE;
    8774              : 
    8775    105886633 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    8776      5431747 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    8777      8068521 :            && !(init
    8778      4829618 :                 && BRACE_ENCLOSED_INITIALIZER_P (init)
    8779      5274368 :                 && CP_AGGREGATE_TYPE_P (type)))
    8780    106153283 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    8781              :         {
    8782      3255724 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    8783              : 
    8784              :           /* A constructor call is a non-trivial initializer even if
    8785              :              it isn't explicitly written.  */
    8786      3255724 :           if (TREE_SIDE_EFFECTS (init_code))
    8787      3232132 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    8788              : 
    8789              :           /* If this is a constexpr initializer, expand_default_init will
    8790              :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    8791              :              case, pull the initializer back out and pass it down into
    8792              :              store_init_value.  */
    8793      8661709 :           while (true)
    8794              :             {
    8795      8661709 :               if (TREE_CODE (init_code) == EXPR_STMT
    8796      5440984 :                   || TREE_CODE (init_code) == STMT_EXPR
    8797      5403310 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    8798      5368476 :                 init_code = TREE_OPERAND (init_code, 0);
    8799      3293233 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    8800        37509 :                 init_code = BIND_EXPR_BODY (init_code);
    8801              :               else
    8802              :                 break;
    8803              :             }
    8804      3255724 :           if (TREE_CODE (init_code) == INIT_EXPR)
    8805              :             {
    8806              :               /* In C++20, the call to build_aggr_init could have created
    8807              :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    8808              :                  A(1, 2).  */
    8809      2139566 :               init = TREE_OPERAND (init_code, 1);
    8810      2139566 :               init_code = NULL_TREE;
    8811              :               /* Don't call digest_init; it's unnecessary and will complain
    8812              :                  about aggregate initialization of non-aggregate classes.  */
    8813      2139566 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8814              :             }
    8815      1116158 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    8816      2213238 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8817              :             {
    8818              :               /* Declared constexpr or constinit, but no suitable initializer;
    8819              :                  massage init appropriately so we can pass it into
    8820              :                  store_init_value for the error.  */
    8821        19096 :               tree new_init = NULL_TREE;
    8822        19096 :               if (!processing_template_decl
    8823          274 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8824          232 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8825        18864 :               else if (CLASS_TYPE_P (type)
    8826        37728 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8827        18683 :                 new_init = build_functional_cast (input_location, type,
    8828              :                                                   init, tf_none);
    8829        18915 :               if (new_init)
    8830              :                 {
    8831        18915 :                   init = new_init;
    8832        18915 :                   if (TREE_CODE (init) == TARGET_EXPR
    8833          261 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8834          261 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8835              :                 }
    8836              :               init_code = NULL_TREE;
    8837              :             }
    8838              :           else
    8839              :             init = NULL_TREE;
    8840              :         }
    8841              : 
    8842     53602243 :       if (init && TREE_CODE (init) != TREE_VEC)
    8843              :         {
    8844     53602228 :           init_code = store_init_value (decl, init, cleanups, flags);
    8845              : 
    8846     53599531 :           if (DECL_INITIAL (decl)
    8847     38825521 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8848     56718071 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8849              :             {
    8850      1382956 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8851      1382956 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8852      1382956 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8853           36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8854              :             }
    8855              : 
    8856      2637573 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8857        66512 :               && DECL_INITIAL (decl)
    8858        65773 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8859     53660880 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8860            6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8861            3 :                                          DECL_SOURCE_LOCATION (decl)),
    8862            3 :                         0, "array %qD initialized by parenthesized "
    8863              :                         "string literal %qE",
    8864            3 :                         decl, DECL_INITIAL (decl));
    8865              :           init = NULL_TREE;
    8866              :         }
    8867              :     }
    8868      3744767 :   else if (!init && REFLECTION_TYPE_P (type))
    8869              :     {
    8870              :       /* [dcl.init.general]: To default-initialize an object of type
    8871              :          std::meta::info means that the object is zero-initialized.  */
    8872          164 :       DECL_INITIAL (decl)
    8873          164 :         = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
    8874          164 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    8875          164 :       TREE_CONSTANT (decl) = true;
    8876          164 :       init = NULL_TREE;
    8877              :     }
    8878              :   else
    8879              :     {
    8880      7489206 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    8881      4562537 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    8882       817919 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    8883           21 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    8884              :                                                   /*complain=*/true);
    8885              : 
    8886      3744603 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8887              :                                          tf_warning_or_error);
    8888              :     }
    8889              : 
    8890          167 :   if (init && init != error_mark_node)
    8891            0 :     init_code = cp_build_init_expr (decl, init);
    8892              : 
    8893     16025667 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    8894     58500788 :       && init_code != error_mark_node)
    8895              :     init_code = NULL_TREE;
    8896              : 
    8897     58384249 :   if (init_code)
    8898              :     {
    8899              :       /* We might have set these in cp_finish_decl.  */
    8900     15968541 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    8901     15968541 :       TREE_CONSTANT (decl) = false;
    8902              :     }
    8903              : 
    8904     15968541 :   if (init_code
    8905     15968541 :       && DECL_IN_AGGR_P (decl)
    8906            6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8907              :     {
    8908            0 :       static int explained = 0;
    8909              : 
    8910            0 :       auto_diagnostic_group d;
    8911            0 :       if (cxx_dialect < cxx11)
    8912            0 :         error ("initializer invalid for static member with constructor");
    8913            0 :       else if (cxx_dialect < cxx17)
    8914            0 :         error ("non-constant in-class initialization invalid for static "
    8915              :                "member %qD", decl);
    8916              :       else
    8917            0 :         error ("non-constant in-class initialization invalid for non-inline "
    8918              :                "static member %qD", decl);
    8919            0 :       if (!explained)
    8920              :         {
    8921            0 :           inform (input_location,
    8922              :                   "(an out of class initialization is required)");
    8923            0 :           explained = 1;
    8924              :         }
    8925            0 :       return NULL_TREE;
    8926            0 :     }
    8927              : 
    8928              :   return init_code;
    8929              : }
    8930              : 
    8931              : /* If DECL is not a local variable, give it RTL.  */
    8932              : 
    8933              : static void
    8934    124169910 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    8935              : {
    8936    124169910 :   int toplev = toplevel_bindings_p ();
    8937    124169910 :   int defer_p;
    8938              : 
    8939              :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    8940    124169910 :   if (asmspec)
    8941              :     {
    8942              :       /* The `register' keyword, when used together with an
    8943              :          asm-specification, indicates that the variable should be
    8944              :          placed in a particular register.  */
    8945      1018635 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    8946              :         {
    8947           87 :           if (TREE_ADDRESSABLE (decl))
    8948            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    8949              :                       "address of explicit register variable %qD requested",
    8950              :                       decl);
    8951              :           else
    8952              :             {
    8953           84 :               set_user_assembler_name (decl, asmspec);
    8954           84 :               DECL_HARD_REGISTER (decl) = 1;
    8955              :             }
    8956              :         }
    8957              :       else
    8958              :         {
    8959      1018548 :           if (TREE_CODE (decl) == FUNCTION_DECL
    8960      1018548 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    8961        81432 :             set_builtin_user_assembler_name (decl, asmspec);
    8962      1018548 :           set_user_assembler_name (decl, asmspec);
    8963      1018548 :           if (DECL_LOCAL_DECL_P (decl))
    8964            6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    8965              :               /* We have to propagate the name to the ns-alias.
    8966              :                  This is horrible, as we're affecting a
    8967              :                  possibly-shared decl.  Again, a one-true-decl
    8968              :                  model breaks down.  */
    8969            6 :               if (ns_decl != error_mark_node)
    8970            6 :                 set_user_assembler_name (ns_decl, asmspec);
    8971              :         }
    8972              :     }
    8973              : 
    8974              :   /* Handle non-variables up front.  */
    8975    124169910 :   if (!VAR_P (decl))
    8976              :     {
    8977     59042346 :       rest_of_decl_compilation (decl, toplev, at_eof);
    8978     59042346 :       return;
    8979              :     }
    8980              : 
    8981              :   /* If we see a class member here, it should be a static data
    8982              :      member.  */
    8983     65127564 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    8984              :     {
    8985      5604575 :       gcc_assert (TREE_STATIC (decl));
    8986              :       /* An in-class declaration of a static data member should be
    8987              :          external; it is only a declaration, and not a definition.  */
    8988      5604575 :       if (init == NULL_TREE)
    8989      5604550 :         gcc_assert (DECL_EXTERNAL (decl)
    8990              :                     || !TREE_PUBLIC (decl));
    8991              :     }
    8992              : 
    8993              :   /* We don't create any RTL for local variables.  */
    8994     65127564 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8995              :     return;
    8996              : 
    8997              :   /* Don't output reflection variables.  */
    8998     39997030 :   if (consteval_only_p (decl))
    8999              :     {
    9000              :       /* Disable assemble_variable.  */
    9001         1540 :       DECL_EXTERNAL (decl) = true;
    9002              :       /* Undo make_decl_one_only.  */
    9003         1540 :       if (DECL_COMDAT_GROUP (decl))
    9004              :         {
    9005          262 :           symtab_node *node = symtab_node::get (decl);
    9006          262 :           node->set_comdat_group (NULL);
    9007          262 :           node->dissolve_same_comdat_group_list ();
    9008              :         }
    9009              :       return;
    9010              :     }
    9011              : 
    9012              :   /* We defer emission of local statics until the corresponding
    9013              :      DECL_EXPR is expanded.  But with constexpr its function might never
    9014              :      be expanded, so go ahead and tell cgraph about the variable now.  */
    9015     79990980 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    9016       142075 :               && !var_in_maybe_constexpr_fn (decl))
    9017     79853655 :              || DECL_VIRTUAL_P (decl));
    9018              : 
    9019              :   /* Defer template instantiations.  */
    9020     39995490 :   if (DECL_LANG_SPECIFIC (decl)
    9021     39995490 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    9022              :     defer_p = 1;
    9023              : 
    9024              :   /* If we're not deferring, go ahead and assemble the variable.  */
    9025     20414008 :   if (!defer_p)
    9026     18014418 :     rest_of_decl_compilation (decl, toplev, at_eof);
    9027              : }
    9028              : 
    9029              : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    9030              : 
    9031              : static tree
    9032     11425032 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    9033              : {
    9034              :   /* Stop at types or full-expression boundaries.  */
    9035     11425032 :   if (TYPE_P (*stmt_p)
    9036     11424804 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    9037              :     {
    9038          488 :       *walk_subtrees = 0;
    9039          488 :       return NULL_TREE;
    9040              :     }
    9041              : 
    9042     11424544 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    9043              :     {
    9044       249966 :       tree guard = (tree)data;
    9045       249966 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    9046              : 
    9047       124857 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    9048       370799 :           && !expr_noexcept_p (tcleanup, tf_none))
    9049              :         {
    9050          145 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    9051              :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    9052              :              cleanup.  */
    9053          145 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    9054          145 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    9055              :         }
    9056              :     }
    9057              : 
    9058              :   return NULL_TREE;
    9059              : }
    9060              : 
    9061              : /* We're initializing a local variable which has a cleanup GUARD.  If there
    9062              :    are any temporaries used in the initializer INIT of this variable, we
    9063              :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    9064              :    variable will be cleaned up properly if one of them throws.
    9065              : 
    9066              :    Unfortunately, there's no way to express this properly in terms of
    9067              :    nesting, as the regions for the temporaries overlap the region for the
    9068              :    variable itself; if there are two temporaries, the variable needs to be
    9069              :    the first thing destroyed if either of the temporary destructors throws.
    9070              :    However, we only want to run the variable's cleanup if it actually got
    9071              :    constructed.  So we need to guard the temporary cleanups with the
    9072              :    variable's cleanup if they are run on the normal path, but not if they
    9073              :    are run on the exceptional path.  We implement this by telling
    9074              :    honor_protect_cleanup_actions to strip the variable cleanup from the
    9075              :    exceptional path.
    9076              : 
    9077              :    Another approach could be to make the variable cleanup region enclose
    9078              :    initialization, but depend on a flag to indicate that the variable is
    9079              :    initialized; that's effectively what we do for arrays.  But the current
    9080              :    approach works fine for non-arrays, and has no code overhead in the usual
    9081              :    case where the temporary destructors are noexcept.  */
    9082              : 
    9083              : static void
    9084      1027202 : wrap_temporary_cleanups (tree init, tree guard)
    9085              : {
    9086      1027202 :   if (TREE_CODE (guard) == BIND_EXPR)
    9087              :     {
    9088              :       /* An array cleanup region already encloses any temporary cleanups,
    9089              :          don't wrap it around them again.  */
    9090          422 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    9091              :       return;
    9092              :     }
    9093      1026780 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    9094              : }
    9095              : 
    9096              : /* Generate code to initialize DECL (a local variable).  */
    9097              : 
    9098              : static void
    9099     25130507 : initialize_local_var (tree decl, tree init, bool decomp)
    9100              : {
    9101     25130507 :   tree type = TREE_TYPE (decl);
    9102     25130507 :   tree cleanup;
    9103     25130507 :   int already_used;
    9104              : 
    9105     25130507 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    9106     25130507 :   gcc_assert (!TREE_STATIC (decl));
    9107              : 
    9108     25130507 :   if (DECL_SIZE (decl) == NULL_TREE)
    9109              :     {
    9110              :       /* If we used it already as memory, it must stay in memory.  */
    9111            0 :       DECL_INITIAL (decl) = NULL_TREE;
    9112            0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    9113            0 :       return;
    9114              :     }
    9115              : 
    9116     25130507 :   if (type == error_mark_node)
    9117              :     return;
    9118              : 
    9119              :   /* Compute and store the initial value.  */
    9120     25130507 :   already_used = TREE_USED (decl) || TREE_USED (type);
    9121     25130507 :   if (TREE_USED (type))
    9122           32 :     DECL_READ_P (decl) = 1;
    9123              : 
    9124              :   /* Generate a cleanup, if necessary.  */
    9125     25130507 :   cleanup = (decomp ? NULL_TREE
    9126     25095110 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    9127              : 
    9128              :   /* Perform the initialization.  */
    9129     25130507 :   if (init)
    9130              :     {
    9131     15954203 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    9132     15954203 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    9133     14566152 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    9134     22557988 :           && TREE_OPERAND (init, 0) == decl)
    9135              :         {
    9136              :           /* Stick simple initializers in DECL_INITIAL so that
    9137              :              -Wno-init-self works (c++/34772).  */
    9138      7991836 :           DECL_INITIAL (decl) = rinit;
    9139              : 
    9140      7991836 :           if (warn_init_self && TYPE_REF_P (type))
    9141              :             {
    9142         2469 :               STRIP_NOPS (rinit);
    9143         2469 :               if (rinit == decl)
    9144            3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    9145            3 :                             OPT_Winit_self,
    9146              :                             "reference %qD is initialized with itself", decl);
    9147              :             }
    9148              :         }
    9149              :       else
    9150              :         {
    9151      7962367 :           int saved_stmts_are_full_exprs_p;
    9152              : 
    9153              :           /* If we're only initializing a single object, guard the
    9154              :              destructors of any temporaries used in its initializer with
    9155              :              its destructor.  */
    9156      7962367 :           if (cleanup)
    9157      1023748 :             wrap_temporary_cleanups (init, cleanup);
    9158              : 
    9159      7962367 :           gcc_assert (building_stmt_list_p ());
    9160      7962367 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    9161              :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    9162              :              bases, those will have CLEANUP_POINT_EXPR at the end of
    9163              :              code emitted by cp_finish_decomp.  */
    9164      7962367 :           if (decomp)
    9165        34897 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    9166              :           else
    9167      7927470 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    9168      7962367 :           finish_expr_stmt (init);
    9169      7962367 :           current_stmt_tree ()->stmts_are_full_exprs_p
    9170      7962367 :             = saved_stmts_are_full_exprs_p;
    9171              :         }
    9172              :     }
    9173              : 
    9174              :   /* Set this to 0 so we can tell whether an aggregate which was
    9175              :      initialized was ever used.  Don't do this if it has a
    9176              :      destructor, so we don't complain about the 'resource
    9177              :      allocation is initialization' idiom.  Now set
    9178              :      attribute((unused)) on types so decls of that type will be
    9179              :      marked used. (see TREE_USED, above.)  */
    9180     25130507 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    9181      2246217 :       && ! already_used
    9182        25289 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9183     25152899 :       && DECL_NAME (decl))
    9184        22344 :     TREE_USED (decl) = 0;
    9185     25108163 :   else if (already_used)
    9186     22076659 :     TREE_USED (decl) = 1;
    9187              : 
    9188     25130507 :   if (cleanup)
    9189      1037549 :     finish_decl_cleanup (decl, cleanup);
    9190              : }
    9191              : 
    9192              : /* DECL is a VAR_DECL for a compiler-generated variable with static
    9193              :    storage duration (like a virtual table) whose initializer is a
    9194              :    compile-time constant.  Initialize the variable and provide it to the
    9195              :    back end.  */
    9196              : 
    9197              : void
    9198      2221376 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    9199              : {
    9200      2221376 :   tree init;
    9201      2221376 :   gcc_assert (DECL_ARTIFICIAL (decl));
    9202      2221376 :   init = build_constructor (TREE_TYPE (decl), v);
    9203      2221376 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    9204      2221376 :   DECL_INITIAL (decl) = init;
    9205      2221376 :   DECL_INITIALIZED_P (decl) = 1;
    9206              :   /* Mark the decl as constexpr so that we can access its content
    9207              :      at compile time.  */
    9208      2221376 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    9209      2221376 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    9210      2221376 :   determine_visibility (decl);
    9211      2221376 :   layout_var_decl (decl);
    9212      2221376 :   maybe_commonize_var (decl);
    9213      2221376 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    9214      2221376 : }
    9215              : 
    9216              : /* INIT is the initializer for a variable, as represented by the
    9217              :    parser.  Returns true iff INIT is value-dependent.  */
    9218              : 
    9219              : static bool
    9220     10109390 : value_dependent_init_p (tree init)
    9221              : {
    9222     10109390 :   if (TREE_CODE (init) == TREE_LIST)
    9223              :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    9224        21587 :     return any_value_dependent_elements_p (init);
    9225     10087803 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    9226              :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    9227              :     {
    9228        73499 :       if (dependent_type_p (TREE_TYPE (init)))
    9229              :         return true;
    9230              : 
    9231        73493 :       vec<constructor_elt, va_gc> *elts;
    9232        73493 :       size_t nelts;
    9233        73493 :       size_t i;
    9234              : 
    9235        73493 :       elts = CONSTRUCTOR_ELTS (init);
    9236        73493 :       nelts = vec_safe_length (elts);
    9237       650299 :       for (i = 0; i < nelts; ++i)
    9238       606087 :         if (value_dependent_init_p ((*elts)[i].value))
    9239              :           return true;
    9240              :     }
    9241              :   else
    9242              :     /* It must be a simple expression, e.g., int i = 3;  */
    9243     10014304 :     return value_dependent_expression_p (init);
    9244              : 
    9245              :   return false;
    9246              : }
    9247              : 
    9248              : /* A helper function to be called via walk_tree.  If any label exists
    9249              :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    9250              : 
    9251              : static tree
    9252          337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    9253              : {
    9254          337 :   if (TYPE_P (*tp))
    9255            0 :     *walk_subtrees = 0;
    9256          337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    9257            6 :     cfun->has_forced_label_in_static = 1;
    9258          337 :   return NULL_TREE;
    9259              : }
    9260              : 
    9261              : /* Return true if DECL has either a trivial destructor, or for C++20
    9262              :    is constexpr and has a constexpr destructor.  */
    9263              : 
    9264              : static bool
    9265     63563595 : decl_maybe_constant_destruction (tree decl, tree type)
    9266              : {
    9267     63563595 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9268     63563595 :           || (cxx_dialect >= cxx20
    9269      4178994 :               && VAR_P (decl)
    9270      4178639 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    9271          488 :               && type_has_constexpr_destructor (strip_array_types (type))));
    9272              : }
    9273              : 
    9274              : static tree declare_simd_adjust_this (tree *, int *, void *);
    9275              : 
    9276              : /* Helper function of omp_declare_variant_finalize.  Finalize one
    9277              :    "omp declare variant base" attribute.  Return true if it should be
    9278              :    removed.  */
    9279              : 
    9280              : static bool
    9281         1773 : omp_declare_variant_finalize_one (tree decl, tree attr)
    9282              : {
    9283         1773 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9284              :     {
    9285          164 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9286              :                  DECL_ARGUMENTS (decl), NULL);
    9287          164 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9288              :                  DECL_ARGUMENTS (decl), NULL);
    9289              :     }
    9290              : 
    9291         1773 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    9292         1773 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    9293              :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    9294         1773 :   if (simd)
    9295              :     {
    9296           69 :       TREE_VALUE (simd)
    9297           69 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    9298           69 :                                                  OMP_TS_PROPERTIES (simd));
    9299              :       /* FIXME, adjusting simd args unimplemented.  */
    9300              :     }
    9301              : 
    9302         1773 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    9303         1773 :   location_t varid_loc
    9304         1773 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    9305         1773 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    9306         1773 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    9307         1773 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    9308              : 
    9309         1773 :   location_t save_loc = input_location;
    9310         1773 :   input_location = varid_loc;
    9311              : 
    9312         1773 :   releasing_vec args;
    9313         1773 :   tree parm = DECL_ARGUMENTS (decl);
    9314         1773 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9315          164 :     parm = DECL_CHAIN (parm);
    9316         3239 :   for (; parm; parm = DECL_CHAIN (parm))
    9317         1466 :     vec_safe_push (args, forward_parm (parm));
    9318              : 
    9319         1773 :   unsigned nappend_args = 0;
    9320         1773 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9321         1773 :   if (append_args_list)
    9322              :     {
    9323          354 :       append_args_list = TREE_VALUE (append_args_list);
    9324          354 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    9325          591 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    9326              :                           : NULL_TREE);
    9327          741 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9328          387 :         nappend_args++;
    9329          354 :       if (nappend_args)
    9330              :         {
    9331          237 :           tree type;
    9332          237 :           if ((type = lookup_qualified_name (global_namespace,
    9333              :                                              "omp_interop_t",
    9334              :                                              LOOK_want::NORMAL,
    9335              :                                              /*complain*/false)) == NULL_TREE
    9336          237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    9337              :             {
    9338           24 :               location_t loc = input_location;
    9339           24 :               variant = tree_strip_any_location_wrapper (variant);
    9340           24 :               if (!identifier_p (variant))
    9341              :                 {
    9342           21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    9343           21 :                     variant = OVL_FIRST (variant);
    9344           21 :                   loc = EXPR_LOC_OR_LOC (variant,
    9345              :                                          DECL_SOURCE_LOCATION (variant));
    9346              :                 }
    9347           24 :               auto_diagnostic_group d;
    9348           24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    9349           24 :                         args->length () + 1, variant);
    9350           24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9351              :                       "%<append_args%> specified here");
    9352           24 :               return true;
    9353           24 :             }
    9354          564 :           for (unsigned i = 0; i < nappend_args; i++)
    9355          351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    9356              :         }
    9357              :     }
    9358              : 
    9359         1749 :   bool koenig_p = false;
    9360         1749 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    9361              :     {
    9362         1679 :       if (identifier_p (variant)
    9363              :           /* In C++20, we may need to perform ADL for a template
    9364              :              name.  */
    9365         1655 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    9366           18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    9367              :         {
    9368           24 :           if (!args->is_empty ())
    9369              :             {
    9370           24 :               koenig_p = true;
    9371           24 :               if (!any_type_dependent_arguments_p (args))
    9372           21 :                 variant = perform_koenig_lookup (variant, args,
    9373              :                                                  tf_warning_or_error);
    9374              :             }
    9375              :           else
    9376            0 :             variant = unqualified_fn_lookup_error (variant);
    9377              :         }
    9378         1655 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    9379              :         {
    9380          896 :           tree fn = get_first_fn (variant);
    9381          896 :           fn = STRIP_TEMPLATE (fn);
    9382          896 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    9383          896 :                  || DECL_FUNCTION_MEMBER_P (fn)
    9384          783 :                  || DECL_LOCAL_DECL_P (fn)))
    9385              :             {
    9386          783 :               koenig_p = true;
    9387          783 :               if (!any_type_dependent_arguments_p (args))
    9388          729 :                 variant = perform_koenig_lookup (variant, args,
    9389              :                                                  tf_warning_or_error);
    9390              :             }
    9391              :         }
    9392              :     }
    9393              : 
    9394         1749 :   if (idk == CP_ID_KIND_QUALIFIED)
    9395            6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    9396              :                                 koenig_p, tf_warning_or_error);
    9397         1743 :   else if (idk == CP_ID_KIND_NONE
    9398           64 :            && TREE_CODE (variant) == FUNCTION_DECL
    9399           64 :            && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
    9400         1791 :            && CLASS_TYPE_P (DECL_CONTEXT (decl)))
    9401              :     {
    9402           48 :       tree saved_ccp = current_class_ptr;
    9403           48 :       tree saved_ccr = current_class_ref;
    9404           48 :       current_class_ptr = NULL_TREE;
    9405           48 :       current_class_ref = NULL_TREE;
    9406           48 :       inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
    9407           48 :       variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9408              :                                   koenig_p, tf_warning_or_error);
    9409           48 :       current_class_ptr = saved_ccp;
    9410           48 :       current_class_ref = saved_ccr;
    9411              :     }
    9412              :   else
    9413         1695 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9414              :                                 koenig_p, tf_warning_or_error);
    9415         1749 :   if (variant == error_mark_node && !processing_template_decl)
    9416              :     return true;
    9417              : 
    9418         1635 :   if (TREE_CODE (variant) == TARGET_EXPR)
    9419            9 :     variant = TARGET_EXPR_INITIAL (variant);
    9420              : 
    9421         3261 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    9422         1635 :   input_location = save_loc;
    9423              : 
    9424         1635 :   if (variant == decl)
    9425              :     {
    9426            0 :       error_at (varid_loc, "variant %qD is the same as base function",
    9427              :                 variant);
    9428            0 :       return true;
    9429              :     }
    9430              : 
    9431         1635 :   if (variant)
    9432              :     {
    9433         1548 :       bool fail;
    9434         1548 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    9435         1548 :       if (!nappend_args)
    9436         1389 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9437              :                            COMPARE_STRICT);
    9438              :       else
    9439              :         {
    9440          159 :           unsigned nbase_args = 0;
    9441          159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    9442          756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    9443          240 :             nbase_args++;
    9444          159 :           tree vargs, varg;
    9445          159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    9446          399 :           for (unsigned i = 0; i < nbase_args && varg;
    9447          240 :                i++, varg = TREE_CHAIN (varg))
    9448          240 :             vargs = varg;
    9449          417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    9450          258 :             varg = TREE_CHAIN (varg);
    9451          159 :           tree saved_vargs;
    9452          159 :           int saved_no_named_args_stdarg = 0;
    9453          159 :           if (nbase_args)
    9454              :             {
    9455          111 :               saved_vargs = TREE_CHAIN (vargs);
    9456          111 :               TREE_CHAIN (vargs) = varg;
    9457              :             }
    9458              :           else
    9459              :             {
    9460           48 :               saved_vargs = vargs;
    9461           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    9462           48 :               saved_no_named_args_stdarg
    9463           48 :                 = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
    9464           48 :               if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
    9465           48 :                   && varg == NULL_TREE)
    9466            2 :                 TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
    9467              :             }
    9468              :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    9469          159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9470              :                              COMPARE_STRUCTURAL);
    9471          159 :           if (nbase_args)
    9472          111 :             TREE_CHAIN (vargs) = saved_vargs;
    9473              :           else
    9474              :             {
    9475           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    9476           48 :               TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
    9477           96 :                 = saved_no_named_args_stdarg;
    9478              :             }
    9479          159 :           varg = saved_vargs;
    9480          159 :           if (!fail && !processing_template_decl)
    9481          402 :             for (unsigned i = 0; i < nappend_args;
    9482          246 :                  i++, varg = TREE_CHAIN (varg))
    9483          507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    9484              :                 {
    9485            9 :                   auto_diagnostic_group d;
    9486            9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    9487              :                             "argument %d of %qD must be of %<omp_interop_t%>",
    9488            9 :                             nbase_args + i + 1, variant);
    9489            9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9490              :                           "%<append_args%> specified here");
    9491            9 :                   break;
    9492            9 :                 }
    9493              :         }
    9494         1548 :       if (fail)
    9495              :         {
    9496           69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    9497              :                                "types", variant, decl);
    9498           69 :           return true;
    9499              :         }
    9500         1479 :       if (fndecl_built_in_p (variant)
    9501         1479 :           && (startswith (varname, "__builtin_")
    9502            0 :               || startswith (varname, "__sync_")
    9503            0 :               || startswith (varname, "__atomic_")))
    9504              :         {
    9505            6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    9506            6 :           return true;
    9507              :         }
    9508              :       else
    9509              :         {
    9510         1473 :           tree construct
    9511         1473 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    9512         1473 :           omp_mark_declare_variant (match_loc, variant, construct);
    9513         1473 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    9514              :             return true;
    9515         1057 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    9516              : 
    9517              :           // Prepend adjust_args list to variant attributes
    9518         1057 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9519         1057 :           if (adjust_args_list != NULL_TREE)
    9520              :             {
    9521          507 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    9522          285 :                   && TREE_VALUE (adjust_args_list))
    9523              :                 {
    9524              :                   /* Shift arg position for the added 'this' pointer.  */
    9525              :                   /* Handle need_device_ptr  */
    9526           21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    9527           51 :                        t; t = TREE_CHAIN (t))
    9528           30 :                     TREE_VALUE (t)
    9529           30 :                       = build_int_cst (TREE_TYPE (t),
    9530           30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    9531              :                 }
    9532          264 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    9533              :                 {
    9534              :                   /* Shift likewise the number of args after which the
    9535              :                      interop object should be added.  */
    9536            6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    9537            6 :                   TREE_PURPOSE (nargs)
    9538            6 :                     = build_int_cst (TREE_TYPE (nargs),
    9539            6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    9540              :                 }
    9541          528 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9542          264 :                 TREE_VALUE (t)
    9543          264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    9544          528 :               DECL_ATTRIBUTES (variant) = tree_cons (
    9545              :                 get_identifier ("omp declare variant variant args"),
    9546          528 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    9547              :             }
    9548              :         }
    9549              :     }
    9550           87 :   else if (!processing_template_decl)
    9551              :     {
    9552            0 :       error_at (varid_loc, "could not find variant declaration");
    9553            0 :       return true;
    9554              :     }
    9555              : 
    9556              :   return false;
    9557         1773 : }
    9558              : 
    9559              : /* Helper function, finish up "omp declare variant base" attribute
    9560              :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    9561              :    attribute.  */
    9562              : 
    9563              : void
    9564         1560 : omp_declare_variant_finalize (tree decl, tree attr)
    9565              : {
    9566         1560 :   size_t attr_len = strlen ("omp declare variant base");
    9567         1560 :   tree *list = &DECL_ATTRIBUTES (decl);
    9568         1560 :   bool remove_all = false;
    9569         1560 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    9570         1560 :   if (TREE_CHAIN (TREE_VALUE (attr))
    9571         1560 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    9572         3120 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    9573         1560 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    9574         3120 :   if (DECL_CONSTRUCTOR_P (decl))
    9575              :     {
    9576           27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    9577           27 :       remove_all = true;
    9578              :     }
    9579         1533 :   else if (DECL_DESTRUCTOR_P (decl))
    9580              :     {
    9581            9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    9582            9 :       remove_all = true;
    9583              :     }
    9584         1524 :   else if (DECL_DEFAULTED_FN (decl))
    9585              :     {
    9586            2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    9587            2 :       remove_all = true;
    9588              :     }
    9589         1522 :   else if (DECL_DELETED_FN (decl))
    9590              :     {
    9591            2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    9592            2 :       remove_all = true;
    9593              :     }
    9594         1520 :   else if (DECL_VIRTUAL_P (decl))
    9595              :     {
    9596            0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    9597            0 :       remove_all = true;
    9598              :     }
    9599              :   /* This loop is like private_lookup_attribute, except that it works
    9600              :      with tree * rather than tree, as we might want to remove the
    9601              :      attributes that are diagnosed as erroneous.  */
    9602         3385 :   while (*list)
    9603              :     {
    9604         1825 :       tree attr = get_attribute_name (*list);
    9605         1825 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    9606         4794 :       if (cmp_attribs ("omp declare variant base", attr_len,
    9607         1825 :                        IDENTIFIER_POINTER (attr), ident_len))
    9608              :         {
    9609         1813 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    9610              :             {
    9611          669 :               *list = TREE_CHAIN (*list);
    9612          669 :               continue;
    9613              :             }
    9614              :         }
    9615         1156 :       list = &TREE_CHAIN (*list);
    9616              :     }
    9617         1560 : }
    9618              : 
    9619              : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
    9620              :    have a potentially throwing exception specification.  */
    9621              : 
    9622              : void
    9623    208804328 : maybe_diagnose_deallocation_noexcept_false (tree decl)
    9624              : {
    9625    208804328 :   if (cxx_dialect >= cxx29
    9626     16964603 :       && DECL_NAME (decl)
    9627     16964603 :       && IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
    9628    208845039 :       && !IDENTIFIER_NEW_OP_P (DECL_NAME (decl)))
    9629              :     {
    9630        22346 :       tree spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
    9631        22346 :       if (spec && spec == noexcept_false_spec)
    9632           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    9633              :                   "deallocation function %qD declared possibly throwing",
    9634              :                   decl);
    9635              :     }
    9636    208804328 : }
    9637              : 
    9638              : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    9639              : 
    9640              : /* Finish processing of a declaration;
    9641              :    install its line number and initial value.
    9642              :    If the length of an array type is not known before,
    9643              :    it must be determined now, from the initial value, or it is an error.
    9644              : 
    9645              :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    9646              :    true, then INIT is an integral constant expression.
    9647              : 
    9648              :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    9649              :    if the (init) syntax was used.
    9650              : 
    9651              :    DECOMP is first identifier's DECL and identifier count in a structured
    9652              :    bindings, nullptr if not a structured binding.  */
    9653              : 
    9654              : void
    9655    336126464 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    9656              :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    9657              : {
    9658    336126464 :   vec<tree, va_gc> *cleanups = NULL;
    9659    336126464 :   const char *asmspec = NULL;
    9660    336126464 :   int was_readonly = 0;
    9661    336126464 :   bool var_definition_p = false;
    9662    336126464 :   tree auto_node;
    9663    336126464 :   auto_vec<tree> extra_cleanups;
    9664    336126464 :   tree aggregates1 = NULL_TREE;
    9665    336126464 :   struct decomp_cleanup {
    9666              :     tree decl;
    9667              :     cp_decomp *&decomp;
    9668    336123765 :     ~decomp_cleanup ()
    9669              :     {
    9670    336123765 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    9671       237146 :         cp_finish_decomp (decl, decomp);
    9672    336123765 :     }
    9673    336126464 :   } decomp_cl = { decl, decomp };
    9674              : 
    9675    336126464 :   if (decl == error_mark_node)
    9676              :     return;
    9677    336126424 :   else if (! decl)
    9678              :     {
    9679            0 :       if (init)
    9680            0 :         error ("assignment (not initialization) in declaration");
    9681              :       return;
    9682              :     }
    9683              : 
    9684    336126424 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    9685              :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    9686    336126424 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    9687              : 
    9688    336126424 :   tree type = TREE_TYPE (decl);
    9689    336126424 :   if (type == error_mark_node)
    9690              :     return;
    9691              : 
    9692    336125781 :   if (VAR_P (decl) && is_copy_initialization (init))
    9693    100270369 :     flags |= LOOKUP_ONLYCONVERTING;
    9694              : 
    9695              :   /* Warn about register storage specifiers except when in GNU global
    9696              :      or local register variable extension.  */
    9697    336125781 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    9698              :     {
    9699         1931 :       if (cxx_dialect >= cxx17)
    9700         1282 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9701              :                  "ISO C++17 does not allow %<register%> storage "
    9702              :                  "class specifier");
    9703              :       else
    9704          649 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9705              :                     "%<register%> storage class specifier used");
    9706              :     }
    9707              : 
    9708              :   /* If a name was specified, get the string.  */
    9709    336125781 :   if (at_namespace_scope_p ())
    9710     72516512 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    9711    336125781 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    9712      1018644 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    9713              : 
    9714    336125781 :   bool in_class_decl
    9715    336125781 :     = (current_class_type
    9716    212156501 :        && CP_DECL_CONTEXT (decl) == current_class_type
    9717    140521055 :        && TYPE_BEING_DEFINED (current_class_type)
    9718    474587926 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    9719              : 
    9720    133253748 :   if (in_class_decl
    9721    133253748 :       && (DECL_INITIAL (decl) || init))
    9722     97840558 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    9723              : 
    9724    336125781 :   if (VAR_P (decl)
    9725    336125781 :       && (auto_node = type_uses_auto (type)))
    9726              :     {
    9727     14038449 :       tree d_init;
    9728     14038449 :       if (init == NULL_TREE)
    9729              :         {
    9730         4610 :           if (DECL_LANG_SPECIFIC (decl)
    9731         4525 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    9732         9132 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    9733              :             {
    9734              :               /* init is null because we're deferring instantiating the
    9735              :                  initializer until we need it.  Well, we need it now.  */
    9736         4516 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    9737         4516 :               return;
    9738              :             }
    9739              : 
    9740           94 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9741              :             /* Class deduction with no initializer is OK.  */;
    9742              :           else
    9743              :             {
    9744              :               /* Ordinary auto deduction without an initializer, a situation
    9745              :                  which grokdeclarator already detects and rejects for the most
    9746              :                  part.  But we can still get here if we're instantiating a
    9747              :                  variable template before we've fully parsed (and attached) its
    9748              :                  initializer, e.g. template<class> auto x = x<int>;  */
    9749            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    9750              :                         "declaration of %q#D has no initializer", decl);
    9751            3 :               TREE_TYPE (decl) = error_mark_node;
    9752            3 :               return;
    9753              :             }
    9754              :         }
    9755     14033930 :       d_init = init;
    9756     14033930 :       if (d_init)
    9757              :         {
    9758     14033839 :           if (TREE_CODE (d_init) == TREE_LIST
    9759     14108102 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9760        47613 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    9761              :                                                       tf_warning_or_error);
    9762     14033839 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    9763              :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    9764              :              on deprecated-14.C.  */
    9765     14033839 :           mark_single_function (d_init, tf_none);
    9766              :         }
    9767     14033930 :       enum auto_deduction_context adc = adc_variable_type;
    9768     14033930 :       if (DECL_DECOMPOSITION_P (decl))
    9769              :         adc = adc_decomp_type;
    9770     14033930 :       tree outer_targs = NULL_TREE;
    9771     14033930 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    9772          325 :           && DECL_LANG_SPECIFIC (decl)
    9773          126 :           && DECL_TEMPLATE_INFO (decl)
    9774     14033987 :           && !DECL_FUNCTION_SCOPE_P (decl))
    9775              :         /* The outer template arguments might be needed for satisfaction.
    9776              :            (For function scope variables, do_auto_deduction will obtain the
    9777              :            outer template arguments from current_function_decl.)  */
    9778           57 :         outer_targs = DECL_TI_ARGS (decl);
    9779     14033930 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    9780              :                                                    tf_warning_or_error, adc,
    9781              :                                                    outer_targs, flags);
    9782     14033930 :       if (type == error_mark_node)
    9783              :         return;
    9784     14032721 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    9785              :         {
    9786            3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    9787              :                  "did you forget the %<()%>?", decl);
    9788            3 :           TREE_TYPE (decl) = error_mark_node;
    9789            3 :           return;
    9790              :         }
    9791              :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    9792     14032718 :       if (!processing_template_decl
    9793      3156835 :           && !type_uses_auto (type)
    9794     17189546 :           && !COMPLETE_TYPE_P (complete_type (type)))
    9795              :         {
    9796           18 :           auto_diagnostic_group d;
    9797           18 :           error_at (location_of (decl),
    9798              :                     "deduced type %qT for %qD is incomplete", type, decl);
    9799           18 :           cxx_incomplete_type_inform (type);
    9800           18 :           TREE_TYPE (decl) = error_mark_node;
    9801           18 :           return;
    9802           18 :         }
    9803              : 
    9804              :       /* Now that we have a type, try these again.  */
    9805     14032700 :       layout_decl (decl, 0);
    9806     14032700 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    9807              : 
    9808              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    9809     14032700 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    9810              :         {
    9811        40423 :           tree tmpl = template_for_substitution (decl);
    9812        40423 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    9813        33893 :             TREE_TYPE (tmpl) = type;
    9814              :         }
    9815              :     }
    9816              : 
    9817    336120032 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    9818              :     {
    9819           65 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    9820           65 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    9821              :         {
    9822            6 :           init = NULL_TREE;
    9823            6 :           DECL_EXTERNAL (decl) = 1;
    9824              :         }
    9825              :     }
    9826              : 
    9827    336120032 :   if (VAR_P (decl)
    9828    126827746 :       && DECL_CLASS_SCOPE_P (decl)
    9829     20407150 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    9830              :                               TCTX_STATIC_STORAGE, type)
    9831    356527182 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    9832     19043286 :     check_static_variable_definition (decl, type);
    9833              : 
    9834    336120032 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    9835              :     {
    9836     37778223 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    9837     37778223 :                                    ? TCTX_THREAD_STORAGE
    9838              :                                    : TCTX_STATIC_STORAGE);
    9839     37778223 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    9840              :     }
    9841              : 
    9842    336120032 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    9843              :     {
    9844       586988 :       tree clone;
    9845       586988 :       if (init == ridpointers[(int)RID_DELETE]
    9846       586988 :           || (TREE_CODE (init) == STRING_CST
    9847           36 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    9848              :         {
    9849              :           /* FIXME check this is 1st decl.  */
    9850       564352 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    9851              :             {
    9852              :               /* [basic.start.main]/3: A program that defines main as deleted
    9853              :                  is ill-formed.  */
    9854            6 :               error ("%<::main%> cannot be deleted");
    9855            6 :               DECL_INITIAL (decl) = error_mark_node;
    9856              :             }
    9857              :           else
    9858              :             {
    9859       564346 :               DECL_DELETED_FN (decl) = 1;
    9860       564346 :               DECL_DECLARED_INLINE_P (decl) = 1;
    9861       564346 :               DECL_INITIAL (decl)
    9862       564346 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    9863       564364 :               FOR_EACH_CLONE (clone, decl)
    9864              :                 {
    9865           18 :                   DECL_DELETED_FN (clone) = 1;
    9866           18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    9867           18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    9868              :                 }
    9869              :             }
    9870       564352 :           init = NULL_TREE;
    9871              :         }
    9872        22636 :       else if (init == ridpointers[(int)RID_DEFAULT])
    9873              :         {
    9874        22624 :           if (defaultable_fn_check (decl))
    9875        22600 :             DECL_DEFAULTED_FN (decl) = 1;
    9876              :           else
    9877           24 :             DECL_INITIAL (decl) = NULL_TREE;
    9878              :         }
    9879              :     }
    9880              : 
    9881    336120032 :   if (init && VAR_P (decl))
    9882              :     {
    9883    110316784 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    9884              :       /* If DECL is a reference, then we want to know whether init is a
    9885              :          reference constant; init_const_expr_p as passed tells us whether
    9886              :          it's an rvalue constant.  */
    9887    110316784 :       if (TYPE_REF_P (type))
    9888      2382303 :         init_const_expr_p = potential_constant_expression (init);
    9889    110316784 :       if (init_const_expr_p)
    9890              :         {
    9891              :           /* Set these flags now for templates.  We'll update the flags in
    9892              :              store_init_value for instantiations.  */
    9893     97134629 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    9894     97134629 :           if (decl_maybe_constant_var_p (decl)
    9895              :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    9896     97134629 :               && !TYPE_REF_P (type))
    9897     42640023 :             TREE_CONSTANT (decl) = true;
    9898              :         }
    9899              :       /* This is handled mostly by gimplify.cc, but we have to deal with
    9900              :          not warning about int x = x; as it is a GCC extension to turn off
    9901              :          this warning but only if warn_init_self is zero.  */
    9902    110316784 :       if (!DECL_EXTERNAL (decl)
    9903    108669691 :           && !TREE_STATIC (decl)
    9904     73601891 :           && decl == tree_strip_any_location_wrapper (init)
    9905    218986475 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    9906         3760 :         suppress_warning (decl, OPT_Winit_self);
    9907              :     }
    9908    225803248 :   else if (VAR_P (decl)
    9909     16510962 :            && COMPLETE_TYPE_P (type)
    9910     12980079 :            && !TYPE_REF_P (type)
    9911     12979371 :            && !dependent_type_p (type)
    9912    238451398 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    9913              :     /* We have no initializer but there's nothing to initialize anyway.
    9914              :        Treat DECL as constant due to c++/109876.  */
    9915       598712 :     TREE_CONSTANT (decl) = true;
    9916              : 
    9917    336120032 :   if (flag_openmp
    9918       873976 :       && TREE_CODE (decl) == FUNCTION_DECL
    9919              :       /* #pragma omp declare variant on methods handled in finish_struct
    9920              :          instead.  */
    9921    336497999 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
    9922       144387 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    9923       234043 :     if (tree attr = lookup_attribute ("omp declare variant base",
    9924       234043 :                                       DECL_ATTRIBUTES (decl)))
    9925          970 :       omp_declare_variant_finalize (decl, attr);
    9926              : 
    9927    336120032 :   if (processing_template_decl)
    9928              :     {
    9929    193610197 :       bool type_dependent_p;
    9930              : 
    9931              :       /* Add this declaration to the statement-tree.  */
    9932    193610197 :       if (at_function_scope_p ())
    9933     69728272 :         add_decl_expr (decl);
    9934              : 
    9935    193610197 :       type_dependent_p = dependent_type_p (type);
    9936              : 
    9937    193610197 :       if (check_for_bare_parameter_packs (init))
    9938              :         {
    9939            3 :           init = NULL_TREE;
    9940            3 :           DECL_INITIAL (decl) = NULL_TREE;
    9941              :         }
    9942              : 
    9943              :       /* Generally, initializers in templates are expanded when the
    9944              :          template is instantiated.  But, if DECL is a variable constant
    9945              :          then it can be used in future constant expressions, so its value
    9946              :          must be available. */
    9947              : 
    9948    193610197 :       bool dep_init = false;
    9949              : 
    9950    193610197 :       if (!VAR_P (decl) || type_dependent_p)
    9951              :         /* We can't do anything if the decl has dependent type.  */;
    9952     24182043 :       else if (init
    9953     22479066 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    9954     18326527 :                && !TYPE_REF_P (type)
    9955     18292744 :                && decl_maybe_constant_var_p (decl)
    9956     33685346 :                && !(dep_init = value_dependent_init_p (init)))
    9957              :         {
    9958              :           /* This variable seems to be a non-dependent constant, so process
    9959              :              its initializer.  If check_initializer returns non-null the
    9960              :              initialization wasn't constant after all.  */
    9961      2459057 :           tree init_code;
    9962      2459057 :           cleanups = make_tree_vector ();
    9963      2459057 :           init_code = check_initializer (decl, init, flags, &cleanups);
    9964      2459057 :           if (init_code == NULL_TREE)
    9965      2459057 :             init = NULL_TREE;
    9966      2459057 :           release_tree_vector (cleanups);
    9967              :         }
    9968              :       else
    9969              :         {
    9970     21722986 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    9971              :           /* Try to deduce array size.  */
    9972     21722986 :           maybe_deduce_size_from_array_init (decl, init);
    9973              :           /* And complain about multiple initializers.  */
    9974     20020009 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    9975     21829247 :               && !MAYBE_CLASS_TYPE_P (type))
    9976            7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    9977              :                                                     tf_warning_or_error);
    9978              :         }
    9979              : 
    9980    193610197 :       if (init)
    9981     58028910 :         DECL_INITIAL (decl) = init;
    9982              : 
    9983    193610197 :       if (dep_init)
    9984              :         {
    9985      7044246 :           retrofit_lang_decl (decl);
    9986      7044246 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    9987              :         }
    9988              : 
    9989    193610197 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    9990              :         {
    9991            9 :           if (TREE_ADDRESSABLE (decl))
    9992            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    9993              :                       "address of explicit register variable %qD requested",
    9994              :                       decl);
    9995              :           else
    9996              :             {
    9997            6 :               set_user_assembler_name (decl, asmspec);
    9998            6 :               DECL_HARD_REGISTER (decl) = 1;
    9999              :             }
   10000              :         }
   10001              :       return;
   10002              :     }
   10003              : 
   10004              :   /* Just store non-static data member initializers for later.  */
   10005    142509835 :   if (init && TREE_CODE (decl) == FIELD_DECL)
   10006       613070 :     DECL_INITIAL (decl) = init;
   10007              : 
   10008              :   /* Take care of TYPE_DECLs up front.  */
   10009    142509835 :   if (TREE_CODE (decl) == TYPE_DECL)
   10010              :     {
   10011     11084660 :       if (type != error_mark_node
   10012     11084660 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
   10013              :         {
   10014      5309132 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
   10015            0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
   10016      5309132 :           set_identifier_type_value (DECL_NAME (decl), decl);
   10017              :         }
   10018              : 
   10019              :       /* If we have installed this as the canonical typedef for this
   10020              :          type, and that type has not been defined yet, delay emitting
   10021              :          the debug information for it, as we will emit it later.  */
   10022     11084660 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
   10023     11084660 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10024       610524 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
   10025              : 
   10026     11084660 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
   10027              :                                 at_eof);
   10028     11084660 :       return;
   10029              :     }
   10030              : 
   10031              :   /* A reference will be modified here, as it is initialized.  */
   10032    131425175 :   if (! DECL_EXTERNAL (decl)
   10033     64436041 :       && TREE_READONLY (decl)
   10034    169884388 :       && TYPE_REF_P (type))
   10035              :     {
   10036       253765 :       was_readonly = 1;
   10037       253765 :       TREE_READONLY (decl) = 0;
   10038              :     }
   10039              : 
   10040              :   /* This needs to happen before extend_ref_init_temps.  */
   10041    131425175 :   if (VAR_OR_FUNCTION_DECL_P (decl))
   10042              :     {
   10043    121951255 :       if (VAR_P (decl))
   10044     62908909 :         maybe_commonize_var (decl);
   10045    121951255 :       determine_visibility (decl);
   10046              :     }
   10047              : 
   10048    131425175 :   if (VAR_P (decl))
   10049              :     {
   10050     62908909 :       duration_kind dk = decl_storage_duration (decl);
   10051              :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
   10052              :          only to a declaration of a variable with static or thread storage
   10053              :          duration."  */
   10054     62908909 :       if (DECL_DECLARED_CONSTINIT_P (decl)
   10055     62908909 :           && !(dk == dk_thread || dk == dk_static))
   10056              :         {
   10057           24 :           error_at (DECL_SOURCE_LOCATION (decl),
   10058              :                     "%<constinit%> can only be applied to a variable with "
   10059              :                     "static or thread storage duration");
   10060           24 :           return;
   10061              :         }
   10062              : 
   10063     62908885 :       if (decomp)
   10064              :         {
   10065        68911 :           if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
   10066           40 :             pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
   10067              :                      "%<constinit%> can be applied to structured binding "
   10068              :                      "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
   10069        68911 :           cp_maybe_mangle_decomp (decl, decomp);
   10070        68911 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
   10071              :             {
   10072          628 :               if (CP_DECL_THREAD_LOCAL_P (decl))
   10073           37 :                 aggregates1 = tls_aggregates;
   10074              :               else
   10075          591 :                 aggregates1 = static_aggregates;
   10076              :             }
   10077              :         }
   10078              : 
   10079              :       /* If this is a local variable that will need a mangled name,
   10080              :          register it now.  We must do this before processing the
   10081              :          initializer for the variable, since the initialization might
   10082              :          require a guard variable, and since the mangled name of the
   10083              :          guard variable will depend on the mangled name of this
   10084              :          variable.  */
   10085     62908885 :       if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl))
   10086              :         {
   10087              :           /* The variable holding an anonymous union will have had its
   10088              :              discriminator set in finish_anon_union, after which it's
   10089              :              NAME will have been cleared.  */
   10090       142321 :           if (DECL_NAME (decl))
   10091       142002 :             determine_local_discriminator (decl);
   10092              :           /* Normally has_forced_label_in_static is set during GIMPLE
   10093              :              lowering, but [cd]tors are never actually compiled directly.
   10094              :              We need to set this early so we can deal with the label
   10095              :              address extension.  */
   10096       142321 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
   10097       142280 :                || DECL_DESTRUCTOR_P (current_function_decl))
   10098       142337 :               && init)
   10099              :             {
   10100           29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
   10101           29 :               add_local_decl (cfun, decl);
   10102              :             }
   10103              :           /* And make sure it's in the symbol table for
   10104              :              c_parse_final_cleanups to find.  */
   10105       142321 :           gcc_checking_assert (!consteval_only_p (decl));
   10106       142321 :           varpool_node::get_create (decl);
   10107              :         }
   10108              : 
   10109     62908885 :       if (flag_openmp
   10110       200242 :           && VAR_P (decl)
   10111       200242 :           && DECL_LANG_SPECIFIC (decl)
   10112       117043 :           && DECL_OMP_DECLARE_MAPPER_P (decl)
   10113     62908898 :           && init)
   10114              :         {
   10115           12 :           gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
   10116           12 :           DECL_INITIAL (decl) = init;
   10117              :         }
   10118              :       /* Convert the initializer to the type of DECL, if we have not
   10119              :          already initialized DECL.  */
   10120     62908873 :       else if (!DECL_INITIALIZED_P (decl)
   10121              :                /* If !DECL_EXTERNAL then DECL is being defined.  In the
   10122              :                   case of a static data member initialized inside the
   10123              :                   class-specifier, there can be an initializer even if DECL
   10124              :                   is *not* defined.  */
   10125     62908873 :                && (!DECL_EXTERNAL (decl) || init))
   10126              :         {
   10127     55985779 :           cleanups = make_tree_vector ();
   10128     55985779 :           init = check_initializer (decl, init, flags, &cleanups);
   10129              : 
   10130              :           /* Handle:
   10131              : 
   10132              :              [dcl.init]
   10133              : 
   10134              :              The memory occupied by any object of static storage
   10135              :              duration is zero-initialized at program startup before
   10136              :              any other initialization takes place.
   10137              : 
   10138              :              We cannot create an appropriate initializer until after
   10139              :              the type of DECL is finalized.  If DECL_INITIAL is set,
   10140              :              then the DECL is statically initialized, and any
   10141              :              necessary zero-initialization has already been performed.  */
   10142     55983082 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
   10143       523700 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
   10144              :                                                    /*nelts=*/NULL_TREE,
   10145              :                                                    /*static_storage_p=*/true);
   10146              :           /* Remember that the initialization for this variable has
   10147              :              taken place.  */
   10148     55983082 :           DECL_INITIALIZED_P (decl) = 1;
   10149              :           /* This declaration is the definition of this variable,
   10150              :              unless we are initializing a static data member within
   10151              :              the class specifier.  */
   10152     55983082 :           if (!DECL_EXTERNAL (decl))
   10153     62906188 :             var_definition_p = true;
   10154              :         }
   10155              :       /* If the variable has an array type, lay out the type, even if
   10156              :          there is no initializer.  It is valid to index through the
   10157              :          array, and we must get TYPE_ALIGN set correctly on the array
   10158              :          type.  */
   10159      6923094 :       else if (TREE_CODE (type) == ARRAY_TYPE)
   10160       216312 :         layout_type (type);
   10161              : 
   10162     62906188 :       if (TREE_STATIC (decl)
   10163     37216793 :           && !at_function_scope_p ()
   10164     99980660 :           && current_function_decl == NULL)
   10165              :         /* So decl is a global variable or a static member of a
   10166              :            non local class. Record the types it uses
   10167              :            so that we can decide later to emit debug info for them.  */
   10168     37074460 :         record_types_used_by_current_var_decl (decl);
   10169              :     }
   10170              : 
   10171              :   /* Add this declaration to the statement-tree.  This needs to happen
   10172              :      after the call to check_initializer so that the DECL_EXPR for a
   10173              :      reference temp is added before the DECL_EXPR for the reference itself.  */
   10174    131422454 :   if (DECL_FUNCTION_SCOPE_P (decl))
   10175              :     {
   10176              :       /* If we're building a variable sized type, and we might be
   10177              :          reachable other than via the top of the current binding
   10178              :          level, then create a new BIND_EXPR so that we deallocate
   10179              :          the object at the right time.  */
   10180     25272855 :       if (VAR_P (decl)
   10181     25272855 :           && DECL_SIZE (decl)
   10182     25210936 :           && !TREE_CONSTANT (DECL_SIZE (decl))
   10183     25273899 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
   10184              :         {
   10185            3 :           tree bind;
   10186            3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
   10187            3 :           TREE_SIDE_EFFECTS (bind) = 1;
   10188            3 :           add_stmt (bind);
   10189            3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
   10190              :         }
   10191     25272855 :       add_decl_expr (decl);
   10192              :     }
   10193              : 
   10194    131422454 :   tree decomp_init = NULL_TREE;
   10195              :   /* Let the middle end know about variables and functions -- but not
   10196              :      static data members in uninstantiated class templates.  */
   10197    131422454 :   if (VAR_OR_FUNCTION_DECL_P (decl))
   10198              :     {
   10199    121948534 :       if (VAR_P (decl))
   10200              :         {
   10201     62906188 :           layout_var_decl (decl);
   10202     62906188 :           if (!flag_weak)
   10203              :             /* Check again now that we have an initializer.  */
   10204           57 :             maybe_commonize_var (decl);
   10205              :           /* A class-scope constexpr variable with an out-of-class declaration.
   10206              :              C++17 makes them implicitly inline, but still force it out.  */
   10207     84770069 :           if (DECL_INLINE_VAR_P (decl)
   10208     29492645 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
   10209     13228997 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
   10210     47333248 :               && !in_class_decl)
   10211          108 :             mark_needed (decl);
   10212              :         }
   10213              : 
   10214    121948534 :       if (var_definition_p
   10215              :           /* With -fmerge-all-constants, gimplify_init_constructor
   10216              :              might add TREE_STATIC to aggregate variables.  */
   10217     54796806 :           && (TREE_STATIC (decl)
   10218     25130662 :               || (flag_merge_constants >= 2
   10219           38 :                   && AGGREGATE_TYPE_P (type))))
   10220              :         {
   10221              :           /* If a TREE_READONLY variable needs initialization
   10222              :              at runtime, it is no longer readonly and we need to
   10223              :              avoid MEM_READONLY_P being set on RTL created for it.  */
   10224     29666147 :           if (init)
   10225              :             {
   10226        14327 :               if (TREE_READONLY (decl))
   10227          346 :                 TREE_READONLY (decl) = 0;
   10228              :               was_readonly = 0;
   10229              :             }
   10230     29651820 :           else if (was_readonly)
   10231         2626 :             TREE_READONLY (decl) = 1;
   10232              : 
   10233              :           /* Likewise if it needs destruction.  */
   10234     29666147 :           if (!decl_maybe_constant_destruction (decl, type))
   10235         3577 :             TREE_READONLY (decl) = 0;
   10236              :         }
   10237     92282387 :       else if (VAR_P (decl)
   10238     33240041 :                && CP_DECL_THREAD_LOCAL_P (decl)
   10239        19297 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
   10240        19297 :                && (was_readonly || TREE_READONLY (decl))
   10241     92282402 :                && var_needs_tls_wrapper (decl))
   10242              :         {
   10243              :           /* TLS variables need dynamic initialization by the TLS wrapper
   10244              :              function, we don't want to hoist accesses to it before the
   10245              :              wrapper.  */
   10246            6 :           was_readonly = 0;
   10247            6 :           TREE_READONLY (decl) = 0;
   10248              :         }
   10249              : 
   10250    121948534 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
   10251              : 
   10252              :       /* Check for abstractness of the type.  */
   10253    121948532 :       if (var_definition_p)
   10254     54796804 :         abstract_virtuals_error (decl, type);
   10255              : 
   10256    121948532 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
   10257        33260 :         decomp = NULL;
   10258              : 
   10259    121948532 :       if (TREE_TYPE (decl) == error_mark_node)
   10260              :         /* No initialization required.  */
   10261              :         ;
   10262    121948439 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
   10263              :         {
   10264     59042346 :           if (init)
   10265              :             {
   10266          602 :               if (init == ridpointers[(int)RID_DEFAULT])
   10267              :                 {
   10268              :                   /* An out-of-class default definition is defined at
   10269              :                      the point where it is explicitly defaulted.  */
   10270          590 :                   if (DECL_DELETED_FN (decl))
   10271           17 :                     maybe_explain_implicit_delete (decl);
   10272          573 :                   else if (DECL_INITIAL (decl) == error_mark_node)
   10273          549 :                     synthesize_method (decl);
   10274              :                 }
   10275              :               else
   10276           24 :                 error_at (cp_expr_loc_or_loc (init,
   10277           12 :                                               DECL_SOURCE_LOCATION (decl)),
   10278              :                           "function %q#D is initialized like a variable",
   10279              :                           decl);
   10280              :             }
   10281              :           /* else no initialization required.  */
   10282              :         }
   10283     62906093 :       else if (DECL_EXTERNAL (decl)
   10284     62906093 :                && ! (DECL_LANG_SPECIFIC (decl)
   10285      7805627 :                      && DECL_NOT_REALLY_EXTERN (decl)))
   10286              :         {
   10287              :           /* check_initializer will have done any constant initialization.  */
   10288              :         }
   10289              :       /* A variable definition.  */
   10290     56723436 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
   10291              :         {
   10292              :           /* Initialize the local variable.  */
   10293     25130507 :           if (!decomp)
   10294     25095110 :             initialize_local_var (decl, init, false);
   10295              :           else
   10296              :             {
   10297        35397 :               tree cleanup = NULL_TREE;
   10298        35397 :               if (DECL_SIZE (decl))
   10299        35397 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10300              :               /* If cp_finish_decomp needs to emit any code, we need to emit that
   10301              :                  code after code emitted by initialize_local_var in a single
   10302              :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
   10303              :                  after the cp_finish_decomp emitted code.
   10304              :                  If there are any cleanups, either extend_ref_init_temps
   10305              :                  created ones or e.g. array destruction, push those first
   10306              :                  with the cleanups guarded on a bool temporary, initially
   10307              :                  set to false and set to true after initialize_local_var
   10308              :                  emitted code.  */
   10309        35397 :               tree guard = NULL_TREE;
   10310        35397 :               if (cleanups || cleanup)
   10311              :                 {
   10312              :                   /* Since the CLEANUP_STMT will refer to the guard, we need it
   10313              :                       to be a variable with the same lifetime.  ??? It might be
   10314              :                       better to use wrap_temporary_cleanups.  */
   10315        35397 :                   guard = get_temp_regvar (boolean_type_node, boolean_false_node);
   10316              :                   /* And make sure register_local_var_uses sees it.  */
   10317        35397 :                   pushdecl (guard);
   10318              :                 }
   10319              : 
   10320        35397 :               tree sl = push_stmt_list ();
   10321        35397 :               initialize_local_var (decl, init, true);
   10322        35397 :               if (guard)
   10323              :                 {
   10324        35397 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
   10325              :                                     guard, boolean_true_node));
   10326        35415 :                   for (tree &t : *cleanups)
   10327           18 :                     t = build3 (COND_EXPR, void_type_node,
   10328              :                                 guard, t, void_node);
   10329        35397 :                   if (cleanup)
   10330           32 :                     cleanup = build3 (COND_EXPR, void_type_node,
   10331              :                                       guard, cleanup, void_node);
   10332              :                 }
   10333        35397 :               unsigned before = stmt_list_stack->length ();
   10334        35397 :               cp_finish_decomp (decl, decomp);
   10335        35397 :               decomp = NULL;
   10336        35397 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
   10337        35397 :               sl = pop_stmt_list (sl);
   10338        35397 :               if (n_extra_cleanups)
   10339              :                 {
   10340              :                   /* If cp_finish_decomp needs any cleanups, such as for
   10341              :                      extend_ref_init_temps created vars, pop_stmt_list
   10342              :                      popped that all, so push those extra cleanups around
   10343              :                      the whole sequence with a guard variable.  */
   10344           15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
   10345           15 :                   guard = get_temp_regvar (integer_type_node, integer_zero_node);
   10346           15 :                   pushdecl (guard);
   10347           78 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
   10348              :                     {
   10349           48 :                       tree_stmt_iterator tsi = tsi_last (sl);
   10350           48 :                       gcc_assert (!tsi_end_p (tsi));
   10351           48 :                       tree last = tsi_stmt (tsi);
   10352           48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
   10353              :                                   && !CLEANUP_EH_ONLY (last));
   10354           48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
   10355           96 :                       tree cl = build3 (COND_EXPR, void_type_node,
   10356              :                                         build2 (GE_EXPR, boolean_type_node,
   10357              :                                                 guard, cst),
   10358           48 :                                         CLEANUP_EXPR (last), void_node);
   10359           48 :                       extra_cleanups.safe_push (cl);
   10360           48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
   10361              :                                                      integer_type_node,
   10362              :                                                      guard, cst),
   10363              :                                        TSI_SAME_STMT);
   10364           48 :                       tree sl2 = CLEANUP_BODY (last);
   10365           48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
   10366           48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
   10367           48 :                       tsi_delink (&tsi);
   10368              :                     }
   10369              :                 }
   10370        35397 :               decomp_init = maybe_cleanup_point_expr_void (sl);
   10371        35397 :               if (cleanup)
   10372           32 :                 finish_decl_cleanup (decl, cleanup);
   10373              :             }
   10374              :         }
   10375              : 
   10376              :       /* If a variable is defined, and then a subsequent
   10377              :          definition with external linkage is encountered, we will
   10378              :          get here twice for the same variable.  We want to avoid
   10379              :          calling expand_static_init more than once.  For variables
   10380              :          that are not static data members, we can call
   10381              :          expand_static_init only when we actually process the
   10382              :          initializer.  It is not legal to redeclare a static data
   10383              :          member, so this issue does not arise in that case.  */
   10384     31592929 :       else if (var_definition_p && TREE_STATIC (decl))
   10385              :         {
   10386     29664602 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
   10387              :             {
   10388          106 :               tree sl = push_stmt_list ();
   10389          106 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
   10390          106 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
   10391          106 :               expand_static_init (decl, init);
   10392          106 :               current_stmt_tree ()->stmts_are_full_exprs_p
   10393          106 :                 = saved_stmts_are_full_exprs_p;
   10394          106 :               cp_finish_decomp (decl, decomp);
   10395          106 :               decomp = NULL;
   10396          106 :               sl = pop_stmt_list (sl);
   10397          106 :               sl = maybe_cleanup_point_expr_void (sl);
   10398          106 :               add_stmt (sl);
   10399              :             }
   10400              :           else
   10401     29664496 :             expand_static_init (decl, init);
   10402              :         }
   10403              :     }
   10404              : 
   10405              :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
   10406              :      reference, insert it in the statement-tree now.  */
   10407    131422452 :   if (cleanups)
   10408              :     {
   10409     55986534 :       for (tree t : *cleanups)
   10410              :         {
   10411         3454 :           push_cleanup (NULL_TREE, t, false);
   10412              :           /* As in initialize_local_var.  */
   10413         3454 :           wrap_temporary_cleanups (init, t);
   10414              :         }
   10415     55983080 :       release_tree_vector (cleanups);
   10416              :     }
   10417              : 
   10418    131422530 :   for (tree t : &extra_cleanups)
   10419           48 :     push_cleanup (NULL_TREE, t, false);
   10420              : 
   10421    131422452 :   if (decomp_init)
   10422        35397 :     add_stmt (decomp_init);
   10423              : 
   10424    131422452 :   if (decomp
   10425          148 :       && var_definition_p
   10426          148 :       && TREE_STATIC (decl)
   10427    131422600 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10428              :     {
   10429          146 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
   10430          146 :                            ? tls_aggregates : static_aggregates);
   10431          146 :       tree aggregates2 = aggregates3;
   10432          146 :       if (aggregates2 != aggregates1)
   10433              :         {
   10434           66 :           cp_finish_decomp (decl, decomp);
   10435           66 :           decomp = NULL;
   10436           66 :           if (aggregates3 != aggregates2)
   10437              :             {
   10438              :               /* If there are dynamic initializers for the structured
   10439              :                  binding base or associated extended ref temps and also
   10440              :                  dynamic initializers for the structured binding non-base
   10441              :                  vars, mark them.  */
   10442          267 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
   10443          204 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
   10444          150 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
   10445           87 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
   10446              :             }
   10447              :         }
   10448              :     }
   10449              : 
   10450    131422452 :   if (was_readonly)
   10451       253195 :     TREE_READONLY (decl) = 1;
   10452              : 
   10453    131422452 :   if (flag_openmp
   10454       453544 :       && VAR_P (decl)
   10455    131622692 :       && lookup_attribute ("omp declare target implicit",
   10456       200240 :                            DECL_ATTRIBUTES (decl)))
   10457              :     {
   10458           52 :       DECL_ATTRIBUTES (decl)
   10459           52 :         = remove_attribute ("omp declare target implicit",
   10460           52 :                             DECL_ATTRIBUTES (decl));
   10461           52 :       complete_type (TREE_TYPE (decl));
   10462           52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
   10463              :         {
   10464           30 :           auto_diagnostic_group d;
   10465           30 :           error ("%q+D in declare target directive does not have mappable"
   10466              :                  " type", decl);
   10467           30 :           if (TREE_TYPE (decl) != error_mark_node
   10468           30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10469           30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
   10470           30 :         }
   10471           22 :       else if (!lookup_attribute ("omp declare target",
   10472           22 :                                   DECL_ATTRIBUTES (decl))
   10473           44 :                && !lookup_attribute ("omp declare target link",
   10474           22 :                                      DECL_ATTRIBUTES (decl)))
   10475              :         {
   10476           22 :           DECL_ATTRIBUTES (decl)
   10477           22 :             = tree_cons (get_identifier ("omp declare target"),
   10478           22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
   10479           22 :           symtab_node *node = symtab_node::get (decl);
   10480           22 :           if (node != NULL)
   10481              :             {
   10482           19 :               node->offloadable = 1;
   10483           19 :               if (ENABLE_OFFLOADING)
   10484              :                 {
   10485              :                   g->have_offload = true;
   10486              :                   if (is_a <varpool_node *> (node))
   10487              :                     vec_safe_push (offload_vars, decl);
   10488              :                 }
   10489              :             }
   10490              :         }
   10491              :     }
   10492              : 
   10493              :   /* This is the last point we can lower alignment so give the target the
   10494              :      chance to do so.  */
   10495    131422452 :   if (VAR_P (decl)
   10496     62906186 :       && !is_global_var (decl)
   10497    156553114 :       && !DECL_HARD_REGISTER (decl))
   10498     25130609 :     targetm.lower_local_decl_alignment (decl);
   10499              : 
   10500    131422452 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
   10501    336123765 : }
   10502              : 
   10503              : /* For class TYPE return itself or some its bases that contain
   10504              :    any direct non-static data members.  Return error_mark_node if an
   10505              :    error has been diagnosed.  */
   10506              : 
   10507              : static tree
   10508        31766 : find_decomp_class_base (location_t loc, tree type, tree ret,
   10509              :                         tsubst_flags_t complain)
   10510              : {
   10511        63532 :   if (LAMBDA_TYPE_P (type))
   10512              :     {
   10513           12 :       if (complain & tf_error)
   10514              :         {
   10515           12 :           auto_diagnostic_group d;
   10516           12 :           error_at (loc, "cannot decompose lambda closure type %qT", type);
   10517           12 :           inform (location_of (type), "lambda declared here");
   10518           12 :         }
   10519           12 :       return error_mark_node;
   10520              :     }
   10521              : 
   10522        31754 :   bool member_seen = false;
   10523       404281 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   10524       680921 :     if (TREE_CODE (field) != FIELD_DECL
   10525        64347 :         || DECL_ARTIFICIAL (field)
   10526       436813 :         || DECL_UNNAMED_BIT_FIELD (field))
   10527       308355 :       continue;
   10528        64211 :     else if (ret)
   10529              :       return type;
   10530        64185 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   10531              :       {
   10532            8 :         if ((complain & tf_error) == 0)
   10533            0 :           return error_mark_node;
   10534            8 :         auto_diagnostic_group d;
   10535            8 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
   10536            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10537              :                          "anonymous struct member", type);
   10538              :         else
   10539            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10540              :                          "anonymous union member", type);
   10541            8 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
   10542            8 :         return error_mark_node;
   10543            8 :       }
   10544        64177 :     else if (!accessible_p (type, field, true))
   10545              :       {
   10546            5 :         if ((complain & tf_error) == 0)
   10547            0 :           return error_mark_node;
   10548            5 :         auto_diagnostic_group d;
   10549            5 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
   10550              :                   field, type);
   10551            5 :         inform (DECL_SOURCE_LOCATION (field),
   10552            5 :                 TREE_PRIVATE (field)
   10553              :                 ? G_("declared private here")
   10554              :                 : G_("declared protected here"));
   10555            5 :         return error_mark_node;
   10556            5 :       }
   10557              :     else
   10558              :       member_seen = true;
   10559              : 
   10560        31715 :   tree base_binfo, binfo;
   10561        31715 :   tree orig_ret = ret;
   10562        31715 :   int i;
   10563        31715 :   if (member_seen)
   10564        31612 :     ret = type;
   10565        31779 :   for (binfo = TYPE_BINFO (type), i = 0;
   10566        31779 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   10567              :     {
   10568           84 :       auto_diagnostic_group d;
   10569           84 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
   10570              :                                        complain);
   10571           84 :       if (t == error_mark_node)
   10572              :         {
   10573            3 :           if (complain & tf_error)
   10574            3 :             inform (location_of (type), "in base class of %qT", type);
   10575            3 :           return error_mark_node;
   10576              :         }
   10577           81 :       if (t != NULL_TREE && t != ret)
   10578              :         {
   10579           54 :           if (ret == type)
   10580              :             {
   10581           10 :               if (complain & tf_error)
   10582           10 :                 error_at (loc, "cannot decompose class type %qT: both it and "
   10583              :                                "its base class %qT have non-static data "
   10584              :                                "members", type, t);
   10585           10 :               return error_mark_node;
   10586              :             }
   10587           44 :           else if (orig_ret != NULL_TREE)
   10588              :             return t;
   10589           44 :           else if (ret != NULL_TREE)
   10590              :             {
   10591            7 :               if (complain & tf_error)
   10592            7 :                 error_at (loc, "cannot decompose class type %qT: its base "
   10593              :                                "classes %qT and %qT have non-static data "
   10594              :                                "members", type, ret, t);
   10595            7 :               return error_mark_node;
   10596              :             }
   10597              :           else
   10598              :             ret = t;
   10599              :         }
   10600           84 :     }
   10601              :   return ret;
   10602              : }
   10603              : 
   10604              : /* Return std::tuple_size<TYPE>::value.  */
   10605              : 
   10606              : static tree
   10607       112933 : get_tuple_size (tree type)
   10608              : {
   10609       112933 :   tree args = make_tree_vec (1);
   10610       112933 :   TREE_VEC_ELT (args, 0) = type;
   10611       112933 :   tree inst = lookup_template_class (tuple_size_identifier, args,
   10612              :                                      /*in_decl*/NULL_TREE,
   10613              :                                      /*context*/std_node,
   10614              :                                      tf_none);
   10615       112933 :   inst = complete_type (inst);
   10616       112933 :   if (inst == error_mark_node
   10617       111419 :       || !COMPLETE_TYPE_P (inst)
   10618       194142 :       || !CLASS_TYPE_P (inst))
   10619              :     return NULL_TREE;
   10620        81209 :   tree val = lookup_qualified_name (inst, value_identifier,
   10621              :                                     LOOK_want::NORMAL, /*complain*/false);
   10622        81209 :   if (val == error_mark_node)
   10623              :     return NULL_TREE;
   10624        81203 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
   10625        81203 :     val = maybe_constant_value (val, NULL_TREE, mce_true);
   10626        81203 :   if (TREE_CODE (val) == INTEGER_CST)
   10627              :     return val;
   10628              :   else
   10629            6 :     return error_mark_node;
   10630              : }
   10631              : 
   10632              : /* Return std::tuple_element<I,TYPE>::type.  */
   10633              : 
   10634              : static tree
   10635        91671 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
   10636              : {
   10637        91671 :   tree args = make_tree_vec (2);
   10638        91671 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
   10639        91671 :   TREE_VEC_ELT (args, 1) = type;
   10640        91671 :   tree inst = lookup_template_class (tuple_element_identifier, args,
   10641              :                                      /*in_decl*/NULL_TREE,
   10642              :                                      /*context*/std_node,
   10643              :                                      tf_warning_or_error);
   10644        91671 :   return make_typename_type (inst, type_identifier,
   10645        91671 :                              none_type, tf_warning_or_error);
   10646              : }
   10647              : 
   10648              : /* Return e.get<i>() or get<i>(e).  */
   10649              : 
   10650              : static tree
   10651        91680 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
   10652              : {
   10653        91680 :   tree targs = make_tree_vec (1);
   10654        91680 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
   10655              : 
   10656        91680 :   tree etype = TREE_TYPE (decl);
   10657        91680 :   tree e = convert_from_reference (decl);
   10658              : 
   10659              :   /* [The id-expression] e is an lvalue if the type of the entity e is an
   10660              :      lvalue reference and an xvalue otherwise.  */
   10661        91680 :   if (!TYPE_REF_P (etype)
   10662        91680 :       || TYPE_REF_IS_RVALUE (etype))
   10663        90308 :     e = move (e);
   10664              : 
   10665        91680 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
   10666              :                                     LOOK_want::NORMAL, /*complain*/false);
   10667        91680 :   bool use_member_get = false;
   10668              : 
   10669              :   /* To use a member get, member lookup must find at least one
   10670              :      declaration that is a function template
   10671              :      whose first template parameter is a non-type parameter.  */
   10672       272554 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
   10673              :     {
   10674        91680 :       tree fn = *iter;
   10675        91680 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
   10676              :         {
   10677         2489 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
   10678         2489 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
   10679         2489 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
   10680              :             {
   10681              :               use_member_get = true;
   10682              :               break;
   10683              :             }
   10684              :         }
   10685              :     }
   10686              : 
   10687        91680 :   if (use_member_get)
   10688              :     {
   10689         2486 :       fns = lookup_template_function (fns, targs);
   10690         2486 :       return build_new_method_call (e, fns, /*args*/NULL,
   10691              :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
   10692         2486 :                                     /*fn_p*/NULL, tf_warning_or_error);
   10693              :     }
   10694              :   else
   10695              :     {
   10696        89194 :       releasing_vec args (make_tree_vector_single (e));
   10697        89194 :       fns = lookup_template_function (get__identifier, targs);
   10698        89194 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
   10699        89194 :       return finish_call_expr (fns, &args, /*novirt*/false,
   10700              :                                /*koenig*/true, tf_warning_or_error);
   10701        89194 :     }
   10702              : }
   10703              : 
   10704              : /* It's impossible to recover the decltype of a tuple decomposition variable
   10705              :    based on the actual type of the variable, so store it in a hash table.  */
   10706              : 
   10707              : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
   10708              : 
   10709              : tree
   10710          662 : lookup_decomp_type (tree v)
   10711              : {
   10712          662 :   if (decomp_type_table)
   10713          535 :     if (tree *slot = decomp_type_table->get (v))
   10714          471 :       return *slot;
   10715              :   return NULL_TREE;
   10716              : }
   10717              : 
   10718              : /* Mangle a decomposition declaration if needed.  Arguments like
   10719              :    in cp_finish_decomp.  */
   10720              : 
   10721              : static void
   10722        68911 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
   10723              : {
   10724        68911 :   if (!processing_template_decl
   10725        68911 :       && !error_operand_p (decl)
   10726       137822 :       && TREE_STATIC (decl))
   10727              :     {
   10728          897 :       auto_vec<tree, 16> v;
   10729          897 :       v.safe_grow (decomp->count, true);
   10730          897 :       tree d = decomp->decl;
   10731         2966 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
   10732         2069 :         v[decomp->count - i - 1] = d;
   10733          897 :       if (DECL_FUNCTION_SCOPE_P (decl))
   10734              :         {
   10735              :           size_t sz = 3;
   10736          933 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10737          664 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
   10738          269 :           char *name = XALLOCAVEC (char, sz);
   10739          269 :           name[0] = 'D';
   10740          269 :           name[1] = 'C';
   10741          269 :           char *p = name + 2;
   10742          933 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10743              :             {
   10744          664 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
   10745          664 :               *p++ = ' ';
   10746          664 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
   10747          664 :               p += len;
   10748              :             }
   10749          269 :           *p = '\0';
   10750          269 :           determine_local_discriminator (decl, get_identifier (name));
   10751              :         }
   10752          897 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
   10753          897 :       maybe_apply_pragma_weak (decl);
   10754          897 :     }
   10755        68911 : }
   10756              : 
   10757              : /* Append #i to DECL_NAME (decl) or for name independent decls
   10758              :    clear DECL_NAME (decl).  */
   10759              : 
   10760              : static void
   10761        33811 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
   10762              : {
   10763        33811 :   if (name_independent_decl_p (decl))
   10764              :     /* Only "_" names are treated as name independent, "_#0" etc. is not and
   10765              :        because we pushdecl the individual decl elements of structured binding
   10766              :        pack, we could get redeclaration errors if there are 2 or more name
   10767              :        independent structured binding packs in the same scope.  */
   10768          312 :     DECL_NAME (decl) = NULL_TREE;
   10769              :   else
   10770              :     {
   10771        33499 :       tree name = DECL_NAME (decl);
   10772        33499 :       size_t len = IDENTIFIER_LENGTH (name) + 22;
   10773        33499 :       char *n = XALLOCAVEC (char, len);
   10774        33499 :       snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
   10775        33499 :                 IDENTIFIER_POINTER (name), i);
   10776        33499 :       DECL_NAME (decl) = get_identifier (n);
   10777              :     }
   10778        33811 : }
   10779              : 
   10780              : /* Return structured binding size of TYPE or -1 if erroneous.  */
   10781              : 
   10782              : HOST_WIDE_INT
   10783          957 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
   10784              : {
   10785          957 :   if (TYPE_REF_P (type))
   10786              :     {
   10787            0 :       type = complete_type (TREE_TYPE (type));
   10788            0 :       if (type == error_mark_node)
   10789              :         return -1;
   10790            0 :       if (!COMPLETE_TYPE_P (type))
   10791              :         {
   10792            0 :           if (complain & tf_error)
   10793            0 :             error_at (loc, "structured binding refers to incomplete type %qT",
   10794              :                       type);
   10795              :           return -1;
   10796              :         }
   10797              :     }
   10798              : 
   10799          957 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10800          957 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10801              :     {
   10802          724 :       if (TYPE_DOMAIN (type) == NULL_TREE)
   10803              :         {
   10804            9 :           if (complain & tf_error)
   10805            6 :             error_at (loc, "cannot decompose array of unknown bound %qT",
   10806              :                       type);
   10807              :           return -1;
   10808              :         }
   10809          715 :       tree nelts = array_type_nelts_top (type);
   10810          715 :       if (nelts == error_mark_node)
   10811              :         return -1;
   10812          715 :       if (!tree_fits_shwi_p (nelts))
   10813              :         {
   10814            3 :           if (complain & tf_error)
   10815            3 :             error_at (loc, "cannot decompose variable length array %qT", type);
   10816              :           return -1;
   10817              :         }
   10818          712 :       return tree_to_shwi (nelts);
   10819              :     }
   10820              :   /* 2 GNU extensions.  */
   10821          233 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10822              :     return 2;
   10823          227 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10824              :     {
   10825           12 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10826              :         {
   10827              :           if (complain & tf_error)
   10828              :             error_at (loc, "cannot decompose variable length vector %qT", type);
   10829              :           return -1;
   10830              :         }
   10831           12 :       return eltscnt;
   10832              :     }
   10833          215 :   else if (tree tsize = get_tuple_size (type))
   10834              :     {
   10835           38 :       if (tsize == error_mark_node
   10836           32 :           || !tree_fits_shwi_p (tsize)
   10837           70 :           || tree_int_cst_sgn (tsize) < 0)
   10838              :         {
   10839            9 :           if (complain & tf_error)
   10840            9 :             error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10841              :                            "constant expression", type);
   10842              :           return -1;
   10843              :         }
   10844           29 :       return tree_to_shwi (tsize);
   10845              :     }
   10846          177 :   else if (TREE_CODE (type) == UNION_TYPE)
   10847              :     {
   10848            3 :       if (complain & tf_error)
   10849            3 :         error_at (loc, "cannot decompose union type %qT", type);
   10850              :       return -1;
   10851              :     }
   10852          174 :   else if (!CLASS_TYPE_P (type))
   10853              :     {
   10854           21 :       if (complain & tf_error)
   10855           18 :         error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10856              :       return -1;
   10857              :     }
   10858          153 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10859              :     return -1;
   10860          153 :   else if (!COMPLETE_TYPE_P (type))
   10861              :     {
   10862            0 :       if (complain & tf_error)
   10863            0 :         error_at (loc, "structured binding refers to incomplete class type "
   10864              :                   "%qT", type);
   10865              :       return -1;
   10866              :     }
   10867              :   else
   10868              :     {
   10869          153 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
   10870          153 :       if (btype == error_mark_node)
   10871              :         return -1;
   10872          132 :       else if (btype == NULL_TREE)
   10873              :         return 0;
   10874          111 :       if (btype != type)
   10875              :         {
   10876            6 :           tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
   10877            6 :           if (binfo == NULL_TREE || binfo == error_mark_node)
   10878              :             return -1;
   10879              :         }
   10880         1150 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10881         1730 :         if (TREE_CODE (field) != FIELD_DECL
   10882          372 :             || DECL_ARTIFICIAL (field)
   10883         1417 :             || DECL_UNNAMED_BIT_FIELD (field))
   10884          685 :           continue;
   10885              :         else
   10886          360 :           eltscnt++;
   10887          105 :       return eltscnt;
   10888              :     }
   10889              : }
   10890              : 
   10891              : /* Finish a decomposition declaration.  DECL is the underlying declaration
   10892              :    "e", FIRST is the head of a chain of decls for the individual identifiers
   10893              :    chained through DECL_CHAIN in reverse order and COUNT is the number of
   10894              :    those decls.  If TEST_P is true, return true if any code would need to be
   10895              :    actually emitted but don't emit it.  Return false otherwise.  */
   10896              : 
   10897              : bool
   10898       342472 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
   10899              : {
   10900       342472 :   tree first = decomp->decl;
   10901       342472 :   unsigned count = decomp->count;
   10902       342472 :   if (error_operand_p (decl))
   10903              :     {
   10904          200 :      error_out:
   10905          625 :       while (count--)
   10906              :         {
   10907          425 :           TREE_TYPE (first) = error_mark_node;
   10908          425 :           if (DECL_HAS_VALUE_EXPR_P (first))
   10909              :             {
   10910            9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
   10911            9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
   10912              :             }
   10913          425 :           first = DECL_CHAIN (first);
   10914              :         }
   10915          200 :       if (DECL_P (decl) && TREE_STATIC (decl))
   10916           54 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
   10917              :       return false;
   10918              :     }
   10919              : 
   10920       342409 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   10921       342409 :   if (type_dependent_expression_p (decl)
   10922              :       /* This happens for range for when not in templates.
   10923              :          Still add the DECL_VALUE_EXPRs for later processing.  */
   10924       342409 :       || (!processing_template_decl
   10925       104843 :           && type_uses_auto (TREE_TYPE (decl))))
   10926              :     {
   10927       654236 :       for (unsigned int i = 0; i < count; i++)
   10928              :         {
   10929       435920 :           if (!DECL_HAS_VALUE_EXPR_P (first))
   10930              :             {
   10931       435920 :               tree v = build_nt (ARRAY_REF, decl,
   10932       435920 :                                  size_int (count - i - 1),
   10933              :                                  NULL_TREE, NULL_TREE);
   10934       435920 :               SET_DECL_VALUE_EXPR (first, v);
   10935       435920 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
   10936              :             }
   10937       435920 :           if (processing_template_decl)
   10938       435284 :             fit_decomposition_lang_decl (first, decl);
   10939       435920 :           first = DECL_CHAIN (first);
   10940              :         }
   10941              :       return false;
   10942              :     }
   10943              : 
   10944       124093 :   auto_vec<tree, 16> v;
   10945       124093 :   v.safe_grow (count, true);
   10946       124093 :   tree d = first;
   10947       124093 :   int pack = -1;
   10948       487323 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
   10949              :     {
   10950       239137 :       v[count - i - 1] = d;
   10951       239137 :       fit_decomposition_lang_decl (d, decl);
   10952       239137 :       if (DECL_PACK_P (d))
   10953        11117 :         pack = count - i - 1;
   10954              :     }
   10955              : 
   10956       124093 :   tree type = TREE_TYPE (decl);
   10957       124093 :   tree dexp = decl;
   10958              : 
   10959       124093 :   if (TYPE_REF_P (type))
   10960              :     {
   10961         2206 :       dexp = convert_from_reference (dexp);
   10962         2206 :       type = complete_type (TREE_TYPE (type));
   10963         2206 :       if (type == error_mark_node)
   10964          137 :         goto error_out;
   10965         2206 :       if (!COMPLETE_TYPE_P (type))
   10966              :         {
   10967            3 :           error_at (loc, "structured binding refers to incomplete type %qT",
   10968              :                     type);
   10969            3 :           goto error_out;
   10970              :         }
   10971              :     }
   10972              : 
   10973       124090 :   tree eltype = NULL_TREE;
   10974       124090 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10975              :   /* Structured binding packs when initializer is non-dependent should
   10976              :      have their DECL_VALUE_EXPR set to a TREE_VEC.  First two elements
   10977              :      of that TREE_VEC are the base and index, what is normally represented
   10978              :      as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
   10979              :      of the pack first element.  The remaining elements of the TREE_VEC
   10980              :      are VAR_DECLs for the pack elements.  */
   10981       124090 :   tree packv = NULL_TREE;
   10982              : 
   10983       124090 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10984              :     {
   10985        11234 :       tree nelts;
   10986        11234 :       nelts = array_type_nelts_top (type);
   10987        11234 :       if (nelts == error_mark_node)
   10988            0 :         goto error_out;
   10989        11234 :       if (DECL_DECOMP_BASE (decl))
   10990              :         {
   10991            9 :           error_at (loc, "array initializer for structured binding "
   10992              :                     "declaration in condition");
   10993            9 :           goto error_out;
   10994              :         }
   10995        11225 :       if (!tree_fits_uhwi_p (nelts))
   10996              :         {
   10997            3 :           error_at (loc, "cannot decompose variable length array %qT", type);
   10998            3 :           goto error_out;
   10999              :         }
   11000        11222 :       eltscnt = tree_to_uhwi (nelts);
   11001        11222 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11002              :         {
   11003           11 :        cnt_mismatch:
   11004           38 :           auto_diagnostic_group d;
   11005           38 :           if (count > eltscnt)
   11006           27 :             error_n (loc, count,
   11007              :                      "%u name provided for structured binding",
   11008              :                      "%u names provided for structured binding", count);
   11009              :           else
   11010           11 :             error_n (loc, count,
   11011              :                      "only %u name provided for structured binding",
   11012              :                      "only %u names provided for structured binding", count);
   11013           38 :           inform_n (loc, eltscnt,
   11014              :                     "while %qT decomposes into %wu element",
   11015              :                     "while %qT decomposes into %wu elements",
   11016              :                     type, eltscnt);
   11017           38 :           goto error_out;
   11018              :         }
   11019        11211 :       eltype = TREE_TYPE (type);
   11020        24136 :       for (unsigned int i = 0; i < count; i++)
   11021              :         {
   11022        12925 :           if ((unsigned) pack == i)
   11023              :             {
   11024        10060 :               packv = make_tree_vec (eltscnt - count + 3);
   11025        51506 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11026              :                 {
   11027        31386 :                   tree t;
   11028        31386 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11029        31386 :                   set_sb_pack_name (t, j);
   11030        31386 :                   maybe_push_decl (t);
   11031        31386 :                   TREE_TYPE (t) = eltype;
   11032        31386 :                   layout_decl (t, 0);
   11033        31386 :                   if (!processing_template_decl)
   11034              :                     {
   11035        31288 :                       tree a = unshare_expr (dexp);
   11036        31288 :                       a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
   11037              :                                   NULL_TREE, NULL_TREE);
   11038        31288 :                       SET_DECL_VALUE_EXPR (t, a);
   11039        31288 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11040              :                     }
   11041              :                 }
   11042        12925 :               continue;
   11043        10060 :             }
   11044         2865 :           TREE_TYPE (v[i]) = eltype;
   11045         2865 :           layout_decl (v[i], 0);
   11046         2865 :           if (processing_template_decl)
   11047          140 :             continue;
   11048         2725 :           tree t = unshare_expr (dexp);
   11049         2725 :           unsigned HOST_WIDE_INT j = i;
   11050         2725 :           if (pack != -1 && (unsigned) pack < i)
   11051           64 :             j = i + eltscnt - count;
   11052         2725 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   11053         2725 :           SET_DECL_VALUE_EXPR (v[i], t);
   11054         2725 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11055              :         }
   11056              :     }
   11057              :   /* 2 GNU extensions.  */
   11058       112856 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   11059              :     {
   11060           78 :       eltscnt = 2;
   11061           78 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11062            3 :         goto cnt_mismatch;
   11063           75 :       eltype = cp_build_qualified_type (TREE_TYPE (type), cp_type_quals (type));
   11064          288 :       for (unsigned int i = 0; i < count; i++)
   11065              :         {
   11066          138 :           if ((unsigned) pack == i)
   11067              :             {
   11068           60 :               packv = make_tree_vec (eltscnt - count + 3);
   11069          192 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11070              :                 {
   11071           72 :                   tree t;
   11072           72 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11073           72 :                   set_sb_pack_name (t, j);
   11074           72 :                   maybe_push_decl (t);
   11075           72 :                   TREE_TYPE (t) = eltype;
   11076           72 :                   layout_decl (t, 0);
   11077           72 :                   if (!processing_template_decl)
   11078              :                     {
   11079           72 :                       tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
   11080              :                                        unshare_expr (dexp));
   11081           48 :                       SET_DECL_VALUE_EXPR (t, a);
   11082           48 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11083              :                     }
   11084              :                 }
   11085           60 :               continue;
   11086           60 :             }
   11087           78 :           TREE_TYPE (v[i]) = eltype;
   11088           78 :           layout_decl (v[i], 0);
   11089           78 :           if (processing_template_decl)
   11090           16 :             continue;
   11091           62 :           tree t = unshare_expr (dexp);
   11092           62 :           unsigned HOST_WIDE_INT j = i;
   11093           62 :           if (pack != -1 && (unsigned) pack < i)
   11094           16 :             j = i + eltscnt - count;
   11095           93 :           t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
   11096           62 :           SET_DECL_VALUE_EXPR (v[i], t);
   11097           62 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11098              :         }
   11099              :     }
   11100       112778 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   11101              :     {
   11102           60 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   11103              :         {
   11104              :           error_at (loc, "cannot decompose variable length vector %qT", type);
   11105              :           goto error_out;
   11106              :         }
   11107           60 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11108            3 :         goto cnt_mismatch;
   11109           57 :       eltype = cp_build_qualified_type (TREE_TYPE (type), cp_type_quals (type));
   11110          306 :       for (unsigned int i = 0; i < count; i++)
   11111              :         {
   11112          192 :           if ((unsigned) pack == i)
   11113              :             {
   11114           48 :               packv = make_tree_vec (eltscnt - count + 3);
   11115          756 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11116              :                 {
   11117          660 :                   tree t;
   11118          660 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11119          660 :                   set_sb_pack_name (t, j);
   11120          660 :                   maybe_push_decl (t);
   11121          660 :                   TREE_TYPE (t) = eltype;
   11122          660 :                   layout_decl (t, 0);
   11123          660 :                   if (!processing_template_decl)
   11124              :                     {
   11125          440 :                       tree a = unshare_expr (dexp);
   11126          440 :                       location_t loc = DECL_SOURCE_LOCATION (t);
   11127          440 :                       tree s = size_int (j + pack);
   11128          440 :                       convert_vector_to_array_for_subscript (loc, &a, s);
   11129          440 :                       a = build4 (ARRAY_REF, eltype, a, s,
   11130              :                                   NULL_TREE, NULL_TREE);
   11131          440 :                       SET_DECL_VALUE_EXPR (t, a);
   11132          440 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   11133              :                     }
   11134              :                 }
   11135           84 :               continue;
   11136           48 :             }
   11137          144 :           TREE_TYPE (v[i]) = eltype;
   11138          144 :           layout_decl (v[i], 0);
   11139          144 :           if (processing_template_decl)
   11140           36 :             continue;
   11141          108 :           tree t = unshare_expr (dexp);
   11142          108 :           unsigned HOST_WIDE_INT j = i;
   11143          108 :           if (pack != -1 && (unsigned) pack < i)
   11144           24 :             j = i + eltscnt - count;
   11145          108 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
   11146          108 :                                                  &t, size_int (j));
   11147          108 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   11148          108 :           SET_DECL_VALUE_EXPR (v[i], t);
   11149          108 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11150              :         }
   11151              :     }
   11152       112718 :   else if (tree tsize = get_tuple_size (type))
   11153              :     {
   11154        81165 :       if (tsize == error_mark_node)
   11155              :         {
   11156            0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   11157              :                          "constant expression", type);
   11158            0 :           goto error_out;
   11159              :         }
   11160        81165 :       if (!tree_fits_uhwi_p (tsize))
   11161              :         {
   11162           12 :           auto_diagnostic_group d;
   11163           12 :           error_n (loc, count,
   11164              :                    "%u name provided for structured binding",
   11165              :                    "%u names provided for structured binding", count);
   11166           12 :           inform (loc, "while %qT decomposes into %E elements",
   11167              :                   type, tsize);
   11168           12 :           goto error_out;
   11169           12 :         }
   11170        81153 :       eltscnt = tree_to_uhwi (tsize);
   11171        81153 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11172            6 :         goto cnt_mismatch;
   11173        81147 :       if (test_p && eltscnt)
   11174       123956 :         return true;
   11175        45496 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
   11176              :         {
   11177              :           /* For structured bindings used in conditions we need to evaluate
   11178              :              the conversion of decl (aka e in the standard) to bool or
   11179              :              integral/enumeral type (the latter for switch conditions)
   11180              :              before the get methods, as [dcl.struct.bind]/7 requires that:
   11181              :              "The initialization of e and any conversion of e considered as
   11182              :              a decision variable is sequenced before the initialization of
   11183              :              any r_i."  */
   11184           89 :           tree cond = convert_from_reference (decl);
   11185           89 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   11186              :             /* switch condition.  */
   11187           18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   11188              :                                                cond, true);
   11189              :           else
   11190              :             /* if/while/for condition.  */
   11191           71 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   11192           89 :           if (cond && !error_operand_p (cond))
   11193              :             {
   11194           89 :               cond = get_temp_regvar (TREE_TYPE (cond), cond);
   11195           89 :               pushdecl (cond);
   11196              :               /* Set DECL_DECOMP_BASE to cond VAR_DECL wrapped in
   11197              :                  NON_LVALUE_EXPR, such that it is considered to be
   11198              :                  the condition of a structured binding rather than
   11199              :                  structured binding's base variable.  */
   11200           89 :               DECL_DECOMP_BASE (decl)
   11201          178 :                 = build1 (NON_LVALUE_EXPR, TREE_TYPE (cond), cond);
   11202              :             }
   11203              :         }
   11204        45496 :       int save_read = DECL_READ_P (decl);
   11205       136371 :       for (unsigned i = 0; i < count; ++i)
   11206              :         {
   11207        90896 :           location_t sloc = input_location;
   11208        90896 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   11209              : 
   11210        90896 :           if ((unsigned) pack == i)
   11211              :             {
   11212          405 :               packv = make_tree_vec (eltscnt - count + 3);
   11213         1999 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11214              :                 {
   11215         1189 :                   tree t;
   11216         1189 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11217         1189 :                   set_sb_pack_name (t, j);
   11218         1189 :                   input_location = dloc;
   11219         1189 :                   tree init = get_tuple_decomp_init (decl, j + pack);
   11220         1189 :                   tree eltype = (init == error_mark_node ? error_mark_node
   11221         1189 :                                  : get_tuple_element_type (type, j + pack));
   11222         1189 :                   input_location = sloc;
   11223              : 
   11224         1189 :                   if (VOID_TYPE_P (eltype))
   11225              :                     {
   11226            0 :                       error ("%<std::tuple_element<%wu, %T>::type%> is "
   11227              :                              "%<void%>", j + pack, type);
   11228            0 :                       eltype = error_mark_node;
   11229              :                     }
   11230         1189 :                   if (init == error_mark_node || eltype == error_mark_node)
   11231              :                     {
   11232            0 :                       inform (dloc, "in initialization of structured binding "
   11233            0 :                               "pack %qD", v[pack]);
   11234            0 :                       goto error_out;
   11235              :                     }
   11236         1189 :                   maybe_push_decl (t);
   11237              :                   /* Save the decltype away before reference collapse.  */
   11238         1189 :                   hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
   11239         1189 :                   if (glvalue_p (init))
   11240         1087 :                     eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11241         1189 :                   TREE_TYPE (t) = eltype;
   11242         1189 :                   layout_decl (t, 0);
   11243         1189 :                   DECL_HAS_VALUE_EXPR_P (t) = 0;
   11244         1189 :                   if (!processing_template_decl)
   11245              :                     {
   11246          797 :                       copy_linkage (t, decl);
   11247          797 :                       tree name = DECL_NAME (t);
   11248          797 :                       if (TREE_STATIC (decl))
   11249           54 :                         DECL_NAME (t) = DECL_NAME (v[pack]);
   11250          797 :                       cp_finish_decl (t, init, /*constexpr*/false,
   11251              :                                       /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11252          797 :                       if (TREE_STATIC (decl))
   11253              :                         {
   11254           54 :                           DECL_ASSEMBLER_NAME (t);
   11255           54 :                           DECL_NAME (t) = name;
   11256              :                         }
   11257              :                     }
   11258              :                 }
   11259          405 :               continue;
   11260          405 :             }
   11261              : 
   11262        90491 :           unsigned HOST_WIDE_INT j = i;
   11263        90491 :           if (pack != -1 && (unsigned) pack < i)
   11264          235 :             j = i + eltscnt - count;
   11265        90491 :           input_location = dloc;
   11266        90491 :           tree init = get_tuple_decomp_init (decl, j);
   11267        90491 :           tree eltype = (init == error_mark_node ? error_mark_node
   11268        90482 :                          : get_tuple_element_type (type, j));
   11269        90491 :           input_location = sloc;
   11270              : 
   11271        90491 :           if (VOID_TYPE_P (eltype))
   11272              :             {
   11273            3 :               error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
   11274              :                      j, type);
   11275            3 :               eltype = error_mark_node;
   11276              :             }
   11277        90491 :           if (init == error_mark_node || eltype == error_mark_node)
   11278              :             {
   11279           21 :               inform (dloc, "in initialization of structured binding "
   11280           21 :                       "variable %qD", v[i]);
   11281           21 :               goto error_out;
   11282              :             }
   11283              :           /* Save the decltype away before reference collapse.  */
   11284        90470 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   11285        90470 :           if (glvalue_p (init))
   11286        90119 :             eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11287        90470 :           TREE_TYPE (v[i]) = eltype;
   11288        90470 :           layout_decl (v[i], 0);
   11289        90470 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   11290              :             {
   11291              :               /* In this case the names are variables, not just proxies.  */
   11292          220 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   11293          220 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   11294              :             }
   11295        90470 :           if (!processing_template_decl)
   11296              :             {
   11297        70878 :               copy_linkage (v[i], decl);
   11298        70878 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   11299              :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11300              :             }
   11301              :         }
   11302              :       /* Ignore reads from the underlying decl performed during initialization
   11303              :          of the individual variables.  If those will be read, we'll mark
   11304              :          the underlying decl as read at that point.  */
   11305        45475 :       DECL_READ_P (decl) = save_read;
   11306              :     }
   11307        31553 :   else if (TREE_CODE (type) == UNION_TYPE)
   11308              :     {
   11309            3 :       error_at (loc, "cannot decompose union type %qT", type);
   11310            3 :       goto error_out;
   11311              :     }
   11312        31550 :   else if (!CLASS_TYPE_P (type))
   11313              :     {
   11314           19 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   11315           19 :       goto error_out;
   11316              :     }
   11317        31531 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   11318            0 :     goto error_out;
   11319        31531 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   11320            2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   11321              :              type);
   11322              :   else
   11323              :     {
   11324        31529 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE,
   11325              :                                            tf_warning_or_error);
   11326        31529 :       if (btype == error_mark_node)
   11327           21 :         goto error_out;
   11328        31508 :       else if (btype == NULL_TREE)
   11329              :         {
   11330           24 :           if (pack == 0 && count == 1)
   11331              :             {
   11332           16 :               eltscnt = 0;
   11333           16 :               packv = make_tree_vec (2);
   11334           16 :               goto done;
   11335              :             }
   11336            8 :           error_at (loc, "cannot decompose class type %qT without non-static "
   11337              :                          "data members", type);
   11338            8 :           goto error_out;
   11339              :         }
   11340       401448 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11341       676154 :         if (TREE_CODE (field) != FIELD_DECL
   11342        63790 :             || DECL_ARTIFICIAL (field)
   11343       433750 :             || DECL_UNNAMED_BIT_FIELD (field))
   11344       306190 :           continue;
   11345              :         else
   11346        63774 :           eltscnt++;
   11347        31484 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11348           15 :         goto cnt_mismatch;
   11349        31469 :       tree t = dexp;
   11350        31469 :       if (type != btype)
   11351              :         {
   11352           18 :           t = convert_to_base (t, btype, /*check_access*/true,
   11353              :                                /*nonnull*/false, tf_warning_or_error);
   11354           18 :           type = btype;
   11355              :         }
   11356        31469 :       unsigned HOST_WIDE_INT j = 0;
   11357        31469 :       unsigned int i = 0;
   11358       401237 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11359       675799 :         if (TREE_CODE (field) != FIELD_DECL
   11360        63753 :             || DECL_ARTIFICIAL (field)
   11361       433517 :             || DECL_UNNAMED_BIT_FIELD (field))
   11362       306031 :           continue;
   11363              :         else
   11364              :           {
   11365        63737 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   11366              :                                                      NULL_TREE);
   11367        63737 :             if (REFERENCE_REF_P (tt))
   11368           30 :               tt = TREE_OPERAND (tt, 0);
   11369        63737 :             if (pack != -1 && j >= (unsigned) pack)
   11370              :               {
   11371          685 :                 if (j == (unsigned) pack)
   11372              :                   {
   11373          227 :                     packv = make_tree_vec (eltscnt - count + 3);
   11374          227 :                     i++;
   11375              :                   }
   11376          685 :                 if (j < (unsigned) pack + eltscnt - (count - 1))
   11377              :                   {
   11378          504 :                     tree t;
   11379          504 :                     TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
   11380          504 :                     set_sb_pack_name (t, j + 1 - i);
   11381          504 :                     maybe_push_decl (t);
   11382          504 :                     TREE_TYPE (t) = TREE_TYPE (tt);
   11383          504 :                     layout_decl (t, 0);
   11384          504 :                     if (!processing_template_decl)
   11385              :                       {
   11386          383 :                         SET_DECL_VALUE_EXPR (t, tt);
   11387          383 :                         DECL_HAS_VALUE_EXPR_P (t) = 1;
   11388              :                       }
   11389              :                     else
   11390          121 :                       DECL_HAS_VALUE_EXPR_P (t) = 0;
   11391          504 :                     j++;
   11392          504 :                     continue;
   11393          504 :                   }
   11394              :               }
   11395        63233 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   11396        63233 :             layout_decl (v[i], 0);
   11397        63233 :             if (!processing_template_decl)
   11398              :               {
   11399        44191 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   11400        44191 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11401              :               }
   11402        63233 :             i++;
   11403        63233 :             j++;
   11404              :           }
   11405        31469 :       if (pack != -1 && j == (unsigned) pack)
   11406              :         {
   11407           20 :           gcc_checking_assert (eltscnt == count - 1);
   11408           20 :           packv = make_tree_vec (2);
   11409              :         }
   11410              :     }
   11411        88305 :  done:
   11412        88305 :   if (packv)
   11413              :     {
   11414        10836 :       gcc_checking_assert (pack != -1);
   11415        10836 :       TREE_VEC_ELT (packv, 0) = decl;
   11416        10836 :       TREE_VEC_ELT (packv, 1) = size_int (pack);
   11417        10836 :       SET_DECL_VALUE_EXPR (v[pack], packv);
   11418        10836 :       DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
   11419        10836 :       DECL_IGNORED_P (v[pack]) = 1;
   11420        10836 :       if (!processing_template_decl)
   11421        43485 :         for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
   11422        32956 :           pushdecl (TREE_VEC_ELT (packv, 2 + i));
   11423              :     }
   11424        88305 :   if (processing_template_decl)
   11425              :     {
   11426        58629 :       for (unsigned int i = 0; i < count; i++)
   11427        39135 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   11428              :           {
   11429        38681 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   11430              :                                NULL_TREE, NULL_TREE);
   11431        38681 :             SET_DECL_VALUE_EXPR (v[i], a);
   11432        38681 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11433              :           }
   11434              :     }
   11435        68811 :   else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
   11436              :     {
   11437          480 :       tree attr = NULL_TREE, *pa = &attr;
   11438         1550 :       for (unsigned int i = 0; i < count; i++)
   11439         1070 :         if ((unsigned) pack != i
   11440         1070 :             && DECL_HAS_VALUE_EXPR_P (v[i])
   11441         1796 :             && !DECL_IGNORED_P (v[i]))
   11442              :           {
   11443          726 :             (*debug_hooks->early_global_decl) (v[i]);
   11444          726 :             *pa = build_tree_list (NULL_TREE, v[i]);
   11445          726 :             pa = &TREE_CHAIN (*pa);
   11446              :           }
   11447          480 :       if (attr)
   11448          364 :         DECL_ATTRIBUTES (decl)
   11449          728 :           = tree_cons (get_identifier ("structured bindings"),
   11450          364 :                        attr, DECL_ATTRIBUTES (decl));
   11451              :     }
   11452              :   return false;
   11453              : }
   11454              : 
   11455              : /* Returns a declaration for a VAR_DECL as if:
   11456              : 
   11457              :      extern "C" TYPE NAME;
   11458              : 
   11459              :    had been seen.  Used to create compiler-generated global
   11460              :    variables.  */
   11461              : 
   11462              : static tree
   11463         2221 : declare_global_var (tree name, tree type)
   11464              : {
   11465         2221 :   auto cookie = push_abi_namespace (global_namespace);
   11466         2221 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   11467         2221 :   TREE_PUBLIC (decl) = 1;
   11468         2221 :   DECL_EXTERNAL (decl) = 1;
   11469         2221 :   DECL_ARTIFICIAL (decl) = 1;
   11470         2221 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   11471              :   /* If the user has explicitly declared this variable (perhaps
   11472              :      because the code we are compiling is part of a low-level runtime
   11473              :      library), then it is possible that our declaration will be merged
   11474              :      with theirs by pushdecl.  */
   11475         2221 :   decl = pushdecl (decl);
   11476         2221 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   11477         2221 :   pop_abi_namespace (cookie, global_namespace);
   11478              : 
   11479         2221 :   return decl;
   11480              : }
   11481              : 
   11482              : /* Returns the type for the argument to "atexit" corresponding to the function
   11483              :    to be called when the program exits.  */
   11484              : 
   11485              : static tree
   11486           24 : get_atexit_fn_ptr_type ()
   11487              : {
   11488           24 :   if (!atexit_fn_ptr_type_node)
   11489              :     {
   11490           12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   11491           12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   11492              :     }
   11493              : 
   11494           24 :   return atexit_fn_ptr_type_node;
   11495              : }
   11496              : 
   11497              : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   11498              :    or "__cxa_throw" corresponding to the destructor to be called when the
   11499              :    program exits.  */
   11500              : 
   11501              : tree
   11502        19419 : get_cxa_atexit_fn_ptr_type ()
   11503              : {
   11504        19419 :   if (!cleanup_type)
   11505              :     {
   11506        14628 :       tree fntype = build_function_type_list (void_type_node,
   11507              :                                               ptr_type_node, NULL_TREE);
   11508        14628 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   11509        14628 :       cleanup_type = build_pointer_type (fntype);
   11510              :     }
   11511              : 
   11512        19419 :   return cleanup_type;
   11513              : }
   11514              : 
   11515              : /* Returns a pointer to the `atexit' function.  Note that if
   11516              :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   11517              :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   11518              : 
   11519              : static tree
   11520         3511 : get_atexit_node (void)
   11521              : {
   11522         3511 :   tree atexit_fndecl;
   11523         3511 :   tree fn_type;
   11524         3511 :   tree fn_ptr_type;
   11525         3511 :   const char *name;
   11526         3511 :   bool use_aeabi_atexit;
   11527         3511 :   tree ctx = global_namespace;
   11528              : 
   11529         3511 :   if (atexit_node)
   11530              :     return atexit_node;
   11531              : 
   11532         2184 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   11533              :     {
   11534              :       /* The declaration for `__cxa_atexit' is:
   11535              : 
   11536              :            int __cxa_atexit (void (*)(void *), void *, void *)
   11537              : 
   11538              :          We build up the argument types and then the function type
   11539              :          itself.  */
   11540         2172 :       tree argtype0, argtype1, argtype2;
   11541              : 
   11542         2172 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   11543              :       /* First, build the pointer-to-function type for the first
   11544              :          argument.  */
   11545         2172 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   11546              :       /* Then, build the rest of the argument types.  */
   11547         2172 :       argtype2 = ptr_type_node;
   11548         2172 :       if (use_aeabi_atexit)
   11549              :         {
   11550              :           argtype1 = fn_ptr_type;
   11551              :           argtype0 = ptr_type_node;
   11552              :         }
   11553              :       else
   11554              :         {
   11555         2172 :           argtype1 = ptr_type_node;
   11556         2172 :           argtype0 = fn_ptr_type;
   11557              :         }
   11558              :       /* And the final __cxa_atexit type.  */
   11559         2172 :       fn_type = build_function_type_list (integer_type_node,
   11560              :                                           argtype0, argtype1, argtype2,
   11561              :                                           NULL_TREE);
   11562              :       /* ... which needs noexcept.  */
   11563         2172 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11564         2172 :       if (use_aeabi_atexit)
   11565              :         {
   11566            0 :           name = "__aeabi_atexit";
   11567            0 :           push_to_top_level ();
   11568            0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   11569            0 :           ctx = current_namespace;
   11570            0 :           while (n--)
   11571            0 :             pop_namespace ();
   11572            0 :           pop_from_top_level ();
   11573              :         }
   11574              :       else
   11575              :         {
   11576         2172 :           name = "__cxa_atexit";
   11577         2172 :           ctx = abi_node;
   11578              :         }
   11579              :     }
   11580              :   else
   11581              :     {
   11582              :       /* The declaration for `atexit' is:
   11583              : 
   11584              :            int atexit (void (*)());
   11585              : 
   11586              :          We build up the argument types and then the function type
   11587              :          itself.  */
   11588           12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   11589              :       /* Build the final atexit type.  */
   11590           12 :       fn_type = build_function_type_list (integer_type_node,
   11591              :                                           fn_ptr_type, NULL_TREE);
   11592              :       /* ... which needs noexcept.  */
   11593           12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11594           12 :       name = "atexit";
   11595              :     }
   11596              : 
   11597              :   /* Now, build the function declaration.  */
   11598         2184 :   push_lang_context (lang_name_c);
   11599         2184 :   auto cookie = push_abi_namespace (ctx);
   11600         2184 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   11601         2184 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11602              :   /* Install as hidden builtin so we're (a) more relaxed about
   11603              :     exception spec matching and (b) will not give a confusing location
   11604              :     in diagnostic and (c) won't magically appear in user-visible name
   11605              :     lookups.  */
   11606         2184 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11607         2184 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11608         2184 :   pop_abi_namespace (cookie, ctx);
   11609         2184 :   mark_used (atexit_fndecl);
   11610         2184 :   pop_lang_context ();
   11611         2184 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11612              : 
   11613         2184 :   return atexit_node;
   11614              : }
   11615              : 
   11616              : /* Like get_atexit_node, but for thread-local cleanups.  */
   11617              : 
   11618              : static tree
   11619           98 : get_thread_atexit_node (void)
   11620              : {
   11621           98 :   if (thread_atexit_node)
   11622              :     return thread_atexit_node;
   11623              : 
   11624              :   /* The declaration for `__cxa_thread_atexit' is:
   11625              : 
   11626              :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   11627           59 :   tree fn_type = build_function_type_list (integer_type_node,
   11628              :                                            get_cxa_atexit_fn_ptr_type (),
   11629              :                                            ptr_type_node, ptr_type_node,
   11630              :                                            NULL_TREE);
   11631              : 
   11632              :   /* Now, build the function declaration, as with __cxa_atexit.  */
   11633           59 :   unsigned flags = push_abi_namespace ();
   11634           59 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   11635              :                                              ECF_LEAF | ECF_NOTHROW);
   11636           59 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11637           59 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11638           59 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11639           59 :   pop_abi_namespace (flags);
   11640           59 :   mark_used (atexit_fndecl);
   11641           59 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11642              : 
   11643           59 :   return thread_atexit_node;
   11644              : }
   11645              : 
   11646              : /* Returns the __dso_handle VAR_DECL.  */
   11647              : 
   11648              : static tree
   11649         3597 : get_dso_handle_node (void)
   11650              : {
   11651         3597 :   if (dso_handle_node)
   11652              :     return dso_handle_node;
   11653              : 
   11654              :   /* Declare the variable.  */
   11655         2221 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   11656              :                                         ptr_type_node);
   11657              : 
   11658              : #ifdef HAVE_GAS_HIDDEN
   11659         2221 :   if (dso_handle_node != error_mark_node)
   11660              :     {
   11661         2218 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   11662         2218 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   11663              :     }
   11664              : #endif
   11665              : 
   11666         2221 :   return dso_handle_node;
   11667              : }
   11668              : 
   11669              : /* Begin a new function with internal linkage whose job will be simply
   11670              :    to destroy some particular DECL.  OB_PARM is true if object pointer
   11671              :    is passed to the cleanup function, otherwise no argument is passed.  */
   11672              : 
   11673              : static tree
   11674          383 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   11675              : {
   11676          383 :   push_to_top_level ();
   11677              : 
   11678              :   /* No need to mangle this.  */
   11679          383 :   push_lang_context (lang_name_c);
   11680              : 
   11681              :   /* Build the name of the function.  */
   11682          383 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   11683          383 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   11684          383 :   dname = targetm.strip_name_encoding (dname);
   11685          763 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   11686              : 
   11687          383 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   11688              :                                    : get_atexit_fn_ptr_type ());
   11689              :   /* Build the function declaration.  */
   11690          383 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   11691          383 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   11692              :   /* It's a function with internal linkage, generated by the
   11693              :      compiler.  */
   11694          383 :   TREE_PUBLIC (fndecl) = 0;
   11695          383 :   DECL_ARTIFICIAL (fndecl) = 1;
   11696              :   /* Make the function `inline' so that it is only emitted if it is
   11697              :      actually needed.  It is unlikely that it will be inlined, since
   11698              :      it is only called via a function pointer, but we avoid unnecessary
   11699              :      emissions this way.  */
   11700          383 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   11701          383 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   11702          383 :   if (ob_parm)
   11703              :     {
   11704              :       /* Build the parameter.  */
   11705          371 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   11706          371 :       TREE_USED (parmdecl) = 1;
   11707          371 :       DECL_READ_P (parmdecl) = 1;
   11708          371 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   11709              :     }
   11710              : 
   11711          383 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   11712          383 :   if (omp_target)
   11713              :     {
   11714            3 :       DECL_ATTRIBUTES (fndecl)
   11715            3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   11716            3 :                      DECL_ATTRIBUTES (fndecl));
   11717            3 :       DECL_ATTRIBUTES (fndecl)
   11718            6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   11719            3 :                      DECL_ATTRIBUTES (fndecl));
   11720              :     }
   11721          383 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   11722              : 
   11723          383 :   pop_lang_context ();
   11724              : 
   11725          383 :   return current_function_decl;
   11726              : }
   11727              : 
   11728              : /* Finish the cleanup function begun by start_cleanup_fn.  */
   11729              : 
   11730              : static void
   11731          383 : end_cleanup_fn (void)
   11732              : {
   11733          383 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   11734              : 
   11735          383 :   pop_from_top_level ();
   11736          383 : }
   11737              : 
   11738              : /* Generate code to handle the destruction of DECL, an object with
   11739              :    static storage duration.  */
   11740              : 
   11741              : tree
   11742        15322 : register_dtor_fn (tree decl, bool omp_target)
   11743              : {
   11744        15322 :   tree cleanup;
   11745        15322 :   tree addr;
   11746        15322 :   tree compound_stmt;
   11747        15322 :   tree fcall;
   11748        15322 :   tree type;
   11749        15322 :   bool ob_parm, dso_parm, use_dtor;
   11750        15322 :   tree arg0, arg1, arg2;
   11751        15322 :   tree atex_node;
   11752              : 
   11753        15322 :   type = TREE_TYPE (decl);
   11754        15322 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   11755        11713 :     return void_node;
   11756              : 
   11757         3609 :   if (decl_maybe_constant_destruction (decl, type)
   11758         3609 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   11759              :     {
   11760            0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11761            0 :       return void_node;
   11762              :     }
   11763              : 
   11764              :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   11765              :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   11766              :      destructor to "__cxa_atexit"; we don't have to build a temporary
   11767              :      function to do the cleanup.  */
   11768         7218 :   dso_parm = (flag_use_cxa_atexit
   11769         3609 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   11770         3609 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   11771         3597 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   11772         3609 :   if (use_dtor)
   11773              :     {
   11774         3226 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   11775              : 
   11776              :       /* Make sure it is accessible.  */
   11777         3226 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   11778              :                                      tf_warning_or_error);
   11779              :     }
   11780              :   else
   11781              :     {
   11782              :       /* Call build_cleanup before we enter the anonymous function so
   11783              :          that any access checks will be done relative to the current
   11784              :          scope, rather than the scope of the anonymous function.  */
   11785          383 :       build_cleanup (decl);
   11786              : 
   11787              :       /* Now start the function.  */
   11788          383 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   11789              : 
   11790              :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   11791              :          to the original function, rather than the anonymous one.  That
   11792              :          will make the back end think that nested functions are in use,
   11793              :          which causes confusion.  */
   11794          383 :       push_deferring_access_checks (dk_no_check);
   11795          383 :       fcall = build_cleanup (decl);
   11796          383 :       pop_deferring_access_checks ();
   11797              : 
   11798              :       /* Create the body of the anonymous function.  */
   11799          383 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   11800          383 :       finish_expr_stmt (fcall);
   11801          383 :       finish_compound_stmt (compound_stmt);
   11802          383 :       end_cleanup_fn ();
   11803              :     }
   11804              : 
   11805              :   /* Call atexit with the cleanup function.  */
   11806         3609 :   mark_used (cleanup);
   11807         3609 :   cleanup = build_address (cleanup);
   11808              : 
   11809         3609 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   11810           98 :     atex_node = get_thread_atexit_node ();
   11811              :   else
   11812         3511 :     atex_node = get_atexit_node ();
   11813              : 
   11814         3609 :   if (use_dtor)
   11815              :     {
   11816              :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   11817              :          expects.  */
   11818         3226 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   11819              :       /* "__cxa_atexit" will pass the address of DECL to the
   11820              :          cleanup function.  */
   11821         3226 :       mark_used (decl);
   11822         3226 :       addr = build_address (decl);
   11823              :       /* The declared type of the parameter to "__cxa_atexit" is
   11824              :          "void *".  For plain "T*", we could just let the
   11825              :          machinery in cp_build_function_call convert it -- but if the
   11826              :          type is "cv-qualified T *", then we need to convert it
   11827              :          before passing it in, to avoid spurious errors.  */
   11828         3226 :       addr = build_nop (ptr_type_node, addr);
   11829              :     }
   11830              :   else
   11831              :     /* Since the cleanup functions we build ignore the address
   11832              :        they're given, there's no reason to pass the actual address
   11833              :        in, and, in general, it's cheaper to pass NULL than any
   11834              :        other value.  */
   11835          383 :     addr = null_pointer_node;
   11836              : 
   11837         3609 :   if (dso_parm)
   11838         3597 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   11839              :                                tf_warning_or_error);
   11840           12 :   else if (ob_parm)
   11841              :     /* Just pass NULL to the dso handle parm if we don't actually
   11842              :        have a DSO handle on this target.  */
   11843            0 :     arg2 = null_pointer_node;
   11844              :   else
   11845              :     arg2 = NULL_TREE;
   11846              : 
   11847         3597 :   if (ob_parm)
   11848              :     {
   11849         3597 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   11850         3597 :           && targetm.cxx.use_aeabi_atexit ())
   11851              :         {
   11852              :           arg1 = cleanup;
   11853              :           arg0 = addr;
   11854              :         }
   11855              :       else
   11856              :         {
   11857              :           arg1 = addr;
   11858              :           arg0 = cleanup;
   11859              :         }
   11860              :     }
   11861              :   else
   11862              :     {
   11863              :       arg0 = cleanup;
   11864              :       arg1 = NULL_TREE;
   11865              :     }
   11866         3609 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   11867         3609 :                                       arg0, arg1, arg2, NULL_TREE);
   11868              : }
   11869              : 
   11870              : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   11871              :    is its initializer.  Generate code to handle the construction
   11872              :    and destruction of DECL.  */
   11873              : 
   11874              : static void
   11875     29664602 : expand_static_init (tree decl, tree init)
   11876              : {
   11877     29664602 :   gcc_assert (VAR_P (decl));
   11878     29664602 :   gcc_assert (TREE_STATIC (decl));
   11879              : 
   11880              :   /* Some variables require no dynamic initialization.  */
   11881     29664602 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   11882              :     {
   11883              :       /* Make sure the destructor is callable.  */
   11884     29661028 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11885     29661028 :       if (!init)
   11886              :         return;
   11887              :     }
   11888              : 
   11889        16186 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   11890        15260 :       && !DECL_FUNCTION_SCOPE_P (decl))
   11891              :     {
   11892           15 :       auto_diagnostic_group d;
   11893           15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   11894           15 :       if (init)
   11895           12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11896              :                   "needs dynamic initialization", decl);
   11897              :       else
   11898            3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11899              :                   "has a non-trivial destructor", decl);
   11900           15 :       static bool informed;
   11901           15 :       if (!informed)
   11902              :         {
   11903            6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   11904              :                   "initialization and destruction");
   11905            6 :           informed = true;
   11906              :         }
   11907           15 :       return;
   11908           15 :     }
   11909              : 
   11910        15216 :   if (DECL_FUNCTION_SCOPE_P (decl))
   11911              :     {
   11912              :       /* Emit code to perform this initialization but once.  */
   11913         3873 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   11914         3873 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   11915         3873 :       tree guard, guard_addr;
   11916         3873 :       tree flag, begin;
   11917              :       /* We don't need thread-safety code for thread-local vars.  */
   11918         3873 :       bool thread_guard = (flag_threadsafe_statics
   11919         3873 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   11920              : 
   11921              :       /* Emit code to perform this initialization but once.  This code
   11922              :          looks like:
   11923              : 
   11924              :            static <type> guard;
   11925              :            if (!__atomic_load (guard.first_byte)) {
   11926              :              if (__cxa_guard_acquire (&guard)) {
   11927              :                bool flag = false;
   11928              :                try {
   11929              :                  // Do initialization.
   11930              :                  flag = true; __cxa_guard_release (&guard);
   11931              :                  // Register variable for destruction at end of program.
   11932              :                } catch {
   11933              :                  if (!flag) __cxa_guard_abort (&guard);
   11934              :                }
   11935              :              }
   11936              :            }
   11937              : 
   11938              :          Note that the `flag' variable is only set to 1 *after* the
   11939              :          initialization is complete.  This ensures that an exception,
   11940              :          thrown during the construction, will cause the variable to
   11941              :          reinitialized when we pass through this code again, as per:
   11942              : 
   11943              :            [stmt.dcl]
   11944              : 
   11945              :            If the initialization exits by throwing an exception, the
   11946              :            initialization is not complete, so it will be tried again
   11947              :            the next time control enters the declaration.
   11948              : 
   11949              :          This process should be thread-safe, too; multiple threads
   11950              :          should not be able to initialize the variable more than
   11951              :          once.  */
   11952              : 
   11953              :       /* Create the guard variable.  */
   11954         3873 :       guard = get_guard (decl);
   11955              : 
   11956              :       /* Begin the conditional initialization.  */
   11957         3873 :       if_stmt = begin_if_stmt ();
   11958              : 
   11959         3873 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   11960         3873 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11961              : 
   11962         3873 :       if (thread_guard)
   11963              :         {
   11964         3725 :           tree vfntype = NULL_TREE;
   11965         3725 :           tree acquire_name, release_name, abort_name;
   11966         3725 :           tree acquire_fn, release_fn, abort_fn;
   11967         3725 :           guard_addr = build_address (guard);
   11968              : 
   11969         3725 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   11970         3725 :           release_name = get_identifier ("__cxa_guard_release");
   11971         3725 :           abort_name = get_identifier ("__cxa_guard_abort");
   11972         3725 :           acquire_fn = get_global_binding (acquire_name);
   11973         3725 :           release_fn = get_global_binding (release_name);
   11974         3725 :           abort_fn = get_global_binding (abort_name);
   11975         3725 :           if (!acquire_fn)
   11976         2087 :             acquire_fn = push_library_fn
   11977         2087 :               (acquire_name, build_function_type_list (integer_type_node,
   11978         2087 :                                                        TREE_TYPE (guard_addr),
   11979              :                                                        NULL_TREE),
   11980              :                NULL_TREE, ECF_NOTHROW);
   11981         3725 :           if (!release_fn || !abort_fn)
   11982         2090 :             vfntype = build_function_type_list (void_type_node,
   11983         2090 :                                                 TREE_TYPE (guard_addr),
   11984              :                                                 NULL_TREE);
   11985         2090 :           if (!release_fn)
   11986         2090 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   11987              :                                           ECF_NOTHROW);
   11988         3725 :           if (!abort_fn)
   11989         2090 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   11990              :                                         ECF_NOTHROW | ECF_LEAF);
   11991              : 
   11992         3725 :           inner_if_stmt = begin_if_stmt ();
   11993         3725 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   11994              :                                inner_if_stmt);
   11995              : 
   11996         3725 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11997         3725 :           begin = get_internal_target_expr (boolean_false_node);
   11998         3725 :           flag = TARGET_EXPR_SLOT (begin);
   11999              : 
   12000         3725 :           TARGET_EXPR_CLEANUP (begin)
   12001         3725 :             = build3 (COND_EXPR, void_type_node, flag,
   12002              :                       void_node,
   12003              :                       build_call_n (abort_fn, 1, guard_addr));
   12004         3725 :           CLEANUP_EH_ONLY (begin) = 1;
   12005              : 
   12006              :           /* Do the initialization itself.  */
   12007         3725 :           init = add_stmt_to_compound (begin, init);
   12008         3725 :           init = add_stmt_to_compound (init,
   12009              :                                        build2 (MODIFY_EXPR, void_type_node,
   12010              :                                                flag, boolean_true_node));
   12011              : 
   12012              :           /* Use atexit to register a function for destroying this static
   12013              :              variable.  Do this before calling __cxa_guard_release.  */
   12014         3725 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   12015              : 
   12016         3725 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   12017              :                                                            guard_addr));
   12018              :         }
   12019              :       else
   12020              :         {
   12021          148 :           init = add_stmt_to_compound (init, set_guard (guard));
   12022              : 
   12023              :           /* Use atexit to register a function for destroying this static
   12024              :              variable.  */
   12025          148 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   12026              :         }
   12027              : 
   12028         3873 :       finish_expr_stmt (init);
   12029              : 
   12030         3873 :       if (thread_guard)
   12031              :         {
   12032         3725 :           finish_compound_stmt (inner_then_clause);
   12033         3725 :           finish_then_clause (inner_if_stmt);
   12034         3725 :           finish_if_stmt (inner_if_stmt);
   12035              :         }
   12036              : 
   12037         3873 :       finish_compound_stmt (then_clause);
   12038         3873 :       finish_then_clause (if_stmt);
   12039         3873 :       finish_if_stmt (if_stmt);
   12040              :     }
   12041        11343 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   12042          795 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   12043              :   else
   12044        10548 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   12045              : }
   12046              : 
   12047              : 
   12048              : /* Make TYPE a complete type based on INITIAL_VALUE.
   12049              :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   12050              :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   12051              :    3 if the initializer list is empty (in pedantic mode). */
   12052              : 
   12053              : int
   12054       625103 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   12055              : {
   12056       625103 :   int failure;
   12057       625103 :   tree type, elt_type;
   12058              : 
   12059              :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   12060       625073 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   12061       149769 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   12062       625435 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   12063              :     return 1;
   12064              : 
   12065       625100 :   if (initial_value)
   12066              :     {
   12067              :       /* An array of character type can be initialized from a
   12068              :          brace-enclosed string constant so call reshape_init to
   12069              :          remove the optional braces from a braced string literal.  */
   12070       625070 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   12071       625070 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   12072        51497 :         initial_value = reshape_init (*ptype, initial_value,
   12073              :                                       tf_warning_or_error);
   12074              : 
   12075              :       /* If any of the elements are parameter packs, we can't actually
   12076              :          complete this type now because the array size is dependent.  */
   12077       625070 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   12078     49327849 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   12079     48878938 :           if (PACK_EXPANSION_P (e.value))
   12080              :             return 0;
   12081              :     }
   12082              : 
   12083       625100 :   failure = complete_array_type (ptype, initial_value, do_default);
   12084              : 
   12085              :   /* We can create the array before the element type is complete, which
   12086              :      means that we didn't have these two bits set in the original type
   12087              :      either.  In completing the type, we are expected to propagate these
   12088              :      bits.  See also complete_type which does the same thing for arrays
   12089              :      of fixed size.  */
   12090       625100 :   type = *ptype;
   12091      1250197 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   12092              :     {
   12093       625073 :       elt_type = TREE_TYPE (type);
   12094       625073 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   12095      1250146 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   12096       625073 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   12097              :     }
   12098              : 
   12099              :   return failure;
   12100              : }
   12101              : 
   12102              : /* As above, but either give an error or reject zero-size arrays, depending
   12103              :    on COMPLAIN.  */
   12104              : 
   12105              : int
   12106         1253 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   12107              :                                  bool do_default, tsubst_flags_t complain)
   12108              : {
   12109         1253 :   int failure;
   12110         1253 :   bool sfinae = !(complain & tf_error);
   12111              :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   12112         1253 :   if (sfinae)
   12113            3 :     ++pedantic;
   12114         1253 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   12115         1253 :   if (sfinae)
   12116            3 :     --pedantic;
   12117         1253 :   if (failure)
   12118              :     {
   12119            3 :       if (sfinae)
   12120              :         /* Not an error.  */;
   12121            0 :       else if (failure == 1)
   12122            0 :         error ("initializer fails to determine size of %qT", *ptype);
   12123            0 :       else if (failure == 2)
   12124              :         {
   12125            0 :           if (do_default)
   12126            0 :             error ("array size missing in %qT", *ptype);
   12127              :         }
   12128            0 :       else if (failure == 3)
   12129            0 :         error ("zero-size array %qT", *ptype);
   12130            3 :       *ptype = error_mark_node;
   12131              :     }
   12132         1253 :   return failure;
   12133              : }
   12134              : 
   12135              : /* Return zero if something is declared to be a member of type
   12136              :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   12137              :    message to print in that case.  Otherwise, quietly return 1.  */
   12138              : 
   12139              : static int
   12140     27294688 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   12141              : {
   12142     27294688 :   if (ctype && ctype != cur_type)
   12143              :     {
   12144            0 :       if (flags == DTOR_FLAG)
   12145            0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   12146              :       else
   12147            0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   12148              :       return 0;
   12149              :     }
   12150              :   return 1;
   12151              : }
   12152              : 
   12153              : /* Subroutine of `grokdeclarator'.  */
   12154              : 
   12155              : /* Generate errors possibly applicable for a given set of specifiers.
   12156              :    This is for ARM $7.1.2.  */
   12157              : 
   12158              : static void
   12159    457619393 : bad_specifiers (tree object,
   12160              :                 enum bad_spec_place type,
   12161              :                 int virtualp,
   12162              :                 int quals,
   12163              :                 int inlinep,
   12164              :                 int friendp,
   12165              :                 int raises,
   12166              :                 const location_t* locations)
   12167              : {
   12168    457619393 :   switch (type)
   12169              :     {
   12170     70951280 :       case BSP_VAR:
   12171     70951280 :         if (virtualp)
   12172            0 :           error_at (locations[ds_virtual],
   12173              :                     "%qD declared as a %<virtual%> variable", object);
   12174     70951280 :         if (quals)
   12175            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   12176              :                  "%qD invalid in variable declaration", object);
   12177              :         break;
   12178    303935234 :       case BSP_PARM:
   12179    303935234 :         if (virtualp)
   12180            0 :           error_at (locations[ds_virtual],
   12181              :                     "%qD declared as a %<virtual%> parameter", object);
   12182    303935234 :         if (inlinep)
   12183            6 :           error_at (locations[ds_inline],
   12184              :                     "%qD declared as an %<inline%> parameter", object);
   12185    303935234 :         if (quals)
   12186            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   12187              :                  "%qD invalid in parameter declaration", object);
   12188              :         break;
   12189     48759046 :       case BSP_TYPE:
   12190     48759046 :         if (virtualp)
   12191            0 :           error_at (locations[ds_virtual],
   12192              :                     "%qD declared as a %<virtual%> type", object);
   12193     48759046 :         if (inlinep)
   12194            6 :           error_at (locations[ds_inline],
   12195              :                     "%qD declared as an %<inline%> type", object);
   12196     48759046 :         if (quals)
   12197            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   12198              :                  "%qD invalid in type declaration", object);
   12199              :         break;
   12200     33973833 :       case BSP_FIELD:
   12201     33973833 :         if (virtualp)
   12202            6 :           error_at (locations[ds_virtual],
   12203              :                     "%qD declared as a %<virtual%> field", object);
   12204     33973833 :         if (inlinep)
   12205            6 :           error_at (locations[ds_inline],
   12206              :                     "%qD declared as an %<inline%> field", object);
   12207     33973833 :         if (quals)
   12208            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   12209              :                  "%qD invalid in field declaration", object);
   12210              :         break;
   12211            0 :       default:
   12212            0 :         gcc_unreachable();
   12213              :     }
   12214    457619393 :   if (friendp)
   12215            0 :     error ("%q+D declared as a friend", object);
   12216    457619393 :   if (raises
   12217          131 :       && !flag_noexcept_type
   12218    457619418 :       && (TREE_CODE (object) == TYPE_DECL
   12219           19 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   12220            5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   12221            4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   12222            6 :     error ("%q+D declared with an exception specification", object);
   12223    457619393 : }
   12224              : 
   12225              : /* DECL is a member function or static data member and is presently
   12226              :    being defined.  Check that the definition is taking place in a
   12227              :    valid namespace.  */
   12228              : 
   12229              : static void
   12230    100869003 : check_class_member_definition_namespace (tree decl)
   12231              : {
   12232              :   /* These checks only apply to member functions and static data
   12233              :      members.  */
   12234    100869003 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   12235              :   /* We check for problems with specializations in pt.cc in
   12236              :      check_specialization_namespace, where we can issue better
   12237              :      diagnostics.  */
   12238    100869003 :   if (processing_specialization)
   12239              :     return;
   12240              :   /* We check this in check_explicit_instantiation_namespace.  */
   12241    100725643 :   if (processing_explicit_instantiation)
   12242              :     return;
   12243              :   /* [class.mfct]
   12244              : 
   12245              :      A member function definition that appears outside of the
   12246              :      class definition shall appear in a namespace scope enclosing
   12247              :      the class definition.
   12248              : 
   12249              :      [class.static.data]
   12250              : 
   12251              :      The definition for a static data member shall appear in a
   12252              :      namespace scope enclosing the member's class definition.  */
   12253    100725563 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   12254           18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   12255           18 :                decl, DECL_CONTEXT (decl));
   12256              : }
   12257              : 
   12258              : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   12259              :    METHOD_TYPE for a non-static member function; QUALS are the
   12260              :    cv-qualifiers that apply to the function.  */
   12261              : 
   12262              : tree
   12263    244313959 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   12264              : {
   12265    244313959 :   tree this_type;
   12266    244313959 :   tree qual_type;
   12267    244313959 :   tree parm;
   12268    244313959 :   cp_cv_quals this_quals;
   12269              : 
   12270    244313959 :   if (CLASS_TYPE_P (type))
   12271              :     {
   12272    106635458 :       this_type
   12273    106635458 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   12274    106635458 :       this_type = build_pointer_type (this_type);
   12275              :     }
   12276              :   else
   12277    137678501 :     this_type = type_of_this_parm (type);
   12278              :   /* The `this' parameter is implicitly `const'; it cannot be
   12279              :      assigned to.  */
   12280    244313959 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   12281    244313959 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   12282    244313959 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   12283    244313959 :   cp_apply_type_quals_to_decl (this_quals, parm);
   12284    244313959 :   return parm;
   12285              : }
   12286              : 
   12287              : /* DECL is a static member function.  Complain if it was declared
   12288              :    with function-cv-quals.  */
   12289              : 
   12290              : static void
   12291     10915034 : check_static_quals (tree decl, cp_cv_quals quals)
   12292              : {
   12293            0 :   if (quals != TYPE_UNQUALIFIED)
   12294            6 :     error ("static member function %q#D declared with type qualifiers",
   12295              :            decl);
   12296            0 : }
   12297              : 
   12298              : /* Helper function.  Replace the temporary this parameter injected
   12299              :    during cp_finish_omp_declare_simd with the real this parameter.  */
   12300              : 
   12301              : static tree
   12302         2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   12303              : {
   12304         2692 :   tree this_parm = (tree) data;
   12305         2692 :   if (TREE_CODE (*tp) == PARM_DECL
   12306          450 :       && DECL_NAME (*tp) == this_identifier
   12307         2965 :       && *tp != this_parm)
   12308          273 :     *tp = this_parm;
   12309         2419 :   else if (TYPE_P (*tp))
   12310           33 :     *walk_subtrees = 0;
   12311         2692 :   return NULL_TREE;
   12312              : }
   12313              : 
   12314              : /* CTYPE is class type, or null if non-class.
   12315              :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   12316              :    or METHOD_TYPE.
   12317              :    DECLARATOR is the function's name.
   12318              :    PARMS is a chain of PARM_DECLs for the function.
   12319              :    VIRTUALP is truthvalue of whether the function is virtual or not.
   12320              :    FLAGS are to be passed through to `grokclassfn'.
   12321              :    QUALS are qualifiers indicating whether the function is `const'
   12322              :    or `volatile'.
   12323              :    RAISES is a list of exceptions that this function can raise.
   12324              :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   12325              :    not look, and -1 if we should not call `grokclassfn' at all.
   12326              : 
   12327              :    SFK is the kind of special function (if any) for the new function.
   12328              : 
   12329              :    Returns `NULL_TREE' if something goes wrong, after issuing
   12330              :    applicable error messages.  */
   12331              : 
   12332              : static tree
   12333    194541494 : grokfndecl (tree ctype,
   12334              :             tree type,
   12335              :             tree declarator,
   12336              :             tree parms,
   12337              :             tree orig_declarator,
   12338              :             const cp_decl_specifier_seq *declspecs,
   12339              :             tree decl_reqs,
   12340              :             int virtualp,
   12341              :             enum overload_flags flags,
   12342              :             cp_cv_quals quals,
   12343              :             cp_ref_qualifier rqual,
   12344              :             tree raises,
   12345              :             int check,
   12346              :             int friendp,
   12347              :             int publicp,
   12348              :             int inlinep,
   12349              :             int initialized,
   12350              :             bool xobj_func_p,
   12351              :             special_function_kind sfk,
   12352              :             bool funcdef_flag,
   12353              :             bool late_return_type_p,
   12354              :             int template_count,
   12355              :             tree in_namespace,
   12356              :             tree* attrlist,
   12357              :             tree contract_specifiers,
   12358              :             location_t location)
   12359              : {
   12360    194541494 :   tree decl;
   12361    194541494 :   tree t;
   12362              : 
   12363    194541494 :   if (location == UNKNOWN_LOCATION)
   12364            0 :     location = input_location;
   12365              : 
   12366              :   /* Was the concept specifier present?  */
   12367    194541494 :   bool concept_p = inlinep & 4;
   12368              : 
   12369    194541494 :   if (concept_p)
   12370              :     {
   12371           15 :       error_at (location, "function concepts are no longer supported");
   12372           15 :       return NULL_TREE;
   12373              :     }
   12374              : 
   12375              :   /* [except.spec]/9 - A deallocation function with no explicit noexcept-specifier
   12376              :      has a non-throwing exception specification.  */
   12377    194541479 :   if (raises == NULL_TREE
   12378    116478061 :       && cxx_dialect >= cxx11
   12379    140769492 :       && IDENTIFIER_NEWDEL_OP_P (declarator)
   12380    194605824 :       && !IDENTIFIER_NEW_OP_P (declarator))
   12381          919 :     raises = noexcept_true_spec;
   12382              : 
   12383    194541479 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   12384              : 
   12385    194541479 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   12386              : 
   12387              :   /* Set the constraints on the declaration. */
   12388    194541479 :   if (flag_concepts)
   12389              :     {
   12390    190296615 :       tree tmpl_reqs = NULL_TREE;
   12391    190296615 :       tree ctx = friendp ? current_class_type : ctype;
   12392    190296615 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   12393    190296615 :       bool memtmpl = (!block_local
   12394    190296615 :                       && (current_template_depth
   12395    190238538 :                           > template_class_depth (ctx)));
   12396     52624767 :       if (memtmpl)
   12397              :         {
   12398     52624767 :           if (!current_template_parms)
   12399              :             /* If there are no template parameters, something must have
   12400              :                gone wrong.  */
   12401            0 :             gcc_assert (seen_error ());
   12402              :           else
   12403     52624767 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   12404              :         }
   12405    190296615 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   12406              :       /* C++20 CA378: Remove non-templated constrained functions.  */
   12407              :       /* [temp.friend]/9 A non-template friend declaration with a
   12408              :          requires-clause shall be a definition. A friend function template with
   12409              :          a constraint that depends on a template parameter from an enclosing
   12410              :          template shall be a definition. */
   12411    190296615 :       if (ci
   12412     10259205 :           && (block_local
   12413     10259202 :               || !processing_template_decl
   12414     10259141 :               || (friendp && !memtmpl && !funcdef_flag)))
   12415              :         {
   12416           73 :           if (!friendp || !processing_template_decl)
   12417           64 :             error_at (location, "constraints on a non-templated function");
   12418              :           else
   12419            9 :             error_at (location, "constrained non-template friend declaration"
   12420              :                       " must be a definition");
   12421              :           ci = NULL_TREE;
   12422              :         }
   12423    190296615 :       set_constraints (decl, ci);
   12424      1280749 :       if (ci && friendp && memtmpl && !funcdef_flag
   12425    190334121 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   12426            6 :         error_at (location, "friend function template with constraints that "
   12427              :                   "depend on outer template parameters must be a definition");
   12428              :     }
   12429              : 
   12430    194541479 :   if (TREE_CODE (type) == METHOD_TYPE)
   12431              :     {
   12432    105117800 :       tree parm = build_this_parm (decl, type, quals);
   12433    105117800 :       DECL_CHAIN (parm) = parms;
   12434    105117800 :       parms = parm;
   12435              : 
   12436              :       /* Allocate space to hold the vptr bit if needed.  */
   12437    105117800 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   12438              :     }
   12439              : 
   12440    194541479 :   DECL_ARGUMENTS (decl) = parms;
   12441    587339080 :   for (t = parms; t; t = DECL_CHAIN (t))
   12442              :     {
   12443    392797601 :       DECL_CONTEXT (t) = decl;
   12444    392797601 :       if (flag_reflection
   12445      8093748 :           && initialized == SD_INITIALIZED
   12446    394427199 :           && DECL_ATTRIBUTES (t))
   12447         3690 :         for (tree a = DECL_ATTRIBUTES (t);
   12448         3694 :              (a = lookup_annotation (a));
   12449            4 :              a = TREE_CHAIN (a))
   12450              :           {
   12451            4 :             gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
   12452              :             /* Mark TREE_PURPOSE of the value that it is an annotation
   12453              :                on an argument of a function definition (rather than
   12454              :                annotation from function declaration).  For function parameter
   12455              :                reflection all annotations are listed, while for variable_of
   12456              :                only those marked here.  Annotation is marked as coming from
   12457              :                function definition's argument if it has TREE_PURPOSE
   12458              :                void_node or INTEGER_CST with signed type.  */
   12459            4 :             tree val = TREE_VALUE (a);
   12460            4 :             gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
   12461            4 :             TREE_PURPOSE (val) = void_node;
   12462              :           }
   12463              :     }
   12464              : 
   12465              :   /* Propagate volatile out from type to decl.  */
   12466    194541479 :   if (TYPE_VOLATILE (type))
   12467            0 :     TREE_THIS_VOLATILE (decl) = 1;
   12468              : 
   12469              :   /* Setup decl according to sfk.  */
   12470    194541479 :   switch (sfk)
   12471              :     {
   12472     24945218 :     case sfk_constructor:
   12473     24945218 :     case sfk_copy_constructor:
   12474     24945218 :     case sfk_move_constructor:
   12475     24945218 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   12476     24945218 :       DECL_NAME (decl) = ctor_identifier;
   12477     24945218 :       break;
   12478      3328301 :     case sfk_destructor:
   12479      3328301 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   12480      3328301 :       DECL_NAME (decl) = dtor_identifier;
   12481      3328301 :       break;
   12482      1259342 :     case sfk_deduction_guide:
   12483              :       /* Give deduction guides a definition even though they don't really
   12484              :          have one: the restriction that you can't repeat a deduction guide
   12485              :          makes them more like a definition anyway.  */
   12486      1259342 :       DECL_INITIAL (decl) = void_node;
   12487              :       /* But to ensure that external-linkage deduction guides in header units
   12488              :          don't fall afoul of [module.import] p6, mark them as inline.  */
   12489      1259342 :       DECL_DECLARED_INLINE_P (decl) = true;
   12490      1259342 :       break;
   12491              :     default:
   12492              :       break;
   12493              :     }
   12494              : 
   12495    194541479 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   12496              :     {
   12497       109902 :       if (funcdef_flag)
   12498            3 :         error_at (location,
   12499              :                   "defining explicit specialization %qD in friend declaration",
   12500              :                   orig_declarator);
   12501              :       else
   12502              :         {
   12503       109899 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   12504       109899 :           tree args = TREE_OPERAND (orig_declarator, 1);
   12505              : 
   12506       109899 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   12507              :             {
   12508              :               /* Something like `template <class T> friend void f<T>()'.  */
   12509            6 :               error_at (location,
   12510              :                         "invalid use of template-id %qD in declaration "
   12511              :                         "of primary template",
   12512              :                         orig_declarator);
   12513            6 :               return NULL_TREE;
   12514              :             }
   12515              : 
   12516              :           /* A friend declaration of the form friend void f<>().  Record
   12517              :              the information in the TEMPLATE_ID_EXPR.  */
   12518       109893 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   12519              : 
   12520       109893 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   12521       109893 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   12522              : 
   12523              :           /* Remember the befriending class like push_template_decl does for
   12524              :              template friends.  */
   12525       109893 :           gcc_checking_assert (!DECL_CHAIN (decl));
   12526       109893 :           DECL_CHAIN (decl) = current_scope ();
   12527              : 
   12528       364252 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   12529       254364 :             if (TREE_PURPOSE (t)
   12530       254364 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   12531              :             {
   12532            5 :               error_at (defparse_location (TREE_PURPOSE (t)),
   12533              :                         "default arguments are not allowed in declaration "
   12534              :                         "of friend template specialization %qD",
   12535              :                         decl);
   12536            5 :               return NULL_TREE;
   12537              :             }
   12538              : 
   12539       109888 :           if (inlinep & 1)
   12540              :             {
   12541            5 :               error_at (declspecs->locations[ds_inline],
   12542              :                         "%<inline%> is not allowed in declaration of friend "
   12543              :                         "template specialization %qD",
   12544              :                         decl);
   12545            5 :               return NULL_TREE;
   12546              :             }
   12547              :         }
   12548              :     }
   12549              : 
   12550              :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   12551              :      expression, that declaration shall be a definition..."  */
   12552    194541463 :   if (friendp && !funcdef_flag)
   12553              :     {
   12554      1896556 :       bool has_errored = false;
   12555      1896556 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   12556      5317132 :            t && t != void_list_node; t = TREE_CHAIN (t))
   12557      3420576 :         if (TREE_PURPOSE (t))
   12558              :           {
   12559           51 :             enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
   12560              :             /* For templates, mark the default argument as erroneous and give a
   12561              :                hard error.  */
   12562           51 :             if (processing_template_decl)
   12563              :               {
   12564           33 :                 diag_kind = diagnostics::kind::error;
   12565           33 :                 TREE_PURPOSE (t) = error_mark_node;
   12566              :               }
   12567           51 :             if (!has_errored)
   12568              :               {
   12569           48 :                 has_errored = true;
   12570           48 :                 emit_diagnostic (diag_kind,
   12571           48 :                                  DECL_SOURCE_LOCATION (decl),
   12572           48 :                                  /*diagnostics::option_id=*/0,
   12573              :                                  "friend declaration of %qD specifies default "
   12574              :                                  "arguments and isn%'t a definition", decl);
   12575              :               }
   12576              :           }
   12577              :     }
   12578              : 
   12579              :   /* If this decl has namespace scope, set that up.  */
   12580    194541463 :   if (in_namespace)
   12581       415624 :     set_decl_namespace (decl, in_namespace, friendp);
   12582    194125839 :   else if (ctype)
   12583    115947832 :     DECL_CONTEXT (decl) = ctype;
   12584              :   else
   12585     78178007 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   12586              : 
   12587              :   /* `main' and builtins have implicit 'C' linkage.  */
   12588    194541463 :   if (ctype == NULL_TREE
   12589     78593631 :       && DECL_FILE_SCOPE_P (decl)
   12590     32353554 :       && current_lang_name == lang_name_cplusplus
   12591    197571071 :       && (MAIN_NAME_P (declarator)
   12592      2995600 :           || (IDENTIFIER_LENGTH (declarator) > 10
   12593      2150969 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   12594      1667501 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   12595       350182 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   12596              :                              "builtin_"))
   12597      2995582 :           || (targetcm.cxx_implicit_extern_c
   12598            0 :               && (targetcm.cxx_implicit_extern_c
   12599            0 :                   (IDENTIFIER_POINTER (declarator))))))
   12600        34026 :     SET_DECL_LANGUAGE (decl, lang_c);
   12601              : 
   12602    194541463 :   DECL_STATIC_FUNCTION_P (decl)
   12603    194541463 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   12604    194541463 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   12605              : 
   12606    194541463 :   if (initialized == SD_DELETED)
   12607      4308963 :     DECL_DELETED_FN (decl) = 1;
   12608              : 
   12609    194541463 :   if (ctype && funcdef_flag)
   12610    100361124 :     check_class_member_definition_namespace (decl);
   12611              : 
   12612    194541463 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12613              :     {
   12614        34014 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   12615            9 :         error_at (location, "cannot declare %<::main%> to be a template");
   12616        34014 :       if (inlinep & 1)
   12617            3 :         error_at (declspecs->locations[ds_inline],
   12618              :                   "cannot declare %<::main%> to be inline");
   12619        34014 :       if (inlinep & 2)
   12620            6 :         error_at (declspecs->locations[ds_constexpr],
   12621              :                   "cannot declare %<::main%> to be %qs", "constexpr");
   12622        34014 :       if (inlinep & 8)
   12623            3 :         error_at (declspecs->locations[ds_consteval],
   12624              :                   "cannot declare %<::main%> to be %qs", "consteval");
   12625        34014 :       if (!publicp)
   12626            0 :         error_at (location, "cannot declare %<::main%> to be static");
   12627        34014 :       if (current_lang_name != lang_name_cplusplus)
   12628           12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   12629              :                  " linkage specification other than %<extern \"C++\"%>");
   12630        34014 :       if (module_attach_p ())
   12631              :         {
   12632            3 :           auto_diagnostic_group adg;
   12633            3 :           error_at (location, "cannot attach %<::main%> to a named module");
   12634            3 :           inform (location, "use %<extern \"C++\"%> to attach it to the "
   12635              :                   "global module instead");
   12636            3 :         }
   12637              :       inlinep = 0;
   12638              :       publicp = 1;
   12639              :     }
   12640              : 
   12641              :   /* Members of anonymous types and local classes have no linkage; make
   12642              :      them internal.  If a typedef is made later, this will be changed.  */
   12643    194541463 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   12644              :     publicp = 0;
   12645    194526213 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   12646              :     /* But members of local classes in a module CMI should have their
   12647              :        definitions exported, in case they are (directly or indirectly)
   12648              :        used by an importer.  We don't just use module_has_cmi_p here
   12649              :        because for entities in the GMF we don't yet know whether this
   12650              :        module will have a CMI, so we'll conservatively assume it might.  */
   12651      2427940 :     publicp = module_maybe_has_cmi_p ();
   12652              : 
   12653    194526213 :   if (publicp && cxx_dialect == cxx98)
   12654              :     {
   12655              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12656              :          or enumeration declared in a local scope) shall not be used to
   12657              :          declare an entity with linkage.
   12658              : 
   12659              :          DR 757 relaxes this restriction for C++0x.  */
   12660      1024736 :       no_linkage_error (decl);
   12661              :     }
   12662              : 
   12663    194541463 :   TREE_PUBLIC (decl) = publicp;
   12664    194541463 :   if (! publicp)
   12665              :     {
   12666      2546245 :       DECL_INTERFACE_KNOWN (decl) = 1;
   12667      2546245 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   12668              :     }
   12669              : 
   12670              :   /* If the declaration was declared inline, mark it as such.  */
   12671    194541463 :   if (inlinep)
   12672              :     {
   12673     75909697 :       DECL_DECLARED_INLINE_P (decl) = 1;
   12674     75909697 :       if (publicp)
   12675     75660786 :         DECL_COMDAT (decl) = 1;
   12676              :     }
   12677     75909697 :   if (inlinep & 2)
   12678     55480015 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12679    139061448 :   else if (inlinep & 8)
   12680              :     {
   12681      1161219 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12682      1161219 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   12683              :     }
   12684              : 
   12685    194541463 :   DECL_EXTERNAL (decl) = 1;
   12686    194541463 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12687              :     {
   12688     89423663 :       if (quals || rqual)
   12689          393 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   12690              :                                               TYPE_UNQUALIFIED,
   12691              :                                               REF_QUAL_NONE);
   12692     89423663 :       auto_diagnostic_group d;
   12693     89423663 :       if (quals)
   12694          621 :         error (!ctype
   12695              :                ? G_("non-member function %qD cannot have cv-qualifier")
   12696              :                : !xobj_func_p
   12697          297 :                  ? G_("static member function %qD cannot have cv-qualifier")
   12698              :                  : G_("explicit object member function "
   12699              :                       "%qD cannot have cv-qualifier"),
   12700              :                decl);
   12701     89423663 :       if (rqual)
   12702          531 :         error (!ctype
   12703              :                ? G_("non-member function %qD cannot have ref-qualifier")
   12704              :                : !xobj_func_p
   12705          264 :                  ? G_("static member function %qD cannot have ref-qualifier")
   12706              :                  : G_("explicit object member function "
   12707              :                       "%qD cannot have ref-qualifier"),
   12708              :                  decl);
   12709              : 
   12710     89423663 :       if (xobj_func_p && (quals || rqual))
   12711          363 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   12712              :                 "explicit object parameter declared here");
   12713     89423663 :       quals = TYPE_UNQUALIFIED;
   12714     89423663 :       rqual = REF_QUAL_NONE;
   12715              : 
   12716     89423663 :     }
   12717              : 
   12718    194541463 :   if (deduction_guide_p (decl))
   12719              :     {
   12720      1259342 :       tree type = TREE_TYPE (DECL_NAME (decl));
   12721      1259342 :       if (in_namespace == NULL_TREE
   12722      1259342 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   12723              :         {
   12724            3 :           auto_diagnostic_group d;
   12725            3 :           error_at (location, "deduction guide %qD must be declared in the "
   12726              :                               "same scope as %qT", decl, type);
   12727            3 :           inform (location_of (type), "  declared here");
   12728            3 :           return NULL_TREE;
   12729            3 :         }
   12730      2518678 :       if (DECL_CLASS_SCOPE_P (decl)
   12731      1259380 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   12732              :         {
   12733            3 :           auto_diagnostic_group d;
   12734            3 :           error_at (location, "deduction guide %qD must have the same access "
   12735              :                               "as %qT", decl, type);
   12736            3 :           inform (location_of (type), "  declared here");
   12737            3 :         }
   12738      1259339 :       if (funcdef_flag)
   12739            3 :         error_at (location,
   12740              :                   "deduction guide %qD must not have a function body", decl);
   12741              :     }
   12742    360356432 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   12743    205478315 :            && !grok_op_properties (decl, /*complain=*/true))
   12744              :     return NULL_TREE;
   12745    193281974 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   12746              :     {
   12747       313948 :       bool long_long_unsigned_p;
   12748       313948 :       bool long_double_p;
   12749       313948 :       const char *suffix = NULL;
   12750              :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   12751       313948 :       if (DECL_LANGUAGE (decl) == lang_c)
   12752              :         {
   12753            6 :           auto_diagnostic_group d;
   12754            6 :           error_at (location, "literal operator with C linkage");
   12755            6 :           maybe_show_extern_c_location ();
   12756            6 :           return NULL_TREE;
   12757            6 :         }
   12758              : 
   12759       313942 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   12760              :         {
   12761       313936 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   12762              :                                             &long_double_p))
   12763              :             {
   12764           42 :               error_at (location, "%qD has invalid argument list", decl);
   12765           42 :               return NULL_TREE;
   12766              :             }
   12767              : 
   12768       313894 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   12769       313894 :           if (long_long_unsigned_p)
   12770              :             {
   12771        46924 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   12772           68 :                 warning_at (location, 0, "integer suffix %qs"
   12773              :                             " shadowed by implementation", suffix);
   12774              :             }
   12775       266970 :           else if (long_double_p)
   12776              :             {
   12777        85901 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   12778           80 :                 warning_at (location, 0, "floating-point suffix %qs"
   12779              :                             " shadowed by implementation", suffix);
   12780              :             }
   12781              :           /* 17.6.3.3.5  */
   12782       313894 :           if (suffix[0] != '_'
   12783       313287 :               && !current_function_decl && !(friendp && !funcdef_flag))
   12784       313281 :             warning_at (location, OPT_Wliteral_suffix,
   12785              :                         "literal operator suffixes not preceded by %<_%>"
   12786              :                         " are reserved for future standardization");
   12787              :         }
   12788              :       else
   12789              :         {
   12790            6 :           error_at (location, "%qD must be a non-member function", decl);
   12791            6 :           return NULL_TREE;
   12792              :         }
   12793              :     }
   12794              : 
   12795    193281923 :   if (funcdef_flag)
   12796              :     /* Make the init_value nonzero so pushdecl knows this is not
   12797              :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   12798    137357761 :     DECL_INITIAL (decl) = error_mark_node;
   12799              : 
   12800    194541259 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   12801     73615268 :     TREE_NOTHROW (decl) = 1;
   12802              : 
   12803    194541259 :   if (flag_openmp || flag_openmp_simd)
   12804              :     {
   12805              :       /* Adjust "omp declare simd" attributes.  */
   12806       491436 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   12807       491436 :       if (ods)
   12808              :         {
   12809              :           tree attr;
   12810         2081 :           for (attr = ods; attr;
   12811         1102 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   12812              :             {
   12813         1102 :               if (TREE_CODE (type) == METHOD_TYPE)
   12814          204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   12815              :                            DECL_ARGUMENTS (decl), NULL);
   12816         1102 :               if (TREE_VALUE (attr) != NULL_TREE)
   12817              :                 {
   12818          896 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   12819          896 :                   cl = c_omp_declare_simd_clauses_to_numbers
   12820          896 :                                                 (DECL_ARGUMENTS (decl), cl);
   12821          896 :                   if (cl)
   12822          896 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   12823              :                   else
   12824            0 :                     TREE_VALUE (attr) = NULL_TREE;
   12825              :                 }
   12826              :             }
   12827              :         }
   12828              :     }
   12829              : 
   12830              :   /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
   12831              :      have a potentially throwing exception specification.  */
   12832    194541259 :   maybe_diagnose_deallocation_noexcept_false (decl);
   12833              : 
   12834              :   /* Caller will do the rest of this.  */
   12835    194541259 :   if (check < 0)
   12836              :     {
   12837      6774588 :       if (decl && decl != error_mark_node && contract_specifiers)
   12838           24 :         set_fn_contract_specifiers (decl, contract_specifiers);
   12839      6774588 :       return decl;
   12840              :     }
   12841              : 
   12842    187766671 :   if (ctype != NULL_TREE)
   12843    115947513 :     grokclassfn (ctype, decl, flags);
   12844              : 
   12845              :   /* 12.4/3  */
   12846    187766671 :   if (cxx_dialect >= cxx11
   12847    373499134 :       && DECL_DESTRUCTOR_P (decl)
   12848      3309895 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   12849    187934375 :       && !processing_template_decl)
   12850        85560 :     deduce_noexcept_on_destructor (decl);
   12851              : 
   12852    187766671 :   set_originating_module (decl);
   12853              : 
   12854    187766671 :   decl = check_explicit_specialization (orig_declarator, decl,
   12855              :                                         template_count,
   12856    187766671 :                                         2 * funcdef_flag +
   12857    187766671 :                                         4 * (friendp != 0),
   12858              :                                         *attrlist);
   12859    187766671 :   if (decl == error_mark_node)
   12860              :     return NULL_TREE;
   12861              : 
   12862    187766397 :   if (DECL_STATIC_FUNCTION_P (decl))
   12863     10736465 :     check_static_quals (decl, quals);
   12864              : 
   12865    187766397 :   if (attrlist)
   12866              :     {
   12867    187766397 :       cplus_decl_attributes (&decl, *attrlist, 0);
   12868    187766397 :       *attrlist = NULL_TREE;
   12869              :     }
   12870              : 
   12871              :   /* Update now we have a decl and maybe know the return type.  */
   12872    187766397 :   if (contract_specifiers)
   12873              :     {
   12874          912 :       tree t = decl;
   12875          912 :       if (TREE_CODE (decl) == TEMPLATE_DECL)
   12876            7 :         t = DECL_TEMPLATE_RESULT (decl);
   12877          912 :       set_fn_contract_specifiers (t, contract_specifiers);
   12878          912 :       rebuild_postconditions (t);
   12879              :     }
   12880              : 
   12881              :   /* Check main's type after attributes have been applied.  */
   12882    187766397 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12883              :     {
   12884        34002 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   12885              :                         integer_type_node))
   12886              :         {
   12887           19 :           tree dtype = TREE_TYPE (decl);
   12888           19 :           tree oldtypeargs = TYPE_ARG_TYPES (dtype);
   12889           19 :           tree newtype;
   12890           19 :           error_at (declspecs->locations[ds_type_spec],
   12891              :                     "%<::main%> must return %<int%>");
   12892           57 :           newtype = build_function_type (integer_type_node, oldtypeargs,
   12893           19 :                                          TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
   12894           19 :           TREE_TYPE (decl) = newtype;
   12895              :         }
   12896        34002 :       if (warn_main)
   12897        33980 :         check_main_parameter_types (decl);
   12898              :     }
   12899              : 
   12900    187766397 :   if (ctype != NULL_TREE && check)
   12901              :     {
   12902      9227376 :       tree old_decl = check_classfn (ctype, decl,
   12903      9227376 :                                      (current_template_depth
   12904      9227376 :                                       > template_class_depth (ctype))
   12905      2311587 :                                      ? current_template_parms
   12906              :                                      : NULL_TREE);
   12907              : 
   12908      9227376 :       if (old_decl == error_mark_node)
   12909              :         return NULL_TREE;
   12910              : 
   12911      9227268 :       if (old_decl)
   12912              :         {
   12913      8830016 :           tree ok;
   12914      8830016 :           tree pushed_scope;
   12915              : 
   12916      8830016 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   12917              :             /* Because grokfndecl is always supposed to return a
   12918              :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   12919              :                here.  We depend on our callers to figure out that its
   12920              :                really a template that's being returned.  */
   12921      2311575 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   12922              : 
   12923      8830016 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   12924      8830016 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   12925              :             {
   12926              :               /* Remove the `this' parm added by grokclassfn.  */
   12927       178569 :               revert_static_member_fn (decl);
   12928       178569 :               check_static_quals (decl, quals);
   12929              :             }
   12930      8830016 :           if (DECL_ARTIFICIAL (old_decl))
   12931              :             {
   12932            9 :               error ("definition of implicitly-declared %qD", old_decl);
   12933            9 :               return NULL_TREE;
   12934              :             }
   12935      8830007 :           else if (DECL_DEFAULTED_FN (old_decl)
   12936      8830009 :                    && !(initialized == SD_DEFAULTED
   12937            2 :                         && redefinable_import_p (old_decl)))
   12938              :             {
   12939            3 :               auto_diagnostic_group d;
   12940            3 :               error ("definition of explicitly-defaulted %q+D", decl);
   12941            3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   12942              :                       "%q#D explicitly defaulted here", old_decl);
   12943            3 :               return NULL_TREE;
   12944            3 :             }
   12945              : 
   12946      8830004 :           if (modules_p () && !module_may_redeclare (old_decl))
   12947              :             return NULL_TREE;
   12948              : 
   12949              :           /* Since we've smashed OLD_DECL to its
   12950              :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   12951      8829944 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   12952          993 :             decl = DECL_TEMPLATE_RESULT (decl);
   12953              : 
   12954              :           /* Attempt to merge the declarations.  This can fail, in
   12955              :              the case of some invalid specialization declarations.  */
   12956      8829944 :           pushed_scope = push_scope (ctype);
   12957      8829944 :           ok = duplicate_decls (decl, old_decl);
   12958      8829944 :           if (pushed_scope)
   12959      8829944 :             pop_scope (pushed_scope);
   12960      8829944 :           if (!ok)
   12961              :             {
   12962            0 :               error ("no %q#D member function declared in class %qT",
   12963              :                      decl, ctype);
   12964            0 :               return NULL_TREE;
   12965              :             }
   12966      8829944 :           if (ok == error_mark_node)
   12967              :             return NULL_TREE;
   12968      8829920 :           return old_decl;
   12969              :         }
   12970              :     }
   12971              : 
   12972    357872546 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   12973              :     return NULL_TREE;
   12974              : 
   12975    178936270 :   if (ctype == NULL_TREE || check)
   12976     72216205 :     return decl;
   12977              : 
   12978    106720065 :   if (virtualp)
   12979      4195728 :     DECL_VIRTUAL_P (decl) = 1;
   12980              : 
   12981    106720065 :   return decl;
   12982              : }
   12983              : 
   12984              : /* decl is a FUNCTION_DECL.
   12985              :    specifiers are the parsed virt-specifiers.
   12986              : 
   12987              :    Set flags to reflect the virt-specifiers.
   12988              : 
   12989              :    Returns decl.  */
   12990              : 
   12991              : static tree
   12992    113494750 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   12993              : {
   12994    113494750 :   if (decl == NULL_TREE)
   12995              :     return decl;
   12996    113494653 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   12997       392077 :     DECL_OVERRIDE_P (decl) = 1;
   12998    113494653 :   if (specifiers & VIRT_SPEC_FINAL)
   12999         9943 :     DECL_FINAL_P (decl) = 1;
   13000              :   return decl;
   13001              : }
   13002              : 
   13003              : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   13004              :    the linkage that DECL will receive in the object file.  */
   13005              : 
   13006              : static void
   13007     13971120 : set_linkage_for_static_data_member (tree decl)
   13008              : {
   13009              :   /* A static data member always has static storage duration and
   13010              :      external linkage.  Note that static data members are forbidden in
   13011              :      local classes -- the only situation in which a class has
   13012              :      non-external linkage.  */
   13013     13971120 :   TREE_PUBLIC (decl) = 1;
   13014     13971120 :   TREE_STATIC (decl) = 1;
   13015              :   /* For non-template classes, static data members are always put
   13016              :      out in exactly those files where they are defined, just as
   13017              :      with ordinary namespace-scope variables.  */
   13018     13971120 :   if (!processing_template_decl)
   13019     10641790 :     DECL_INTERFACE_KNOWN (decl) = 1;
   13020     13971120 : }
   13021              : 
   13022              : /* Create a VAR_DECL named NAME with the indicated TYPE.
   13023              : 
   13024              :    If SCOPE is non-NULL, it is the class type or namespace containing
   13025              :    the variable.  If SCOPE is NULL, the variable should is created in
   13026              :    the innermost enclosing scope.  */
   13027              : 
   13028              : static tree
   13029     70951372 : grokvardecl (tree type,
   13030              :              tree name,
   13031              :              tree orig_declarator,
   13032              :              const cp_decl_specifier_seq *declspecs,
   13033              :              int initialized,
   13034              :              int type_quals,
   13035              :              int inlinep,
   13036              :              bool conceptp,
   13037              :              int template_count,
   13038              :              tree scope,
   13039              :              location_t location)
   13040              : {
   13041     70951372 :   tree decl;
   13042     70951372 :   tree explicit_scope;
   13043              : 
   13044     70951372 :   gcc_assert (!name || identifier_p (name));
   13045              : 
   13046     70951372 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   13047     70951372 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   13048              : 
   13049              :   /* Compute the scope in which to place the variable, but remember
   13050              :      whether or not that scope was explicitly specified by the user.   */
   13051     70951372 :   explicit_scope = scope;
   13052     70951372 :   if (!scope)
   13053              :     {
   13054              :       /* An explicit "extern" specifier indicates a namespace-scope
   13055              :          variable.  */
   13056     70427157 :       if (declspecs->storage_class == sc_extern)
   13057       556980 :         scope = current_decl_namespace ();
   13058     69870177 :       else if (!at_function_scope_p ())
   13059      7405105 :         scope = current_scope ();
   13060              :     }
   13061              : 
   13062     70427157 :   if (scope
   13063      8486300 :       && (/* If the variable is a namespace-scope variable declared in a
   13064              :              template, we need DECL_LANG_SPECIFIC.  */
   13065      8486300 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   13066              :           /* Similarly for namespace-scope variables with language linkage
   13067              :              other than C++.  */
   13068      7978421 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   13069      4582361 :               && current_lang_name != lang_name_cplusplus)
   13070              :           /* Similarly for static data members.  */
   13071      4853862 :           || TYPE_P (scope)
   13072              :           /* Similarly for explicit specializations.  */
   13073      4345983 :           || (orig_declarator
   13074      4345133 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   13075      5077328 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   13076              :   else
   13077     65874044 :     decl = build_decl (location, VAR_DECL, name, type);
   13078              : 
   13079     70951372 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   13080        16336 :     set_decl_namespace (decl, explicit_scope, 0);
   13081              :   else
   13082     70935036 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   13083              : 
   13084     70951372 :   if (declspecs->storage_class == sc_extern)
   13085              :     {
   13086       556980 :       DECL_THIS_EXTERN (decl) = 1;
   13087       556980 :       DECL_EXTERNAL (decl) = !initialized;
   13088              :     }
   13089              : 
   13090     70951372 :   if (DECL_CLASS_SCOPE_P (decl))
   13091              :     {
   13092       507879 :       set_linkage_for_static_data_member (decl);
   13093              :       /* This function is only called with out-of-class definitions.  */
   13094       507879 :       DECL_EXTERNAL (decl) = 0;
   13095       507879 :       check_class_member_definition_namespace (decl);
   13096              :     }
   13097              :   /* At top level, either `static' or no s.c. makes a definition
   13098              :      (perhaps tentative), and absence of `static' makes it public.  */
   13099     70443493 :   else if (toplevel_bindings_p ())
   13100              :     {
   13101     15954514 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   13102      7977257 :                             && (DECL_THIS_EXTERN (decl)
   13103      7382100 :                                 || ! constp
   13104      7382100 :                                 || volatilep
   13105      7302452 :                                 || inlinep
   13106       599111 :                                 || in_template_context
   13107        31777 :                                 || processing_specialization
   13108        31694 :                                 || module_attach_p ()));
   13109      7977257 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   13110              :     }
   13111              :   /* Not at top level, only `static' makes a static definition.  */
   13112              :   else
   13113              :     {
   13114     62466236 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   13115     62466236 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   13116              :     }
   13117              : 
   13118     70951372 :   set_originating_module (decl);
   13119              : 
   13120     70951372 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   13121              :     {
   13122        20101 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   13123              :         {
   13124        20093 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   13125              :           // NB: Set a tentative TLS model to avoid tls_model attribute
   13126              :           // warnings due to lack of thread storage duration.  It will
   13127              :           // be updated by cplus_decl_attributes later.
   13128        20093 :           if (!processing_template_decl)
   13129        19968 :             set_decl_tls_model (decl, TLS_MODEL_REAL);
   13130              :         }
   13131        20101 :       if (declspecs->gnu_thread_keyword_p)
   13132        19082 :         SET_DECL_GNU_TLS_P (decl);
   13133              :     }
   13134              : 
   13135              :   /* If the type of the decl has no linkage, make sure that we'll
   13136              :      notice that in mark_used.  */
   13137     70951372 :   if (cxx_dialect > cxx98
   13138     70683926 :       && decl_linkage (decl) != lk_none
   13139     69961943 :       && DECL_LANG_SPECIFIC (decl) == NULL
   13140     64803548 :       && !DECL_EXTERN_C_P (decl)
   13141    135754920 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   13142         4739 :     retrofit_lang_decl (decl);
   13143              : 
   13144     70951372 :   if (TREE_PUBLIC (decl))
   13145              :     {
   13146              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   13147              :          or enumeration declared in a local scope) shall not be used to
   13148              :          declare an entity with linkage.
   13149              : 
   13150              :          DR 757 relaxes this restriction for C++0x.  */
   13151      8415273 :       if (cxx_dialect < cxx11)
   13152        22027 :         no_linkage_error (decl);
   13153              :     }
   13154              :   else
   13155     62536099 :     DECL_INTERFACE_KNOWN (decl) = 1;
   13156              : 
   13157     70951372 :   if (DECL_NAME (decl)
   13158     70951372 :       && MAIN_NAME_P (DECL_NAME (decl)))
   13159              :     {
   13160           12 :       if (scope == global_namespace)
   13161            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13162              :                   "cannot declare %<::main%> to be a global variable");
   13163            6 :       else if (DECL_EXTERN_C_P (decl))
   13164            3 :         error_at (DECL_SOURCE_LOCATION (decl),
   13165              :                   "an entity named %<main%> cannot be declared with "
   13166              :                   "C language linkage");
   13167              :     }
   13168              : 
   13169              :   /* Check if a variable is being declared as a concept.  */
   13170     70951372 :   if (conceptp)
   13171              :     {
   13172           30 :       if (!processing_template_decl)
   13173           13 :         error_at (declspecs->locations[ds_concept],
   13174              :                   "a non-template variable cannot be %<concept%>");
   13175           17 :       else if (!at_namespace_scope_p ())
   13176            2 :         error_at (declspecs->locations[ds_concept],
   13177              :                   "concept must be defined at namespace scope");
   13178              :       else
   13179           15 :         error_at (declspecs->locations[ds_concept],
   13180              :                   "variable concepts are no longer supported");
   13181              :       return NULL_TREE;
   13182              :     }
   13183     70951342 :   else if (flag_concepts
   13184     70951342 :            && current_template_depth > template_class_depth (scope))
   13185              :     {
   13186     61130578 :       tree ci = current_template_constraints ();
   13187     61130578 :       set_constraints (decl, ci);
   13188              :     }
   13189              : 
   13190              :   // Handle explicit specializations and instantiations of variable templates.
   13191     70951342 :   if (orig_declarator)
   13192     70221893 :     decl = check_explicit_specialization (orig_declarator, decl,
   13193              :                                           template_count, 0);
   13194              : 
   13195     70951342 :   return decl != error_mark_node ? decl : NULL_TREE;
   13196              : }
   13197              : 
   13198              : /* Create and return a canonical pointer to member function type, for
   13199              :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   13200              : 
   13201              : tree
   13202      3120904 : build_ptrmemfunc_type (tree type)
   13203              : {
   13204      3120904 :   tree field, fields;
   13205      3120904 :   tree t;
   13206              : 
   13207      3120904 :   if (type == error_mark_node)
   13208              :     return type;
   13209              : 
   13210              :   /* Make sure that we always have the unqualified pointer-to-member
   13211              :      type first.  */
   13212      3120904 :   if (cp_cv_quals quals = cp_type_quals (type))
   13213              :     {
   13214            0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   13215            0 :       return cp_build_qualified_type (unqual, quals);
   13216              :     }
   13217              : 
   13218              :   /* If a canonical type already exists for this type, use it.  We use
   13219              :      this method instead of type_hash_canon, because it only does a
   13220              :      simple equality check on the list of field members.  */
   13221              : 
   13222      3120904 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   13223      3120904 :   if (t)
   13224              :     return t;
   13225              : 
   13226      1042274 :   t = make_node (RECORD_TYPE);
   13227              : 
   13228              :   /* Let the front end know this is a pointer to member function.  */
   13229      1042274 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   13230              : 
   13231      1042274 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   13232      1042274 :   DECL_NONADDRESSABLE_P (field) = 1;
   13233      1042274 :   fields = field;
   13234              : 
   13235      1042274 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   13236              :                       delta_type_node);
   13237      1042274 :   DECL_NONADDRESSABLE_P (field) = 1;
   13238      1042274 :   DECL_CHAIN (field) = fields;
   13239      1042274 :   fields = field;
   13240              : 
   13241      1042274 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   13242              : 
   13243              :   /* Zap out the name so that the back end will give us the debugging
   13244              :      information for this anonymous RECORD_TYPE.  */
   13245      1042274 :   TYPE_NAME (t) = NULL_TREE;
   13246              : 
   13247              :   /* Cache this pointer-to-member type so that we can find it again
   13248              :      later.  */
   13249      1042274 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   13250              : 
   13251      1042274 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   13252       519880 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   13253       522394 :   else if (TYPE_CANONICAL (type) != type)
   13254       330846 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   13255              : 
   13256              :   return t;
   13257              : }
   13258              : 
   13259              : /* Create and return a pointer to data member type.  */
   13260              : 
   13261              : tree
   13262       332596 : build_ptrmem_type (tree class_type, tree member_type)
   13263              : {
   13264       332596 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   13265              :     {
   13266        60401 :       cp_cv_quals quals = type_memfn_quals (member_type);
   13267        60401 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   13268        60401 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   13269        60401 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   13270              :     }
   13271              :   else
   13272              :     {
   13273       272195 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   13274       272195 :       return build_offset_type (class_type, member_type);
   13275              :     }
   13276              : }
   13277              : 
   13278              : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   13279              :    Check to see that the definition is valid.  Issue appropriate error
   13280              :    messages.  */
   13281              : 
   13282              : static void
   13283     19043286 : check_static_variable_definition (tree decl, tree type)
   13284              : {
   13285              :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   13286     19043286 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   13287              :     ;
   13288              :   /* Can't check yet if we don't know the type.  */
   13289     17683634 :   else if (dependent_type_p (type))
   13290              :     ;
   13291              :   /* If DECL is declared constexpr, we'll do the appropriate checks
   13292              :      in check_initializer.  Similarly for inline static data members.  */
   13293     17137214 :   else if (DECL_P (decl)
   13294     17137214 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   13295      2735722 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   13296              :     ;
   13297      2735139 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13298              :     {
   13299           60 :       if (!COMPLETE_TYPE_P (type))
   13300           11 :         error_at (DECL_SOURCE_LOCATION (decl),
   13301              :                   "in-class initialization of static data member %q#D of "
   13302              :                   "incomplete type", decl);
   13303           49 :       else if (literal_type_p (type))
   13304           43 :         permerror (DECL_SOURCE_LOCATION (decl),
   13305              :                    "%<constexpr%> needed for in-class initialization of "
   13306              :                    "static data member %q#D of non-integral type", decl);
   13307              :       else
   13308            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13309              :                   "in-class initialization of static data member %q#D of "
   13310              :                   "non-literal type", decl);
   13311              :     }
   13312              :   /* Motion 10 at San Diego: If a static const integral data member is
   13313              :      initialized with an integral constant expression, the initializer
   13314              :      may appear either in the declaration (within the class), or in
   13315              :      the definition, but not both.  If it appears in the class, the
   13316              :      member is a member constant.  The file-scope definition is always
   13317              :      required.  */
   13318      2735079 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   13319           11 :     error_at (DECL_SOURCE_LOCATION (decl),
   13320              :               "invalid in-class initialization of static data member "
   13321              :               "of non-integral type %qT",
   13322              :               type);
   13323      2735068 :   else if (!CP_TYPE_CONST_P (type))
   13324            5 :     error_at (DECL_SOURCE_LOCATION (decl),
   13325              :               "ISO C++ forbids in-class initialization of non-const "
   13326              :               "static member %qD",
   13327              :               decl);
   13328      2735063 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13329            5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   13330              :              "ISO C++ forbids initialization of member constant "
   13331              :              "%qD of non-integral type %qT", decl, type);
   13332     19043286 : }
   13333              : 
   13334              : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   13335              :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   13336              :    expressions out into temporary variables so that walk_tree doesn't
   13337              :    step into them (c++/15764).  */
   13338              : 
   13339              : static tree
   13340         3406 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   13341              : {
   13342         3406 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   13343         3406 :   tree expr = *expr_p;
   13344         3406 :   if (TREE_CODE (expr) == SAVE_EXPR)
   13345              :     {
   13346         1484 :       tree op = TREE_OPERAND (expr, 0);
   13347         1484 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   13348         1484 :       if (TREE_SIDE_EFFECTS (op))
   13349           56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   13350         1484 :       *walk_subtrees = 0;
   13351              :     }
   13352         1922 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   13353         1747 :     *walk_subtrees = 0;
   13354         3406 :   return NULL;
   13355              : }
   13356              : 
   13357              : /* Entry point for the above.  */
   13358              : 
   13359              : static void
   13360         1543 : stabilize_vla_size (tree size)
   13361              : {
   13362         1543 :   hash_set<tree> pset;
   13363              :   /* Break out any function calls into temporary variables.  */
   13364         1543 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   13365         1543 : }
   13366              : 
   13367              : /* Reduce a SIZEOF_EXPR to its value.  */
   13368              : 
   13369              : tree
   13370     13299548 : fold_sizeof_expr (tree t)
   13371              : {
   13372     13299548 :   tree r;
   13373     13299548 :   if (SIZEOF_EXPR_TYPE_P (t))
   13374     12682415 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13375     12682415 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   13376              :                                     SIZEOF_EXPR, false, false);
   13377       617133 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   13378            0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13379            0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13380              :                                     false, false);
   13381              :   else
   13382       617133 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   13383       617133 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13384              :                                     false, false);
   13385     13299548 :   if (r == error_mark_node)
   13386           94 :     r = size_one_node;
   13387     13299548 :   r = cp_fold_convert (size_type_node, r);
   13388     13299548 :   return r;
   13389              : }
   13390              : 
   13391              : /* Given the SIZE (i.e., number of elements) in an array, compute
   13392              :    an appropriate index type for the array.  If non-NULL, NAME is
   13393              :    the name of the entity being declared.  */
   13394              : 
   13395              : static tree
   13396      3507852 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   13397              :                               tsubst_flags_t complain)
   13398              : {
   13399      3507852 :   if (error_operand_p (size))
   13400           32 :     return error_mark_node;
   13401              : 
   13402              :   /* The type of the index being computed.  */
   13403      3507820 :   tree itype;
   13404              : 
   13405              :   /* The original numeric size as seen in the source code before
   13406              :      conversion to size_t.  */
   13407      3507820 :   tree origsize = size;
   13408              : 
   13409      3507820 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   13410              : 
   13411      3507820 :   if (!type_dependent_expression_p (size))
   13412              :     {
   13413      3458504 :       origsize = size = mark_rvalue_use (size);
   13414              : 
   13415        35214 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   13416      3458665 :           && TREE_SIDE_EFFECTS (size))
   13417              :         /* In C++98, we mark a non-constant array bound with a magic
   13418              :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   13419              :       else
   13420              :         {
   13421      3458503 :           size = build_converted_constant_expr (size_type_node, size, complain);
   13422              :           /* Pedantically a constant expression is required here and so
   13423              :              __builtin_is_constant_evaluated () should fold to true if it
   13424              :              is successfully folded into a constant.  */
   13425      3458503 :           size = fold_non_dependent_expr (size, complain,
   13426              :                                           /*manifestly_const_eval=*/true);
   13427              : 
   13428      3458503 :           if (!TREE_CONSTANT (size))
   13429       147620 :             size = origsize;
   13430              :         }
   13431              : 
   13432      3458504 :       if (error_operand_p (size))
   13433            3 :         return error_mark_node;
   13434              : 
   13435              :       /* The array bound must be an integer type.  */
   13436      3458501 :       tree type = TREE_TYPE (size);
   13437      3458501 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   13438              :         {
   13439           21 :           if (!(complain & tf_error))
   13440            0 :             return error_mark_node;
   13441           21 :           if (name)
   13442           18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   13443              :                       name, type);
   13444              :           else
   13445            3 :             error_at (loc, "size of array has non-integral type %qT", type);
   13446           21 :           size = integer_one_node;
   13447              :         }
   13448              :     }
   13449              : 
   13450              :   /* A type is dependent if it is...an array type constructed from any
   13451              :      dependent type or whose size is specified by a constant expression
   13452              :      that is value-dependent.  */
   13453              :   /* We can only call value_dependent_expression_p on integral constant
   13454              :      expressions.  */
   13455      3507817 :   if (processing_template_decl
   13456      1610522 :       && potential_constant_expression (size)
   13457      5118314 :       && value_dependent_expression_p (size))
   13458              :     {
   13459              :       /* Just build the index type and mark that it requires
   13460              :          structural equality checks.  */
   13461       901745 :     in_template:
   13462       901745 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   13463              :                                            size, size_one_node));
   13464       901745 :       TYPE_DEPENDENT_P (itype) = 1;
   13465       901745 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   13466       901745 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   13467       901745 :       return itype;
   13468              :     }
   13469              : 
   13470      2623088 :   if (TREE_CODE (size) != INTEGER_CST)
   13471              :     {
   13472        19131 :       tree folded = cp_fully_fold (size);
   13473        19131 :       if (TREE_CODE (folded) == INTEGER_CST)
   13474              :         {
   13475          208 :           if (name)
   13476          134 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   13477              :                      "integral constant-expression", name);
   13478              :           else
   13479           74 :             pedwarn (loc, OPT_Wpedantic,
   13480              :                      "size of array is not an integral constant-expression");
   13481              :         }
   13482        19131 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   13483              :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   13484              :            folding a conversion from a pointer to integral type.  In that
   13485              :            case issue an error below and don't treat this as a VLA.  */;
   13486              :       else
   13487              :         /* Use the folded result for VLAs, too; it will have resolved
   13488              :            SIZEOF_EXPR.  */
   13489              :         size = folded;
   13490              :     }
   13491              : 
   13492              :   /* Normally, the array-bound will be a constant.  */
   13493      2623088 :   if (TREE_CODE (size) == INTEGER_CST)
   13494              :     {
   13495              :       /* The size to use in diagnostics that reflects the constant
   13496              :          size used in the source, rather than SIZE massaged above.  */
   13497      2604165 :       tree diagsize = size;
   13498              : 
   13499              :       /* If the original size before conversion to size_t was signed
   13500              :          and negative, convert it to ssizetype to restore the sign.  */
   13501      2604165 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   13502              :           && TREE_CODE (size) == INTEGER_CST
   13503      2604165 :           && tree_int_cst_sign_bit (size))
   13504              :         {
   13505          227 :           diagsize = fold_convert (ssizetype, size);
   13506              : 
   13507              :           /* Clear the overflow bit that may have been set as a result
   13508              :              of the conversion from the sizetype of the new size to
   13509              :              ssizetype.  */
   13510          227 :           TREE_OVERFLOW (diagsize) = false;
   13511              :         }
   13512              : 
   13513              :       /* Verify that the array has a positive number of elements
   13514              :          and issue the appropriate diagnostic if it doesn't.  */
   13515      2604165 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   13516              :         {
   13517          458 :           if (!(complain & tf_error))
   13518           15 :             return error_mark_node;
   13519          443 :           size = integer_one_node;
   13520              :         }
   13521              :       /* As an extension we allow zero-sized arrays.  */
   13522      2603707 :       else if (integer_zerop (size))
   13523              :         {
   13524         3190 :           if (!(complain & tf_error))
   13525              :             /* We must fail if performing argument deduction (as
   13526              :                indicated by the state of complain), so that
   13527              :                another substitution can be found.  */
   13528            8 :             return error_mark_node;
   13529         3182 :           else if (name)
   13530         2887 :             pedwarn (loc, OPT_Wpedantic,
   13531              :                      "ISO C++ forbids zero-size array %qD", name);
   13532              :           else
   13533          295 :             pedwarn (loc, OPT_Wpedantic,
   13534              :                      "ISO C++ forbids zero-size array");
   13535              :         }
   13536              :     }
   13537        18923 :   else if (TREE_CONSTANT (size)
   13538              :            /* We don't allow VLAs at non-function scopes, or during
   13539              :               tentative template substitution.  */
   13540        18908 :            || !at_function_scope_p ()
   13541        37488 :            || !(complain & tf_error))
   13542              :     {
   13543          364 :       if (!(complain & tf_error))
   13544          313 :         return error_mark_node;
   13545              :       /* `(int) &fn' is not a valid array bound.  */
   13546           51 :       if (name)
   13547           37 :         error_at (loc,
   13548              :                   "size of array %qD is not an integral constant-expression",
   13549              :                   name);
   13550              :       else
   13551           14 :         error_at (loc, "size of array is not an integral constant-expression");
   13552           51 :       size = integer_one_node;
   13553              :     }
   13554        18559 :   else if (pedantic && warn_vla != 0)
   13555              :     {
   13556           30 :       if (name)
   13557           15 :         pedwarn (name_loc, OPT_Wvla,
   13558              :                  "ISO C++ forbids variable length array %qD", name);
   13559              :       else
   13560           15 :         pedwarn (input_location, OPT_Wvla,
   13561              :                  "ISO C++ forbids variable length array");
   13562              :     }
   13563        18529 :   else if (warn_vla > 0)
   13564              :     {
   13565            3 :       if (name)
   13566            3 :         warning_at (name_loc, OPT_Wvla,
   13567              :                     "variable length array %qD is used", name);
   13568              :       else
   13569            0 :         warning (OPT_Wvla,
   13570              :                  "variable length array is used");
   13571              :     }
   13572              : 
   13573      2622752 :   if (processing_template_decl && !TREE_CONSTANT (size))
   13574        17016 :     goto in_template;
   13575              :   else
   13576              :     {
   13577      2605736 :       if (!TREE_CONSTANT (size))
   13578              :         {
   13579              :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   13580              :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   13581              :              that happens when building TYPE_SIZE.  */
   13582         1543 :           size = variable_size (size);
   13583         1543 :           stabilize_vla_size (size);
   13584              :         }
   13585              : 
   13586              :       /* Compute the index of the largest element in the array.  It is
   13587              :          one less than the number of elements in the array.  We save
   13588              :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   13589              :          cp_build_binary_op will be appropriately folded.  */
   13590      2605736 :       {
   13591      2605736 :         processing_template_decl_sentinel s;
   13592      2605736 :         itype = cp_build_binary_op (input_location,
   13593              :                                     MINUS_EXPR,
   13594              :                                     cp_convert (ssizetype, size, complain),
   13595              :                                     cp_convert (ssizetype, integer_one_node,
   13596              :                                                 complain),
   13597              :                                     complain);
   13598      2605736 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   13599      2605736 :       }
   13600              : 
   13601      2605736 :       if (!TREE_CONSTANT (itype))
   13602              :         {
   13603         1543 :           if (sanitize_flags_p (SANITIZE_VLA)
   13604         1543 :               && current_function_decl != NULL_TREE)
   13605              :             {
   13606              :               /* We have to add 1 -- in the ubsan routine we generate
   13607              :                  LE_EXPR rather than LT_EXPR.  */
   13608           78 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   13609              :                                     build_one_cst (TREE_TYPE (itype)));
   13610           78 :               t = ubsan_instrument_vla (input_location, t);
   13611           78 :               finish_expr_stmt (t);
   13612              :             }
   13613              :         }
   13614              :       /* Make sure that there was no overflow when creating to a signed
   13615              :          index type.  (For example, on a 32-bit machine, an array with
   13616              :          size 2^32 - 1 is too big.)  */
   13617      2604193 :       else if (TREE_CODE (itype) == INTEGER_CST
   13618      2604193 :                && TREE_OVERFLOW (itype))
   13619              :         {
   13620            0 :           if (!(complain & tf_error))
   13621            0 :             return error_mark_node;
   13622            0 :           error ("overflow in array dimension");
   13623            0 :           TREE_OVERFLOW (itype) = 0;
   13624              :         }
   13625              :     }
   13626              : 
   13627              :   /* Create and return the appropriate index type.  */
   13628      2605736 :   itype = build_index_type (itype);
   13629              : 
   13630              :   /* If the index type were dependent, we would have returned early, so
   13631              :      remember that it isn't.  */
   13632      2605736 :   TYPE_DEPENDENT_P (itype) = 0;
   13633      2605736 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   13634      2605736 :   return itype;
   13635              : }
   13636              : 
   13637              : tree
   13638       618593 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   13639              : {
   13640       618593 :   return compute_array_index_type_loc (input_location, name, size, complain);
   13641              : }
   13642              : 
   13643              : /* Returns the scope (if any) in which the entity declared by
   13644              :    DECLARATOR will be located.  If the entity was declared with an
   13645              :    unqualified name, NULL_TREE is returned.  */
   13646              : 
   13647              : tree
   13648    776234811 : get_scope_of_declarator (const cp_declarator *declarator)
   13649              : {
   13650    899448064 :   while (declarator && declarator->kind != cdk_id)
   13651    123213253 :     declarator = declarator->declarator;
   13652              : 
   13653              :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   13654              :      declaration occurs is the first operand.  */
   13655    776234811 :   if (declarator
   13656    774969226 :       && declarator->u.id.qualifying_scope)
   13657              :     return declarator->u.id.qualifying_scope;
   13658              : 
   13659              :   /* Otherwise, the declarator is not a qualified name; the entity will
   13660              :      be declared in the current scope.  */
   13661              :   return NULL_TREE;
   13662              : }
   13663              : 
   13664              : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   13665              :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   13666              :    with this type.  */
   13667              : 
   13668              : static tree
   13669      3714607 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   13670              : {
   13671      3714607 :   tree itype = NULL_TREE;
   13672              : 
   13673              :   /* If things have already gone awry, bail now.  */
   13674      3714607 :   if (type == error_mark_node || size == error_mark_node)
   13675              :     return error_mark_node;
   13676              : 
   13677              :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   13678              :      for a deduced class type.  */
   13679      3714544 :   if (template_placeholder_p (type))
   13680              :     {
   13681            6 :       if (name)
   13682            0 :         error_at (loc, "%qD declared as array of template placeholder "
   13683              :                   "type %qT", name, type);
   13684              :       else
   13685            6 :         error ("creating array of template placeholder type %qT", type);
   13686            6 :       return error_mark_node;
   13687              :     }
   13688              : 
   13689              :   /* If there are some types which cannot be array elements,
   13690              :      issue an error-message and return.  */
   13691      3714538 :   switch (TREE_CODE (type))
   13692              :     {
   13693            3 :     case VOID_TYPE:
   13694            3 :       if (name)
   13695            0 :         error_at (loc, "declaration of %qD as array of void", name);
   13696              :       else
   13697            3 :         error ("creating array of void");
   13698            3 :       return error_mark_node;
   13699              : 
   13700            6 :     case FUNCTION_TYPE:
   13701            6 :       if (name)
   13702            6 :         error_at (loc, "declaration of %qD as array of functions", name);
   13703              :       else
   13704            0 :         error ("creating array of functions");
   13705            6 :       return error_mark_node;
   13706              : 
   13707           21 :     case REFERENCE_TYPE:
   13708           21 :       if (name)
   13709           15 :         error_at (loc, "declaration of %qD as array of references", name);
   13710              :       else
   13711            6 :         error ("creating array of references");
   13712           21 :       return error_mark_node;
   13713              : 
   13714            0 :     case METHOD_TYPE:
   13715            0 :       if (name)
   13716            0 :         error_at (loc, "declaration of %qD as array of function members",
   13717              :                   name);
   13718              :       else
   13719            0 :         error ("creating array of function members");
   13720            0 :       return error_mark_node;
   13721              : 
   13722      3714508 :     default:
   13723      3714508 :       break;
   13724              :     }
   13725              : 
   13726      3714508 :   if (!verify_type_context (name ? loc : input_location,
   13727              :                             TCTX_ARRAY_ELEMENT, type))
   13728            0 :     return error_mark_node;
   13729              : 
   13730              :   /* [dcl.array]
   13731              : 
   13732              :      The constant expressions that specify the bounds of the arrays
   13733              :      can be omitted only for the first member of the sequence.  */
   13734      3714508 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   13735              :     {
   13736           30 :       if (name)
   13737           24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   13738              :                   "have bounds for all dimensions except the first",
   13739              :                   name);
   13740              :       else
   13741            6 :         error ("multidimensional array must have bounds for all "
   13742              :                "dimensions except the first");
   13743              : 
   13744           30 :       return error_mark_node;
   13745              :     }
   13746              : 
   13747              :   /* Figure out the index type for the array.  */
   13748      3714478 :   if (size)
   13749              :     {
   13750      2889259 :       itype = compute_array_index_type_loc (loc, name, size,
   13751              :                                             tf_warning_or_error);
   13752      2889259 :       if (type_uses_auto (type)
   13753      2889259 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   13754              :         {
   13755            9 :           sorry_at (loc, "variable-length array of %<auto%>");
   13756            9 :           return error_mark_node;
   13757              :         }
   13758              :     }
   13759              : 
   13760      3714469 :   return build_cplus_array_type (type, itype);
   13761              : }
   13762              : 
   13763              : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   13764              : 
   13765              : static location_t
   13766   1077131605 : min_location (location_t loca, location_t locb)
   13767              : {
   13768   1077131605 :   if (loca == UNKNOWN_LOCATION
   13769   1077131605 :       || (locb != UNKNOWN_LOCATION
   13770    112527015 :           && linemap_location_before_p (line_table, locb, loca)))
   13771    965845481 :     return locb;
   13772              :   return loca;
   13773              : }
   13774              : 
   13775              : /* Returns the smallest location != UNKNOWN_LOCATION among the
   13776              :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   13777              :    and LOCATIONS[ds_restrict].  */
   13778              : 
   13779              : static location_t
   13780   1075342904 : smallest_type_quals_location (int type_quals, const location_t* locations)
   13781              : {
   13782   1075342904 :   location_t loc = UNKNOWN_LOCATION;
   13783              : 
   13784   1075342904 :   if (type_quals & TYPE_QUAL_CONST)
   13785    110994272 :     loc = locations[ds_const];
   13786              : 
   13787   1075342904 :   if (type_quals & TYPE_QUAL_VOLATILE)
   13788      1788610 :     loc = min_location (loc, locations[ds_volatile]);
   13789              : 
   13790   1075342904 :   if (type_quals & TYPE_QUAL_RESTRICT)
   13791           43 :     loc = min_location (loc, locations[ds_restrict]);
   13792              : 
   13793   1075342904 :   return loc;
   13794              : }
   13795              : 
   13796              : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   13797              : 
   13798              : static location_t
   13799   1075342883 : smallest_type_location (int type_quals, const location_t* locations)
   13800              : {
   13801   1075342883 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   13802   1075342883 :   return min_location (loc, locations[ds_type_spec]);
   13803              : }
   13804              : 
   13805              : static location_t
   13806           26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   13807              : {
   13808           26 :   int type_quals = get_type_quals (declspecs);
   13809           26 :   return smallest_type_location (type_quals, declspecs->locations);
   13810              : }
   13811              : 
   13812              : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   13813              :    strip out the pointer/reference declarator(s).  */
   13814              : 
   13815              : static bool
   13816     30584791 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   13817              : {
   13818     30584791 :   bool indirect_ref_p = false;
   13819     61169729 :   while (declarator && *declarator
   13820     30584938 :          && ((*declarator)->kind == cdk_pointer
   13821     30584938 :              || (*declarator)->kind == cdk_reference))
   13822              :     {
   13823          147 :       indirect_ref_p = true;
   13824          147 :       *declarator = (*declarator)->declarator;
   13825              :     }
   13826     30584791 :   return indirect_ref_p;
   13827              : }
   13828              : 
   13829              : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   13830              :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   13831              :    this function is.  OPTYPE is the type given in a conversion operator
   13832              :    declaration, or the class type for a constructor/destructor.
   13833              :    Returns the actual return type of the function; that may be different
   13834              :    than TYPE if an error occurs, or for certain special functions.  */
   13835              : 
   13836              : static tree
   13837     30584791 : check_special_function_return_type (special_function_kind sfk,
   13838              :                                     tree type,
   13839              :                                     tree optype,
   13840              :                                     int type_quals,
   13841              :                                     const cp_declarator** declarator,
   13842              :                                     const location_t* locations)
   13843              : {
   13844     30584791 :   gcc_assert (declarator);
   13845     30584791 :   location_t rettype_loc = (type
   13846     30584791 :                             ? smallest_type_location (type_quals, locations)
   13847     30584710 :                             : (*declarator)->id_loc);
   13848     30584791 :   switch (sfk)
   13849              :     {
   13850     24945260 :     case sfk_constructor:
   13851     24945260 :       if (maybe_strip_indirect_ref (declarator) || type)
   13852           81 :         error_at (rettype_loc,
   13853              :                   "return type specification for constructor invalid");
   13854     24945179 :       else if (type_quals != TYPE_UNQUALIFIED)
   13855           15 :         error_at (smallest_type_quals_location (type_quals, locations),
   13856              :                   "qualifiers are not allowed on constructor declaration");
   13857              : 
   13858     24945260 :       if (targetm.cxx.cdtor_returns_this ())
   13859            0 :         type = build_pointer_type (optype);
   13860              :       else
   13861     24945260 :         type = void_type_node;
   13862              :       break;
   13863              : 
   13864      3328352 :     case sfk_destructor:
   13865      3328352 :       if (maybe_strip_indirect_ref (declarator) || type)
   13866           45 :         error_at (rettype_loc,
   13867              :                   "return type specification for destructor invalid");
   13868      3328307 :       else if (type_quals != TYPE_UNQUALIFIED)
   13869            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13870              :                   "qualifiers are not allowed on destructor declaration");
   13871              : 
   13872              :       /* We can't use the proper return type here because we run into
   13873              :          problems with ambiguous bases and covariant returns.  */
   13874      3328352 :       if (targetm.cxx.cdtor_returns_this ())
   13875            0 :         type = build_pointer_type (void_type_node);
   13876              :       else
   13877      3328352 :         type = void_type_node;
   13878              :       break;
   13879              : 
   13880      1051831 :     case sfk_conversion:
   13881      1051831 :       if (maybe_strip_indirect_ref (declarator) || type)
   13882           42 :         error_at (rettype_loc,
   13883              :                   "return type specified for %<operator %T%>", optype);
   13884      1051789 :       else if (type_quals != TYPE_UNQUALIFIED)
   13885            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13886              :                   "qualifiers are not allowed on declaration of "
   13887              :                   "%<operator %T%>", optype);
   13888              : 
   13889              :       type = optype;
   13890              :       break;
   13891              : 
   13892      1259348 :     case sfk_deduction_guide:
   13893      1259348 :       if (maybe_strip_indirect_ref (declarator) || type)
   13894            0 :         error_at (rettype_loc,
   13895              :                   "return type specified for deduction guide");
   13896      1259348 :       else if (type_quals != TYPE_UNQUALIFIED)
   13897            0 :         error_at (smallest_type_quals_location (type_quals, locations),
   13898              :                   "qualifiers are not allowed on declaration of "
   13899              :                   "deduction guide");
   13900      1259348 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   13901              :         {
   13902            3 :           error ("template template parameter %qT in declaration of "
   13903              :                  "deduction guide", optype);
   13904            3 :           type = error_mark_node;
   13905              :         }
   13906              :       else
   13907      1259345 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   13908     34002396 :       for (int i = 0; i < ds_last; ++i)
   13909     32743048 :         if (i != ds_explicit && locations[i])
   13910            3 :           error_at (locations[i],
   13911              :                     "%<decl-specifier%> in declaration of deduction guide");
   13912              :       break;
   13913              : 
   13914            0 :     default:
   13915            0 :       gcc_unreachable ();
   13916              :     }
   13917              : 
   13918     30584791 :   return type;
   13919              : }
   13920              : 
   13921              : /* A variable or data member (whose unqualified name is IDENTIFIER)
   13922              :    has been declared with the indicated TYPE.  If the TYPE is not
   13923              :    acceptable, issue an error message and return a type to use for
   13924              :    error-recovery purposes.  */
   13925              : 
   13926              : tree
   13927    337934779 : check_var_type (tree identifier, tree type, location_t loc)
   13928              : {
   13929    337934779 :   if (VOID_TYPE_P (type))
   13930              :     {
   13931           92 :       if (!identifier)
   13932            0 :         error_at (loc, "unnamed variable or field declared void");
   13933           92 :       else if (identifier_p (identifier))
   13934              :         {
   13935           92 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   13936           92 :           error_at (loc, "variable or field %qE declared void",
   13937              :                     identifier);
   13938              :         }
   13939              :       else
   13940            0 :         error_at (loc, "variable or field declared void");
   13941           92 :       type = error_mark_node;
   13942              :     }
   13943              : 
   13944    337934779 :   return type;
   13945              : }
   13946              : 
   13947              : /* Handle declaring DECL as an inline variable.  */
   13948              : 
   13949              : static void
   13950      6890310 : mark_inline_variable (tree decl, location_t loc)
   13951              : {
   13952      6890310 :   bool inlinep = true;
   13953      6890310 :   if (! toplevel_bindings_p ())
   13954              :     {
   13955           24 :       error_at (loc, "%<inline%> specifier invalid for variable "
   13956              :                 "%qD declared at block scope", decl);
   13957           24 :       inlinep = false;
   13958              :     }
   13959      6890286 :   else if (cxx_dialect < cxx17)
   13960          662 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   13961              :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   13962          686 :   if (inlinep)
   13963              :     {
   13964      6890286 :       retrofit_lang_decl (decl);
   13965      6890286 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   13966              :     }
   13967      6890310 : }
   13968              : 
   13969              : 
   13970              : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn.  TYPE is the unnamed class
   13971              :    with a typedef name for linkage purposes with freshly updated TYPE_NAME,
   13972              :    ORIG is the anonymous TYPE_NAME before that change.  */
   13973              : 
   13974              : static bool
   13975           42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
   13976              : {
   13977           42 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
   13978           42 :   tree name = DECL_NAME (TYPE_NAME (type));
   13979           42 :   richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
   13980           42 :   return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
   13981              :                   "anonymous non-C-compatible type given name for linkage "
   13982           42 :                   "purposes by %<typedef%> declaration");
   13983           42 : }
   13984              : 
   13985              : /* Diagnose -Wnon-c-typedef-for-linkage violations on T.  TYPE and ORIG
   13986              :    like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
   13987              :    to TYPE but during recursion can be set to nested classes.  */
   13988              : 
   13989              : static bool
   13990       526722 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
   13991              : {
   13992       526722 :   if (!COMPLETE_TYPE_P (t))
   13993              :     return false;
   13994       526719 :   if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
   13995              :     {
   13996            6 :       auto_diagnostic_group d;
   13997            6 :       if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13998            9 :         inform (type == t ? DECL_SOURCE_LOCATION (orig)
   13999            3 :                 : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
   14000              :                 "type is not C-compatible because it has a base class");
   14001            6 :       return true;
   14002            6 :     }
   14003      2476166 :   for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
   14004      1949514 :     switch (TREE_CODE (field))
   14005              :       {
   14006            9 :       case VAR_DECL:
   14007              :         /* static data members have been diagnosed already.  */
   14008            9 :         continue;
   14009      1296861 :       case FIELD_DECL:
   14010      1296861 :         if (DECL_INITIAL (field))
   14011              :           {
   14012            4 :             auto_diagnostic_group d;
   14013            4 :             if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   14014            4 :               inform (DECL_SOURCE_LOCATION (field),
   14015              :                       "type is not C-compatible because %qD has default "
   14016              :                       "member initializer", field);
   14017            4 :             return true;
   14018            4 :           }
   14019      1296857 :         continue;
   14020            9 :       case CONST_DECL:
   14021            9 :         continue;
   14022       652554 :       case TYPE_DECL:
   14023       652554 :         if (DECL_SELF_REFERENCE_P (field))
   14024       526687 :           continue;
   14025       125867 :         if (DECL_IMPLICIT_TYPEDEF_P (field))
   14026              :           {
   14027       125857 :             if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
   14028            3 :               continue;
   14029       125854 :             if (CLASS_TYPE_P (TREE_TYPE (field)))
   14030              :               {
   14031       125854 :                 tree tf = TREE_TYPE (field);
   14032       125854 :                 if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
   14033              :                                                                     tf))
   14034              :                   return true;
   14035       125829 :                 continue;
   14036       125829 :               }
   14037              :           }
   14038              :         /* FALLTHRU */
   14039           32 :       case FUNCTION_DECL:
   14040           32 :       case TEMPLATE_DECL:
   14041           32 :         {
   14042           32 :           auto_diagnostic_group d;
   14043           32 :           if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   14044           32 :             inform (DECL_SOURCE_LOCATION (field),
   14045              :                     "type is not C-compatible because it contains %qD "
   14046              :                     "declaration", field);
   14047           32 :           return true;
   14048           32 :         }
   14049              :       default:
   14050              :         break;
   14051      1296875 :       }
   14052              :   return false;
   14053              : }
   14054              : 
   14055              : /* Assign a typedef-given name to a class or enumeration type declared
   14056              :    as anonymous at first.  This was split out of grokdeclarator
   14057              :    because it is also used in libcc1.  */
   14058              : 
   14059              : void
   14060       402665 : name_unnamed_type (tree type, tree decl)
   14061              : {
   14062      1207995 :   gcc_assert (TYPE_UNNAMED_P (type)
   14063              :               || enum_with_enumerator_for_linkage_p (type));
   14064              : 
   14065       402665 :   tree orig = TYPE_NAME (type);
   14066       402665 :   if (flag_reflection)
   14067              :     {
   14068              :       /* For -freflection for typedef struct { ... } S; ^^S needs to be
   14069              :          a reflection of a type alias.  So, TREE_TYPE (DECL) can't be
   14070              :          TYPE.  Instead of what we do below, override DECL_NAME (orig).  */
   14071        16176 :       DECL_NAME (orig) = DECL_NAME (decl);
   14072        16176 :       TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
   14073              :     }
   14074              :   else
   14075              :     /* Replace the anonymous decl with the real decl.  Be careful not to
   14076              :        rename other typedefs (such as the self-reference) of type.  */
   14077      1157751 :     for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   14078       771262 :       if (TYPE_NAME (t) == orig)
   14079       386489 :         TYPE_NAME (t) = decl;
   14080       402665 :   TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
   14081              : 
   14082              :   /* If this is a typedef within a template class, the nested
   14083              :      type is a (non-primary) template.  The name for the
   14084              :      template needs updating as well.  */
   14085       402665 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   14086           68 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   14087              : 
   14088              :   /* Adjust linkage now that we aren't unnamed anymore.  */
   14089       402665 :   reset_type_linkage (type);
   14090              : 
   14091       402665 :   if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
   14092       400868 :     maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
   14093              : 
   14094              :   /* FIXME remangle member functions; member functions of a
   14095              :      type with external linkage have external linkage.  */
   14096              : 
   14097              :   /* Check that our job is done, and that it would fail if we
   14098              :      attempted to do it again.  */
   14099       805330 :   gcc_assert (!TYPE_UNNAMED_P (type)
   14100              :               && !enum_with_enumerator_for_linkage_p (type));
   14101       402665 : }
   14102              : 
   14103              : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   14104              :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   14105              :    there was a problem, false otherwise.  */
   14106              : 
   14107              : static bool
   14108    654442468 : check_decltype_auto (location_t loc, tree type)
   14109              : {
   14110    654442468 :   if (tree a = type_uses_auto (type))
   14111              :     {
   14112     18478462 :       if (AUTO_IS_DECLTYPE (a))
   14113              :         {
   14114       656265 :           if (a != type)
   14115              :             {
   14116           33 :               error_at (loc, "%qT as type rather than plain "
   14117              :                         "%<decltype(auto)%>", type);
   14118           33 :               return true;
   14119              :             }
   14120       656232 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   14121              :             {
   14122           37 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   14123           37 :               return true;
   14124              :             }
   14125              :         }
   14126              :     }
   14127              :   return false;
   14128              : }
   14129              : 
   14130              : /* Issue an error about two mutually incompatible declspecs
   14131              :    with the given names and locations
   14132              :    e.g. "error: `signed' and `unsigned' specified together" */
   14133              : 
   14134              : static void
   14135           66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   14136              :                                        const char *name_b, location_t loc_b)
   14137              : {
   14138           66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   14139           66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   14140              :                      nullptr, highlight_colors::rhs);
   14141           66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   14142           66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   14143           66 :   error_at (&richloc, "%e and %e specified together",
   14144              :             &e_name_a, &e_name_b);
   14145           66 : }
   14146              : 
   14147              : /* Given declspecs and a declarator (abstract or otherwise), determine
   14148              :    the name and type of the object declared and construct a DECL node
   14149              :    for it.
   14150              : 
   14151              :    DECLSPECS points to the representation of declaration-specifier
   14152              :    sequence that precedes declarator.
   14153              : 
   14154              :    DECL_CONTEXT says which syntactic context this declaration is in:
   14155              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   14156              :      FUNCDEF for a function definition.  Like NORMAL but a few different
   14157              :       error messages in each case.  Return value may be zero meaning
   14158              :       this definition is too screwy to try to parse.
   14159              :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   14160              :       handle member functions (which have FIELD context).
   14161              :       Return value may be zero meaning this definition is too screwy to
   14162              :       try to parse.
   14163              :      PARM for a parameter declaration (either within a function prototype
   14164              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   14165              :      TPARM for a template parameter declaration.
   14166              :      CATCHPARM for a parameter declaration before a catch clause.
   14167              :      TYPENAME if for a typename (in a cast or sizeof).
   14168              :       Don't make a DECL node; just return the ..._TYPE node.
   14169              :      FIELD for a struct or union field; make a FIELD_DECL.
   14170              :      BITFIELD for a field with specified width.
   14171              : 
   14172              :    INITIALIZED is as for start_decl.
   14173              : 
   14174              :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   14175              :    if there are none; *ATTRLIST may be modified if attributes from inside
   14176              :    the declarator should be applied to the declaration.
   14177              : 
   14178              :    When this function is called, scoping variables (such as
   14179              :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   14180              :    declaration occurs, not the scope in which the new declaration will
   14181              :    be placed.  For example, on:
   14182              : 
   14183              :      void S::f() { ... }
   14184              : 
   14185              :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   14186              :    should not be `S'.
   14187              : 
   14188              :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   14189              :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   14190              :    error occurs. */
   14191              : 
   14192              : tree
   14193   1075342776 : grokdeclarator (const cp_declarator *declarator,
   14194              :                 cp_decl_specifier_seq *declspecs,
   14195              :                 enum decl_context decl_context,
   14196              :                 int initialized,
   14197              :                 tree* attrlist)
   14198              : {
   14199   1075342776 :   tree type = NULL_TREE;
   14200   1075342776 :   int longlong = 0;
   14201   1075342776 :   int explicit_intN = 0;
   14202   1075342776 :   int int_n_alt = 0;
   14203   1075342776 :   int virtualp, explicitp, friendp, inlinep, staticp;
   14204   1075342776 :   int explicit_int = 0;
   14205   1075342776 :   int explicit_char = 0;
   14206   1075342776 :   int defaulted_int = 0;
   14207              : 
   14208   1075342776 :   tree typedef_decl = NULL_TREE;
   14209   1075342776 :   const char *name = NULL;
   14210   1075342776 :   tree typedef_type = NULL_TREE;
   14211              :   /* True if this declarator is a function definition.  */
   14212   1075342776 :   bool funcdef_flag = false;
   14213   1075342776 :   cp_declarator_kind innermost_code = cdk_error;
   14214   1075342776 :   int bitfield = 0;
   14215              : #if 0
   14216              :   /* See the code below that used this.  */
   14217              :   tree decl_attr = NULL_TREE;
   14218              : #endif
   14219              : 
   14220              :   /* Keep track of what sort of function is being processed
   14221              :      so that we can warn about default return values, or explicit
   14222              :      return values which do not match prescribed defaults.  */
   14223   1075342776 :   special_function_kind sfk = sfk_none;
   14224              : 
   14225   1075342776 :   tree dname = NULL_TREE;
   14226   1075342776 :   tree ctor_return_type = NULL_TREE;
   14227   1075342776 :   enum overload_flags flags = NO_SPECIAL;
   14228              :   /* cv-qualifiers that apply to the declarator, for a declaration of
   14229              :      a member function.  */
   14230   1075342776 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   14231              :   /* virt-specifiers that apply to the declarator, for a declaration of
   14232              :      a member function.  */
   14233   1075342776 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   14234              :   /* ref-qualifier that applies to the declarator, for a declaration of
   14235              :      a member function.  */
   14236   1075342776 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   14237              :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   14238   1075342776 :   auto type_quals = get_type_quals (declspecs);
   14239   1075342776 :   tree raises = NULL_TREE;
   14240   1075342776 :   int template_count = 0;
   14241   1075342776 :   tree returned_attrs = NULL_TREE;
   14242   1075342776 :   tree contract_specifiers = NULL_TREE;
   14243   1075342776 :   tree parms = NULL_TREE;
   14244   1075342776 :   const cp_declarator *id_declarator;
   14245              :   /* The unqualified name of the declarator; either an
   14246              :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   14247   1075342776 :   tree unqualified_id;
   14248              :   /* The class type, if any, in which this entity is located,
   14249              :      or NULL_TREE if none.  Note that this value may be different from
   14250              :      the current class type; for example if an attempt is made to declare
   14251              :      "A::f" inside "B", this value will be "A".  */
   14252   1075342776 :   tree ctype = current_class_type;
   14253              :   /* The NAMESPACE_DECL for the namespace in which this entity is
   14254              :      located.  If an unqualified name is used to declare the entity,
   14255              :      this value will be NULL_TREE, even if the entity is located at
   14256              :      namespace scope.  */
   14257   1075342776 :   tree in_namespace = NULL_TREE;
   14258   1075342776 :   cp_storage_class storage_class;
   14259   1075342776 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   14260   1075342776 :   bool type_was_error_mark_node = false;
   14261   1075342776 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   14262   1075342776 :   bool template_type_arg = false;
   14263   1075342776 :   bool template_parm_flag = false;
   14264   1075342776 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   14265   1075342776 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   14266   1075342776 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   14267   1075342776 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   14268   1075342776 :   bool late_return_type_p = false;
   14269   1075342776 :   bool array_parameter_p = false;
   14270   1075342776 :   tree reqs = NULL_TREE;
   14271              : 
   14272   1075342776 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   14273   1075342776 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   14274   1075342776 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   14275   1075342776 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   14276   1075342776 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   14277   1075342776 :   explicit_intN = declspecs->explicit_intN_p;
   14278   1075342776 :   int_n_alt = declspecs->int_n_alt;
   14279   1075342776 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   14280              : 
   14281              :   // Was concept_p specified? Note that ds_concept
   14282              :   // implies ds_constexpr!
   14283   1075342776 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   14284   1075342776 :   if (concept_p)
   14285          117 :     constexpr_p = true;
   14286              : 
   14287   1075342776 :   if (decl_context == FUNCDEF)
   14288              :     funcdef_flag = true, decl_context = NORMAL;
   14289              :   else if (decl_context == MEMFUNCDEF)
   14290              :     funcdef_flag = true, decl_context = FIELD;
   14291              :   else if (decl_context == BITFIELD)
   14292              :     bitfield = 1, decl_context = FIELD;
   14293              :   else if (decl_context == TEMPLATE_TYPE_ARG)
   14294              :     template_type_arg = true, decl_context = TYPENAME;
   14295              :   else if (decl_context == TPARM)
   14296     11516523 :     template_parm_flag = true, decl_context = PARM;
   14297              : 
   14298   1075342776 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   14299     11334579 :     funcdef_flag = true;
   14300              : 
   14301   1075342776 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   14302              :                                               (type_quals,
   14303   1075342776 :                                                declspecs->locations));
   14304   1075342776 :   location_t id_loc;
   14305   1075342776 :   location_t init_loc;
   14306   1075342776 :   if (declarator)
   14307              :     {
   14308    648511691 :       id_loc = loc_or_input_loc (declarator->id_loc);
   14309    648511691 :       init_loc = loc_or_input_loc (declarator->init_loc);
   14310              :     }
   14311              :   else
   14312    426831085 :     init_loc = id_loc = input_location;
   14313              : 
   14314              :   /* Look inside a declarator for the name being declared
   14315              :      and get it as a string, for an error message.  */
   14316   1075342776 :   for (id_declarator = declarator;
   14317   1476180766 :        id_declarator;
   14318    400837990 :        id_declarator = id_declarator->declarator)
   14319              :     {
   14320   1006141994 :       if (id_declarator->kind != cdk_id)
   14321    400838015 :         innermost_code = id_declarator->kind;
   14322              : 
   14323   1006141994 :       switch (id_declarator->kind)
   14324              :         {
   14325    196966780 :         case cdk_function:
   14326    196966780 :           if (id_declarator->declarator
   14327    196576708 :               && id_declarator->declarator->kind == cdk_id)
   14328              :             {
   14329    194685272 :               sfk = id_declarator->declarator->u.id.sfk;
   14330    194685272 :               if (sfk == sfk_destructor)
   14331      3328355 :                 flags = DTOR_FLAG;
   14332              :             }
   14333              :           break;
   14334              : 
   14335    605303979 :         case cdk_id:
   14336    605303979 :           {
   14337    605303979 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   14338    605303979 :             tree decl = id_declarator->u.id.unqualified_name;
   14339    605303979 :             if (!decl)
   14340              :               break;
   14341    605303979 :             if (qualifying_scope)
   14342              :               {
   14343     10167784 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   14344     10167784 :                                                     id_declarator->id_loc))
   14345            6 :                   return error_mark_node;
   14346     10167778 :                 if (at_function_scope_p ())
   14347              :                   {
   14348              :                     /* [dcl.meaning]
   14349              : 
   14350              :                        A declarator-id shall not be qualified except
   14351              :                        for ...
   14352              : 
   14353              :                        None of the cases are permitted in block
   14354              :                        scope.  */
   14355            0 :                     if (qualifying_scope == global_namespace)
   14356            0 :                       error ("invalid use of qualified-name %<::%D%>",
   14357              :                              decl);
   14358            0 :                     else if (TYPE_P (qualifying_scope))
   14359            0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   14360              :                              qualifying_scope, decl);
   14361              :                     else
   14362            0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   14363              :                              qualifying_scope, decl);
   14364            0 :                     return error_mark_node;
   14365              :                   }
   14366     10167778 :                 else if (TYPE_P (qualifying_scope))
   14367              :                   {
   14368      9735776 :                     ctype = qualifying_scope;
   14369      9735776 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   14370              :                       {
   14371            6 :                         error_at (id_declarator->id_loc,
   14372              :                                   "%q#T is not a class or namespace", ctype);
   14373            6 :                         ctype = NULL_TREE;
   14374              :                       }
   14375      9735770 :                     else if (innermost_code != cdk_function
   14376       507930 :                              && current_class_type
   14377      9735785 :                              && !uniquely_derived_from_p (ctype,
   14378              :                                                           current_class_type))
   14379              :                       {
   14380            9 :                         error_at (id_declarator->id_loc,
   14381              :                                   "invalid use of qualified-name %<%T::%D%>",
   14382              :                                   qualifying_scope, decl);
   14383            9 :                         return error_mark_node;
   14384              :                       }
   14385              :                   }
   14386       432002 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   14387    605303964 :                   in_namespace = qualifying_scope;
   14388              :               }
   14389    605303964 :             switch (TREE_CODE (decl))
   14390              :               {
   14391      3328370 :               case BIT_NOT_EXPR:
   14392      3328370 :                 {
   14393      3328370 :                   if (innermost_code != cdk_function)
   14394              :                     {
   14395            6 :                       error_at (EXPR_LOCATION (decl),
   14396              :                                 "declaration of %qE as non-function", decl);
   14397            6 :                       return error_mark_node;
   14398              :                     }
   14399      3328364 :                   else if (!qualifying_scope
   14400      3328364 :                            && !(current_class_type && at_class_scope_p ()))
   14401              :                     {
   14402            9 :                       error_at (EXPR_LOCATION (decl),
   14403              :                                 "declaration of %qE as non-member", decl);
   14404            9 :                       return error_mark_node;
   14405              :                     }
   14406              : 
   14407      3328355 :                   tree type = TREE_OPERAND (decl, 0);
   14408      3328355 :                   if (TYPE_P (type))
   14409      3328352 :                     type = constructor_name (type);
   14410      3328355 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   14411      3328355 :                   dname = decl;
   14412              :                 }
   14413      3328355 :                 break;
   14414              : 
   14415      2946267 :               case TEMPLATE_ID_EXPR:
   14416      2946267 :                 {
   14417      2946267 :                   tree fns = TREE_OPERAND (decl, 0);
   14418              : 
   14419      2946267 :                   dname = fns;
   14420      3920876 :                   if (!identifier_p (dname))
   14421      2946240 :                     dname = OVL_NAME (dname);
   14422              :                 }
   14423              :                 /* Fall through.  */
   14424              : 
   14425    601975594 :               case IDENTIFIER_NODE:
   14426    601975594 :                 if (identifier_p (decl))
   14427    599029327 :                   dname = decl;
   14428              : 
   14429    601975594 :                 if (IDENTIFIER_KEYWORD_P (dname))
   14430              :                   {
   14431            0 :                     error ("declarator-id missing; using reserved word %qD",
   14432              :                            dname);
   14433            0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14434              :                   }
   14435    601975594 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   14436    600923760 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14437              :                 else
   14438              :                   {
   14439      1051834 :                     gcc_assert (flags == NO_SPECIAL);
   14440      1051834 :                     flags = TYPENAME_FLAG;
   14441      1051834 :                     sfk = sfk_conversion;
   14442      1051834 :                     tree glob = get_global_binding (dname);
   14443      1051834 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   14444            0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14445              :                     else
   14446              :                       name = "<invalid operator>";
   14447              :                   }
   14448              :                 break;
   14449              : 
   14450            0 :               default:
   14451            0 :                 gcc_unreachable ();
   14452              :               }
   14453              :             break;
   14454              :           }
   14455              : 
   14456              :         case cdk_array:
   14457              :         case cdk_pointer:
   14458              :         case cdk_reference:
   14459              :         case cdk_ptrmem:
   14460              :           break;
   14461              : 
   14462              :         case cdk_decomp:
   14463   1006141939 :           name = "structured binding";
   14464              :           break;
   14465              : 
   14466           25 :         case cdk_error:
   14467           25 :           return error_mark_node;
   14468              : 
   14469            0 :         default:
   14470            0 :           gcc_unreachable ();
   14471              :         }
   14472   1006141939 :       if (id_declarator->kind == cdk_id)
   14473              :         break;
   14474              :     }
   14475              : 
   14476              :   /* [dcl.fct.edf]
   14477              : 
   14478              :      The declarator in a function-definition shall have the form
   14479              :      D1 ( parameter-declaration-clause) ...  */
   14480   1075342721 :   if (funcdef_flag && innermost_code != cdk_function)
   14481              :     {
   14482            3 :       error_at (id_loc, "function definition does not declare parameters");
   14483            3 :       return error_mark_node;
   14484              :     }
   14485              : 
   14486   1075342718 :   if (flags == TYPENAME_FLAG
   14487   1075342718 :       && innermost_code != cdk_function
   14488            3 :       && ! (ctype && !declspecs->any_specifiers_p))
   14489              :     {
   14490            3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   14491            3 :       return error_mark_node;
   14492              :     }
   14493              : 
   14494   1075342715 :   if (dname && identifier_p (dname))
   14495              :     {
   14496    601975588 :       if (UDLIT_OPER_P (dname)
   14497    601975588 :           && innermost_code != cdk_function)
   14498              :         {
   14499            6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   14500            6 :           return error_mark_node;
   14501              :         }
   14502              : 
   14503    601975582 :       if (IDENTIFIER_ANY_OP_P (dname))
   14504              :         {
   14505     38404064 :           if (typedef_p)
   14506              :             {
   14507            3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   14508            3 :               return error_mark_node;
   14509              :             }
   14510     38404061 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14511              :             {
   14512           15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   14513           15 :               return error_mark_node;
   14514              :             }
   14515              :         }
   14516              :     }
   14517              : 
   14518              :   /* Anything declared one level down from the top level
   14519              :      must be one of the parameters of a function
   14520              :      (because the body is at least two levels down).  */
   14521              : 
   14522              :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   14523              :      by not allowing C++ class definitions to specify their parameters
   14524              :      with xdecls (must be spec.d in the parmlist).
   14525              : 
   14526              :      Since we now wait to push a class scope until we are sure that
   14527              :      we are in a legitimate method context, we must set oldcname
   14528              :      explicitly (since current_class_name is not yet alive).
   14529              : 
   14530              :      We also want to avoid calling this a PARM if it is in a namespace.  */
   14531              : 
   14532   1075342691 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   14533              :     {
   14534     74712885 :       cp_binding_level *b = current_binding_level;
   14535     74712885 :       current_binding_level = b->level_chain;
   14536     74712885 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   14537              :         decl_context = PARM;
   14538     74712885 :       current_binding_level = b;
   14539              :     }
   14540              : 
   14541   1075342691 :   if (name == NULL)
   14542    469793211 :     name = decl_context == PARM ? "parameter" : "type name";
   14543              : 
   14544   1075342691 :   if (consteval_p && constexpr_p)
   14545              :     {
   14546            6 :       error_at (declspecs->locations[ds_consteval],
   14547              :                 "both %qs and %qs specified", "constexpr", "consteval");
   14548            6 :       return error_mark_node;
   14549              :     }
   14550              : 
   14551   1075342685 :   if (concept_p && typedef_p)
   14552              :     {
   14553            9 :       error_at (declspecs->locations[ds_concept],
   14554              :                 "%qs cannot appear in a typedef declaration", "concept");
   14555            9 :       return error_mark_node;
   14556              :     }
   14557              : 
   14558   1075342676 :   if (constexpr_p && typedef_p)
   14559              :     {
   14560            3 :       error_at (declspecs->locations[ds_constexpr],
   14561              :                 "%qs cannot appear in a typedef declaration", "constexpr");
   14562            3 :       return error_mark_node;
   14563              :     }
   14564              : 
   14565   1075342673 :   if (consteval_p && typedef_p)
   14566              :     {
   14567            3 :       error_at (declspecs->locations[ds_consteval],
   14568              :                 "%qs cannot appear in a typedef declaration", "consteval");
   14569            3 :       return error_mark_node;
   14570              :     }
   14571              : 
   14572   1075342670 :   if (constinit_p && typedef_p)
   14573              :     {
   14574            3 :       error_at (declspecs->locations[ds_constinit],
   14575              :                 "%qs cannot appear in a typedef declaration", "constinit");
   14576            3 :       return error_mark_node;
   14577              :     }
   14578              : 
   14579              :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   14580              :      keywords shall appear in a decl-specifier-seq."  */
   14581   1075342667 :   if (constinit_p && constexpr_p)
   14582              :     {
   14583            6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   14584            6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   14585            6 :       error_at (&richloc,
   14586              :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   14587              :                 "specifiers");
   14588            6 :       return error_mark_node;
   14589            6 :     }
   14590              : 
   14591              :   /* If there were multiple types specified in the decl-specifier-seq,
   14592              :      issue an error message.  */
   14593   1075342661 :   if (declspecs->multiple_types_p)
   14594              :     {
   14595         1501 :       error_at (typespec_loc,
   14596              :                 "two or more data types in declaration of %qs", name);
   14597         1501 :       return error_mark_node;
   14598              :     }
   14599              : 
   14600   1075341160 :   if (declspecs->conflicting_specifiers_p)
   14601           31 :     return error_mark_node;
   14602              : 
   14603              :   /* Extract the basic type from the decl-specifier-seq.  */
   14604   1075341129 :   type = declspecs->type;
   14605   1075341129 :   if (type == error_mark_node)
   14606              :     {
   14607         1243 :       type = NULL_TREE;
   14608         1243 :       type_was_error_mark_node = true;
   14609              :     }
   14610              : 
   14611              :   /* Ignore erroneous attributes.  */
   14612   1075341129 :   if (attrlist && *attrlist == error_mark_node)
   14613           12 :     *attrlist = NULL_TREE;
   14614              : 
   14615              :   /* An object declared as __attribute__((unavailable)) suppresses
   14616              :      any reports of being declared with unavailable or deprecated
   14617              :      items.  An object declared as __attribute__((deprecated))
   14618              :      suppresses warnings of uses of other deprecated items.  */
   14619   1075341129 :   auto ds = make_temp_override (deprecated_state);
   14620   1075341129 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   14621          171 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   14622   1075340958 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   14623       963568 :     deprecated_state = DEPRECATED_SUPPRESS;
   14624              : 
   14625   1075341129 :   cp_handle_deprecated_or_unavailable (type);
   14626   1075341129 :   if (type && TREE_CODE (type) == TYPE_DECL)
   14627              :     {
   14628    749002369 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   14629    749002369 :       typedef_decl = type;
   14630    749002369 :       type = TREE_TYPE (typedef_decl);
   14631    749002369 :       if (DECL_ARTIFICIAL (typedef_decl))
   14632    544033133 :         cp_handle_deprecated_or_unavailable (type);
   14633              :     }
   14634              :   /* No type at all: default to `int', and set DEFAULTED_INT
   14635              :      because it was not a user-defined typedef.  */
   14636   1075341129 :   if (type == NULL_TREE)
   14637              :     {
   14638     40024778 :       if (signed_p || unsigned_p || long_p || short_p)
   14639              :         {
   14640              :           /* These imply 'int'.  */
   14641      9438344 :           type = integer_type_node;
   14642      9438344 :           defaulted_int = 1;
   14643              :         }
   14644              :       /* If we just have "complex", it is equivalent to "complex double".  */
   14645     30586434 :       else if (!longlong && !explicit_intN
   14646     30586434 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14647              :         {
   14648           81 :           type = double_type_node;
   14649           81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   14650              :                    "ISO C++ does not support plain %<complex%> meaning "
   14651              :                    "%<double complex%>");
   14652              :         }
   14653              :     }
   14654              :   /* Gather flags.  */
   14655   1075341129 :   explicit_int = declspecs->explicit_int_p;
   14656   1075341129 :   explicit_char = declspecs->explicit_char_p;
   14657              : 
   14658              : #if 0
   14659              :   /* See the code below that used this.  */
   14660              :   if (typedef_decl)
   14661              :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   14662              : #endif
   14663   1075341129 :   typedef_type = type;
   14664              : 
   14665   1075341129 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   14666      2311179 :     ctor_return_type = TREE_TYPE (dname);
   14667              :   else
   14668              :     ctor_return_type = ctype;
   14669              : 
   14670   1075341129 :   if (sfk != sfk_none)
   14671              :     {
   14672     30584791 :       type = check_special_function_return_type (sfk, type,
   14673              :                                                  ctor_return_type,
   14674              :                                                  type_quals,
   14675              :                                                  &declarator,
   14676              :                                                  declspecs->locations);
   14677     30584791 :       type_quals = TYPE_UNQUALIFIED;
   14678              :     }
   14679   1044756338 :   else if (type == NULL_TREE)
   14680              :     {
   14681         1643 :       int is_main;
   14682              : 
   14683         1643 :       explicit_int = -1;
   14684              : 
   14685              :       /* We handle `main' specially here, because 'main () { }' is so
   14686              :          common.  With no options, it is allowed.  With -Wreturn-type,
   14687              :          it is a warning.  It is only an error with -pedantic-errors.  */
   14688         3286 :       is_main = (funcdef_flag
   14689         3520 :                  && dname && identifier_p (dname)
   14690          234 :                  && MAIN_NAME_P (dname)
   14691           68 :                  && ctype == NULL_TREE
   14692           68 :                  && in_namespace == NULL_TREE
   14693         1711 :                  && current_namespace == global_namespace);
   14694              : 
   14695         1643 :       if (type_was_error_mark_node)
   14696              :         /* We've already issued an error, don't complain more.  */;
   14697          400 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   14698              :         /* Allow it, sigh.  */;
   14699          338 :       else if (! is_main)
   14700          276 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   14701              :                    name);
   14702           62 :       else if (pedantic)
   14703            4 :         pedwarn (id_loc, OPT_Wpedantic,
   14704              :                  "ISO C++ forbids declaration of %qs with no type", name);
   14705              :       else
   14706           58 :         warning_at (id_loc, OPT_Wreturn_type,
   14707              :                     "ISO C++ forbids declaration of %qs with no type", name);
   14708              : 
   14709         1643 :       if (type_was_error_mark_node && template_parm_flag)
   14710              :         /* FIXME we should be able to propagate the error_mark_node as is
   14711              :            for other contexts too.  */
   14712          162 :         type = error_mark_node;
   14713              :       else
   14714         1481 :         type = integer_type_node;
   14715              :     }
   14716              : 
   14717   1075341129 :   ctype = NULL_TREE;
   14718              : 
   14719   1075341129 :   if (explicit_intN)
   14720              :     {
   14721      1137869 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   14722              :         {
   14723            0 :           error_at (declspecs->locations[ds_type_spec],
   14724              :                     "%<__int%d%> is not supported by this target",
   14725            0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   14726            0 :           explicit_intN = false;
   14727              :         }
   14728              :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   14729              :          of "__intN".  */
   14730      1137869 :       else if (!int_n_alt && pedantic)
   14731        11104 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   14732              :                  "ISO C++ does not support %<__int%d%> for %qs",
   14733        11104 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   14734              :     }
   14735              : 
   14736              :   /* Now process the modifiers that were specified
   14737              :      and check for invalid combinations.  */
   14738              : 
   14739              :   /* Long double is a special combination.  */
   14740   1075341129 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   14741              :     {
   14742      9149545 :       long_p = false;
   14743      9149545 :       type = cp_build_qualified_type (long_double_type_node,
   14744              :                                       cp_type_quals (type));
   14745              :     }
   14746              : 
   14747              :   /* Check all other uses of type modifiers.  */
   14748              : 
   14749   1075341129 :   if (unsigned_p || signed_p || long_p || short_p)
   14750              :     {
   14751     21745149 :       location_t loc;
   14752     21745149 :       const char *key;
   14753     21745149 :       if (unsigned_p)
   14754              :         {
   14755     14820946 :           key = "unsigned";
   14756     14820946 :           loc = declspecs->locations[ds_unsigned];
   14757              :         }
   14758      6924203 :       else if (signed_p)
   14759              :         {
   14760      1053834 :           key = "signed";
   14761      1053834 :           loc = declspecs->locations[ds_signed];
   14762              :         }
   14763      5870369 :       else if (longlong)
   14764              :         {
   14765      2293491 :           key = "long long";
   14766      2293491 :           loc = declspecs->locations[ds_long_long];
   14767              :         }
   14768      3576878 :       else if (long_p)
   14769              :         {
   14770      3007340 :           key = "long";
   14771      3007340 :           loc = declspecs->locations[ds_long];
   14772              :         }
   14773              :       else /* if (short_p) */
   14774              :         {
   14775       569538 :           key = "short";
   14776       569538 :           loc = declspecs->locations[ds_short];
   14777              :         }
   14778              : 
   14779     21745149 :       int ok = 0;
   14780              : 
   14781     21745149 :       if (signed_p && unsigned_p)
   14782           54 :         complain_about_incompatible_declspecs
   14783           54 :           ("signed", declspecs->locations[ds_signed],
   14784              :            "unsigned", declspecs->locations[ds_unsigned]);
   14785     21745095 :       else if (long_p && short_p)
   14786           12 :         complain_about_incompatible_declspecs
   14787           12 :           ("long", declspecs->locations[ds_long],
   14788              :            "short", declspecs->locations[ds_short]);
   14789     21745083 :       else if (TREE_CODE (type) != INTEGER_TYPE
   14790     21745070 :                || type == char8_type_node
   14791     21745046 :                || type == char16_type_node
   14792     21745022 :                || type == char32_type_node
   14793     21744998 :                || ((long_p || short_p)
   14794     11405678 :                    && (explicit_char || explicit_intN)))
   14795          418 :         error_at (loc, "%qs specified with %qT", key, type);
   14796     21744665 :       else if (!explicit_int && !defaulted_int
   14797     21744665 :                && !explicit_char && !explicit_intN)
   14798              :         {
   14799           30 :           if (typedef_decl)
   14800              :             {
   14801           27 :               pedwarn (loc, OPT_Wpedantic,
   14802              :                        "%qs specified with typedef-name %qD",
   14803              :                        key, typedef_decl);
   14804           27 :               ok = !flag_pedantic_errors;
   14805              :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   14806              :                  and is not built as a typedef.  */
   14807           27 :               if (is_typedef_decl (typedef_decl))
   14808           18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   14809              :             }
   14810            3 :           else if (declspecs->decltype_p)
   14811            0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   14812              :           else
   14813            3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   14814              :         }
   14815              :       else
   14816              :         ok = 1;
   14817              : 
   14818              :       /* Discard the type modifiers if they are invalid.  */
   14819          514 :       if (! ok)
   14820              :         {
   14821              :           unsigned_p = false;
   14822              :           signed_p = false;
   14823              :           long_p = false;
   14824              :           short_p = false;
   14825              :           longlong = 0;
   14826              :         }
   14827              :     }
   14828              : 
   14829              :   /* Decide whether an integer type is signed or not.
   14830              :      Optionally treat bitfields as signed by default.  */
   14831   1075340639 :   if (unsigned_p
   14832              :       /* [class.bit]
   14833              : 
   14834              :          It is implementation-defined whether a plain (neither
   14835              :          explicitly signed or unsigned) char, short, int, or long
   14836              :          bit-field is signed or unsigned.
   14837              : 
   14838              :          Naturally, we extend this to long long as well.  Note that
   14839              :          this does not include wchar_t.  */
   14840   1075341129 :       || (bitfield && !flag_signed_bitfields
   14841           18 :           && !signed_p
   14842              :           /* A typedef for plain `int' without `signed' can be
   14843              :              controlled just like plain `int', but a typedef for
   14844              :              `signed int' cannot be so controlled.  */
   14845           18 :           && !(typedef_decl
   14846           18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   14847           13 :           && TREE_CODE (type) == INTEGER_TYPE
   14848           10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   14849              :     {
   14850     14820731 :       if (explicit_intN)
   14851       538533 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   14852     14282198 :       else if (longlong)
   14853      1468879 :         type = long_long_unsigned_type_node;
   14854     12813319 :       else if (long_p)
   14855      2404542 :         type = long_unsigned_type_node;
   14856     10408777 :       else if (short_p)
   14857      1448400 :         type = short_unsigned_type_node;
   14858      8960377 :       else if (type == char_type_node)
   14859      1942299 :         type = unsigned_char_type_node;
   14860      7018078 :       else if (typedef_decl)
   14861           25 :         type = c_common_unsigned_type (type);
   14862              :       else
   14863      7018053 :         type = unsigned_type_node;
   14864              :     }
   14865   1060520398 :   else if (signed_p && type == char_type_node)
   14866       692713 :     type = signed_char_type_node;
   14867   1059827685 :   else if (explicit_intN)
   14868       599336 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   14869   1059228349 :   else if (longlong)
   14870      2358081 :     type = long_long_integer_type_node;
   14871   1056870268 :   else if (long_p)
   14872      3076271 :     type = long_integer_type_node;
   14873   1053793997 :   else if (short_p)
   14874       649172 :     type = short_integer_type_node;
   14875   1053144825 :   else if (signed_p && typedef_decl)
   14876            9 :     type = c_common_signed_type (type);
   14877              : 
   14878   1075341129 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14879              :     {
   14880      1275343 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   14881            3 :         error_at (declspecs->locations[ds_complex],
   14882              :                   "complex invalid for %qs", name);
   14883              :       /* If a modifier is specified, the resulting complex is the complex
   14884              :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   14885      1275340 :       else if (type == integer_type_node)
   14886          171 :         type = complex_integer_type_node;
   14887      1275169 :       else if (type == float_type_node)
   14888       347152 :         type = complex_float_type_node;
   14889       928017 :       else if (type == double_type_node)
   14890       347703 :         type = complex_double_type_node;
   14891       580314 :       else if (type == long_double_type_node)
   14892       347193 :         type = complex_long_double_type_node;
   14893              :       else
   14894       233121 :         type = build_complex_type (type);
   14895              :     }
   14896              : 
   14897              :   /* If we're using the injected-class-name to form a compound type or a
   14898              :      declaration, replace it with the underlying class so we don't get
   14899              :      redundant typedefs in the debug output.  But if we are returning the
   14900              :      type unchanged, leave it alone so that it's available to
   14901              :      maybe_get_template_decl_from_type_decl.  */
   14902    210610615 :   if (CLASS_TYPE_P (type)
   14903    210546755 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   14904     36240601 :       && type == TREE_TYPE (TYPE_NAME (type))
   14905   1111581730 :       && (declarator || type_quals))
   14906     34608827 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   14907              : 
   14908   1075341129 :   type_quals |= cp_type_quals (type);
   14909   2150682258 :   type = cp_build_qualified_type
   14910   2150682258 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   14911    870371893 :                           || declspecs->decltype_p)
   14912              :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   14913              :   /* We might have ignored or rejected some of the qualifiers.  */
   14914   1075341129 :   type_quals = cp_type_quals (type);
   14915              : 
   14916   1060047797 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   14917     23663279 :       && innermost_code != cdk_function
   14918              :       /* Placeholder in parm gets a better error below.  */
   14919     14678323 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   14920   1089980436 :       && id_declarator && declarator != id_declarator)
   14921      1210978 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   14922              :       {
   14923           16 :         auto_diagnostic_group g;
   14924           16 :         gcc_rich_location richloc (typespec_loc);
   14925           16 :         richloc.add_fixit_insert_after ("<>");
   14926           16 :         error_at (&richloc, "missing template argument list after %qE; "
   14927              :                   "for deduction, template placeholder must be followed "
   14928              :                   "by a simple declarator-id", tmpl);
   14929           16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   14930           16 :         type = error_mark_node;
   14931           16 :       }
   14932              : 
   14933   1075341129 :   staticp = 0;
   14934   1075341129 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   14935   1075341129 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   14936   1075341129 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   14937              : 
   14938   1075341129 :   storage_class = declspecs->storage_class;
   14939   1075341129 :   if (storage_class == sc_static)
   14940     24539279 :     staticp = 1 + (decl_context == FIELD);
   14941   1050801850 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   14942              :     /* Treat class-scope deduction guides as static member functions
   14943              :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   14944     24190003 :     staticp = 2;
   14945              : 
   14946   1075341129 :   if (virtualp)
   14947              :     {
   14948      4195859 :       if (staticp == 2)
   14949              :         {
   14950           21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14951           21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   14952           21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   14953              :                     "and %<static%>", dname);
   14954           21 :           storage_class = sc_none;
   14955           21 :           staticp = 0;
   14956           21 :         }
   14957      4195859 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   14958              :         {
   14959            6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14960            6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   14961            6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   14962              :                    "declared both %<virtual%> and %<constexpr%> only in "
   14963              :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   14964            6 :         }
   14965              :     }
   14966   1075341129 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   14967              : 
   14968              :   /* Issue errors about use of storage classes for parameters.  */
   14969   1075341129 :   if (decl_context == PARM)
   14970              :     {
   14971    303935386 :       if (typedef_p)
   14972              :         {
   14973           24 :           error_at (declspecs->locations[ds_typedef],
   14974              :                     "typedef declaration invalid in parameter declaration");
   14975           24 :           return error_mark_node;
   14976              :         }
   14977    303935362 :       else if (template_parm_flag && storage_class != sc_none)
   14978              :         {
   14979           16 :           error_at (min_location (declspecs->locations[ds_thread],
   14980              :                                   declspecs->locations[ds_storage_class]),
   14981              :                     "storage class specified for template parameter %qs",
   14982              :                     name);
   14983           16 :           return error_mark_node;
   14984              :         }
   14985    303935346 :       else if (storage_class == sc_static
   14986    303935346 :                || storage_class == sc_extern
   14987    303935343 :                || thread_p)
   14988              :         {
   14989            9 :           error_at (min_location (declspecs->locations[ds_thread],
   14990              :                                   declspecs->locations[ds_storage_class]),
   14991              :                     "storage class specified for parameter %qs", name);
   14992            9 :           return error_mark_node;
   14993              :         }
   14994              : 
   14995              :       /* Function parameters cannot be concept. */
   14996    303935337 :       if (concept_p)
   14997              :         {
   14998            9 :           error_at (declspecs->locations[ds_concept],
   14999              :                     "a parameter cannot be declared %qs", "concept");
   15000            9 :           concept_p = 0;
   15001            9 :           constexpr_p = 0;
   15002              :         }
   15003              :       /* Function parameters cannot be constexpr.  If we saw one, moan
   15004              :          and pretend it wasn't there.  */
   15005    303935328 :       else if (constexpr_p)
   15006              :         {
   15007            9 :           error_at (declspecs->locations[ds_constexpr],
   15008              :                     "a parameter cannot be declared %qs", "constexpr");
   15009            9 :           constexpr_p = 0;
   15010              :         }
   15011    303935337 :       if (constinit_p)
   15012              :         {
   15013            6 :           error_at (declspecs->locations[ds_constinit],
   15014              :                     "a parameter cannot be declared %qs", "constinit");
   15015            6 :           constinit_p = 0;
   15016              :         }
   15017    303935337 :       if (consteval_p)
   15018              :         {
   15019            3 :           error_at (declspecs->locations[ds_consteval],
   15020              :                     "a parameter cannot be declared %qs", "consteval");
   15021            3 :           consteval_p = 0;
   15022              :         }
   15023              :     }
   15024              : 
   15025              :   /* Give error if `virtual' is used outside of class declaration.  */
   15026   1075341080 :   if (virtualp
   15027      4195859 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   15028              :     {
   15029           68 :       error_at (declspecs->locations[ds_virtual],
   15030              :                 "%<virtual%> outside class declaration");
   15031           68 :       virtualp = 0;
   15032              :     }
   15033              : 
   15034   1075341080 :   if (innermost_code == cdk_decomp)
   15035              :     {
   15036       235316 :       location_t loc = (declarator->kind == cdk_reference
   15037       245561 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   15038       245561 :       if (inlinep)
   15039           29 :         error_at (declspecs->locations[ds_inline],
   15040              :                   "structured binding declaration cannot be %qs", "inline");
   15041       245561 :       if (typedef_p)
   15042           29 :         error_at (declspecs->locations[ds_typedef],
   15043              :                   "structured binding declaration cannot be %qs", "typedef");
   15044       245561 :       if (constexpr_p && !concept_p && cxx_dialect < cxx26)
   15045          101 :         pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
   15046              :                  "structured binding declaration can be %qs only with "
   15047              :                  "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
   15048       245561 :       if (consteval_p)
   15049           13 :         error_at (declspecs->locations[ds_consteval], "structured "
   15050              :                   "binding declaration cannot be %qs", "consteval");
   15051       245561 :       if (thread_p && cxx_dialect < cxx20)
   15052           75 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   15053              :                  "structured binding declaration can be %qs only in "
   15054              :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   15055           75 :                  declspecs->gnu_thread_keyword_p
   15056              :                  ? "__thread" : "thread_local");
   15057       245561 :       if (concept_p)
   15058              :         {
   15059            0 :           error_at (declspecs->locations[ds_concept],
   15060              :                     "structured binding declaration cannot be %qs", "concept");
   15061            0 :           constexpr_p = 0;
   15062              :         }
   15063              :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   15064       245561 :       if (type_quals & TYPE_QUAL_VOLATILE)
   15065           26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   15066              :                     "%<volatile%>-qualified structured binding is deprecated");
   15067       245561 :       switch (storage_class)
   15068              :         {
   15069              :         case sc_none:
   15070              :           break;
   15071           28 :         case sc_register:
   15072           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   15073              :                     "register");
   15074           28 :           break;
   15075          254 :         case sc_static:
   15076          254 :           if (cxx_dialect < cxx20)
   15077          185 :             pedwarn (loc, OPT_Wc__20_extensions,
   15078              :                      "structured binding declaration can be %qs only in "
   15079              :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   15080              :           break;
   15081           29 :         case sc_extern:
   15082           29 :           error_at (loc, "structured binding declaration cannot be %qs",
   15083              :                     "extern");
   15084           29 :           break;
   15085           28 :         case sc_mutable:
   15086           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   15087              :                     "mutable");
   15088           28 :           break;
   15089            0 :         case sc_auto:
   15090            0 :           error_at (loc, "structured binding declaration cannot be "
   15091              :                     "C++98 %<auto%>");
   15092            0 :           break;
   15093            0 :         default:
   15094            0 :           gcc_unreachable ();
   15095              :         }
   15096       245561 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   15097       245561 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   15098              :         {
   15099            3 :           if (type != error_mark_node)
   15100              :             {
   15101            3 :               auto_diagnostic_group d;
   15102            3 :               error_at (loc, "structured binding declaration cannot have "
   15103              :                         "type %qT", type);
   15104            3 :               inform (loc,
   15105              :                       "type must be cv-qualified %<auto%> or reference to "
   15106              :                       "cv-qualified %<auto%>");
   15107            3 :             }
   15108            3 :           type = build_qualified_type (make_auto (), type_quals);
   15109            3 :           declspecs->type = type;
   15110              :         }
   15111       245558 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   15112           51 :         pedwarn (loc, OPT_Wpedantic,
   15113              :                  "structured binding declaration cannot have constrained "
   15114              :                  "%<auto%> type %qT", type);
   15115       245561 :       inlinep = 0;
   15116       245561 :       typedef_p = 0;
   15117       245561 :       consteval_p = 0;
   15118       245561 :       concept_p = 0;
   15119       245561 :       if (storage_class != sc_static)
   15120              :         {
   15121       245307 :           storage_class = sc_none;
   15122       245307 :           declspecs->storage_class = sc_none;
   15123              :         }
   15124              :     }
   15125              : 
   15126              :   /* Static anonymous unions are dealt with here.  */
   15127   1075341080 :   if (staticp && decl_context == TYPENAME
   15128            0 :       && declspecs->type
   15129   1075341080 :       && ANON_AGGR_TYPE_P (declspecs->type))
   15130              :     decl_context = FIELD;
   15131              : 
   15132              :   /* Warn about storage classes that are invalid for certain
   15133              :      kinds of declarations (parameters, typenames, etc.).  */
   15134   1075341080 :   if (thread_p
   15135        20547 :       && ((storage_class
   15136        20547 :            && storage_class != sc_extern
   15137          528 :            && storage_class != sc_static)
   15138        20536 :           || typedef_p))
   15139              :     {
   15140           17 :       location_t loc
   15141           17 :         = min_location (declspecs->locations[ds_thread],
   15142              :                         declspecs->locations[ds_storage_class]);
   15143           17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   15144           17 :       thread_p = false;
   15145              :     }
   15146   1075341080 :   if (decl_context != NORMAL
   15147    901247116 :       && ((storage_class != sc_none
   15148    901247116 :            && storage_class != sc_mutable)
   15149    877057127 :           || thread_p))
   15150              :     {
   15151     24189992 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   15152           36 :           && (storage_class == sc_register
   15153           36 :               || storage_class == sc_auto))
   15154              :         ;
   15155     24189956 :       else if (typedef_p)
   15156              :         ;
   15157     24189956 :       else if (decl_context == FIELD
   15158              :                /* C++ allows static class elements.  */
   15159     24189956 :                && storage_class == sc_static)
   15160              :         /* C++ also allows inlines and signed and unsigned elements,
   15161              :            but in those cases we don't come in here.  */
   15162              :         ;
   15163              :       else
   15164              :         {
   15165           15 :           location_t loc
   15166           15 :             = min_location (declspecs->locations[ds_thread],
   15167              :                             declspecs->locations[ds_storage_class]);
   15168           15 :           if (decl_context == FIELD)
   15169           15 :             error_at (loc, "storage class specified for %qs", name);
   15170            0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   15171            0 :             error_at (loc, "storage class specified for parameter %qs", name);
   15172              :           else
   15173            0 :             error_at (loc, "storage class specified for typename");
   15174           15 :           if (storage_class == sc_register
   15175           15 :               || storage_class == sc_auto
   15176           15 :               || storage_class == sc_extern
   15177            3 :               || thread_p)
   15178           15 :             storage_class = sc_none;
   15179              :         }
   15180              :     }
   15181   1051151088 :   else if (storage_class == sc_extern && funcdef_flag
   15182   1051151088 :            && ! toplevel_bindings_p ())
   15183            0 :     error ("nested function %qs declared %<extern%>", name);
   15184   1051151088 :   else if (toplevel_bindings_p ())
   15185              :     {
   15186    489732460 :       if (storage_class == sc_auto)
   15187            2 :         error_at (declspecs->locations[ds_storage_class],
   15188              :                   "top-level declaration of %qs specifies %<auto%>", name);
   15189              :     }
   15190    561418628 :   else if (thread_p
   15191    561418628 :            && storage_class != sc_extern
   15192          243 :            && storage_class != sc_static)
   15193              :     {
   15194          210 :       if (declspecs->gnu_thread_keyword_p)
   15195           49 :         pedwarn (declspecs->locations[ds_thread],
   15196           49 :                  0, "function-scope %qs implicitly auto and "
   15197              :                  "declared %<__thread%>", name);
   15198              : 
   15199              :       /* When thread_local is applied to a variable of block scope the
   15200              :          storage-class-specifier static is implied if it does not appear
   15201              :          explicitly.  */
   15202          210 :       storage_class = declspecs->storage_class = sc_static;
   15203          210 :       staticp = 1;
   15204              :     }
   15205              : 
   15206   1075341080 :   if (storage_class && friendp)
   15207              :     {
   15208           12 :       error_at (min_location (declspecs->locations[ds_thread],
   15209              :                               declspecs->locations[ds_storage_class]),
   15210              :                 "storage class specifiers invalid in friend function "
   15211              :                 "declarations");
   15212           12 :       storage_class = sc_none;
   15213           12 :       staticp = 0;
   15214              :     }
   15215              : 
   15216   1075341080 :   if (!id_declarator)
   15217              :     unqualified_id = NULL_TREE;
   15218              :   else
   15219              :     {
   15220    605302388 :       unqualified_id = id_declarator->u.id.unqualified_name;
   15221    605302388 :       switch (TREE_CODE (unqualified_id))
   15222              :         {
   15223      3328355 :         case BIT_NOT_EXPR:
   15224      3328355 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   15225      3328355 :           if (TYPE_P (unqualified_id))
   15226      3328352 :             unqualified_id = constructor_name (unqualified_id);
   15227              :           break;
   15228              : 
   15229              :         case IDENTIFIER_NODE:
   15230              :         case TEMPLATE_ID_EXPR:
   15231              :           break;
   15232              : 
   15233            0 :         default:
   15234            0 :           gcc_unreachable ();
   15235              :         }
   15236              :     }
   15237              : 
   15238   1075341080 :   if (declspecs->std_attributes)
   15239              :     {
   15240          795 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   15241          795 :       auto_diagnostic_group d;
   15242          795 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   15243          795 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   15244          792 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   15245              :                 "is ignored");
   15246          795 :     }
   15247              : 
   15248              :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   15249   1075341080 :   bool is_xobj_member_function = false;
   15250              :   /* Determine the type of the entity declared by recurring on the
   15251              :      declarator.  */
   15252   1475931495 :   for (; declarator; declarator = declarator->declarator)
   15253              :     {
   15254   1006138390 :       const cp_declarator *inner_declarator;
   15255   1006138390 :       tree attrs;
   15256              : 
   15257   1006138390 :       if (type == error_mark_node)
   15258          607 :         return error_mark_node;
   15259              : 
   15260   1006138062 :       attrs = declarator->attributes;
   15261   1006138062 :       if (attrs)
   15262              :         {
   15263        13373 :           int attr_flags;
   15264              : 
   15265        13373 :           attr_flags = 0;
   15266        13373 :           if (declarator->kind == cdk_id)
   15267        12665 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   15268        13373 :           if (declarator->kind == cdk_function)
   15269          691 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   15270        13373 :           if (declarator->kind == cdk_array)
   15271            2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   15272        13373 :           tree late_attrs = NULL_TREE;
   15273        13373 :           if (decl_context != PARM && decl_context != TYPENAME)
   15274              :             /* Assume that any attributes that get applied late to
   15275              :                templates will DTRT when applied to the declaration
   15276              :                as a whole.  */
   15277        13361 :             late_attrs = splice_template_attributes (&attrs, type);
   15278        13373 :           returned_attrs = decl_attributes (&type,
   15279              :                                             attr_chainon (returned_attrs,
   15280              :                                                           attrs),
   15281              :                                             attr_flags);
   15282        13373 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   15283              :         }
   15284              : 
   15285   1006138062 :       inner_declarator = declarator->declarator;
   15286              : 
   15287              :       /* We don't want to warn in parameter context because we don't
   15288              :          yet know if the parse will succeed, and this might turn out
   15289              :          to be a constructor call.  */
   15290   1006138062 :       if (decl_context != PARM
   15291   1006138062 :           && decl_context != TYPENAME
   15292    584625424 :           && !typedef_p
   15293    534736624 :           && declarator->parenthesized != UNKNOWN_LOCATION
   15294              :           /* If the type is class-like and the inner name used a
   15295              :              global namespace qualifier, we need the parens.
   15296              :              Unfortunately all we can tell is whether a qualified name
   15297              :              was used or not.  */
   15298   1006138243 :           && !(inner_declarator
   15299          126 :                && inner_declarator->kind == cdk_id
   15300          108 :                && inner_declarator->u.id.qualifying_scope
   15301           18 :                && (MAYBE_CLASS_TYPE_P (type)
   15302           12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   15303              :         {
   15304          169 :           auto_diagnostic_group d;
   15305          169 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   15306              :                           "unnecessary parentheses in declaration of %qs",
   15307              :                           name))
   15308              :             {
   15309           42 :               gcc_rich_location iloc (declarator->parenthesized);
   15310           42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   15311           42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   15312           42 :               inform (&iloc, "remove parentheses");
   15313           42 :             }
   15314          169 :         }
   15315   1006138062 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   15316              :         break;
   15317              : 
   15318    400590694 :       switch (declarator->kind)
   15319              :         {
   15320      3714607 :         case cdk_array:
   15321      7429214 :           type = create_array_type_for_decl (dname, type,
   15322      3714607 :                                              declarator->u.array.bounds,
   15323      3714607 :                                              declarator->id_loc);
   15324      3714607 :           if (!valid_array_size_p (dname
   15325              :                                    ? declarator->id_loc : input_location,
   15326              :                                    type, dname))
   15327          267 :             type = error_mark_node;
   15328              : 
   15329      3714607 :           if (declarator->std_attributes)
   15330              :             /* [dcl.array]/1:
   15331              : 
   15332              :                The optional attribute-specifier-seq appertains to the
   15333              :                array type.  */
   15334          209 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15335              :           break;
   15336              : 
   15337    196966744 :         case cdk_function:
   15338    196966744 :           {
   15339    196966744 :             tree arg_types;
   15340    196966744 :             int funcdecl_p;
   15341              : 
   15342              :             /* Declaring a function type.  */
   15343              : 
   15344              :             /* Pick up type qualifiers which should be applied to `this'.  */
   15345    196966744 :             memfn_quals = declarator->u.function.qualifiers;
   15346              :             /* Pick up virt-specifiers.  */
   15347    196966744 :             virt_specifiers = declarator->u.function.virt_specifiers;
   15348              :             /* And ref-qualifier, too */
   15349    196966744 :             rqual = declarator->u.function.ref_qualifier;
   15350              :             /* And tx-qualifier.  */
   15351    196966744 :             tree tx_qual = declarator->u.function.tx_qualifier;
   15352              :             /* Pick up the exception specifications.  */
   15353    196966744 :             raises = declarator->u.function.exception_specification;
   15354              :             /* If the exception-specification is ill-formed, let's pretend
   15355              :                there wasn't one.  */
   15356    196966744 :             if (raises == error_mark_node)
   15357            9 :               raises = NULL_TREE;
   15358              : 
   15359    393933488 :             auto find_xobj_parm = [](tree parm_list)
   15360              :               {
   15361              :                 /* There is no need to iterate over the list,
   15362              :                    only the first parm can be a valid xobj parm.  */
   15363    393700719 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   15364              :                   return NULL_TREE;
   15365              :                 /* If we make it here, we are looking at an xobj parm.
   15366              : 
   15367              :                    Non-null 'purpose' usually means the parm has a default
   15368              :                    argument, we don't want to violate this assumption.  */
   15369        94710 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   15370        94710 :                 return TREE_VALUE (parm_list);
   15371              :               };
   15372              : 
   15373    196966744 :             tree xobj_parm
   15374    196966744 :               = find_xobj_parm (declarator->u.function.parameters);
   15375    196966744 :             is_xobj_member_function = xobj_parm;
   15376              : 
   15377    196966744 :             if (xobj_parm && cxx_dialect < cxx23)
   15378        42084 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   15379              :                        "explicit object member function only available "
   15380              :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   15381              : 
   15382    196966744 :             if (xobj_parm && decl_context == TYPENAME)
   15383              :               {
   15384              :                 /* We inform in every case, just differently depending on what
   15385              :                    case it is.  */
   15386            9 :                 auto_diagnostic_group d;
   15387            9 :                 bool ptr_type = true;
   15388              :                 /* If declarator->kind is cdk_function and we are at the end of
   15389              :                    the declarator chain, we are looking at a function type.  */
   15390            9 :                 if (!declarator->declarator)
   15391              :                   {
   15392            3 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15393              :                               "a function type cannot "
   15394              :                               "have an explicit object parameter");
   15395            3 :                     ptr_type = false;
   15396              :                   }
   15397            6 :                 else if (declarator->declarator->kind == cdk_pointer)
   15398            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15399              :                             "a pointer to function type cannot "
   15400              :                             "have an explicit object parameter");
   15401            3 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   15402            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15403              :                             "a pointer to member function type "
   15404              :                             "cannot have an explicit object parameter");
   15405              :                 else
   15406            0 :                   gcc_unreachable ();
   15407              : 
   15408              :                 /* The locations being used here are probably not correct.  */
   15409            6 :                 if (ptr_type)
   15410            6 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15411              :                           "the type of a pointer to explicit object member "
   15412              :                           "function is a regular pointer to function type");
   15413              :                 else
   15414            3 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15415              :                           "the type of an explicit object "
   15416              :                           "member function is a regular function type");
   15417              :                 /* Ideally we should synthesize the correct syntax
   15418              :                    for the user, perhaps this could be added later.  */
   15419            9 :               }
   15420              :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   15421              :                the first parm node will never erroneously be detected here.  */
   15422    196966744 :             {
   15423    196966744 :               auto_diagnostic_group d;
   15424    196966744 :               bool bad_xobj_parm_encountered = false;
   15425    196966744 :               for (tree parm = declarator->u.function.parameters;
   15426    488410393 :                    parm && parm != void_list_node;
   15427    291443649 :                    parm = TREE_CHAIN (parm))
   15428              :                 {
   15429    291443649 :                   if (TREE_PURPOSE (parm) != this_identifier)
   15430    291443640 :                     continue;
   15431            9 :                   bad_xobj_parm_encountered = true;
   15432            9 :                   TREE_PURPOSE (parm) = NULL_TREE;
   15433            9 :                   gcc_rich_location bad_xobj_parm
   15434            9 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   15435            9 :                   error_at (&bad_xobj_parm,
   15436              :                             "only the first parameter of a member function "
   15437              :                             "can be declared as an explicit object parameter");
   15438            9 :                 }
   15439    196966744 :               if (bad_xobj_parm_encountered && xobj_parm)
   15440            0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   15441              :                         "valid explicit object parameter declared here");
   15442    196966744 :             }
   15443              : 
   15444    196966744 :             if (reqs)
   15445            3 :               error_at (location_of (reqs), "requires-clause on return type");
   15446    196966744 :             reqs = declarator->u.function.requires_clause;
   15447              : 
   15448              :             /* Say it's a definition only for the CALL_EXPR
   15449              :                closest to the identifier.  */
   15450    196966744 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   15451              : 
   15452              :             /* Handle a late-specified return type.  */
   15453    196966744 :             tree late_return_type = declarator->u.function.late_return_type;
   15454    196966744 :             if (tree auto_node = type_uses_auto (type))
   15455              :               {
   15456      8997274 :                 if (!late_return_type)
   15457              :                   {
   15458      5278247 :                     if (!funcdecl_p)
   15459              :                       /* auto (*fp)() = f; is OK.  */;
   15460      5278213 :                     else if (current_class_type
   15461      9708409 :                              && LAMBDA_TYPE_P (current_class_type))
   15462              :                       /* OK for C++11 lambdas.  */;
   15463      3404932 :                     else if (cxx_dialect < cxx14)
   15464              :                       {
   15465            7 :                         auto_diagnostic_group d;
   15466            7 :                         error_at (typespec_loc, "%qs function uses "
   15467              :                                   "%<auto%> type specifier without "
   15468              :                                   "trailing return type", name);
   15469            7 :                         inform (typespec_loc,
   15470              :                                 "deduced return type only available "
   15471              :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   15472            7 :                       }
   15473      3404925 :                     else if (virtualp)
   15474              :                       {
   15475            6 :                         error_at (typespec_loc, "virtual function "
   15476              :                                   "cannot have deduced return type");
   15477            6 :                         virtualp = false;
   15478              :                       }
   15479              :                   }
   15480      3719027 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   15481              :                   {
   15482           15 :                     error_at (typespec_loc, "%qs function with trailing "
   15483              :                               "return type has %qT as its type rather "
   15484              :                               "than plain %<auto%>", name, type);
   15485          276 :                     return error_mark_node;
   15486              :                   }
   15487      3719012 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   15488              :                   {
   15489            9 :                     if (funcdecl_p)
   15490            3 :                       error_at (typespec_loc,
   15491              :                                 "%qs function with trailing return type "
   15492              :                                 "has %<decltype(auto)%> as its type "
   15493              :                                 "rather than plain %<auto%>", name);
   15494              :                     else
   15495            6 :                       error_at (typespec_loc,
   15496              :                                 "invalid use of %<decltype(auto)%>");
   15497            9 :                     return error_mark_node;
   15498              :                   }
   15499      3719003 :                 else if (is_constrained_auto (type))
   15500              :                   {
   15501            6 :                     if (funcdecl_p)
   15502            3 :                       error_at (typespec_loc,
   15503              :                                 "%qs function with trailing return type "
   15504              :                                 "has constrained %<auto%> type specifier "
   15505              :                                 "rather than plain %<auto%>",
   15506              :                                 name);
   15507              :                     else
   15508            3 :                       error_at (typespec_loc,
   15509              :                                 "invalid use of constrained %<auto%> type");
   15510            6 :                     return error_mark_node;
   15511              :                   }
   15512      8997244 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   15513      8997244 :                 if (!tmpl)
   15514      7737892 :                   if (tree late_auto = type_uses_auto (late_return_type))
   15515        40126 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   15516      7737892 :                 if (tmpl)
   15517              :                   {
   15518      1259358 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   15519              :                       {
   15520           13 :                         auto_diagnostic_group g;
   15521           13 :                         error_at (typespec_loc, "deduced class "
   15522              :                                   "type %qD in function return type",
   15523           13 :                                   DECL_NAME (tmpl));
   15524           13 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15525              :                                 "%qD declared here", tmpl);
   15526           13 :                         return error_mark_node;
   15527           13 :                       }
   15528      1259345 :                     else if (!late_return_type)
   15529              :                       {
   15530            3 :                         auto_diagnostic_group d;
   15531            3 :                         error_at (declarator->id_loc, "deduction guide "
   15532              :                                   "for %qT must have trailing return "
   15533            3 :                                   "type", TREE_TYPE (tmpl));
   15534            3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15535              :                                 "%qD declared here", tmpl);
   15536            3 :                         return error_mark_node;
   15537            3 :                       }
   15538      1259342 :                     else if (CLASS_TYPE_P (late_return_type)
   15539      1259342 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   15540      2518684 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   15541              :                                   == tmpl))
   15542              :                       /* OK */;
   15543              :                     else
   15544            0 :                       error ("trailing return type %qT of deduction guide "
   15545              :                               "is not a specialization of %qT",
   15546            0 :                               late_return_type, TREE_TYPE (tmpl));
   15547              :                   }
   15548              :               }
   15549    187969470 :             else if (late_return_type
   15550    187969470 :                      && sfk != sfk_conversion)
   15551              :               {
   15552           37 :                 if (late_return_type == error_mark_node)
   15553              :                   return error_mark_node;
   15554           37 :                 if (cxx_dialect < cxx11)
   15555              :                   /* Not using maybe_warn_cpp0x because this should
   15556              :                      always be an error.  */
   15557            1 :                   error_at (typespec_loc,
   15558              :                             "trailing return type only available "
   15559              :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   15560              :                 else
   15561           36 :                   error_at (typespec_loc, "%qs function with trailing "
   15562              :                             "return type not declared with %<auto%> "
   15563              :                             "type specifier", name);
   15564           37 :                 return error_mark_node;
   15565              :               }
   15566    196966661 :             if (late_return_type && sfk == sfk_conversion)
   15567              :               {
   15568           14 :                 error ("a conversion function cannot have a trailing return type");
   15569           14 :                 return error_mark_node;
   15570              :               }
   15571    196966647 :             type = splice_late_return_type (type, late_return_type);
   15572    196966647 :             if (type == error_mark_node)
   15573              :               return error_mark_node;
   15574              : 
   15575    196966569 :             if (late_return_type)
   15576              :               {
   15577      3718905 :                 late_return_type_p = true;
   15578      3718905 :                 type_quals = cp_type_quals (type);
   15579              :               }
   15580              : 
   15581    196966569 :             if (type_quals != TYPE_UNQUALIFIED)
   15582              :               {
   15583              :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   15584              :                    warning for
   15585              :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   15586              :                     because there the qualifier matters.  */
   15587        12304 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   15588          232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   15589              :                               "qualifiers ignored on function return type");
   15590              :                 /* [dcl.fct] "A volatile-qualified return type is
   15591              :                    deprecated."  */
   15592        12304 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   15593          643 :                   warning_at (typespec_loc, OPT_Wvolatile,
   15594              :                               "%<volatile%>-qualified return type is "
   15595              :                               "deprecated");
   15596              : 
   15597              :                 /* We now know that the TYPE_QUALS don't apply to the
   15598              :                    decl, but to its return type.  */
   15599              :                 type_quals = TYPE_UNQUALIFIED;
   15600              :               }
   15601              : 
   15602              :             /* Error about some types functions can't return.  */
   15603              : 
   15604    196966569 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   15605              :               {
   15606           30 :                 error_at (typespec_loc, "%qs declared as function returning "
   15607              :                           "a function", name);
   15608           30 :                 return error_mark_node;
   15609              :               }
   15610    196966539 :             if (TREE_CODE (type) == ARRAY_TYPE)
   15611              :               {
   15612            6 :                 error_at (typespec_loc, "%qs declared as function returning "
   15613              :                           "an array", name);
   15614            6 :                 return error_mark_node;
   15615              :               }
   15616    196966533 :             if (constinit_p && funcdecl_p)
   15617              :               {
   15618           15 :                 error_at (declspecs->locations[ds_constinit],
   15619              :                           "%<constinit%> on function return type is not "
   15620              :                           "allowed");
   15621           15 :                 return error_mark_node;
   15622              :               }
   15623              : 
   15624    196966518 :             if (check_decltype_auto (typespec_loc, type))
   15625           50 :               return error_mark_node;
   15626              : 
   15627    196966468 :             if (ctype == NULL_TREE
   15628    196966468 :                 && decl_context == FIELD
   15629              :                 && funcdecl_p
   15630    113817649 :                 && friendp == 0)
   15631    106720359 :               ctype = current_class_type;
   15632              : 
   15633    196966468 :             if (ctype && (sfk == sfk_constructor
   15634    106720359 :                           || sfk == sfk_destructor))
   15635              :               {
   15636              :                 /* We are within a class's scope. If our declarator name
   15637              :                    is the same as the class name, and we are defining
   15638              :                    a function, then it is a constructor/destructor, and
   15639              :                    therefore returns a void type.  */
   15640              : 
   15641              :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   15642              :                    const or volatile.  A destructor may not be static.
   15643              :                    A destructor may not be declared with ref-qualifier.
   15644              : 
   15645              :                    ISO C++ 12.1.  A constructor may not be declared
   15646              :                    const or volatile.  A constructor may not be
   15647              :                    virtual.  A constructor may not be static.
   15648              :                    A constructor may not be declared with ref-qualifier. */
   15649     27294688 :                 if (staticp == 2)
   15650            9 :                   error_at (declspecs->locations[ds_storage_class],
   15651              :                             (flags == DTOR_FLAG)
   15652              :                             ? G_("destructor cannot be static member "
   15653              :                                  "function")
   15654              :                             : G_("constructor cannot be static member "
   15655              :                                  "function"));
   15656     27294688 :                 if (memfn_quals)
   15657              :                   {
   15658            9 :                     error ((flags == DTOR_FLAG)
   15659              :                            ? G_("destructors may not be cv-qualified")
   15660              :                            : G_("constructors may not be cv-qualified"));
   15661            9 :                     memfn_quals = TYPE_UNQUALIFIED;
   15662              :                   }
   15663              : 
   15664     27294688 :                 if (rqual)
   15665              :                   {
   15666            6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   15667            6 :                     error ((flags == DTOR_FLAG)
   15668              :                            ? G_("destructors may not be ref-qualified")
   15669              :                            : G_("constructors may not be ref-qualified"));
   15670            6 :                     rqual = REF_QUAL_NONE;
   15671              :                   }
   15672              : 
   15673     27294688 :                 if (decl_context == FIELD
   15674     27294688 :                     && !member_function_or_else (ctype,
   15675              :                                                  current_class_type,
   15676              :                                                  flags))
   15677            0 :                   return error_mark_node;
   15678              : 
   15679     27294688 :                 if (flags != DTOR_FLAG)
   15680              :                   {
   15681              :                     /* It's a constructor.  */
   15682     24135404 :                     if (explicitp == 1)
   15683      5641646 :                       explicitp = 2;
   15684     24135404 :                     if (virtualp)
   15685              :                       {
   15686            3 :                         permerror (declspecs->locations[ds_virtual],
   15687              :                                    "constructors cannot be declared %<virtual%>");
   15688            3 :                         virtualp = 0;
   15689              :                       }
   15690     24135404 :                     if (decl_context == FIELD
   15691     24135404 :                         && sfk != sfk_constructor)
   15692            0 :                       return error_mark_node;
   15693              :                   }
   15694     27294688 :                 if (decl_context == FIELD)
   15695     27294688 :                   staticp = 0;
   15696              :               }
   15697    169671780 :             else if (friendp)
   15698              :               {
   15699      6774679 :                 if (virtualp)
   15700              :                   {
   15701              :                     /* Cannot be both friend and virtual.  */
   15702           12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15703           12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   15704           12 :                     error_at (&richloc, "virtual functions cannot be friends");
   15705           12 :                     friendp = 0;
   15706           12 :                   }
   15707      6774679 :                 if (decl_context == NORMAL)
   15708            0 :                   error_at (declarator->id_loc,
   15709              :                             "friend declaration not in class definition");
   15710      6774679 :                 if (current_function_decl && funcdef_flag)
   15711              :                   {
   15712            9 :                     error_at (declarator->id_loc,
   15713              :                               "cannot define friend function %qs in a local "
   15714              :                               "class definition", name);
   15715            9 :                     friendp = 0;
   15716              :                   }
   15717              :                 /* [class.friend]/6: A function can be defined in a friend
   15718              :                    declaration if the function name is unqualified.  */
   15719      6774679 :                 if (funcdef_flag && in_namespace)
   15720              :                   {
   15721            6 :                     if (in_namespace == global_namespace)
   15722            3 :                       error_at (declarator->id_loc,
   15723              :                                 "friend function definition %qs cannot have "
   15724              :                                 "a name qualified with %<::%>", name);
   15725              :                     else
   15726            3 :                       error_at (declarator->id_loc,
   15727              :                                 "friend function definition %qs cannot have "
   15728              :                                 "a name qualified with %<%D::%>", name,
   15729              :                                 in_namespace);
   15730              :                   }
   15731              :               }
   15732    162897101 :             else if (ctype && sfk == sfk_conversion)
   15733              :               {
   15734      1051414 :                 if (explicitp == 1)
   15735              :                   {
   15736       491985 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   15737       491985 :                     explicitp = 2;
   15738              :                   }
   15739              :               }
   15740    161845687 :             else if (sfk == sfk_deduction_guide)
   15741              :               {
   15742      1259342 :                 if (explicitp == 1)
   15743    196966468 :                   explicitp = 2;
   15744              :               }
   15745              : 
   15746    196966468 :             if (xobj_parm)
   15747              :               {
   15748        94710 :                 if (!ctype
   15749          110 :                     && (decl_context == NORMAL || friendp)
   15750          101 :                     && (in_namespace
   15751          101 :                         || !declarator->declarator->u.id.qualifying_scope))
   15752              :                   {
   15753           24 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15754              :                               "a non-member function cannot have "
   15755              :                               "an explicit object parameter");
   15756           24 :                     is_xobj_member_function = false;
   15757              :                   }
   15758              :                 else
   15759              :                   {
   15760        94686 :                     if (virtualp)
   15761              :                       {
   15762           24 :                         auto_diagnostic_group d;
   15763           24 :                         error_at (declspecs->locations[ds_virtual],
   15764              :                                   "an explicit object member function cannot "
   15765              :                                   "be %<virtual%>");
   15766           24 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15767              :                                 "explicit object parameter declared here");
   15768           24 :                         virtualp = false;
   15769           24 :                       }
   15770        94686 :                     if (staticp >= 2)
   15771              :                       {
   15772            3 :                         auto_diagnostic_group d;
   15773            3 :                         error_at (declspecs->locations[ds_storage_class],
   15774              :                                   "an explicit object member function cannot "
   15775              :                                   "be %<static%>");
   15776            3 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15777              :                                 "explicit object parameter declared here");
   15778            3 :                       }
   15779        94686 :                     if (unqualified_id
   15780    197061145 :                         && identifier_p (unqualified_id)
   15781       189363 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15782           12 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15783              :                                 "%qD cannot be an explicit object member "
   15784              :                                 "function", unqualified_id);
   15785              :                   }
   15786              :               }
   15787    196966468 :             tree pushed_scope = NULL_TREE;
   15788    196966468 :             if (funcdecl_p
   15789    196966468 :                 && decl_context != FIELD
   15790     81189969 :                 && inner_declarator->u.id.qualifying_scope
   15791    206349905 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   15792      9227481 :               pushed_scope
   15793      9227481 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   15794              : 
   15795    196966468 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   15796              : 
   15797    196966468 :             if (pushed_scope)
   15798      9227481 :               pop_scope (pushed_scope);
   15799              : 
   15800    196966468 :             if (inner_declarator
   15801    196576413 :                 && inner_declarator->kind == cdk_id
   15802    194685007 :                 && inner_declarator->u.id.sfk == sfk_destructor
   15803      3328346 :                 && arg_types != void_list_node)
   15804              :               {
   15805           21 :                 error_at (declarator->id_loc,
   15806              :                           "destructors may not have parameters");
   15807           21 :                 arg_types = void_list_node;
   15808           21 :                 parms = NULL_TREE;
   15809           21 :                 is_xobj_member_function = false;
   15810              :               }
   15811              : 
   15812    196966468 :             type = cp_build_function_type (type, arg_types);
   15813              : 
   15814    196966468 :             tree attrs = declarator->std_attributes;
   15815    196966468 :             if (tx_qual)
   15816              :               {
   15817          242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   15818              :                 /* transaction_safe applies to the type, but
   15819              :                    transaction_safe_dynamic applies to the function.  */
   15820          242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   15821          213 :                   attrs = attr_chainon (attrs, att);
   15822              :                 else
   15823           29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   15824              :               }
   15825              : 
   15826              :             /* Actually apply the contract specifiers to the declaration.  */
   15827    196966468 :             if (flag_contracts)
   15828     23229080 :               contract_specifiers
   15829              :                 = contract_specifiers_concat
   15830     23229080 :                     (contract_specifiers,
   15831     23229080 :                      declarator->u.function.contract_specifiers);
   15832              : 
   15833    196966468 :             if (attrs)
   15834              :               /* [dcl.fct]/2:
   15835              : 
   15836              :                  The optional attribute-specifier-seq appertains to
   15837              :                  the function type.  */
   15838          513 :               cplus_decl_attributes (&type, attrs, 0);
   15839              : 
   15840    196966468 :             if (raises)
   15841     78401968 :               type = build_exception_variant (type, raises);
   15842              :           }
   15843    196966468 :           break;
   15844              : 
   15845    199909343 :         case cdk_pointer:
   15846    199909343 :         case cdk_reference:
   15847    199909343 :         case cdk_ptrmem:
   15848              :           /* Filter out pointers-to-references and references-to-references.
   15849              :              We can get these if a TYPE_DECL is used.  */
   15850              : 
   15851    199909343 :           if (TYPE_REF_P (type))
   15852              :             {
   15853          240 :               if (declarator->kind != cdk_reference)
   15854              :                 {
   15855            3 :                   error ("cannot declare pointer to %q#T", type);
   15856            3 :                   type = TREE_TYPE (type);
   15857              :                 }
   15858              : 
   15859              :               /* In C++0x, we allow reference to reference declarations
   15860              :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   15861              :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   15862              :                  check for direct reference to reference declarations, which
   15863              :                  are still forbidden, occurs below. Reasoning behind the change
   15864              :                  can be found in DR106, DR540, and the rvalue reference
   15865              :                  proposals. */
   15866          237 :               else if (cxx_dialect == cxx98)
   15867              :                 {
   15868            0 :                   error ("cannot declare reference to %q#T", type);
   15869            0 :                   type = TREE_TYPE (type);
   15870              :                 }
   15871              :             }
   15872    199909103 :           else if (VOID_TYPE_P (type))
   15873              :             {
   15874      5315830 :               if (declarator->kind == cdk_reference)
   15875            4 :                 error ("cannot declare reference to %q#T", type);
   15876      5315826 :               else if (declarator->kind == cdk_ptrmem)
   15877            3 :                 error ("cannot declare pointer to %q#T member", type);
   15878              :             }
   15879              : 
   15880              :           /* We now know that the TYPE_QUALS don't apply to the decl,
   15881              :              but to the target of the pointer.  */
   15882    199909343 :           type_quals = TYPE_UNQUALIFIED;
   15883              : 
   15884              :           /* This code used to handle METHOD_TYPE, but I don't think it's
   15885              :              possible to get it here anymore.  */
   15886    199909343 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   15887    199909343 :           if (declarator->kind == cdk_ptrmem
   15888      1142606 :               && TREE_CODE (type) == FUNCTION_TYPE)
   15889              :             {
   15890       924549 :               memfn_quals |= type_memfn_quals (type);
   15891       924549 :               if (rqual == REF_QUAL_NONE)
   15892       586429 :                 rqual = type_memfn_rqual (type);
   15893      1849098 :               type = build_memfn_type (type,
   15894       924549 :                                        declarator->u.pointer.class_type,
   15895              :                                        memfn_quals,
   15896              :                                        rqual);
   15897       924549 :               if (type == error_mark_node)
   15898              :                 return error_mark_node;
   15899              : 
   15900              :               rqual = REF_QUAL_NONE;
   15901              :               memfn_quals = TYPE_UNQUALIFIED;
   15902              :             }
   15903              : 
   15904    199909340 :           if (TREE_CODE (type) == FUNCTION_TYPE
   15905    199909340 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   15906      1041760 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   15907           15 :             error (declarator->kind == cdk_reference
   15908              :                    ? G_("cannot declare reference to qualified function type %qT")
   15909              :                    : G_("cannot declare pointer to qualified function type %qT"),
   15910              :                    type);
   15911              : 
   15912              :           /* When the pointed-to type involves components of variable size,
   15913              :              care must be taken to ensure that the size evaluation code is
   15914              :              emitted early enough to dominate all the possible later uses
   15915              :              and late enough for the variables on which it depends to have
   15916              :              been assigned.
   15917              : 
   15918              :              This is expected to happen automatically when the pointed-to
   15919              :              type has a name/declaration of it's own, but special attention
   15920              :              is required if the type is anonymous.
   15921              : 
   15922              :              We handle the NORMAL and FIELD contexts here by inserting a
   15923              :              dummy statement that just evaluates the size at a safe point
   15924              :              and ensures it is not deferred until e.g. within a deeper
   15925              :              conditional context (c++/43555).
   15926              : 
   15927              :              We expect nothing to be needed here for PARM or TYPENAME.
   15928              :              Evaluating the size at this point for TYPENAME would
   15929              :              actually be incorrect, as we might be in the middle of an
   15930              :              expression with side effects on the pointed-to type size
   15931              :              "arguments" prior to the pointer declaration point and the
   15932              :              size evaluation could end up prior to the side effects.  */
   15933              : 
   15934    199909340 :           if (!TYPE_NAME (type)
   15935      5621534 :               && (decl_context == NORMAL || decl_context == FIELD)
   15936       628042 :               && at_function_scope_p ()
   15937    199950063 :               && variably_modified_type_p (type, NULL_TREE))
   15938              :             {
   15939          119 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   15940              :                                              NULL_TREE, type);
   15941          119 :               add_decl_expr (TYPE_NAME (type));
   15942              :             }
   15943              : 
   15944    199909340 :           if (declarator->kind == cdk_reference)
   15945              :             {
   15946              :               /* In C++0x, the type we are creating a reference to might be
   15947              :                  a typedef which is itself a reference type. In that case,
   15948              :                  we follow the reference collapsing rules in
   15949              :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   15950              : 
   15951              :                  "If a typedef TD names a type that is a reference to a type
   15952              :                  T, an attempt to create the type 'lvalue reference to cv TD'
   15953              :                  creates the type 'lvalue reference to T,' while an attempt
   15954              :                  to create the type "rvalue reference to cv TD' creates the
   15955              :                  type TD."
   15956              :               */
   15957    134049908 :               if (VOID_TYPE_P (type))
   15958              :                 /* We already gave an error.  */;
   15959    134049904 :               else if (TYPE_REF_P (type))
   15960              :                 {
   15961          237 :                   if (declarator->u.reference.rvalue_ref)
   15962              :                     /* Leave type alone.  */;
   15963              :                   else
   15964          116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   15965              :                 }
   15966              :               else
   15967    134049667 :                 type = cp_build_reference_type
   15968    134049667 :                   (type, declarator->u.reference.rvalue_ref);
   15969              : 
   15970              :               /* In C++0x, we need this check for direct reference to
   15971              :                  reference declarations, which are forbidden by
   15972              :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   15973              :                  are only allowed indirectly through typedefs and template
   15974              :                  type arguments. Example:
   15975              : 
   15976              :                    void foo(int & &);      // invalid ref-to-ref decl
   15977              : 
   15978              :                    typedef int & int_ref;
   15979              :                    void foo(int_ref &);    // valid ref-to-ref decl
   15980              :               */
   15981    134049908 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   15982            2 :                 error ("cannot declare reference to %q#T, which is not "
   15983              :                        "a typedef or a template type argument", type);
   15984              :             }
   15985     65859432 :           else if (TREE_CODE (type) == METHOD_TYPE)
   15986       924546 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   15987     64934886 :           else if (declarator->kind == cdk_ptrmem)
   15988              :             {
   15989       218057 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   15990              :                           != NAMESPACE_DECL);
   15991       218057 :               if (declarator->u.pointer.class_type == error_mark_node)
   15992              :                 /* We will already have complained.  */
   15993            3 :                 type = error_mark_node;
   15994              :               else
   15995       218054 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   15996              :                                           type);
   15997              :             }
   15998              :           else
   15999     64716829 :             type = build_pointer_type (type);
   16000              : 
   16001              :           /* Process a list of type modifier keywords (such as
   16002              :              const or volatile) that were given inside the `*' or `&'.  */
   16003              : 
   16004    199909340 :           if (declarator->u.pointer.qualifiers)
   16005              :             {
   16006      8728691 :               type
   16007      8728691 :                 = cp_build_qualified_type (type,
   16008              :                                            declarator->u.pointer.qualifiers);
   16009      8728691 :               type_quals = cp_type_quals (type);
   16010              :             }
   16011              : 
   16012              :           /* Apply C++11 attributes to the pointer, and not to the
   16013              :              type pointed to.  This is unlike what is done for GNU
   16014              :              attributes above.  It is to comply with [dcl.ptr]/1:
   16015              : 
   16016              :                  [the optional attribute-specifier-seq (7.6.1) appertains
   16017              :                   to the pointer and not to the object pointed to].  */
   16018    199909340 :           if (declarator->std_attributes)
   16019          189 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   16020              : 
   16021              :           ctype = NULL_TREE;
   16022              :           break;
   16023              : 
   16024              :         case cdk_error:
   16025              :           break;
   16026              : 
   16027            0 :         default:
   16028            0 :           gcc_unreachable ();
   16029              :         }
   16030              :     }
   16031              : 
   16032   1075340473 :   id_loc = declarator ? declarator->id_loc : input_location;
   16033              : 
   16034   1075340473 :   if (innermost_code != cdk_function
   16035              :     /* Don't check this if it can be the artificial decltype(auto)
   16036              :        we created when building a constraint in a compound-requirement:
   16037              :        that the type-constraint is plain is going to be checked in
   16038              :        cp_parser_compound_requirement.  */
   16039   1075340473 :       && decl_context != TYPENAME
   16040   1075340473 :       && check_decltype_auto (id_loc, type))
   16041           20 :     return error_mark_node;
   16042              : 
   16043              :   /* A `constexpr' specifier used in an object declaration declares
   16044              :      the object as `const'.  */
   16045   1075340453 :   if (constexpr_p && innermost_code != cdk_function)
   16046              :     {
   16047              :       /* DR1688 says that a `constexpr' specifier in combination with
   16048              :          `volatile' is valid.  */
   16049              : 
   16050     20451454 :       if (!TYPE_REF_P (type))
   16051              :         {
   16052     20439616 :           type_quals |= TYPE_QUAL_CONST;
   16053     20439616 :           type = cp_build_qualified_type (type, type_quals);
   16054              :         }
   16055              :     }
   16056              : 
   16057    605301790 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   16058      2946265 :       && !FUNC_OR_METHOD_TYPE_P (type)
   16059   1077312082 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   16060              :     {
   16061            0 :       error ("template-id %qD used as a declarator",
   16062              :              unqualified_id);
   16063            0 :       unqualified_id = dname;
   16064              :     }
   16065              : 
   16066              :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   16067              :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   16068              :      we know that the function is static.  We take advantage of this
   16069              :      opportunity to do other processing that pertains to entities
   16070              :      explicitly declared to be class members.  Note that if DECLARATOR
   16071              :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   16072              :      would not have exited the loop above.  */
   16073   1075340453 :   if (declarator
   16074    605547351 :       && declarator->kind == cdk_id
   16075    605301790 :       && declarator->u.id.qualifying_scope
   16076   1085508222 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   16077              :     {
   16078      9735761 :       ctype = declarator->u.id.qualifying_scope;
   16079      9735761 :       ctype = TYPE_MAIN_VARIANT (ctype);
   16080      9735761 :       template_count = num_template_headers_for_class (ctype);
   16081              : 
   16082      9735761 :       if (ctype == current_class_type)
   16083              :         {
   16084           54 :           if (friendp)
   16085              :             {
   16086           15 :               permerror (declspecs->locations[ds_friend],
   16087              :                          "member functions are implicitly "
   16088              :                          "friends of their class");
   16089           15 :               friendp = 0;
   16090              :             }
   16091              :           else
   16092           39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   16093              :                        ctype, name);
   16094              :         }
   16095      9735707 :       else if (/* If the qualifying type is already complete, then we
   16096              :                   can skip the following checks.  */
   16097      9735707 :                !COMPLETE_TYPE_P (ctype)
   16098          154 :                && (/* If the function is being defined, then
   16099              :                       qualifying type must certainly be complete.  */
   16100              :                    funcdef_flag
   16101              :                    /* A friend declaration of "T::f" is OK, even if
   16102              :                       "T" is a template parameter.  But, if this
   16103              :                       function is not a friend, the qualifying type
   16104              :                       must be a class.  */
   16105          117 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   16106              :                    /* For a declaration, the type need not be
   16107              :                       complete, if either it is dependent (since there
   16108              :                       is no meaningful definition of complete in that
   16109              :                       case) or the qualifying class is currently being
   16110              :                       defined.  */
   16111          129 :                    || !(dependent_type_p (ctype)
   16112           24 :                         || currently_open_class (ctype)))
   16113              :                /* Check that the qualifying type is complete.  */
   16114      9735771 :                && !complete_type_or_else (ctype, NULL_TREE))
   16115           64 :         return error_mark_node;
   16116      9735643 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16117              :         {
   16118      9227743 :           if (current_class_type
   16119          289 :               && (!friendp || funcdef_flag || initialized))
   16120              :             {
   16121           57 :               error_at (id_loc, funcdef_flag || initialized
   16122              :                         ? G_("cannot define member function %<%T::%s%> "
   16123              :                              "within %qT")
   16124              :                         : G_("cannot declare member function %<%T::%s%> "
   16125              :                              "within %qT"),
   16126              :                         ctype, name, current_class_type);
   16127           48 :               return error_mark_node;
   16128              :             }
   16129              :         }
   16130       507900 :       else if (typedef_p && current_class_type)
   16131              :         {
   16132            0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   16133              :                     ctype, name, current_class_type);
   16134            0 :           return error_mark_node;
   16135              :         }
   16136              :     }
   16137              : 
   16138   1075340341 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   16139     60139308 :     ctype = current_class_type;
   16140              : 
   16141              :   /* Now TYPE has the actual type.  */
   16142              : 
   16143   1075340341 :   if (returned_attrs)
   16144              :     {
   16145         2970 :       if (attrlist)
   16146         2970 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   16147              :       else
   16148              :         attrlist = &returned_attrs;
   16149              :     }
   16150              : 
   16151   1075340341 :   if (declarator
   16152    605547239 :       && declarator->kind == cdk_id
   16153    605301678 :       && declarator->std_attributes
   16154       594263 :       && attrlist != NULL)
   16155              :     {
   16156              :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   16157              :          a declarator-id appertains to the entity that is declared.  */
   16158       594260 :       if (declarator->std_attributes != error_mark_node)
   16159              :         {
   16160       594242 :           if (flag_reflection
   16161              :               && declarator->std_attributes != error_mark_node
   16162        29196 :               && lookup_annotation (declarator->std_attributes)
   16163           40 :               && *attrlist != error_mark_node
   16164       594282 :               && lookup_annotation (*attrlist))
   16165              :             /* If there are annotations in both lists, ensure
   16166              :                declarator->std_attributes go after *attrlist.  See
   16167              :                PR124399.  */
   16168           14 :             *attrlist = chainon (copy_list (*attrlist),
   16169           14 :                                  declarator->std_attributes);
   16170              :           else
   16171       594228 :             *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   16172              :         }
   16173              :       else
   16174              :         /* We should have already diagnosed the issue (c++/78344).  */
   16175           18 :         gcc_assert (seen_error ());
   16176              :     }
   16177              : 
   16178              :   /* Handle parameter packs. */
   16179   1075340341 :   if (parameter_pack_p)
   16180              :     {
   16181      3190928 :       if (decl_context == PARM)
   16182              :         /* Turn the type into a pack expansion.*/
   16183      3190928 :         type = make_pack_expansion (type);
   16184              :       else
   16185            0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   16186              :     }
   16187              : 
   16188   1075340341 :   if ((decl_context == FIELD || decl_context == PARM)
   16189    477569538 :       && !processing_template_decl
   16190   1227317283 :       && variably_modified_type_p (type, NULL_TREE))
   16191              :     {
   16192           12 :       if (decl_context == FIELD)
   16193            6 :         error_at (id_loc,
   16194              :                   "data member may not have variably modified type %qT", type);
   16195              :       else
   16196            6 :         error_at (id_loc,
   16197              :                   "parameter may not have variably modified type %qT", type);
   16198           12 :       type = error_mark_node;
   16199              :     }
   16200              : 
   16201   1075340341 :   if (explicitp == 1 || (explicitp && friendp))
   16202              :     {
   16203              :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   16204              :          in the declaration of a constructor or conversion function within
   16205              :          a class definition.  */
   16206           74 :       if (!current_class_type)
   16207           59 :         error_at (declspecs->locations[ds_explicit],
   16208              :                   "%<explicit%> outside class declaration");
   16209           15 :       else if (friendp)
   16210           12 :         error_at (declspecs->locations[ds_explicit],
   16211              :                   "%<explicit%> in friend declaration");
   16212              :       else
   16213            3 :         error_at (declspecs->locations[ds_explicit],
   16214              :                   "only declarations of constructors and conversion operators "
   16215              :                   "can be %<explicit%>");
   16216              :       explicitp = 0;
   16217              :     }
   16218              : 
   16219   1075340341 :   if (storage_class == sc_mutable)
   16220              :     {
   16221       139152 :       location_t sloc = declspecs->locations[ds_storage_class];
   16222       139152 :       if (decl_context != FIELD || friendp)
   16223              :         {
   16224           30 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   16225              :                     name);
   16226           30 :           storage_class = sc_none;
   16227              :         }
   16228       139122 :       else if (decl_context == TYPENAME || typedef_p)
   16229              :         {
   16230            0 :           error_at (sloc,
   16231              :                     "non-object member %qs cannot be declared %<mutable%>",
   16232              :                     name);
   16233            0 :           storage_class = sc_none;
   16234              :         }
   16235       139122 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   16236              :         {
   16237            3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   16238              :                     name);
   16239            3 :           storage_class = sc_none;
   16240              :         }
   16241       139119 :       else if (staticp)
   16242              :         {
   16243            0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   16244              :                     name);
   16245            0 :           storage_class = sc_none;
   16246              :         }
   16247       139119 :       else if (type_quals & TYPE_QUAL_CONST)
   16248              :         {
   16249            9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   16250              :                     name);
   16251            9 :           storage_class = sc_none;
   16252              :         }
   16253       139110 :       else if (TYPE_REF_P (type))
   16254              :         {
   16255            6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   16256              :                      name);
   16257            6 :           storage_class = sc_none;
   16258              :         }
   16259              :     }
   16260              : 
   16261              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   16262   1075340341 :   if (typedef_p && decl_context != TYPENAME)
   16263              :     {
   16264     48759052 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   16265     48759052 :       tree decl;
   16266              : 
   16267     48759052 :       if (funcdef_flag)
   16268              :         {
   16269            6 :           if (decl_context == NORMAL)
   16270            3 :             error_at (id_loc,
   16271              :                       "typedef may not be a function definition");
   16272              :           else
   16273            3 :             error_at (id_loc,
   16274              :                       "typedef may not be a member function definition");
   16275            6 :           return error_mark_node;
   16276              :         }
   16277              : 
   16278              :       /* This declaration:
   16279              : 
   16280              :            typedef void f(int) const;
   16281              : 
   16282              :          declares a function type which is not a member of any
   16283              :          particular class, but which is cv-qualified; for
   16284              :          example "f S::*" declares a pointer to a const-qualified
   16285              :          member function of S.  We record the cv-qualification in the
   16286              :          function type.  */
   16287     48759046 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   16288              :         {
   16289           62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   16290              : 
   16291              :           /* We have now dealt with these qualifiers.  */
   16292           62 :           memfn_quals = TYPE_UNQUALIFIED;
   16293           62 :           rqual = REF_QUAL_NONE;
   16294              :         }
   16295              : 
   16296     48759046 :       if (type_uses_auto (type))
   16297              :         {
   16298           62 :           if (alias_p)
   16299           20 :             error_at (declspecs->locations[ds_type_spec],
   16300              :                       "%<auto%> not allowed in alias declaration");
   16301              :           else
   16302           42 :             error_at (declspecs->locations[ds_type_spec],
   16303              :                       "typedef declared %<auto%>");
   16304           62 :           type = error_mark_node;
   16305              :         }
   16306              : 
   16307     48759046 :       if (reqs)
   16308            3 :         error_at (location_of (reqs), "requires-clause on typedef");
   16309              : 
   16310     48759046 :       if (id_declarator && declarator->u.id.qualifying_scope)
   16311              :         {
   16312           21 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   16313           21 :           type = error_mark_node;
   16314              :         }
   16315              : 
   16316     48759046 :       if (decl_context == FIELD)
   16317     26165625 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   16318              :       else
   16319     22593421 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   16320              : 
   16321     48759046 :       if (decl_context != FIELD)
   16322              :         {
   16323     22593421 :           if (!current_function_decl)
   16324      9910198 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   16325     12683223 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   16326              :             /* The TYPE_DECL is "abstract" because there will be
   16327              :                clones of this constructor/destructor, and there will
   16328              :                be copies of this TYPE_DECL generated in those
   16329              :                clones.  The decloning optimization (for space) may
   16330              :                revert this subsequently if it determines that
   16331              :                the clones should share a common implementation.  */
   16332       164702 :             DECL_ABSTRACT_P (decl) = true;
   16333              : 
   16334     22593421 :           set_originating_module (decl);
   16335              :         }
   16336     26165625 :       else if (current_class_type
   16337     26165625 :                && constructor_name_p (unqualified_id, current_class_type))
   16338            3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   16339              :                    "as enclosing class",
   16340              :                    unqualified_id);
   16341              : 
   16342              :       /* If the user declares "typedef struct {...} foo" then the
   16343              :          struct will have an anonymous name.  Fill that name in now.
   16344              :          Nothing can refer to it, so nothing needs know about the name
   16345              :          change.  */
   16346     48759046 :       if (type != error_mark_node
   16347     48758963 :           && unqualified_id
   16348     48758960 :           && TYPE_NAME (type)
   16349     45329679 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   16350     90521016 :           && (TYPE_UNNAMED_P (type)
   16351              :               /* An enum may have previously used an enumerator for linkage
   16352              :                  purposes, but we want the typedef name to take priority.  */
   16353     44927332 :               || enum_with_enumerator_for_linkage_p (type))
   16354       402769 :           && declspecs->type_definition_p
   16355       402686 :           && attributes_naming_typedef_ok (*attrlist)
   16356     49161729 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   16357       402665 :         name_unnamed_type (type, decl);
   16358              : 
   16359     48759046 :       if (signed_p
   16360     48759046 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   16361       383863 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   16362              : 
   16363     48759046 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   16364              :                       memfn_quals != TYPE_UNQUALIFIED,
   16365              :                       inlinep, friendp, raises != NULL_TREE,
   16366              :                       declspecs->locations);
   16367              : 
   16368     48759046 :       if (alias_p)
   16369              :         /* Acknowledge that this was written:
   16370              :              `using analias = atype;'.  */
   16371     22158615 :         TYPE_DECL_ALIAS_P (decl) = 1;
   16372              : 
   16373              :       /* We use a flag so that dependent_opaque_alias_p doesn't have to
   16374              :          recompute the answer every single time.  */
   16375     48759046 :       TYPE_DECL_OPAQUE_ALIAS_P (decl) = any_lambdas_p (type);
   16376              : 
   16377     48759046 :       return decl;
   16378              :     }
   16379              : 
   16380              :   /* Detect the case of an array type of unspecified size
   16381              :      which came, as such, direct from a typedef name.
   16382              :      We must copy the type, so that the array's domain can be
   16383              :      individually set by the object's initializer.  */
   16384              : 
   16385   1026581289 :   if (type && typedef_type
   16386    995995136 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   16387   1027188972 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   16388           83 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16389              : 
   16390              :   /* Detect where we're using a typedef of function type to declare a
   16391              :      function. PARMS will not be set, so we must create it now.  */
   16392              : 
   16393   1026581289 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   16394              :     {
   16395        16095 :       tree decls = NULL_TREE;
   16396        16095 :       tree args;
   16397              : 
   16398        16095 :       for (args = TYPE_ARG_TYPES (type);
   16399        34655 :            args && args != void_list_node;
   16400        18560 :            args = TREE_CHAIN (args))
   16401              :         {
   16402        18560 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   16403        18560 :                                           TREE_VALUE (args));
   16404              : 
   16405        18560 :           DECL_CHAIN (decl) = decls;
   16406        18560 :           decls = decl;
   16407              :         }
   16408              : 
   16409        16095 :       parms = nreverse (decls);
   16410              : 
   16411        16095 :       if (decl_context != TYPENAME)
   16412              :         {
   16413              :           /* The qualifiers on the function type become the qualifiers on
   16414              :              the non-static member function. */
   16415        15311 :           memfn_quals |= type_memfn_quals (type);
   16416        15311 :           rqual = type_memfn_rqual (type);
   16417        15311 :           type_quals = TYPE_UNQUALIFIED;
   16418        15311 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   16419              :         }
   16420              :     }
   16421              : 
   16422              :   /* If this is a type name (such as, in a cast or sizeof),
   16423              :      compute the type and return it now.  */
   16424              : 
   16425   1026580505 :   if (decl_context == TYPENAME)
   16426              :     {
   16427              :       /* Note that here we don't care about type_quals.  */
   16428              : 
   16429              :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   16430    423179174 :       if (friendp)
   16431              :         {
   16432            0 :           if (inlinep)
   16433              :             {
   16434            0 :               error ("%<inline%> specified for friend class declaration");
   16435            0 :               inlinep = 0;
   16436              :             }
   16437              : 
   16438            0 :           if (!current_aggr)
   16439              :             {
   16440              :               /* Don't allow friend declaration without a class-key.  */
   16441            0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   16442            0 :                 permerror (input_location, "template parameters cannot be friends");
   16443            0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   16444            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16445              :                            "i.e. %<friend class %T::%D%>",
   16446            0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   16447              :               else
   16448            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16449              :                            "i.e. %<friend %#T%>",
   16450              :                            type);
   16451              :             }
   16452              : 
   16453              :           /* Only try to do this stuff if we didn't already give up.  */
   16454            0 :           if (type != integer_type_node)
   16455              :             {
   16456              :               /* A friendly class?  */
   16457            0 :               if (current_class_type)
   16458            0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   16459              :                                    /*complain=*/true);
   16460              :               else
   16461            0 :                 error ("trying to make class %qT a friend of global scope",
   16462              :                        type);
   16463              : 
   16464            0 :               type = void_type_node;
   16465              :             }
   16466              :         }
   16467    423179174 :       else if (memfn_quals || rqual)
   16468              :         {
   16469        14101 :           if (ctype == NULL_TREE
   16470        14101 :               && TREE_CODE (type) == METHOD_TYPE)
   16471            0 :             ctype = TYPE_METHOD_BASETYPE (type);
   16472              : 
   16473        14101 :           if (ctype)
   16474            0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   16475              :           /* Core issue #547: need to allow this in template type args.
   16476              :              Allow it in general in C++11 for alias-declarations.  */
   16477        14101 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   16478        14099 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   16479        14097 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   16480              :           else
   16481            4 :             error ("invalid qualifiers on non-member function type");
   16482              :         }
   16483              : 
   16484    423179174 :       if (reqs)
   16485            3 :         error_at (location_of (reqs), "requires-clause on type-id");
   16486              : 
   16487    423179174 :       return type;
   16488              :     }
   16489    603402115 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   16490       863772 :            && decl_context != CATCHPARM
   16491       380267 :            && TREE_CODE (type) != UNION_TYPE
   16492       379884 :            && ! bitfield
   16493       379884 :            && innermost_code != cdk_decomp)
   16494              :     {
   16495            9 :       error ("abstract declarator %qT used as declaration", type);
   16496            9 :       return error_mark_node;
   16497              :     }
   16498              : 
   16499    603402106 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   16500              :     {
   16501              :       /* Only functions may be declared using an operator-function-id.  */
   16502    408757526 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   16503              :         {
   16504            8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   16505            8 :           return error_mark_node;
   16506              :         }
   16507              : 
   16508    408757518 :       if (reqs)
   16509           15 :         error_at (location_of (reqs),
   16510              :                   "requires-clause on declaration of non-function type %qT",
   16511              :                   type);
   16512              :     }
   16513              : 
   16514              :   /* We don't check parameter types here because we can emit a better
   16515              :      error message later.  */
   16516    603402098 :   if (decl_context != PARM)
   16517              :     {
   16518    299466864 :       type = check_var_type (unqualified_id, type, id_loc);
   16519    299466864 :       if (type == error_mark_node)
   16520              :         return error_mark_node;
   16521              :     }
   16522              : 
   16523              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   16524              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   16525              : 
   16526    603402014 :   if (decl_context == PARM || decl_context == CATCHPARM)
   16527              :     {
   16528    304433339 :       if (ctype || in_namespace)
   16529            0 :         error ("cannot use %<::%> in parameter declaration");
   16530              : 
   16531    304433339 :       tree auto_node = type_uses_auto (type);
   16532    304433339 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   16533              :         {
   16534          126 :           bool err_p = true;
   16535          126 :           if (cxx_dialect >= cxx14)
   16536              :             {
   16537          224 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   16538            3 :                 error_at (typespec_loc,
   16539              :                           "cannot declare a parameter with %<decltype(auto)%>");
   16540          115 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16541              :                 {
   16542            7 :                   auto_diagnostic_group g;
   16543            7 :                   gcc_rich_location richloc (typespec_loc);
   16544            7 :                   richloc.add_fixit_insert_after ("<>");
   16545            7 :                   error_at (&richloc,
   16546              :                             "missing template argument list after %qE; template "
   16547              :                             "placeholder not permitted in parameter", c);
   16548            7 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   16549            6 :                     inform (typespec_loc, "or use %<auto%> for an "
   16550              :                             "abbreviated function template");
   16551            7 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   16552            7 :                 }
   16553          108 :               else if (decl_context == CATCHPARM || template_parm_flag)
   16554           14 :                 error_at (typespec_loc,
   16555              :                           "%<auto%> parameter not permitted in this context");
   16556              :               else
   16557              :                 /* Do not issue an error while tentatively parsing a function
   16558              :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   16559              :                    parameter, we don't know yet that this construct won't be
   16560              :                    a function declaration.  Defer the checking to
   16561              :                    cp_parser_parameter_declaration_clause.  */
   16562              :                 err_p = false;
   16563              :             }
   16564              :           else
   16565            8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   16566           32 :           if (err_p)
   16567           32 :             type = error_mark_node;
   16568              :         }
   16569              : 
   16570              :       /* A parameter declared as an array of T is really a pointer to T.
   16571              :          One declared as a function is really a pointer to a function.
   16572              :          One declared as a member is really a pointer to member.  */
   16573              : 
   16574    304433339 :       if (TREE_CODE (type) == ARRAY_TYPE)
   16575              :         {
   16576              :           /* Transfer const-ness of array into that of type pointed to.  */
   16577       782400 :           type = build_pointer_type (TREE_TYPE (type));
   16578       782400 :           type_quals = TYPE_UNQUALIFIED;
   16579       782400 :           array_parameter_p = true;
   16580              :         }
   16581    303650939 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16582       103026 :         type = build_pointer_type (type);
   16583              :     }
   16584              : 
   16585    150429595 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   16586              :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   16587    115947877 :       && !is_xobj_member_function
   16588    708528503 :       && !(unqualified_id
   16589    210243934 :            && identifier_p (unqualified_id)
   16590    105126089 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   16591              :     {
   16592    105117845 :       cp_cv_quals real_quals = memfn_quals;
   16593    105117845 :       if (cxx_dialect < cxx14 && constexpr_p
   16594       653265 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   16595         3743 :         real_quals |= TYPE_QUAL_CONST;
   16596    105117845 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   16597              :     }
   16598              : 
   16599    603402014 :   {
   16600    603402014 :     tree decl = NULL_TREE;
   16601              : 
   16602    603402014 :     if (decl_context == PARM)
   16603              :       {
   16604    303935234 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   16605    303935234 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   16606              : 
   16607    303935234 :         bad_specifiers (decl, BSP_PARM, virtualp,
   16608              :                         memfn_quals != TYPE_UNQUALIFIED,
   16609              :                         inlinep, friendp, raises != NULL_TREE,
   16610              :                         declspecs->locations);
   16611              :       }
   16612    299466780 :     else if (decl_context == FIELD)
   16613              :       {
   16614    147468664 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   16615     20510598 :           if (tree auto_node = type_uses_auto (type))
   16616              :             {
   16617           24 :               location_t tloc = declspecs->locations[ds_type_spec];
   16618           24 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16619            6 :                 error_at (tloc, "invalid use of template-name %qE without an "
   16620              :                           "argument list",
   16621            6 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   16622              :               else
   16623           18 :                 error_at (tloc, "non-static data member declared with "
   16624              :                           "placeholder %qT", auto_node);
   16625           24 :               type = error_mark_node;
   16626              :             }
   16627              : 
   16628              :         /* The C99 flexible array extension.  */
   16629    123278706 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   16630    148600760 :             && TYPE_DOMAIN (type) == NULL_TREE)
   16631              :           {
   16632         1400 :             if (ctype
   16633         1400 :                 && (TREE_CODE (ctype) == UNION_TYPE
   16634         1400 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   16635           84 :               pedwarn (id_loc, OPT_Wpedantic,
   16636              :                        "flexible array member in union is a GCC extension");
   16637              : 
   16638              :             else
   16639              :               {
   16640              :                 /* Array is a flexible member.  */
   16641         1316 :                 if (name)
   16642         1316 :                   pedwarn (id_loc, OPT_Wpedantic,
   16643              :                            "ISO C++ forbids flexible array member %qs", name);
   16644              :                 else
   16645              :                   pedwarn (input_location, OPT_Wpedantic,
   16646              :                            "ISO C++ forbids flexible array members");
   16647              : 
   16648              :                 /* Flexible array member has a null domain.  */
   16649         1316 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16650              :               }
   16651              :           }
   16652              : 
   16653    147468664 :         if (type == error_mark_node)
   16654              :           {
   16655              :             /* Happens when declaring arrays of sizes which
   16656              :                are error_mark_node, for example.  */
   16657           24 :             decl = NULL_TREE;
   16658              :           }
   16659    147468640 :         else if (in_namespace && !friendp)
   16660              :           {
   16661              :             /* Something like struct S { int N::j; };  */
   16662            6 :             error_at (id_loc, "invalid use of %<::%>");
   16663            6 :             return error_mark_node;
   16664              :           }
   16665    147468634 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   16666              :           {
   16667    113494804 :             int publicp = 0;
   16668    113494804 :             tree function_context;
   16669              : 
   16670    113494804 :             if (friendp == 0)
   16671              :               {
   16672              :                 /* This should never happen in pure C++ (the check
   16673              :                    could be an assert).  It could happen in
   16674              :                    Objective-C++ if someone writes invalid code that
   16675              :                    uses a function declaration for an instance
   16676              :                    variable or property (instance variables and
   16677              :                    properties are parsed as FIELD_DECLs, but they are
   16678              :                    part of an Objective-C class, not a C++ class).
   16679              :                    That code is invalid and is caught by this
   16680              :                    check.  */
   16681    106720182 :                 if (!ctype)
   16682              :                   {
   16683            0 :                     error ("declaration of function %qD in invalid context",
   16684              :                            unqualified_id);
   16685            0 :                     return error_mark_node;
   16686              :                   }
   16687              : 
   16688              :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   16689              :                    ARM 9.5 */
   16690    106720182 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   16691              :                   {
   16692            3 :                     error_at (declspecs->locations[ds_virtual],
   16693              :                               "function %qD declared %<virtual%> inside a union",
   16694              :                               unqualified_id);
   16695            3 :                     return error_mark_node;
   16696              :                   }
   16697              : 
   16698      4195737 :                 if (virtualp
   16699    117690538 :                     && identifier_p (unqualified_id)
   16700      4195737 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16701              :                   {
   16702            9 :                     error_at (declspecs->locations[ds_virtual],
   16703              :                               "%qD cannot be declared %<virtual%>, since it "
   16704              :                               "is always static", unqualified_id);
   16705            9 :                     virtualp = 0;
   16706              :                   }
   16707              :               }
   16708              : 
   16709              :             /* Check that the name used for a destructor makes sense.  */
   16710    113494801 :             if (sfk == sfk_destructor)
   16711              :               {
   16712      3159320 :                 tree uqname = id_declarator->u.id.unqualified_name;
   16713              : 
   16714      3159320 :                 if (!ctype)
   16715              :                   {
   16716           12 :                     gcc_assert (friendp);
   16717           12 :                     error_at (id_loc, "expected qualified name in friend "
   16718              :                               "declaration for destructor %qD", uqname);
   16719           12 :                     return error_mark_node;
   16720              :                   }
   16721              : 
   16722      3159308 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   16723              :                   {
   16724            9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   16725              :                               uqname, ctype);
   16726            9 :                     return error_mark_node;
   16727              :                   }
   16728      3159299 :                 if (concept_p)
   16729              :                   {
   16730            9 :                     error_at (declspecs->locations[ds_concept],
   16731              :                               "a destructor cannot be %qs", "concept");
   16732            9 :                     return error_mark_node;
   16733              :                   }
   16734      3159290 :                 if (constexpr_p && cxx_dialect < cxx20)
   16735              :                   {
   16736            6 :                     error_at (declspecs->locations[ds_constexpr],
   16737              :                               "%<constexpr%> destructors only available"
   16738              :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   16739            6 :                     return error_mark_node;
   16740              :                   }
   16741      3159284 :                 if (consteval_p)
   16742              :                   {
   16743            3 :                     error_at (declspecs->locations[ds_consteval],
   16744              :                               "a destructor cannot be %qs", "consteval");
   16745            3 :                     return error_mark_node;
   16746              :                   }
   16747              :               }
   16748    110335481 :             else if (sfk == sfk_constructor && friendp && !ctype)
   16749              :               {
   16750            0 :                 error ("expected qualified name in friend declaration "
   16751              :                        "for constructor %qD",
   16752            0 :                        id_declarator->u.id.unqualified_name);
   16753            0 :                 return error_mark_node;
   16754              :               }
   16755    113494762 :             if (sfk == sfk_constructor)
   16756     24135428 :               if (concept_p)
   16757              :                 {
   16758            9 :                   error_at (declspecs->locations[ds_concept],
   16759              :                             "a constructor cannot be %<concept%>");
   16760            9 :                   return error_mark_node;
   16761              :                 }
   16762     89359334 :             if (concept_p)
   16763              :               {
   16764            9 :                 error_at (declspecs->locations[ds_concept],
   16765              :                           "a concept cannot be a member function");
   16766            9 :                 concept_p = false;
   16767              :               }
   16768    113494744 :             else if (consteval_p
   16769    114290078 :                      && identifier_p (unqualified_id)
   16770    114290069 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16771              :               {
   16772            9 :                 error_at (declspecs->locations[ds_consteval],
   16773              :                           "%qD cannot be %qs", unqualified_id, "consteval");
   16774            9 :                 consteval_p = false;
   16775              :               }
   16776              : 
   16777    113494753 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16778              :               {
   16779       109923 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   16780       109923 :                 if (variable_template_p (tmpl))
   16781              :                   {
   16782            3 :                     auto_diagnostic_group d;
   16783            3 :                     error_at (id_loc, "specialization of variable template "
   16784              :                               "%qD declared as function", tmpl);
   16785            3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   16786              :                             "variable template declared here");
   16787            3 :                     return error_mark_node;
   16788            3 :                   }
   16789              :               }
   16790              : 
   16791              :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   16792    113494750 :             function_context
   16793              :               = (ctype != NULL_TREE
   16794    113494750 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   16795    226989500 :             publicp = ((! friendp || ! staticp)
   16796    113494750 :                        && function_context == NULL_TREE);
   16797              : 
   16798    113494750 :             decl = grokfndecl (ctype, type,
   16799    113494750 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   16800              :                                ? unqualified_id : dname,
   16801              :                                parms,
   16802              :                                unqualified_id,
   16803              :                                declspecs,
   16804              :                                reqs,
   16805              :                                virtualp, flags, memfn_quals, rqual, raises,
   16806              :                                friendp ? -1 : 0, friendp, publicp,
   16807    113494750 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   16808    113494750 :                                        | (8 * consteval_p),
   16809              :                                initialized,
   16810              :                                is_xobj_member_function, sfk,
   16811              :                                funcdef_flag, late_return_type_p,
   16812              :                                template_count, in_namespace,
   16813              :                                attrlist, contract_specifiers, id_loc);
   16814    113494750 :             decl = set_virt_specifiers (decl, virt_specifiers);
   16815    113494750 :             if (decl == NULL_TREE)
   16816           97 :               return error_mark_node;
   16817              : #if 0
   16818              :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   16819              :             /* The decl and setting of decl_attr is also turned off.  */
   16820              :             decl = build_decl_attribute_variant (decl, decl_attr);
   16821              : #endif
   16822              : 
   16823              :             /* [class.conv.ctor]
   16824              : 
   16825              :                A constructor declared without the function-specifier
   16826              :                explicit that can be called with a single parameter
   16827              :                specifies a conversion from the type of its first
   16828              :                parameter to the type of its class.  Such a constructor
   16829              :                is called a converting constructor.  */
   16830    113494653 :             if (explicitp == 2)
   16831      6133631 :               DECL_NONCONVERTING_P (decl) = 1;
   16832              : 
   16833    113494653 :             if (declspecs->explicit_specifier)
   16834       447307 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   16835              :           }
   16836     33973830 :         else if (!staticp
   16837     33973830 :                  && ((current_class_type
   16838     20510589 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   16839              :                                       current_class_type))
   16840     20510493 :                      || (!dependent_type_p (type)
   16841     12351748 :                          && !COMPLETE_TYPE_P (complete_type (type))
   16842         1448 :                          && (!complete_or_array_type_p (type)
   16843         1373 :                              || initialized == SD_UNINITIALIZED))))
   16844              :           {
   16845         1511 :             if (TREE_CODE (type) != ARRAY_TYPE
   16846         1511 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   16847              :               {
   16848          171 :                 if (unqualified_id)
   16849              :                   {
   16850          126 :                     auto_diagnostic_group d;
   16851          126 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   16852              :                               unqualified_id, type);
   16853          126 :                     cxx_incomplete_type_inform (strip_array_types (type));
   16854          126 :                   }
   16855              :                 else
   16856           45 :                   error ("name %qT has incomplete type", type);
   16857              : 
   16858          171 :                 type = error_mark_node;
   16859          171 :                 decl = NULL_TREE;
   16860              :               }
   16861              :           }
   16862     54481385 :         else if (!verify_type_context (input_location,
   16863              :                                        staticp
   16864              :                                        ? TCTX_STATIC_STORAGE
   16865              :                                        : TCTX_FIELD, type))
   16866              :           {
   16867            0 :             type = error_mark_node;
   16868            0 :             decl = NULL_TREE;
   16869              :           }
   16870              :         else
   16871              :           {
   16872     33972313 :             if (friendp)
   16873              :               {
   16874           12 :                 if (unqualified_id)
   16875            9 :                   error_at (id_loc,
   16876              :                             "%qE is neither function nor member function; "
   16877              :                             "cannot be declared friend", unqualified_id);
   16878              :                 else
   16879            3 :                   error ("unnamed field is neither function nor member "
   16880              :                          "function; cannot be declared friend");
   16881           12 :                 return error_mark_node;
   16882              :               }
   16883     33972301 :             decl = NULL_TREE;
   16884              :           }
   16885              : 
   16886    147468489 :         if (friendp)
   16887              :           {
   16888      6774591 :             if (flag_reflection && !funcdef_flag && decl)
   16889              :               {
   16890        17156 :                 if (attrlist && lookup_annotation (*attrlist))
   16891              :                   {
   16892              :                     /* Remove the annotations to avoid spurious warning
   16893              :                        below.  */
   16894            8 :                     *attrlist = remove_attribute ("internal ", "annotation ",
   16895              :                                                   *attrlist);
   16896            8 :                     error_at (id_loc, "annotation applied to non-defining "
   16897              :                                       "friend declaration %qD", decl);
   16898              :                   }
   16899        17156 :                 for (tree arg = DECL_ARGUMENTS (decl);
   16900        40021 :                      arg; arg = DECL_CHAIN (arg))
   16901        22865 :                   if (lookup_annotation (DECL_ATTRIBUTES (arg)))
   16902            8 :                     error_at (DECL_SOURCE_LOCATION (arg),
   16903              :                               "annotation applied to parameter %qD of "
   16904              :                               "non-defining friend declaration", arg);
   16905              :               }
   16906              :             /* Packages tend to use GNU attributes on friends, so we only
   16907              :                warn for standard attributes.  */
   16908      6774591 :             if (attrlist
   16909      6774591 :                 && !funcdef_flag
   16910      6774591 :                 && cxx11_attribute_p (*attrlist))
   16911              :               {
   16912           27 :                 *attrlist = NULL_TREE;
   16913           27 :                 auto_diagnostic_group d;
   16914           27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   16915           27 :                   inform (id_loc, "an attribute that appertains to a friend "
   16916              :                           "declaration that is not a definition is ignored");
   16917           27 :               }
   16918              :             /* Friends are treated specially.  */
   16919      6774591 :             if (ctype == current_class_type)
   16920              :               ;  /* We already issued a permerror.  */
   16921      6774591 :             else if (decl && DECL_NAME (decl))
   16922              :               {
   16923      6774588 :                 set_originating_module (decl, true);
   16924              : 
   16925      6774588 :                 if (initialized)
   16926              :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   16927              :                      in-class defaulted functions, but that breaks grokfndecl.
   16928              :                      So set it here.  */
   16929       218803 :                   funcdef_flag = true;
   16930              : 
   16931      6774588 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   16932      6774588 :                 *attrlist = NULL_TREE;
   16933              : 
   16934      6774588 :                 tree scope = ctype ? ctype : in_namespace;
   16935      6774588 :                 decl = do_friend (scope, unqualified_id, decl,
   16936              :                                   flags, funcdef_flag);
   16937      6774588 :                 return decl;
   16938              :               }
   16939              :             else
   16940            3 :               return error_mark_node;
   16941              :           }
   16942              : 
   16943              :         /* Structure field.  It may not be a function, except for C++.  */
   16944              : 
   16945    140693898 :         if (decl == NULL_TREE)
   16946              :           {
   16947     33973833 :             if (staticp)
   16948              :               {
   16949              :                 /* C++ allows static class members.  All other work
   16950              :                    for this is done by grokfield.  */
   16951     13463241 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   16952              :                                             dname, type);
   16953     13463241 :                 if (unqualified_id
   16954     13463238 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16955              :                   {
   16956        44292 :                     decl = check_explicit_specialization (unqualified_id, decl,
   16957              :                                                           template_count,
   16958              :                                                           concept_p * 8);
   16959        44292 :                     if (decl == error_mark_node)
   16960              :                       return error_mark_node;
   16961              :                   }
   16962     13463241 :                 set_linkage_for_static_data_member (decl);
   16963     13463241 :                 if (concept_p)
   16964           15 :                   error_at (declspecs->locations[ds_concept],
   16965              :                             "static data member %qE declared %qs",
   16966              :                             unqualified_id, "concept");
   16967     13463226 :                 else if (constexpr_p && !initialized)
   16968              :                   {
   16969            9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   16970              :                               "%<constexpr%> static data member %qD must "
   16971              :                               "have an initializer", decl);
   16972            9 :                     constexpr_p = false;
   16973              :                   }
   16974     13463241 :                 if (consteval_p)
   16975            3 :                   error_at (declspecs->locations[ds_consteval],
   16976              :                             "static data member %qE declared %qs",
   16977              :                             unqualified_id, "consteval");
   16978              : 
   16979     13463241 :                 if (inlinep)
   16980        24272 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   16981              : 
   16982     13463241 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   16983     13463241 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   16984              :                   /* Even if there is an in-class initialization, DECL
   16985              :                      is considered undefined until an out-of-class
   16986              :                      definition is provided, unless this is an inline
   16987              :                      variable.  */
   16988      1867616 :                   DECL_EXTERNAL (decl) = 1;
   16989              : 
   16990     13463241 :                 if (thread_p)
   16991              :                   {
   16992          422 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   16993          422 :                     if (!processing_template_decl)
   16994          376 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   16995          422 :                     if (declspecs->gnu_thread_keyword_p)
   16996           34 :                       SET_DECL_GNU_TLS_P (decl);
   16997              :                   }
   16998              : 
   16999              :                 /* Set the constraints on the declaration.  */
   17000     13463241 :                 bool memtmpl = (current_template_depth
   17001     13463241 :                                 > template_class_depth (current_class_type));
   17002     13463241 :                 if (memtmpl)
   17003              :                   {
   17004       394695 :                     tree ci = current_template_constraints ();
   17005       394695 :                     set_constraints (decl, ci);
   17006              :                   }
   17007              :               }
   17008              :             else
   17009              :               {
   17010     20510592 :                 if (concept_p)
   17011              :                   {
   17012           12 :                     error_at (declspecs->locations[ds_concept],
   17013              :                               "non-static data member %qE declared %qs",
   17014              :                               unqualified_id, "concept");
   17015           12 :                     concept_p = false;
   17016           12 :                     constexpr_p = false;
   17017              :                   }
   17018     20510580 :                 else if (constexpr_p)
   17019              :                   {
   17020            9 :                     error_at (declspecs->locations[ds_constexpr],
   17021              :                               "non-static data member %qE declared %qs",
   17022              :                               unqualified_id, "constexpr");
   17023            9 :                     constexpr_p = false;
   17024              :                   }
   17025     20510592 :                 if (constinit_p)
   17026              :                   {
   17027            6 :                     error_at (declspecs->locations[ds_constinit],
   17028              :                               "non-static data member %qE declared %qs",
   17029              :                               unqualified_id, "constinit");
   17030            6 :                     constinit_p = false;
   17031              :                   }
   17032     20510592 :                 if (consteval_p)
   17033              :                   {
   17034            3 :                     error_at (declspecs->locations[ds_consteval],
   17035              :                               "non-static data member %qE declared %qs",
   17036              :                               unqualified_id, "consteval");
   17037            3 :                     consteval_p = false;
   17038              :                   }
   17039     20510592 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   17040     20510592 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   17041     20510592 :                 if (bitfield && !unqualified_id)
   17042       134305 :                   DECL_PADDING_P (decl) = 1;
   17043              : 
   17044     20510592 :                 if (storage_class == sc_mutable)
   17045              :                   {
   17046       139104 :                     DECL_MUTABLE_P (decl) = 1;
   17047       139104 :                     storage_class = sc_none;
   17048              :                   }
   17049              : 
   17050     20510592 :                 if (initialized)
   17051              :                   {
   17052              :                     /* An attempt is being made to initialize a non-static
   17053              :                        member.  This is new in C++11.  */
   17054      2401340 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   17055              : 
   17056              :                     /* If this has been parsed with static storage class, but
   17057              :                        errors forced staticp to be cleared, ensure NSDMI is
   17058              :                        not present.  */
   17059      2401340 :                     if (declspecs->storage_class == sc_static)
   17060            3 :                       DECL_INITIAL (decl) = error_mark_node;
   17061              :                   }
   17062              :               }
   17063              : 
   17064     54484425 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   17065              :                             memfn_quals != TYPE_UNQUALIFIED,
   17066              :                             staticp ? false : inlinep, friendp,
   17067              :                             raises != NULL_TREE,
   17068              :                             declspecs->locations);
   17069              :           }
   17070              :       }
   17071    151998116 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   17072              :       {
   17073     81046744 :         tree original_name;
   17074     81046744 :         int publicp = 0;
   17075              : 
   17076     81046744 :         if (!unqualified_id)
   17077            0 :           return error_mark_node;
   17078              : 
   17079     81046744 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   17080              :           original_name = dname;
   17081              :         else
   17082     80182037 :           original_name = unqualified_id;
   17083              :         // FIXME:gcc_assert (original_name == dname);
   17084              : 
   17085     81046744 :         if (storage_class == sc_auto)
   17086            1 :           error_at (declspecs->locations[ds_storage_class],
   17087              :                     "storage class %<auto%> invalid for function %qs", name);
   17088     81046743 :         else if (storage_class == sc_register)
   17089            7 :           error_at (declspecs->locations[ds_storage_class],
   17090              :                     "storage class %<register%> invalid for function %qs",
   17091              :                     name);
   17092     81046736 :         else if (thread_p)
   17093              :           {
   17094           12 :             if (declspecs->gnu_thread_keyword_p)
   17095           12 :               error_at (declspecs->locations[ds_thread],
   17096              :                         "storage class %<__thread%> invalid for function %qs",
   17097              :                         name);
   17098              :             else
   17099            0 :               error_at (declspecs->locations[ds_thread],
   17100              :                         "storage class %<thread_local%> invalid for "
   17101              :                         "function %qs", name);
   17102              :           }
   17103     81046724 :         else if (constinit_p)
   17104            3 :           error_at (declspecs->locations[ds_constinit],
   17105              :                     "%<constinit%> specifier invalid for function %qs", name);
   17106              : 
   17107     81046744 :         if (virt_specifiers)
   17108            6 :           error ("virt-specifiers in %qs not allowed outside a class "
   17109              :                  "definition", name);
   17110              :         /* Function declaration not at top level.
   17111              :            Storage classes other than `extern' are not allowed
   17112              :            and `extern' makes no difference.  */
   17113     81046744 :         if (! toplevel_bindings_p ()
   17114        61451 :             && (storage_class == sc_static
   17115        61442 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   17116     81046756 :             && pedantic)
   17117              :           {
   17118            9 :             if (storage_class == sc_static)
   17119            6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   17120              :                        "%<static%> specifier invalid for function %qs "
   17121              :                        "declared out of global scope", name);
   17122              :             else
   17123            3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   17124              :                        "%<inline%> specifier invalid for function %qs "
   17125              :                        "declared out of global scope", name);
   17126              :           }
   17127              : 
   17128     81046744 :         if (ctype == NULL_TREE)
   17129              :           {
   17130     71819296 :             if (virtualp)
   17131              :               {
   17132            0 :                 error ("virtual non-class function %qs", name);
   17133            0 :                 virtualp = 0;
   17134              :               }
   17135     71819296 :             else if (sfk == sfk_constructor
   17136     71819296 :                      || sfk == sfk_destructor)
   17137              :               {
   17138            3 :                 error (funcdef_flag
   17139              :                        ? G_("%qs defined in a non-class scope")
   17140              :                        : G_("%qs declared in a non-class scope"), name);
   17141            3 :                 sfk = sfk_none;
   17142              :               }
   17143              :           }
   17144     81046744 :         if (consteval_p
   17145     81411223 :             && identifier_p (unqualified_id)
   17146     81411223 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   17147              :           {
   17148            9 :             error_at (declspecs->locations[ds_consteval],
   17149              :                       "%qD cannot be %qs", unqualified_id, "consteval");
   17150            9 :             consteval_p = false;
   17151              :           }
   17152              : 
   17153              :         /* Record whether the function is public.  */
   17154     81046744 :         publicp = (ctype != NULL_TREE
   17155     81046744 :                    || storage_class != sc_static);
   17156              : 
   17157    162093488 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   17158              :                            declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
   17159              :                            1, friendp,
   17160              :                            publicp,
   17161     81046744 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   17162     81046744 :                                    | (8 * consteval_p),
   17163              :                            initialized,
   17164              :                            is_xobj_member_function, sfk,
   17165              :                            funcdef_flag,
   17166              :                            late_return_type_p,
   17167              :                            template_count, in_namespace, attrlist,
   17168              :                            contract_specifiers, id_loc);
   17169     81046744 :         if (decl == NULL_TREE)
   17170          619 :           return error_mark_node;
   17171              : 
   17172     81046125 :         if (explicitp == 2)
   17173        11363 :           DECL_NONCONVERTING_P (decl) = 1;
   17174     81046125 :         if (staticp == 1)
   17175              :           {
   17176       115208 :             int invalid_static = 0;
   17177              : 
   17178              :             /* Don't allow a static member function in a class, and forbid
   17179              :                declaring main to be static.  */
   17180       115208 :             if (TREE_CODE (type) == METHOD_TYPE)
   17181              :               {
   17182            0 :                 permerror (input_location, "cannot declare member function %qD to have "
   17183              :                            "static linkage", decl);
   17184            0 :                 invalid_static = 1;
   17185              :               }
   17186       115208 :             else if (current_function_decl)
   17187              :               {
   17188              :                 /* 7.1.1: There can be no static function declarations within a
   17189              :                    block.  */
   17190            9 :                 error_at (declspecs->locations[ds_storage_class],
   17191              :                           "cannot declare static function inside another function");
   17192            9 :                 invalid_static = 1;
   17193              :               }
   17194              : 
   17195            9 :             if (invalid_static)
   17196              :               {
   17197     81046125 :                 staticp = 0;
   17198              :                 storage_class = sc_none;
   17199              :               }
   17200              :           }
   17201     81046125 :         if (declspecs->explicit_specifier)
   17202            3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   17203              :       }
   17204              :     else
   17205              :       {
   17206              :         /* It's a variable.  */
   17207              : 
   17208              :         /* An uninitialized decl with `extern' is a reference.  */
   17209    141394865 :         decl = grokvardecl (type, dname, unqualified_id,
   17210              :                             declspecs,
   17211              :                             initialized,
   17212              :                             type_quals,
   17213              :                             inlinep,
   17214              :                             concept_p,
   17215              :                             template_count,
   17216              :                             ctype ? ctype : in_namespace,
   17217              :                             id_loc);
   17218     70951372 :         if (decl == NULL_TREE)
   17219           92 :           return error_mark_node;
   17220              : 
   17221     70951280 :         bad_specifiers (decl, BSP_VAR, virtualp,
   17222              :                         memfn_quals != TYPE_UNQUALIFIED,
   17223              :                         inlinep, friendp, raises != NULL_TREE,
   17224              :                         declspecs->locations);
   17225              : 
   17226     70951280 :         if (ctype)
   17227              :           {
   17228       507873 :             DECL_CONTEXT (decl) = ctype;
   17229       507873 :             if (staticp == 1)
   17230              :               {
   17231            6 :                 permerror (declspecs->locations[ds_storage_class],
   17232              :                            "%<static%> may not be used when defining "
   17233              :                            "(as opposed to declaring) a static data member");
   17234            6 :                 staticp = 0;
   17235            6 :                 storage_class = sc_none;
   17236              :               }
   17237       507873 :             if (storage_class == sc_register && TREE_STATIC (decl))
   17238              :               {
   17239            0 :                 error ("static member %qD declared %<register%>", decl);
   17240            0 :                 storage_class = sc_none;
   17241              :               }
   17242       507873 :             if (storage_class == sc_extern && pedantic)
   17243              :               {
   17244            0 :                 pedwarn (input_location, OPT_Wpedantic,
   17245              :                          "cannot explicitly declare member %q#D to have "
   17246              :                          "extern linkage", decl);
   17247            0 :                 storage_class = sc_none;
   17248              :               }
   17249              :           }
   17250     70443407 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   17251              :           {
   17252           14 :             error_at (DECL_SOURCE_LOCATION (decl),
   17253              :                       "declaration of %<constexpr%> variable %qD "
   17254              :                       "is not a definition", decl);
   17255           14 :             constexpr_p = false;
   17256              :           }
   17257     70951280 :         if (consteval_p)
   17258              :           {
   17259           13 :             error_at (DECL_SOURCE_LOCATION (decl),
   17260              :                       "a variable cannot be declared %<consteval%>");
   17261           13 :             consteval_p = false;
   17262              :           }
   17263              : 
   17264     70951280 :         if (inlinep)
   17265      6866038 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   17266     70951280 :         if (innermost_code == cdk_decomp)
   17267              :           {
   17268       245561 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   17269       245561 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   17270       245561 :             DECL_ARTIFICIAL (decl) = 1;
   17271       245561 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   17272              :           }
   17273              :       }
   17274              : 
   17275    596626537 :     if (VAR_P (decl) && !initialized)
   17276      7596436 :       if (tree auto_node = type_uses_auto (type))
   17277          104 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   17278              :           {
   17279           21 :             location_t loc = declspecs->locations[ds_type_spec];
   17280           21 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   17281           21 :             TREE_TYPE (decl) = error_mark_node;
   17282              :           }
   17283              : 
   17284    596626537 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   17285              :       {
   17286          276 :         if (toplevel_bindings_p ())
   17287              :           {
   17288              :             /* It's common practice (and completely valid) to have a const
   17289              :                be initialized and declared extern.  */
   17290          252 :             if (!(type_quals & TYPE_QUAL_CONST))
   17291           19 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   17292              :                           "%qs initialized and declared %<extern%>", name);
   17293              :           }
   17294              :         else
   17295              :           {
   17296           24 :             error_at (DECL_SOURCE_LOCATION (decl),
   17297              :                       "%qs has both %<extern%> and initializer", name);
   17298           24 :             return error_mark_node;
   17299              :           }
   17300              :       }
   17301              : 
   17302              :     /* Record `register' declaration for warnings on &
   17303              :        and in case doing stupid register allocation.  */
   17304              : 
   17305    596626513 :     if (storage_class == sc_register)
   17306              :       {
   17307         2069 :         DECL_REGISTER (decl) = 1;
   17308              :         /* Warn about register storage specifiers on PARM_DECLs.  */
   17309         2069 :         if (TREE_CODE (decl) == PARM_DECL)
   17310              :           {
   17311           35 :             if (cxx_dialect >= cxx17)
   17312           24 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17313              :                        "ISO C++17 does not allow %<register%> storage "
   17314              :                        "class specifier");
   17315              :             else
   17316           11 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17317              :                           "%<register%> storage class specifier used");
   17318              :           }
   17319              :       }
   17320    596624444 :     else if (storage_class == sc_extern)
   17321     31782126 :       DECL_THIS_EXTERN (decl) = 1;
   17322    564842318 :     else if (storage_class == sc_static)
   17323     24539390 :       DECL_THIS_STATIC (decl) = 1;
   17324              : 
   17325    596626513 :     if (VAR_P (decl))
   17326              :       {
   17327              :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   17328     84414497 :         if (constexpr_p)
   17329     20451380 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   17330              :         /* And the constinit flag (which only applies to variables).  */
   17331     63963117 :         else if (constinit_p)
   17332          453 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   17333              :       }
   17334    512212016 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   17335              :       {
   17336              :         /* If we saw a return type, record its location.  */
   17337    187766190 :         location_t loc = declspecs->locations[ds_type_spec];
   17338    187766190 :         if (loc == UNKNOWN_LOCATION)
   17339              :           /* Build DECL_RESULT in start_preparsed_function.  */;
   17340    153579509 :         else if (!DECL_RESULT (decl))
   17341              :           {
   17342    153540005 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   17343    153540005 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   17344    153540005 :             DECL_ARTIFICIAL (resdecl) = 1;
   17345    153540005 :             DECL_IGNORED_P (resdecl) = 1;
   17346    153540005 :             DECL_RESULT (decl) = resdecl;
   17347              :           }
   17348        39504 :         else if (funcdef_flag)
   17349          869 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   17350              :       }
   17351              : 
   17352              :     /* Record constancy and volatility on the DECL itself .  There's
   17353              :        no need to do this when processing a template; we'll do this
   17354              :        for the instantiated declaration based on the type of DECL.  */
   17355    596626513 :     if (!processing_template_decl
   17356              :         /* Don't do it for instantiated variable templates either,
   17357              :            cp_apply_type_quals_to_decl should have been called on it
   17358              :            already and might have been overridden in cp_finish_decl
   17359              :            if initializer needs runtime initialization.  */
   17360    596626513 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   17361    198915876 :       cp_apply_type_quals_to_decl (type_quals, decl);
   17362              : 
   17363    596626513 :     return decl;
   17364              :   }
   17365   1075341123 : }
   17366              : 
   17367              : /* Subroutine of start_function.  Ensure that each of the parameter
   17368              :    types (as listed in PARMS) is complete, as is required for a
   17369              :    function definition.  */
   17370              : 
   17371              : static void
   17372    167105565 : require_complete_types_for_parms (tree parms)
   17373              : {
   17374    494371222 :   for (; parms; parms = DECL_CHAIN (parms))
   17375              :     {
   17376    327265657 :       if (dependent_type_p (TREE_TYPE (parms)))
   17377    183668854 :         continue;
   17378    143596803 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   17379    143596803 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   17380              :         {
   17381    143596722 :           relayout_decl (parms);
   17382    143596722 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   17383              : 
   17384    143596722 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   17385    143596722 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   17386    143596722 :                                DECL_SOURCE_LOCATION (parms));
   17387              :         }
   17388              :       else
   17389              :         /* grokparms or complete_type_or_else will have already issued
   17390              :            an error.  */
   17391           81 :         TREE_TYPE (parms) = error_mark_node;
   17392              :     }
   17393    167105565 : }
   17394              : 
   17395              : /* Returns nonzero if T is a local variable.  */
   17396              : 
   17397              : int
   17398    179575793 : local_variable_p (const_tree t)
   17399              : {
   17400    179575793 :   if ((VAR_P (t)
   17401     69622212 :        && (DECL_LOCAL_DECL_P (t)
   17402     69622212 :            || !DECL_CONTEXT (t)
   17403     69579126 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   17404    185429167 :       || (TREE_CODE (t) == PARM_DECL))
   17405    159810218 :     return 1;
   17406              : 
   17407              :   return 0;
   17408              : }
   17409              : 
   17410              : /* Like local_variable_p, but suitable for use as a tree-walking
   17411              :    function.  */
   17412              : 
   17413              : static tree
   17414      5659226 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   17415              :                          void * /*data*/)
   17416              : {
   17417      5659226 :   if (unevaluated_p (TREE_CODE (*tp)))
   17418              :     {
   17419              :       /* DR 2082 permits local variables in unevaluated contexts
   17420              :          within a default argument.  */
   17421           70 :       *walk_subtrees = 0;
   17422           70 :       return NULL_TREE;
   17423              :     }
   17424              : 
   17425      5659156 :   if (local_variable_p (*tp)
   17426      5659156 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   17427              :     return *tp;
   17428      5659156 :   else if (TYPE_P (*tp))
   17429           30 :     *walk_subtrees = 0;
   17430              : 
   17431              :   return NULL_TREE;
   17432              : }
   17433              : 
   17434              : /* Check that ARG, which is a default-argument expression for a
   17435              :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   17436              :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   17437              :    DECL, if there is no DECL available.  */
   17438              : 
   17439              : tree
   17440      2795327 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   17441              : {
   17442      2795327 :   tree var;
   17443      2795327 :   tree decl_type;
   17444              : 
   17445      2795327 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   17446              :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   17447              :        with a default argument.  Ignore the argument for now; we'll
   17448              :        deal with it after the class is complete.  */
   17449              :     return arg;
   17450              : 
   17451      1981905 :   if (TYPE_P (decl))
   17452              :     {
   17453              :       decl_type = decl;
   17454              :       decl = NULL_TREE;
   17455              :     }
   17456              :   else
   17457       603174 :     decl_type = TREE_TYPE (decl);
   17458              : 
   17459      1981905 :   if (arg == error_mark_node
   17460      1981764 :       || decl == error_mark_node
   17461      1981755 :       || TREE_TYPE (arg) == error_mark_node
   17462      3963660 :       || decl_type == error_mark_node)
   17463              :     /* Something already went wrong.  There's no need to check
   17464              :        further.  */
   17465              :     return error_mark_node;
   17466              : 
   17467              :   /* [dcl.fct.default]
   17468              : 
   17469              :      A default argument expression is implicitly converted to the
   17470              :      parameter type.  */
   17471      1981755 :   ++cp_unevaluated_operand;
   17472              :   /* Avoid digest_init clobbering the initializer.  */
   17473      1981755 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   17474      1981755 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   17475              :                                      LOOKUP_IMPLICIT);
   17476      1981755 :   --cp_unevaluated_operand;
   17477              : 
   17478              :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   17479              :      the call sites.  */
   17480      1577309 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   17481       404461 :       && null_ptr_cst_p (arg)
   17482              :       /* Don't lose side-effects as in PR90473.  */
   17483      2351305 :       && !TREE_SIDE_EFFECTS (arg))
   17484       369547 :     return nullptr_node;
   17485              : 
   17486              :   /* [dcl.fct.default]
   17487              : 
   17488              :      Local variables shall not be used in default argument
   17489              :      expressions.
   17490              : 
   17491              :      The keyword `this' shall not be used in a default argument of a
   17492              :      member function.  */
   17493      1612208 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   17494      1612208 :   if (var)
   17495              :     {
   17496            0 :       if (complain & tf_warning_or_error)
   17497              :         {
   17498            0 :           if (DECL_NAME (var) == this_identifier)
   17499            0 :             permerror (input_location, "default argument %qE uses %qD",
   17500              :                        arg, var);
   17501              :           else
   17502            0 :             error ("default argument %qE uses local variable %qD", arg, var);
   17503              :         }
   17504            0 :       return error_mark_node;
   17505              :     }
   17506              : 
   17507              :   /* All is well.  */
   17508      1612208 :   return arg;
   17509              : }
   17510              : 
   17511              : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   17512              : 
   17513              : static tree
   17514    290541251 : type_is_deprecated (tree type)
   17515              : {
   17516    427953771 :   enum tree_code code;
   17517    427953771 :   if (TREE_DEPRECATED (type))
   17518              :     return type;
   17519    427913074 :   if (TYPE_NAME (type))
   17520              :     {
   17521    286125528 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   17522              :         return type;
   17523              :       else
   17524              :         {
   17525    286125522 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17526    286125522 :           return NULL_TREE;
   17527              :         }
   17528              :     }
   17529              : 
   17530              :   /* Do warn about using typedefs to a deprecated class.  */
   17531    141787546 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17532            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17533              : 
   17534    141787546 :   code = TREE_CODE (type);
   17535              : 
   17536    141787546 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17537    141787546 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17538              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17539    137293028 :     return type_is_deprecated (TREE_TYPE (type));
   17540              : 
   17541       119492 :   if (TYPE_PTRMEMFUNC_P (type))
   17542       119492 :     return type_is_deprecated
   17543       119492 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17544              : 
   17545              :   return NULL_TREE;
   17546              : }
   17547              : 
   17548              : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   17549              : 
   17550              : static tree
   17551    291782066 : type_is_unavailable (tree type)
   17552              : {
   17553    429933932 :   enum tree_code code;
   17554    429933932 :   if (TREE_UNAVAILABLE (type))
   17555              :     return type;
   17556    429933926 :   if (TYPE_NAME (type))
   17557              :     {
   17558    287406977 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   17559              :         return type;
   17560              :       else
   17561              :         {
   17562    287406971 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17563    287406971 :           return NULL_TREE;
   17564              :         }
   17565              :     }
   17566              : 
   17567              :   /* Do warn about using typedefs to a deprecated class.  */
   17568    142526949 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17569            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17570              : 
   17571    142526949 :   code = TREE_CODE (type);
   17572              : 
   17573    142526949 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17574    142526949 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17575              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17576    137919286 :     return type_is_unavailable (TREE_TYPE (type));
   17577              : 
   17578       232580 :   if (TYPE_PTRMEMFUNC_P (type))
   17579       232580 :     return type_is_unavailable
   17580       232580 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17581              : 
   17582              :   return NULL_TREE;
   17583              : }
   17584              : 
   17585              : /* Decode the list of parameter types for a function type.
   17586              :    Given the list of things declared inside the parens,
   17587              :    return a list of types.
   17588              : 
   17589              :    If this parameter does not end with an ellipsis, we append
   17590              :    void_list_node.
   17591              : 
   17592              :    *PARMS is set to the chain of PARM_DECLs created.  */
   17593              : 
   17594              : tree
   17595    200000157 : grokparms (tree parmlist, tree *parms)
   17596              : {
   17597    200000157 :   tree result = NULL_TREE;
   17598    200000157 :   tree decls = NULL_TREE;
   17599    200000157 :   tree parm;
   17600    200000157 :   int any_error = 0;
   17601              : 
   17602    492417677 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   17603              :     {
   17604    489879343 :       tree type = NULL_TREE;
   17605    489879343 :       tree init = TREE_PURPOSE (parm);
   17606    489879343 :       tree decl = TREE_VALUE (parm);
   17607              : 
   17608    489879343 :       if (parm == void_list_node || parm == explicit_void_list_node)
   17609              :         break;
   17610              : 
   17611    292417536 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   17612              :         {
   17613          198 :           any_error = 1;
   17614          198 :           continue;
   17615              :         }
   17616              : 
   17617    292417338 :       type = TREE_TYPE (decl);
   17618    292417338 :       if (VOID_TYPE_P (type))
   17619              :         {
   17620           82 :           if (same_type_p (type, void_type_node)
   17621           73 :               && !init
   17622           61 :               && !DECL_NAME (decl) && !result
   17623          110 :               && TREE_CHAIN (parm) == void_list_node)
   17624              :             /* DR 577: A parameter list consisting of a single
   17625              :                unnamed parameter of non-dependent type 'void'.  */
   17626              :             break;
   17627           66 :           else if (cv_qualified_p (type))
   17628            9 :             error_at (DECL_SOURCE_LOCATION (decl),
   17629              :                       "invalid use of cv-qualified type %qT in "
   17630              :                       "parameter declaration", type);
   17631              :           else
   17632           57 :             error_at (DECL_SOURCE_LOCATION (decl),
   17633              :                       "invalid use of type %<void%> in parameter "
   17634              :                       "declaration");
   17635              :           /* It's not a good idea to actually create parameters of
   17636              :              type `void'; other parts of the compiler assume that a
   17637              :              void type terminates the parameter list.  */
   17638           66 :           type = error_mark_node;
   17639           66 :           TREE_TYPE (decl) = error_mark_node;
   17640              :         }
   17641              : 
   17642    292417322 :       if (type != error_mark_node)
   17643              :         {
   17644    292417256 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17645              :             {
   17646    291782066 :               tree unavailtype = type_is_unavailable (type);
   17647    291782066 :               if (unavailtype)
   17648           12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   17649              :             }
   17650    292417256 :           if (deprecated_state != DEPRECATED_SUPPRESS
   17651    292417256 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17652              :             {
   17653    290541251 :               tree deptype = type_is_deprecated (type);
   17654    290541251 :               if (deptype)
   17655        40703 :                 cp_handle_deprecated_or_unavailable (deptype);
   17656              :             }
   17657              : 
   17658              :           /* [dcl.fct] "A parameter with volatile-qualified type is
   17659              :              deprecated."  */
   17660    292417256 :           if (CP_TYPE_VOLATILE_P (type))
   17661          564 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   17662              :                         "%<volatile%>-qualified parameter is "
   17663              :                         "deprecated");
   17664              : 
   17665              :           /* Top-level qualifiers on the parameters are
   17666              :              ignored for function types.  */
   17667    292417256 :           type = cp_build_qualified_type (type, TYPE_UNQUALIFIED);
   17668    292417256 :           if (TREE_CODE (type) == METHOD_TYPE)
   17669              :             {
   17670            0 :               error ("parameter %qD invalidly declared method type", decl);
   17671            0 :               type = build_pointer_type (type);
   17672            0 :               TREE_TYPE (decl) = type;
   17673              :             }
   17674    292417256 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   17675              :             {
   17676              :               /* Before C++17 DR 393:
   17677              :                  [dcl.fct]/6, parameter types cannot contain pointers
   17678              :                  (references) to arrays of unknown bound.  */
   17679      1632153 :               tree t = TREE_TYPE (type);
   17680      1632153 :               int ptr = TYPE_PTR_P (type);
   17681              : 
   17682      1789389 :               while (1)
   17683              :                 {
   17684      1710771 :                   if (TYPE_PTR_P (t))
   17685              :                     ptr = 1;
   17686      1635339 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   17687              :                     break;
   17688         3196 :                   else if (!TYPE_DOMAIN (t))
   17689              :                     break;
   17690        78618 :                   t = TREE_TYPE (t);
   17691              :                 }
   17692      1632153 :               if (TREE_CODE (t) == ARRAY_TYPE)
   17693           16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   17694              :                          ptr
   17695              :                          ? G_("parameter %qD includes pointer to array of "
   17696              :                               "unknown bound %qT")
   17697              :                          : G_("parameter %qD includes reference to array of "
   17698              :                               "unknown bound %qT"),
   17699              :                          decl, t);
   17700              :             }
   17701              : 
   17702    292417256 :           if (init && !processing_template_decl)
   17703      1416587 :             init = check_default_argument (decl, init, tf_warning_or_error);
   17704              :         }
   17705              : 
   17706    292417322 :       DECL_CHAIN (decl) = decls;
   17707    292417322 :       decls = decl;
   17708    292417322 :       result = tree_cons (init, type, result);
   17709              :     }
   17710    200000157 :   decls = nreverse (decls);
   17711    200000157 :   result = nreverse (result);
   17712    200000157 :   if (parm)
   17713    197461823 :     result = chainon (result, void_list_node);
   17714    200000157 :   *parms = decls;
   17715    200000157 :   if (any_error)
   17716          183 :     result = NULL_TREE;
   17717              : 
   17718          183 :   if (any_error)
   17719              :     /* We had parm errors, recover by giving the function (...) type.  */
   17720          183 :     result = NULL_TREE;
   17721              : 
   17722    200000157 :   return result;
   17723              : }
   17724              : 
   17725              : 
   17726              : /* D is a constructor or overloaded `operator='.
   17727              : 
   17728              :    Let T be the class in which D is declared. Then, this function
   17729              :    returns:
   17730              : 
   17731              :    -1 if D's is an ill-formed constructor or copy assignment operator
   17732              :       whose first parameter is of type `T'.
   17733              :    0  if D is not a copy constructor or copy assignment
   17734              :       operator.
   17735              :    1  if D is a copy constructor or copy assignment operator whose
   17736              :       first parameter is a reference to non-const qualified T.
   17737              :    2  if D is a copy constructor or copy assignment operator whose
   17738              :       first parameter is a reference to const qualified T.
   17739              : 
   17740              :    This function can be used as a predicate. Positive values indicate
   17741              :    a copy constructor and nonzero values indicate a copy assignment
   17742              :    operator.  */
   17743              : 
   17744              : int
   17745    352943804 : copy_fn_p (const_tree d)
   17746              : {
   17747    352943804 :   tree args;
   17748    352943804 :   tree arg_type;
   17749    352943804 :   int result = 1;
   17750              : 
   17751    352943804 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   17752              : 
   17753    352943804 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17754    352943804 :       || (DECL_TEMPLATE_INFO (d)
   17755    156375672 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17756              :     /* Instantiations of template member functions are never copy
   17757              :        functions.  Note that member functions of templated classes are
   17758              :        represented as template functions internally, and we must
   17759              :        accept those as copy functions.  */
   17760              :     return 0;
   17761              : 
   17762    297795060 :   if (!DECL_CONSTRUCTOR_P (d)
   17763    297795060 :       && DECL_NAME (d) != assign_op_identifier)
   17764              :     return 0;
   17765              : 
   17766    296969368 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17767              :     {
   17768          282 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17769          282 :       if (!TYPE_REF_P (object_param)
   17770          255 :           || TYPE_REF_IS_RVALUE (object_param)
   17771              :           /* Reject unrelated object parameters. */
   17772          237 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17773          519 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17774              :         return 0;
   17775          228 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17776              :     }
   17777              :   else
   17778    296969086 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17779    296969314 :   if (!args)
   17780              :     return 0;
   17781              : 
   17782    296961465 :   arg_type = TREE_VALUE (args);
   17783    296961465 :   if (arg_type == error_mark_node)
   17784              :     return 0;
   17785              : 
   17786    296961430 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   17787              :     {
   17788              :       /* Pass by value copy assignment operator.  */
   17789              :       result = -1;
   17790              :     }
   17791    296959874 :   else if (TYPE_REF_P (arg_type)
   17792    188248120 :            && !TYPE_REF_IS_RVALUE (arg_type)
   17793    416151051 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   17794              :     {
   17795     96083970 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   17796     95913446 :         result = 2;
   17797              :     }
   17798              :   else
   17799              :     return 0;
   17800              : 
   17801     96085526 :   args = TREE_CHAIN (args);
   17802              : 
   17803     98973707 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17804              :     /* There are more non-optional args.  */
   17805      2887667 :     return 0;
   17806              : 
   17807              :   return result;
   17808              : }
   17809              : 
   17810              : /* D is a constructor or overloaded `operator='.
   17811              : 
   17812              :    Let T be the class in which D is declared. Then, this function
   17813              :    returns true when D is a move constructor or move assignment
   17814              :    operator, false otherwise.  */
   17815              : 
   17816              : bool
   17817    163928398 : move_fn_p (const_tree d)
   17818              : {
   17819    163928398 :   if (cxx_dialect == cxx98)
   17820              :     /* There are no move constructors if we are in C++98 mode.  */
   17821              :     return false;
   17822              : 
   17823    163864264 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17824    163864264 :       || (DECL_TEMPLATE_INFO (d)
   17825     66199759 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17826              :     /* Instantiations of template member functions are never move
   17827              :        functions.  Note that member functions of templated classes are
   17828              :        represented as template functions internally, and we must
   17829              :        accept those as move functions.  */
   17830              :     return 0;
   17831              : 
   17832    132961069 :   return move_signature_fn_p (d);
   17833              : }
   17834              : 
   17835              : /* D is a constructor or overloaded `operator='.
   17836              : 
   17837              :    Then, this function returns true when D has the same signature as a move
   17838              :    constructor or move assignment operator (because either it is such a
   17839              :    ctor/op= or it is a template specialization with the same signature),
   17840              :    false otherwise.  */
   17841              : 
   17842              : bool
   17843    132961069 : move_signature_fn_p (const_tree d)
   17844              : {
   17845    132961069 :   tree args;
   17846    132961069 :   tree arg_type;
   17847    132961069 :   bool result = false;
   17848              : 
   17849    132961069 :   if (!DECL_CONSTRUCTOR_P (d)
   17850    132961069 :       && DECL_NAME (d) != assign_op_identifier)
   17851              :     return 0;
   17852              : 
   17853    132960843 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17854              :     {
   17855          126 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17856          126 :       if (!TYPE_REF_P (object_param)
   17857          102 :           || TYPE_REF_IS_RVALUE (object_param)
   17858              :           /* Reject unrelated object parameters. */
   17859           90 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17860          216 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17861              :         return 0;
   17862           84 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17863              :     }
   17864              :   else
   17865    132960717 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17866    132960801 :   if (!args)
   17867              :     return 0;
   17868              : 
   17869    132957817 :   arg_type = TREE_VALUE (args);
   17870    132957817 :   if (arg_type == error_mark_node)
   17871              :     return 0;
   17872              : 
   17873    132957809 :   if (TYPE_REF_P (arg_type)
   17874     67666137 :       && TYPE_REF_IS_RVALUE (arg_type)
   17875    186003495 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   17876              :                       DECL_CONTEXT (d)))
   17877              :     result = true;
   17878              : 
   17879    132957809 :   args = TREE_CHAIN (args);
   17880              : 
   17881    148479775 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17882              :     /* There are more non-optional args.  */
   17883     12335847 :     return false;
   17884              : 
   17885              :   return result;
   17886              : }
   17887              : 
   17888              : /* Remember any special properties of member function DECL.  */
   17889              : 
   17890              : void
   17891    362198027 : grok_special_member_properties (tree decl)
   17892              : {
   17893    362198027 :   tree class_type;
   17894              : 
   17895    362198027 :   if (TREE_CODE (decl) == USING_DECL
   17896    362198027 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   17897              :     return;
   17898              : 
   17899    339595590 :   class_type = DECL_CONTEXT (decl);
   17900    339595590 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   17901              :     {
   17902    153425228 :       int ctor = copy_fn_p (decl);
   17903              : 
   17904    153425228 :       if (!DECL_ARTIFICIAL (decl))
   17905    106490363 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   17906              : 
   17907    153425228 :       if (ctor > 0)
   17908              :         {
   17909              :           /* [class.copy]
   17910              : 
   17911              :              A non-template constructor for class X is a copy
   17912              :              constructor if its first parameter is of type X&, const
   17913              :              X&, volatile X& or const volatile X&, and either there
   17914              :              are no other parameters or else all other parameters have
   17915              :              default arguments.  */
   17916     31250306 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   17917     31250306 :           if (ctor > 1)
   17918     31171240 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   17919              :         }
   17920              : 
   17921    153425228 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   17922     32714451 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   17923              : 
   17924    153425228 :       if (is_list_ctor (decl))
   17925      1553048 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   17926              : 
   17927    153425228 :       if (maybe_constexpr_fn (decl)
   17928    153425228 :           && !ctor && !move_fn_p (decl))
   17929     56036589 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   17930              :     }
   17931    186170362 :   else if (DECL_NAME (decl) == assign_op_identifier)
   17932              :     {
   17933              :       /* [class.copy]
   17934              : 
   17935              :          A non-template assignment operator for class X is a copy
   17936              :          assignment operator if its parameter is of type X, X&, const
   17937              :          X&, volatile X& or const volatile X&.  */
   17938              : 
   17939     15522018 :       int assop = copy_fn_p (decl);
   17940              : 
   17941     15522018 :       if (assop)
   17942              :         {
   17943      7891828 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   17944      7891828 :           if (assop != 1)
   17945      7863090 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   17946              :         }
   17947              :     }
   17948    170648344 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   17949      2803342 :     TYPE_HAS_CONVERSION (class_type) = true;
   17950              : 
   17951              :   /* Destructors are handled in check_methods.  */
   17952              : }
   17953              : 
   17954              : /* Check a constructor DECL has the correct form.  Complains
   17955              :    if the class has a constructor of the form X(X).  */
   17956              : 
   17957              : bool
   17958     49312016 : grok_ctor_properties (const_tree ctype, const_tree decl)
   17959              : {
   17960     49312016 :   int ctor_parm = copy_fn_p (decl);
   17961              : 
   17962     49312016 :   if (ctor_parm < 0)
   17963              :     {
   17964              :       /* [class.copy]
   17965              : 
   17966              :          A declaration of a constructor for a class X is ill-formed if
   17967              :          its first parameter is of type (optionally cv-qualified) X
   17968              :          and either there are no other parameters or else all other
   17969              :          parameters have default arguments.
   17970              : 
   17971              :          We *don't* complain about member template instantiations that
   17972              :          have this form, though; they can occur as we try to decide
   17973              :          what constructor to use during overload resolution.  Since
   17974              :          overload resolution will never prefer such a constructor to
   17975              :          the non-template copy constructor (which is either explicitly
   17976              :          or implicitly defined), there's no need to worry about their
   17977              :          existence.  Theoretically, they should never even be
   17978              :          instantiated, but that's hard to forestall.  */
   17979            9 :       error_at (DECL_SOURCE_LOCATION (decl),
   17980              :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   17981              :                 ctype, ctype);
   17982            9 :       return false;
   17983              :     }
   17984              : 
   17985              :   return true;
   17986              : }
   17987              : 
   17988              : /* DECL is a declaration for an overloaded or conversion operator.  If
   17989              :    COMPLAIN is true, errors are issued for invalid declarations.  */
   17990              : 
   17991              : bool
   17992     61443935 : grok_op_properties (tree decl, bool complain)
   17993              : {
   17994     61443935 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   17995     61443935 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   17996     61443935 :   tree name = DECL_NAME (decl);
   17997     61443935 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   17998              : 
   17999     61443935 :   tree class_type = DECL_CONTEXT (decl);
   18000     61443935 :   if (class_type && !CLASS_TYPE_P (class_type))
   18001              :     class_type = NULL_TREE;
   18002              : 
   18003     61443935 :   tree_code operator_code;
   18004     61443935 :   unsigned op_flags;
   18005     61443935 :   if (IDENTIFIER_CONV_OP_P (name))
   18006              :     {
   18007              :       /* Conversion operators are TYPE_EXPR for the purposes of this
   18008              :          function.  */
   18009              :       operator_code = TYPE_EXPR;
   18010              :       op_flags = OVL_OP_FLAG_UNARY;
   18011              :     }
   18012              :   else
   18013              :     {
   18014     59035300 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   18015              : 
   18016     59035300 :       operator_code = ovl_op->tree_code;
   18017     59035300 :       op_flags = ovl_op->flags;
   18018     59035300 :       gcc_checking_assert (operator_code != ERROR_MARK);
   18019     59035300 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   18020              :     }
   18021              : 
   18022     59035300 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   18023              :     {
   18024              :       /* operator new and operator delete are quite special.  */
   18025       351970 :       if (class_type)
   18026         9898 :         switch (op_flags)
   18027              :           {
   18028         6779 :           case OVL_OP_FLAG_ALLOC:
   18029         6779 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   18030         6779 :             break;
   18031              : 
   18032         2803 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   18033         2803 :             TYPE_GETS_DELETE (class_type) |= 1;
   18034         2803 :             break;
   18035              : 
   18036          135 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   18037          135 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   18038          135 :             break;
   18039              : 
   18040          181 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   18041          181 :             TYPE_GETS_DELETE (class_type) |= 2;
   18042          181 :             break;
   18043              : 
   18044            0 :           default:
   18045            0 :             gcc_unreachable ();
   18046              :           }
   18047              : 
   18048              :       /* [basic.std.dynamic.allocation]/1:
   18049              : 
   18050              :          A program is ill-formed if an allocation function is declared
   18051              :          in a namespace scope other than global scope or declared
   18052              :          static in global scope.
   18053              : 
   18054              :          The same also holds true for deallocation functions.  */
   18055       351970 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   18056              :         {
   18057       342072 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   18058              :             {
   18059            6 :               error_at (loc, "%qD may not be declared within a namespace",
   18060              :                         decl);
   18061            6 :               return false;
   18062              :             }
   18063              : 
   18064       342066 :           if (!TREE_PUBLIC (decl))
   18065              :             {
   18066            6 :               error_at (loc, "%qD may not be declared as static", decl);
   18067            6 :               return false;
   18068              :             }
   18069              :         }
   18070              : 
   18071              :       /* Check for replaceable global new/delete operators with
   18072              :          const std::nothrow_t & last argument, other replaceable global
   18073              :          new/delete operators are marked in cxx_init_decl_processing.  */
   18074       351958 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   18075              :         {
   18076       342060 :           tree args = argtypes;
   18077       342060 :           if (args
   18078       342048 :               && args != void_list_node
   18079      1026138 :               && same_type_p (TREE_VALUE (args),
   18080              :                               (op_flags & OVL_OP_FLAG_DELETE)
   18081              :                               ? ptr_type_node : size_type_node))
   18082              :             {
   18083       342018 :               args = TREE_CHAIN (args);
   18084       342018 :               if (aligned_allocation_fn_p (decl))
   18085       110364 :                 args = TREE_CHAIN (args);
   18086       342018 :               if (args
   18087       342012 :                   && args != void_list_node
   18088       570357 :                   && TREE_CHAIN (args) == void_list_node)
   18089              :                 {
   18090       200593 :                   tree t = TREE_VALUE (args);
   18091       200593 :                   if (TYPE_REF_P (t)
   18092       113821 :                       && !TYPE_REF_IS_RVALUE (t)
   18093       113821 :                       && (t = TREE_TYPE (t))
   18094       113821 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   18095       313916 :                       && is_std_class (t, "nothrow_t"))
   18096       113323 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   18097              :                 }
   18098              :             }
   18099              :         }
   18100              : 
   18101       351958 :       if (op_flags & OVL_OP_FLAG_DELETE)
   18102              :         {
   18103       201054 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   18104       201054 :           coerce_delete_type (decl, loc);
   18105              :         }
   18106              :       else
   18107              :         {
   18108       150904 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   18109       150904 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   18110              :         }
   18111              : 
   18112              :       return true;
   18113              :     }
   18114              : 
   18115              :   /* An operator function must either be a non-static member function
   18116              :      or have at least one parameter of a class, a reference to a class,
   18117              :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   18118     61091965 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   18119              :     {
   18120     15687788 :       if (operator_code == TYPE_EXPR
   18121     15687788 :           || operator_code == COMPONENT_REF
   18122     15687767 :           || operator_code == NOP_EXPR)
   18123              :         {
   18124           33 :           error_at (loc, "%qD must be a non-static member function", decl);
   18125           33 :           return false;
   18126              :         }
   18127              : 
   18128     15687755 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   18129              :         {
   18130       138003 :           if (! DECL_STATIC_FUNCTION_P (decl))
   18131              :             {
   18132           12 :               error_at (loc, "%qD must be a member function", decl);
   18133           12 :               return false;
   18134              :             }
   18135       137991 :           if (cxx_dialect < cxx23
   18136              :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   18137       209226 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   18138              :               /* For instantiations, we have diagnosed this already.  */
   18139       242590 :               && ! DECL_USE_TEMPLATE (decl))
   18140       104593 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   18141              :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   18142              :                      decl);
   18143       137991 :           if (operator_code == ARRAY_REF)
   18144              :             /* static operator[] should have exactly one argument
   18145              :                for C++20 and earlier, so that it isn't multidimensional.  */
   18146              :             op_flags = OVL_OP_FLAG_UNARY;
   18147              :         }
   18148     15549752 :       else if (DECL_STATIC_FUNCTION_P (decl))
   18149              :         {
   18150            9 :           error_at (loc, "%qD must be either a non-static member "
   18151              :                     "function or a non-member function", decl);
   18152            9 :           return false;
   18153              :         }
   18154              :       else
   18155       418033 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   18156              :           {
   18157     15967776 :             if (!arg || arg == void_list_node)
   18158              :               {
   18159           18 :                 if (complain)
   18160           15 :                   error_at (loc, "%qD must have an argument of class or "
   18161              :                             "enumerated type", decl);
   18162              :                 return false;
   18163              :               }
   18164              : 
   18165     15967758 :             tree type = non_reference (TREE_VALUE (arg));
   18166     15967758 :             if (type == error_mark_node)
   18167              :               return false;
   18168              : 
   18169              :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   18170              :                because these checks are performed even on template
   18171              :                functions.  */
   18172     15967755 :             if (MAYBE_CLASS_TYPE_P (type)
   18173      1432109 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   18174              :               break;
   18175       418033 :           }
   18176              :     }
   18177              : 
   18178     61088553 :   if (operator_code == CALL_EXPR)
   18179              :     /* There are no further restrictions on the arguments to an overloaded
   18180              :        "operator ()".  */
   18181              :     return true;
   18182              : 
   18183              :   /* C++23 allows an arbitrary number of parameters and default arguments for
   18184              :      operator[], and none of the other checks below apply.  */
   18185     50865948 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   18186              :     return true;
   18187              : 
   18188     50544768 :   if (operator_code == COND_EXPR)
   18189              :     {
   18190              :       /* 13.4.0.3 */
   18191            6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   18192            6 :       return false;
   18193              :     }
   18194              : 
   18195              :   /* Count the number of arguments and check for ellipsis.  */
   18196              :   int arity = 0;
   18197    143641465 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   18198              :     {
   18199     93096718 :       if (!arg)
   18200              :         {
   18201           15 :           error_at (loc, "%qD must not have variable number of arguments",
   18202              :                     decl);
   18203           15 :           return false;
   18204              :         }
   18205     93096703 :       ++arity;
   18206              :     }
   18207              :   /* FIXME: We need tests for these errors with xobj member functions.  */
   18208              :   /* Verify correct number of arguments.  */
   18209     50544747 :   switch (op_flags)
   18210              :     {
   18211     10501324 :     case OVL_OP_FLAG_AMBIARY:
   18212     10501324 :       if (arity == 1)
   18213              :         {
   18214              :           /* We have a unary instance of an ambi-ary op.  Remap to the
   18215              :              unary one.  */
   18216      4525160 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   18217      4525160 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   18218      4525160 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   18219      4525160 :           operator_code = ovl_op->tree_code;
   18220      4525160 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   18221              :         }
   18222      5976164 :       else if (arity != 2)
   18223              :         {
   18224              :           /* This was an ambiguous operator but is invalid. */
   18225            3 :           error_at (loc,
   18226              :                     methodp
   18227              :                     ? G_("%qD must have either zero or one argument")
   18228              :                     : G_("%qD must have either one or two arguments"), decl);
   18229            3 :           return false;
   18230              :         }
   18231      5976161 :       else if ((operator_code == POSTINCREMENT_EXPR
   18232      5976161 :                 || operator_code == POSTDECREMENT_EXPR)
   18233      2776524 :                && ! processing_template_decl
   18234              :                /* x++ and x--'s second argument must be an int.  */
   18235      7778425 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   18236              :                                  integer_type_node))
   18237              :         {
   18238           15 :           error_at (loc,
   18239              :                     methodp
   18240              :                     ? G_("postfix %qD must have %<int%> as its argument")
   18241              :                     : G_("postfix %qD must have %<int%> as its second argument"),
   18242              :                     decl);
   18243           15 :           return false;
   18244              :         }
   18245              :       break;
   18246              : 
   18247      3467661 :     case OVL_OP_FLAG_UNARY:
   18248      3467661 :       if (arity != 1)
   18249              :         {
   18250            9 :           error_at (loc,
   18251              :                     methodp
   18252              :                     ? G_("%qD must have no arguments")
   18253              :                     : G_("%qD must have exactly one argument"), decl);
   18254            9 :           return false;
   18255              :         }
   18256              :       break;
   18257              : 
   18258     36575762 :     case OVL_OP_FLAG_BINARY:
   18259     36575762 :       if (arity != 2)
   18260              :         {
   18261            3 :           error_at (loc,
   18262              :                     methodp
   18263              :                     ? G_("%qD must have exactly one argument")
   18264              :                     : G_("%qD must have exactly two arguments"), decl);
   18265            3 :           return false;
   18266              :         }
   18267              :       break;
   18268              : 
   18269            0 :     default:
   18270            0 :       gcc_unreachable ();
   18271              :     }
   18272              : 
   18273              :   /* There can be no default arguments.  */
   18274    143641324 :   for (tree arg = argtypes; arg && arg != void_list_node;
   18275     93096607 :        arg = TREE_CHAIN (arg))
   18276     93096622 :     if (TREE_PURPOSE (arg))
   18277              :       {
   18278           15 :         TREE_PURPOSE (arg) = NULL_TREE;
   18279           15 :         error_at (loc, "%qD cannot have default arguments", decl);
   18280           15 :         return false;
   18281              :       }
   18282              : 
   18283              :   /* At this point the declaration is well-formed.  It may not be
   18284              :      sensible though.  */
   18285              : 
   18286              :   /* Check member function warnings only on the in-class declaration.
   18287              :      There's no point warning on an out-of-class definition.  */
   18288     50544702 :   if (class_type && class_type != current_class_type)
   18289              :     return true;
   18290              : 
   18291              :   /* Warn about conversion operators that will never be used.  */
   18292     48646521 :   if (IDENTIFIER_CONV_OP_P (name)
   18293      2408223 :       && ! DECL_TEMPLATE_INFO (decl)
   18294     49697926 :       && warn_class_conversion)
   18295              :     {
   18296      1051372 :       tree t = TREE_TYPE (name);
   18297      1051372 :       int ref = TYPE_REF_P (t);
   18298              : 
   18299      1051372 :       if (ref)
   18300        21782 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   18301              : 
   18302      1051372 :       if (VOID_TYPE_P (t))
   18303            9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   18304              :                     "will never use a type conversion operator", class_type);
   18305      1051363 :       else if (class_type)
   18306              :         {
   18307      1051363 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   18308           24 :             warning_at (loc, OPT_Wclass_conversion,
   18309              :                         ref
   18310              :                         ? G_("converting %qT to a reference to the same type "
   18311              :                              "will never use a type conversion operator")
   18312              :                         : G_("converting %qT to the same type "
   18313              :                              "will never use a type conversion operator"),
   18314              :                         class_type);
   18315              :           /* Don't force t to be complete here.  */
   18316      1051348 :           else if (MAYBE_CLASS_TYPE_P (t)
   18317       599690 :                    && COMPLETE_TYPE_P (t)
   18318       160096 :                    && DERIVED_FROM_P (t, class_type))
   18319           30 :             warning_at (loc, OPT_Wclass_conversion,
   18320              :                         ref
   18321              :                         ? G_("converting %qT to a reference to a base class "
   18322              :                              "%qT will never use a type conversion operator")
   18323              :                         : G_("converting %qT to a base class %qT "
   18324              :                              "will never use a type conversion operator"),
   18325              :                         class_type, t);
   18326              :         }
   18327              :     }
   18328              : 
   18329     48646521 :   if (!warn_ecpp)
   18330              :     return true;
   18331              : 
   18332              :   /* Effective C++ rules below.  */
   18333              : 
   18334              :   /* More Effective C++ rule 7.  */
   18335           54 :   if (operator_code == TRUTH_ANDIF_EXPR
   18336           54 :       || operator_code == TRUTH_ORIF_EXPR
   18337           54 :       || operator_code == COMPOUND_EXPR)
   18338            0 :     warning_at (loc, OPT_Weffc__,
   18339              :                 "user-defined %qD always evaluates both arguments", decl);
   18340              : 
   18341              :   /* More Effective C++ rule 6.  */
   18342           54 :   if (operator_code == POSTINCREMENT_EXPR
   18343              :       || operator_code == POSTDECREMENT_EXPR
   18344              :       || operator_code == PREINCREMENT_EXPR
   18345           54 :       || operator_code == PREDECREMENT_EXPR)
   18346              :     {
   18347            0 :       tree arg = TREE_VALUE (argtypes);
   18348            0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   18349            0 :       if (methodp || TYPE_REF_P (arg))
   18350            0 :         arg = TREE_TYPE (arg);
   18351            0 :       arg = TYPE_MAIN_VARIANT (arg);
   18352              : 
   18353            0 :       if (operator_code == PREINCREMENT_EXPR
   18354              :           || operator_code == PREDECREMENT_EXPR)
   18355              :         {
   18356            0 :           if (!TYPE_REF_P (ret)
   18357            0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   18358            0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   18359              :                         build_reference_type (arg));
   18360              :         }
   18361              :       else
   18362              :         {
   18363            0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   18364            0 :             warning_at (loc, OPT_Weffc__,
   18365              :                         "postfix %qD should return %qT", decl, arg);
   18366              :         }
   18367              :     }
   18368              : 
   18369              :   /* Effective C++ rule 23.  */
   18370           54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   18371              :       && (operator_code == PLUS_EXPR
   18372            9 :           || operator_code == MINUS_EXPR
   18373            9 :           || operator_code == TRUNC_DIV_EXPR
   18374              :           || operator_code == MULT_EXPR
   18375              :           || operator_code == TRUNC_MOD_EXPR)
   18376           60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   18377            3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   18378              : 
   18379              :   return true;
   18380              : }
   18381              : 
   18382              : /* Return a string giving the keyword associate with CODE.  */
   18383              : 
   18384              : const char *
   18385         3578 : tag_name (enum tag_types code)
   18386              : {
   18387         3578 :   switch (code)
   18388              :     {
   18389              :     case record_type:
   18390              :       return "struct";
   18391          114 :     case class_type:
   18392          114 :       return "class";
   18393            3 :     case union_type:
   18394            3 :       return "union";
   18395            9 :     case enum_type:
   18396            9 :       return "enum";
   18397         3363 :     case typename_type:
   18398         3363 :     case none_type:
   18399         3363 :       return "typename";
   18400           29 :     case scope_type:
   18401           29 :       return nullptr;
   18402              :     }
   18403            0 :   gcc_unreachable ();
   18404              : }
   18405              : 
   18406              : /* Name lookup in an elaborated-type-specifier (after the keyword
   18407              :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   18408              :    elaborated-type-specifier is invalid, issue a diagnostic and return
   18409              :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   18410              :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   18411              : 
   18412              : tree
   18413     12466388 : check_elaborated_type_specifier (enum tag_types tag_code,
   18414              :                                  tree decl,
   18415              :                                  bool allow_template_p)
   18416              : {
   18417     12466388 :   tree type;
   18418              : 
   18419              :   /* In the case of:
   18420              : 
   18421              :        struct S { struct S *p; };
   18422              : 
   18423              :      name lookup will find the TYPE_DECL for the implicit "S::S"
   18424              :      typedef.  Adjust for that here.  */
   18425     12466388 :   if (DECL_SELF_REFERENCE_P (decl))
   18426       429344 :     decl = TYPE_NAME (TREE_TYPE (decl));
   18427              : 
   18428     12466388 :   type = TREE_TYPE (decl);
   18429              : 
   18430              :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   18431              :      is false for this case as well.  */
   18432     12466388 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   18433              :     {
   18434            9 :       error ("using template type parameter %qT after %qs",
   18435              :              type, tag_name (tag_code));
   18436            9 :       return error_mark_node;
   18437              :     }
   18438              :   /* Accept template template parameters.  */
   18439     12466379 :   else if (allow_template_p
   18440      7054572 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   18441      7054560 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   18442              :     ;
   18443              :   /*   [dcl.type.elab]
   18444              : 
   18445              :        If the identifier resolves to a typedef-name or the
   18446              :        simple-template-id resolves to an alias template
   18447              :        specialization, the elaborated-type-specifier is ill-formed.
   18448              : 
   18449              :      In other words, the only legitimate declaration to use in the
   18450              :      elaborated type specifier is the implicit typedef created when
   18451              :      the type is declared.  */
   18452     12466364 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   18453       429473 :            && !DECL_SELF_REFERENCE_P (decl)
   18454     12466493 :            && tag_code != typename_type)
   18455              :     {
   18456           78 :       auto_diagnostic_group d;
   18457           78 :       if (alias_template_specialization_p (type, nt_opaque))
   18458           21 :         error ("using alias template specialization %qT after %qs",
   18459              :                type, tag_name (tag_code));
   18460              :       else
   18461           57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   18462           78 :       inform (DECL_SOURCE_LOCATION (decl),
   18463              :               "%qD has a previous declaration here", decl);
   18464           78 :       return error_mark_node;
   18465           78 :     }
   18466     12466286 :   else if (TREE_CODE (type) != RECORD_TYPE
   18467     12466286 :            && TREE_CODE (type) != UNION_TYPE
   18468              :            && tag_code != enum_type
   18469        72240 :            && tag_code != typename_type)
   18470              :     {
   18471            6 :       auto_diagnostic_group d;
   18472            6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   18473            6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18474            6 :       return error_mark_node;
   18475            6 :     }
   18476     12466280 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   18477     12394085 :            && tag_code == enum_type)
   18478              :     {
   18479            3 :       auto_diagnostic_group d;
   18480            3 :       error ("%qT referred to as enum", type);
   18481            3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18482            3 :       return error_mark_node;
   18483            3 :     }
   18484     12466277 :   else if (!allow_template_p
   18485      5411747 :            && TREE_CODE (type) == RECORD_TYPE
   18486     17752602 :            && CLASSTYPE_IS_TEMPLATE (type))
   18487              :     {
   18488              :       /* If a class template appears as elaborated type specifier
   18489              :          without a template header such as:
   18490              : 
   18491              :            template <class T> class C {};
   18492              :            void f(class C);             // No template header here
   18493              : 
   18494              :          then the required template argument is missing.  */
   18495           18 :       error ("template argument required for %<%s %T%>",
   18496              :              tag_name (tag_code),
   18497           18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   18498           18 :       return error_mark_node;
   18499              :     }
   18500              : 
   18501              :   return type;
   18502              : }
   18503              : 
   18504              : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   18505              :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   18506              :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   18507              :    error.  */
   18508              : 
   18509              : static tree
   18510     27055683 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   18511              :                       TAG_how how, bool template_header_p)
   18512              : {
   18513     27055683 :   tree decl;
   18514     27055683 :   if (how == TAG_how::GLOBAL)
   18515              :     {
   18516              :       /* First try ordinary name lookup, ignoring hidden class name
   18517              :          injected via friend declaration.  */
   18518      2161467 :       decl = lookup_name (name, LOOK_want::TYPE);
   18519              :       /* If that fails, the name will be placed in the smallest
   18520              :          non-class, non-function-prototype scope according to 3.3.1/5.
   18521              :          We may already have a hidden name declared as friend in this
   18522              :          scope.  So lookup again but not ignoring hidden names.
   18523              :          If we find one, that name will be made visible rather than
   18524              :          creating a new tag.  */
   18525      2161467 :       if (!decl)
   18526        18803 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   18527              :     }
   18528              :   else
   18529     24894216 :     decl = lookup_elaborated_type (name, how);
   18530              : 
   18531     24913019 :   if (!decl)
   18532              :     /* We found nothing.  */
   18533              :     return NULL_TREE;
   18534              : 
   18535      6126544 :   if (TREE_CODE (decl) == TREE_LIST)
   18536              :     {
   18537            3 :       auto_diagnostic_group d;
   18538            3 :       error ("reference to %qD is ambiguous", name);
   18539            3 :       print_candidates (input_location, decl);
   18540            3 :       return error_mark_node;
   18541            3 :     }
   18542              : 
   18543      2517404 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18544      2517398 :       && !template_header_p
   18545      8643939 :       && how == TAG_how::CURRENT_ONLY)
   18546              :     {
   18547           12 :       auto_diagnostic_group d;
   18548           12 :       error ("class template %qD redeclared as non-template", name);
   18549           12 :       inform (location_of (decl), "previous declaration here");
   18550           12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   18551           12 :       return error_mark_node;
   18552           12 :     }
   18553              : 
   18554      2517392 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18555              :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   18556              :          so ignore a template template parameter.  */
   18557      6126535 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   18558      2517389 :     decl = DECL_TEMPLATE_RESULT (decl);
   18559              : 
   18560      6126529 :   if (TREE_CODE (decl) == USING_DECL)
   18561              :     {
   18562           24 :       tree u = decl;
   18563           24 :       decl = strip_using_decl (decl);
   18564           24 :       if (how == TAG_how::CURRENT_ONLY
   18565           24 :           && TREE_CODE (decl) == TYPE_DECL
   18566           51 :           && !(DECL_IMPLICIT_TYPEDEF_P (decl)
   18567           24 :                && CP_DECL_CONTEXT (decl) == CP_DECL_CONTEXT (u)
   18568            3 :                && redefinable_import_p (decl)))
   18569              :         {
   18570           21 :           auto_diagnostic_group _;
   18571           21 :           error ("%qD conflicts with a previous declaration", name);
   18572           21 :           inform (location_of (u), "previous declaration %qD", u);
   18573           21 :           inform (location_of (decl), "%qD declared here", decl);
   18574           21 :           return error_mark_node;
   18575           21 :         }
   18576              :     }
   18577              : 
   18578      6126508 :   if (TREE_CODE (decl) != TYPE_DECL)
   18579              :     /* Found not-a-type.  */
   18580              :     return NULL_TREE;
   18581              : 
   18582              :   /* Look for invalid nested type:
   18583              :      class C {
   18584              :      class C {};
   18585              :      };  */
   18586      6126487 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   18587              :     {
   18588            6 :       error ("%qD has the same name as the class in which it is "
   18589              :              "declared", decl);
   18590            6 :       return error_mark_node;
   18591              :     }
   18592              : 
   18593              :   /* Two cases we need to consider when deciding if a class
   18594              :      template is allowed as an elaborated type specifier:
   18595              :      1. It is a self reference to its own class.
   18596              :      2. It comes with a template header.
   18597              : 
   18598              :      For example:
   18599              : 
   18600              :      template <class T> class C {
   18601              :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   18602              :        class D;
   18603              :      };
   18604              :      template <class U> class C; // template_header_p is true
   18605              :      template <class T> class C<T>::D {
   18606              :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   18607              :      };  */
   18608              : 
   18609     18379443 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   18610              :                                             template_header_p
   18611     11823633 :                                             | DECL_SELF_REFERENCE_P (decl));
   18612      2700801 :   if (template_header_p && t && CLASS_TYPE_P (t)
   18613      8827270 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   18614      2700771 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   18615              :     {
   18616           21 :       auto_diagnostic_group d;
   18617           21 :       error ("%qT is not a template", t);
   18618           21 :       inform (location_of (t), "previous declaration here");
   18619           42 :       if (TYPE_CLASS_SCOPE_P (t)
   18620           24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   18621            3 :         inform (input_location,
   18622              :                 "perhaps you want to explicitly add %<%T::%>",
   18623            3 :                 TYPE_CONTEXT (t));
   18624           21 :       return error_mark_node;
   18625           21 :     }
   18626              : 
   18627              :   return t;
   18628              : }
   18629              : 
   18630              : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   18631              :    Define the tag as a forward-reference if it is not defined.
   18632              : 
   18633              :    If a declaration is given, process it here, and report an error if
   18634              :    multiple declarations are not identical.
   18635              : 
   18636              :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   18637              :    the current frame for the name (since C++ allows new names in any
   18638              :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   18639              :    declaration.  Only look beginning from the current scope outward up
   18640              :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   18641              : 
   18642              :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   18643              :    a set of template parameters.  */
   18644              : 
   18645              : tree
   18646     27065848 : xref_tag (enum tag_types tag_code, tree name,
   18647              :           TAG_how how, bool template_header_p)
   18648              : {
   18649     27065848 :   enum tree_code code;
   18650     27065848 :   tree context = NULL_TREE;
   18651              : 
   18652     27065848 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   18653              : 
   18654     27065848 :   gcc_assert (identifier_p (name));
   18655              : 
   18656     27065848 :   switch (tag_code)
   18657              :     {
   18658              :     case record_type:
   18659              :     case class_type:
   18660              :       code = RECORD_TYPE;
   18661              :       break;
   18662              :     case union_type:
   18663              :       code = UNION_TYPE;
   18664              :       break;
   18665              :     case enum_type:
   18666              :       code = ENUMERAL_TYPE;
   18667              :       break;
   18668            0 :     default:
   18669            0 :       gcc_unreachable ();
   18670              :     }
   18671              : 
   18672              :   /* In case of anonymous name, xref_tag is only called to
   18673              :      make type node and push name.  Name lookup is not required.  */
   18674     27065848 :   tree t = NULL_TREE;
   18675     27065848 :   if (!IDENTIFIER_ANON_P (name))
   18676     24647127 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   18677              : 
   18678     27065848 :   if (t == error_mark_node)
   18679              :     return error_mark_node;
   18680              : 
   18681      2892841 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   18682      1383169 :       && template_class_depth (current_class_type)
   18683     27679643 :       && template_header_p)
   18684              :     {
   18685       357672 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   18686              :         return t;
   18687              : 
   18688              :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   18689              :          a definition of this tag.  Since, in addition, we are
   18690              :          currently processing a (member) template declaration of a
   18691              :          template class, we must be very careful; consider:
   18692              : 
   18693              :            template <class X> struct S1
   18694              : 
   18695              :            template <class U> struct S2
   18696              :            {
   18697              :              template <class V> friend struct S1;
   18698              :            };
   18699              : 
   18700              :          Here, the S2::S1 declaration should not be confused with the
   18701              :          outer declaration.  In particular, the inner version should
   18702              :          have a template parameter of level 2, not level 1.
   18703              : 
   18704              :          On the other hand, when presented with:
   18705              : 
   18706              :            template <class T> struct S1
   18707              :            {
   18708              :              template <class U> struct S2 {};
   18709              :              template <class U> friend struct S2;
   18710              :            };
   18711              : 
   18712              :          the friend must find S1::S2 eventually.  We accomplish this
   18713              :          by making sure that the new type we create to represent this
   18714              :          declaration has the right TYPE_CONTEXT.  */
   18715       357669 :       context = TYPE_CONTEXT (t);
   18716       357669 :       t = NULL_TREE;
   18717              :     }
   18718              : 
   18719     27065722 :   if (! t)
   18720              :     {
   18721              :       /* If no such tag is yet defined, create a forward-reference node
   18722              :          and record it as the "definition".
   18723              :          When a real declaration of this type is found,
   18724              :          the forward-reference will be altered into a real type.  */
   18725     21333145 :       if (code == ENUMERAL_TYPE)
   18726              :         {
   18727           13 :           error ("use of enum %q#D without previous declaration", name);
   18728           13 :           return error_mark_node;
   18729              :         }
   18730              : 
   18731     21333132 :       t = make_class_type (code);
   18732     21333132 :       TYPE_CONTEXT (t) = context;
   18733     21333132 :       if (IDENTIFIER_LAMBDA_P (name))
   18734              :         /* Mark it as a lambda type right now.  Our caller will
   18735              :            correct the value.  */
   18736      1669474 :         SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
   18737     21333132 :       t = pushtag (name, t, how);
   18738              :     }
   18739              :   else
   18740              :     {
   18741      5732577 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   18742              :         {
   18743              :           /* Check that we aren't trying to overload a class with different
   18744              :              constraints.  */
   18745      2343099 :           if (!redeclare_class_template (t, current_template_parms,
   18746              :                                          current_template_constraints ()))
   18747           60 :             return error_mark_node;
   18748              :         }
   18749      3389478 :       else if (!processing_template_decl
   18750      3046699 :                && CLASS_TYPE_P (t)
   18751      6409881 :                && CLASSTYPE_IS_TEMPLATE (t))
   18752              :         {
   18753            0 :           auto_diagnostic_group d;
   18754            0 :           error ("redeclaration of %qT as a non-template", t);
   18755            0 :           inform (location_of (t), "previous declaration %qD", t);
   18756            0 :           return error_mark_node;
   18757            0 :         }
   18758              : 
   18759      5732517 :       if (modules_p ()
   18760      5732517 :           && how == TAG_how::CURRENT_ONLY)
   18761              :         {
   18762        13748 :           tree decl = TYPE_NAME (t);
   18763        13748 :           if (!module_may_redeclare (decl))
   18764           15 :             return error_mark_node;
   18765              : 
   18766        13733 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   18767        13733 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   18768         5510 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   18769           57 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   18770        13775 :               && module_exporting_p ())
   18771              :             {
   18772            6 :               auto_diagnostic_group d;
   18773            6 :               error ("conflicting exporting for declaration %qD", decl);
   18774            6 :               inform (DECL_SOURCE_LOCATION (decl),
   18775              :                       "previously declared here without exporting");
   18776            6 :             }
   18777              : 
   18778        13733 :           tree maybe_tmpl = decl;
   18779        13733 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   18780        10241 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   18781              : 
   18782              :           /* FIXME: we should do a more precise check for redefinitions
   18783              :              of a conflicting using-declaration here, as these diagnostics
   18784              :              are not ideal.  */
   18785        13733 :           if (DECL_LANG_SPECIFIC (decl)
   18786         5510 :               && DECL_MODULE_IMPORT_P (decl)
   18787        14489 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   18788              :             {
   18789              :               /* Push it into this TU's symbol slot.  */
   18790          756 :               if (maybe_tmpl != decl)
   18791              :                 /* We're in the template parm binding level.
   18792              :                    Pushtag has logic to slide under that, but we're
   18793              :                    not pushing a *new* type.  */
   18794          548 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   18795              : 
   18796          756 :               pushdecl (maybe_tmpl);
   18797          756 :               if (maybe_tmpl != decl)
   18798          548 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   18799              :             }
   18800              : 
   18801        13733 :           set_instantiating_module (maybe_tmpl);
   18802              :         }
   18803              :     }
   18804              : 
   18805              :   return t;
   18806     27065848 : }
   18807              : 
   18808              : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   18809              :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   18810              :    access_* node, and the TREE_VALUE is the type of the base-class.
   18811              :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   18812              : 
   18813              : void
   18814     72582528 : xref_basetypes (tree ref, tree base_list)
   18815              : {
   18816     72582528 :   tree *basep;
   18817     72582528 :   tree binfo, base_binfo;
   18818     72582528 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   18819     72582528 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   18820     72582528 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   18821              :   /* Highest direct base index with annotations.  */
   18822     72582528 :   unsigned max_annotated_base = 0;
   18823     72582528 :   int i;
   18824     72582528 :   tree default_access;
   18825     72582528 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   18826              : 
   18827     72582528 :   if (ref == error_mark_node)
   18828           12 :     return;
   18829              : 
   18830              :   /* The base of a derived class is private by default, all others are
   18831              :      public.  */
   18832     72582528 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   18833     71949779 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   18834     72582528 :                     ? access_private_node : access_public_node);
   18835              : 
   18836              :   /* First, make sure that any templates in base-classes are
   18837              :      instantiated.  This ensures that if we call ourselves recursively
   18838              :      we do not get confused about which classes are marked and which
   18839              :      are not.  */
   18840     72582528 :   basep = &base_list;
   18841    106207970 :   while (*basep)
   18842              :     {
   18843     33625442 :       tree basetype = TREE_VALUE (*basep);
   18844              : 
   18845              :       /* The dependent_type_p call below should really be dependent_scope_p
   18846              :          so that we give a hard error about using an incomplete type as a
   18847              :          base, but we allow it with a pedwarn for backward
   18848              :          compatibility.  */
   18849     33625442 :       if (processing_template_decl
   18850     33625442 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   18851            3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
   18852              :                                         diagnostics::kind::pedwarn);
   18853     33625442 :       if (!dependent_type_p (basetype)
   18854     33625442 :           && !complete_type_or_else (basetype, NULL))
   18855              :         /* An incomplete type.  Remove it from the list.  */
   18856           15 :         *basep = TREE_CHAIN (*basep);
   18857              :       else
   18858              :         {
   18859     33625427 :           max_bases++;
   18860     33625427 :           if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
   18861           28 :             max_annotated_base = max_bases;
   18862     33625427 :           if (TREE_TYPE (*basep))
   18863        69024 :             max_dvbases++;
   18864     33625427 :           if (CLASS_TYPE_P (basetype))
   18865     32813761 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18866     33625427 :           basep = &TREE_CHAIN (*basep);
   18867              :         }
   18868              :     }
   18869     72582528 :   max_vbases += max_dvbases;
   18870              : 
   18871     72582528 :   TYPE_MARKED_P (ref) = 1;
   18872              : 
   18873              :   /* The binfo slot should be empty, unless this is an (ill-formed)
   18874              :      redefinition.  */
   18875     72582528 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   18876              : 
   18877     72582528 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   18878              : 
   18879     72582528 :   binfo = make_tree_binfo (max_bases);
   18880              : 
   18881     72582528 :   TYPE_BINFO (ref) = binfo;
   18882     72582528 :   BINFO_OFFSET (binfo) = size_zero_node;
   18883     72582528 :   BINFO_TYPE (binfo) = ref;
   18884              : 
   18885              :   /* Apply base-class info set up to the variants of this type.  */
   18886     72582528 :   fixup_type_variants (ref);
   18887              : 
   18888     72582528 :   if (max_bases)
   18889              :     {
   18890     32702870 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
   18891     32702870 :       BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
   18892              :       /* A C++98 POD cannot have base classes.  */
   18893     32702870 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   18894              : 
   18895     32702870 :       if (TREE_CODE (ref) == UNION_TYPE)
   18896              :         {
   18897           12 :           error ("derived union %qT invalid", ref);
   18898           12 :           return;
   18899              :         }
   18900              :     }
   18901              : 
   18902     32702858 :   if (max_bases > 1)
   18903       728625 :     warning (OPT_Wmultiple_inheritance,
   18904              :              "%qT defined with multiple direct bases", ref);
   18905              : 
   18906     72582516 :   if (max_vbases)
   18907              :     {
   18908              :       /* An aggregate can't have virtual base classes.  */
   18909       205968 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   18910              : 
   18911       205968 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   18912              : 
   18913       205968 :       if (max_dvbases)
   18914        67597 :         warning (OPT_Wvirtual_inheritance,
   18915              :                  "%qT defined with direct virtual base", ref);
   18916              :     }
   18917              : 
   18918    106207931 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   18919              :     {
   18920     33625415 :       tree access = TREE_PURPOSE (base_list);
   18921     33625415 :       tree annotations = NULL_TREE;
   18922     33625415 :       if (TREE_CODE (access) == TREE_LIST)
   18923              :         {
   18924           28 :           annotations = TREE_VALUE (access);
   18925           28 :           access = TREE_PURPOSE (access);
   18926           78 :           for (tree *d = &annotations; *d; )
   18927              :             {
   18928           50 :               if (annotation_p (*d))
   18929              :                 {
   18930           50 :                   tree name = get_attribute_name (*d);
   18931           50 :                   tree args = TREE_VALUE (*d);
   18932           50 :                   const attribute_spec *as
   18933           50 :                     = lookup_attribute_spec (TREE_PURPOSE (*d));
   18934           50 :                   bool no_add_attrs = false;
   18935           50 :                   as->handler (&binfo, name, args, 0, &no_add_attrs);
   18936           50 :                   if (no_add_attrs)
   18937              :                     {
   18938            2 :                       *d = TREE_CHAIN (*d);
   18939            2 :                       continue;
   18940              :                     }
   18941              :                 }
   18942           48 :               d = &TREE_CHAIN (*d);
   18943              :             }
   18944              :         }
   18945     33625415 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   18946     33625415 :       tree basetype = TREE_VALUE (base_list);
   18947              : 
   18948     33625415 :       if (access == access_default_node)
   18949      4587087 :         access = default_access;
   18950              : 
   18951              :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   18952              :          aggregate can't have virtual, private, or protected base classes.  */
   18953     33625415 :       if (cxx_dialect < cxx17
   18954     33410625 :           || access != access_public_node
   18955     32448191 :           || via_virtual)
   18956      1243008 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   18957              : 
   18958     33625415 :       if (PACK_EXPANSION_P (basetype))
   18959        29779 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   18960     33625415 :       if (TREE_CODE (basetype) == TYPE_DECL)
   18961            0 :         basetype = TREE_TYPE (basetype);
   18962     33625415 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   18963              :         {
   18964           24 :           error ("base type %qT fails to be a struct or class type",
   18965              :                  basetype);
   18966           24 :           goto dropped_base;
   18967              :         }
   18968     33625391 :       else if (ANON_AGGR_TYPE_P (basetype))
   18969              :         {
   18970            2 :           error ("base type %qT is anonymous struct type", basetype);
   18971            2 :           goto dropped_base;
   18972              :         }
   18973              : 
   18974     33625389 :       base_binfo = NULL_TREE;
   18975     33625389 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   18976              :         {
   18977     26511531 :           base_binfo = TYPE_BINFO (basetype);
   18978              :           /* The original basetype could have been a typedef'd type.  */
   18979     26511531 :           basetype = BINFO_TYPE (base_binfo);
   18980              : 
   18981              :           /* Inherit flags from the base.  */
   18982     79534593 :           TYPE_HAS_NEW_OPERATOR (ref)
   18983     26511531 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   18984     79534593 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   18985     26511531 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   18986     26511531 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   18987     26511531 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   18988     79534593 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   18989     26511531 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   18990     79534593 :           CLASSTYPE_REPEATED_BASE_P (ref)
   18991     26511531 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   18992              :         }
   18993              : 
   18994              :       /* We must do this test after we've seen through a typedef
   18995              :          type.  */
   18996     33625389 :       if (TYPE_MARKED_P (basetype))
   18997              :         {
   18998           18 :           if (basetype == ref)
   18999            0 :             error ("recursive type %qT undefined", basetype);
   19000              :           else
   19001           18 :             error ("duplicate base type %qT invalid", basetype);
   19002           18 :           goto dropped_base;
   19003              :         }
   19004              : 
   19005     33625371 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   19006              :         /* Regenerate the pack expansion for the bases. */
   19007        29779 :         basetype = make_pack_expansion (basetype);
   19008              : 
   19009     33625371 :       TYPE_MARKED_P (basetype) = 1;
   19010              : 
   19011     33625371 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   19012              :                                &igo_prev, via_virtual);
   19013     33625371 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   19014     33556362 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   19015              : 
   19016     33625371 :       unsigned len;
   19017     33625371 :       len = BINFO_N_BASE_BINFOS (binfo);
   19018     33625371 :       BINFO_BASE_APPEND (binfo, base_binfo);
   19019     33625371 :       BINFO_BASE_ACCESS (binfo, len) = access;
   19020     33625371 :       if (len < max_annotated_base)
   19021           34 :         BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
   19022     33625371 :       continue;
   19023              : 
   19024           44 :     dropped_base:
   19025              :       /* Update max_vbases to reflect the reality that we are dropping
   19026              :          this base:  if it reaches zero we want to undo the vec_alloc
   19027              :          above to avoid inconsistencies during error-recovery: eg, in
   19028              :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   19029              :          and vtt null (c++/27952).  */
   19030           44 :       if (via_virtual)
   19031           12 :         max_vbases--;
   19032           44 :       if (CLASS_TYPE_P (basetype))
   19033           32 :         max_vbases
   19034           35 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   19035     33625371 :     }
   19036              : 
   19037     72582516 :   unsigned len = BINFO_N_BASE_BINFOS (binfo);
   19038     72582516 :   if (len < max_bases)
   19039              :     {
   19040           44 :       if (len && max_annotated_base)
   19041            0 :         memmove (&BINFO_BASE_ACCESS (binfo, len),
   19042            0 :                  &BINFO_BASE_ACCESS (binfo, max_bases),
   19043            0 :                  MIN (max_annotated_base, len) * sizeof (tree));
   19044           44 :       BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
   19045              :                                                         len));
   19046              :     }
   19047              : 
   19048     72582516 :   if (CLASSTYPE_VBASECLASSES (ref)
   19049     72582516 :       && max_vbases == 0)
   19050           24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   19051              : 
   19052     72788472 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   19053              :     /* If we didn't get max_vbases vbases, we must have shared at
   19054              :        least one of them, and are therefore diamond shaped.  */
   19055        22336 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   19056              : 
   19057              :   /* Unmark all the types.  */
   19058    106207887 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   19059     33625371 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   19060     72582516 :   TYPE_MARKED_P (ref) = 0;
   19061              : 
   19062              :   /* Now see if we have a repeated base type.  */
   19063     72582516 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   19064              :     {
   19065    182956779 :       for (base_binfo = binfo; base_binfo;
   19066    110374699 :            base_binfo = TREE_CHAIN (base_binfo))
   19067              :         {
   19068    110375448 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   19069              :             {
   19070          749 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   19071          749 :               break;
   19072              :             }
   19073    110374699 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   19074              :         }
   19075    182956779 :       for (base_binfo = binfo; base_binfo;
   19076    110374699 :            base_binfo = TREE_CHAIN (base_binfo))
   19077    110375448 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   19078    110374699 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   19079              :         else
   19080              :           break;
   19081              :     }
   19082              : }
   19083              : 
   19084              : 
   19085              : /* Copies the enum-related properties from type SRC to type DST.
   19086              :    Used with the underlying type of an enum and the enum itself.  */
   19087              : static void
   19088      2042540 : copy_type_enum (tree dst, tree src)
   19089              : {
   19090      2042540 :   tree t;
   19091      4085104 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   19092              :     {
   19093      2042564 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   19094      2042564 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   19095      2042564 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   19096      2042564 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   19097      2042564 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   19098      2042564 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   19099      2042564 :       unsigned valign = TYPE_ALIGN (src);
   19100      2042564 :       if (TYPE_USER_ALIGN (t))
   19101           12 :         valign = MAX (valign, TYPE_ALIGN (t));
   19102              :       else
   19103      2042552 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   19104      2042564 :       SET_TYPE_ALIGN (t, valign);
   19105      2042564 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   19106              :     }
   19107      2042540 : }
   19108              : 
   19109              : /* Begin compiling the definition of an enumeration type.
   19110              :    NAME is its name,
   19111              : 
   19112              :    if ENUMTYPE is not NULL_TREE then the type has already been found.
   19113              : 
   19114              :    UNDERLYING_TYPE is the type that will be used as the storage for
   19115              :    the enumeration type. This should be NULL_TREE if no storage type
   19116              :    was specified.
   19117              : 
   19118              :    ATTRIBUTES are any attributes specified after the enum-key.
   19119              : 
   19120              :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   19121              : 
   19122              :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   19123              : 
   19124              :    Returns the type object, as yet incomplete.
   19125              :    Also records info about it so that build_enumerator
   19126              :    may be used to declare the individual values as they are read.  */
   19127              : 
   19128              : tree
   19129      2408698 : start_enum (tree name, tree enumtype, tree underlying_type,
   19130              :             tree attributes, bool scoped_enum_p, bool *is_new)
   19131              : {
   19132      2408698 :   tree prevtype = NULL_TREE;
   19133      2408698 :   gcc_assert (identifier_p (name));
   19134              : 
   19135      2408698 :   if (is_new)
   19136      1943936 :     *is_new = false;
   19137              :   /* [C++0x dcl.enum]p5:
   19138              : 
   19139              :     If not explicitly specified, the underlying type of a scoped
   19140              :     enumeration type is int.  */
   19141      2408698 :   if (!underlying_type && scoped_enum_p)
   19142       179128 :     underlying_type = integer_type_node;
   19143              : 
   19144      2408698 :   if (underlying_type)
   19145       607356 :     underlying_type = cv_unqualified (underlying_type);
   19146              : 
   19147              :   /* If this is the real definition for a previous forward reference,
   19148              :      fill in the contents in the same object that used to be the
   19149              :      forward reference.  */
   19150      2408698 :   if (!enumtype)
   19151      2408556 :     enumtype = lookup_and_check_tag (enum_type, name,
   19152              :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   19153              :                                      /*template_header_p=*/false);
   19154              : 
   19155              :   /* In case of a template_decl, the only check that should be deferred
   19156              :      to instantiation time is the comparison of underlying types.  */
   19157      2408698 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   19158              :     {
   19159              :       /* Attempt to set the declaring module.  */
   19160        36281 :       if (modules_p ())
   19161              :         {
   19162          252 :           tree decl = TYPE_NAME (enumtype);
   19163          252 :           if (!module_may_redeclare (decl))
   19164            3 :             enumtype = error_mark_node;
   19165          249 :           else if (COMPLETE_TYPE_P (enumtype)
   19166          249 :                    && redefinable_import_p (decl))
   19167           36 :             return enumtype;
   19168              :           else
   19169          213 :             set_instantiating_module (decl);
   19170              :         }
   19171              : 
   19172        36245 :       if (enumtype == error_mark_node)
   19173              :         ;
   19174        36455 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   19175              :         {
   19176            6 :           auto_diagnostic_group d;
   19177            6 :           error_at (input_location, "scoped/unscoped mismatch "
   19178              :                     "in enum %q#T", enumtype);
   19179            6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19180              :                   "previous definition here");
   19181            6 :           enumtype = error_mark_node;
   19182            6 :         }
   19183        36236 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   19184              :         {
   19185            0 :           auto_diagnostic_group d;
   19186            0 :           error_at (input_location, "underlying type mismatch "
   19187              :                     "in enum %q#T", enumtype);
   19188            0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19189              :                   "previous definition here");
   19190            0 :           enumtype = error_mark_node;
   19191            0 :         }
   19192        36230 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   19193        72466 :                && !same_type_p (underlying_type,
   19194              :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   19195              :         {
   19196           29 :           auto_diagnostic_group d;
   19197           29 :           error_at (input_location, "different underlying type "
   19198              :                     "in enum %q#T", enumtype);
   19199           29 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19200              :                   "previous definition here");
   19201           29 :           underlying_type = NULL_TREE;
   19202           29 :         }
   19203              :     }
   19204              : 
   19205      2408662 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   19206        36236 :       || processing_template_decl)
   19207              :     {
   19208              :       /* In case of error, make a dummy enum to allow parsing to
   19209              :          continue.  */
   19210      2372527 :       if (enumtype == error_mark_node)
   19211              :         {
   19212           18 :           name = make_anon_name ();
   19213           18 :           enumtype = NULL_TREE;
   19214              :         }
   19215              : 
   19216              :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   19217              :          of an opaque enum, or an opaque enum of an already defined
   19218              :          enumeration (C++11).
   19219              :          In any other case, it'll be NULL_TREE. */
   19220      2372527 :       if (!enumtype)
   19221              :         {
   19222      2372423 :           if (is_new)
   19223      1907661 :             *is_new = true;
   19224              :         }
   19225      2372527 :       prevtype = enumtype;
   19226              : 
   19227              :       /* Do not push the decl more than once.  */
   19228      2372527 :       if (!enumtype
   19229          104 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   19230              :         {
   19231      2372426 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   19232      2372426 :           enumtype = pushtag (name, enumtype);
   19233              : 
   19234      2372426 :           if (enumtype != error_mark_node)
   19235              :             {
   19236              :               /* ??? We wouldn't need to repeat this if lookup_elaborated_type
   19237              :                  found (and pushed) mergeable types.  */
   19238      2372408 :               if (COMPLETE_TYPE_P (enumtype)
   19239      2372408 :                   && redefinable_import_p (TYPE_NAME (enumtype)))
   19240           42 :                 return enumtype;
   19241              : 
   19242              :               /* The enum is considered opaque until the opening '{' of the
   19243              :                  enumerator list.  */
   19244      2372366 :               SET_OPAQUE_ENUM_P (enumtype, true);
   19245      2372366 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   19246              : 
   19247              :               /* std::byte aliases anything.  */
   19248      2372366 :               if (TYPE_CONTEXT (enumtype) == std_node
   19249      2735052 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   19250        13539 :                 TYPE_ALIAS_SET (enumtype) = 0;
   19251              :             }
   19252              :         }
   19253              :       else
   19254          101 :           enumtype = xref_tag (enum_type, name);
   19255              : 
   19256      2372485 :       if (enumtype == error_mark_node)
   19257              :         return error_mark_node;
   19258              :     }
   19259              : 
   19260      2408602 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   19261              : 
   19262      2408602 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   19263              : 
   19264      2408602 :   if (underlying_type)
   19265              :     {
   19266       607262 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   19267              :         /* We already checked that it matches, don't change it to a different
   19268              :            typedef variant.  */;
   19269       571061 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   19270              :         {
   19271       570987 :           copy_type_enum (enumtype, underlying_type);
   19272       570987 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19273              :         }
   19274           74 :       else if (dependent_type_p (underlying_type))
   19275           61 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19276              :       else
   19277              :         {
   19278           13 :           error ("underlying type %qT of %qT must be an integral type",
   19279              :                  underlying_type, enumtype);
   19280           13 :           copy_type_enum (enumtype, integer_type_node);
   19281           13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   19282              :         }
   19283              :     }
   19284              : 
   19285              :   /* If into a template class, the returned enum is always the first
   19286              :      declaration (opaque or not) seen. This way all the references to
   19287              :      this type will be to the same declaration. The following ones are used
   19288              :      only to check for definition errors.  */
   19289      2408602 :   if (prevtype && processing_template_decl)
   19290              :     return prevtype;
   19291              :   else
   19292      2408501 :     return enumtype;
   19293              : }
   19294              : 
   19295              : /* Returns true if TYPE is an enum that uses an enumerator name for
   19296              :    linkage purposes at namespace scope.  The term is defined in [dcl.enum]/12
   19297              :    for all enums, not just those at namespace scope, but for backward ABI
   19298              :    compatibility we want to treat those not at namespace scope the old way
   19299              :    and e.g. mangle the class scope ones based on their position within the
   19300              :    class rather than the first enumerator.  */
   19301              : 
   19302              : bool
   19303    415642521 : enum_with_enumerator_for_linkage_p (tree type)
   19304              : {
   19305    415642521 :   return (cxx_dialect >= cxx20
   19306    411196569 :           && UNSCOPED_ENUM_P (type)
   19307     20155502 :           && TYPE_ANON_P (type)
   19308      3091772 :           && TYPE_VALUES (type)
   19309    417542183 :           && TYPE_NAMESPACE_SCOPE_P (type));
   19310              : }
   19311              : 
   19312              : /* After processing and defining all the values of an enumeration type,
   19313              :    install their decls in the enumeration type.
   19314              :    ENUMTYPE is the type object.  */
   19315              : 
   19316              : void
   19317      2304208 : finish_enum_value_list (tree enumtype)
   19318              : {
   19319      2304208 :   tree values;
   19320      2304208 :   tree underlying_type;
   19321      2304208 :   tree decl;
   19322      2304208 :   tree value;
   19323      2304208 :   tree minnode, maxnode;
   19324      2304208 :   tree t;
   19325              : 
   19326      2304208 :   ENUM_BEING_DEFINED_P (enumtype) = 0;
   19327              : 
   19328      2304208 :   bool fixed_underlying_type_p
   19329      2304208 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   19330              : 
   19331              :   /* We built up the VALUES in reverse order.  */
   19332      2304208 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   19333              : 
   19334              :   /* For an enum defined in a template, just set the type of the values;
   19335              :      all further processing is postponed until the template is
   19336              :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   19337              :      works.  */
   19338      2304208 :   if (processing_template_decl)
   19339              :     {
   19340       436546 :       for (values = TYPE_VALUES (enumtype);
   19341       785741 :            values;
   19342       436546 :            values = TREE_CHAIN (values))
   19343       436546 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   19344              :       return;
   19345              :     }
   19346              : 
   19347              :   /* Determine the minimum and maximum values of the enumerators.  */
   19348      1955013 :   if (TYPE_VALUES (enumtype))
   19349              :     {
   19350              :       minnode = maxnode = NULL_TREE;
   19351              : 
   19352     11725472 :       for (values = TYPE_VALUES (enumtype);
   19353     13643574 :            values;
   19354     11725472 :            values = TREE_CHAIN (values))
   19355              :         {
   19356     11725472 :           decl = TREE_VALUE (values);
   19357              : 
   19358              :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   19359              :              each enumerator has the type of its enumeration.  Prior to the
   19360              :              closing brace, the type of each enumerator is the type of its
   19361              :              initializing value.  */
   19362     11725472 :           TREE_TYPE (decl) = enumtype;
   19363              : 
   19364              :           /* Update the minimum and maximum values, if appropriate.  */
   19365     11725472 :           value = DECL_INITIAL (decl);
   19366     11725472 :           if (!value || TREE_CODE (value) != INTEGER_CST)
   19367            7 :             value = integer_zero_node;
   19368              :           /* Figure out what the minimum and maximum values of the
   19369              :              enumerators are.  */
   19370     11725472 :           if (!minnode)
   19371              :             minnode = maxnode = value;
   19372      9807370 :           else if (tree_int_cst_lt (maxnode, value))
   19373              :             maxnode = value;
   19374      1509031 :           else if (tree_int_cst_lt (value, minnode))
   19375       171337 :             minnode = value;
   19376              :         }
   19377              :     }
   19378              :   else
   19379              :     /* [dcl.enum]
   19380              : 
   19381              :        If the enumerator-list is empty, the underlying type is as if
   19382              :        the enumeration had a single enumerator with value 0.  */
   19383        36911 :     minnode = maxnode = integer_zero_node;
   19384              : 
   19385      1955013 :   if (!fixed_underlying_type_p)
   19386              :     {
   19387              :       /* Compute the number of bits require to represent all values of the
   19388              :          enumeration.  We must do this before the type of MINNODE and
   19389              :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   19390              :          on the TREE_TYPE of the value it is passed.  */
   19391      1471540 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   19392      1471540 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   19393      1471540 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   19394      1471540 :       int precision = MAX (lowprec, highprec);
   19395      1471540 :       unsigned int itk;
   19396      1471540 :       bool use_short_enum;
   19397              : 
   19398              :       /* Determine the underlying type of the enumeration.
   19399              : 
   19400              :          [dcl.enum]
   19401              : 
   19402              :          The underlying type of an enumeration is an integral type that
   19403              :          can represent all the enumerator values defined in the
   19404              :          enumeration.  It is implementation-defined which integral type is
   19405              :          used as the underlying type for an enumeration except that the
   19406              :          underlying type shall not be larger than int unless the value of
   19407              :          an enumerator cannot fit in an int or unsigned int.
   19408              : 
   19409              :          We use "int" or an "unsigned int" as the underlying type, even if
   19410              :          a smaller integral type would work, unless the user has
   19411              :          explicitly requested that we use the smallest possible type.  The
   19412              :          user can request that for all enumerations with a command line
   19413              :          flag, or for just one enumeration with an attribute.  */
   19414              : 
   19415      2943080 :       use_short_enum = flag_short_enums
   19416      1471540 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   19417              : 
   19418              :       /* If the precision of the type was specified with an attribute and it
   19419              :          was too small, give an error.  Otherwise, use it.  */
   19420      1471540 :       if (TYPE_PRECISION (enumtype))
   19421              :         {
   19422           11 :           if (precision > TYPE_PRECISION (enumtype))
   19423            0 :             error ("specified mode too small for enumerated values");
   19424              :           else
   19425              :             {
   19426           11 :               use_short_enum = true;
   19427           11 :               precision = TYPE_PRECISION (enumtype);
   19428              :             }
   19429              :         }
   19430              : 
   19431      2861889 :       for (itk = (use_short_enum ? itk_char : itk_int);
   19432      2861889 :            itk != itk_none;
   19433              :            itk++)
   19434              :         {
   19435      2861886 :           underlying_type = integer_types[itk];
   19436      2861886 :           if (underlying_type != NULL_TREE
   19437      2861868 :               && TYPE_PRECISION (underlying_type) >= precision
   19438      5721617 :               && TYPE_SIGN (underlying_type) == sgn)
   19439              :             break;
   19440              :         }
   19441      1471540 :       if (itk == itk_none)
   19442              :         {
   19443              :           /* DR 377
   19444              : 
   19445              :              IF no integral type can represent all the enumerator values, the
   19446              :              enumeration is ill-formed.  */
   19447            3 :           error ("no integral type can represent all of the enumerator values "
   19448              :                  "for %qT", enumtype);
   19449            3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   19450            3 :           underlying_type = integer_types[itk_unsigned_long_long];
   19451              :         }
   19452              : 
   19453              :       /* [dcl.enum]
   19454              : 
   19455              :          The value of sizeof() applied to an enumeration type, an object
   19456              :          of an enumeration type, or an enumerator, is the value of sizeof()
   19457              :          applied to the underlying type.  */
   19458      1471540 :       copy_type_enum (enumtype, underlying_type);
   19459              : 
   19460              :       /* Compute the minimum and maximum values for the type.
   19461              : 
   19462              :          [dcl.enum]
   19463              : 
   19464              :          For an enumeration where emin is the smallest enumerator and emax
   19465              :          is the largest, the values of the enumeration are the values of the
   19466              :          underlying type in the range bmin to bmax, where bmin and bmax are,
   19467              :          respectively, the smallest and largest values of the smallest bit-
   19468              :          field that can store emin and emax.  */
   19469              : 
   19470              :       /* The middle-end currently assumes that types with TYPE_PRECISION
   19471              :          narrower than their underlying type are suitably zero or sign
   19472              :          extended to fill their mode.  Similarly, it assumes that the front
   19473              :          end assures that a value of a particular type must be within
   19474              :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   19475              : 
   19476              :          We used to set these fields based on bmin and bmax, but that led
   19477              :          to invalid assumptions like optimizing away bounds checking.  So
   19478              :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   19479              :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   19480              :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   19481      1471540 :       ENUM_UNDERLYING_TYPE (enumtype)
   19482      1471540 :         = build_distinct_type_copy (underlying_type);
   19483      1471540 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   19484      1471540 :       set_min_and_max_values_for_integral_type
   19485      1471540 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   19486              : 
   19487              :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   19488      1471540 :       if (flag_strict_enums)
   19489           38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   19490              : 
   19491      1471540 :       if (use_short_enum)
   19492              :         {
   19493          126 :           TYPE_PACKED (enumtype) = use_short_enum;
   19494          126 :           fixup_attribute_variants (enumtype);
   19495              :         }
   19496              :     }
   19497              :   else
   19498       483473 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   19499              : 
   19500              :   /* If the enum is exported, mark the consts too.  */
   19501      1955013 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   19502      1548459 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   19503      1955601 :                    && at_namespace_scope_p ());
   19504              : 
   19505              :   /* Convert each of the enumerators to the type of the underlying
   19506              :      type of the enumeration.  */
   19507     13680485 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   19508              :     {
   19509     11725472 :       decl = TREE_VALUE (values);
   19510     11725472 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   19511     11725472 :       if (fixed_underlying_type_p)
   19512              :         /* If the enumeration type has a fixed underlying type, we
   19513              :            already checked all of the enumerator values.  */
   19514      4142886 :         value = DECL_INITIAL (decl);
   19515              :       else
   19516      7582586 :         value = perform_implicit_conversion (underlying_type,
   19517      7582586 :                                              DECL_INITIAL (decl),
   19518              :                                              tf_warning_or_error);
   19519     11725472 :       if (!value)
   19520            3 :         value = integer_zero_node;
   19521              :       /* Do not clobber shared ints.  But do share identical enumerators.  */
   19522     11725472 :       value = fold_convert (enumtype, value);
   19523              : 
   19524     11725472 :       DECL_INITIAL (decl) = value;
   19525     11725472 :       if (export_p)
   19526         3594 :         DECL_MODULE_EXPORT_P (decl) = true;
   19527     11725472 :     }
   19528              : 
   19529              :   /* Fix up all variant types of this enum type.  */
   19530      3910072 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   19531      1955059 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   19532              : 
   19533      1955013 :   if (at_class_scope_p ()
   19534      1041285 :       && COMPLETE_TYPE_P (current_class_type)
   19535      1955080 :       && UNSCOPED_ENUM_P (enumtype))
   19536              :     {
   19537           48 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   19538              :       /* TYPE_FIELDS needs fixup.  */
   19539           48 :       fixup_type_variants (current_class_type);
   19540              :     }
   19541              : 
   19542              :   /* P2115: An unnamed enum uses the name of its first enumerator for
   19543              :      linkage purposes; reset the type linkage if that is the case.  */
   19544      1955013 :   if (enum_with_enumerator_for_linkage_p (enumtype))
   19545       349078 :     reset_type_linkage (enumtype);
   19546              : 
   19547              :   /* Finish debugging output for this type.  */
   19548      1955013 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   19549              : 
   19550              :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   19551              :      so that this change in types doesn't confuse us later on.  */
   19552      1955013 :   clear_cv_and_fold_caches ();
   19553              : }
   19554              : 
   19555              : /* Finishes the enum type. This is called only the first time an
   19556              :    enumeration is seen, be it opaque or odinary.
   19557              :    ENUMTYPE is the type object.  */
   19558              : 
   19559              : void
   19560      2292789 : finish_enum (tree enumtype)
   19561              : {
   19562      2292789 :   if (processing_template_decl)
   19563              :     {
   19564       349223 :       if (at_function_scope_p ())
   19565         9581 :         add_stmt (build_min (TAG_DEFN, enumtype));
   19566              :       return;
   19567              :     }
   19568              : 
   19569              :   /* If this is a forward declaration, there should not be any variants,
   19570              :      though we can get a variant in the middle of an enum-specifier with
   19571              :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   19572      3887132 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   19573              :               && (TYPE_VALUES (enumtype)
   19574              :                   || !TYPE_NEXT_VARIANT (enumtype)));
   19575              : }
   19576              : 
   19577              : /* Build and install a CONST_DECL for an enumeration constant of the
   19578              :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   19579              :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   19580              :    Assignment of sequential values by default is handled here.  */
   19581              : 
   19582              : tree
   19583     12162001 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   19584              :                   location_t loc)
   19585              : {
   19586     12162001 :   tree decl;
   19587     12162001 :   tree context;
   19588     12162001 :   tree type;
   19589              : 
   19590              :   /* scalar_constant_value will pull out this expression, so make sure
   19591              :      it's folded as appropriate.
   19592              : 
   19593              :      Creating a TARGET_EXPR in a template breaks when substituting, and
   19594              :      here we would create it for instance when using a class prvalue with
   19595              :      a user-defined conversion function.  So don't use such a tree.  We
   19596              :      instantiate VALUE here to get errors about bad enumerators even in
   19597              :      a template that does not get instantiated.  */
   19598     12162001 :   if (processing_template_decl)
   19599       436546 :     value = maybe_fold_non_dependent_expr (value);
   19600              : 
   19601              :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   19602              :      result in the enum being assigned the next value in sequence.  */
   19603     12162001 :   if (value == error_mark_node)
   19604              :     value = NULL_TREE;
   19605              : 
   19606              :   /* Remove no-op casts from the value.  */
   19607     12161963 :   if (value)
   19608      9325859 :     STRIP_TYPE_NOPS (value);
   19609              : 
   19610     12162001 :   if (! processing_template_decl)
   19611              :     {
   19612              :       /* Validate and default VALUE.  */
   19613     11725455 :       if (value != NULL_TREE)
   19614              :         {
   19615      5330019 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   19616              :             {
   19617      2690199 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   19618              :                                                            value, true);
   19619      2690199 :               if (tmp_value)
   19620      5330019 :                 value = tmp_value;
   19621              :             }
   19622      2639820 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19623              :                    (TREE_TYPE (value)))
   19624           39 :             value = perform_implicit_conversion_flags
   19625           39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   19626              :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   19627              : 
   19628      5330019 :           if (value == error_mark_node)
   19629              :             value = NULL_TREE;
   19630              : 
   19631      5329998 :           if (value != NULL_TREE)
   19632              :             {
   19633      5329998 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19634              :                   (TREE_TYPE (value)))
   19635              :                 {
   19636           17 :                   error_at (cp_expr_loc_or_input_loc (value),
   19637              :                             "enumerator value for %qD must have integral or "
   19638              :                             "unscoped enumeration type", name);
   19639           17 :                   value = NULL_TREE;
   19640              :                 }
   19641              :               else
   19642              :                 {
   19643      5329981 :                   value = cxx_constant_value (value);
   19644              : 
   19645      5329981 :                   if (TREE_CODE (value) != INTEGER_CST)
   19646              :                     {
   19647           48 :                       error ("enumerator value for %qD is not an integer "
   19648              :                              "constant", name);
   19649           48 :                       value = NULL_TREE;
   19650              :                     }
   19651              :                 }
   19652              :             }
   19653              :         }
   19654              : 
   19655              :       /* Default based on previous value.  */
   19656           65 :       if (value == NULL_TREE)
   19657              :         {
   19658      6395522 :           if (TYPE_VALUES (enumtype))
   19659              :             {
   19660      5855313 :               tree prev_value;
   19661              : 
   19662              :               /* C++03 7.2/4: If no initializer is specified for the first
   19663              :                  enumerator, the type is an unspecified integral
   19664              :                  type. Otherwise the type is the same as the type of the
   19665              :                  initializing value of the preceding enumerator unless the
   19666              :                  incremented value is not representable in that type, in
   19667              :                  which case the type is an unspecified integral type
   19668              :                  sufficient to contain the incremented value.  */
   19669      5855313 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   19670      5855313 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   19671            2 :                 value = error_mark_node;
   19672              :               else
   19673              :                 {
   19674      5855311 :                   wi::overflow_type overflowed;
   19675      5855311 :                   tree type = TREE_TYPE (prev_value);
   19676      5855311 :                   signop sgn = TYPE_SIGN (type);
   19677      5855311 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   19678      5855311 :                                            &overflowed);
   19679      5855311 :                   if (!overflowed)
   19680              :                     {
   19681      5855311 :                       bool pos = !wi::neg_p (wi, sgn);
   19682      5855311 :                       if (!wi::fits_to_tree_p (wi, type))
   19683              :                         {
   19684              :                           unsigned int itk;
   19685           53 :                           for (itk = itk_int; itk != itk_none; itk++)
   19686              :                             {
   19687           53 :                               type = integer_types[itk];
   19688           53 :                               if (type != NULL_TREE
   19689           53 :                                   && (pos || !TYPE_UNSIGNED (type))
   19690          106 :                                   && wi::fits_to_tree_p (wi, type))
   19691              :                                 break;
   19692              :                             }
   19693           17 :                           if (type && cxx_dialect < cxx11
   19694            6 :                               && itk > itk_unsigned_long)
   19695            3 :                             pedwarn (input_location, OPT_Wlong_long,
   19696              :                                      pos ? G_("\
   19697              : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   19698              : incremented enumerator value is too large for %<long%>"));
   19699              :                         }
   19700      5855311 :                       if (type == NULL_TREE)
   19701            0 :                         overflowed = wi::OVF_UNKNOWN;
   19702              :                       else
   19703      5855311 :                         value = wide_int_to_tree (type, wi);
   19704              :                     }
   19705              : 
   19706      5855311 :                   if (overflowed)
   19707              :                     {
   19708            0 :                       error ("overflow in enumeration values at %qD", name);
   19709            0 :                       value = error_mark_node;
   19710              :                     }
   19711      5855311 :                 }
   19712              :             }
   19713              :           else
   19714       540209 :             value = integer_zero_node;
   19715              :         }
   19716              : 
   19717              :       /* Remove no-op casts from the value.  */
   19718     11725455 :       STRIP_TYPE_NOPS (value);
   19719              : 
   19720              :       /* If the underlying type of the enum is fixed, check whether
   19721              :          the enumerator values fits in the underlying type.  If it
   19722              :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   19723     11725455 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   19724              :           && value
   19725     11725455 :           && TREE_CODE (value) == INTEGER_CST)
   19726              :         {
   19727      4142867 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   19728            9 :             error ("enumerator value %qE is outside the range of underlying "
   19729            9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   19730              : 
   19731              :           /* Convert the value to the appropriate type.  */
   19732      4142867 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   19733              :         }
   19734              :     }
   19735              : 
   19736              :   /* C++ associates enums with global, function, or class declarations.  */
   19737     12162001 :   context = current_scope ();
   19738              : 
   19739              :   /* Build the actual enumeration constant.  Note that the enumeration
   19740              :      constants have the underlying type of the enum (if it is fixed)
   19741              :      or the type of their initializer (if the underlying type of the
   19742              :      enum is not fixed):
   19743              : 
   19744              :       [ C++0x dcl.enum ]
   19745              : 
   19746              :         If the underlying type is fixed, the type of each enumerator
   19747              :         prior to the closing brace is the underlying type; if the
   19748              :         initializing value of an enumerator cannot be represented by
   19749              :         the underlying type, the program is ill-formed. If the
   19750              :         underlying type is not fixed, the type of each enumerator is
   19751              :         the type of its initializing value.
   19752              : 
   19753              :     If the underlying type is not fixed, it will be computed by
   19754              :     finish_enum and we will reset the type of this enumerator.  Of
   19755              :     course, if we're processing a template, there may be no value.  */
   19756     12162001 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   19757              : 
   19758     12162001 :   decl = build_decl (loc, CONST_DECL, name, type);
   19759              : 
   19760     12162001 :   DECL_CONTEXT (decl) = enumtype;
   19761     12162001 :   TREE_CONSTANT (decl) = 1;
   19762     12162001 :   TREE_READONLY (decl) = 1;
   19763     12162001 :   DECL_INITIAL (decl) = value;
   19764              : 
   19765     12162001 :   if (attributes)
   19766       142054 :     cplus_decl_attributes (&decl, attributes, 0);
   19767              : 
   19768     12162001 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   19769              :     {
   19770              :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   19771              :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   19772              :          things like `S::i' later.)  */
   19773              : 
   19774              :       /* The enumerator may be getting declared outside of its enclosing
   19775              :          class, like so:
   19776              : 
   19777              :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   19778              : 
   19779              :          For which case we need to make sure that the access of `S::i'
   19780              :          matches the access of `S::E'.  */
   19781      2102649 :       auto cas = make_temp_override (current_access_specifier);
   19782      2102649 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   19783      2102649 :       finish_member_declaration (decl);
   19784      2102649 :     }
   19785              :   else
   19786     10059352 :     pushdecl (decl);
   19787              : 
   19788              :   /* Add this enumeration constant to the list for this type.  */
   19789     12162001 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   19790              : 
   19791     12162001 :   return decl;
   19792              : }
   19793              : 
   19794              : /* Look for an enumerator with the given NAME within the enumeration
   19795              :    type ENUMTYPE.  This routine is used primarily for qualified name
   19796              :    lookup into an enumerator in C++0x, e.g.,
   19797              : 
   19798              :      enum class Color { Red, Green, Blue };
   19799              : 
   19800              :      Color color = Color::Red;
   19801              : 
   19802              :    Returns the value corresponding to the enumerator, or
   19803              :    NULL_TREE if no such enumerator was found.  */
   19804              : tree
   19805     29437483 : lookup_enumerator (tree enumtype, tree name)
   19806              : {
   19807     29437483 :   tree e;
   19808     29437483 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   19809              : 
   19810     29437483 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   19811     58874868 :   return e? TREE_VALUE (e) : NULL_TREE;
   19812              : }
   19813              : 
   19814              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   19815              : 
   19816              : tree
   19817            0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   19818              :                         vec<string_int_pair> *values)
   19819              : {
   19820            0 :   location_t saved_loc = input_location;
   19821            0 :   input_location = loc;
   19822              : 
   19823            0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   19824              :                               NULL_TREE, false, NULL);
   19825            0 :   if (!OPAQUE_ENUM_P (enumtype))
   19826              :     {
   19827            0 :       auto_diagnostic_group d;
   19828            0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   19829            0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19830              :               "previous definition here");
   19831            0 :       return enumtype;
   19832            0 :     }
   19833            0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   19834            0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   19835              : 
   19836            0 :   for (const string_int_pair &value : values)
   19837            0 :     build_enumerator (get_identifier (value.first),
   19838            0 :                       build_int_cst (integer_type_node, value.second),
   19839              :                       enumtype, NULL_TREE, loc);
   19840              : 
   19841            0 :   finish_enum_value_list (enumtype);
   19842            0 :   finish_enum (enumtype);
   19843              : 
   19844            0 :   input_location = saved_loc;
   19845            0 :   return enumtype;
   19846              : }
   19847              : 
   19848              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   19849              : 
   19850              : tree
   19851            0 : cxx_simulate_record_decl (location_t loc, const char *name,
   19852              :                           array_slice<const tree> fields)
   19853              : {
   19854            0 :   iloc_sentinel ils (loc);
   19855              : 
   19856            0 :   tree ident = get_identifier (name);
   19857            0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   19858            0 :   if (type != error_mark_node
   19859            0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   19860              :     {
   19861            0 :       error ("redefinition of %q#T", type);
   19862            0 :       type = error_mark_node;
   19863              :     }
   19864            0 :   if (type == error_mark_node)
   19865            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19866              : 
   19867            0 :   xref_basetypes (type, NULL_TREE);
   19868            0 :   type = begin_class_definition (type);
   19869            0 :   if (type == error_mark_node)
   19870            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19871              : 
   19872            0 :   for (tree field : fields)
   19873            0 :     finish_member_declaration (field);
   19874              : 
   19875            0 :   type = finish_struct (type, NULL_TREE);
   19876              : 
   19877            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   19878            0 :   set_underlying_type (decl);
   19879            0 :   lang_hooks.decls.pushdecl (decl);
   19880              : 
   19881            0 :   return type;
   19882            0 : }
   19883              : 
   19884              : /* We're defining DECL.  Make sure that its type is OK.  */
   19885              : 
   19886              : static void
   19887    167105565 : check_function_type (tree decl, tree current_function_parms)
   19888              : {
   19889    167105565 :   tree fntype = TREE_TYPE (decl);
   19890    167105565 :   tree return_type = complete_type (TREE_TYPE (fntype));
   19891              : 
   19892              :   /* In a function definition, arg types must be complete.  */
   19893    167105565 :   require_complete_types_for_parms (current_function_parms);
   19894              : 
   19895    167105565 :   if (dependent_type_p (return_type)
   19896    167105565 :       || type_uses_auto (return_type))
   19897              :     return;
   19898    114030950 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   19899              :     {
   19900           12 :       tree args = TYPE_ARG_TYPES (fntype);
   19901              : 
   19902           12 :       error ("return type %q#T is incomplete", return_type);
   19903              : 
   19904              :       /* Make it return void instead.  */
   19905           12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   19906            3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   19907              :                                              void_type_node,
   19908            3 :                                              TREE_CHAIN (args));
   19909              :       else
   19910           18 :         fntype = build_function_type (void_type_node, args,
   19911            9 :                                       TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
   19912           12 :       fntype = (cp_build_type_attribute_variant
   19913           12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   19914           12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   19915           12 :       TREE_TYPE (decl) = fntype;
   19916              :     }
   19917              :   else
   19918              :     {
   19919    114030938 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   19920    114030938 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   19921    114030938 :                            DECL_SOURCE_LOCATION (decl));
   19922              :     }
   19923              : }
   19924              : 
   19925              : /* True iff FN is an implicitly-defined default constructor.  */
   19926              : 
   19927              : static bool
   19928     17415028 : implicit_default_ctor_p (tree fn)
   19929              : {
   19930     17415028 :   return (DECL_CONSTRUCTOR_P (fn)
   19931     17415028 :           && !user_provided_p (fn)
   19932     19389735 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   19933              : }
   19934              : 
   19935              : /* Clobber the contents of *this to let the back end know that the object
   19936              :    storage is dead when we enter the constructor or leave the destructor.  */
   19937              : 
   19938              : static tree
   19939      1516060 : build_clobber_this (clobber_kind kind)
   19940              : {
   19941              :   /* Clobbering an empty base is pointless, and harmful if its one byte
   19942              :      TYPE_SIZE overlays real data.  */
   19943      1516060 :   if (is_empty_class (current_class_type))
   19944            0 :     return void_node;
   19945              : 
   19946              :   /* If we have virtual bases, clobber the whole object, but only if we're in
   19947              :      charge.  If we don't have virtual bases, clobber the as-base type so we
   19948              :      don't mess with tail padding.  */
   19949      1516060 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   19950              : 
   19951      1516060 :   tree ctype = current_class_type;
   19952      1516060 :   if (!vbases)
   19953      1508521 :     ctype = CLASSTYPE_AS_BASE (ctype);
   19954              : 
   19955      1516060 :   tree clobber = build_clobber (ctype, kind);
   19956              : 
   19957      1516060 :   tree thisref = current_class_ref;
   19958      1516060 :   if (ctype != current_class_type)
   19959              :     {
   19960       173522 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   19961       173522 :       thisref = convert_from_reference (thisref);
   19962              :     }
   19963              : 
   19964      1516060 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   19965      1516060 :   if (kind == CLOBBER_OBJECT_BEGIN)
   19966            0 :     TREE_SET_CODE (exprstmt, INIT_EXPR);
   19967      1516060 :   if (vbases)
   19968         7539 :     exprstmt = build_if_in_charge (exprstmt);
   19969              : 
   19970              :   return exprstmt;
   19971              : }
   19972              : 
   19973              : /* Create the FUNCTION_DECL for a function definition.
   19974              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   19975              :    they describe the function's name and the type it returns,
   19976              :    but twisted together in a fashion that parallels the syntax of C.
   19977              : 
   19978              :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   19979              :    DECLARATOR is really the DECL for the function we are about to
   19980              :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   19981              :    indicating that the function is an inline defined in-class.
   19982              : 
   19983              :    This function creates a binding context for the function body
   19984              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   19985              : 
   19986              :    For C++, we must first check whether that datum makes any sense.
   19987              :    For example, "class A local_a(1,2);" means that variable local_a
   19988              :    is an aggregate of type A, which should have a constructor
   19989              :    applied to it with the argument list [1, 2].
   19990              : 
   19991              :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   19992              :    or may be a BLOCK if the function has been defined previously
   19993              :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   19994              :    error_mark_node if the function has never been defined, or
   19995              :    a BLOCK if the function has been defined somewhere.  */
   19996              : 
   19997              : bool
   19998    167105601 : start_preparsed_function (tree decl1, tree attrs, int flags)
   19999              : {
   20000    167105601 :   tree ctype = NULL_TREE;
   20001    167105601 :   bool doing_friend = false;
   20002              : 
   20003              :   /* Sanity check.  */
   20004    167105601 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   20005    167105601 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   20006              : 
   20007    167105601 :   tree fntype = TREE_TYPE (decl1);
   20008    167105601 :   if (DECL_CLASS_SCOPE_P (decl1))
   20009    123154301 :     ctype = DECL_CONTEXT (decl1);
   20010              :   else
   20011              :     {
   20012     87902600 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   20013              : 
   20014     43951299 :       if (ctype)
   20015    167105601 :         doing_friend = true;
   20016              :     }
   20017              : 
   20018              :   /* Adjust for #pragma target/optimize if this is an artificial function that
   20019              :      (probably) didn't go through grokfndecl.  We particularly don't want this
   20020              :      for deferred instantiations, which should match their template.  */
   20021    167105601 :   if (DECL_ARTIFICIAL (decl1))
   20022      3948731 :     decl_attributes (&decl1, NULL_TREE, 0);
   20023              : 
   20024    167105601 :   if (DECL_DECLARED_INLINE_P (decl1)
   20025    167105601 :       && lookup_attribute ("noinline", attrs))
   20026              :     {
   20027            0 :       auto_urlify_attributes sentinel;
   20028            0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   20029              :                   "inline function %qD given attribute %qs", decl1, "noinline");
   20030            0 :     }
   20031              : 
   20032              :   /* Handle gnu_inline attribute.  */
   20033    167105601 :   if (GNU_INLINE_P (decl1))
   20034              :     {
   20035      2008271 :       DECL_EXTERNAL (decl1) = 1;
   20036      2008271 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   20037      2008271 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20038      2008271 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   20039              :     }
   20040              : 
   20041    167105601 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   20042              :     /* This is a constructor, we must ensure that any default args
   20043              :        introduced by this definition are propagated to the clones
   20044              :        now. The clones are used directly in overload resolution.  */
   20045     20815271 :     adjust_clone_args (decl1);
   20046              : 
   20047              :   /* Sometimes we don't notice that a function is a static member, and
   20048              :      build a METHOD_TYPE for it.  Fix that up now.  */
   20049    167105601 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   20050              :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   20051              : 
   20052              :   /* Set up current_class_type, and enter the scope of the class, if
   20053              :      appropriate.  */
   20054    167105601 :   if (ctype)
   20055    127918910 :     push_nested_class (ctype);
   20056              : 
   20057              :   /* Now that we have entered the scope of the class, we must restore
   20058              :      the bindings for any template parameters surrounding DECL1, if it
   20059              :      is an inline member template.  (Order is important; consider the
   20060              :      case where a template parameter has the same name as a field of
   20061              :      the class.)  It is not until after this point that
   20062              :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   20063    167105601 :   if (flags & SF_INCLASS_INLINE)
   20064     85798955 :     maybe_begin_member_template_processing (decl1);
   20065              : 
   20066              :   /* Effective C++ rule 15.  */
   20067    167105601 :   if (warn_ecpp
   20068          123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   20069           30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   20070    167105631 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   20071            0 :     warning (OPT_Weffc__,
   20072              :              "%<operator=%> should return a reference to %<*this%>");
   20073              : 
   20074              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   20075              :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   20076    167105601 :   if (!DECL_INITIAL (decl1))
   20077     36383044 :     DECL_INITIAL (decl1) = error_mark_node;
   20078              : 
   20079              :   /* This function exists in static storage.
   20080              :      (This does not mean `static' in the C sense!)  */
   20081    167105601 :   TREE_STATIC (decl1) = 1;
   20082              : 
   20083              :   /* We must call push_template_decl after current_class_type is set
   20084              :      up.  (If we are processing inline definitions after exiting a
   20085              :      class scope, current_class_type will be NULL_TREE until set above
   20086              :      by push_nested_class.)  */
   20087    167105601 :   if (processing_template_decl)
   20088              :     {
   20089     98085988 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   20090     98085988 :       if (newdecl1 == error_mark_node)
   20091              :         {
   20092           36 :           if (ctype)
   20093            9 :             pop_nested_class ();
   20094              :           return false;
   20095              :         }
   20096     98085952 :       decl1 = newdecl1;
   20097              :     }
   20098              : 
   20099              :   /* Make sure the parameter and return types are reasonable.  When
   20100              :      you declare a function, these types can be incomplete, but they
   20101              :      must be complete when you define the function.  */
   20102    167105565 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   20103              : 
   20104              :   /* Build the return declaration for the function.  */
   20105    167105565 :   tree restype = TREE_TYPE (fntype);
   20106              : 
   20107    167105565 :   if (DECL_RESULT (decl1) == NULL_TREE)
   20108              :     {
   20109              :       /* In a template instantiation, copy the return type location.  When
   20110              :          parsing, the location will be set in grokdeclarator.  */
   20111     69049240 :       location_t loc = input_location;
   20112     69049240 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   20113              :         {
   20114     32758044 :           tree tmpl = template_for_substitution (decl1);
   20115     32758044 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   20116     31803994 :             loc = DECL_SOURCE_LOCATION (res);
   20117              :         }
   20118              : 
   20119     69049240 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   20120     69049240 :       DECL_ARTIFICIAL (resdecl) = 1;
   20121     69049240 :       DECL_IGNORED_P (resdecl) = 1;
   20122     69049240 :       DECL_RESULT (decl1) = resdecl;
   20123              : 
   20124     69049240 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   20125              :     }
   20126              : 
   20127              :   /* Record the decl so that the function name is defined.
   20128              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   20129              :      use the old decl.  */
   20130    167105565 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   20131              :     {
   20132              :       /* A specialization is not used to guide overload resolution.  */
   20133     20651519 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   20134     20631665 :           && !(DECL_USE_TEMPLATE (decl1) &&
   20135        13329 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   20136              :         {
   20137      9890100 :           tree olddecl = pushdecl (decl1);
   20138              : 
   20139      9890100 :           if (olddecl == error_mark_node)
   20140              :             /* If something went wrong when registering the declaration,
   20141              :                use DECL1; we have to have a FUNCTION_DECL to use when
   20142              :                parsing the body of the function.  */
   20143              :             ;
   20144              :           else
   20145              :             {
   20146              :               /* Otherwise, OLDDECL is either a previous declaration
   20147              :                  of the same function or DECL1 itself.  */
   20148              : 
   20149      9889887 :               if (warn_missing_declarations
   20150           21 :                   && olddecl == decl1
   20151           15 :                   && !DECL_MAIN_P (decl1)
   20152           15 :                   && TREE_PUBLIC (decl1)
   20153      9889899 :                   && !DECL_DECLARED_INLINE_P (decl1))
   20154              :                 {
   20155            9 :                   tree context;
   20156              : 
   20157              :                   /* Check whether DECL1 is in an anonymous
   20158              :                      namespace.  */
   20159            9 :                   for (context = DECL_CONTEXT (decl1);
   20160           18 :                        context;
   20161            9 :                        context = DECL_CONTEXT (context))
   20162              :                     {
   20163           12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   20164           12 :                           && DECL_NAME (context) == NULL_TREE)
   20165              :                         break;
   20166              :                     }
   20167              : 
   20168            9 :                   if (context == NULL)
   20169            6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   20170            6 :                                 OPT_Wmissing_declarations,
   20171              :                                 "no previous declaration for %qD", decl1);
   20172              :                 }
   20173              : 
   20174      9889887 :               decl1 = olddecl;
   20175              :             }
   20176              :         }
   20177              :       else
   20178              :         {
   20179              :           /* We need to set the DECL_CONTEXT.  */
   20180       838136 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   20181            0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   20182              :         }
   20183     10728236 :       fntype = TREE_TYPE (decl1);
   20184     10728236 :       restype = TREE_TYPE (fntype);
   20185              : 
   20186              :       /* If #pragma weak applies, mark the decl appropriately now.
   20187              :          The pragma only applies to global functions.  Because
   20188              :          determining whether or not the #pragma applies involves
   20189              :          computing the mangled name for the declaration, we cannot
   20190              :          apply the pragma until after we have merged this declaration
   20191              :          with any previous declarations; if the original declaration
   20192              :          has a linkage specification, that specification applies to
   20193              :          the definition as well, and may affect the mangled name.  */
   20194     10728236 :       if (DECL_FILE_SCOPE_P (decl1))
   20195      2553737 :         maybe_apply_pragma_weak (decl1);
   20196              :     }
   20197              : 
   20198              :   /* We are now in the scope of the function being defined.  */
   20199    167105565 :   current_function_decl = decl1;
   20200              : 
   20201              :   /* Save the parm names or decls from this function's declarator
   20202              :      where store_parm_decls will find them.  */
   20203    167105565 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   20204              : 
   20205              :   /* Let the user know we're compiling this function.  */
   20206    167105565 :   announce_function (decl1);
   20207              : 
   20208    167105565 :   gcc_assert (DECL_INITIAL (decl1));
   20209              : 
   20210              :   /* This function may already have been parsed, in which case just
   20211              :      return; our caller will skip over the body without parsing.  */
   20212    167105565 :   if (DECL_INITIAL (decl1) != error_mark_node)
   20213              :     return true;
   20214              : 
   20215              :   /* Initialize RTL machinery.  We cannot do this until
   20216              :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   20217              :      even when processing a template; this is how we get
   20218              :      CFUN set up, and our per-function variables initialized.
   20219              :      FIXME factor out the non-RTL stuff.  */
   20220    167100737 :   cp_binding_level *bl = current_binding_level;
   20221    167100737 :   allocate_struct_function (decl1, processing_template_decl);
   20222              : 
   20223              :   /* Initialize the language data structures.  Whenever we start
   20224              :      a new function, we destroy temporaries in the usual way.  */
   20225    167100737 :   cfun->language = ggc_cleared_alloc<language_function> ();
   20226    167100737 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   20227    167100737 :   current_binding_level = bl;
   20228              : 
   20229              :   /* If we are (erroneously) defining a function that we have already
   20230              :      defined before, wipe out what we knew before.  */
   20231    167100737 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   20232    167100737 :   FNDECL_USED_AUTO (decl1) = false;
   20233    167100737 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   20234              : 
   20235    167100737 :   if (!processing_template_decl && type_uses_auto (restype))
   20236              :     {
   20237      1199500 :       FNDECL_USED_AUTO (decl1) = true;
   20238      1199500 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   20239              :     }
   20240              : 
   20241              :   /* Start the statement-tree, start the tree now.  */
   20242    167100737 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   20243              : 
   20244    167100737 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   20245              :     {
   20246              :       /* We know that this was set up by `grokclassfn'.  We do not
   20247              :          wait until `store_parm_decls', since evil parse errors may
   20248              :          never get us to that point.  Here we keep the consistency
   20249              :          between `current_class_type' and `current_class_ptr'.  */
   20250    108423088 :       tree t = DECL_ARGUMENTS (decl1);
   20251              : 
   20252    108423088 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   20253    108423088 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   20254              : 
   20255    108423088 :       cp_function_chain->x_current_class_ref
   20256    108423088 :         = cp_build_fold_indirect_ref (t);
   20257              :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   20258    108423088 :       cp_function_chain->x_current_class_ptr = t;
   20259              : 
   20260              :       /* Constructors and destructors need to know whether they're "in
   20261              :          charge" of initializing virtual base classes.  */
   20262    108423088 :       t = DECL_CHAIN (t);
   20263    108423088 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   20264              :         {
   20265        17829 :           current_in_charge_parm = t;
   20266        17829 :           t = DECL_CHAIN (t);
   20267              :         }
   20268    108423088 :       if (DECL_HAS_VTT_PARM_P (decl1))
   20269              :         {
   20270        35713 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   20271        35713 :           current_vtt_parm = t;
   20272              :         }
   20273              :     }
   20274              : 
   20275    301425825 :   bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
   20276              :                           /* Implicitly-defined methods (like the
   20277              :                              destructor for a class in which no destructor
   20278              :                              is explicitly declared) must not be defined
   20279              :                              until their definition is needed.  So, we
   20280              :                              ignore interface specifications for
   20281              :                              compiler-generated functions.  */
   20282    203276070 :                           && !DECL_ARTIFICIAL (decl1));
   20283    167100737 :   struct c_fileinfo *finfo
   20284    167100737 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   20285              : 
   20286    167100737 :   if (processing_template_decl)
   20287              :     /* Don't mess with interface flags.  */;
   20288     69018239 :   else if (DECL_INTERFACE_KNOWN (decl1))
   20289              :     {
   20290     20120837 :       tree ctx = decl_function_context (decl1);
   20291              : 
   20292     20120837 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   20293     16027862 :         DECL_EXTERNAL (decl1) = 0;
   20294              : 
   20295     20120837 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   20296              :         /* This is a function in a local class in an extern inline
   20297              :            or template function.  */
   20298      3135139 :         comdat_linkage (decl1);
   20299              :     }
   20300              :   /* If this function belongs to an interface, it is public.
   20301              :      If it belongs to someone else's interface, it is also external.
   20302              :      This only affects inlines and template instantiations.  */
   20303     48897402 :   else if (!finfo->interface_unknown && honor_interface)
   20304              :     {
   20305          106 :       if (DECL_DECLARED_INLINE_P (decl1)
   20306          106 :           || DECL_TEMPLOID_INSTANTIATION (decl1))
   20307              :         {
   20308           82 :           DECL_EXTERNAL (decl1)
   20309          164 :             = (finfo->interface_only
   20310           82 :                || (DECL_DECLARED_INLINE_P (decl1)
   20311           36 :                    && ! flag_implement_inlines
   20312            0 :                    && !DECL_VINDEX (decl1)));
   20313              : 
   20314              :           /* For WIN32 we also want to put these in linkonce sections.  */
   20315           82 :           maybe_make_one_only (decl1);
   20316              :         }
   20317              :       else
   20318           24 :         DECL_EXTERNAL (decl1) = 0;
   20319          106 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20320              :       /* If this function is in an interface implemented in this file,
   20321              :          make sure that the back end knows to emit this function
   20322              :          here.  */
   20323          106 :       if (!DECL_EXTERNAL (decl1))
   20324           60 :         mark_needed (decl1);
   20325              :     }
   20326     48897296 :   else if (finfo->interface_unknown && finfo->interface_only
   20327            0 :            && honor_interface)
   20328              :     {
   20329              :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   20330              :          interface, we will have both finfo->interface_unknown and
   20331              :          finfo->interface_only set.  In that case, we don't want to
   20332              :          use the normal heuristics because someone will supply a
   20333              :          #pragma implementation elsewhere, and deducing it here would
   20334              :          produce a conflict.  */
   20335            0 :       comdat_linkage (decl1);
   20336            0 :       DECL_EXTERNAL (decl1) = 0;
   20337            0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20338            0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   20339              :     }
   20340              :   else
   20341              :     {
   20342              :       /* This is a definition, not a reference.
   20343              :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   20344     48897296 :       if (!GNU_INLINE_P (decl1))
   20345     48897293 :         DECL_EXTERNAL (decl1) = 0;
   20346              : 
   20347     48897296 :       if ((DECL_DECLARED_INLINE_P (decl1)
   20348      1907039 :            || DECL_TEMPLOID_INSTANTIATION (decl1))
   20349     50563211 :           && ! DECL_INTERFACE_KNOWN (decl1))
   20350     48656172 :         DECL_DEFER_OUTPUT (decl1) = 1;
   20351              :       else
   20352       241124 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   20353              :     }
   20354              : 
   20355              :   /* Determine the ELF visibility attribute for the function.  We must not
   20356              :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   20357              :      to merge any attributes appropriately.  We also need to wait until
   20358              :      linkage is set.  */
   20359    167100737 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   20360    150563420 :     determine_visibility (decl1);
   20361              : 
   20362    167100737 :   if (!processing_template_decl)
   20363     69018239 :     maybe_instantiate_noexcept (decl1);
   20364              : 
   20365    167100737 :   begin_scope (sk_function_parms, decl1);
   20366              : 
   20367    167100737 :   ++function_depth;
   20368              : 
   20369    167100737 :   start_fname_decls ();
   20370              : 
   20371    167100737 :   store_parm_decls (current_function_parms);
   20372              : 
   20373    167100737 :   start_function_contracts (decl1);
   20374              : 
   20375    167100737 :   if (!processing_template_decl
   20376     69018239 :       && flag_lifetime_dse > 1
   20377    138027096 :       && DECL_CONSTRUCTOR_P (decl1)
   20378              :       /* Clobbering an empty base is harmful if it overlays real data.  */
   20379     19330001 :       && !is_empty_class (current_class_type)
   20380              :       /* We can't clobber safely for an implicitly-defined default constructor
   20381              :          because part of the initialization might happen before we enter the
   20382              :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   20383     17414383 :       && !implicit_default_ctor_p (decl1)
   20384    183299831 :       && !lookup_attribute ("clobber *this",
   20385     16199094 :                             DECL_ATTRIBUTES (current_class_ptr)))
   20386     16189826 :     DECL_ATTRIBUTES (current_class_ptr)
   20387     32379652 :       = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
   20388     16189826 :                    DECL_ATTRIBUTES (current_class_ptr));
   20389              : 
   20390    167100737 :   if (!processing_template_decl
   20391    138036478 :       && DECL_CONSTRUCTOR_P (decl1)
   20392     19331249 :       && sanitize_flags_p (SANITIZE_VPTR)
   20393         1935 :       && !DECL_CLONED_FUNCTION_P (decl1)
   20394    167101382 :       && !implicit_default_ctor_p (decl1))
   20395          485 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   20396              : 
   20397    167100737 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   20398    167100160 :     start_lambda_scope (decl1);
   20399              : 
   20400              :   return true;
   20401              : }
   20402              : 
   20403              : 
   20404              : /* Like start_preparsed_function, except that instead of a
   20405              :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   20406              : 
   20407              :    Returns true on success.  If the DECLARATOR is not suitable
   20408              :    for a function, we return false, which tells the parser to
   20409              :    skip the entire function.  */
   20410              : 
   20411              : bool
   20412     40003073 : start_function (cp_decl_specifier_seq *declspecs,
   20413              :                 const cp_declarator *declarator,
   20414              :                 tree attrs)
   20415              : {
   20416     40003073 :   tree decl1;
   20417              : 
   20418     40003073 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   20419     40003073 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   20420     40003073 :   if (decl1 == error_mark_node)
   20421              :     return false;
   20422              : 
   20423     40002707 :   if (DECL_MAIN_P (decl1))
   20424              :     /* main must return int.  grokfndecl should have corrected it
   20425              :        (and issued a diagnostic) if the user got it wrong.  */
   20426        33954 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   20427              :                              integer_type_node));
   20428              : 
   20429     40002707 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   20430              : }
   20431              : 
   20432              : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   20433              :    FN.  */
   20434              : 
   20435              : bool
   20436    320066063 : use_eh_spec_block (tree fn)
   20437              : {
   20438    318086701 :   return (flag_exceptions && flag_enforce_eh_specs
   20439    318086701 :           && !processing_template_decl
   20440              :           /* We insert the EH_SPEC_BLOCK only in the original
   20441              :              function; then, it is copied automatically to the
   20442              :              clones.  */
   20443    120575197 :           && !DECL_CLONED_FUNCTION_P (fn)
   20444              :           /* Implicitly-generated constructors and destructors have
   20445              :              exception specifications.  However, those specifications
   20446              :              are the union of the possible exceptions specified by the
   20447              :              constructors/destructors for bases and members, so no
   20448              :              unallowed exception will ever reach this function.  By
   20449              :              not creating the EH_SPEC_BLOCK we save a little memory,
   20450              :              and we avoid spurious warnings about unreachable
   20451              :              code.  */
   20452    104079659 :           && !DECL_DEFAULTED_FN (fn)
   20453    421578960 :           && !type_throw_all_p (TREE_TYPE (fn)));
   20454              : }
   20455              : 
   20456              : /* Helper function to push ARGS into the current lexical scope.  DECL
   20457              :    is the function declaration.  NONPARMS is used to handle enum
   20458              :    constants.  */
   20459              : 
   20460              : void
   20461    162035253 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   20462              : {
   20463              :   /* If we're doing semantic analysis, then we'll call pushdecl
   20464              :      for each of these.  We must do them in reverse order so that
   20465              :      they end in the correct forward order.  */
   20466    162035253 :   args = nreverse (args);
   20467              : 
   20468    162035253 :   tree next;
   20469    658932824 :   for (tree parm = args; parm; parm = next)
   20470              :     {
   20471    334862318 :       next = DECL_CHAIN (parm);
   20472    334862318 :       if (TREE_CODE (parm) == PARM_DECL)
   20473    334862318 :         pushdecl (parm);
   20474            0 :       else if (nonparms)
   20475              :         {
   20476              :           /* If we find an enum constant or a type tag, put it aside for
   20477              :              the moment.  */
   20478            0 :           TREE_CHAIN (parm) = NULL_TREE;
   20479            0 :           *nonparms = chainon (*nonparms, parm);
   20480              :         }
   20481              :     }
   20482              : 
   20483              :   /* Get the decls in their original chain order and record in the
   20484              :      function.  This is all and only the PARM_DECLs that were
   20485              :      pushed into scope by the loop above.  */
   20486    162035253 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   20487    162035253 : }
   20488              : 
   20489              : /* Store the parameter declarations into the current function declaration.
   20490              :    This is called after parsing the parameter declarations, before
   20491              :    digesting the body of the function.
   20492              : 
   20493              :    Also install to binding contour return value identifier, if any.  */
   20494              : 
   20495              : static void
   20496    167100737 : store_parm_decls (tree current_function_parms)
   20497              : {
   20498    167100737 :   tree fndecl = current_function_decl;
   20499              : 
   20500              :   /* This is a chain of any other decls that came in among the parm
   20501              :      declarations.  If a parm is declared with  enum {foo, bar} x;
   20502              :      then CONST_DECLs for foo and bar are put here.  */
   20503    167100737 :   tree nonparms = NULL_TREE;
   20504              : 
   20505    167100737 :   if (current_function_parms)
   20506              :     {
   20507              :       /* This case is when the function was defined with an ANSI prototype.
   20508              :          The parms already have decls, so we need not do anything here
   20509              :          except record them as in effect
   20510              :          and complain if any redundant old-style parm decls were written.  */
   20511              : 
   20512    158437637 :       tree specparms = current_function_parms;
   20513              : 
   20514              :       /* Must clear this because it might contain TYPE_DECLs declared
   20515              :              at class level.  */
   20516    158437637 :       current_binding_level->names = NULL;
   20517              : 
   20518    158437637 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   20519              :     }
   20520              :   else
   20521      8663100 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   20522              : 
   20523              :   /* Now store the final chain of decls for the arguments
   20524              :      as the decl-chain of the current lexical scope.
   20525              :      Put the enumerators in as well, at the front so that
   20526              :      DECL_ARGUMENTS is not modified.  */
   20527    167100737 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   20528              : 
   20529              :   /* Register cleanups for parameters with trivial_abi attribute, the cleanup
   20530              :      of which is the callee's responsibility.  */
   20531    167100737 :   if (!processing_template_decl && !DECL_CLONED_FUNCTION_P (fndecl))
   20532    135471423 :     for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   20533              :       {
   20534     82990501 :         if (TREE_CODE (parm) == PARM_DECL)
   20535              :           {
   20536     82990501 :             tree parm_type = TREE_TYPE (parm);
   20537     82990501 :             if (has_trivial_abi_attribute (parm_type))
   20538              :               {
   20539           18 :                 tree cleanup
   20540           18 :                   = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
   20541           18 :                 if (cleanup && cleanup != error_mark_node)
   20542           18 :                   finish_decl_cleanup (parm, cleanup);
   20543              :               }
   20544              :           }
   20545              :       }
   20546              : 
   20547    167100737 :   if (use_eh_spec_block (current_function_decl))
   20548     25386519 :     current_eh_spec_block = begin_eh_spec_block ();
   20549    167100737 : }
   20550              : 
   20551              : 
   20552              : /* Mark CDTOR's implicit THIS argument for returning, if required by
   20553              :    the ABI..  Return the decl for THIS, if it is to be returned, and
   20554              :    NULL otherwise.  */
   20555              : 
   20556              : tree
   20557    143170701 : maybe_prepare_return_this (tree cdtor)
   20558              : {
   20559    143170701 :   if (targetm.cxx.cdtor_returns_this ())
   20560            0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   20561              :       {
   20562            0 :         suppress_warning (val, OPT_Wuse_after_free_);
   20563            0 :         return val;
   20564              :       }
   20565              : 
   20566              :   return NULL_TREE;
   20567              : }
   20568              : 
   20569              : /* Set the return value of the [cd]tor if the ABI wants that.  */
   20570              : 
   20571              : void
   20572      8420519 : maybe_return_this ()
   20573              : {
   20574      8420519 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   20575              :     {
   20576              :       /* Return the address of the object.  */
   20577            0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   20578            0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   20579            0 :                     DECL_RESULT (current_function_decl), val);
   20580            0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   20581            0 :       add_stmt (exprstmt);
   20582              :     }
   20583      8420519 : }
   20584              : 
   20585              : /* Do all the processing for the beginning of a destructor; set up the
   20586              :    vtable pointers and cleanups for bases and members.  */
   20587              : 
   20588              : static void
   20589      1659667 : begin_destructor_body (void)
   20590              : {
   20591      1659667 :   tree compound_stmt;
   20592              : 
   20593              :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   20594              :      issued an error message.  We still want to try to process the
   20595              :      body of the function, but initialize_vtbl_ptrs will crash if
   20596              :      TYPE_BINFO is NULL.  */
   20597      1659667 :   if (COMPLETE_TYPE_P (current_class_type))
   20598              :     {
   20599      1659667 :       compound_stmt = begin_compound_stmt (0);
   20600              :       /* Make all virtual function table pointers in non-virtual base
   20601              :          classes point to CURRENT_CLASS_TYPE's virtual function
   20602              :          tables.  */
   20603      1659667 :       initialize_vtbl_ptrs (current_class_ptr);
   20604      1659667 :       finish_compound_stmt (compound_stmt);
   20605              : 
   20606      1659667 :       if (flag_lifetime_dse
   20607              :           /* Clobbering an empty base is harmful if it overlays real data.  */
   20608      1659667 :           && !is_empty_class (current_class_type))
   20609              :       {
   20610      1516123 :         if (sanitize_flags_p (SANITIZE_VPTR)
   20611          239 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   20612      1516186 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   20613              :           {
   20614           63 :             tree binfo = TYPE_BINFO (current_class_type);
   20615           63 :             tree ref
   20616           63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   20617              : 
   20618           63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   20619           63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   20620           63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   20621              :                                               NOP_EXPR, vtbl,
   20622              :                                               tf_warning_or_error);
   20623              :             /* If the vptr is shared with some virtual nearly empty base,
   20624              :                don't clear it if not in charge, the dtor of the virtual
   20625              :                nearly empty base will do that later.  */
   20626           63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   20627              :               {
   20628              :                 tree c = current_class_type;
   20629           66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   20630              :                   {
   20631           63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   20632              :                       {
   20633           36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   20634              :                                                 tf_warning_or_error);
   20635           36 :                         stmt = build_if_in_charge (stmt);
   20636           36 :                         break;
   20637              :                       }
   20638           27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   20639              :                   }
   20640              :               }
   20641           63 :             finish_decl_cleanup (NULL_TREE, stmt);
   20642              :           }
   20643              :         else
   20644      1516060 :           finish_decl_cleanup (NULL_TREE,
   20645              :                                build_clobber_this (CLOBBER_OBJECT_END));
   20646              :       }
   20647              : 
   20648              :       /* And insert cleanups for our bases and members so that they
   20649              :          will be properly destroyed if we throw.  */
   20650      1659667 :       push_base_cleanups ();
   20651              :     }
   20652      1659667 : }
   20653              : 
   20654              : /* Do the necessary processing for the beginning of a function body, which
   20655              :    in this case includes member-initializers, but not the catch clauses of
   20656              :    a function-try-block.  Currently, this means opening a binding level
   20657              :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   20658              :    and capture proxies (in a lambda operator()).  */
   20659              : 
   20660              : tree
   20661    131353632 : begin_function_body (void)
   20662              : {
   20663    270426326 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   20664              :     return NULL_TREE;
   20665              : 
   20666     25683474 :   if (processing_template_decl)
   20667              :     /* Do nothing now.  */;
   20668              :   else
   20669              :     /* Always keep the BLOCK node associated with the outermost pair of
   20670              :        curly braces of a function.  These are needed for correct
   20671              :        operation of dwarfout.c.  */
   20672      8594729 :     keep_next_level (true);
   20673              : 
   20674     25683474 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   20675     25683474 :   current_binding_level->artificial = 1;
   20676              : 
   20677     25683474 :   if (processing_template_decl)
   20678              :     /* Do nothing now.  */;
   20679     17189458 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   20680      1659667 :     begin_destructor_body ();
   20681              : 
   20682              :   return stmt;
   20683              : }
   20684              : 
   20685              : /* Do the processing for the end of a function body.  Currently, this means
   20686              :    closing out the cleanups for fully-constructed bases and members, and in
   20687              :    the case of the destructor, deleting the object if desired.  Again, this
   20688              :    is only meaningful for [cd]tors, since they are the only functions where
   20689              :    there is a significant distinction between the main body and any
   20690              :    function catch clauses.  Handling, say, main() return semantics here
   20691              :    would be wrong, as flowing off the end of a function catch clause for
   20692              :    main() would also need to return 0.  */
   20693              : 
   20694              : void
   20695    131353606 : finish_function_body (tree compstmt)
   20696              : {
   20697    131353606 :   if (compstmt == NULL_TREE)
   20698              :     return;
   20699              : 
   20700              :   /* Close the block.  */
   20701     25683472 :   finish_compound_stmt (compstmt);
   20702              : 
   20703     25683472 :   if (processing_template_decl)
   20704              :     /* Do nothing now.  */;
   20705      8594727 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   20706      8594727 :            || DECL_DESTRUCTOR_P (current_function_decl))
   20707      8098912 :     maybe_return_this ();
   20708              : }
   20709              : 
   20710              : /* Given a function, returns the BLOCK corresponding to the outermost level
   20711              :    of curly braces, skipping the artificial block created for constructor
   20712              :    initializers.  */
   20713              : 
   20714              : tree
   20715       358225 : outer_curly_brace_block (tree fndecl)
   20716              : {
   20717       358225 :   tree block = DECL_INITIAL (fndecl);
   20718       358225 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20719              :     return block;
   20720         1223 :   block = BLOCK_SUBBLOCKS (block);
   20721         1223 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20722              :     return block;
   20723            0 :   block = BLOCK_SUBBLOCKS (block);
   20724            0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   20725              :   return block;
   20726              : }
   20727              : 
   20728              : /* If FNDECL is a class's key method, add the class to the list of
   20729              :    keyed classes that should be emitted.  */
   20730              : 
   20731              : static void
   20732    167104681 : record_key_method_defined (tree fndecl)
   20733              : {
   20734    225786252 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   20735    108518895 :       && DECL_VIRTUAL_P (fndecl)
   20736    169936130 :       && !processing_template_decl)
   20737              :     {
   20738      1479783 :       tree fnclass = DECL_CONTEXT (fndecl);
   20739      1479783 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   20740              :         {
   20741        31184 :           tree classdecl = TYPE_NAME (fnclass);
   20742              :           /* Classes attached to a named module are already handled.  */
   20743        31184 :           if (!DECL_LANG_SPECIFIC (classdecl)
   20744        31507 :               || !DECL_MODULE_ATTACH_P (classdecl))
   20745        31139 :             vec_safe_push (keyed_classes, fnclass);
   20746              :         }
   20747              :     }
   20748    167104681 : }
   20749              : 
   20750              : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   20751              :    of "return *this;" immediately before its location, using FNDECL's
   20752              :    first statement (if any) to give the indentation, if appropriate.  */
   20753              : 
   20754              : static void
   20755           18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   20756              : {
   20757           18 :   location_t indent = UNKNOWN_LOCATION;
   20758           18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   20759           18 :   if (stmts)
   20760            9 :     indent = EXPR_LOCATION (stmts);
   20761           18 :   richloc->add_fixit_insert_formatted ("return *this;",
   20762              :                                        richloc->get_loc (),
   20763              :                                        indent);
   20764           18 : }
   20765              : 
   20766              : /* Finish up a function declaration and compile that function
   20767              :    all the way to assembler language output.  The free the storage
   20768              :    for the function definition. INLINE_P is TRUE if we just
   20769              :    finished processing the body of an in-class inline function
   20770              :    definition.  (This processing will have taken place after the
   20771              :    class definition is complete.)  */
   20772              : 
   20773              : tree
   20774    167100697 : finish_function (bool inline_p)
   20775              : {
   20776    167100697 :   tree fndecl = current_function_decl;
   20777    167100697 :   tree fntype, ctype = NULL_TREE;
   20778    167100697 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   20779              : 
   20780              :   /* When we get some parse errors, we can end up without a
   20781              :      current_function_decl, so cope.  */
   20782    167100697 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   20783            0 :     return error_mark_node;
   20784              : 
   20785    167100697 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20786    167100120 :     finish_lambda_scope ();
   20787              : 
   20788    167100697 :   if (c_dialect_objc ())
   20789            0 :     objc_finish_function ();
   20790              : 
   20791    167100697 :   record_key_method_defined (fndecl);
   20792              : 
   20793    167100697 :   fntype = TREE_TYPE (fndecl);
   20794              : 
   20795              :   /*  TREE_READONLY (fndecl) = 1;
   20796              :       This caused &foo to be of type ptr-to-const-function
   20797              :       which then got a warning when stored in a ptr-to-function variable.  */
   20798              : 
   20799    167100697 :   gcc_assert (building_stmt_list_p ());
   20800              :   /* The current function is being defined, so its DECL_INITIAL should
   20801              :      be set, and unless there's a multiple definition, it should be
   20802              :      error_mark_node.  */
   20803    167100697 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   20804              : 
   20805    167100697 :   cp_coroutine_transform *coroutine = nullptr;
   20806    167100697 :   if (flag_coroutines
   20807    164342903 :       && !processing_template_decl
   20808     67227527 :       && DECL_COROUTINE_P (fndecl)
   20809    167105707 :       && !DECL_RAMP_FN (fndecl))
   20810              :     {
   20811         1722 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   20812              :                            && !DECL_DEFAULTED_FN (fndecl));
   20813         1722 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   20814         1722 :       if (coroutine && coroutine->cp_valid_coroutine ())
   20815         1722 :         coroutine->apply_transforms ();
   20816              : 
   20817              :       /* We should handle coroutine IFNs in middle end lowering.  */
   20818         1722 :       cfun->coroutine_component = true;
   20819              : 
   20820              :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   20821         1722 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   20822          360 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20823              :                               (TREE_TYPE (fndecl)),
   20824          360 :                               current_eh_spec_block);
   20825              : 
   20826              :      /* If outlining succeeded, then add contracts handling if needed.  */
   20827         1722 :      if (coroutine->cp_valid_coroutine ())
   20828         1644 :         maybe_apply_function_contracts (fndecl);
   20829              :     }
   20830              :   else
   20831              :   /* For a cloned function, we've already got all the code we need;
   20832              :      there's no need to add any extra bits.  */
   20833    167098975 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   20834              :     {
   20835              :       /* Make it so that `main' always returns 0 by default.  */
   20836    150561658 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   20837    150595597 :           && !TREE_THIS_VOLATILE (current_function_decl))
   20838        33939 :         finish_return_stmt (integer_zero_node);
   20839              : 
   20840    150561658 :       if (use_eh_spec_block (current_function_decl))
   20841     25386156 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20842              :                               (TREE_TYPE (current_function_decl)),
   20843     25386156 :                               current_eh_spec_block);
   20844              : 
   20845    150561658 :       maybe_apply_function_contracts (current_function_decl);
   20846              : 
   20847              :     }
   20848              : 
   20849              :   /* If we're saving up tree structure, tie off the function now.  */
   20850    167100697 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   20851              : 
   20852    167100697 :   finish_fname_decls ();
   20853              : 
   20854              :   /* This must come after expand_function_end because cleanups might
   20855              :      have declarations (from inline functions) that need to go into
   20856              :      this function's blocks.  */
   20857              : 
   20858              :   /* If the current binding level isn't the outermost binding level
   20859              :      for this function, either there is a bug, or we have experienced
   20860              :      syntax errors and the statement tree is malformed.  */
   20861    167100697 :   if (current_binding_level->kind != sk_function_parms)
   20862              :     {
   20863              :       /* Make sure we have already experienced errors.  */
   20864           12 :       gcc_assert (errorcount);
   20865              : 
   20866              :       /* Throw away the broken statement tree and extra binding
   20867              :          levels.  */
   20868           12 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   20869              : 
   20870           27 :       while (current_binding_level->kind != sk_function_parms)
   20871              :         {
   20872           15 :           if (current_binding_level->kind == sk_class)
   20873            0 :             pop_nested_class ();
   20874              :           else
   20875           15 :             poplevel (0, 0, 0);
   20876              :         }
   20877              :     }
   20878    167100697 :   poplevel (1, 0, 1);
   20879              : 
   20880              :   /* Statements should always be full-expressions at the outermost set
   20881              :      of curly braces for a function.  */
   20882    167100697 :   gcc_assert (stmts_are_full_exprs_p ());
   20883              : 
   20884              :   /* If there are no return statements in a function with auto return type,
   20885              :      the return type is void.  But if the declared type is something like
   20886              :      auto*, this is an error.  */
   20887     69018199 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   20888    168300195 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20889              :     {
   20890       148425 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20891       148410 :           && !current_function_returns_value
   20892       296596 :           && !current_function_returns_null)
   20893              :         {
   20894              :           /* We haven't applied return type deduction because we haven't
   20895              :              seen any return statements. Do that now.  */
   20896       148171 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20897       148171 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   20898              :                              void_node, node, tf_warning_or_error,
   20899              :                              adc_return_type);
   20900              : 
   20901       148171 :           apply_deduced_return_type (fndecl, void_type_node);
   20902       148171 :           fntype = TREE_TYPE (fndecl);
   20903              :         }
   20904          254 :       else if (!current_function_returns_value
   20905            6 :                && !current_function_returns_null)
   20906              :         {
   20907            6 :           auto_diagnostic_group d;
   20908           12 :           error ("no return statements in function returning %qT",
   20909            6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20910            6 :           inform (input_location, "only plain %<auto%> return type can be "
   20911              :                   "deduced to %<void%>");
   20912            6 :         }
   20913              :     }
   20914              : 
   20915    167100697 :   if (FNDECL_USED_AUTO (fndecl)
   20916    167100697 :       && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20917      1199244 :     if (location_t fcloc = failed_completion_location (fndecl))
   20918              :       {
   20919            6 :         auto_diagnostic_group adg;
   20920            6 :         if (warning (OPT_Wsfinae_incomplete_,
   20921              :                      "defining %qD, which previously failed to be deduced "
   20922              :                      "in a SFINAE context", fndecl)
   20923            6 :             && warn_sfinae_incomplete == 1)
   20924            6 :           inform (fcloc, "here.  Use %qs for a diagnostic at that point",
   20925              :                   "-Wsfinae-incomplete=2");
   20926            6 :       }
   20927              : 
   20928              :   /* Remember that we were in class scope.  */
   20929    167100697 :   if (current_class_name)
   20930    127917931 :     ctype = current_class_type;
   20931              : 
   20932    167100697 :   if (DECL_DELETED_FN (fndecl))
   20933              :     {
   20934           93 :       DECL_INITIAL (fndecl) = error_mark_node;
   20935           93 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   20936           93 :       goto cleanup;
   20937              :     }
   20938              : 
   20939    167100604 :   if (flag_openmp)
   20940       334295 :     if (tree attr = lookup_attribute ("omp declare variant base",
   20941       334295 :                                       DECL_ATTRIBUTES (fndecl)))
   20942          276 :       omp_declare_variant_finalize (fndecl, attr);
   20943              : 
   20944              :   /* Complain if there's just no return statement.  */
   20945    167100604 :   if ((warn_return_type
   20946        47430 :        || (cxx_dialect >= cxx14
   20947        39394 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   20948    167071229 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   20949    105160977 :       && !dependent_type_p (TREE_TYPE (fntype))
   20950     53292890 :       && !current_function_returns_value && !current_function_returns_null
   20951              :       /* Don't complain if we abort or throw.  */
   20952        37927 :       && !current_function_returns_abnormally
   20953              :       /* Don't complain if there's an infinite loop.  */
   20954          944 :       && !current_function_infinite_loop
   20955              :       /* Don't complain if we are declared noreturn.  */
   20956          876 :       && !TREE_THIS_VOLATILE (fndecl)
   20957          870 :       && !DECL_NAME (DECL_RESULT (fndecl))
   20958          870 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   20959              :       /* Structor return values (if any) are set by the compiler.  */
   20960         1264 :       && !DECL_CONSTRUCTOR_P (fndecl)
   20961          632 :       && !DECL_DESTRUCTOR_P (fndecl)
   20962    167101236 :       && targetm.warn_func_return (fndecl))
   20963              :     {
   20964          626 :       gcc_rich_location richloc (input_location);
   20965              :       /* Potentially add a "return *this;" fix-it hint for
   20966              :          assignment operators.  */
   20967          626 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   20968              :         {
   20969           39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   20970           39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   20971           32 :               && current_class_ref
   20972           26 :               && same_type_ignoring_top_level_qualifiers_p
   20973           26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   20974           71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   20975           18 :             add_return_star_this_fixit (&richloc, fndecl);
   20976              :         }
   20977          626 :       if (cxx_dialect >= cxx14
   20978          626 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   20979            2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   20980              :                             "returning non-void");
   20981          624 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   20982              :                            "no return statement in function returning "
   20983              :                            "non-void"))
   20984          166 :         suppress_warning (fndecl, OPT_Wreturn_type);
   20985          626 :     }
   20986              : 
   20987              :   /* Lambda closure members are implicitly constexpr if possible.  */
   20988    167100604 :   if (cxx_dialect >= cxx17
   20989    289042407 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   20990      2027804 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   20991      2027804 :       = ((processing_template_decl
   20992       656534 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   20993      4054528 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   20994              : 
   20995              :   /* Invoke the pre-genericize plugin before we start munging things.  */
   20996    167100604 :   if (!processing_template_decl)
   20997     69018106 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   20998              : 
   20999              :   /* Fold away non-ODR usages of constants so that we don't need to
   21000              :      try and stream them in modules if they're internal.  */
   21001    167100604 :   if (!processing_template_decl)
   21002     69018106 :     cp_fold_function_non_odr_use (fndecl);
   21003              : 
   21004              :   /* Save constexpr function body before it gets munged by
   21005              :      the NRV transformation.   */
   21006    167100604 :   maybe_save_constexpr_fundef (fndecl);
   21007              : 
   21008              :   /* Perform delayed folding before NRV transformation.  */
   21009    167100604 :   if (!processing_template_decl
   21010    138036212 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   21011    235074430 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   21012     67973379 :     cp_fold_function (fndecl);
   21013              : 
   21014              :   /* Set up the named return value optimization, if we can.  Candidate
   21015              :      variables are selected in check_return_expr.  */
   21016    167100604 :   if (tree r = current_function_return_value)
   21017              :     {
   21018     44053180 :       if (r != error_mark_node)
   21019       229758 :         finalize_nrv (fndecl, r);
   21020     44053180 :       current_function_return_value = NULL_TREE;
   21021              :     }
   21022              : 
   21023              :   /* Must mark the RESULT_DECL as being in this function.  */
   21024    167100604 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   21025              : 
   21026              :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   21027              :      to the FUNCTION_DECL node itself.  */
   21028    167100604 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   21029              : 
   21030              :   /* Store the end of the function, so that we get good line number
   21031              :      info for the epilogue.  */
   21032    167100604 :   cfun->function_end_locus = input_location;
   21033              : 
   21034              :   /* Complain about parameters that are only set, but never otherwise used.  */
   21035    167100604 :   if (warn_unused_but_set_parameter
   21036      1001387 :       && !processing_template_decl
   21037       511480 :       && errorcount == unused_but_set_errorcount
   21038    167612081 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   21039              :     {
   21040       399634 :       tree decl;
   21041              : 
   21042       399634 :       for (decl = DECL_ARGUMENTS (fndecl);
   21043      1064787 :            decl;
   21044       665153 :            decl = DECL_CHAIN (decl))
   21045       665153 :         if (TREE_USED (decl)
   21046       552108 :             && TREE_CODE (decl) == PARM_DECL
   21047       552108 :             && !DECL_READ_P (decl)
   21048          225 :             && DECL_NAME (decl)
   21049          225 :             && !DECL_ARTIFICIAL (decl)
   21050          225 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
   21051          225 :             && !DECL_IN_SYSTEM_HEADER (decl)
   21052          225 :             && TREE_TYPE (decl) != error_mark_node
   21053          225 :             && !TYPE_REF_P (TREE_TYPE (decl))
   21054       665378 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   21055            0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   21056          225 :           warning_at (DECL_SOURCE_LOCATION (decl),
   21057          225 :                       OPT_Wunused_but_set_parameter_,
   21058              :                       "parameter %qD set but not used", decl);
   21059       399634 :       unused_but_set_errorcount = errorcount;
   21060              :     }
   21061              : 
   21062              :   /* Complain about locally defined typedefs that are not used in this
   21063              :      function.  */
   21064    167100604 :   maybe_warn_unused_local_typedefs ();
   21065              : 
   21066              :   /* Possibly warn about unused parameters.  */
   21067    167100604 :   if (warn_unused_parameter
   21068       732001 :       && !processing_template_decl
   21069    167454684 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   21070       272087 :     do_warn_unused_parameter (fndecl);
   21071              : 
   21072              :   /* Genericize before inlining.  */
   21073    167100604 :   if (!processing_template_decl
   21074    138036212 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   21075    235073942 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   21076     67972891 :     cp_genericize (fndecl);
   21077              : 
   21078              :   /* If this function can't throw any exceptions, remember that.  */
   21079    167100604 :   if (!processing_template_decl
   21080     69018106 :       && !cp_function_chain->can_throw
   21081     52656743 :       && !flag_non_call_exceptions
   21082     52647947 :       && !decl_replaceable_p (fndecl,
   21083     52647947 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   21084    219503571 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   21085     52400025 :     TREE_NOTHROW (fndecl) = 1;
   21086              : 
   21087    167100697 :  cleanup:
   21088              : 
   21089              :   /* We're leaving the context of this function, so zap cfun.  It's still in
   21090              :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   21091    167100697 :   set_cfun (NULL);
   21092    167100697 :   current_function_decl = NULL;
   21093              : 
   21094              :   /* If this is an in-class inline definition, we may have to pop the
   21095              :      bindings for the template parameters that we added in
   21096              :      maybe_begin_member_template_processing when start_function was
   21097              :      called.  */
   21098    167100697 :   if (inline_p)
   21099     85799391 :     maybe_end_member_template_processing ();
   21100              : 
   21101              :   /* Leave the scope of the class.  */
   21102    167100697 :   if (ctype)
   21103    127917931 :     pop_nested_class ();
   21104              : 
   21105    167100697 :   --function_depth;
   21106              : 
   21107              :   /* Clean up.  */
   21108    167100697 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   21109              : 
   21110              :   /* Build outlined functions for coroutines and contracts.  */
   21111              : 
   21112    167100697 :   if (coroutine)
   21113              :     {
   21114              :       /* Emit the resumer and destroyer functions now, providing that we have
   21115              :          not encountered some fatal error.  */
   21116         1722 :       if (coroutine->cp_valid_coroutine ())
   21117              :         {
   21118         1644 :           coroutine->finish_transforms ();
   21119         1644 :           resumer = coroutine->get_resumer ();
   21120         1644 :           destroyer = coroutine->get_destroyer ();
   21121         1644 :           expand_or_defer_fn (resumer);
   21122         1644 :           expand_or_defer_fn (destroyer);
   21123              :         }
   21124         1722 :       delete coroutine;
   21125              :     }
   21126              : 
   21127              :   /* If we have used outlined contracts checking functions, build and emit
   21128              :      them here.  */
   21129    167100697 :   finish_function_outlined_contracts (fndecl);
   21130              : 
   21131    167100697 :   return fndecl;
   21132              : }
   21133              : 
   21134              : /* Create the FUNCTION_DECL for a function definition.
   21135              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   21136              :    they describe the return type and the name of the function,
   21137              :    but twisted together in a fashion that parallels the syntax of C.
   21138              : 
   21139              :    This function creates a binding context for the function body
   21140              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   21141              : 
   21142              :    Returns a FUNCTION_DECL on success.
   21143              : 
   21144              :    If the DECLARATOR is not suitable for a function (it defines a datum
   21145              :    instead), we return 0, which tells yyparse to report a parse error.
   21146              : 
   21147              :    May return void_type_node indicating that this method is actually
   21148              :    a friend.  See grokfield for more details.
   21149              : 
   21150              :    Came here with a `.pushlevel' .
   21151              : 
   21152              :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   21153              :    CHANGES TO CODE IN `grokfield'.  */
   21154              : 
   21155              : tree
   21156     86020376 : grokmethod (cp_decl_specifier_seq *declspecs,
   21157              :             const cp_declarator *declarator, tree attrlist)
   21158              : {
   21159     86020376 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   21160     86020376 :                                 &attrlist);
   21161              : 
   21162     86020376 :   if (fndecl == error_mark_node)
   21163              :     return error_mark_node;
   21164              : 
   21165     86020271 :   if (attrlist)
   21166            0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   21167              : 
   21168              :   /* Pass friends other than inline friend functions back.  */
   21169     86020271 :   if (fndecl == void_type_node)
   21170              :     return fndecl;
   21171              : 
   21172     86020271 :   if (DECL_IN_AGGR_P (fndecl))
   21173              :     {
   21174            0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   21175            0 :         error ("%qD is already defined in class %qT", fndecl,
   21176            0 :                DECL_CONTEXT (fndecl));
   21177            0 :       return error_mark_node;
   21178              :     }
   21179              : 
   21180     86020271 :   check_template_shadow (fndecl);
   21181              : 
   21182              :   /* p1779 ABI-Isolation makes inline not a default for in-class
   21183              :      definitions attached to a named module.  If the user explicitly
   21184              :      made it inline, grokdeclarator will already have done the right
   21185              :      things.  */
   21186     86020271 :   if ((!named_module_attach_p ()
   21187         1132 :        || flag_module_implicit_inline
   21188              :       /* Lambda's operator function remains inline.  */
   21189         2228 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   21190              :       /* If the user explicitly asked for this to be inline, we don't
   21191              :          need to do more, but more importantly we want to warn if we
   21192              :          can't inline it.  */
   21193     86019808 :       && !DECL_DECLARED_INLINE_P (fndecl))
   21194              :     {
   21195     47659078 :       if (TREE_PUBLIC (fndecl))
   21196     45416179 :         DECL_COMDAT (fndecl) = 1;
   21197     47659078 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   21198              :       /* It's ok if we can't inline this.  */
   21199     47659078 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   21200              :     }
   21201              : 
   21202              :   /* We process method specializations in finish_struct_1.  */
   21203     86020271 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   21204              :     {
   21205              :       /* Avoid calling decl_spec_seq... until we have to.  */
   21206     69139791 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   21207     69139791 :       fndecl = push_template_decl (fndecl, friendp);
   21208     69139791 :       if (fndecl == error_mark_node)
   21209              :         return fndecl;
   21210              :     }
   21211              : 
   21212     86020263 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   21213              :     {
   21214            0 :       fndecl = copy_node (fndecl);
   21215            0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   21216              :     }
   21217              : 
   21218     86020263 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   21219              : 
   21220     86020263 :   DECL_IN_AGGR_P (fndecl) = 1;
   21221     86020263 :   return fndecl;
   21222              : }
   21223              : 
   21224              : 
   21225              : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   21226              :    we can lay it out later, when and if its type becomes complete.
   21227              : 
   21228              :    Also handle constexpr variables where the initializer involves
   21229              :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   21230              : 
   21231              : void
   21232    106771548 : maybe_register_incomplete_var (tree var)
   21233              : {
   21234    106771548 :   gcc_assert (VAR_P (var));
   21235              : 
   21236              :   /* Keep track of variables with incomplete types.  */
   21237     46759636 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   21238    153529389 :       && DECL_EXTERNAL (var))
   21239              :     {
   21240      6646839 :       tree inner_type = TREE_TYPE (var);
   21241              : 
   21242      6801989 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   21243       155150 :         inner_type = TREE_TYPE (inner_type);
   21244      6646839 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   21245              : 
   21246      6799830 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   21247              :           /* RTTI TD entries are created while defining the type_info.  */
   21248      6646839 :           || (TYPE_LANG_SPECIFIC (inner_type)
   21249      2364300 :               && TYPE_BEING_DEFINED (inner_type)))
   21250              :         {
   21251       152991 :           incomplete_var iv = {var, inner_type};
   21252       152991 :           vec_safe_push (incomplete_vars, iv);
   21253              :         }
   21254     12686414 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   21255      3535434 :                && DECL_CLASS_SCOPE_P (var)
   21256      1095763 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   21257      1095763 :                && decl_constant_var_p (var)
   21258      7195917 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   21259              :         {
   21260              :           /* When the outermost open class is complete we can resolve any
   21261              :              pointers-to-members.  */
   21262           27 :           tree context = outermost_open_class ();
   21263           27 :           incomplete_var iv = {var, context};
   21264           27 :           vec_safe_push (incomplete_vars, iv);
   21265              :         }
   21266              :     }
   21267    106771548 : }
   21268              : 
   21269              : /* Called when a class type (given by TYPE) is defined.  If there are
   21270              :    any existing VAR_DECLs whose type has been completed by this
   21271              :    declaration, update them now.  */
   21272              : 
   21273              : void
   21274     72443572 : complete_vars (tree type)
   21275              : {
   21276     72443572 :   unsigned ix;
   21277     72443572 :   incomplete_var *iv;
   21278              : 
   21279     73113229 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   21280              :     {
   21281       669657 :       if (same_type_p (type, iv->incomplete_type))
   21282              :         {
   21283       151787 :           tree var = iv->decl;
   21284       151787 :           tree type = TREE_TYPE (var);
   21285              : 
   21286       151787 :           if (type != error_mark_node
   21287       151787 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   21288       151784 :                   == iv->incomplete_type))
   21289              :             {
   21290              :               /* Complete the type of the variable.  */
   21291       151757 :               complete_type (type);
   21292       151757 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   21293       151757 :               if (COMPLETE_TYPE_P (type))
   21294       151742 :                 layout_var_decl (var);
   21295              :             }
   21296              : 
   21297              :           /* Remove this entry from the list.  */
   21298       151787 :           incomplete_vars->unordered_remove (ix);
   21299              :         }
   21300              :       else
   21301       517870 :         ix++;
   21302              :     }
   21303     72443572 : }
   21304              : 
   21305              : /* If DECL is of a type which needs a cleanup, build and return an
   21306              :    expression to perform that cleanup here.  Return NULL_TREE if no
   21307              :    cleanup need be done.  DECL can also be a _REF when called from
   21308              :    split_nonconstant_init_1.  */
   21309              : 
   21310              : tree
   21311     91778990 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   21312              : {
   21313     91778990 :   tree type;
   21314     91778990 :   tree attr;
   21315     91778990 :   tree cleanup;
   21316              : 
   21317              :   /* Assume no cleanup is required.  */
   21318     91778990 :   cleanup = NULL_TREE;
   21319              : 
   21320     91778990 :   if (!decl || error_operand_p (decl))
   21321              :     return cleanup;
   21322              : 
   21323              :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   21324              :      before the destructor since the destructor is what actually
   21325              :      terminates the lifetime of the object.  */
   21326     91778990 :   if (DECL_P (decl))
   21327     91421542 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   21328              :   else
   21329              :     attr = NULL_TREE;
   21330     91421542 :   if (attr)
   21331              :     {
   21332          166 :       tree id;
   21333          166 :       tree fn;
   21334          166 :       tree arg;
   21335              : 
   21336              :       /* Get the name specified by the user for the cleanup function.  */
   21337          166 :       id = TREE_VALUE (TREE_VALUE (attr));
   21338              :       /* Look up the name to find the cleanup function to call.  It is
   21339              :          important to use lookup_name here because that is what is
   21340              :          used in c-common.cc:handle_cleanup_attribute when performing
   21341              :          initial checks on the attribute.  Note that those checks
   21342              :          include ensuring that the function found is not an overloaded
   21343              :          function, or an object with an overloaded call operator,
   21344              :          etc.; we can rely on the fact that the function found is an
   21345              :          ordinary FUNCTION_DECL.  */
   21346          166 :       fn = lookup_name (id);
   21347          166 :       arg = build_address (decl);
   21348          166 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   21349            0 :         return error_mark_node;
   21350          166 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   21351          166 :       if (cleanup == error_mark_node)
   21352              :         return error_mark_node;
   21353              :     }
   21354              :   /* Handle ordinary C++ destructors.  */
   21355     91778978 :   type = TREE_TYPE (decl);
   21356     91778978 :   if (type_build_dtor_call (type))
   21357              :     {
   21358      6919032 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   21359      6919032 :       tree addr;
   21360      6919032 :       tree call;
   21361              : 
   21362      6919032 :       if (TREE_CODE (type) == ARRAY_TYPE)
   21363              :         addr = decl;
   21364              :       else
   21365      6913768 :         addr = build_address (decl);
   21366              : 
   21367      6919032 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   21368              :                            sfk_complete_destructor, flags, 0, complain);
   21369      6919032 :       if (call == error_mark_node)
   21370              :         cleanup = error_mark_node;
   21371      6918969 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   21372              :         /* Discard the call.  */;
   21373      4229237 :       else if (decl_maybe_constant_destruction (decl, type)
   21374      4229439 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   21375          202 :         cxx_constant_dtor (call, decl);
   21376      4229035 :       else if (cleanup)
   21377            3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   21378              :       else
   21379              :         cleanup = call;
   21380              :     }
   21381              : 
   21382              :   /* build_delete sets the location of the destructor call to the
   21383              :      current location, even though the destructor is going to be
   21384              :      called later, at the end of the current scope.  This can lead to
   21385              :      a "jumpy" behavior for users of debuggers when they step around
   21386              :      the end of the block.  So let's unset the location of the
   21387              :      destructor call instead.  */
   21388     91778978 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   21389     91778978 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   21390            0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   21391              : 
   21392            0 :   if (cleanup
   21393      4229249 :       && DECL_P (decl)
   21394      4228783 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   21395              :       /* Treat objects with destructors as used; the destructor may do
   21396              :          something substantive.  */
   21397      4228777 :       && !mark_used (decl, complain) && !(complain & tf_error))
   21398            0 :     return error_mark_node;
   21399              : 
   21400      4229249 :   if (cleanup && cfun && !processing_template_decl
   21401     95572300 :       && !expr_noexcept_p (cleanup, tf_none))
   21402         5458 :     cp_function_chain->throwing_cleanup = true;
   21403              : 
   21404              :   return cleanup;
   21405              : }
   21406              : 
   21407              : 
   21408              : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   21409              :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   21410              :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   21411              : 
   21412              : tree
   21413       791761 : static_fn_type (tree memfntype)
   21414              : {
   21415       791761 :   tree fntype;
   21416       791761 :   tree args;
   21417              : 
   21418       791761 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   21419        20797 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   21420       791761 :   if (INDIRECT_TYPE_P (memfntype)
   21421       677661 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   21422       620007 :     memfntype = TREE_TYPE (memfntype);
   21423       791761 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   21424              :     return memfntype;
   21425       622279 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   21426       622279 :   args = TYPE_ARG_TYPES (memfntype);
   21427       622279 :   fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   21428       622279 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   21429       622279 :   fntype = (cp_build_type_attribute_variant
   21430       622279 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   21431       622279 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   21432       622279 :   return fntype;
   21433              : }
   21434              : 
   21435              : /* DECL was originally constructed as a non-static member function,
   21436              :    but turned out to be static.  Update it accordingly.  */
   21437              : 
   21438              : void
   21439       179634 : revert_static_member_fn (tree decl)
   21440              : {
   21441       179634 :   tree stype = static_fn_type (decl);
   21442       179634 :   cp_cv_quals quals = type_memfn_quals (stype);
   21443       179634 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   21444              : 
   21445       179634 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   21446            9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   21447              : 
   21448       179634 :   TREE_TYPE (decl) = stype;
   21449              : 
   21450       179634 :   if (DECL_ARGUMENTS (decl))
   21451       179634 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   21452       179634 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   21453       179634 : }
   21454              : 
   21455              : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   21456              :    one of the language-independent trees.  */
   21457              : 
   21458              : enum cp_tree_node_structure_enum
   21459  39155905658 : cp_tree_node_structure (union lang_tree_node * t)
   21460              : {
   21461  39155905658 :   switch (TREE_CODE (&t->generic))
   21462              :     {
   21463              :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   21464    160937883 :     case BASELINK:              return TS_CP_BASELINK;
   21465     84213353 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   21466     11739263 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   21467      6320565 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   21468   2100650959 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   21469      3549508 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   21470       213233 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   21471    727069427 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   21472          749 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   21473     16206623 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   21474    690166316 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   21475   1605549440 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   21476    698355053 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   21477     15565109 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   21478            6 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   21479      3617617 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   21480     14630080 :     case REQUIRES_EXPR:         return TS_CP_REQUIRES_EXPR;
   21481  33017120474 :     default:                    return TS_CP_GENERIC;
   21482              :     }
   21483              : }
   21484              : 
   21485              : bool
   21486         9108 : cp_missing_noreturn_ok_p (tree decl)
   21487              : {
   21488              :   /* A missing noreturn is ok for the `main' function.  */
   21489         9108 :   return DECL_MAIN_P (decl);
   21490              : }
   21491              : 
   21492              : /* Return the decl used to identify the COMDAT group into which DECL should
   21493              :    be placed.  */
   21494              : 
   21495              : tree
   21496    128479844 : cxx_comdat_group (tree decl)
   21497              : {
   21498              :   /* Virtual tables, construction virtual tables, and virtual table
   21499              :      tables all go in a single COMDAT group, named after the primary
   21500              :      virtual table.  */
   21501    128479844 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   21502       534887 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   21503              :   /* For all other DECLs, the COMDAT group is the mangled name of the
   21504              :      declaration itself.  */
   21505              :   else
   21506              :     {
   21507    127944957 :       while (DECL_THUNK_P (decl))
   21508              :         {
   21509              :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   21510              :              into the same section as the target function.  In that case
   21511              :              we must return target's name.  */
   21512            0 :           tree target = THUNK_TARGET (decl);
   21513            0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   21514            0 :               && DECL_SECTION_NAME (target) != NULL
   21515            0 :               && DECL_ONE_ONLY (target))
   21516              :             decl = target;
   21517              :           else
   21518              :             break;
   21519              :         }
   21520              :       /* If a ctor/dtor has already set the comdat group by
   21521              :          maybe_clone_body, don't override it.  */
   21522    127944957 :       if (SUPPORTS_ONE_ONLY
   21523    127944957 :           && TREE_CODE (decl) == FUNCTION_DECL
   21524    127944957 :           && DECL_CLONED_FUNCTION_P (decl))
   21525     18600088 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   21526      2708941 :           return comdat;
   21527              :     }
   21528              : 
   21529              :   return decl;
   21530              : }
   21531              : 
   21532              : /* Returns the return type for FN as written by the user, which may include
   21533              :    a placeholder for a deduced return type.  */
   21534              : 
   21535              : tree
   21536    563028050 : fndecl_declared_return_type (tree fn)
   21537              : {
   21538    563028050 :   fn = STRIP_TEMPLATE (fn);
   21539    563028050 :   if (FNDECL_USED_AUTO (fn))
   21540       403269 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   21541              : 
   21542    562624781 :   return TREE_TYPE (TREE_TYPE (fn));
   21543              : }
   21544              : 
   21545              : /* Returns true iff DECL is a variable or function declared with an auto type
   21546              :    that has not yet been deduced to a real type.  */
   21547              : 
   21548              : bool
   21549   1011919887 : undeduced_auto_decl (tree decl)
   21550              : {
   21551   1011919887 :   if (cxx_dialect < cxx11)
   21552              :     return false;
   21553   1009605085 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   21554    460600923 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   21555     96801047 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   21556   1373665850 :           && type_uses_auto (TREE_TYPE (decl)));
   21557              : }
   21558              : 
   21559              : /* Complain if DECL has an undeduced return type.  */
   21560              : 
   21561              : bool
   21562    335525467 : require_deduced_type (tree decl, tsubst_flags_t complain)
   21563              : {
   21564    335525467 :   if (undeduced_auto_decl (decl))
   21565              :     {
   21566        14372 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21567        14372 :           && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
   21568              :                                 BUILT_IN_FRONTEND))
   21569              :         {
   21570              :           /* Set the return type of __builtin_source_location.  */
   21571        10266 :           tree type = get_source_location_impl_type ();
   21572        10266 :           if (type == error_mark_node)
   21573              :             {
   21574           33 :               inform (input_location, "using %qs", "__builtin_source_location");
   21575           33 :               return false;
   21576              :             }
   21577        10233 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   21578        10233 :           type = build_pointer_type (type);
   21579        10233 :           apply_deduced_return_type (decl, type);
   21580        10233 :           return true;
   21581              :         }
   21582              : 
   21583         4106 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21584         4106 :           && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
   21585              :                                 BUILT_IN_FRONTEND))
   21586              :         {
   21587              :           /* Set the return type of __builtin_current_exception.  */
   21588         2106 :           tree name = get_identifier ("exception_ptr");
   21589         2106 :           tree eptr = lookup_qualified_name (std_node, name);
   21590         2106 :           tree fld;
   21591         2106 :           if (TREE_CODE (eptr) != TYPE_DECL
   21592         2106 :               || !CLASS_TYPE_P (TREE_TYPE (eptr))
   21593         2106 :               || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
   21594         2106 :               || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
   21595         2106 :               || DECL_ARTIFICIAL (fld)
   21596         2106 :               || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
   21597         2106 :               || next_aggregate_field (DECL_CHAIN (fld))
   21598         4212 :               || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
   21599         2106 :                                       TYPE_SIZE (TREE_TYPE (fld))))
   21600              :             {
   21601            0 :               error ("%qs used without %qs declaration",
   21602              :                      "__builtin_current_exception", "std::exception_ptr");
   21603            0 :               return false;
   21604              :             }
   21605              : 
   21606         2106 :           apply_deduced_return_type (decl, TREE_TYPE (eptr));
   21607         2106 :           return true;
   21608              :         }
   21609              : 
   21610         2000 :       if (warning_suppressed_p (decl) && seen_error ())
   21611              :         /* We probably already complained about deduction failure.  */;
   21612         1815 :       else if (complain & tf_error)
   21613           74 :         error ("use of %qD before deduction of %<auto%>", decl);
   21614         2000 :       note_failed_type_completion (decl, complain);
   21615         2000 :       return false;
   21616              :     }
   21617              :   return true;
   21618              : }
   21619              : 
   21620              : /* Create a representation of the explicit-specifier with
   21621              :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   21622              : 
   21623              : tree
   21624      8478960 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   21625              : {
   21626      8478960 :   if (check_for_bare_parameter_packs (expr))
   21627            3 :     return error_mark_node;
   21628              : 
   21629      8478957 :   if (instantiation_dependent_expression_p (expr))
   21630              :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   21631              :     return expr;
   21632              : 
   21633      6807004 :   expr = build_converted_constant_bool_expr (expr, complain);
   21634      6807004 :   expr = instantiate_non_dependent_expr (expr, complain);
   21635      6807004 :   expr = cxx_constant_value (expr, complain);
   21636      6807004 :   return expr;
   21637              : }
   21638              : 
   21639              : #include "gt-cp-decl.h"
        

Generated by: LCOV version 2.5.0-beta

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