LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.6 % 9631 9114
Test Date: 2026-02-28 14:20:25 Functions: 97.9 % 242 237
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Process declarations and variables for -*- 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    243653793 : current_tmpl_spec_kind (int n_class_scopes)
     312              : {
     313    243653793 :   int n_template_parm_scopes = 0;
     314    243653793 :   int seen_specialization_p = 0;
     315    243653793 :   int innermost_specialization_p = 0;
     316    243653793 :   cp_binding_level *b;
     317              : 
     318              :   /* Scan through the template parameter scopes.  */
     319    243653793 :   for (b = current_binding_level;
     320    303482443 :        b->kind == sk_template_parms;
     321     59828650 :        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     59828650 :       if (b->explicit_spec_p)
     333              :         {
     334      1383350 :           if (n_template_parm_scopes == 0)
     335              :             innermost_specialization_p = 1;
     336              :           else
     337         1254 :             seen_specialization_p = 1;
     338              :         }
     339     58445300 :       else if (seen_specialization_p == 1)
     340              :         return tsk_invalid_member_spec;
     341              : 
     342     59828650 :       ++n_template_parm_scopes;
     343              :     }
     344              : 
     345              :   /* Handle explicit instantiations.  */
     346    243653793 :   if (processing_explicit_instantiation)
     347              :     {
     348      1935213 :       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      1935213 :         return tsk_expl_inst;
     358              :     }
     359              : 
     360    241718580 :   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    241718580 :   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     51944182 :   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    102972790 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     394              : }
     395              : 
     396              : /* Exit the current scope.  */
     397              : 
     398              : void
     399     94712576 : finish_scope (void)
     400              : {
     401     94712576 :   poplevel (0, 0, 0);
     402     94712576 : }
     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        20458 : check_label_used (tree label)
     409              : {
     410        20458 :   if (!processing_template_decl)
     411              :     {
     412        20149 :       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        20140 :         warn_for_unused_label (label);
     424              :     }
     425        20458 : }
     426              : 
     427              : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     428              : 
     429              : static int
     430       229893 : sort_labels (const void *a, const void *b)
     431              : {
     432       229893 :   tree label1 = *(tree const *) a;
     433       229893 :   tree label2 = *(tree const *) b;
     434              : 
     435              :   /* DECL_UIDs can never be equal.  */
     436       229893 :   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    166164434 : pop_labels (tree block)
     508              : {
     509    166164434 :   if (!named_labels)
     510    166159829 :     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         4605 :   auto_vec<tree, 32> labels (named_labels->elements ());
     518         4605 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     519              : 
     520         4605 :   if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
     521          681 :       && !processing_template_decl)
     522              :     {
     523         6078 :       for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     524              :         {
     525         2392 :           named_label_entry *ent = *iter;
     526         2392 :           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        45455 :   for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     537              :     {
     538        20425 :       named_label_entry *ent = *iter;
     539              : 
     540        20425 :       gcc_checking_assert (!ent->outer);
     541        20425 :       if (ent->label_decl)
     542        20239 :         labels.quick_push (ent->label_decl);
     543        20425 :       ggc_free (ent);
     544              :     }
     545         4605 :   named_labels = NULL;
     546         4605 :   labels.qsort (sort_labels);
     547              : 
     548        24844 :   while (labels.length ())
     549              :     {
     550        20239 :       tree label = labels.pop ();
     551              : 
     552        20239 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     553        20239 :       BLOCK_VARS (block) = label;
     554              : 
     555        20239 :       check_label_used (label);
     556              :     }
     557         4605 : }
     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      4538829 : level_for_constexpr_if (cp_binding_level *b)
     618              : {
     619      4534767 :   return (b->kind == sk_cond && b->this_entity
     620          292 :           && TREE_CODE (b->this_entity) == IF_STMT
     621      4539121 :           && 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      4538805 : level_for_consteval_if (cp_binding_level *b)
     628              : {
     629      4534743 :   return (b->kind == sk_cond && b->this_entity
     630          268 :           && TREE_CODE (b->this_entity) == IF_STMT
     631      4539073 :           && 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       153619 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     652              : {
     653       153619 :   named_label_entry *ent = *slot;
     654       153619 :   cp_binding_level *obl = bl->level_chain;
     655              : 
     656       153619 :   if (ent->binding_level == bl)
     657              :     {
     658        10127 :       tree decl;
     659              : 
     660              :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     661              :          TREE_LISTs representing OVERLOADs, so be careful.  */
     662        15023 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     663         4969 :                                                      ? DECL_CHAIN (decl)
     664           73 :                                                      : TREE_CHAIN (decl)))
     665         4896 :         if (decl_jump_unsafe (decl))
     666              :           {
     667         1872 :             vec_safe_push (ent->bad_decls, decl);
     668         1872 :             ent->has_bad_decls = true;
     669              :           }
     670         3024 :         else if (decl_instrument_init_bypass_p (decl))
     671          435 :           vec_safe_push (ent->bad_decls, decl);
     672              : 
     673        10127 :       ent->binding_level = obl;
     674        10127 :       ent->names_in_scope = obl->names;
     675        10127 :       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         4100 :         case sk_block:
     693         4100 :           if (level_for_constexpr_if (obl))
     694           15 :             ent->in_constexpr_if = true;
     695         4085 :           else if (level_for_consteval_if (obl))
     696           30 :             ent->in_consteval_if = true;
     697              :           break;
     698              :         default:
     699              :           break;
     700              :         }
     701              :     }
     702       143492 :   else if (ent->uses)
     703              :     {
     704              :       struct named_label_use_entry *use;
     705              : 
     706        22845 :       for (use = ent->uses; use ; use = use->next)
     707        15527 :         if (use->binding_level == bl)
     708              :           {
     709         5981 :             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         5981 :             use->binding_level = obl;
     719         5981 :             use->names_in_scope = obl->names;
     720         5981 :             if (bl->kind == sk_omp)
     721           12 :               use->in_omp_scope = true;
     722              :           }
     723              :     }
     724              : 
     725       153619 :   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    700553909 : poplevel (int keep, int reverse, int functionbody)
     749              : {
     750    700553909 :   tree link;
     751              :   /* The chain of decls was accumulated in reverse order.
     752              :      Put it into forward order, just for cleanliness.  */
     753    700553909 :   tree decls;
     754    700553909 :   tree subblocks;
     755    700553909 :   tree block;
     756    700553909 :   tree decl;
     757    700553909 :   scope_kind kind;
     758              : 
     759    700553909 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     760    700554299 :  restart:
     761              : 
     762    700554299 :   block = NULL_TREE;
     763              : 
     764    700554299 :   gcc_assert (current_binding_level->kind != sk_class
     765              :               && current_binding_level->kind != sk_namespace);
     766              : 
     767    700554299 :   if (current_binding_level->kind == sk_cleanup)
     768              :     functionbody = 0;
     769    700554299 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     770              : 
     771    700554299 :   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    700554299 :   gcc_assert (keep == 0 || keep == 1);
     777              : 
     778    700554299 :   if (current_binding_level->keep)
     779      9869256 :     keep = 1;
     780              : 
     781              :   /* Any uses of undefined labels, and any defined labels, now operate
     782              :      under constraints of next binding contour.  */
     783    700554299 :   if (cfun && !functionbody && named_labels)
     784        43290 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     785       196909 :                    (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    700554299 :   decls = current_binding_level->names;
     792    700554299 :   if (reverse)
     793              :     {
     794    394750782 :       decls = nreverse (decls);
     795    394750782 :       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    700554299 :   block = NULL_TREE;
     802              :   /* Avoid function body block if possible.  */
     803    743926938 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     804              :     keep = 0;
     805    657181921 :   else if (keep == 1 || functionbody)
     806    213509320 :     block = make_node (BLOCK);
     807    213509320 :   if (block != NULL_TREE)
     808              :     {
     809    213509320 :       BLOCK_VARS (block) = decls;
     810    213509320 :       BLOCK_SUBBLOCKS (block) = subblocks;
     811              :     }
     812              : 
     813              :   /* In each subblock, record that this is its superior.  */
     814    700554299 :   if (keep >= 0)
     815    791270849 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     816     90716550 :       BLOCK_SUPERCONTEXT (link) = block;
     817              : 
     818              :   /* Before we remove the declarations first check for unused variables.  */
     819    700554299 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     820      6480625 :       && current_binding_level->kind != sk_template_parms
     821      5475782 :       && !processing_template_decl)
     822      6371335 :     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      3238313 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     828      3238313 :         decl = strip_using_decl (udecl);
     829              : 
     830      3238313 :         tree type = TREE_TYPE (decl);
     831      3238313 :         if (VAR_P (decl)
     832       378758 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     833         3439 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     834              :             /* For structured bindings, consider only real variables, not
     835              :                subobjects.  */
     836         3427 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     837         3173 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     838              :             /* Don't warn about name-independent declarations.  */
     839          893 :             && !name_independent_decl_p (decl)
     840          737 :             && type != error_mark_node
     841      3242443 :             && (!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          703 :             if (!TREE_USED (decl))
     847              :               {
     848          308 :                 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          305 :                 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          302 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     858          302 :                               OPT_Wunused_variable, "unused variable %qD", decl);
     859          308 :                 suppress_warning (decl, OPT_Wunused_variable);
     860              :               }
     861          395 :             else if (DECL_CONTEXT (decl) == current_function_decl
     862              :                      // For -Wunused-but-set-variable leave references alone.
     863          371 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     864          766 :                      && errorcount == unused_but_set_errorcount)
     865              :               {
     866          362 :                 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          350 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     872          350 :                               OPT_Wunused_but_set_variable_,
     873              :                               "variable %qD set but not used", decl);
     874          362 :                 unused_but_set_errorcount = errorcount;
     875              :               }
     876              :           }
     877              :       }
     878              : 
     879              :   /* Remove declarations for all the DECLs in this level.  */
     880   1400643781 :   for (link = decls; link; link = TREE_CHAIN (link))
     881              :     {
     882    700089482 :       tree name;
     883    700089482 :       if (TREE_CODE (link) == TREE_LIST)
     884              :         {
     885     13269600 :           decl = TREE_VALUE (link);
     886     13269600 :           name = TREE_PURPOSE (link);
     887     13269600 :           gcc_checking_assert (name);
     888              :         }
     889              :       else
     890              :         {
     891    686819882 :           decl = link;
     892    686819882 :           name = DECL_NAME (decl);
     893              :         }
     894              : 
     895              :       /* Remove the binding.  */
     896    700089482 :       if (TREE_CODE (decl) == LABEL_DECL)
     897          219 :         pop_local_label (name, decl);
     898              :       else
     899    700089263 :         pop_local_binding (name, decl);
     900              :     }
     901              : 
     902              :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     903    700554299 :   for (link = current_binding_level->type_shadowed;
     904    941482265 :        link; link = TREE_CHAIN (link))
     905    240927966 :     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    700554299 :   if (block)
     915              :     {
     916    213509320 :       tree* d;
     917              : 
     918    557370083 :       for (d = &BLOCK_VARS (block); *d; )
     919              :         {
     920    343860763 :           if (TREE_CODE (*d) == TREE_LIST
     921    343860763 :               || (!processing_template_decl
     922    122058173 :                   && undeduced_auto_decl (*d)))
     923     13269652 :             *d = TREE_CHAIN (*d);
     924              :           else
     925    330591111 :             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    700554299 :   if (functionbody)
     932              :     {
     933    166164434 :       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    122792056 :           BLOCK_VARS (block) = 0;
     939    122792056 :           pop_labels (block);
     940              :         }
     941              :       else
     942     43372378 :         pop_labels (subblocks);
     943              :     }
     944              : 
     945    700554299 :   kind = current_binding_level->kind;
     946    700554299 :   if (kind == sk_cleanup)
     947              :     {
     948          390 :       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          390 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     954          390 :       stmt = c_build_bind_expr (input_location, block, stmt);
     955          390 :       add_stmt (stmt);
     956              :     }
     957              : 
     958    700554299 :   leave_scope ();
     959    700554299 :   if (functionbody)
     960              :     {
     961              :       /* The current function is being defined, so its DECL_INITIAL
     962              :          should be error_mark_node.  */
     963    166164434 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     964    209536812 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     965    166164434 :       if (subblocks)
     966              :         {
     967     82679202 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
     968     54753326 :               && BLOCK_SUBBLOCKS (subblocks))
     969      1794906 :             BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     970              :           else
     971     41577733 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     972              :         }
     973              :     }
     974    534389865 :   else if (block)
     975     90717264 :     current_binding_level->blocks
     976    181434528 :       = 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    443672601 :   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    700554299 :   if (block)
     991    213509320 :     TREE_USED (block) = 1;
     992              : 
     993              :   /* All temporary bindings created for cleanups are popped silently.  */
     994    700554299 :   if (kind == sk_cleanup)
     995          390 :     goto restart;
     996              : 
     997   1401107818 :   return block;
     998    700553909 : }
     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       140656 : wrapup_namespace_globals ()
    1006              : {
    1007       140656 :   if (vec<tree, va_gc> *statics = static_decls)
    1008              :     {
    1009     17356520 :       for (tree decl : *statics)
    1010              :         {
    1011     17241009 :           if (warn_unused_function
    1012       990021 :               && TREE_CODE (decl) == FUNCTION_DECL
    1013       742885 :               && DECL_INITIAL (decl) == 0
    1014         7160 :               && DECL_EXTERNAL (decl)
    1015         7160 :               && !TREE_PUBLIC (decl)
    1016           32 :               && !DECL_ARTIFICIAL (decl)
    1017           32 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
    1018            9 :               && !warning_suppressed_p (decl, OPT_Wunused)
    1019     18231030 :               && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
    1020              :                              "%qF declared %<static%> but never defined",
    1021              :                              decl))
    1022            6 :                 suppress_warning (decl, OPT_Wunused);
    1023              : 
    1024     17241009 :           if (VAR_P (decl)
    1025      5895040 :               && DECL_EXTERNAL (decl)
    1026      1995285 :               && DECL_INLINE_VAR_P (decl)
    1027     17241038 :               && DECL_ODR_USED (decl))
    1028            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    1029              :                       "odr-used inline variable %qD is not defined", decl);
    1030              :         }
    1031              : 
    1032              :       /* Clear out the list, so we don't rescan next time.  */
    1033       115511 :       static_decls = NULL;
    1034              : 
    1035              :       /* Write out any globals that need to be output.  */
    1036       115511 :       return wrapup_global_declarations (statics->address (),
    1037       115511 :                                          statics->length ());
    1038              :     }
    1039              :   return 0;
    1040              : }
    1041              : 
    1042              : /* In C++, you don't have to write `struct S' to refer to `S'; you
    1043              :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
    1044              :    if the user had written `typedef struct S S'.  Create and return
    1045              :    the TYPE_DECL for TYPE.  */
    1046              : 
    1047              : tree
    1048    190098773 : create_implicit_typedef (tree name, tree type)
    1049              : {
    1050    190098773 :   tree decl;
    1051              : 
    1052    190098773 :   decl = build_decl (input_location, TYPE_DECL, name, type);
    1053    190098773 :   DECL_ARTIFICIAL (decl) = 1;
    1054              :   /* There are other implicit type declarations, like the one *within*
    1055              :      a class that allows you to write `S::S'.  We must distinguish
    1056              :      amongst these.  */
    1057    190098773 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
    1058    190098773 :   TYPE_NAME (type) = decl;
    1059    190098773 :   TYPE_STUB_DECL (type) = decl;
    1060              : 
    1061    190098773 :   return decl;
    1062              : }
    1063              : 
    1064              : /* Function-scope local entities that need discriminators.  Each entry
    1065              :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
    1066              :    smashed, so we cannot rely on DECL_NAME.  */
    1067              : 
    1068              : static GTY((deletable)) vec<tree, va_gc> *local_entities;
    1069              : 
    1070              : /* Determine the mangling discriminator of local DECL.  There are
    1071              :    generally very few of these in any particular function.  */
    1072              : 
    1073              : void
    1074       837284 : determine_local_discriminator (tree decl, tree name)
    1075              : {
    1076       837284 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    1077       837284 :   retrofit_lang_decl (decl);
    1078       837284 :   tree ctx = DECL_CONTEXT (decl);
    1079       837284 :   size_t nelts = vec_safe_length (local_entities);
    1080       837284 :   if (name == NULL_TREE)
    1081       837023 :     name = (TREE_CODE (decl) == TYPE_DECL
    1082      1341466 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
    1083      1503739 :             ? NULL_TREE : DECL_NAME (decl));
    1084     29292899 :   for (size_t i = 0; i < nelts; i += 2)
    1085              :     {
    1086     28456082 :       tree *pair = &(*local_entities)[i];
    1087     28456082 :       tree d = pair[0];
    1088     28456082 :       tree n = pair[1];
    1089     28456082 :       gcc_checking_assert (d != decl);
    1090     28456082 :       if (name == n
    1091      4655638 :           && TREE_CODE (decl) == TREE_CODE (d)
    1092     33111711 :           && ctx == DECL_CONTEXT (d))
    1093              :         {
    1094          467 :           tree disc = integer_one_node;
    1095          467 :           if (DECL_DISCRIMINATOR (d))
    1096          244 :             disc = build_int_cst (TREE_TYPE (disc),
    1097          244 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
    1098          467 :           DECL_DISCRIMINATOR (decl) = disc;
    1099              :           /* Replace the saved decl.  */
    1100          467 :           pair[0] = decl;
    1101          467 :           decl = NULL_TREE;
    1102          467 :           break;
    1103              :         }
    1104              :     }
    1105              : 
    1106       837284 :   if (decl)
    1107              :     {
    1108       836817 :       vec_safe_reserve (local_entities, 2);
    1109       836817 :       local_entities->quick_push (decl);
    1110       836817 :       local_entities->quick_push (name);
    1111              :     }
    1112       837284 : }
    1113              : 
    1114              : 
    1115              : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
    1116              : 
    1117              :    A non-template friend declaration with a requires-clause shall be a
    1118              :    definition. A friend function template with a constraint that depends on a
    1119              :    template parameter from an enclosing template shall be a definition. Such a
    1120              :    constrained friend function or function template declaration does not
    1121              :    declare the same function or function template as a declaration in any other
    1122              :    scope.
    1123              : 
    1124              :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1125              :    member function to avoid collisions.  */
    1126              : 
    1127              : bool
    1128   2674969594 : member_like_constrained_friend_p (tree decl)
    1129              : {
    1130   2674969594 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1131    890402463 :           && DECL_UNIQUE_FRIEND_P (decl)
    1132    160143044 :           && DECL_FRIEND_CONTEXT (decl)
    1133     63059636 :           && get_constraints (decl)
    1134      2683426 :           && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
    1135   2676310253 :           && (!DECL_TEMPLATE_INFO (decl)
    1136      1340659 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1137         6025 :               || (uses_outer_template_parms_in_constraints
    1138         6025 :                   (most_general_template (decl)))));
    1139              : }
    1140              : 
    1141              : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1142              :    requires clauses.  */
    1143              : 
    1144              : static bool
    1145    101717554 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1146              : {
    1147              :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1148              :      same function as a declaration in any other scope."  So no need to
    1149              :      actually compare the requirements.  */
    1150    101717554 :   if (member_like_constrained_friend_p (newfn)
    1151    101717554 :       || member_like_constrained_friend_p (oldfn))
    1152           95 :     return false;
    1153              : 
    1154              :   /* Compare only trailing requirements.  */
    1155    101717459 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1156    101717459 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1157    101717459 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1158              :     return false;
    1159              : 
    1160              :   /* Substitution is needed when friends are involved.  */
    1161    101595965 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1162    101595965 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1163              : 
    1164    101595965 :   return cp_tree_equal (reqs1, reqs2);
    1165              : }
    1166              : 
    1167              : /* Two functions of the same name correspond [basic.scope.scope] if
    1168              : 
    1169              :    + both declare functions with the same non-object-parameter-type-list,
    1170              :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1171              :    specified in [temp.friend]), and, if both are non-static members, they have
    1172              :    corresponding object parameters, or
    1173              : 
    1174              :    + both declare function templates with equivalent
    1175              :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1176              :    trailing requires-clauses (if any), and, if both are non-static members,
    1177              :    they have corresponding object parameters.
    1178              : 
    1179              :    This is a subset of decls_match: it identifies declarations that cannot be
    1180              :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1181              : 
    1182              : bool
    1183   2707517797 : fns_correspond (tree newdecl, tree olddecl)
    1184              : {
    1185   2707517797 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1186              :     return false;
    1187              : 
    1188   2513738912 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1189              :     {
    1190   2512383636 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1191              :         return 0;
    1192    606512062 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1193    606512062 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1194              :     }
    1195              : 
    1196    607867338 :   tree f1 = TREE_TYPE (newdecl);
    1197    607867338 :   tree f2 = TREE_TYPE (olddecl);
    1198              : 
    1199    607867338 :   int rq1 = type_memfn_rqual (f1);
    1200    607867338 :   int rq2 = type_memfn_rqual (f2);
    1201              : 
    1202              :   /* If only one is a non-static member function, ignore ref-quals.  */
    1203    607867338 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1204              :     rq1 = rq2;
    1205              :   /* Two non-static member functions have corresponding object parameters if:
    1206              :      + exactly one is an implicit object member function with no ref-qualifier
    1207              :      and the types of their object parameters ([dcl.fct]), after removing
    1208              :      top-level references, are the same, or
    1209              :      + their object parameters have the same type.  */
    1210              :   /* ??? We treat member functions of different classes as corresponding even
    1211              :      though that means the object parameters have different types.  */
    1212    607867338 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1213            0 :     rq1 = rq2;
    1214              : 
    1215    607867338 :   bool types_match = rq1 == rq2;
    1216              : 
    1217    607867338 :   if (types_match)
    1218              :     {
    1219    607867338 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1220    607867338 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1221    607867338 :       types_match = compparms (p1, p2);
    1222              :     }
    1223              : 
    1224              :   /* Two function declarations match if either has a requires-clause
    1225              :      then both have a requires-clause and their constraints-expressions
    1226              :      are equivalent.  */
    1227    607867338 :   if (types_match && flag_concepts)
    1228     74069746 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1229              : 
    1230              :   return types_match;
    1231              : }
    1232              : 
    1233              : /* Subroutine of duplicate_decls: return truthvalue of whether
    1234              :    or not types of these decls match.
    1235              : 
    1236              :    For C++, we must compare the parameter list so that `int' can match
    1237              :    `int&' in a parameter position, but `int&' is not confused with
    1238              :    `const int&'.  */
    1239              : 
    1240              : int
    1241    786668216 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1242              : {
    1243    786668216 :   int types_match;
    1244              : 
    1245    786668216 :   if (newdecl == olddecl)
    1246              :     return 1;
    1247              : 
    1248    786583923 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1249              :     /* If the two DECLs are not even the same kind of thing, we're not
    1250              :        interested in their types.  */
    1251              :     return 0;
    1252              : 
    1253    400024786 :   gcc_assert (DECL_P (newdecl));
    1254              : 
    1255    400024786 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1256              :     {
    1257              :       /* Specializations of different templates are different functions
    1258              :          even if they have the same type.  */
    1259    252351350 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1260    252351350 :                  ? DECL_TI_TEMPLATE (newdecl)
    1261       626388 :                  : NULL_TREE);
    1262    252351350 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1263    252351350 :                  ? DECL_TI_TEMPLATE (olddecl)
    1264      3911298 :                  : NULL_TREE);
    1265    252351350 :       if (t1 != t2)
    1266              :         return 0;
    1267              : 
    1268    249066370 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1269    251951921 :           && ! (DECL_EXTERN_C_P (newdecl)
    1270      2885551 :                 && DECL_EXTERN_C_P (olddecl)))
    1271              :         return 0;
    1272              : 
    1273              :       /* A new declaration doesn't match a built-in one unless it
    1274              :          is also extern "C".  */
    1275    228377593 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1276    228377593 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1277              :         return 0;
    1278              : 
    1279    227740867 :       tree f1 = TREE_TYPE (newdecl);
    1280    227740867 :       tree f2 = TREE_TYPE (olddecl);
    1281    227740867 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1282              :         return 0;
    1283              : 
    1284              :       /* A declaration with deduced return type should use its pre-deduction
    1285              :          type for declaration matching.  */
    1286    227573674 :       tree r2 = fndecl_declared_return_type (olddecl);
    1287    227573674 :       tree r1 = fndecl_declared_return_type (newdecl);
    1288              : 
    1289              :       /* For memchr et al, allow const void* return type (as specified by C++)
    1290              :          when we expect void* (as in C).  */
    1291    227573674 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1292      6307492 :           && DECL_EXTERN_C_P (olddecl)
    1293      3911390 :           && !same_type_p (r1, r2)
    1294           70 :           && TREE_CODE (r1) == POINTER_TYPE
    1295           15 :           && TREE_CODE (r2) == POINTER_TYPE
    1296    227573686 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1297              :         r2 = r1;
    1298              : 
    1299    227573674 :       tree p1 = TYPE_ARG_TYPES (f1);
    1300    227573674 :       tree p2 = TYPE_ARG_TYPES (f2);
    1301              : 
    1302    227573674 :       if (same_type_p (r1, r2))
    1303              :         {
    1304    160766388 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1305    160766360 :               && fndecl_built_in_p (olddecl))
    1306              :             {
    1307           50 :               types_match = self_promoting_args_p (p1);
    1308           50 :               if (p1 == void_list_node)
    1309            3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1310              :             }
    1311              :           else
    1312    160766254 :             types_match =
    1313    160766254 :               compparms (p1, p2)
    1314     28134337 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1315    188900348 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1316      1190416 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1317      1190416 :                                            TREE_TYPE (olddecl)) != 0);
    1318              :         }
    1319              :       else
    1320              :         types_match = 0;
    1321              : 
    1322              :       /* Two function declarations match if either has a requires-clause
    1323              :          then both have a requires-clause and their constraints-expressions
    1324              :          are equivalent.  */
    1325     28134123 :       if (types_match && flag_concepts)
    1326     27647779 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1327              : 
    1328              :       /* The decls dont match if they correspond to two different versions
    1329              :          of the same function.   Disallow extern "C" functions to be
    1330              :          versions for now.  */
    1331     28134123 :       if (types_match
    1332     27950241 :           && !DECL_EXTERN_C_P (newdecl)
    1333     20386348 :           && !DECL_EXTERN_C_P (olddecl)
    1334     48516561 :           && disjoint_version_decls (newdecl, olddecl))
    1335              :         {
    1336         8850 :           if (record_versions)
    1337         8763 :             maybe_version_functions (newdecl, olddecl);
    1338         8850 :           return 0;
    1339              :         }
    1340              :     }
    1341    147673436 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1342              :     {
    1343    145978582 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1344              :         return 0;
    1345              : 
    1346     48369674 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1347     48369674 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1348              : 
    1349     48369674 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1350              :         return 0;
    1351              : 
    1352              :       /* Two template types match if they are the same. Otherwise, compare
    1353              :          the underlying declarations.  */
    1354     48369668 :       if (TREE_CODE (newres) == TYPE_DECL)
    1355           30 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1356              :       else
    1357     48369638 :         types_match = decls_match (newres, oldres);
    1358              :     }
    1359              :   else
    1360              :     {
    1361              :       /* Need to check scope for variable declaration (VAR_DECL).
    1362              :          For typedef (TYPE_DECL), scope is ignored.  */
    1363      1694854 :       if (VAR_P (newdecl)
    1364      1159504 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1365              :           /* [dcl.link]
    1366              :              Two declarations for an object with C language linkage
    1367              :              with the same name (ignoring the namespace that qualify
    1368              :              it) that appear in different namespace scopes refer to
    1369              :              the same object.  */
    1370      1879524 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1371              :         return 0;
    1372              : 
    1373      1510232 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1374            0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1375      1510232 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1376            0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1377      1510232 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1378              :         types_match = 0;
    1379              :       else
    1380      1510232 :         types_match = comptypes (TREE_TYPE (newdecl),
    1381      1510232 :                                  TREE_TYPE (olddecl),
    1382              :                                  COMPARE_REDECLARATION);
    1383              :     }
    1384              : 
    1385              :   return types_match;
    1386              : }
    1387              : 
    1388              : /* Mark DECL as versioned if it isn't already.  */
    1389              : 
    1390              : void
    1391        17616 : maybe_mark_function_versioned (tree decl)
    1392              : {
    1393        17616 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1394              :     {
    1395              :       /* We need to insert function version now to make sure the correct
    1396              :          pre-mangled assembler name is recorded.  */
    1397         1053 :       cgraph_node *node = cgraph_node::get_create (decl);
    1398              : 
    1399         1053 :       if (!node->function_version ())
    1400         1053 :         node->insert_new_function_version ();
    1401              : 
    1402         1053 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1403              :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1404              :          to include the version marker.  */
    1405         1053 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1406         1047 :         mangle_decl (decl);
    1407              :     }
    1408        17616 : }
    1409              : 
    1410              : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1411              :    different versions adjust them, record function versions, and return
    1412              :    true.  */
    1413              : 
    1414              : bool
    1415       195469 : maybe_version_functions (tree newdecl, tree olddecl)
    1416              : {
    1417       195469 :   if (!disjoint_version_decls (newdecl, olddecl))
    1418              :     return false;
    1419              : 
    1420         8790 :   maybe_mark_function_versioned (olddecl);
    1421         8790 :   if (DECL_LOCAL_DECL_P (olddecl))
    1422              :     {
    1423           18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1424           18 :       maybe_mark_function_versioned (olddecl);
    1425              :     }
    1426              : 
    1427         8790 :   maybe_mark_function_versioned (newdecl);
    1428         8790 :   if (DECL_LOCAL_DECL_P (newdecl))
    1429              :     {
    1430              :       /* Unfortunately, we can get here before pushdecl naturally calls
    1431              :          push_local_extern_decl_alias, so we need to call it directly.  */
    1432           18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1433            6 :         push_local_extern_decl_alias (newdecl);
    1434           18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1435           18 :       maybe_mark_function_versioned (newdecl);
    1436              :     }
    1437              : 
    1438              :   /* Add the new version to the function version structure.  */
    1439         8790 :   cgraph_node *fn_node = cgraph_node::get_create (olddecl);
    1440         8790 :   cgraph_function_version_info *fn_v = fn_node->function_version ();
    1441         8790 :   if (!fn_v)
    1442           15 :     fn_v = fn_node->insert_new_function_version ();
    1443              : 
    1444         8790 :   cgraph_node::add_function_version (fn_v, newdecl);
    1445              : 
    1446         8790 :   return true;
    1447              : }
    1448              : 
    1449              : /* If NEWDECL is `static' and an `extern' was seen previously,
    1450              :    warn about it.  OLDDECL is the previous declaration.
    1451              : 
    1452              :    Note that this does not apply to the C++ case of declaring
    1453              :    a variable `extern const' and then later `const'.
    1454              : 
    1455              :    Don't complain about built-in functions, since they are beyond
    1456              :    the user's control.  */
    1457              : 
    1458              : void
    1459     19167558 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1460              : {
    1461     19167558 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1462     19121627 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1463     15204085 :       || TREE_CODE (newdecl) == CONST_DECL
    1464     15204085 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1465     19167546 :     return;
    1466              : 
    1467              :   /* Don't get confused by static member functions; that's a different
    1468              :      use of `static'.  */
    1469     15204085 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1470     15204085 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1471              :     return;
    1472              : 
    1473              :   /* If the old declaration was `static', or the new one isn't, then
    1474              :      everything is OK.  */
    1475     15035158 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1476              :     return;
    1477              : 
    1478              :   /* It's OK to declare a builtin function as `static'.  */
    1479           12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1480           12 :       && DECL_ARTIFICIAL (olddecl))
    1481              :     return;
    1482              : 
    1483           12 :   auto_diagnostic_group d;
    1484           12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1485              :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1486           12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1487              :             "previous declaration of %qD", olddecl);
    1488           12 : }
    1489              : 
    1490              : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1491              :    function templates.  If their exception specifications do not
    1492              :    match, issue a diagnostic.  */
    1493              : 
    1494              : static void
    1495     18634757 : check_redeclaration_exception_specification (tree new_decl,
    1496              :                                              tree old_decl)
    1497              : {
    1498     18634757 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1499     18634757 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1500              : 
    1501              :   /* Two default specs are equivalent, don't force evaluation.  */
    1502      7120462 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1503     18776835 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1504              :     return;
    1505              : 
    1506     18625146 :   if (!type_dependent_expression_p (old_decl))
    1507              :     {
    1508     11392446 :       maybe_instantiate_noexcept (new_decl);
    1509     11392446 :       maybe_instantiate_noexcept (old_decl);
    1510              :     }
    1511     18625146 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1512     18625146 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1513              : 
    1514              :   /* [except.spec]
    1515              : 
    1516              :      If any declaration of a function has an exception-specification,
    1517              :      all declarations, including the definition and an explicit
    1518              :      specialization, of that function shall have an
    1519              :      exception-specification with the same set of type-ids.  */
    1520     18625146 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1521     14833312 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1522     33458328 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1523              :     {
    1524          326 :       const char *const msg
    1525              :         = G_("declaration of %qF has a different exception specifier");
    1526          326 :       bool complained = true;
    1527          326 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1528          326 :       auto_diagnostic_group d;
    1529              : 
    1530              :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1531          652 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1532            1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1533          328 :                          && (nothrow_spec_p (new_exceptions)
    1534            1 :                              == nothrow_spec_p (old_exceptions)));
    1535              : 
    1536          326 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1537          326 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1538              :         /* Don't fuss about the C library; the C library functions are not
    1539              :            specified to have exception specifications (just behave as if they
    1540              :            have them), but some implementations include them.  */
    1541          233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1542           93 :       else if (!flag_exceptions)
    1543              :         /* We used to silently permit mismatched eh specs with
    1544              :            -fno-exceptions, so only complain if -pedantic.  */
    1545            3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1546           90 :       else if (!new_exceptions || global_new)
    1547              :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1548              :            flag for this; silence the warning by correcting the code.  */
    1549           21 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1550              :       else
    1551           69 :         error_at (new_loc, msg, new_decl);
    1552              : 
    1553          326 :       if (complained)
    1554           96 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1555              :                 "from previous declaration %qF", old_decl);
    1556              : 
    1557              :       /* Copy the old exception specification if new_decl has none.  Unless the
    1558              :          old decl is extern "C", as obscure code might depend on the type of
    1559              :          the new declaration (e.g. noexcept-type19.C).  */
    1560          326 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1561           20 :         TREE_TYPE (new_decl)
    1562           40 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1563          326 :     }
    1564              : }
    1565              : 
    1566              : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1567              :    Otherwise issue diagnostics.  */
    1568              : 
    1569              : bool
    1570     19168065 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1571              : {
    1572     19168065 :   old_decl = STRIP_TEMPLATE (old_decl);
    1573     19168065 :   new_decl = STRIP_TEMPLATE (new_decl);
    1574     19168065 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1575     19122110 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1576              :     return true;
    1577     19122110 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1578     19122110 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1579              :     {
    1580     18981269 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1581              :         return true;
    1582     37270322 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1583     18635161 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1584              :         return true;
    1585              :     }
    1586       140847 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1587              :     {
    1588              :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1589              :          keyword.  */
    1590           69 :       if (flag_implicit_constexpr
    1591           69 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1592            0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1593              :         return true;
    1594           69 :       if (fndecl_built_in_p (old_decl))
    1595              :         {
    1596              :           /* Hide a built-in declaration.  */
    1597            0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1598            0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1599            0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1600            0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1601            0 :           return true;
    1602              :         }
    1603              :       /* 7.1.5 [dcl.constexpr]
    1604              :          Note: An explicit specialization can differ from the template
    1605              :          declaration with respect to the constexpr specifier.  */
    1606           69 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1607           69 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1608              :         return true;
    1609              : 
    1610           42 :       const char *kind = "constexpr";
    1611           42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1612           72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1613              :         kind = "consteval";
    1614           42 :       auto_diagnostic_group d;
    1615           42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1616              :                 "redeclaration %qD differs in %qs "
    1617              :                 "from previous declaration", new_decl,
    1618              :                 kind);
    1619           42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1620              :               "previous declaration %qD", old_decl);
    1621           42 :       return false;
    1622           42 :     }
    1623              :   return true;
    1624              : }
    1625              : 
    1626              : /* DECL is a redeclaration of a function or function template.  If
    1627              :    it does have default arguments issue a diagnostic.  Note: this
    1628              :    function is used to enforce the requirements in C++11 8.3.6 about
    1629              :    no default arguments in redeclarations.  */
    1630              : 
    1631              : static void
    1632     11224069 : check_redeclaration_no_default_args (tree decl)
    1633              : {
    1634     11224069 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1635              : 
    1636     11224069 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1637     32973069 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1638     21749057 :     if (TREE_PURPOSE (t))
    1639              :       {
    1640           57 :         permerror (DECL_SOURCE_LOCATION (decl),
    1641              :                    "redeclaration of %q#D may not have default "
    1642              :                    "arguments", decl);
    1643           57 :         return;
    1644              :       }
    1645              : }
    1646              : 
    1647              : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1648              :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1649              :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1650              :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1651              :    "If a friend declaration specifies a default argument expression, that
    1652              :    declaration shall be a definition and shall be the only declaration of
    1653              :    the function or function template in the translation unit."  */
    1654              : 
    1655              : static void
    1656      6866020 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1657              : {
    1658     13039320 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1659              :     return;
    1660              : 
    1661      3552832 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1662      1776416 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1663      4689132 :        t1 && t1 != void_list_node;
    1664      2912716 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1665      4150564 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1666      8308769 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1667              :       {
    1668           36 :         auto_diagnostic_group d;
    1669           36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1670              :                        "friend declaration of %q#D specifies default "
    1671              :                        "arguments and isn%'t the only declaration", newdecl))
    1672           36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1673              :                   "previous declaration of %q#D", olddecl);
    1674           36 :         return;
    1675           36 :       }
    1676              : }
    1677              : 
    1678              : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1679              :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1680              : 
    1681              : static void
    1682     18085485 : merge_attribute_bits (tree newdecl, tree olddecl)
    1683              : {
    1684     18085485 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1685     18085485 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1686     18085485 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1687     18085485 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1688     18085485 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1689     18085485 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1690     18085485 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1691     18085485 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1692     18085485 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1693     18085485 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1694     18085485 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1695     18085485 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1696     18085485 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1697     18085485 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1698     18085485 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1699     18085485 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1700     18085485 : }
    1701              : 
    1702              : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1703              :                           && lookup_attribute ("gnu_inline",          \
    1704              :                                                DECL_ATTRIBUTES (fn)))
    1705              : 
    1706              : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1707              :    ambiguates olddecl.  Returns true if an error occurs.  */
    1708              : 
    1709              : static bool
    1710    142060884 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1711              : {
    1712    142060884 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1713    142060884 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1714              :   /* Function template declarations can be differentiated by parameter
    1715              :      and return type.  */
    1716    142060884 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1717    142060884 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1718    142060884 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1719              :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1720              :     {
    1721              :       /* ... and also by their template-heads and requires-clauses.  */
    1722         6455 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1723         6455 :           && function_requirements_equivalent_p (newres, oldres))
    1724              :         {
    1725            0 :           auto_diagnostic_group d;
    1726            0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1727            0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1728              :                   "old declaration %q#D", olddecl);
    1729            0 :           return true;
    1730            0 :         }
    1731              : 
    1732              :       /* FIXME: The types are the same but the are differences
    1733              :          in either the template heads or function requirements.
    1734              :          We should be able to diagnose a set of common errors
    1735              :          stemming from these declarations. For example:
    1736              : 
    1737              :            template<typename T> requires C void f(...);
    1738              :            template<typename T> void f(...) requires C;
    1739              : 
    1740              :          These are functionally equivalent but not equivalent.  */
    1741              :     }
    1742              : 
    1743              :   return false;
    1744              : }
    1745              : 
    1746              : /* OLD_PARMS is the innermost set of template parameters for some template
    1747              :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1748              :    for a redeclaration of that template.  Merge the default arguments within
    1749              :    these two sets of parameters.  CLASS_P is true iff the template in
    1750              :    question is a class template.  */
    1751              : 
    1752              : bool
    1753      8680254 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1754              : {
    1755      8680254 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1756              :                        == TREE_VEC_LENGTH (old_parms));
    1757     24563259 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1758              :     {
    1759     15883035 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1760     15883035 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1761     15883035 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1762     15883035 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1763     15883035 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1764              :         return false;
    1765     15883032 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1766              :         {
    1767           27 :           auto_diagnostic_group d;
    1768           27 :           error ("redefinition of default argument for %q+#D", new_parm);
    1769           27 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1770              :                   "original definition appeared here");
    1771           27 :           return false;
    1772           27 :         }
    1773     15883005 :       else if (new_default != NULL_TREE)
    1774              :         /* Update the previous template parameters (which are the ones
    1775              :            that will really count) with the new default value.  */
    1776       205138 :         old_default = new_default;
    1777     15677867 :       else if (class_p && old_default != NULL_TREE)
    1778              :         /* Update the new parameters, too; they'll be used as the
    1779              :            parameters for any members.  */
    1780      1139220 :         new_default = old_default;
    1781              :     }
    1782              :   return true;
    1783              : }
    1784              : 
    1785              : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
    1786              :    Merge parameter attributes and names between NEWDECL and OLDDECL.
    1787              :    NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
    1788              :    duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
    1789              :    push_local_extern_decl_alias.  */
    1790              : 
    1791              : void
    1792     14717646 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
    1793              :                       bool types_match, bool extern_alias)
    1794              : {
    1795     14717646 :   tree oldarg, newarg, type = NULL_TREE;
    1796     14717646 :   tree first_user_parm = NULL_TREE;
    1797     14717646 :   if (extern_alias)
    1798          176 :     first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
    1799     14717646 :   for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
    1800     41174517 :        oldarg && newarg;
    1801     26456871 :        oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
    1802              :     {
    1803     26456871 :       DECL_ATTRIBUTES (newarg)
    1804     26456871 :         = (*targetm.merge_decl_attributes) (oldarg, newarg);
    1805     26456871 :       if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
    1806     26456940 :           && !lookup_attribute (NULL, "indeterminate",
    1807           69 :                                 DECL_ATTRIBUTES (oldarg)))
    1808              :         {
    1809           18 :           auto_diagnostic_group d;
    1810           18 :           error_at (DECL_SOURCE_LOCATION (newarg),
    1811              :                     "%<indeterminate%> attribute not specified for parameter "
    1812              :                     "%qD on the first declaration of its function", newarg);
    1813           18 :           inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
    1814           18 :         }
    1815              :       /* ??? Should attributes propagate out from a block extern?  If so,
    1816              :          we should do that for the function itself, not just parameters.  */
    1817     26456871 :       if (!extern_alias || flag_reflection)
    1818     26456710 :         DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1819     26456871 :       if (!flag_reflection)
    1820     26306270 :         continue;
    1821              :       /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
    1822              :          if the local extern has a default argument for that parameter.  */
    1823       150601 :       if (extern_alias)
    1824              :         {
    1825           17 :           if (newarg == first_user_parm)
    1826            5 :             type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1827           12 :           else if (type)
    1828           12 :             type = TREE_CHAIN (type);
    1829           34 :           if (type && TREE_PURPOSE (type))
    1830            2 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1831              :         }
    1832              :       else
    1833              :         {
    1834              :           /* Otherwise propagate the flag.  */
    1835       150584 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
    1836            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
    1837       150584 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
    1838            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1839              :         }
    1840              :       /* Merge names for std::meta::has_identifier and
    1841              :          std::meta::{,u8}identifier_of purposes.  If they are different and
    1842              :          both oldarg and newarg are named, add flag to force that
    1843              :          std::meta::has_identifier returns false.  If one is named and one is
    1844              :          unnamed, if neither is a olddecl nor newdecl is definition, propagate
    1845              :          DECL_NAME to both.  Otherwise stash the old name into "old parm name"
    1846              :          artificial attribute.  */
    1847       150601 :       if (DECL_NAME (oldarg) != DECL_NAME (newarg))
    1848              :         {
    1849        17115 :           if (DECL_NAME (oldarg) && DECL_NAME (newarg))
    1850              :             {
    1851              :               /* Different names.  */
    1852         3616 :               MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1853         3616 :               MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1854              :             }
    1855        13499 :           else if (!new_defines_function
    1856        13499 :                    && types_match
    1857        13499 :                    && DECL_INITIAL (olddecl) == NULL_TREE)
    1858              :             {
    1859              :               /* For 2 non-definitions with matching types, one is named and
    1860              :                  one unnamed, propagate name to both.  */
    1861         2573 :               if (DECL_NAME (oldarg))
    1862         2139 :                 DECL_NAME (newarg) = DECL_NAME (oldarg);
    1863              :               else
    1864          434 :                 DECL_NAME (oldarg) = DECL_NAME (newarg);
    1865              :             }
    1866              :           /* Depending on which PARM_DECL we'll keep, look at the other
    1867              :              PARM_DECL's name.  */
    1868        10926 :           else if (tree name = ((new_defines_function || !types_match)
    1869        10926 :                                 ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
    1870              :             {
    1871           93 :               tree opn = lookup_attribute ("old parm name",
    1872           93 :                                            DECL_ATTRIBUTES (oldarg));
    1873           93 :               if (opn)
    1874              :                 {
    1875            0 :                   if (TREE_VALUE (TREE_VALUE (opn)) == name)
    1876              :                     /* Name already in "old parm name" attribute.  */;
    1877              :                   else
    1878              :                     {
    1879              :                       /* Different names.  */
    1880            0 :                       MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1881            0 :                       MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1882              :                     }
    1883              :                 }
    1884              :               else
    1885              :                 {
    1886              :                   /* Save name into attribute.  */
    1887           93 :                   DECL_ATTRIBUTES (newarg)
    1888           93 :                     = tree_cons (get_identifier ("old parm name"),
    1889              :                                  tree_cons (NULL_TREE, name, NULL_TREE),
    1890           93 :                                  DECL_ATTRIBUTES (newarg));
    1891           93 :                   DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1892              :                 }
    1893              :             }
    1894        10833 :           else if (extern_alias)
    1895            1 :             DECL_NAME (newarg) = DECL_NAME (oldarg);
    1896              :         }
    1897              :     }
    1898     14717646 : }
    1899              : 
    1900              : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1901              :    If the redeclaration is invalid, a diagnostic is issued, and the
    1902              :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1903              : 
    1904              :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1905              :    returned.
    1906              : 
    1907              :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1908              :    if the old decl was hidden.
    1909              : 
    1910              :    Hidden decls can be anticipated builtins, injected friends, or
    1911              :    (coming soon) injected from a local-extern decl.   */
    1912              : 
    1913              : tree
    1914    283923889 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1915              : {
    1916    283923889 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1917    283923889 :   int types_match = 0;
    1918    283923889 :   int new_defines_function = 0;
    1919    283923889 :   tree new_template_info;
    1920    283923889 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1921    283923889 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1922              : 
    1923    283923889 :   if (newdecl == olddecl)
    1924              :     return olddecl;
    1925              : 
    1926    283104545 :   types_match = decls_match (newdecl, olddecl);
    1927              : 
    1928              :   /* If either the type of the new decl or the type of the old decl is an
    1929              :      error_mark_node, then that implies that we have already issued an
    1930              :      error (earlier) for some bogus type specification, and in that case,
    1931              :      it is rather pointless to harass the user with yet more error message
    1932              :      about the same declaration, so just pretend the types match here.  */
    1933    283104545 :   if (TREE_TYPE (newdecl) == error_mark_node
    1934    283104545 :       || TREE_TYPE (olddecl) == error_mark_node)
    1935              :     return error_mark_node;
    1936              : 
    1937              :   /* Check for redeclaration and other discrepancies.  */
    1938    283104520 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1939    283104520 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1940              :     {
    1941      6108403 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1942              :         {
    1943              :           /* Avoid warnings redeclaring built-ins which have not been
    1944              :              explicitly declared.  */
    1945       185156 :           if (was_hidden)
    1946              :             {
    1947       185114 :               if (TREE_PUBLIC (newdecl)
    1948       185114 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1949           12 :                 warning_at (newdecl_loc,
    1950           12 :                             OPT_Wbuiltin_declaration_mismatch,
    1951              :                             "built-in function %qD declared as non-function",
    1952              :                             newdecl);
    1953       185114 :               return NULL_TREE;
    1954              :             }
    1955              : 
    1956              :           /* If you declare a built-in or predefined function name as static,
    1957              :              the old definition is overridden, but optionally warn this was a
    1958              :              bad choice of name.  */
    1959           42 :           if (! TREE_PUBLIC (newdecl))
    1960              :             {
    1961           42 :               warning_at (newdecl_loc,
    1962           42 :                           OPT_Wshadow,
    1963           42 :                           fndecl_built_in_p (olddecl)
    1964              :                           ? G_("shadowing built-in function %q#D")
    1965              :                           : G_("shadowing library function %q#D"), olddecl);
    1966              :               /* Discard the old built-in function.  */
    1967           42 :               return NULL_TREE;
    1968              :             }
    1969              :           /* If the built-in is not ansi, then programs can override
    1970              :              it even globally without an error.  */
    1971            0 :           else if (! fndecl_built_in_p (olddecl))
    1972            0 :             warning_at (newdecl_loc, 0,
    1973              :                         "library function %q#D redeclared as non-function %q#D",
    1974              :                         olddecl, newdecl);
    1975              :           else
    1976            0 :             error_at (newdecl_loc,
    1977              :                       "declaration of %q#D conflicts with built-in "
    1978              :                       "declaration %q#D", newdecl, olddecl);
    1979            0 :           return NULL_TREE;
    1980              :         }
    1981      5923247 :       else if (!types_match)
    1982              :         {
    1983              :           /* Avoid warnings redeclaring built-ins which have not been
    1984              :              explicitly declared.  */
    1985      2131413 :           if (was_hidden)
    1986              :             {
    1987       775122 :               tree t1, t2;
    1988              : 
    1989              :               /* A new declaration doesn't match a built-in one unless it
    1990              :                  is also extern "C".  */
    1991       775122 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1992       775122 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1993       775122 :               if (!DECL_EXTERN_C_P (newdecl))
    1994              :                 return NULL_TREE;
    1995              : 
    1996       138396 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1997       138396 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1998       238593 :                    t1 || t2;
    1999       100197 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2000              :                 {
    2001       238575 :                   if (!t1 || !t2)
    2002              :                     break;
    2003              :                   /* FILE, tm types are not known at the time
    2004              :                      we create the builtins.  */
    2005       738227 :                   for (unsigned i = 0;
    2006       976640 :                        i < sizeof (builtin_structptr_types)
    2007              :                            / sizeof (builtin_structptr_type);
    2008              :                        ++i)
    2009       876437 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    2010              :                       {
    2011       138210 :                         tree t = TREE_VALUE (t1);
    2012              : 
    2013       138210 :                         if (TYPE_PTR_P (t)
    2014       276420 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    2015       138210 :                             == get_identifier (builtin_structptr_types[i].str)
    2016       276405 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    2017              :                           {
    2018       138195 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2019              : 
    2020       138195 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    2021       138195 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    2022       138195 :                             types_match = decls_match (newdecl, olddecl);
    2023       138195 :                             if (types_match)
    2024       138195 :                               return duplicate_decls (newdecl, olddecl,
    2025       138195 :                                                       hiding, was_hidden);
    2026            0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    2027              :                           }
    2028           15 :                         goto next_arg;
    2029              :                       }
    2030              : 
    2031       100203 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2032              :                     break;
    2033       100197 :                 next_arg:;
    2034              :                 }
    2035              : 
    2036          201 :               warning_at (newdecl_loc,
    2037          201 :                           OPT_Wbuiltin_declaration_mismatch,
    2038              :                           "declaration of %q#D conflicts with built-in "
    2039              :                           "declaration %q#D", newdecl, olddecl);
    2040              :             }
    2041      1356291 :           else if ((DECL_EXTERN_C_P (newdecl)
    2042           15 :                     && DECL_EXTERN_C_P (olddecl))
    2043      2712567 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2044      1356276 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    2045              :             {
    2046              :               /* Don't really override olddecl for __* prefixed builtins
    2047              :                  except for __[^b]*_chk, the compiler might be using those
    2048              :                  explicitly.  */
    2049           15 :               if (fndecl_built_in_p (olddecl))
    2050              :                 {
    2051           15 :                   tree id = DECL_NAME (olddecl);
    2052           15 :                   const char *name = IDENTIFIER_POINTER (id);
    2053           15 :                   size_t len;
    2054              : 
    2055           15 :                   if (name[0] == '_'
    2056           15 :                       && name[1] == '_'
    2057           30 :                       && (startswith (name + 2, "builtin_")
    2058            6 :                           || (len = strlen (name)) <= strlen ("___chk")
    2059            6 :                           || memcmp (name + len - strlen ("_chk"),
    2060              :                                      "_chk", strlen ("_chk") + 1) != 0))
    2061              :                     {
    2062           15 :                       if (DECL_INITIAL (newdecl))
    2063              :                         {
    2064            6 :                           error_at (newdecl_loc,
    2065              :                                     "definition of %q#D ambiguates built-in "
    2066              :                                     "declaration %q#D", newdecl, olddecl);
    2067            6 :                           return error_mark_node;
    2068              :                         }
    2069            9 :                       auto_diagnostic_group d;
    2070            9 :                       if (permerror (newdecl_loc,
    2071              :                                      "new declaration %q#D ambiguates built-in"
    2072              :                                      " declaration %q#D", newdecl, olddecl)
    2073            9 :                           && flag_permissive)
    2074            3 :                         inform (newdecl_loc,
    2075              :                                 "ignoring the %q#D declaration", newdecl);
    2076            9 :                       return flag_permissive ? olddecl : error_mark_node;
    2077            9 :                     }
    2078              :                 }
    2079              : 
    2080              :               /* A near match; override the builtin.  */
    2081              : 
    2082            0 :               if (TREE_PUBLIC (newdecl))
    2083            0 :                 warning_at (newdecl_loc,
    2084            0 :                             OPT_Wbuiltin_declaration_mismatch,
    2085              :                             "new declaration %q#D ambiguates built-in "
    2086              :                             "declaration %q#D", newdecl, olddecl);
    2087              :               else
    2088            0 :                 warning (OPT_Wshadow,
    2089              :                          fndecl_built_in_p (olddecl)
    2090              :                          ? G_("shadowing built-in function %q#D")
    2091              :                          : G_("shadowing library function %q#D"), olddecl);
    2092              :             }
    2093              :           else
    2094              :             /* Discard the old built-in function.  */
    2095              :             return NULL_TREE;
    2096              : 
    2097              :           /* Replace the old RTL to avoid problems with inlining.  */
    2098          201 :           COPY_DECL_RTL (newdecl, olddecl);
    2099              :         }
    2100              :       else
    2101              :         {
    2102              :           /* Even if the types match, prefer the new declarations type
    2103              :              for built-ins which have not been explicitly declared,
    2104              :              for exception lists, etc...  */
    2105      3791834 :           tree type = TREE_TYPE (newdecl);
    2106      3791834 :           tree attribs = (*targetm.merge_type_attributes)
    2107      3791834 :             (TREE_TYPE (olddecl), type);
    2108              : 
    2109      3791834 :           type = cp_build_type_attribute_variant (type, attribs);
    2110      3791834 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    2111              :         }
    2112              : 
    2113              :       /* If a function is explicitly declared "throw ()", propagate that to
    2114              :          the corresponding builtin.  */
    2115      3792035 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    2116      3634720 :           && was_hidden
    2117      3634677 :           && TREE_NOTHROW (newdecl)
    2118      7174167 :           && !TREE_NOTHROW (olddecl))
    2119              :         {
    2120        26854 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    2121        26854 :           tree tmpdecl = builtin_decl_explicit (fncode);
    2122        26854 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    2123        26854 :             TREE_NOTHROW (tmpdecl)  = 1;
    2124              :         }
    2125              : 
    2126              :       /* Whether or not the builtin can throw exceptions has no
    2127              :          bearing on this declarator.  */
    2128      3792035 :       TREE_NOTHROW (olddecl) = 0;
    2129              : 
    2130      3792035 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    2131              :         {
    2132              :           /* If a builtin function is redeclared as `static', merge
    2133              :              the declarations, but make the original one static.  */
    2134            3 :           DECL_THIS_STATIC (olddecl) = 1;
    2135            3 :           TREE_PUBLIC (olddecl) = 0;
    2136              : 
    2137              :           /* Make the old declaration consistent with the new one so
    2138              :              that all remnants of the builtin-ness of this function
    2139              :              will be banished.  */
    2140            3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2141            3 :           COPY_DECL_RTL (newdecl, olddecl);
    2142              :         }
    2143              :     }
    2144    276996117 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2145              :     {
    2146              :       /* C++ Standard, 3.3, clause 4:
    2147              :          "[Note: a namespace name or a class template name must be unique
    2148              :          in its declarative region (7.3.2, clause 14). ]"  */
    2149     68902395 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    2150     68902368 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    2151              :         /* Namespace conflicts with not namespace.  */;
    2152     33809127 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    2153    102711483 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    2154              :         /* Class template conflicts.  */;
    2155     68902350 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    2156     33809127 :                 && DECL_TEMPLATE_RESULT (olddecl)
    2157     33809127 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    2158    102711471 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    2159     35046110 :                    && DECL_TEMPLATE_RESULT (newdecl)
    2160     35046110 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    2161              :         /* Variable template conflicts.  */;
    2162     68902341 :       else if (concept_definition_p (olddecl)
    2163    137804676 :                || concept_definition_p (newdecl))
    2164              :         /* Concept conflicts.  */;
    2165     68902329 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    2166     33846847 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    2167     68940061 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    2168     35046120 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    2169              :         {
    2170              :           /* One is a function and the other is a template
    2171              :              function.  */
    2172     68855201 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    2173              :             return NULL_TREE;
    2174              : 
    2175              :           /* There can only be one!  */
    2176        55675 :           auto_diagnostic_group d;
    2177        55675 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    2178        55675 :               && check_raw_literal_operator (olddecl))
    2179            3 :             error_at (newdecl_loc,
    2180              :                       "literal operator %q#D conflicts with"
    2181              :                       " raw literal operator", newdecl);
    2182        55672 :           else if (check_raw_literal_operator (newdecl))
    2183            3 :             error_at (newdecl_loc,
    2184              :                       "raw literal operator %q#D conflicts with"
    2185              :                       " literal operator template", newdecl);
    2186              :           else
    2187              :             return NULL_TREE;
    2188              : 
    2189            6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2190            6 :           return error_mark_node;
    2191        55675 :         }
    2192        47128 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    2193              :         /* A structured binding must be unique in its declarative region.  */;
    2194        37877 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2195        47125 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    2196              :         /* One is an implicit typedef, that's ok.  */
    2197              :         return NULL_TREE;
    2198              : 
    2199          153 :       auto_diagnostic_group d;
    2200          153 :       error ("%q#D redeclared as different kind of entity", newdecl);
    2201          153 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2202              : 
    2203          153 :       return error_mark_node;
    2204          153 :     }
    2205    208093722 :   else if (!types_match)
    2206              :     {
    2207    192686345 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    2208              :         /* These are certainly not duplicate declarations; they're
    2209              :            from different scopes.  */
    2210              :         return NULL_TREE;
    2211              : 
    2212    192686285 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2213              :         {
    2214    142060902 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    2215    142060902 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    2216              : 
    2217              :           /* The name of a class template may not be declared to refer to
    2218              :              any other template, class, function, object, namespace, value,
    2219              :              or type in the same scope.  */
    2220    142060902 :           if (TREE_CODE (oldres) == TYPE_DECL
    2221    142060896 :               || TREE_CODE (newres) == TYPE_DECL)
    2222              :             {
    2223            9 :               auto_diagnostic_group d;
    2224            9 :               error_at (newdecl_loc,
    2225              :                         "conflicting declaration of template %q#D", newdecl);
    2226            9 :               inform (olddecl_loc,
    2227              :                       "previous declaration %q#D", olddecl);
    2228            9 :               return error_mark_node;
    2229            9 :             }
    2230              : 
    2231    142060893 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    2232    142060884 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    2233              :             {
    2234    142060884 :               if (duplicate_function_template_decls (newdecl, olddecl))
    2235            0 :                 return error_mark_node;
    2236              :               return NULL_TREE;
    2237              :             }
    2238              :           return NULL_TREE;
    2239              :         }
    2240     50625383 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2241              :         {
    2242     50625234 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2243              :             {
    2244           57 :               auto_diagnostic_group d;
    2245           57 :               error_at (newdecl_loc,
    2246              :                         "conflicting declaration of C function %q#D",
    2247              :                         newdecl);
    2248           57 :               inform (olddecl_loc,
    2249              :                       "previous declaration %q#D", olddecl);
    2250           57 :               return error_mark_node;
    2251           57 :             }
    2252              :           /* For function versions, params and types match, but they
    2253              :              are not ambiguous.  */
    2254     50625177 :           else if (((!DECL_FUNCTION_VERSIONED (newdecl)
    2255     50616873 :                      && !DECL_FUNCTION_VERSIONED (olddecl))
    2256         8349 :                     || !same_type_p (fndecl_declared_return_type (newdecl),
    2257              :                                      fndecl_declared_return_type (olddecl)))
    2258              :                    /* Let constrained hidden friends coexist for now, we'll
    2259              :                       check satisfaction later.  */
    2260     50616828 :                    && !member_like_constrained_friend_p (newdecl)
    2261     49574794 :                    && !member_like_constrained_friend_p (olddecl)
    2262              :                    // The functions have the same parameter types.
    2263     49474799 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2264     49474799 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2265              :                    // And the same constraints.
    2266     50625246 :                    && equivalently_constrained (newdecl, olddecl))
    2267              :             {
    2268           69 :               auto_diagnostic_group d;
    2269           69 :               error_at (newdecl_loc,
    2270              :                         "ambiguating new declaration of %q#D", newdecl);
    2271           69 :               inform (olddecl_loc,
    2272              :                       "old declaration %q#D", olddecl);
    2273           69 :               return error_mark_node;
    2274           69 :             }
    2275              :           else
    2276     50625108 :             return NULL_TREE;
    2277              :         }
    2278              :       else
    2279              :         {
    2280          149 :           auto_diagnostic_group d;
    2281          149 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2282          149 :           inform (olddecl_loc,
    2283              :                   "previous declaration as %q#D", olddecl);
    2284          149 :           return error_mark_node;
    2285          149 :         }
    2286              :     }
    2287     15407377 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2288     15407377 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2289              :     {
    2290              :       /* OMP UDRs are never duplicates. */
    2291           33 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2292           33 :       auto_diagnostic_group d;
    2293           33 :       error_at (newdecl_loc,
    2294              :                 "redeclaration of %<pragma omp declare reduction%>");
    2295           33 :       inform (olddecl_loc,
    2296              :               "previous %<pragma omp declare reduction%> declaration");
    2297           33 :       return error_mark_node;
    2298           33 :     }
    2299     15407344 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2300     15407344 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2301          222 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2302          222 :                      || (DECL_TI_TEMPLATE (newdecl)
    2303          222 :                          != DECL_TI_TEMPLATE (olddecl))))
    2304     10925717 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2305       549536 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2306       549536 :                         || (DECL_TI_TEMPLATE (olddecl)
    2307       549536 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2308              :     /* It's OK to have a template specialization and a non-template
    2309              :        with the same type, or to have specializations of two
    2310              :        different templates with the same type.  Note that if one is a
    2311              :        specialization, and the other is an instantiation of the same
    2312              :        template, that we do not exit at this point.  That situation
    2313              :        can occur if we instantiate a template class, and then
    2314              :        specialize one of its methods.  This situation is valid, but
    2315              :        the declarations must be merged in the usual way.  */
    2316              :     return NULL_TREE;
    2317     15407344 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2318     15407344 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2319       626096 :                 && !DECL_USE_TEMPLATE (newdecl))
    2320     10925717 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2321        76782 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2322              :     /* One of the declarations is a template instantiation, and the
    2323              :        other is not a template at all.  That's OK.  */
    2324              :     return NULL_TREE;
    2325     15407344 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2326              :     {
    2327              :       /* In [namespace.alias] we have:
    2328              : 
    2329              :            In a declarative region, a namespace-alias-definition can be
    2330              :            used to redefine a namespace-alias declared in that declarative
    2331              :            region to refer only to the namespace to which it already
    2332              :            refers.
    2333              : 
    2334              :          Therefore, if we encounter a second alias directive for the same
    2335              :          alias, we can just ignore the second directive.  */
    2336           22 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2337           22 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2338           19 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2339              :         return olddecl;
    2340              : 
    2341              :       /* Leave it to update_binding to merge or report error.  */
    2342              :       return NULL_TREE;
    2343              :     }
    2344              :   /* Check if the two decls are non-mergeable versioned decls.  */
    2345     15407322 :   else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2346              :            && diagnose_versioned_decls (olddecl, newdecl))
    2347              :     return error_mark_node;
    2348              :   else
    2349              :     {
    2350     15407322 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2351     15407322 :       if (errmsg)
    2352              :         {
    2353          617 :           auto_diagnostic_group d;
    2354          617 :           error_at (newdecl_loc, errmsg, newdecl);
    2355          617 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2356          617 :             inform (olddecl_loc,
    2357          617 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2358              :                     ? G_("%q#D previously defined here")
    2359              :                     : G_("%q#D previously declared here"), olddecl);
    2360          617 :           if (cxx_dialect >= cxx26
    2361          147 :               && DECL_NAME (newdecl)
    2362          147 :               && id_equal (DECL_NAME (newdecl), "_")
    2363          630 :               && !name_independent_decl_p (newdecl))
    2364              :             {
    2365           13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2366            2 :                 inform (newdecl_loc,
    2367              :                         "parameter declaration is not name-independent");
    2368           11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2369              :                 {
    2370            3 :                   if (at_namespace_scope_p ())
    2371            2 :                     inform (newdecl_loc,
    2372              :                             "structured binding at namespace scope is not "
    2373              :                             "name-independent");
    2374            1 :                   else if (TREE_STATIC (newdecl))
    2375            1 :                     inform (newdecl_loc,
    2376              :                             "static structured binding is not "
    2377              :                             "name-independent");
    2378            0 :                   else if (DECL_EXTERNAL (newdecl))
    2379            0 :                     inform (newdecl_loc,
    2380              :                             "extern structured binding is not "
    2381              :                             "name-independent");
    2382              :                 }
    2383            8 :               else if (at_class_scope_p ()
    2384            0 :                        && VAR_P (newdecl)
    2385            8 :                        && TREE_STATIC (newdecl))
    2386            0 :                 inform (newdecl_loc,
    2387              :                         "static data member is not name-independent");
    2388            8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2389            3 :                 inform (newdecl_loc,
    2390              :                         "variable at namespace scope is not name-independent");
    2391            5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2392            3 :                 inform (newdecl_loc,
    2393              :                         "static variable is not name-independent");
    2394            2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2395            0 :                 inform (newdecl_loc,
    2396              :                         "extern variable is not name-independent");
    2397              :             }
    2398          617 :           return error_mark_node;
    2399          617 :         }
    2400     15406705 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2401     10925480 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2402        11055 :                && !prototype_p (TREE_TYPE (olddecl))
    2403     15406705 :                && prototype_p (TREE_TYPE (newdecl)))
    2404              :         {
    2405              :           /* Prototype decl follows defn w/o prototype.  */
    2406            0 :           auto_diagnostic_group d;
    2407            0 :           if (warning_at (newdecl_loc, 0,
    2408              :                           "prototype specified for %q#D", newdecl))
    2409            0 :             inform (olddecl_loc,
    2410              :                     "previous non-prototype definition here");
    2411            0 :         }
    2412     14920090 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2413     26332185 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2414              :         {
    2415              :           /* [dcl.link]
    2416              :              If two declarations of the same function or object
    2417              :              specify different linkage-specifications ..., the program
    2418              :              is ill-formed.... Except for functions with C++ linkage,
    2419              :              a function declaration without a linkage specification
    2420              :              shall not precede the first linkage specification for
    2421              :              that function.  A function can be declared without a
    2422              :              linkage specification after an explicit linkage
    2423              :              specification has been seen; the linkage explicitly
    2424              :              specified in the earlier declaration is not affected by
    2425              :              such a function declaration.
    2426              : 
    2427              :              DR 563 raises the question why the restrictions on
    2428              :              functions should not also apply to objects.  Older
    2429              :              versions of G++ silently ignore the linkage-specification
    2430              :              for this example:
    2431              : 
    2432              :                namespace N {
    2433              :                  extern int i;
    2434              :                  extern "C" int i;
    2435              :                }
    2436              : 
    2437              :              which is clearly wrong.  Therefore, we now treat objects
    2438              :              like functions.  */
    2439         1844 :           if (current_lang_depth () == 0)
    2440              :             {
    2441              :               /* There is no explicit linkage-specification, so we use
    2442              :                  the linkage from the previous declaration.  */
    2443         1832 :               retrofit_lang_decl (newdecl);
    2444         1832 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2445              :             }
    2446              :           else
    2447              :             {
    2448           12 :               auto_diagnostic_group d;
    2449           12 :               error_at (newdecl_loc,
    2450              :                         "conflicting declaration of %q#D with %qL linkage",
    2451           12 :                         newdecl, DECL_LANGUAGE (newdecl));
    2452           12 :               inform (olddecl_loc,
    2453              :                       "previous declaration with %qL linkage",
    2454           12 :                       DECL_LANGUAGE (olddecl));
    2455           12 :             }
    2456              :         }
    2457              : 
    2458     15406705 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2459              :         ;
    2460     14760355 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2461              :         {
    2462              :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2463     12844077 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2464     10299171 :               && (/* grokfndecl passes member function templates too
    2465              :                      as FUNCTION_DECLs.  */
    2466      7923064 :                   DECL_TEMPLATE_INFO (olddecl)
    2467              :                   /* C++11 8.3.6/6.
    2468              :                      Default arguments for a member function of a class
    2469              :                      template shall be specified on the initial declaration
    2470              :                      of the member function within the class template.  */
    2471       672352 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2472              :             {
    2473      7328610 :               check_redeclaration_no_default_args (newdecl);
    2474              : 
    2475      7328610 :               if (DECL_TEMPLATE_INFO (olddecl)
    2476      7328610 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2477              :                 {
    2478      2124050 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2479      2124050 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2480      2124050 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2481      2124050 :                   tree old_parms
    2482      2124050 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2483      2124050 :                   merge_default_template_args (new_parms, old_parms,
    2484              :                                                /*class_p=*/false);
    2485              :                 }
    2486              :             }
    2487              :           else
    2488              :             {
    2489      2970561 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2490      2970561 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2491      2970561 :               int i = 1;
    2492              : 
    2493      7661369 :               for (; t1 && t1 != void_list_node;
    2494      4690808 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2495      4692725 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2496              :                   {
    2497           57 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2498           57 :                                           TREE_PURPOSE (t2)) == 1)
    2499              :                       {
    2500           24 :                         auto_diagnostic_group d;
    2501           24 :                         if (permerror (newdecl_loc,
    2502              :                                        "default argument given for parameter "
    2503              :                                        "%d of %q#D", i, newdecl))
    2504           24 :                           inform (olddecl_loc,
    2505              :                                   "previous specification in %q#D here",
    2506              :                                   olddecl);
    2507           24 :                       }
    2508              :                     else
    2509              :                       {
    2510           33 :                         auto_diagnostic_group d;
    2511           33 :                         error_at (newdecl_loc,
    2512              :                                   "default argument given for parameter %d "
    2513              :                                   "of %q#D", i, newdecl);
    2514           33 :                         inform (olddecl_loc,
    2515              :                                 "previous specification in %q#D here",
    2516              :                                 olddecl);
    2517           33 :                       }
    2518              :                   }
    2519              : 
    2520              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2521              :                  argument expression, that declaration... shall be the only
    2522              :                  declaration of the function or function template in the
    2523              :                  translation unit."  */
    2524      2970561 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2525              :             }
    2526              :         }
    2527              :     }
    2528              : 
    2529              :   /* Do not merge an implicit typedef with an explicit one.  In:
    2530              : 
    2531              :        class A;
    2532              :        ...
    2533              :        typedef class A A __attribute__ ((foo));
    2534              : 
    2535              :      the attribute should apply only to the typedef.  */
    2536     19198740 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2537     19198740 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2538        45934 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2539              :     return NULL_TREE;
    2540              : 
    2541     19167624 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2542              :     return NULL_TREE;
    2543              : 
    2544     19167612 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2545           30 :     return error_mark_node;
    2546              : 
    2547     19167582 :   if (modules_p ()
    2548        44491 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2549     19193988 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2550              :     {
    2551        26406 :       if (!module_may_redeclare (olddecl, newdecl))
    2552           24 :         return error_mark_node;
    2553              : 
    2554        26382 :       if (!hiding)
    2555              :         {
    2556              :           /* The old declaration should match the exportingness of the new
    2557              :              declaration.  But hidden friend declarations just keep the
    2558              :              exportingness of the old declaration; see CWG2588.  */
    2559        23290 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2560        23290 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2561        23245 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2562              :               /* Typedefs are not entities and so are OK to be redeclared
    2563              :                  as exported: see [module.interface]/p6.  */
    2564        23475 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2565              :             {
    2566          173 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2567          173 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2568              :                 {
    2569           15 :                   auto_diagnostic_group d;
    2570           15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2571           15 :                   inform (olddecl_loc,
    2572              :                           "previously declared here without exporting");
    2573           15 :                 }
    2574              :             }
    2575        23117 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2576        10025 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2577              :         }
    2578              :     }
    2579              : 
    2580              :   /* We have committed to returning OLDDECL at this point.  */
    2581              : 
    2582              :   /* If new decl is `static' and an `extern' was seen previously,
    2583              :      warn about it.  */
    2584     19167558 :   warn_extern_redeclared_static (newdecl, olddecl);
    2585              : 
    2586              :   /* True to merge attributes between the declarations, false to
    2587              :      set OLDDECL's attributes to those of NEWDECL (for template
    2588              :      explicit specializations that specify their own attributes
    2589              :      independent of those specified for the primary template).  */
    2590     19167558 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2591     14717470 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2592     19717079 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2593              : 
    2594     19167558 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2595              :     {
    2596     14717470 :       if (merge_attr)
    2597              :         {
    2598     14168156 :           {
    2599     14168156 :             auto_diagnostic_group d;
    2600     14168156 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2601           36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2602              :                       ? G_("previous definition of %qD here")
    2603              :                       : G_("previous declaration of %qD here"), olddecl);
    2604     14168156 :           }
    2605              : 
    2606              :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2607              :              specify the noreturn attribute if any declaration of that function
    2608              :              specifies the noreturn attribute.  */
    2609     14168156 :           tree a;
    2610     14168156 :           if (TREE_THIS_VOLATILE (newdecl)
    2611        86893 :               && !TREE_THIS_VOLATILE (olddecl)
    2612              :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2613           76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2614           54 :               && cxx11_attribute_p (a)
    2615     14168177 :               && get_attribute_namespace (a) == NULL_TREE)
    2616              :             {
    2617            9 :               auto_diagnostic_group d;
    2618            9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2619              :                         "but its first declaration was not", newdecl);
    2620            9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2621            9 :             }
    2622              :         }
    2623              : 
    2624              :       /* Now that functions must hold information normally held
    2625              :          by field decls, there is extra work to do so that
    2626              :          declaration information does not get destroyed during
    2627              :          definition.  */
    2628     14717470 :       if (DECL_VINDEX (olddecl))
    2629       154946 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2630     14717470 :       if (DECL_CONTEXT (olddecl))
    2631     14717470 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2632     14717470 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2633     14717470 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2634     14717470 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2635     14717470 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2636     14717470 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2637     14717470 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2638     14717470 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2639     14717470 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2640     14717470 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2641     14717470 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2642     14717470 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2643      2665619 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2644      5331238 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2645     14717470 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2646              : 
    2647     14717470 :       check_redecl_contract (newdecl, olddecl);
    2648              : 
    2649              :       /* Optionally warn about more than one declaration for the same
    2650              :          name, but don't warn about a function declaration followed by a
    2651              :          definition.  */
    2652           27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2653           27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2654              :           /* Don't warn about extern decl followed by definition.  */
    2655           27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2656              :           /* Don't warn if at least one is/was hidden.  */
    2657           27 :           && !(hiding || was_hidden)
    2658              :           /* Don't warn about declaration followed by specialization.  */
    2659     14717482 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2660            9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2661              :         {
    2662            6 :           auto_diagnostic_group d;
    2663            6 :           if (warning_at (newdecl_loc,
    2664            6 :                           OPT_Wredundant_decls,
    2665              :                           "redundant redeclaration of %qD in same scope",
    2666              :                           newdecl))
    2667            6 :             inform (olddecl_loc,
    2668              :                     "previous declaration of %qD", olddecl);
    2669            6 :         }
    2670              : 
    2671              :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2672              :          first declaration of the function or, for an explicit specialization
    2673              :          of a function template, the first declaration of that
    2674              :          specialization.  */
    2675     14717470 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2676       626096 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2677              :         {
    2678     14168156 :           if (DECL_DELETED_FN (newdecl))
    2679              :             {
    2680           21 :               auto_diagnostic_group d;
    2681           21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2682              :                            "is not first declaration", newdecl))
    2683           21 :                 inform (olddecl_loc,
    2684              :                         "previous declaration of %qD", olddecl);
    2685           21 :             }
    2686     14168156 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2687     14168156 :           if (DECL_DELETED_FN (olddecl)
    2688            6 :               && DECL_INITIAL (olddecl)
    2689     14168162 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2690            3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2691              :         }
    2692              :     }
    2693              : 
    2694              :   /* Deal with C++: must preserve virtual function table size.  */
    2695     19167558 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2696              :     {
    2697        45931 :       tree newtype = TREE_TYPE (newdecl);
    2698        45931 :       tree oldtype = TREE_TYPE (olddecl);
    2699              : 
    2700        45931 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2701        91862 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2702       125751 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2703        41917 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2704              : 
    2705        45931 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2706              :     }
    2707              : 
    2708              :   /* Copy all the DECL_... slots specified in the new decl except for
    2709              :      any that we copy here from the old type.  */
    2710     19167558 :   if (merge_attr)
    2711     18618244 :     DECL_ATTRIBUTES (newdecl)
    2712     37236488 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2713              :   else
    2714       549314 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2715              : 
    2716              :   /* Transfer purviewness and importingness to the old decl.  */
    2717     19167558 :   transfer_defining_module (olddecl, newdecl);
    2718              : 
    2719     19167558 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2720              :     {
    2721      3917542 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2722      3917542 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2723      3917542 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2724              : 
    2725              :       /* The new decl should not already have gathered any
    2726              :          specializations.  */
    2727      3917542 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2728              : 
    2729              :       /* Make sure the contracts are equivalent.  */
    2730      3917542 :       check_redecl_contract (newdecl, olddecl);
    2731              : 
    2732      3917542 :       DECL_ATTRIBUTES (old_result)
    2733      3917542 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2734              : 
    2735      3917542 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2736              :         {
    2737      3917512 :           if (DECL_SOURCE_LOCATION (newdecl)
    2738      3917512 :               != DECL_SOURCE_LOCATION (olddecl))
    2739              :             {
    2740              :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2741              :                  later declarations of a function template.  */
    2742      3895459 :               check_redeclaration_no_default_args (newdecl);
    2743              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2744              :                  argument expression, that declaration... shall be the only
    2745              :                  declaration of the function or function template in the
    2746              :                  translation unit."  */
    2747      3895459 :               check_no_redeclaration_friend_default_args
    2748      3895459 :                 (old_result, new_result);
    2749              : 
    2750      3895459 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2751      3895459 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2752      3895459 :               merge_default_template_args (new_parms, old_parms,
    2753              :                                            /*class_p=*/false);
    2754              :             }
    2755      3917512 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2756      2849578 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2757              : 
    2758      3917512 :           check_default_args (newdecl);
    2759              : 
    2760      7835012 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2761      3917512 :               && DECL_INITIAL (new_result))
    2762              :             {
    2763           24 :               if (DECL_INITIAL (old_result))
    2764           12 :                 DECL_UNINLINABLE (old_result) = 1;
    2765              :               else
    2766           12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2767           24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2768           72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2769           24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2770           48 :               DECL_INTERFACE_KNOWN (old_result)
    2771           24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2772           24 :               DECL_DECLARED_INLINE_P (old_result)
    2773           24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2774           24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2775           24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2776              :             }
    2777              :           else
    2778              :             {
    2779      3917488 :               DECL_DECLARED_INLINE_P (old_result)
    2780      3917488 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2781      3917488 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2782      3917488 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2783      3917488 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2784              : 
    2785      3917488 :               merge_attribute_bits (new_result, old_result);
    2786              :             }
    2787              :         }
    2788              : 
    2789              :       /* If the new declaration is a definition, update the file and
    2790              :          line information on the declaration, and also make
    2791              :          the old declaration the same definition.  */
    2792      3917542 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2793              :         {
    2794      5301120 :           DECL_SOURCE_LOCATION (olddecl)
    2795      5301120 :             = DECL_SOURCE_LOCATION (old_result)
    2796      2650560 :             = DECL_SOURCE_LOCATION (newdecl);
    2797      2650560 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2798      2650560 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2799              :             {
    2800      2650560 :               update_contract_arguments (new_result, old_result);
    2801              : 
    2802      2650560 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2803      9526250 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2804      6875690 :                 DECL_CONTEXT (p) = old_result;
    2805              : 
    2806      5301120 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2807           18 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2808              :             }
    2809              :         }
    2810              : 
    2811      3917542 :       return olddecl;
    2812              :     }
    2813              : 
    2814     15250016 :   if (types_match)
    2815              :     {
    2816     15249815 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2817     14717269 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2818              : 
    2819              :       /* Automatically handles default parameters.  */
    2820     15249815 :       tree oldtype = TREE_TYPE (olddecl);
    2821     15249815 :       tree newtype;
    2822              : 
    2823              :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2824              :          at newdecl, which will be ggc_freed.  */
    2825     15249815 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2826              :         {
    2827              :           /* But NEWTYPE might have an attribute, honor that.  */
    2828        45931 :           tree tem = TREE_TYPE (newdecl);
    2829        45931 :           newtype = oldtype;
    2830              : 
    2831        45931 :           if (TYPE_USER_ALIGN (tem))
    2832              :             {
    2833           21 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2834            6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2835           21 :               TYPE_USER_ALIGN (newtype) = true;
    2836              :             }
    2837              : 
    2838              :           /* And remove the new type from the variants list.  */
    2839        45931 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2840              :             {
    2841           24 :               tree remove = TREE_TYPE (newdecl);
    2842           24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2843              :                 {
    2844            9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2845              :                   /* If remove is the main variant, no need to remove that
    2846              :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2847              :                      variants, e.g. created for aligned attribute, might still
    2848              :                      refer to the newdecl TYPE_DECL though, so remove that one
    2849              :                      in that case.  */
    2850            9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2851            6 :                     if (orig != remove)
    2852            6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2853            0 :                            t = TYPE_MAIN_VARIANT (t))
    2854            6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2855              :                           {
    2856           12 :                             TYPE_NEXT_VARIANT (t)
    2857            6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2858            6 :                             break;
    2859              :                           }
    2860              :                 }
    2861              :               else
    2862           15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2863            0 :                      t = TYPE_NEXT_VARIANT (t))
    2864           15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2865              :                     {
    2866           15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2867           15 :                       break;
    2868              :                     }
    2869              :             }
    2870              :         }
    2871     15203884 :       else if (merge_attr)
    2872     14654570 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2873              :       else
    2874       549314 :         newtype = TREE_TYPE (newdecl);
    2875              : 
    2876     15249815 :       if (VAR_P (newdecl))
    2877              :         {
    2878       486615 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2879              :           /* For already initialized vars, TREE_READONLY could have been
    2880              :              cleared in cp_finish_decl, because the var needs runtime
    2881              :              initialization or destruction.  Make sure not to set
    2882              :              TREE_READONLY on it again.  */
    2883       486615 :           if (DECL_INITIALIZED_P (olddecl)
    2884         1213 :               && !DECL_EXTERNAL (olddecl)
    2885       486700 :               && !TREE_READONLY (olddecl))
    2886           30 :             TREE_READONLY (newdecl) = 0;
    2887       486615 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2888       973230 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2889       486615 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2890       486615 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2891       102240 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2892       973230 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2893       486615 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2894       486615 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2895       486615 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2896       973230 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2897       486615 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2898              : 
    2899              :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2900       486615 :           if (DECL_LANG_SPECIFIC (olddecl)
    2901       969651 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2902              :             {
    2903              :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2904           41 :               retrofit_lang_decl (newdecl);
    2905           41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2906              :             }
    2907              :         }
    2908              : 
    2909              :       /* An explicit specialization of a function template or of a member
    2910              :          function of a class template can be declared transaction_safe
    2911              :          independently of whether the corresponding template entity is declared
    2912              :          transaction_safe. */
    2913         1204 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2914         1069 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2915           78 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2916           54 :           && tx_safe_fn_type_p (newtype)
    2917     15249815 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2918            0 :         newtype = tx_unsafe_fn_variant (newtype);
    2919              : 
    2920     15249815 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2921              : 
    2922     15249815 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2923     14717269 :         check_default_args (newdecl);
    2924              : 
    2925              :       /* Lay the type out, unless already done.  */
    2926     15249815 :       if (! same_type_p (newtype, oldtype)
    2927          366 :           && TREE_TYPE (newdecl) != error_mark_node
    2928     15250181 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2929          285 :         layout_type (TREE_TYPE (newdecl));
    2930              : 
    2931     15249815 :       if ((VAR_P (newdecl)
    2932     14763200 :            || TREE_CODE (newdecl) == PARM_DECL
    2933     14763200 :            || TREE_CODE (newdecl) == RESULT_DECL
    2934     14763200 :            || TREE_CODE (newdecl) == FIELD_DECL
    2935     14763200 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2936     15295746 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2937       375025 :         layout_decl (newdecl, 0);
    2938              : 
    2939              :       /* Merge deprecatedness.  */
    2940     15249815 :       if (TREE_DEPRECATED (newdecl))
    2941        11377 :         TREE_DEPRECATED (olddecl) = 1;
    2942              : 
    2943              :       /* Merge unavailability.  */
    2944     15249815 :       if (TREE_UNAVAILABLE (newdecl))
    2945            3 :         TREE_UNAVAILABLE (olddecl) = 1;
    2946              : 
    2947              :       /* Preserve function specific target and optimization options */
    2948     15249815 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2949              :         {
    2950     14717269 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2951     14717269 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2952            0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2953            0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2954              : 
    2955     14717269 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2956     14717269 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2957           55 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2958           55 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2959              : 
    2960     14717269 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2961     14206286 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2962              :         }
    2963              :       else
    2964              :         {
    2965              :           /* Merge the const type qualifier.  */
    2966       532546 :           if (TREE_READONLY (newdecl))
    2967       142114 :             TREE_READONLY (olddecl) = 1;
    2968              :           /* Merge the volatile type qualifier.  */
    2969       532546 :           if (TREE_THIS_VOLATILE (newdecl))
    2970            5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2971              :         }
    2972              : 
    2973              :       /* Merge the initialization information.  */
    2974     15249815 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2975     15249815 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2976              :         {
    2977       171163 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2978       171163 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2979       171163 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2980              :             {
    2981        10971 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2982        10971 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2983              :             }
    2984              :         }
    2985              : 
    2986     15249815 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2987              :         {
    2988     14717269 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2989     14717269 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2990     14717269 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2991     14717269 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2992        53197 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2993     14717269 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2994     14717269 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2995     14717269 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    2996     14717269 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    2997              : 
    2998     14717269 :           if (merge_attr)
    2999     14167955 :             merge_attribute_bits (newdecl, olddecl);
    3000              :           else
    3001              :             {
    3002              :               /* Merge the noreturn bit.  */
    3003       549314 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3004       549314 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3005       549314 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3006       549314 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    3007       549314 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    3008              :             }
    3009              :           /* Keep the old RTL.  */
    3010     14717269 :           COPY_DECL_RTL (olddecl, newdecl);
    3011              :         }
    3012       532546 :       else if (VAR_P (newdecl)
    3013       532546 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    3014              :         {
    3015              :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    3016              :              declaration was for an incomplete object and the new
    3017              :              declaration is not since many attributes of the RTL will
    3018              :              change.  */
    3019       486541 :           COPY_DECL_RTL (olddecl, newdecl);
    3020              :         }
    3021              :     }
    3022              :   /* If cannot merge, then use the new type and qualifiers,
    3023              :      and don't preserve the old rtl.  */
    3024              :   else
    3025              :     {
    3026              :       /* Clean out any memory we had of the old declaration.  */
    3027          201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    3028          201 :       if (oldstatic)
    3029            0 :         TREE_VALUE (oldstatic) = error_mark_node;
    3030              : 
    3031          201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    3032          201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3033          201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3034          201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3035          201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    3036              :     }
    3037              : 
    3038              :   /* Merge the storage class information.  */
    3039     15250016 :   merge_weak (newdecl, olddecl);
    3040              : 
    3041     15250016 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    3042     15250016 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3043     15250016 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    3044     15250016 :   if (! DECL_EXTERNAL (olddecl))
    3045        50569 :     DECL_EXTERNAL (newdecl) = 0;
    3046     15250016 :   if (! DECL_COMDAT (olddecl))
    3047      6507187 :     DECL_COMDAT (newdecl) = 0;
    3048              : 
    3049     15250016 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    3050              :     {
    3051           78 :       if (!DECL_LOCAL_DECL_P (olddecl))
    3052              :         /* This can happen if olddecl was brought in from the
    3053              :            enclosing namespace via a using-decl.  The new decl is
    3054              :            then not a block-scope extern at all.  */
    3055            3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    3056              :       else
    3057              :         {
    3058           75 :           retrofit_lang_decl (newdecl);
    3059           75 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    3060           75 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    3061           75 :           if (alias != error_mark_node)
    3062              :             {
    3063           72 :               DECL_ATTRIBUTES (alias)
    3064           72 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    3065           72 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3066           42 :                 merge_attribute_bits (newdecl, alias);
    3067              :             }
    3068              :         }
    3069              :     }
    3070              : 
    3071     15250016 :   new_template_info = NULL_TREE;
    3072     15250016 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    3073              :     {
    3074     15200524 :       bool new_redefines_gnu_inline = false;
    3075              : 
    3076     15200524 :       if (new_defines_function
    3077     15200524 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    3078         1226 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    3079      8941291 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    3080            0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    3081              :                       == FUNCTION_DECL))))
    3082         2452 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    3083              : 
    3084              :       if (!new_redefines_gnu_inline)
    3085              :         {
    3086     15200446 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    3087     15200446 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    3088     15200446 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    3089              :         }
    3090              : 
    3091     15200524 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    3092              :         {
    3093     15200460 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    3094     15200460 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    3095     15200460 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    3096              : 
    3097              :           /* If the OLDDECL is an instantiation and/or specialization,
    3098              :              then the NEWDECL must be too.  But, it may not yet be marked
    3099              :              as such if the caller has created NEWDECL, but has not yet
    3100              :              figured out that it is a redeclaration.  */
    3101     15200460 :           if (!DECL_USE_TEMPLATE (newdecl))
    3102     14574148 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    3103              : 
    3104     15200460 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3105     14650920 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    3106     29301840 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    3107              :         }
    3108              : 
    3109              :       /* Don't really know how much of the language-specific
    3110              :          values we should copy from old to new.  */
    3111     15200524 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    3112              : 
    3113     15200524 :       if (LANG_DECL_HAS_MIN (newdecl))
    3114              :         {
    3115     15200524 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    3116     15200524 :           if (DECL_TEMPLATE_INFO (newdecl))
    3117              :             {
    3118       626345 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    3119       626345 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3120       626345 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3121              :                 /* Remember the presence of explicit specialization args.  */
    3122      1098634 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    3123      1098634 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    3124              :             }
    3125              : 
    3126              :           /* We don't want to copy template info from a non-templated friend
    3127              :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    3128     15200524 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    3129              :                                || !non_templated_friend_p (olddecl));
    3130     15200524 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    3131              :         }
    3132              : 
    3133     15200524 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    3134              :         {
    3135              :           /* Only functions have these fields.  */
    3136     14717470 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    3137     14717470 :           DECL_BEFRIENDING_CLASSES (newdecl)
    3138     14717470 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    3139     14717470 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    3140              :           /* DECL_THUNKS is only valid for virtual functions,
    3141              :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    3142     14717470 :           if (DECL_VIRTUAL_P (newdecl))
    3143       615978 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    3144     28202984 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    3145       367899 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    3146              :         }
    3147       483054 :       else if (VAR_P (newdecl))
    3148              :         {
    3149              :           /* Only variables have this field.  */
    3150       482990 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    3151          194 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    3152              :         }
    3153              :     }
    3154              : 
    3155     15250016 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3156              :     {
    3157     14717470 :       merge_decl_arguments (newdecl, olddecl, new_defines_function,
    3158              :                             types_match, false);
    3159              : 
    3160     14717470 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3161     14717470 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    3162              :         {
    3163              :           /* If newdecl is not a specialization, then it is not a
    3164              :              template-related function at all.  And that means that we
    3165              :              should have exited above, returning 0.  */
    3166       549314 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    3167              : 
    3168       549314 :           if (DECL_ODR_USED (olddecl))
    3169              :             /* From [temp.expl.spec]:
    3170              : 
    3171              :                If a template, a member template or the member of a class
    3172              :                template is explicitly specialized then that
    3173              :                specialization shall be declared before the first use of
    3174              :                that specialization that would cause an implicit
    3175              :                instantiation to take place, in every translation unit in
    3176              :                which such a use occurs.  */
    3177            0 :             error ("explicit specialization of %qD after first use",
    3178              :                       olddecl);
    3179              : 
    3180       549314 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    3181       549314 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    3182      1098475 :                                    && DECL_NONGNU_INLINE_P (newdecl));
    3183              : 
    3184              :           /* Don't propagate visibility from the template to the
    3185              :              specialization here.  We'll do that in determine_visibility if
    3186              :              appropriate.  */
    3187       549314 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    3188              : 
    3189              :           /* [temp.expl.spec/14] We don't inline explicit specialization
    3190              :              just because the primary template says so.  */
    3191       549314 :           gcc_assert (!merge_attr);
    3192              : 
    3193       549314 :           DECL_DECLARED_INLINE_P (olddecl)
    3194       549314 :             = DECL_DECLARED_INLINE_P (newdecl);
    3195              : 
    3196       549314 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3197       549314 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    3198              : 
    3199       549314 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    3200              :         }
    3201     14168156 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    3202              :         {
    3203              :           /* Never inline re-defined extern inline functions.
    3204              :              FIXME: this could be better handled by keeping both
    3205              :              function as separate declarations.  */
    3206           78 :           DECL_UNINLINABLE (newdecl) = 1;
    3207              :         }
    3208              :       else
    3209              :         {
    3210     14168078 :           if (DECL_PENDING_INLINE_P (olddecl))
    3211              :             {
    3212            6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    3213            6 :               DECL_PENDING_INLINE_INFO (newdecl)
    3214           12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    3215              :             }
    3216     14168072 :           else if (DECL_PENDING_INLINE_P (newdecl))
    3217              :             ;
    3218     14168072 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    3219     14168072 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    3220     28336144 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    3221              : 
    3222     14168078 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    3223              : 
    3224     42504234 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3225     28336156 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3226              : 
    3227     28336156 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3228     14168078 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3229     14168078 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3230     27941392 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3231              :         }
    3232              : 
    3233              :       /* Preserve abstractness on cloned [cd]tors.  */
    3234     14717470 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3235              : 
    3236              :       /* Update newdecl's parms to point at olddecl.  */
    3237     46793689 :       for (tree parm = DECL_ARGUMENTS (newdecl); parm;
    3238     32076219 :            parm = DECL_CHAIN (parm))
    3239     32076219 :         DECL_CONTEXT (parm) = olddecl;
    3240              : 
    3241     14717470 :       if (! types_match)
    3242              :         {
    3243          201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3244          201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3245          201 :           COPY_DECL_RTL (newdecl, olddecl);
    3246              :         }
    3247     14717470 :       if (! types_match || new_defines_function)
    3248              :         {
    3249              :           /* Update the contracts to reflect the new parameter names. */
    3250      8942718 :           update_contract_arguments (newdecl, olddecl);
    3251              : 
    3252              :           /* Mark the old PARM_DECLs in case std::meta::parameters_of has
    3253              :              been called on the old declaration and reflections of those
    3254              :              arguments are held across this point and used later.
    3255              :              Such PARM_DECLs are no longer present in
    3256              :              DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain.  */
    3257      8942718 :           for (tree oldarg = DECL_ARGUMENTS (olddecl);
    3258     31349011 :                oldarg; oldarg = DECL_CHAIN (oldarg))
    3259     22406293 :             OLD_PARM_DECL_P (oldarg) = 1;
    3260              : 
    3261              :           /* These need to be copied so that the names are available.
    3262              :              Note that if the types do match, we'll preserve inline
    3263              :              info and other bits, but if not, we won't.  */
    3264      8942718 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3265      8942718 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3266              :         }
    3267              :       /* If redeclaring a builtin function, it stays built in
    3268              :          if newdecl is a gnu_inline definition, or if newdecl is just
    3269              :          a declaration.  */
    3270     14717470 :       if (fndecl_built_in_p (olddecl)
    3271     14773159 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3272              :         {
    3273      3878269 :           copy_decl_built_in_function (newdecl, olddecl);
    3274              :           /* If we're keeping the built-in definition, keep the rtl,
    3275              :              regardless of declaration matches.  */
    3276      3878269 :           COPY_DECL_RTL (olddecl, newdecl);
    3277      3878269 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3278              :             {
    3279      3878263 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3280      3878263 :               if (builtin_decl_explicit_p (fncode))
    3281              :                 {
    3282              :                   /* A compatible prototype of these builtin functions
    3283              :                      is seen, assume the runtime implements it with
    3284              :                      the expected semantics.  */
    3285      3878263 :                   switch (fncode)
    3286              :                     {
    3287         9737 :                     case BUILT_IN_STPCPY:
    3288         9737 :                       set_builtin_decl_implicit_p (fncode, true);
    3289         9737 :                       break;
    3290      3868526 :                     default:
    3291      3868526 :                       set_builtin_decl_declared_p (fncode, true);
    3292      3868526 :                       break;
    3293              :                     }
    3294              :                 }
    3295              : 
    3296      3878263 :               copy_attributes_to_builtin (newdecl);
    3297              :             }
    3298              :         }
    3299     14717470 :       if (new_defines_function)
    3300              :         /* If defining a function declared with other language
    3301              :            linkage, use the previously declared language linkage.  */
    3302      8942517 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3303      5774953 :       else if (types_match)
    3304              :         {
    3305      5774752 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3306              :           /* Don't clear out the arguments if we're just redeclaring a
    3307              :              function.  */
    3308      5774752 :           if (DECL_ARGUMENTS (olddecl))
    3309      1865576 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3310              :         }
    3311              :     }
    3312       532546 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3313            0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3314              : 
    3315              :   /* Now preserve various other info from the definition.  */
    3316     15250016 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3317     15250016 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3318     15250016 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3319     15250016 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3320              : 
    3321              :   /* Warn about conflicting visibility specifications.  */
    3322     15250016 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3323      5364586 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3324     15261579 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3325              :     {
    3326           12 :       auto_diagnostic_group d;
    3327           12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3328              :                       "%qD: visibility attribute ignored because it "
    3329              :                       "conflicts with previous declaration", newdecl))
    3330           12 :         inform (olddecl_loc,
    3331              :                 "previous declaration of %qD", olddecl);
    3332           12 :     }
    3333              :   /* Choose the declaration which specified visibility.  */
    3334     15250016 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3335              :     {
    3336      5364586 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3337      5364586 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3338              :     }
    3339              :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3340              :      so keep this behavior.  */
    3341     15250016 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3342              :     {
    3343           10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3344           10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3345              :     }
    3346              :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3347     15250016 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3348              :     {
    3349           54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3350           54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3351              :     }
    3352     15249962 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3353     15249962 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3354            3 :     DECL_USER_ALIGN (newdecl) = 1;
    3355              : 
    3356     15250016 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3357     30500032 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3358     15250016 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3359            0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3360              :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3361     15250016 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3362            0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3363              : 
    3364              :   /* Merge module entity mapping information.  */
    3365     15250016 :   if (DECL_LANG_SPECIFIC (olddecl)
    3366     30450586 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3367     15200292 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3368              :     {
    3369          278 :       retrofit_lang_decl (newdecl);
    3370          278 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3371          278 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3372              :     }
    3373              : 
    3374              :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3375              :      with that from NEWDECL below.  */
    3376     15250016 :   if (DECL_LANG_SPECIFIC (olddecl))
    3377              :     {
    3378     15200570 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3379              :                            != DECL_LANG_SPECIFIC (newdecl));
    3380     15200570 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3381              :     }
    3382              : 
    3383              :   /* Merge the USED information.  */
    3384     15250016 :   if (TREE_USED (olddecl))
    3385       478273 :     TREE_USED (newdecl) = 1;
    3386     14771743 :   else if (TREE_USED (newdecl))
    3387           54 :     TREE_USED (olddecl) = 1;
    3388              : 
    3389     15250016 :   if (VAR_P (newdecl))
    3390              :     {
    3391       486615 :       if (DECL_READ_P (olddecl))
    3392        41734 :         DECL_READ_P (newdecl) = 1;
    3393       444881 :       else if (DECL_READ_P (newdecl))
    3394            3 :         DECL_READ_P (olddecl) = 1;
    3395              :     }
    3396              : 
    3397     15250016 :   if (DECL_PRESERVE_P (olddecl))
    3398           48 :     DECL_PRESERVE_P (newdecl) = 1;
    3399     15249968 :   else if (DECL_PRESERVE_P (newdecl))
    3400           63 :     DECL_PRESERVE_P (olddecl) = 1;
    3401              : 
    3402              :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3403              :      to olddecl and deleted.  */
    3404     15250016 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3405     29967486 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3406              :     {
    3407              :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3408          258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3409              :       /* newdecl will be purged after copying to olddecl and is no longer
    3410              :          a version.  */
    3411          258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3412              :     }
    3413              : 
    3414     15250016 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3415              :     {
    3416     14717470 :       int function_size;
    3417     14717470 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3418              : 
    3419     14717470 :       function_size = sizeof (struct tree_decl_common);
    3420              : 
    3421     14717470 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3422              :               (char *) newdecl + sizeof (struct tree_common),
    3423              :               function_size - sizeof (struct tree_common));
    3424              : 
    3425     14717470 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3426              :               (char *) newdecl + sizeof (struct tree_decl_common),
    3427              :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3428              : 
    3429              :       /* Preserve symtab node mapping.  */
    3430     14717470 :       olddecl->decl_with_vis.symtab_node = snode;
    3431              : 
    3432     14717470 :       if (new_template_info)
    3433              :         /* If newdecl is a template instantiation, it is possible that
    3434              :            the following sequence of events has occurred:
    3435              : 
    3436              :            o A friend function was declared in a class template.  The
    3437              :            class template was instantiated.
    3438              : 
    3439              :            o The instantiation of the friend declaration was
    3440              :            recorded on the instantiation list, and is newdecl.
    3441              : 
    3442              :            o Later, however, instantiate_class_template called pushdecl
    3443              :            on the newdecl to perform name injection.  But, pushdecl in
    3444              :            turn called duplicate_decls when it discovered that another
    3445              :            declaration of a global function with the same name already
    3446              :            existed.
    3447              : 
    3448              :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3449              : 
    3450              :            If we're going to do that, we'd better make sure that
    3451              :            olddecl, and not newdecl, is on the list of
    3452              :            instantiations so that if we try to do the instantiation
    3453              :            again we won't get the clobbered declaration.  */
    3454       626336 :         reregister_specialization (newdecl,
    3455              :                                    new_template_info,
    3456              :                                    olddecl);
    3457              :     }
    3458              :   else
    3459              :     {
    3460       532546 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3461              : 
    3462       532546 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3463              :               (char *) newdecl + sizeof (struct tree_common),
    3464              :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3465              : 
    3466       532546 :       switch (TREE_CODE (newdecl))
    3467              :         {
    3468       532546 :         case LABEL_DECL:
    3469       532546 :         case VAR_DECL:
    3470       532546 :         case RESULT_DECL:
    3471       532546 :         case PARM_DECL:
    3472       532546 :         case FIELD_DECL:
    3473       532546 :         case TYPE_DECL:
    3474       532546 :         case CONST_DECL:
    3475       532546 :           {
    3476       532546 :             struct symtab_node *snode = NULL;
    3477              : 
    3478       532546 :             if (VAR_P (newdecl)
    3479       532546 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3480            3 :                     || DECL_EXTERNAL (olddecl)))
    3481       486615 :               snode = symtab_node::get (olddecl);
    3482       532546 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3483              :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3484              :                     size - sizeof (struct tree_decl_common)
    3485       532546 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3486       532546 :             if (VAR_P (newdecl))
    3487       486615 :               olddecl->decl_with_vis.symtab_node = snode;
    3488              :           }
    3489              :           break;
    3490            0 :         default:
    3491            0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3492              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3493              :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3494            0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3495            0 :           break;
    3496              :         }
    3497              :     }
    3498              : 
    3499     15250016 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3500              :     {
    3501     15204085 :       if (DECL_EXTERNAL (olddecl)
    3502       487985 :           || TREE_PUBLIC (olddecl)
    3503     15204154 :           || TREE_STATIC (olddecl))
    3504              :         {
    3505              :           /* Merge the section attribute.
    3506              :              We want to issue an error if the sections conflict but that must be
    3507              :              done later in decl_attributes since we are called before attributes
    3508              :              are assigned.  */
    3509     15204085 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3510            7 :             set_decl_section_name (olddecl, newdecl);
    3511              : 
    3512     15204085 :           if (DECL_ONE_ONLY (newdecl))
    3513              :             {
    3514            0 :               struct symtab_node *oldsym, *newsym;
    3515            0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3516            0 :                 oldsym = cgraph_node::get_create (olddecl);
    3517              :               else
    3518            0 :                 oldsym = varpool_node::get_create (olddecl);
    3519            0 :               newsym = symtab_node::get (newdecl);
    3520            0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3521              :             }
    3522              :         }
    3523              : 
    3524     15204085 :       if (VAR_P (newdecl)
    3525     15204085 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3526              :         {
    3527          404 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3528          404 :           if (!processing_template_decl)
    3529          371 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3530              :         }
    3531              :     }
    3532              : 
    3533     15250016 :   DECL_UID (olddecl) = olddecl_uid;
    3534              : 
    3535              :   /* NEWDECL contains the merged attribute lists.
    3536              :      Update OLDDECL to be the same.  */
    3537     15250016 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3538              : 
    3539              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3540              :     so that encode_section_info has a chance to look at the new decl
    3541              :     flags and attributes.  */
    3542     15250016 :   if (DECL_RTL_SET_P (olddecl)
    3543     15250016 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3544            0 :           || (VAR_P (olddecl)
    3545            0 :               && TREE_STATIC (olddecl))))
    3546            0 :     make_decl_rtl (olddecl);
    3547              : 
    3548              :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3549              :      declaration of a member results in a call to duplicate_decls,
    3550              :      freeing these nodes represents in a significant savings.
    3551              : 
    3552              :      Before releasing the node, be sore to remove function from symbol
    3553              :      table that might have been inserted there to record comdat group.
    3554              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3555              :      structure is shared in between newdecl and oldecl.  */
    3556     15250016 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3557     14717470 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3558     15250016 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3559              :     {
    3560     15204085 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3561     15204085 :       if (snode)
    3562          399 :         snode->remove ();
    3563              :     }
    3564              : 
    3565     15250016 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3566              :     {
    3567     14717470 :       tree clone;
    3568     15241252 :       FOR_EACH_CLONE (clone, olddecl)
    3569              :         {
    3570       523782 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3571       523782 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3572              :         }
    3573              :     }
    3574              : 
    3575              :   /* Remove the associated constraints for newdecl, if any, before
    3576              :      reclaiming memory. */
    3577     15250016 :   if (flag_concepts)
    3578     14983114 :     remove_constraints (newdecl);
    3579              : 
    3580     15250016 :   if (flag_contracts)
    3581              :     /* Remove the specifiers, and then remove the decl from the lookup.  */
    3582         5215 :     remove_decl_with_fn_contracts_specifiers (newdecl);
    3583              : 
    3584              :   /* And similarly for any module tracking data.  */
    3585     15250016 :   if (modules_p ())
    3586        31850 :     remove_defining_module (newdecl);
    3587              : 
    3588     15250016 :   ggc_free (newdecl);
    3589              : 
    3590     15250016 :   return olddecl;
    3591              : }
    3592              : 
    3593              : /* Return zero if the declaration NEWDECL is valid
    3594              :    when the declaration OLDDECL (assumed to be for the same name)
    3595              :    has already been seen.
    3596              :    Otherwise return an error message format string with a %s
    3597              :    where the identifier should go.  */
    3598              : 
    3599              : static const char *
    3600     15407322 : redeclaration_error_message (tree newdecl, tree olddecl)
    3601              : {
    3602     15407358 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3603              :     {
    3604              :       /* Because C++ can put things into name space for free,
    3605              :          constructs like "typedef struct foo { ... } foo"
    3606              :          would look like an erroneous redeclaration.  */
    3607        77083 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3608              :         return NULL;
    3609              :       else
    3610              :         return G_("redefinition of %q#D");
    3611              :     }
    3612     15330275 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3613              :     {
    3614              :       /* If this is a pure function, its olddecl will actually be
    3615              :          the original initialization to `0' (which we force to call
    3616              :          abort()).  Don't complain about redefinition in this case.  */
    3617     21851434 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3618     10925735 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3619              :         return NULL;
    3620              : 
    3621              :       /* If both functions come from different namespaces, this is not
    3622              :          a redeclaration - this is a conflict with a used function.  */
    3623     21851404 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3624      2555884 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3625     10925705 :           && ! decls_match (olddecl, newdecl))
    3626              :         return G_("%qD conflicts with used function");
    3627              : 
    3628              :       /* We'll complain about linkage mismatches in
    3629              :          warn_extern_redeclared_static.  */
    3630              : 
    3631              :       /* Defining the same name twice is no good.  */
    3632     10925702 :       if (decl_defined_p (olddecl)
    3633     10925702 :           && decl_defined_p (newdecl))
    3634              :         {
    3635          303 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3636              :             return G_("%q#D not declared in class");
    3637          444 :           else if (!GNU_INLINE_P (olddecl)
    3638          390 :                    || GNU_INLINE_P (newdecl))
    3639          219 :             return G_("redefinition of %q#D");
    3640              :         }
    3641              : 
    3642     12608255 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3643              :         {
    3644      1638461 :           bool olda = GNU_INLINE_P (olddecl);
    3645      1638461 :           bool newa = GNU_INLINE_P (newdecl);
    3646              : 
    3647      1638461 :           if (olda != newa)
    3648              :             {
    3649           15 :               if (newa)
    3650              :                 return G_("%q+D redeclared inline with "
    3651              :                           "%<gnu_inline%> attribute");
    3652              :               else
    3653              :                 return G_("%q+D redeclared inline without "
    3654              :                           "%<gnu_inline%> attribute");
    3655              :             }
    3656              :         }
    3657              : 
    3658              :       /* [class.compare.default]: A definition of a comparison operator as
    3659              :          defaulted that appears in a class shall be the first declaration of
    3660              :          that function.  */
    3661     10925468 :       special_function_kind sfk = special_function_p (olddecl);
    3662     10925468 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3663              :         return G_("comparison operator %q+D defaulted after "
    3664              :                   "its first declaration");
    3665              : 
    3666     10925465 :       check_abi_tag_redeclaration
    3667     10925465 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3668     10925465 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3669              : 
    3670     10925465 :       return NULL;
    3671              :     }
    3672      4404558 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3673              :     {
    3674      3917581 :       tree nt, ot;
    3675              : 
    3676      3917581 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3677              :         return G_("redefinition of %q#D");
    3678              : 
    3679      3917575 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3680           36 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3681           36 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3682              : 
    3683      3917539 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3684              :         return NULL;
    3685              : 
    3686      3917527 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3687      3917527 :       if (DECL_TEMPLATE_INFO (nt))
    3688       949255 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3689      3917527 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3690      3917527 :       if (DECL_TEMPLATE_INFO (ot))
    3691      3917527 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3692      6568141 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3693      3917566 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3694           15 :         return G_("redefinition of %q#D");
    3695              : 
    3696      6350197 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3697              :         {
    3698      1729882 :           bool olda = GNU_INLINE_P (ot);
    3699      1729882 :           bool newa = GNU_INLINE_P (nt);
    3700              : 
    3701      1729882 :           if (olda != newa)
    3702              :             {
    3703            0 :               if (newa)
    3704              :                 return G_("%q+D redeclared inline with "
    3705              :                           "%<gnu_inline%> attribute");
    3706              :               else
    3707              :                 return G_("%q+D redeclared inline without "
    3708              :                           "%<gnu_inline%> attribute");
    3709              :             }
    3710              :         }
    3711              : 
    3712              :       /* Core issue #226 (C++11):
    3713              : 
    3714              :            If a friend function template declaration specifies a
    3715              :            default template-argument, that declaration shall be a
    3716              :            definition and shall be the only declaration of the
    3717              :            function template in the translation unit.  */
    3718      3917512 :       if ((cxx_dialect != cxx98)
    3719      3900125 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3720      4119387 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3721              :                                        /*is_primary=*/true,
    3722              :                                        /*is_partial=*/false,
    3723              :                                        /*is_friend_decl=*/2))
    3724              :         return G_("redeclaration of friend %q#D "
    3725              :                   "may not have default template arguments");
    3726              : 
    3727      3917509 :       return NULL;
    3728              :     }
    3729       486977 :   else if (VAR_P (newdecl)
    3730       486893 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3731       486893 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3732       487024 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3733           44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3734           41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3735              :     {
    3736              :       /* Only variables can be thread-local, and all declarations must
    3737              :          agree on this property.  */
    3738            6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3739              :         return G_("thread-local declaration of %q#D follows "
    3740              :                   "non-thread-local declaration");
    3741              :       else
    3742            3 :         return G_("non-thread-local declaration of %q#D follows "
    3743              :                   "thread-local declaration");
    3744              :     }
    3745       486971 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3746              :     {
    3747              :       /* The objects have been declared at namespace scope.  If either
    3748              :          is a member of an anonymous union, then this is an invalid
    3749              :          redeclaration.  For example:
    3750              : 
    3751              :            int i;
    3752              :            union { int i; };
    3753              : 
    3754              :            is invalid.  */
    3755       486742 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3756       973553 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3757              :         return G_("redeclaration of %q#D");
    3758              :       /* If at least one declaration is a reference, there is no
    3759              :          conflict.  For example:
    3760              : 
    3761              :            int i = 3;
    3762              :            extern int i;
    3763              : 
    3764              :          is valid.  */
    3765       486808 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3766              :         return NULL;
    3767              : 
    3768              :       /* Static data member declared outside a class definition
    3769              :          if the variable is defined within the class with constexpr
    3770              :          specifier is declaration rather than definition (and
    3771              :          deprecated).  */
    3772         2824 :       if (cxx_dialect >= cxx17
    3773         2749 :           && VAR_P (olddecl)
    3774         2693 :           && DECL_CLASS_SCOPE_P (olddecl)
    3775         2649 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3776         5461 :           && !DECL_INITIAL (newdecl))
    3777              :         {
    3778         2637 :           DECL_EXTERNAL (newdecl) = 1;
    3779              :           /* For now, only warn with explicit -Wdeprecated.  */
    3780         2637 :           if (OPTION_SET_P (warn_deprecated))
    3781              :             {
    3782           40 :               auto_diagnostic_group d;
    3783           40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3784              :                                 "redundant redeclaration of %<constexpr%> "
    3785              :                                 "static data member %qD", newdecl))
    3786            4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3787              :                           "previous declaration of %qD", olddecl);
    3788           40 :             }
    3789         2637 :           return NULL;
    3790              :         }
    3791              : 
    3792              :       /* Reject two definitions.  */
    3793              :       return G_("redefinition of %q#D");
    3794              :     }
    3795              :   else
    3796              :     {
    3797              :       /* Objects declared with block scope:  */
    3798              :       /* Reject two definitions, and reject a definition
    3799              :          together with an external reference.  */
    3800          148 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3801              :         return G_("redeclaration of %q#D");
    3802              :       return NULL;
    3803              :     }
    3804              : }
    3805              : 
    3806              : 
    3807              : /* Hash and equality functions for the named_label table.  */
    3808              : 
    3809              : hashval_t
    3810        77707 : named_label_hash::hash (const value_type entry)
    3811              : {
    3812        77707 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3813              : }
    3814              : 
    3815              : bool
    3816        74813 : named_label_hash::equal (const value_type entry, compare_type name)
    3817              : {
    3818        74813 :   return name == entry->name;
    3819              : }
    3820              : 
    3821              : /* Look for a label named ID in the current function.  If one cannot
    3822              :    be found, create one.  Return the named_label_entry, or NULL on
    3823              :    failure.  */
    3824              : 
    3825              : static named_label_entry *
    3826        23907 : lookup_label_1 (tree id, bool making_local_p)
    3827              : {
    3828        23907 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3829              : 
    3830              :   /* You can't use labels at global scope.  */
    3831        23907 :   if (current_function_decl == NULL_TREE)
    3832              :     {
    3833            3 :       error ("label %qE referenced outside of any function", id);
    3834            3 :       return NULL;
    3835              :     }
    3836              : 
    3837        23904 :   if (!named_labels)
    3838         4614 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3839              : 
    3840        23904 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3841        23904 :   named_label_entry **slot
    3842        23904 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3843        23904 :   named_label_entry *old = *slot;
    3844              : 
    3845        23904 :   if (old && old->label_decl)
    3846              :     {
    3847         3458 :       if (!making_local_p)
    3848              :         return old;
    3849              : 
    3850           21 :       if (old->binding_level == current_binding_level)
    3851              :         {
    3852            0 :           auto_diagnostic_group d;
    3853            0 :           error ("local label %qE conflicts with existing label", id);
    3854            0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3855            0 :           return NULL;
    3856            0 :         }
    3857              :     }
    3858              : 
    3859              :   /* We are making a new decl, create or reuse the named_label_entry  */
    3860        20488 :   named_label_entry *ent = NULL;
    3861           33 :   if (old && !old->label_decl)
    3862              :     ent = old;
    3863              :   else
    3864              :     {
    3865        20455 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3866        20455 :       ent->name = id;
    3867        20455 :       ent->outer = old;
    3868        20455 :       *slot = ent;
    3869              :     }
    3870              : 
    3871              :   /* Now create the LABEL_DECL.  */
    3872        20467 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3873              : 
    3874        20467 :   DECL_CONTEXT (decl) = current_function_decl;
    3875        20467 :   SET_DECL_MODE (decl, VOIDmode);
    3876        20467 :   if (making_local_p)
    3877              :     {
    3878          219 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3879          219 :       DECL_CHAIN (decl) = current_binding_level->names;
    3880          219 :       current_binding_level->names = decl;
    3881              :     }
    3882              : 
    3883        20467 :   ent->label_decl = decl;
    3884              : 
    3885        20467 :   return ent;
    3886        23907 : }
    3887              : 
    3888              : /* Wrapper for lookup_label_1.  */
    3889              : 
    3890              : tree
    3891         2952 : lookup_label (tree id)
    3892              : {
    3893         2952 :   named_label_entry *ent = lookup_label_1 (id, false);
    3894         2952 :   return ent ? ent->label_decl : NULL_TREE;
    3895              : }
    3896              : 
    3897              : /* Remember that we've seen &&ID.  */
    3898              : 
    3899              : void
    3900          253 : mark_label_addressed (tree id)
    3901              : {
    3902          253 :   named_label_entry *ent = lookup_label_1 (id, false);
    3903          253 :   ent->addressed = true;
    3904          253 : }
    3905              : 
    3906              : tree
    3907          219 : declare_local_label (tree id)
    3908              : {
    3909          219 :   named_label_entry *ent = lookup_label_1 (id, true);
    3910          219 :   return ent ? ent->label_decl : NULL_TREE;
    3911              : }
    3912              : 
    3913              : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3914              : 
    3915              : static bool
    3916        85057 : decl_jump_unsafe (tree decl)
    3917              : {
    3918              :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3919              :      with automatic storage duration is not in scope to a point where it is
    3920              :      in scope is ill-formed unless the variable has scalar type, class type
    3921              :      with a trivial default constructor and a trivial destructor, a
    3922              :      cv-qualified version of one of these types, or an array of one of the
    3923              :      preceding types and is declared without an initializer (8.5).  */
    3924        85057 :   tree type = TREE_TYPE (decl);
    3925              : 
    3926        85057 :   return (type != error_mark_node
    3927        85039 :           && VAR_P (decl)
    3928        15025 :           && !TREE_STATIC (decl)
    3929        99946 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3930        12975 :               || variably_modified_type_p (type, NULL_TREE)));
    3931              : }
    3932              : 
    3933              : /* Returns true if decl is an automatic variable with vacuous initialization
    3934              :    except when it is [[indeterminate]] or [[gnu::uninitialized]].
    3935              :    Jumps across such initialization need to be instrumented for
    3936              :    !!flag_auto_var_init.  */
    3937              : 
    3938              : static bool
    3939        83134 : decl_instrument_init_bypass_p (tree decl)
    3940              : {
    3941        83134 :   tree type = TREE_TYPE (decl);
    3942              : 
    3943        83134 :   return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    3944         5920 :           && !processing_template_decl
    3945         5674 :           && type != error_mark_node
    3946         5668 :           && VAR_P (decl)
    3947         1053 :           && !TREE_STATIC (decl)
    3948         1032 :           && !DECL_EXTERNAL (decl)
    3949         2036 :           && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3950         1018 :                || variably_modified_type_p (type, NULL_TREE))
    3951         1018 :           && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
    3952         1018 :           && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
    3953        84152 :           && !DECL_HAS_VALUE_EXPR_P (decl));
    3954              : }
    3955              : 
    3956              : /* Build .DEFERRED_INIT call for DECL.  */
    3957              : 
    3958              : static tree
    3959          133 : build_deferred_init_call (tree decl)
    3960              : {
    3961          133 :   tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    3962          266 :   tree init_type_arg = build_int_cst (integer_type_node,
    3963          133 :                                       (int) flag_auto_var_init);
    3964          133 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    3965          133 :   tree decl_name;
    3966              : 
    3967          133 :   if (DECL_NAME (decl))
    3968          133 :     decl_name = build_string_literal (DECL_NAME (decl));
    3969              :   else
    3970              :     {
    3971            0 :       char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
    3972            0 :       sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
    3973            0 :       decl_name = build_string_literal (decl_name_anonymous);
    3974              :     }
    3975              : 
    3976          133 :   tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
    3977          133 :                                             TREE_TYPE (decl), 3,
    3978              :                                             decl_size_arg, init_type_arg,
    3979              :                                             decl_name);
    3980          133 :   tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
    3981          133 :   return build_stmt (loc, EXPR_STMT, ret);
    3982              : }
    3983              : 
    3984              : /* Emit before ITER (and any labels/case labels before it) code like
    3985              :    if (0)
    3986              :      {
    3987              :        l1:
    3988              :         v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
    3989              :         v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
    3990              :         v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
    3991              :         v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
    3992              :      }
    3993              :    and return l1 label, or if it already exists, assert it has the
    3994              :    .DEFERRED_INIT calls for the right decls in the right order and
    3995              :    amend it, either by adding extra labels in between or further
    3996              :    ,DEFERRED_INIT calls before the first label and extra label before
    3997              :    that.  If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
    3998              :    of adding a label.  DECLS points to an array of NDECLS VAR_DECLs
    3999              :    which should be initialized.  */
    4000              : 
    4001              : static tree
    4002          121 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
    4003              :                                tree *decls, unsigned ndecls)
    4004              : {
    4005          121 :   tree lab = NULL_TREE;
    4006          185 :   for (; !tsi_end_p (iter); tsi_prev (&iter))
    4007              :     {
    4008          179 :       switch (TREE_CODE (tsi_stmt (iter)))
    4009              :         {
    4010           64 :         case LABEL_EXPR:
    4011           64 :         case CASE_LABEL_EXPR:
    4012           64 :         case DEBUG_BEGIN_STMT:
    4013           64 :           continue;
    4014              :         default:
    4015              :           break;
    4016              :         }
    4017              :       break;
    4018              :     }
    4019          121 :   if (!tsi_end_p (iter)
    4020          115 :       && TREE_CODE (tsi_stmt (iter)) == IF_STMT
    4021          197 :       && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
    4022              :     {
    4023              :       /* Found IF_STMT added for this or some adjacent
    4024              :          LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
    4025              :          The decls are ordered so that we can always reuse it.  Sometimes
    4026              :          by no modifications at all and just returning the right label
    4027              :          which was added already before, sometimes by adding a label in
    4028              :          between two previously added .DEFERRED_INIT calls and sometimes
    4029              :          by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
    4030              :          before that) before the statements in IF_STMT body.  */
    4031           70 :       tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
    4032           70 :       iter = tsi_last (then_clause);
    4033           70 :       bool add = false;
    4034          378 :       for (unsigned int i = 0; i < ndecls; ++i)
    4035              :         {
    4036          308 :           tree decl = decls[i];
    4037          308 :           if (!add)
    4038              :             {
    4039              :               /* Skip over labels/case labels after .DEFERRED_INIT for the
    4040              :                  DECL we are looking for.  */
    4041          396 :               while (!tsi_end_p (iter)
    4042          396 :                      && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
    4043          284 :                          || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
    4044           25 :                              && !case_label)))
    4045          118 :                 tsi_prev (&iter);
    4046          278 :               if (tsi_end_p (iter))
    4047              :                 {
    4048              :                   /* Reached the start, we'll need to prepend further
    4049              :                      statements.  */
    4050           19 :                   add = true;
    4051           19 :                   iter = tsi_start (then_clause);
    4052              :                 }
    4053              :               else
    4054              :                 {
    4055              :                   /* Found something, assert it is .DEFERRED_INIT for
    4056              :                      DECL.  */
    4057          259 :                   tree t = tsi_stmt (iter);
    4058          259 :                   gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
    4059          259 :                   t = EXPR_STMT_EXPR (t);
    4060          259 :                   gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
    4061              :                                        && TREE_OPERAND (t, 0) == decl
    4062              :                                        && (TREE_CODE (TREE_OPERAND (t, 1))
    4063              :                                            == CALL_EXPR));
    4064          259 :                   t = TREE_OPERAND (t, 1);
    4065          259 :                   gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
    4066              :                                        && (CALL_EXPR_IFN (t)
    4067              :                                            == IFN_DEFERRED_INIT));
    4068          259 :                   tsi_prev (&iter);
    4069              :                 }
    4070              :             }
    4071          278 :           if (add)
    4072              :             {
    4073              :               /* If reached the start in this or some earlier iteration,
    4074              :                  prepend .DEFERRED_INIT call for DECL.  */
    4075           49 :               tree t = build_deferred_init_call (decl);
    4076           49 :               STMT_IS_FULL_EXPR_P (t) = 1;
    4077           49 :               tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4078              :             }
    4079              :         }
    4080           70 :       if (!add)
    4081              :         {
    4082              :           /* If .DEFERRED_INIT calls for all the decls were already there,
    4083              :              skip over case labels and if we find a LABEL_EXPR, return
    4084              :              its label.  */
    4085           63 :           while (!tsi_end_p (iter)
    4086           63 :                  && !case_label
    4087          117 :                  && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
    4088           12 :             tsi_prev (&iter);
    4089           51 :           if (tsi_end_p (iter))
    4090              :             {
    4091              :               /* Only case labels were found and we are looking for normal
    4092              :                  label, we'll need to add it.  */
    4093            0 :               add = true;
    4094            0 :               iter = tsi_start (then_clause);
    4095              :             }
    4096           51 :           else if (!case_label
    4097           51 :                    && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
    4098              :             /* Return existing label.  */
    4099           21 :             lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
    4100              :           else
    4101              :             {
    4102              :               /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR.  */
    4103           30 :               gcc_checking_assert (case_label
    4104              :                                    || (TREE_CODE (tsi_stmt (iter))
    4105              :                                        == EXPR_STMT));
    4106           30 :               add = true;
    4107           30 :               tsi_next (&iter);
    4108           30 :               gcc_checking_assert (!tsi_end_p (iter));
    4109              :             }
    4110              :         }
    4111           21 :       if (add)
    4112              :         {
    4113           49 :           tree t;
    4114           49 :           if (case_label)
    4115              :             t = case_label;
    4116              :           else
    4117              :             {
    4118           40 :               lab = create_artificial_label (UNKNOWN_LOCATION);
    4119           40 :               t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
    4120              :             }
    4121           49 :           tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4122              :         }
    4123              :     }
    4124              :   else
    4125              :     {
    4126              :       /* No IF_STMT created by this function found.  Create it all
    4127              :          from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
    4128              :          followed by .DEFERRED_INIT calls inside of a new if (0).  */
    4129           51 :       tree new_then = push_stmt_list ();
    4130           51 :       if (!case_label)
    4131              :         {
    4132           22 :           lab = create_artificial_label (UNKNOWN_LOCATION);
    4133           22 :           add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
    4134              :         }
    4135              :       else
    4136           29 :         add_stmt (case_label);
    4137          135 :       for (unsigned int i = ndecls; i; --i)
    4138           84 :         add_stmt (build_deferred_init_call (decls[i - 1]));
    4139           51 :       new_then = pop_stmt_list (new_then);
    4140           51 :       tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
    4141              :                           new_then, void_node, NULL_TREE);
    4142           51 :       IF_STMT_VACUOUS_INIT_P (stmt) = 1;
    4143           51 :       if (tsi_end_p (iter))
    4144              :         {
    4145            6 :           iter = tsi_start (iter.container);
    4146            6 :           tsi_link_before (&iter, stmt, TSI_SAME_STMT);
    4147              :         }
    4148              :       else
    4149           45 :         tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
    4150              :     }
    4151          121 :   return lab;
    4152              : }
    4153              : 
    4154              : /* Adjust backward gotos to named label ENT if they jump over vacuous
    4155              :    initializers if !!flag_auto_var_init.  ITER is the location of
    4156              :    LABEL_EXPR for that named label.  */
    4157              : 
    4158              : static void
    4159           19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
    4160              : {
    4161           19 :   auto_vec<tree, 4> decls;
    4162           19 :   unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
    4163           19 :   tree decl;
    4164           88 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
    4165           88 :     if (!decl_jump_unsafe (decl))
    4166              :       {
    4167           88 :         gcc_checking_assert (decl_instrument_init_bypass_p (decl));
    4168           88 :         decls.safe_push (decl);
    4169          176 :         if (decls.length () == max_cnt)
    4170              :           break;
    4171              :       }
    4172           19 :   named_label_bck_direct_goto *dgoto;
    4173           19 :   unsigned last = 0;
    4174           19 :   tree lab = NULL_TREE;
    4175          103 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
    4176              :     {
    4177           46 :       if (dgoto->n_bad_decls != last)
    4178              :         {
    4179           40 :           last = dgoto->n_bad_decls;
    4180           80 :           lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
    4181              :                                                decls.address (), last);
    4182              :         }
    4183           46 :       *dgoto->direct_goto = lab;
    4184              :     }
    4185           19 : }
    4186              : 
    4187              : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    4188              :    to the user.  */
    4189              : 
    4190              : static bool
    4191          286 : identify_goto (tree decl, location_t loc, const location_t *locus,
    4192              :                enum diagnostics::kind diag_kind, bool computed)
    4193              : {
    4194          286 :   if (computed)
    4195           43 :     diag_kind = diagnostics::kind::warning;
    4196          286 :   bool complained
    4197          373 :     = emit_diagnostic (diag_kind, loc, 0,
    4198              :                        decl ? G_("jump to label %qD")
    4199              :                        : G_("jump to case label"), decl);
    4200          286 :   if (complained && locus)
    4201              :     {
    4202          199 :       if (computed)
    4203           43 :         inform (*locus, "  as a possible target of computed goto");
    4204              :       else
    4205          156 :         inform (*locus, "  from here");
    4206              :     }
    4207          286 :   return complained;
    4208              : }
    4209              : 
    4210              : /* Check that a single previously seen jump to a newly defined label
    4211              :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    4212              :    the jump context; NAMES are the names in scope in LEVEL at the jump
    4213              :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    4214              :    is a vec of decls if the jump is a computed goto.  DIRECT_GOTO is a
    4215              :    vec of pointers to LABEL_DECLs that might need adjusting if vacuous
    4216              :    initializations are crossed for !!flag_auto_var_init.  CASE_LABEL is
    4217              :    CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
    4218              :    Returns non-zero if all is well, 2 if any vacuous initializers were
    4219              :    crossed.  */
    4220              : 
    4221              : static int
    4222      4563697 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
    4223              :                        bool exited_omp, const location_t *locus,
    4224              :                        vec<tree, va_gc> *computed,
    4225              :                        vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
    4226              :                        tree case_label)
    4227              : {
    4228      4563697 :   auto_diagnostic_group d;
    4229      4563697 :   cp_binding_level *b;
    4230      4563697 :   bool complained = false;
    4231      4563697 :   int identified = 0;
    4232      4563697 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    4233      4563697 :   bool saw_ceif = false, saw_se = false;
    4234      4563697 :   auto_vec<tree> vacuous_decls;
    4235      4563697 :   bool vacuous_inits = false;
    4236              : 
    4237      4563697 :   if (exited_omp)
    4238              :     {
    4239           12 :       complained = identify_goto (decl, input_location, locus,
    4240              :                                   diagnostics::kind::error,
    4241              :                                   computed);
    4242           12 :       if (complained)
    4243           12 :         inform (input_location, "  exits OpenMP structured block");
    4244              :       saw_omp = true;
    4245              :       identified = 2;
    4246              :     }
    4247              : 
    4248     13662396 :   for (b = current_binding_level; b ; b = b->level_chain)
    4249              :     {
    4250      9098699 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    4251              : 
    4252      9178582 :       for (new_decls = b->names; new_decls != old_decls;
    4253       149090 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    4254        69207 :                         : TREE_CHAIN (new_decls)))
    4255              :         {
    4256        79883 :           bool problem = decl_jump_unsafe (new_decls);
    4257        79883 :           if (! problem)
    4258              :             {
    4259        79838 :               if (decl_instrument_init_bypass_p (new_decls))
    4260              :                 {
    4261          311 :                   if (direct_goto || case_label)
    4262          246 :                     vacuous_decls.safe_push (new_decls);
    4263              :                   vacuous_inits = true;
    4264              :                 }
    4265        79838 :               continue;
    4266              :             }
    4267              : 
    4268           45 :           if (!identified)
    4269              :             {
    4270           45 :               complained = identify_goto (decl, input_location, locus,
    4271              :                                           diagnostics::kind::error,
    4272              :                                           computed);
    4273           45 :               identified = 2;
    4274              :             }
    4275           45 :           if (complained)
    4276           45 :             inform (DECL_SOURCE_LOCATION (new_decls),
    4277              :                     "  crosses initialization of %q#D", new_decls);
    4278              :         }
    4279              : 
    4280      9098699 :       if (b == level)
    4281              :         break;
    4282              : 
    4283      4535002 :       const char *inf = NULL;
    4284      4535002 :       location_t loc = input_location;
    4285      4535002 :       switch (b->kind)
    4286              :         {
    4287            3 :         case sk_try:
    4288            3 :           if (!saw_eh)
    4289              :             inf = G_("  enters %<try%> block");
    4290              :           saw_eh = true;
    4291              :           break;
    4292              : 
    4293            9 :         case sk_catch:
    4294            9 :           if (!saw_eh)
    4295              :             inf = G_("  enters %<catch%> block");
    4296              :           saw_eh = true;
    4297              :           break;
    4298              : 
    4299          102 :         case sk_omp:
    4300          102 :           if (!saw_omp)
    4301              :             inf = G_("  enters OpenMP structured block");
    4302              :           saw_omp = true;
    4303              :           break;
    4304              : 
    4305            3 :         case sk_transaction:
    4306            3 :           if (!saw_tm)
    4307              :             inf = G_("  enters synchronized or atomic statement");
    4308              :           saw_tm = true;
    4309              :           break;
    4310              : 
    4311           18 :         case sk_stmt_expr:
    4312           18 :           if (!saw_se)
    4313              :             inf = G_("  enters statement expression");
    4314              :           saw_se = true;
    4315              :           break;
    4316              : 
    4317      4534732 :         case sk_block:
    4318      4534732 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    4319              :             {
    4320            9 :               inf = G_("  enters %<constexpr if%> statement");
    4321            9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4322              :               saw_cxif = true;
    4323              :             }
    4324      4534723 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    4325              :             {
    4326           18 :               inf = G_("  enters %<consteval if%> statement");
    4327           18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4328              :               saw_ceif = true;
    4329              :             }
    4330              :           break;
    4331              : 
    4332              :         default:
    4333              :           break;
    4334              :         }
    4335              : 
    4336              :       if (inf)
    4337              :         {
    4338          141 :           if (identified < 2)
    4339          141 :             complained = identify_goto (decl, input_location, locus,
    4340              :                                         diagnostics::kind::error,
    4341              :                                         computed);
    4342          141 :           identified = 2;
    4343          141 :           if (complained)
    4344          141 :             inform (loc, inf);
    4345              :         }
    4346              :     }
    4347              : 
    4348      4563697 :   if (!vec_safe_is_empty (computed))
    4349              :     {
    4350            9 :       if (!identified)
    4351            6 :         complained = identify_goto (decl, input_location, locus,
    4352              :                                     diagnostics::kind::error,
    4353              :                                     computed);
    4354            9 :       identified = 2;
    4355            9 :       if (complained)
    4356           18 :         for (tree d : computed)
    4357              :           {
    4358            9 :             if (DECL_P (d))
    4359            6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    4360            3 :             else if (d == get_identifier ("catch"))
    4361            3 :               inform (*locus, "  does not clean up handled exception");
    4362              :           }
    4363              :     }
    4364              : 
    4365      4563780 :   if (!vacuous_decls.is_empty () && !seen_error ())
    4366              :     {
    4367           81 :       tree_stmt_iterator iter = tsi_last (cur_stmt_list);
    4368           81 :       if (case_label)
    4369              :         {
    4370           38 :           gcc_checking_assert (tsi_stmt (iter) == case_label);
    4371           38 :           tsi_delink (&iter);
    4372           38 :           iter = tsi_last (cur_stmt_list);
    4373              :         }
    4374           81 :       tree lab = maybe_add_deferred_init_calls (iter, case_label,
    4375              :                                                 vacuous_decls.address (),
    4376              :                                                 vacuous_decls.length ());
    4377           81 :       if (lab)
    4378              :         {
    4379              :           unsigned int i;
    4380              :           named_label_fwd_direct_goto *dgoto;
    4381          167 :           FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
    4382           43 :             *dgoto->direct_goto = lab;
    4383              :         }
    4384              :     }
    4385              : 
    4386      4563697 :   if (identified)
    4387              :     return 0;
    4388      4563493 :   return vacuous_inits ? 2 : 1;
    4389      4563697 : }
    4390              : 
    4391              : static void
    4392         2106 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    4393              : {
    4394         2106 :   check_previous_goto_1 (decl, use->binding_level,
    4395         2106 :                          use->names_in_scope, use->in_omp_scope,
    4396         2106 :                          &use->o_goto_locus, use->computed_goto,
    4397              :                          use->direct_goto, NULL_TREE);
    4398         2106 :   vec_free (use->direct_goto);
    4399         2106 : }
    4400              : 
    4401              : static int
    4402      4561591 : check_switch_goto (cp_binding_level *level, tree case_label)
    4403              : {
    4404      4561591 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    4405      4561591 :                                 false, NULL, nullptr, nullptr, case_label);
    4406              : }
    4407              : 
    4408              : /* Check that a new jump to a label ENT is OK.  DECLP is a pointer
    4409              :    to a LABEL_DECL for direct gotos and NULL for computed gotos.  */
    4410              : 
    4411              : void
    4412         2830 : check_goto_1 (named_label_entry *ent, tree *declp)
    4413              : {
    4414         2830 :   auto_diagnostic_group d;
    4415         2830 :   tree decl = ent->label_decl;
    4416         2830 :   bool computed = declp == NULL;
    4417              : 
    4418              :   /* If the label hasn't been defined yet, defer checking.  */
    4419         2830 :   if (! DECL_INITIAL (decl))
    4420              :     {
    4421              :       /* Don't bother creating another use if the last goto had the
    4422              :          same data, and will therefore create the same set of errors.  */
    4423         2175 :       if (ent->uses
    4424          658 :           && ent->uses->binding_level == current_binding_level
    4425           60 :           && ent->uses->names_in_scope == current_binding_level->names)
    4426              :         {
    4427           60 :           if (declp
    4428           54 :               && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4429           11 :               && !processing_template_decl)
    4430            9 :             vec_safe_push (ent->uses->direct_goto,
    4431            9 :                            named_label_fwd_direct_goto { declp });
    4432           60 :           return;
    4433              :         }
    4434              : 
    4435         2115 :       named_label_use_entry *new_use
    4436         2115 :         = ggc_alloc<named_label_use_entry> ();
    4437         2115 :       new_use->binding_level = current_binding_level;
    4438         2115 :       new_use->names_in_scope = current_binding_level->names;
    4439         2115 :       new_use->o_goto_locus = input_location;
    4440         2115 :       new_use->in_omp_scope = false;
    4441         2115 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    4442         2115 :       new_use->direct_goto = nullptr;
    4443         2115 :       if (declp
    4444         2024 :           && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4445          355 :           && !processing_template_decl)
    4446          298 :         vec_safe_push (new_use->direct_goto,
    4447          298 :                        named_label_fwd_direct_goto { declp });
    4448              : 
    4449         2115 :       new_use->next = ent->uses;
    4450         2115 :       ent->uses = new_use;
    4451         2115 :       return;
    4452              :     }
    4453              : 
    4454          655 :   bool saw_catch = false, complained = false;
    4455          655 :   int identified = 0;
    4456          655 :   tree bad;
    4457          655 :   unsigned ix;
    4458          655 :   unsigned n_bad_decls = 0;
    4459              : 
    4460          655 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    4461          640 :       || ent->in_constexpr_if || ent->in_consteval_if
    4462          634 :       || ent->in_omp_scope || ent->in_stmt_expr
    4463          616 :       || ent->has_bad_decls)
    4464              :     {
    4465           45 :       enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
    4466           45 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    4467           30 :           || ent->in_consteval_if || ent->in_transaction_scope
    4468           24 :           || ent->in_omp_scope || ent->in_stmt_expr)
    4469           39 :         diag_kind = diagnostics::kind::error;
    4470           45 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4471              :                                   &input_location, diag_kind, computed);
    4472           45 :       identified = 1 + (diag_kind == diagnostics::kind::error);
    4473              :     }
    4474              : 
    4475          845 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    4476              :     {
    4477          190 :       bool problem = decl_jump_unsafe (bad);
    4478          190 :       if (!problem)
    4479              :         {
    4480          184 :           gcc_checking_assert (decl_instrument_init_bypass_p (bad));
    4481          184 :           n_bad_decls++;
    4482          184 :           continue;
    4483              :         }
    4484              : 
    4485            6 :       if (DECL_ARTIFICIAL (bad))
    4486              :         {
    4487              :           /* Can't skip init of __exception_info.  */
    4488            0 :           if (identified == 1)
    4489              :             {
    4490            0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4491              :                                           &input_location,
    4492              :                                           diagnostics::kind::error,
    4493              :                                           computed);
    4494            0 :               identified = 2;
    4495              :             }
    4496            0 :           if (complained)
    4497            0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    4498              :           saw_catch = true;
    4499              :         }
    4500            6 :       else if (complained)
    4501            6 :         inform (DECL_SOURCE_LOCATION (bad),
    4502              :                 "  skips initialization of %q#D", bad);
    4503              :     }
    4504              : 
    4505          655 :   if (complained)
    4506              :     {
    4507           45 :       if (ent->in_try_scope)
    4508            9 :         inform (input_location, "  enters %<try%> block");
    4509           36 :       else if (ent->in_catch_scope && !saw_catch)
    4510            3 :         inform (input_location, "  enters %<catch%> block");
    4511           33 :       else if (ent->in_transaction_scope)
    4512            3 :         inform (input_location, "  enters synchronized or atomic statement");
    4513           30 :       else if (ent->in_constexpr_if)
    4514            3 :         inform (input_location, "  enters %<constexpr if%> statement");
    4515           27 :       else if (ent->in_consteval_if)
    4516            3 :         inform (input_location, "  enters %<consteval if%> statement");
    4517           24 :       else if (ent->in_stmt_expr)
    4518           15 :         inform (input_location, "  enters statement expression");
    4519              :     }
    4520              : 
    4521          655 :   if (ent->in_omp_scope)
    4522              :     {
    4523            3 :       if (complained)
    4524            3 :         inform (input_location, "  enters OpenMP structured block");
    4525              :     }
    4526          652 :   else if (flag_openmp)
    4527           69 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4528              :       {
    4529           42 :         if (b == ent->binding_level)
    4530              :           break;
    4531           36 :         if (b->kind == sk_omp)
    4532              :           {
    4533           21 :             if (identified < 2)
    4534              :               {
    4535           42 :                 complained = identify_goto (decl,
    4536           21 :                                             DECL_SOURCE_LOCATION (decl),
    4537              :                                             &input_location,
    4538              :                                             diagnostics::kind::error,
    4539              :                                             computed);
    4540           21 :                 identified = 2;
    4541              :               }
    4542           21 :             if (complained)
    4543           21 :               inform (input_location, "  exits OpenMP structured block");
    4544              :             break;
    4545              :           }
    4546              :       }
    4547              : 
    4548              :   /* Warn if a computed goto might involve a local variable going out of scope
    4549              :      without being cleaned up.  */
    4550          655 :   if (computed)
    4551              :     {
    4552           71 :       auto level = ent->binding_level;
    4553           71 :       auto names = ent->names_in_scope;
    4554           71 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4555              :         {
    4556          111 :           if (b->kind == sk_catch)
    4557              :             {
    4558            6 :               if (!identified)
    4559              :                 {
    4560            6 :                   complained
    4561            6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4562              :                                      &input_location, diagnostics::kind::error,
    4563              :                                      computed);
    4564            6 :                   identified = 2;
    4565              :                 }
    4566            6 :               if (complained)
    4567            6 :                 inform (input_location,
    4568              :                         "  does not clean up handled exception");
    4569              :             }
    4570          111 :           tree end = b == level ? names : NULL_TREE;
    4571          127 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4572              :             {
    4573           16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4574              :                 {
    4575           10 :                   if (!identified)
    4576              :                     {
    4577           10 :                       complained
    4578           10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4579              :                                          &input_location, diagnostics::kind::error,
    4580              :                                          computed);
    4581           10 :                       identified = 2;
    4582              :                     }
    4583           10 :                   if (complained)
    4584           10 :                     inform (DECL_SOURCE_LOCATION (d),
    4585              :                             "  does not destroy %qD", d);
    4586              :                 }
    4587              :             }
    4588          111 :           if (b == level)
    4589              :             break;
    4590           40 :         }
    4591              :     }
    4592              : 
    4593          655 :   if (n_bad_decls && declp)
    4594           46 :     vec_safe_push (ent->direct_goto,
    4595           46 :                    named_label_bck_direct_goto { declp, n_bad_decls });
    4596         2830 : }
    4597              : 
    4598              : /* Check that a new jump to a label *DECLP is OK.  Called by
    4599              :    finish_goto_stmt.  */
    4600              : 
    4601              : void
    4602         2790 : check_goto (tree *declp)
    4603              : {
    4604         2790 :   if (!named_labels)
    4605              :     return;
    4606         2775 :   tree decl = *declp;
    4607         2775 :   if (TREE_CODE (decl) != LABEL_DECL)
    4608              :     {
    4609              :       /* We don't know where a computed goto is jumping,
    4610              :          so check all addressable labels.  */
    4611          312 :       for (auto iter = named_labels->begin ();
    4612          425 :            iter != named_labels->end ();
    4613          199 :            ++iter)
    4614              :         {
    4615          199 :           auto ent = *iter;
    4616          199 :           if (ent->addressed)
    4617          168 :             check_goto_1 (ent, NULL);
    4618              :         }
    4619              :     }
    4620              :   else
    4621              :     {
    4622         2662 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4623         2662 :       named_label_entry **slot
    4624         2662 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4625         2662 :       named_label_entry *ent = *slot;
    4626         2662 :       check_goto_1 (ent, declp);
    4627              :     }
    4628              : }
    4629              : 
    4630              : /* Check that a return is ok wrt OpenMP structured blocks.
    4631              :    Called by finish_return_stmt.  Returns true if all is well.  */
    4632              : 
    4633              : bool
    4634       278904 : check_omp_return (void)
    4635              : {
    4636      1103233 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4637       824329 :     if (b->kind == sk_omp)
    4638              :       {
    4639           15 :         error ("invalid exit from OpenMP structured block");
    4640           15 :         return false;
    4641              :       }
    4642       824314 :     else if (b->kind == sk_function_parms)
    4643              :       break;
    4644              :   return true;
    4645              : }
    4646              : 
    4647              : /* Define a label, specifying the location in the source file.
    4648              :    Return the LABEL_DECL node for the label.  */
    4649              : 
    4650              : tree
    4651        20464 : define_label (location_t location, tree name)
    4652              : {
    4653        20464 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4654              : 
    4655              :   /* After labels, make any new cleanups in the function go into their
    4656              :      own new (temporary) binding contour.  */
    4657        20464 :   for (cp_binding_level *p = current_binding_level;
    4658        31053 :        p->kind != sk_function_parms;
    4659        10589 :        p = p->level_chain)
    4660        10589 :     p->more_cleanups_ok = 0;
    4661              : 
    4662        20464 :   named_label_entry *ent = lookup_label_1 (name, false);
    4663        20464 :   tree decl = ent->label_decl;
    4664              : 
    4665        20464 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4666              :     {
    4667            6 :       error ("duplicate label %qD", decl);
    4668            6 :       return error_mark_node;
    4669              :     }
    4670              :   else
    4671              :     {
    4672              :       /* Mark label as having been defined.  */
    4673        20458 :       DECL_INITIAL (decl) = error_mark_node;
    4674              :       /* Say where in the source.  */
    4675        20458 :       DECL_SOURCE_LOCATION (decl) = location;
    4676              : 
    4677        20458 :       ent->binding_level = current_binding_level;
    4678        20458 :       ent->names_in_scope = current_binding_level->names;
    4679              : 
    4680        22564 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4681         2106 :         check_previous_goto (decl, use);
    4682        20458 :       ent->uses = NULL;
    4683              :     }
    4684              : 
    4685        20458 :   return decl;
    4686        20464 : }
    4687              : 
    4688              : struct cp_switch
    4689              : {
    4690              :   cp_binding_level *level;
    4691              :   struct cp_switch *next;
    4692              :   /* The SWITCH_STMT being built.  */
    4693              :   tree switch_stmt;
    4694              :   /* A splay-tree mapping the low element of a case range to the high
    4695              :      element, or NULL_TREE if there is no high element.  Used to
    4696              :      determine whether or not a new case label duplicates an old case
    4697              :      label.  We need a tree, rather than simply a hash table, because
    4698              :      of the GNU case range extension.  */
    4699              :   splay_tree cases;
    4700              :   /* Remember whether a default: case label has been seen.  */
    4701              :   bool has_default_p;
    4702              :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4703              :   bool break_stmt_seen_p;
    4704              :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4705              :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4706              :   bool in_loop_body_p;
    4707              : };
    4708              : 
    4709              : /* A stack of the currently active switch statements.  The innermost
    4710              :    switch statement is on the top of the stack.  There is no need to
    4711              :    mark the stack for garbage collection because it is only active
    4712              :    during the processing of the body of a function, and we never
    4713              :    collect at that point.  */
    4714              : 
    4715              : static struct cp_switch *switch_stack;
    4716              : 
    4717              : /* Called right after a switch-statement condition is parsed.
    4718              :    SWITCH_STMT is the switch statement being parsed.  */
    4719              : 
    4720              : void
    4721      1016802 : push_switch (tree switch_stmt)
    4722              : {
    4723      1016802 :   struct cp_switch *p = XNEW (struct cp_switch);
    4724      1016802 :   p->level = current_binding_level;
    4725      1016802 :   p->next = switch_stack;
    4726      1016802 :   p->switch_stmt = switch_stmt;
    4727      1016802 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4728      1016802 :   p->has_default_p = false;
    4729      1016802 :   p->break_stmt_seen_p = false;
    4730      1016802 :   p->in_loop_body_p = false;
    4731      1016802 :   switch_stack = p;
    4732      1016802 : }
    4733              : 
    4734              : void
    4735      1016802 : pop_switch (void)
    4736              : {
    4737      1016802 :   struct cp_switch *cs = switch_stack;
    4738              : 
    4739              :   /* Emit warnings as needed.  */
    4740      1016802 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4741      1016802 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4742      1016802 :   const bool bool_cond_p
    4743      1016802 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4744      1016802 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4745      1016802 :   if (!processing_template_decl)
    4746       611419 :     c_do_switch_warnings (cs->cases, switch_location,
    4747       611419 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4748              :                           bool_cond_p);
    4749              : 
    4750              :   /* For the benefit of block_may_fallthru remember if the switch body
    4751              :      case labels cover all possible values and if there are break; stmts.  */
    4752      1016802 :   if (cs->has_default_p
    4753      1016802 :       || (!processing_template_decl
    4754        80490 :           && c_switch_covers_all_cases_p (cs->cases,
    4755        80490 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4756       796673 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4757      1016802 :   if (!cs->break_stmt_seen_p)
    4758       475215 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4759              :   /* Now that we're done with the switch warnings, set the switch type
    4760              :      to the type of the condition if the index type was of scoped enum type.
    4761              :      (Such types don't participate in the integer promotions.)  We do this
    4762              :      because of bit-fields whose declared type is a scoped enum type:
    4763              :      gimplification will use the lowered index type, but convert the
    4764              :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4765              :      and verify_gimple_switch doesn't accept that.  */
    4766      1016802 :   if (is_bitfield_expr_with_lowered_type (cond))
    4767       201513 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4768      1016802 :   gcc_assert (!cs->in_loop_body_p);
    4769      1016802 :   splay_tree_delete (cs->cases);
    4770      1016802 :   switch_stack = switch_stack->next;
    4771      1016802 :   free (cs);
    4772      1016802 : }
    4773              : 
    4774              : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4775              :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4776              :    in switch_stack we've seen a BREAK_STMT.  */
    4777              : 
    4778              : void
    4779      5673725 : note_break_stmt (void)
    4780              : {
    4781      5673725 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4782      3602016 :     switch_stack->break_stmt_seen_p = true;
    4783      5673725 : }
    4784              : 
    4785              : /* Note the start of processing of an iteration statement's body.
    4786              :    The note_break_stmt function will do nothing while processing it.
    4787              :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4788              : 
    4789              : bool
    4790     18086691 : note_iteration_stmt_body_start (void)
    4791              : {
    4792     18086691 :   if (!switch_stack)
    4793              :     return false;
    4794       295161 :   bool ret = switch_stack->in_loop_body_p;
    4795       295161 :   switch_stack->in_loop_body_p = true;
    4796       295161 :   return ret;
    4797              : }
    4798              : 
    4799              : /* Note the end of processing of an iteration statement's body.  */
    4800              : 
    4801              : void
    4802     18086691 : note_iteration_stmt_body_end (bool prev)
    4803              : {
    4804     18086691 :   if (switch_stack)
    4805       295161 :     switch_stack->in_loop_body_p = prev;
    4806     18086691 : }
    4807              : 
    4808              : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4809              :    condition.  Note that if TYPE and VALUE are already integral we don't
    4810              :    really do the conversion because the language-independent
    4811              :    warning/optimization code will work better that way.  */
    4812              : 
    4813              : static tree
    4814      9122858 : case_conversion (tree type, tree value)
    4815              : {
    4816      9122858 :   if (value == NULL_TREE)
    4817              :     return value;
    4818              : 
    4819      4030668 :   value = mark_rvalue_use (value);
    4820              : 
    4821      4030668 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4822      1422838 :     type = type_promotes_to (type);
    4823              : 
    4824      4030668 :   tree ovalue = value;
    4825              :   /* The constant-expression VALUE shall be a converted constant expression
    4826              :      of the adjusted type of the switch condition, which doesn't allow
    4827              :      narrowing conversions.  */
    4828      4030668 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4829              : 
    4830      4030668 :   if (cxx_dialect >= cxx11
    4831      4030668 :       && (SCOPED_ENUM_P (type)
    4832      1419717 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4833              :     /* Use the converted value.  */;
    4834              :   else
    4835              :     /* The already integral case.  */
    4836              :     value = ovalue;
    4837              : 
    4838      4030668 :   return cxx_constant_value (value);
    4839              : }
    4840              : 
    4841              : /* Note that we've seen a definition of a case label, and complain if this
    4842              :    is a bad place for one.  */
    4843              : 
    4844              : tree
    4845      8411978 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4846              : {
    4847      8411978 :   tree cond, r;
    4848      8411978 :   cp_binding_level *p;
    4849      8411978 :   tree type;
    4850              : 
    4851      8411978 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4852       796637 :     switch_stack->has_default_p = true;
    4853              : 
    4854      8411978 :   if (processing_template_decl)
    4855              :     {
    4856      3850426 :       tree label;
    4857              : 
    4858              :       /* For templates, just add the case label; we'll do semantic
    4859              :          analysis at instantiation-time.  But diagnose case labels
    4860              :          in expansion statements with switch outside of it here.  */
    4861      3850426 :       if (in_expansion_stmt)
    4862           39 :         for (cp_binding_level *b = current_binding_level;
    4863           78 :              b != switch_stack->level; b = b->level_chain)
    4864           63 :           if (b->kind == sk_template_for && b->this_entity)
    4865              :             {
    4866           24 :               auto_diagnostic_group d;
    4867           24 :               error ("jump to case label");
    4868           24 :               inform (EXPR_LOCATION (b->this_entity),
    4869              :                       "  enters %<template for%> statement");
    4870           24 :               return error_mark_node;
    4871           24 :             }
    4872      3850402 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4873      3850402 :       return add_stmt (build_case_label (low_value, high_value, label));
    4874              :     }
    4875              : 
    4876              :   /* Find the condition on which this switch statement depends.  */
    4877      4561552 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4878      4561552 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4879            0 :     cond = TREE_VALUE (cond);
    4880              : 
    4881      4561552 :   int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
    4882      4561552 :   if (!chk_switch_goto)
    4883           87 :     return error_mark_node;
    4884              : 
    4885      4561465 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4886      4561465 :   if (type == error_mark_node)
    4887              :     return error_mark_node;
    4888              : 
    4889      4561429 :   low_value = case_conversion (type, low_value);
    4890      4561429 :   high_value = case_conversion (type, high_value);
    4891              : 
    4892      4561429 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4893              : 
    4894      4561429 :   if (r != error_mark_node && chk_switch_goto == 2)
    4895           39 :     check_switch_goto (switch_stack->level, r);
    4896              : 
    4897              :   /* After labels, make any new cleanups in the function go into their
    4898              :      own new (temporary) binding contour.  */
    4899      4561429 :   for (p = current_binding_level;
    4900     18938198 :        p->kind != sk_function_parms;
    4901     14376769 :        p = p->level_chain)
    4902     14376769 :     p->more_cleanups_ok = 0;
    4903              : 
    4904              :   return r;
    4905              : }
    4906              : 
    4907              : struct typename_info {
    4908              :   tree scope;
    4909              :   tree name;
    4910              :   tree template_id;
    4911              :   tag_types tag_type;
    4912              : };
    4913              : 
    4914              : struct typename_hasher : ggc_ptr_hash<tree_node>
    4915              : {
    4916              :   typedef typename_info *compare_type;
    4917              : 
    4918              :   /* Hash a TYPENAME_TYPE.  */
    4919              : 
    4920              :   static hashval_t
    4921    442506814 :   hash (tree context, tree fullname)
    4922              :   {
    4923    442506814 :     hashval_t hash = 0;
    4924    442506814 :     hash = iterative_hash_object (context, hash);
    4925    442506814 :     hash = iterative_hash_object (fullname, hash);
    4926    442506814 :     return hash;
    4927              :   }
    4928              : 
    4929              :   static hashval_t
    4930     62110242 :   hash (const typename_info *ti)
    4931              :   {
    4932     62110242 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4933              :   }
    4934              : 
    4935              :   static hashval_t
    4936    380396572 :   hash (tree t)
    4937              :   {
    4938    380396572 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4939              :   }
    4940              : 
    4941              :   /* Compare two TYPENAME_TYPEs.  */
    4942              : 
    4943              :   static bool
    4944    448603097 :   equal (tree t1, const typename_info *t2)
    4945              :   {
    4946    448603097 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4947    144469083 :             && TYPE_CONTEXT (t1) == t2->scope
    4948     32284322 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4949    480876770 :             && get_typename_tag (t1) == t2->tag_type);
    4950              :   }
    4951              : };
    4952              : 
    4953              : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4954              :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4955              : 
    4956              :    Returns the new TYPENAME_TYPE.  */
    4957              : 
    4958              : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4959              : 
    4960              : tree
    4961     62110242 : build_typename_type (tree context, tree name, tree fullname,
    4962              :                      enum tag_types tag_type)
    4963              : {
    4964     62110242 :   typename_info ti;
    4965              : 
    4966     62110242 :   if (typename_htab == NULL)
    4967        18949 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4968              : 
    4969     62110242 :   ti.scope = FROB_CONTEXT (context);
    4970     62110242 :   ti.name = name;
    4971     62110242 :   ti.template_id = fullname;
    4972     62110242 :   ti.tag_type = tag_type;
    4973     62110242 :   hashval_t hash = typename_hasher::hash (&ti);
    4974              : 
    4975              :   /* See if we already have this type.  */
    4976     62110242 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4977     62110242 :   tree t = *e;
    4978     62110242 :   if (*e)
    4979              :     t = *e;
    4980              :   else
    4981              :     {
    4982              :       /* Build the TYPENAME_TYPE.  */
    4983     30884902 :       t = cxx_make_type (TYPENAME_TYPE);
    4984     30884902 :       TYPE_CONTEXT (t) = ti.scope;
    4985     30884902 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4986     30884902 :       set_typename_tag (t, ti.tag_type);
    4987              : 
    4988              :       /* Build the corresponding TYPE_DECL.  */
    4989     30884902 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4990     30884902 :       TYPE_NAME (t) = d;
    4991     30884902 :       TYPE_STUB_DECL (t) = d;
    4992     30884902 :       DECL_CONTEXT (d) = ti.scope;
    4993     30884902 :       DECL_ARTIFICIAL (d) = 1;
    4994              : 
    4995              :       /* Store it in the hash table.  */
    4996     30884902 :       *e = t;
    4997              : 
    4998              :       /* TYPENAME_TYPEs must always be compared structurally, because
    4999              :          they may or may not resolve down to another type depending on
    5000              :          the currently open classes. */
    5001     30884902 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    5002              :     }
    5003              : 
    5004     62110242 :   return t;
    5005              : }
    5006              : 
    5007              : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    5008              :    provided to name the type.  Returns an appropriate type, unless an
    5009              :    error occurs, in which case error_mark_node is returned.  If we
    5010              :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    5011              :    return that, rather than the _TYPE it corresponds to, in other
    5012              :    cases we look through the type decl.  If TF_ERROR is set, complain
    5013              :    about errors, otherwise be quiet.  */
    5014              : 
    5015              : tree
    5016    364972986 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    5017              :                     tsubst_flags_t complain)
    5018              : {
    5019    364972986 :   tree fullname;
    5020    364972986 :   tree t;
    5021    364972986 :   bool want_template;
    5022              : 
    5023    364972986 :   if (name == error_mark_node
    5024    364972980 :       || context == NULL_TREE
    5025    364972980 :       || context == error_mark_node)
    5026              :     return error_mark_node;
    5027              : 
    5028    364972964 :   if (TYPE_P (name))
    5029              :     {
    5030            0 :       if (!(TYPE_LANG_SPECIFIC (name)
    5031            0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    5032            0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    5033            0 :         name = TYPE_IDENTIFIER (name);
    5034              :       else
    5035              :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    5036            0 :         name = build_nt (TEMPLATE_ID_EXPR,
    5037            0 :                          CLASSTYPE_TI_TEMPLATE (name),
    5038            0 :                          CLASSTYPE_TI_ARGS (name));
    5039              :     }
    5040    364972964 :   else if (TREE_CODE (name) == TYPE_DECL)
    5041            0 :     name = DECL_NAME (name);
    5042              : 
    5043    364972964 :   fullname = name;
    5044              : 
    5045    364972964 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    5046              :     {
    5047      5251244 :       name = TREE_OPERAND (name, 0);
    5048      5251244 :       if (DECL_TYPE_TEMPLATE_P (name))
    5049            0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    5050      5251244 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    5051              :         {
    5052            0 :           if (complain & tf_error)
    5053            0 :             error ("%qD is not a type", name);
    5054            0 :           return error_mark_node;
    5055              :         }
    5056              :     }
    5057    364972964 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    5058              :     {
    5059            0 :       if (complain & tf_error)
    5060            0 :         error ("%qD used without template arguments", name);
    5061            0 :       return error_mark_node;
    5062              :     }
    5063    364972964 :   else if (is_overloaded_fn (name))
    5064              :     {
    5065            3 :       if (complain & tf_error)
    5066            3 :         error ("%qD is a function, not a type", name);
    5067            3 :       return error_mark_node;
    5068              :     }
    5069    364972961 :   gcc_assert (identifier_p (name));
    5070    364972961 :   gcc_assert (TYPE_P (context));
    5071              : 
    5072    364972961 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    5073              :     /* This can happen for C++17 variadic using (c++/88986).  */;
    5074    352213310 :   else if (!MAYBE_CLASS_TYPE_P (context))
    5075              :     {
    5076            6 :       if (complain & tf_error)
    5077            6 :         error ("%q#T is not a class", context);
    5078            6 :       return error_mark_node;
    5079              :     }
    5080              : 
    5081              :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    5082              :      dependent base class of CONTEXT.  But look inside it anyway
    5083              :      if CONTEXT is a currently open scope, in case it refers to a
    5084              :      member of the current instantiation or a non-dependent base;
    5085              :      lookup will stop when we hit a dependent base.  */
    5086    364972955 :   if (!dependent_scope_p (context))
    5087              :     {
    5088              :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    5089              :          (as per [temp.res.general]/3), unless
    5090              :            - the tag corresponds to a class-key or 'enum' so
    5091              :              [basic.lookup.elab] applies, or
    5092              :            - the tag corresponds to scope_type or tf_qualifying_scope is
    5093              :              set so [basic.lookup.qual]/1 applies, or
    5094              :            - we're inside a base-specifier so [class.derived.general]/2 applies;
    5095              :              the tag will already be class_type in that case.
    5096              :          TODO: If we'd set/track the scope_type tag thoroughly on all
    5097              :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    5098              :          tf_qualifying_scope flag.  */
    5099    614971896 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    5100    307485948 :         || (complain & tf_qualifying_scope);
    5101    307485948 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    5102              :     }
    5103              :   else
    5104              :     t = NULL_TREE;
    5105              : 
    5106    394128701 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    5107     57487931 :     return build_typename_type (context, name, fullname, tag_type);
    5108              : 
    5109    307485024 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    5110              : 
    5111    307485024 :   if (!t)
    5112              :     {
    5113     29154822 :       if (complain & tf_error)
    5114              :         {
    5115          223 :           if (!COMPLETE_TYPE_P (context))
    5116           18 :             cxx_incomplete_type_error (NULL_TREE, context);
    5117              :           else
    5118          409 :             error (want_template ? G_("no class template named %q#T in %q#T")
    5119              :                    : G_("no type named %q#T in %q#T"), name, context);
    5120              :         }
    5121     29154822 :       return error_mark_node;
    5122              :     }
    5123              : 
    5124              :   /* Pull out the template from an injected-class-name (or multiple).  */
    5125    278330202 :   if (want_template)
    5126      3454379 :     t = maybe_get_template_decl_from_type_decl (t);
    5127              : 
    5128    278330202 :   if (TREE_CODE (t) == TREE_LIST)
    5129              :     {
    5130            3 :       if (complain & tf_error)
    5131              :         {
    5132            3 :           auto_diagnostic_group d;
    5133            3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    5134            3 :           print_candidates (input_location, t);
    5135            3 :         }
    5136            3 :       return error_mark_node;
    5137              :     }
    5138              : 
    5139    278330199 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    5140              :     {
    5141            6 :       if (complain & tf_error)
    5142            6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    5143              :                context, name, t);
    5144            6 :       return error_mark_node;
    5145              :     }
    5146    278330193 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    5147              :     {
    5148         1469 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    5149         2941 :           && DECL_TYPE_TEMPLATE_P (t))
    5150              :         /* The caller permits this typename-specifier to name a template
    5151              :            (because it appears in a CTAD-enabled context).  */;
    5152              :       else
    5153              :         {
    5154           23 :           if (complain & tf_error)
    5155           17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    5156              :                    context, name, t);
    5157           23 :           return error_mark_node;
    5158              :         }
    5159              :     }
    5160              : 
    5161    278330170 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    5162              :                                             context, complain))
    5163           46 :     return error_mark_node;
    5164              : 
    5165    278330124 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    5166         1458 :     return make_template_placeholder (t);
    5167              : 
    5168    278328666 :   if (want_template)
    5169              :     {
    5170      3454373 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    5171              :                                  NULL_TREE, context,
    5172              :                                  complain | tf_user);
    5173      3454373 :       if (t == error_mark_node)
    5174              :         return error_mark_node;
    5175      3454368 :       t = TYPE_NAME (t);
    5176              :     }
    5177              : 
    5178    278328661 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    5179      2604773 :     t = TREE_TYPE (t);
    5180              : 
    5181    278328661 :   maybe_record_typedef_use (t);
    5182              : 
    5183    278328661 :   return t;
    5184              : }
    5185              : 
    5186              : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    5187              :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    5188              :    in which case error_mark_node is returned.
    5189              : 
    5190              :    If PARM_LIST is non-NULL, also make sure that the template parameter
    5191              :    list of TEMPLATE_DECL matches.
    5192              : 
    5193              :    If COMPLAIN zero, don't complain about any errors that occur.  */
    5194              : 
    5195              : tree
    5196       172960 : make_unbound_class_template (tree context, tree name, tree parm_list,
    5197              :                              tsubst_flags_t complain)
    5198              : {
    5199       172960 :   if (TYPE_P (name))
    5200            0 :     name = TYPE_IDENTIFIER (name);
    5201       172960 :   else if (DECL_P (name))
    5202            0 :     name = DECL_NAME (name);
    5203       172960 :   gcc_assert (identifier_p (name));
    5204              : 
    5205       172960 :   if (!dependent_type_p (context)
    5206       172960 :       || currently_open_class (context))
    5207              :     {
    5208        84458 :       tree tmpl = NULL_TREE;
    5209              : 
    5210        84458 :       if (MAYBE_CLASS_TYPE_P (context))
    5211        84452 :         tmpl = lookup_field (context, name, 0, false);
    5212              : 
    5213        84452 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    5214            3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    5215              : 
    5216        84446 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    5217              :         {
    5218           12 :           if (complain & tf_error)
    5219            9 :             error ("no class template named %q#T in %q#T", name, context);
    5220           12 :           return error_mark_node;
    5221              :         }
    5222              : 
    5223        84446 :       if (parm_list
    5224        84446 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    5225              :         {
    5226            0 :           if (complain & tf_error)
    5227              :             {
    5228            0 :               auto_diagnostic_group d;
    5229            0 :               error ("template parameters do not match template %qD", tmpl);
    5230            0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    5231              :                       "%qD declared here", tmpl);
    5232            0 :             }
    5233            0 :           return error_mark_node;
    5234              :         }
    5235              : 
    5236        84446 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    5237              :                                           complain))
    5238            0 :         return error_mark_node;
    5239              : 
    5240              :       return tmpl;
    5241              :     }
    5242              : 
    5243        88502 :   return make_unbound_class_template_raw (context, name, parm_list);
    5244              : }
    5245              : 
    5246              : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    5247              : 
    5248              : tree
    5249        88554 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    5250              : {
    5251              :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    5252        88554 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    5253        88554 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    5254        88554 :   TREE_TYPE (t) = NULL_TREE;
    5255        88554 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    5256              : 
    5257              :   /* Build the corresponding TEMPLATE_DECL.  */
    5258        88554 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    5259        88554 :   TYPE_NAME (t) = d;
    5260        88554 :   TYPE_STUB_DECL (t) = d;
    5261        88554 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    5262        88554 :   DECL_ARTIFICIAL (d) = 1;
    5263        88554 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    5264              : 
    5265        88554 :   return t;
    5266              : }
    5267              : 
    5268              : 
    5269              : 
    5270              : /* Push the declarations of builtin types into the global namespace.
    5271              :    RID_INDEX is the index of the builtin type in the array
    5272              :    RID_POINTERS.  NAME is the name used when looking up the builtin
    5273              :    type.  TYPE is the _TYPE node for the builtin type.
    5274              : 
    5275              :    The calls to set_global_binding below should be
    5276              :    eliminated.  Built-in types should not be looked up name; their
    5277              :    names are keywords that the parser can recognize.  However, there
    5278              :    is code in c-common.cc that uses identifier_global_value to look up
    5279              :    built-in types by name.  */
    5280              : 
    5281              : void
    5282      4037876 : record_builtin_type (enum rid rid_index,
    5283              :                      const char* name,
    5284              :                      tree type)
    5285              : {
    5286      4037876 :   tree decl = NULL_TREE;
    5287              : 
    5288      4037876 :   if (name)
    5289              :     {
    5290      2382042 :       tree tname = get_identifier (name);
    5291      2382042 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    5292      2382042 :       DECL_ARTIFICIAL (tdecl) = 1;
    5293      2382042 :       set_global_binding (tdecl);
    5294      2382042 :       decl = tdecl;
    5295              :     }
    5296              : 
    5297      4037876 :   if ((int) rid_index < (int) RID_MAX)
    5298      2478946 :     if (tree rname = ridpointers[(int) rid_index])
    5299      1894534 :       if (!decl || DECL_NAME (decl) != rname)
    5300              :         {
    5301      1363628 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    5302      1363628 :           DECL_ARTIFICIAL (rdecl) = 1;
    5303      1363628 :           set_global_binding (rdecl);
    5304      1363628 :           if (!decl)
    5305              :             decl = rdecl;
    5306              :         }
    5307              : 
    5308      3745670 :   if (decl)
    5309              :     {
    5310      3453464 :       if (!TYPE_NAME (type))
    5311      2869052 :         TYPE_NAME (type) = decl;
    5312      3453464 :       debug_hooks->type_decl (decl, 0);
    5313              :     }
    5314      4037876 : }
    5315              : 
    5316              : /* Push a type into the namespace so that the back ends ignore it.  */
    5317              : 
    5318              : static void
    5319       292206 : record_unknown_type (tree type, const char* name)
    5320              : {
    5321       292206 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    5322              :                                     TYPE_DECL, get_identifier (name), type));
    5323              :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    5324       292206 :   DECL_IGNORED_P (decl) = 1;
    5325       292206 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    5326       292206 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    5327       292206 :   SET_TYPE_ALIGN (type, 1);
    5328       292206 :   TYPE_USER_ALIGN (type) = 0;
    5329       292206 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    5330       292206 : }
    5331              : 
    5332              : /* Create all the predefined identifiers.  */
    5333              : 
    5334              : static void
    5335        97402 : initialize_predefined_identifiers (void)
    5336              : {
    5337        97402 :   struct predefined_identifier
    5338              :   {
    5339              :     const char *name; /* Name.  */
    5340              :     tree *node;  /* Node to store it in.  */
    5341              :     cp_identifier_kind kind;  /* Kind of identifier.  */
    5342              :   };
    5343              : 
    5344              :   /* A table of identifiers to create at startup.  */
    5345        97402 :   static const predefined_identifier predefined_identifiers[] = {
    5346              :     {"C++", &lang_name_cplusplus, cik_normal},
    5347              :     {"C", &lang_name_c, cik_normal},
    5348              :     /* Some of these names have a trailing space so that it is
    5349              :        impossible for them to conflict with names written by users.  */
    5350              :     {"__ct ", &ctor_identifier, cik_ctor},
    5351              :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    5352              :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    5353              :     {"__dt ", &dtor_identifier, cik_dtor},
    5354              :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    5355              :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    5356              :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    5357              :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    5358              :     {"__in_chrg", &in_charge_identifier, cik_normal},
    5359              :     {"__as_base ", &as_base_identifier, cik_normal},
    5360              :     {"this", &this_identifier, cik_normal},
    5361              :     {"__delta", &delta_identifier, cik_normal},
    5362              :     {"__pfn", &pfn_identifier, cik_normal},
    5363              :     {"_vptr", &vptr_identifier, cik_normal},
    5364              :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    5365              :     {"::", &global_identifier, cik_normal},
    5366              :       /* The demangler expects anonymous namespaces to be called
    5367              :          something starting with '_GLOBAL__N_'.  It no longer needs
    5368              :          to be unique to the TU.  */
    5369              :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    5370              :     {"auto", &auto_identifier, cik_normal},
    5371              :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    5372              :     {"initializer_list", &init_list_identifier, cik_normal},
    5373              :     {"__for_range ", &for_range__identifier, cik_normal},
    5374              :     {"__for_begin ", &for_begin__identifier, cik_normal},
    5375              :     {"__for_end ", &for_end__identifier, cik_normal},
    5376              :     {"__for_range", &for_range_identifier, cik_normal},
    5377              :     {"__for_begin", &for_begin_identifier, cik_normal},
    5378              :     {"__for_end", &for_end_identifier, cik_normal},
    5379              :     {"abi_tag", &abi_tag_identifier, cik_normal},
    5380              :     {"aligned", &aligned_identifier, cik_normal},
    5381              :     {"begin", &begin_identifier, cik_normal},
    5382              :     {"end", &end_identifier, cik_normal},
    5383              :     {"get", &get__identifier, cik_normal},
    5384              :     {"gnu", &gnu_identifier, cik_normal},
    5385              :     {"tuple_element", &tuple_element_identifier, cik_normal},
    5386              :     {"tuple_size", &tuple_size_identifier, cik_normal},
    5387              :     {"type", &type_identifier, cik_normal},
    5388              :     {"value", &value_identifier, cik_normal},
    5389              :     {"_FUN", &fun_identifier, cik_normal},
    5390              :     {"__closure", &closure_identifier, cik_normal},
    5391              :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    5392              :     {"heap ", &heap_identifier, cik_normal},
    5393              :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    5394              :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    5395              :     {"heap []", &heap_vec_identifier, cik_normal},
    5396              :     {"omp", &omp_identifier, cik_normal},
    5397              :     {"internal ", &internal_identifier, cik_normal},
    5398              :     {"annotation ", &annotation_identifier, cik_normal},
    5399              :     {NULL, NULL, cik_normal}
    5400              :   };
    5401              : 
    5402      4772698 :   for (const predefined_identifier *pid = predefined_identifiers;
    5403      4772698 :        pid->name; ++pid)
    5404              :     {
    5405      4675296 :       *pid->node = get_identifier (pid->name);
    5406              :       /* Some of these identifiers already have a special kind.  */
    5407      4675296 :       if (pid->kind != cik_normal)
    5408       779216 :         set_identifier_kind (*pid->node, pid->kind);
    5409              :     }
    5410        97402 : }
    5411              : 
    5412              : /* Build a specific variant of operator new.  */
    5413              : 
    5414              : static void
    5415       173719 : cxx_build_operator_new (tree newtype)
    5416              : {
    5417       173719 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    5418       173719 :   DECL_IS_MALLOC (opnew) = 1;
    5419       173719 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5420       173719 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5421       173719 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    5422       173719 :   DECL_IS_MALLOC (opnew) = 1;
    5423       173719 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5424       173719 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5425       173719 : }
    5426              : 
    5427              : /* Build a specific variant of operator delete.  */
    5428              : 
    5429              : static void
    5430       327629 : cxx_build_operator_delete (tree deltype)
    5431              : {
    5432       327629 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    5433       327629 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5434       327629 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5435       327629 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    5436       327629 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5437       327629 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5438       327629 : }
    5439              : 
    5440              : /* Declare all variants of operator new and delete.  */
    5441              : 
    5442              : static void
    5443        97402 : cxx_init_operator_new_delete_decls (void)
    5444              : {
    5445        97402 :   tree newattrs, extvisattr;
    5446        97402 :   tree newtype, deltype;
    5447        97402 :   tree ptr_ftype_sizetype;
    5448        97402 :   tree new_eh_spec;
    5449        97402 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    5450              :                                                   ptr_type_node, NULL_TREE);
    5451        97402 :   void_ftype_ptr
    5452        97402 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    5453              : 
    5454        97402 :   ptr_ftype_sizetype
    5455        97402 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    5456        97402 :   if (cxx_dialect == cxx98)
    5457              :     {
    5458        14166 :       tree bad_alloc_id;
    5459        14166 :       tree bad_alloc_type_node;
    5460        14166 :       tree bad_alloc_decl;
    5461              : 
    5462        14166 :       push_nested_namespace (std_node);
    5463        14166 :       bad_alloc_id = get_identifier ("bad_alloc");
    5464        14166 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    5465        14166 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    5466        14166 :       bad_alloc_decl
    5467        14166 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    5468        14166 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    5469        14166 :       pop_nested_namespace (std_node);
    5470              : 
    5471        14166 :       new_eh_spec
    5472        14166 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    5473              :     }
    5474              :   else
    5475        83236 :     new_eh_spec = noexcept_false_spec;
    5476              : 
    5477        97402 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    5478              :                                 NULL_TREE);
    5479        97402 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    5480              :                         build_tree_list (NULL_TREE, integer_one_node),
    5481              :                         extvisattr);
    5482        97402 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    5483        97402 :   newtype = build_exception_variant (newtype, new_eh_spec);
    5484        97402 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    5485        97402 :   deltype = build_exception_variant (deltype, empty_except_spec);
    5486        97402 :   cxx_build_operator_new (newtype);
    5487        97402 :   cxx_build_operator_delete (deltype);
    5488        97402 :   if (flag_sized_deallocation)
    5489              :     {
    5490              :       /* Also push the sized deallocation variants:
    5491              :            void operator delete(void*, std::size_t) throw();
    5492              :            void operator delete[](void*, std::size_t) throw();  */
    5493        77598 :       tree void_ftype_ptr_size
    5494        77598 :         = build_function_type_list (void_type_node, ptr_type_node,
    5495              :                                     size_type_node, NULL_TREE);
    5496        77598 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    5497              :                                                  extvisattr);
    5498        77598 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5499        77598 :       cxx_build_operator_delete (deltype);
    5500              :     }
    5501              : 
    5502        97402 :   if (aligned_new_threshold)
    5503              :     {
    5504        76317 :       push_nested_namespace (std_node);
    5505        76317 :       tree align_id = get_identifier ("align_val_t");
    5506        76317 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    5507              :                                     NULL_TREE, /*scoped*/true, NULL);
    5508        76317 :       pop_nested_namespace (std_node);
    5509              : 
    5510              :       /* operator new (size_t, align_val_t); */
    5511        76317 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    5512              :                                           align_type_node, NULL_TREE);
    5513        76317 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    5514        76317 :       newtype = build_exception_variant (newtype, new_eh_spec);
    5515        76317 :       cxx_build_operator_new (newtype);
    5516              : 
    5517              :       /* operator delete (void *, align_val_t); */
    5518        76317 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    5519              :                                           align_type_node, NULL_TREE);
    5520        76317 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5521        76317 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5522        76317 :       cxx_build_operator_delete (deltype);
    5523              : 
    5524        76317 :       if (flag_sized_deallocation)
    5525              :         {
    5526              :           /* operator delete (void *, size_t, align_val_t); */
    5527        76312 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    5528              :                                               size_type_node, align_type_node,
    5529              :                                               NULL_TREE);
    5530        76312 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5531        76312 :           deltype = build_exception_variant (deltype, empty_except_spec);
    5532        76312 :           cxx_build_operator_delete (deltype);
    5533              :         }
    5534              :     }
    5535        97402 : }
    5536              : 
    5537              : /* Create the predefined scalar types of C,
    5538              :    and some nodes representing standard constants (0, 1, (void *)0).
    5539              :    Initialize the global binding level.
    5540              :    Make definitions for built-in primitive functions.  */
    5541              : 
    5542              : void
    5543        97402 : cxx_init_decl_processing (void)
    5544              : {
    5545        97402 :   tree void_ftype;
    5546              : 
    5547              :   /* Create all the identifiers we need.  */
    5548        97402 :   initialize_predefined_identifiers ();
    5549              : 
    5550              :   /* Create the global variables.  */
    5551        97402 :   push_to_top_level ();
    5552              : 
    5553        97402 :   current_function_decl = NULL_TREE;
    5554        97402 :   current_binding_level = NULL;
    5555              :   /* Enter the global namespace.  */
    5556        97402 :   gcc_assert (global_namespace == NULL_TREE);
    5557        97402 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5558              :                                       void_type_node);
    5559        97402 :   TREE_PUBLIC (global_namespace) = true;
    5560        97402 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5561        97402 :   DECL_CONTEXT (global_namespace)
    5562        97402 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5563              :   /* Remember whether we want the empty class passing ABI change warning
    5564              :      in this TU.  */
    5565        97402 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5566       122547 :     = warn_abi && abi_version_crosses (12);
    5567        97402 :   debug_hooks->register_main_translation_unit
    5568        97402 :     (DECL_CONTEXT (global_namespace));
    5569        97402 :   begin_scope (sk_namespace, global_namespace);
    5570        97402 :   current_namespace = global_namespace;
    5571              : 
    5572        97402 :   if (flag_visibility_ms_compat)
    5573            6 :     default_visibility = VISIBILITY_HIDDEN;
    5574              : 
    5575              :   /* Initially, C.  */
    5576        97402 :   current_lang_name = lang_name_c;
    5577              : 
    5578              :   /* Create the `std' namespace.  */
    5579        97402 :   push_namespace (get_identifier ("std"));
    5580        97402 :   std_node = current_namespace;
    5581        97402 :   pop_namespace ();
    5582              : 
    5583        97402 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5584              : 
    5585        97402 :   c_common_nodes_and_builtins ();
    5586              : 
    5587        97402 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5588        97402 :   tree decl
    5589        97402 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5590              :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5591              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5592        97402 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5593              : 
    5594              :   /* The concrete return type of __builtin_source_location is
    5595              :      const std::source_location::__impl*, but we can't form the type
    5596              :      at this point.  So we initially declare it with an auto return
    5597              :      type which we then "deduce" from require_deduced_type upon first use.  */
    5598        97402 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5599        97402 :   decl = add_builtin_function ("__builtin_source_location",
    5600              :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5601              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5602        97402 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5603              : 
    5604        97402 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5605              :                                                         NULL_TREE);
    5606        97402 :   decl
    5607        97402 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5608              :                             bool_vaftype,
    5609              :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5610              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5611        97402 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5612              : 
    5613        97402 :   decl
    5614        97402 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5615              :                             bool_vaftype,
    5616              :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5617              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5618        97402 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5619              : 
    5620        97402 :   if (cxx_dialect >= cxx26)
    5621              :     {
    5622        23466 :       tree void_ptrintftype
    5623        23466 :         = build_function_type_list (void_type_node, ptr_type_node,
    5624              :                                     integer_type_node, NULL_TREE);
    5625        23466 :       decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
    5626              :                                    void_ptrintftype,
    5627              :                                    CP_BUILT_IN_EH_PTR_ADJUST_REF,
    5628              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5629        23466 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5630              :     }
    5631              : 
    5632        97402 :   decl
    5633        97402 :     = add_builtin_function ("__builtin_is_string_literal",
    5634              :                             bool_vaftype,
    5635              :                             CP_BUILT_IN_IS_STRING_LITERAL,
    5636              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5637        97402 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5638              : 
    5639        97402 :   tree void_vaintftype = build_varargs_function_type_list (void_type_node,
    5640              :                                                            integer_type_node,
    5641              :                                                            NULL_TREE);
    5642        97402 :   decl = add_builtin_function ("__builtin_constexpr_diag",
    5643              :                                void_vaintftype,
    5644              :                                CP_BUILT_IN_CONSTEXPR_DIAG,
    5645              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5646        97402 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5647              : 
    5648        97402 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    5649              : 
    5650              :   /* Guess at the initial static decls size.  */
    5651        97402 :   vec_alloc (static_decls, 500);
    5652              : 
    5653              :   /* ... and keyed classes.  */
    5654        97402 :   vec_alloc (keyed_classes, 100);
    5655              : 
    5656        97402 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5657        97402 :   truthvalue_type_node = boolean_type_node;
    5658        97402 :   truthvalue_false_node = boolean_false_node;
    5659        97402 :   truthvalue_true_node = boolean_true_node;
    5660              : 
    5661        97402 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5662        97402 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5663        97402 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5664        97402 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5665              :                                             NULL_TREE);
    5666              : 
    5667              : #if 0
    5668              :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5669              : #endif
    5670              : 
    5671        97402 :   delta_type_node = ptrdiff_type_node;
    5672        97402 :   vtable_index_type = ptrdiff_type_node;
    5673              : 
    5674        97402 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5675        97402 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5676              : 
    5677              :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5678              :      is in the identifier table, so we can use identifier equality to
    5679              :      find it.  */
    5680        97402 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5681              :                                     void_ftype);
    5682              : 
    5683              :   /* C++ extensions */
    5684              : 
    5685        97402 :   unknown_type_node = make_node (LANG_TYPE);
    5686        97402 :   record_unknown_type (unknown_type_node, "unknown type");
    5687              : 
    5688              :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5689        97402 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5690              : 
    5691              :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5692              :      result.  */
    5693        97402 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5694        97402 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5695              : 
    5696        97402 :   init_list_type_node = make_node (LANG_TYPE);
    5697        97402 :   record_unknown_type (init_list_type_node, "init list");
    5698              : 
    5699              :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5700        97402 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5701              : 
    5702        97402 :   {
    5703              :     /* Make sure we get a unique function type, so we can give
    5704              :        its pointer type a name.  (This wins for gdb.) */
    5705        97402 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5706        97402 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5707        97402 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5708        97402 :     layout_type (vfunc_type);
    5709              : 
    5710        97402 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5711              :   }
    5712        97402 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5713              : 
    5714        97402 :   vtbl_type_node
    5715        97402 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5716        97402 :   layout_type (vtbl_type_node);
    5717        97402 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5718        97402 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5719        97402 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5720        97402 :   layout_type (vtbl_ptr_type_node);
    5721        97402 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5722              : 
    5723        97402 :   push_namespace (get_identifier ("__cxxabiv1"));
    5724        97402 :   abi_node = current_namespace;
    5725        97402 :   pop_namespace ();
    5726              : 
    5727        97402 :   any_targ_node = make_node (LANG_TYPE);
    5728        97402 :   record_unknown_type (any_targ_node, "any type");
    5729              : 
    5730              :   /* Now, C++.  */
    5731        97402 :   current_lang_name = lang_name_cplusplus;
    5732              : 
    5733        97402 :   if (aligned_new_threshold > 1
    5734        97402 :       && !pow2p_hwi (aligned_new_threshold))
    5735              :     {
    5736            0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5737              :              aligned_new_threshold);
    5738            0 :       aligned_new_threshold = 1;
    5739              :     }
    5740        97402 :   if (aligned_new_threshold == -1)
    5741       118473 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5742        97402 :   if (aligned_new_threshold == 1)
    5743        76314 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5744              : 
    5745              :   /* Ensure attribs.cc is initialized.  */
    5746        97402 :   init_attributes ();
    5747        97402 :   cxx_init_operator_new_delete_decls ();
    5748              : 
    5749              :   /* C++-specific nullptr initialization.  */
    5750        97402 :   if (abi_version_at_least (9))
    5751        97231 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5752        97402 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5753              : 
    5754        97402 :   if (! supports_one_only ())
    5755            0 :     flag_weak = 0;
    5756              : 
    5757        97402 :   abort_fndecl
    5758        97402 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5759              :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5760        97402 :   if (flag_weak)
    5761              :     /* If no definition is available, resolve references to NULL.  */
    5762        97372 :     declare_weak (abort_fndecl);
    5763              : 
    5764              :   /* Perform other language dependent initializations.  */
    5765        97402 :   init_class_processing ();
    5766        97402 :   init_rtti_processing ();
    5767        97402 :   init_template_processing ();
    5768              : 
    5769        97402 :   if (flag_exceptions)
    5770        96149 :     init_exception_processing ();
    5771              : 
    5772        97402 :   if (flag_contracts)
    5773          134 :     init_contracts ();
    5774              : 
    5775        97402 :   if (modules_p ())
    5776         4709 :     init_modules (parse_in);
    5777              : 
    5778        97402 :   if (flag_reflection)
    5779          498 :     init_reflection ();
    5780              : 
    5781        97402 :   make_fname_decl = cp_make_fname_decl;
    5782        97402 :   start_fname_decls ();
    5783              : 
    5784              :   /* Show we use EH for cleanups.  */
    5785        97402 :   if (flag_exceptions)
    5786        96149 :     using_eh_for_cleanups ();
    5787              : 
    5788              :   /* Check that the hardware interference sizes are at least
    5789              :      alignof(max_align_t), as required by the standard.  */
    5790        97402 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5791        97402 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5792              :     {
    5793            0 :       if (param_destruct_interfere_size < max_align)
    5794            0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5795              :                "%d", param_destruct_interfere_size, max_align);
    5796            0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5797            0 :         warning (OPT_Winterference_size,
    5798              :                  "%<--param destructive-interference-size=%d%> "
    5799              :                  "is less than %<--param l1-cache-line-size=%d%>",
    5800              :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5801              :     }
    5802        97402 :   else if (param_destruct_interfere_size)
    5803              :     /* Assume the internal value is OK.  */;
    5804            0 :   else if (param_l1_cache_line_size >= max_align)
    5805            0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5806              :   /* else leave it unset.  */
    5807              : 
    5808        97402 :   if (OPTION_SET_P (param_construct_interfere_size))
    5809              :     {
    5810            0 :       if (param_construct_interfere_size < max_align)
    5811            0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5812              :                "%d", param_construct_interfere_size, max_align);
    5813            0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5814            0 :                && param_l1_cache_line_size >= max_align)
    5815            0 :         warning (OPT_Winterference_size,
    5816              :                  "%<--param constructive-interference-size=%d%> "
    5817              :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5818              :                  param_construct_interfere_size, param_l1_cache_line_size);
    5819              :     }
    5820        97402 :   else if (param_construct_interfere_size)
    5821              :     /* Assume the internal value is OK.  */;
    5822            0 :   else if (param_l1_cache_line_size >= max_align)
    5823            0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5824        97402 : }
    5825              : 
    5826              : /* Enter an abi node in global-module context.  returns a cookie to
    5827              :    give to pop_abi_namespace.  */
    5828              : 
    5829              : unsigned
    5830        63696 : push_abi_namespace (tree node)
    5831              : {
    5832        63696 :   push_nested_namespace (node);
    5833        63696 :   push_visibility ("default", 2);
    5834        63696 :   unsigned flags = module_kind;
    5835        63696 :   module_kind = 0;
    5836        63696 :   return flags;
    5837              : }
    5838              : 
    5839              : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5840              :    you.  */
    5841              : 
    5842              : void
    5843        63696 : pop_abi_namespace (unsigned flags, tree node)
    5844              : {
    5845        63696 :   module_kind = flags;
    5846        63696 :   pop_visibility (2);
    5847        63696 :   pop_nested_namespace (node);
    5848        63696 : }
    5849              : 
    5850              : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5851              :    the decl, LOC is the location to give the decl, NAME is the
    5852              :    initialization string and TYPE_DEP indicates whether NAME depended
    5853              :    on the type of the function. We make use of that to detect
    5854              :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5855              :    at the point of first use, so we mustn't push the decl now.  */
    5856              : 
    5857              : static tree
    5858       165102 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5859              : {
    5860       165102 :   tree domain = NULL_TREE;
    5861       165102 :   tree init = NULL_TREE;
    5862              : 
    5863       165102 :   if (!(type_dep && current_function_decl && in_template_context))
    5864              :     {
    5865        45408 :       const char *name = NULL;
    5866        45408 :       bool release_name = false;
    5867              : 
    5868        45408 :       if (current_function_decl == NULL_TREE)
    5869              :         name = "top level";
    5870        45394 :       else if (type_dep == 0)
    5871              :         {
    5872              :           /* __FUNCTION__ */
    5873          581 :           name = fname_as_string (type_dep);
    5874          581 :           release_name = true;
    5875              :         }
    5876              :       else
    5877              :         {
    5878              :           /* __PRETTY_FUNCTION__ */
    5879        44813 :           gcc_checking_assert (type_dep == 1);
    5880        44813 :           name = cxx_printable_name (current_function_decl, 2);
    5881              :         }
    5882              : 
    5883        45394 :       if (!release_name)
    5884              :         {
    5885        44827 :           cpp_string cstr = { 0, 0 }, strname;
    5886        44827 :           size_t len = strlen (name) + 3; /* Two for '"'s.  One for NULL.  */
    5887        44827 :           char *namep = XNEWVEC (char, len);
    5888        44827 :           snprintf (namep, len, "\"%s\"", name);
    5889        44827 :           strname.text = (unsigned char *) namep;
    5890        44827 :           strname.len = len - 1;
    5891        44827 :           if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
    5892              :             {
    5893        44827 :               name = (const char *) cstr.text;
    5894        44827 :               release_name = true;
    5895              :             }
    5896              : 
    5897        44827 :           XDELETEVEC (namep);
    5898              :         }
    5899              : 
    5900        45408 :       size_t length = strlen (name);
    5901        45408 :       domain = build_index_type (size_int (length));
    5902        45408 :       init = build_string (length + 1, name);
    5903        45408 :       if (release_name)
    5904        45408 :         free (const_cast<char *> (name));
    5905              :     }
    5906              : 
    5907       165102 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5908       165102 :   type = build_cplus_array_type (type, domain);
    5909              : 
    5910       165102 :   if (init)
    5911        45408 :     TREE_TYPE (init) = type;
    5912              :   else
    5913       119694 :     init = error_mark_node;
    5914              : 
    5915       165102 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5916              : 
    5917       165102 :   TREE_READONLY (decl) = 1;
    5918       165102 :   DECL_ARTIFICIAL (decl) = 1;
    5919       165102 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5920       165102 :   TREE_STATIC (decl) = 1;
    5921              : 
    5922       165102 :   TREE_USED (decl) = 1;
    5923              : 
    5924       165102 :   SET_DECL_VALUE_EXPR (decl, init);
    5925       165102 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5926              :   /* For decl_constant_var_p.  */
    5927       165102 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5928              : 
    5929       165102 :   if (current_function_decl)
    5930              :     {
    5931       165088 :       DECL_CONTEXT (decl) = current_function_decl;
    5932       165088 :       decl = pushdecl_outermost_localscope (decl);
    5933       165088 :       if (decl != error_mark_node)
    5934       165085 :         add_decl_expr (decl);
    5935              :       else
    5936            3 :         gcc_assert (seen_error ());
    5937              :     }
    5938              :   else
    5939              :     {
    5940           14 :       DECL_THIS_STATIC (decl) = true;
    5941           14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5942              :     }
    5943              : 
    5944       165102 :   return decl;
    5945              : }
    5946              : 
    5947              : /* Install DECL as a builtin function at current global scope.  Return
    5948              :    the new decl (if we found an existing version).  Also installs it
    5949              :    into ::std, if it's not '_*'.  */
    5950              : 
    5951              : tree
    5952    225486823 : cxx_builtin_function (tree decl)
    5953              : {
    5954    225486823 :   retrofit_lang_decl (decl);
    5955              : 
    5956    225486823 :   DECL_ARTIFICIAL (decl) = 1;
    5957    225486823 :   SET_DECL_LANGUAGE (decl, lang_c);
    5958              :   /* Runtime library routines are, by definition, available in an
    5959              :      external shared object.  */
    5960    225486823 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5961    225486823 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5962              : 
    5963    225486823 :   tree id = DECL_NAME (decl);
    5964    225486823 :   const char *name = IDENTIFIER_POINTER (id);
    5965    225486823 :   bool hiding = false;
    5966    225486823 :   if (name[0] != '_' || name[1] != '_')
    5967              :     /* In the user's namespace, it must be declared before use.  */
    5968              :     hiding = true;
    5969    189140027 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5970    189140027 :            && !startswith (name + 2, "builtin_")
    5971    211786150 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5972              :                            "_chk", strlen ("_chk") + 1))
    5973              :     /* Treat __*_chk fortification functions as anticipated as well,
    5974              :        unless they are __builtin_*_chk.  */
    5975              :     hiding = true;
    5976              : 
    5977              :   /* All builtins that don't begin with an '_' should additionally
    5978              :      go in the 'std' namespace.  */
    5979    225486823 :   if (name[0] != '_')
    5980              :     {
    5981     36214115 :       tree std_decl = copy_decl (decl);
    5982              : 
    5983     36214115 :       push_nested_namespace (std_node);
    5984     36214115 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    5985     36214115 :       pushdecl (std_decl, hiding);
    5986     36214115 :       pop_nested_namespace (std_node);
    5987              :     }
    5988              : 
    5989    225486823 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5990    225486823 :   decl = pushdecl (decl, hiding);
    5991              : 
    5992    225486823 :   return decl;
    5993              : }
    5994              : 
    5995              : /* Like cxx_builtin_function, but guarantee the function is added to the global
    5996              :    scope.  This is to allow function specific options to add new machine
    5997              :    dependent builtins when the target ISA changes via attribute((target(...)))
    5998              :    which saves space on program startup if the program does not use non-generic
    5999              :    ISAs.  */
    6000              : 
    6001              : tree
    6002       719433 : cxx_builtin_function_ext_scope (tree decl)
    6003              : {
    6004       719433 :   push_nested_namespace (global_namespace);
    6005       719433 :   decl = cxx_builtin_function (decl);
    6006       719433 :   pop_nested_namespace (global_namespace);
    6007              : 
    6008       719433 :   return decl;
    6009              : }
    6010              : 
    6011              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    6012              : 
    6013              : tree
    6014            0 : cxx_simulate_builtin_function_decl (tree decl)
    6015              : {
    6016            0 :   retrofit_lang_decl (decl);
    6017              : 
    6018            0 :   DECL_ARTIFICIAL (decl) = 1;
    6019            0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    6020            0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6021            0 :   return pushdecl (decl);
    6022              : }
    6023              : 
    6024              : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    6025              :    function.  Not called directly.  */
    6026              : 
    6027              : static tree
    6028      1572810 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    6029              :                   int ecf_flags)
    6030              : {
    6031      1572810 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    6032      1572810 :   DECL_EXTERNAL (fn) = 1;
    6033      1572810 :   TREE_PUBLIC (fn) = 1;
    6034      1572810 :   DECL_ARTIFICIAL (fn) = 1;
    6035      1572810 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    6036      1572810 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    6037      1572810 :   SET_DECL_LANGUAGE (fn, lang_c);
    6038              :   /* Runtime library routines are, by definition, available in an
    6039              :      external shared object.  */
    6040      1572810 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    6041      1572810 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    6042      1572810 :   set_call_expr_flags (fn, ecf_flags);
    6043      1572810 :   return fn;
    6044              : }
    6045              : 
    6046              : /* Returns the _DECL for a library function with C++ linkage.  */
    6047              : 
    6048              : static tree
    6049      1098929 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    6050              :                      int ecf_flags)
    6051              : {
    6052      1098929 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    6053      1098929 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    6054      1098929 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    6055      1098929 :   return fn;
    6056              : }
    6057              : 
    6058              : /* Like build_library_fn, but takes a C string instead of an
    6059              :    IDENTIFIER_NODE.  */
    6060              : 
    6061              : tree
    6062       109206 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6063              : {
    6064       109206 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    6065              : }
    6066              : 
    6067              : /* Like build_cp_library_fn, but takes a C string instead of an
    6068              :    IDENTIFIER_NODE.  */
    6069              : 
    6070              : tree
    6071        96233 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6072              : {
    6073        96233 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    6074        96233 :                               ecf_flags);
    6075              : }
    6076              : 
    6077              : /* Like build_library_fn, but also pushes the function so that we will
    6078              :    be able to find it via get_global_binding.  Also, the function
    6079              :    may throw exceptions listed in RAISES.  */
    6080              : 
    6081              : tree
    6082       364675 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    6083              : {
    6084       364675 :   if (raises)
    6085        40258 :     type = build_exception_variant (type, raises);
    6086              : 
    6087       364675 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    6088       364675 :   return pushdecl_top_level (fn);
    6089              : }
    6090              : 
    6091              : /* Like build_cp_library_fn, but also pushes the function so that it
    6092              :    will be found by normal lookup.  */
    6093              : 
    6094              : static tree
    6095      1002696 : push_cp_library_fn (enum tree_code operator_code, tree type,
    6096              :                     int ecf_flags)
    6097              : {
    6098      1002696 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    6099              :                                  operator_code, type, ecf_flags);
    6100      1002696 :   pushdecl (fn);
    6101      1002696 :   if (flag_tm)
    6102         3004 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    6103      1002696 :   return fn;
    6104              : }
    6105              : 
    6106              : /* Like push_library_fn, but also note that this function throws
    6107              :    and does not return.  Used for __throw_foo and the like.  */
    6108              : 
    6109              : tree
    6110       106774 : push_throw_library_fn (tree name, tree type)
    6111              : {
    6112       106774 :   tree fn = push_library_fn (name, type, NULL_TREE,
    6113              :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    6114       106774 :   return fn;
    6115              : }
    6116              : 
    6117              : /* When we call finish_struct for an anonymous union, we create
    6118              :    default copy constructors and such.  But, an anonymous union
    6119              :    shouldn't have such things; this function undoes the damage to the
    6120              :    anonymous union type T.
    6121              : 
    6122              :    (The reason that we create the synthesized methods is that we don't
    6123              :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    6124              :    The first is an anonymous union; the second is just an ordinary
    6125              :    union type.)  */
    6126              : 
    6127              : void
    6128       169872 : fixup_anonymous_aggr (tree t)
    6129              : {
    6130              :   /* Wipe out memory of synthesized methods.  */
    6131       169872 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    6132       169872 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    6133       169872 :   TYPE_HAS_COPY_CTOR (t) = 0;
    6134       169872 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    6135       169872 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    6136       169872 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    6137              : 
    6138              :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    6139              :      invalid members.  */
    6140       994016 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    6141              :     {
    6142       824144 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    6143            0 :         *prev_p = DECL_CHAIN (probe);
    6144              :       else
    6145       824144 :         prev_p = &DECL_CHAIN (probe);
    6146              : 
    6147       824144 :       if (DECL_ARTIFICIAL (probe)
    6148       824144 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    6149        74454 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    6150       278805 :         continue;
    6151              : 
    6152       545339 :       if (TREE_CODE (probe) != FIELD_DECL
    6153       545285 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    6154              :         {
    6155              :           /* We already complained about static data members in
    6156              :              finish_static_data_member_decl.  */
    6157           66 :           if (!VAR_P (probe))
    6158              :             {
    6159           51 :               auto_diagnostic_group d;
    6160           51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    6161           51 :                              TREE_CODE (t) == UNION_TYPE
    6162              :                              ? "%q#D invalid; an anonymous union may "
    6163              :                              "only have public non-static data members"
    6164              :                              : "%q#D invalid; an anonymous struct may "
    6165              :                              "only have public non-static data members", probe))
    6166              :                 {
    6167           51 :                   static bool hint;
    6168           51 :                   if (flag_permissive && !hint)
    6169              :                     {
    6170            6 :                       hint = true;
    6171            6 :                       inform (DECL_SOURCE_LOCATION (probe),
    6172              :                               "this flexibility is deprecated and will be "
    6173              :                               "removed");
    6174              :                     }
    6175              :                 }
    6176           51 :             }
    6177              :         }
    6178              :       }
    6179              : 
    6180              :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    6181       169872 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    6182       169872 :   unsigned store = 0;
    6183       507821 :   for (tree elt : vec)
    6184       337949 :     if (!is_overloaded_fn (elt))
    6185       337928 :       (*vec)[store++] = elt;
    6186       169872 :   vec_safe_truncate (vec, store);
    6187              : 
    6188              :   /* Wipe RTTI info.  */
    6189       169872 :   CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
    6190              : 
    6191              :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    6192              :      assignment operators (because they cannot have these methods themselves).
    6193              :      For anonymous unions this is already checked because they are not allowed
    6194              :      in any union, otherwise we have to check it.  */
    6195       169872 :   if (TREE_CODE (t) != UNION_TYPE)
    6196              :     {
    6197        36585 :       tree field, type;
    6198              : 
    6199        36585 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    6200              :         {
    6201            9 :           error_at (location_of (t), "anonymous struct with base classes");
    6202              :           /* Avoid ICE after error on anon-struct9.C.  */
    6203            9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    6204              :         }
    6205              : 
    6206       147172 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6207       110587 :         if (TREE_CODE (field) == FIELD_DECL)
    6208              :           {
    6209        73901 :             type = TREE_TYPE (field);
    6210        73901 :             if (CLASS_TYPE_P (type))
    6211              :               {
    6212           61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    6213            6 :                   error ("member %q+#D with constructor not allowed "
    6214              :                          "in anonymous aggregate", field);
    6215           61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6216            0 :                   error ("member %q+#D with destructor not allowed "
    6217              :                          "in anonymous aggregate", field);
    6218           61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    6219            0 :                   error ("member %q+#D with copy assignment operator "
    6220              :                          "not allowed in anonymous aggregate", field);
    6221              :               }
    6222              :           }
    6223              :     }
    6224       169872 : }
    6225              : 
    6226              : /* Warn for an attribute located at LOCATION that appertains to the
    6227              :    class type CLASS_TYPE that has not been properly placed after its
    6228              :    class-key, in it class-specifier.  */
    6229              : 
    6230              : void
    6231          109 : warn_misplaced_attr_for_class_type (location_t location,
    6232              :                                     tree class_type)
    6233              : {
    6234          109 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    6235              : 
    6236          109 :   auto_diagnostic_group d;
    6237          109 :   if (warning_at (location, OPT_Wattributes,
    6238              :                   "attribute ignored in declaration "
    6239              :                   "of %q#T", class_type))
    6240          109 :     inform (location,
    6241              :             "attribute for %q#T must follow the %qs keyword",
    6242              :             class_type, class_key_or_enum_as_string (class_type));
    6243          109 : }
    6244              : 
    6245              : /* Returns the cv-qualifiers that apply to the type specified
    6246              :    by the DECLSPECS.  */
    6247              : 
    6248              : static int
    6249   1011991506 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    6250              : {
    6251   1011991506 :   int type_quals = TYPE_UNQUALIFIED;
    6252              : 
    6253   1011991506 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6254    105013500 :     type_quals |= TYPE_QUAL_CONST;
    6255   1011991506 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6256      1659244 :     type_quals |= TYPE_QUAL_VOLATILE;
    6257   1011991506 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6258           34 :     type_quals |= TYPE_QUAL_RESTRICT;
    6259              : 
    6260   1011991506 :   return type_quals;
    6261              : }
    6262              : 
    6263              : /* Make sure that a declaration with no declarator is well-formed, i.e.
    6264              :    just declares a tagged type or anonymous union.
    6265              : 
    6266              :    Returns the type declared; or NULL_TREE if none.  */
    6267              : 
    6268              : tree
    6269     36275325 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    6270              :                 bool explicit_type_instantiation_p)
    6271              : {
    6272     36275325 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    6273     36275325 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    6274              :   /* If a class, struct, or enum type is declared by the DECLSPECS
    6275              :      (i.e, if a class-specifier, enum-specifier, or non-typename
    6276              :      elaborated-type-specifier appears in the DECLSPECS),
    6277              :      DECLARED_TYPE is set to the corresponding type.  */
    6278     36275325 :   tree declared_type = NULL_TREE;
    6279     36275325 :   bool error_p = false;
    6280              : 
    6281     36275325 :   if (declspecs->multiple_types_p)
    6282           26 :     error_at (smallest_type_location (declspecs),
    6283              :               "multiple types in one declaration");
    6284     36275299 :   else if (declspecs->redefined_builtin_type)
    6285              :     {
    6286           21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    6287           21 :       if (!in_system_header_at (loc))
    6288            9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    6289              :                    declspecs->redefined_builtin_type);
    6290           21 :       return NULL_TREE;
    6291              :     }
    6292              : 
    6293     36275304 :   if (declspecs->type
    6294     36275289 :       && TYPE_P (declspecs->type)
    6295     72222276 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    6296     35946240 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    6297      1814007 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    6298              :     declared_type = declspecs->type;
    6299       329109 :   else if (declspecs->type == error_mark_node)
    6300         1463 :     error_p = true;
    6301              : 
    6302     36275304 :   if (type_uses_auto (declared_type))
    6303              :     {
    6304            8 :       error_at (declspecs->locations[ds_type_spec],
    6305              :                 "%<auto%> can only be specified for variables "
    6306              :                 "or function declarations");
    6307            8 :       return error_mark_node;
    6308              :     }
    6309              : 
    6310     36275296 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    6311              :     declared_type = NULL_TREE;
    6312              : 
    6313     36275296 :   if (!declared_type && !saw_friend && !error_p)
    6314           91 :     permerror (input_location, "declaration does not declare anything");
    6315              :   /* Check for an anonymous union.  */
    6316     35946160 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    6317    104710943 :            && TYPE_UNNAMED_P (declared_type))
    6318              :     {
    6319              :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    6320              :          can be omitted only when declaring a class (clause 9) or
    6321              :          enumeration (7.2), that is, when the decl-specifier-seq contains
    6322              :          either a class-specifier, an elaborated-type-specifier with
    6323              :          a class-key (9.1), or an enum-specifier.  In these cases and
    6324              :          whenever a class-specifier or enum-specifier is present in the
    6325              :          decl-specifier-seq, the identifiers in these specifiers are among
    6326              :          the names being declared by the declaration (as class-name,
    6327              :          enum-names, or enumerators, depending on the syntax).  In such
    6328              :          cases, and except for the declaration of an unnamed bit-field (9.6),
    6329              :          the decl-specifier-seq shall introduce one or more names into the
    6330              :          program, or shall redeclare a name introduced by a previous
    6331              :          declaration.  [Example:
    6332              :              enum { };                  // ill-formed
    6333              :              typedef class { };         // ill-formed
    6334              :          --end example]  */
    6335       169878 :       if (saw_typedef)
    6336              :         {
    6337            6 :           error_at (declspecs->locations[ds_typedef],
    6338              :                     "missing type-name in typedef-declaration");
    6339            6 :           return NULL_TREE;
    6340              :         }
    6341       169872 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    6342       169872 :       SET_ANON_AGGR_TYPE_P (declared_type);
    6343              : 
    6344       169872 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    6345        36585 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    6346        36585 :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    6347              :     }
    6348              : 
    6349              :   else
    6350              :     {
    6351     36105327 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    6352            9 :         error_at (declspecs->locations[ds_inline],
    6353              :                   "%<inline%> can only be specified for functions");
    6354     36105318 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    6355            3 :         error_at (declspecs->locations[ds_virtual],
    6356              :                   "%<virtual%> can only be specified for functions");
    6357     36105315 :       else if (saw_friend
    6358     36105315 :                && (!current_class_type
    6359      2007041 :                    || current_scope () != current_class_type))
    6360            0 :         error_at (declspecs->locations[ds_friend],
    6361              :                   "%<friend%> can only be specified inside a class");
    6362     36105315 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    6363            3 :         error_at (declspecs->locations[ds_explicit],
    6364              :                   "%<explicit%> can only be specified for constructors");
    6365     36105312 :       else if (declspecs->storage_class)
    6366            3 :         error_at (declspecs->locations[ds_storage_class],
    6367              :                   "a storage class can only be specified for objects "
    6368              :                   "and functions");
    6369     36105309 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6370            9 :         error_at (declspecs->locations[ds_const],
    6371              :                   "%<const%> can only be specified for objects and "
    6372              :                   "functions");
    6373     36105300 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6374            3 :         error_at (declspecs->locations[ds_volatile],
    6375              :                   "%<volatile%> can only be specified for objects and "
    6376              :                   "functions");
    6377     36105297 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6378            3 :         error_at (declspecs->locations[ds_restrict],
    6379              :                   "%<__restrict%> can only be specified for objects and "
    6380              :                   "functions");
    6381     36105294 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    6382            3 :         error_at (declspecs->locations[ds_thread],
    6383              :                   "%<__thread%> can only be specified for objects "
    6384              :                   "and functions");
    6385     36105291 :       else if (saw_typedef)
    6386           24 :         warning_at (declspecs->locations[ds_typedef], 0,
    6387              :                     "%<typedef%> was ignored in this declaration");
    6388     36105267 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    6389            9 :         error_at (declspecs->locations[ds_constexpr],
    6390              :                   "%qs cannot be used for type declarations", "constexpr");
    6391     36105258 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    6392            3 :         error_at (declspecs->locations[ds_constinit],
    6393              :                   "%qs cannot be used for type declarations", "constinit");
    6394     36105255 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    6395            3 :         error_at (declspecs->locations[ds_consteval],
    6396              :                   "%qs cannot be used for type declarations", "consteval");
    6397              :     }
    6398              : 
    6399     36275290 :   if (declspecs->attributes && warn_attributes && declared_type)
    6400              :     {
    6401           30 :       location_t loc;
    6402           24 :       if (!CLASS_TYPE_P (declared_type)
    6403           54 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    6404              :         /* For a non-template class, use the name location.  */
    6405           21 :         loc = location_of (declared_type);
    6406              :       else
    6407              :         /* For a template class (an explicit instantiation), use the
    6408              :            current location.  */
    6409            9 :         loc = input_location;
    6410              : 
    6411           30 :       if (explicit_type_instantiation_p)
    6412              :         /* [dcl.attr.grammar]/4:
    6413              : 
    6414              :                No attribute-specifier-seq shall appertain to an explicit
    6415              :                instantiation.  */
    6416              :         {
    6417            6 :           auto_diagnostic_group d;
    6418            6 :           if (warning_at (loc, OPT_Wattributes,
    6419              :                           "attribute ignored in explicit instantiation %q#T",
    6420              :                           declared_type))
    6421            6 :             inform (loc,
    6422              :                     "no attribute can be applied to "
    6423              :                     "an explicit instantiation");
    6424            6 :         }
    6425              :       else
    6426           24 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    6427              :     }
    6428              : 
    6429     36275290 :   if (declspecs->std_attributes
    6430           85 :       && declared_type
    6431     36275372 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    6432              :     {
    6433           82 :       auto_diagnostic_group d;
    6434           82 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    6435              :                       "attribute ignored"))
    6436           82 :         inform (declspecs->locations[ds_std_attribute],
    6437              :                 "an attribute that appertains to a type-specifier is ignored");
    6438           82 :     }
    6439              : 
    6440              :   return declared_type;
    6441              : }
    6442              : 
    6443              : /* Called when a declaration is seen that contains no names to declare.
    6444              :    If its type is a reference to a structure, union or enum inherited
    6445              :    from a containing scope, shadow that tag name for the current scope
    6446              :    with a forward reference.
    6447              :    If its type defines a new named structure or union
    6448              :    or defines an enum, it is valid but we need not do anything here.
    6449              :    Otherwise, it is an error.
    6450              : 
    6451              :    C++: may have to grok the declspecs to learn about static,
    6452              :    complain for anonymous unions.
    6453              : 
    6454              :    Returns the TYPE declared -- or NULL_TREE if none.  */
    6455              : 
    6456              : tree
    6457     31763309 : shadow_tag (cp_decl_specifier_seq *declspecs)
    6458              : {
    6459     31763309 :   tree t = check_tag_decl (declspecs,
    6460              :                            /*explicit_type_instantiation_p=*/false);
    6461              : 
    6462     31763309 :   if (!t)
    6463              :     return NULL_TREE;
    6464              : 
    6465     31761832 :   t = maybe_process_partial_specialization (t);
    6466     31761832 :   if (t == error_mark_node)
    6467              :     return NULL_TREE;
    6468              : 
    6469              :   /* This is where the variables in an anonymous union are
    6470              :      declared.  An anonymous union declaration looks like:
    6471              :      union { ... } ;
    6472              :      because there is no declarator after the union, the parser
    6473              :      sends that declaration here.  */
    6474     31759994 :   if (ANON_AGGR_TYPE_P (t))
    6475              :     {
    6476          313 :       fixup_anonymous_aggr (t);
    6477              : 
    6478          313 :       if (TYPE_FIELDS (t))
    6479              :         {
    6480          313 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    6481              :                                       declspecs, NORMAL, 0, NULL);
    6482          313 :           finish_anon_union (decl);
    6483              :         }
    6484              :     }
    6485              : 
    6486              :   return t;
    6487              : }
    6488              : 
    6489              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    6490              : 
    6491              : tree
    6492    394048094 : groktypename (cp_decl_specifier_seq *type_specifiers,
    6493              :               const cp_declarator *declarator,
    6494              :               bool is_template_arg)
    6495              : {
    6496    394048094 :   tree attrs;
    6497    394048094 :   tree type;
    6498     65261644 :   enum decl_context context
    6499    394048094 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    6500    394048094 :   attrs = type_specifiers->attributes;
    6501    394048094 :   type_specifiers->attributes = NULL_TREE;
    6502    394048094 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    6503    394048094 :   if (attrs && type != error_mark_node)
    6504              :     {
    6505          634 :       if (CLASS_TYPE_P (type))
    6506            6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    6507              :                  "outside of definition", type);
    6508          628 :       else if (MAYBE_CLASS_TYPE_P (type))
    6509              :         /* A template type parameter or other dependent type.  */
    6510            9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    6511              :                  "type %qT without an associated declaration", type);
    6512              :       else
    6513          619 :         cplus_decl_attributes (&type, attrs, 0);
    6514              :     }
    6515    394048094 :   return type;
    6516              : }
    6517              : 
    6518              : /* Process a DECLARATOR for a function-scope or namespace-scope
    6519              :    variable or function declaration.
    6520              :    (Function definitions go through start_function; class member
    6521              :    declarations appearing in the body of the class go through
    6522              :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    6523              :    If an error occurs, the error_mark_node is returned instead.
    6524              : 
    6525              :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    6526              :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    6527              :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    6528              :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    6529              :    implicitly initialized via a default constructor.  It can also be
    6530              :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    6531              :    mark the new decl as DECL_DECOMPOSITION_P.
    6532              : 
    6533              :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    6534              :    declaration.
    6535              : 
    6536              :    The scope represented by the context of the returned DECL is pushed
    6537              :    (if it is not the global namespace) and is assigned to
    6538              :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    6539              :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    6540              : 
    6541              : tree
    6542    124615965 : start_decl (const cp_declarator *declarator,
    6543              :             cp_decl_specifier_seq *declspecs,
    6544              :             int initialized,
    6545              :             tree attributes,
    6546              :             tree prefix_attributes,
    6547              :             tree *pushed_scope_p)
    6548              : {
    6549    124615965 :   tree decl;
    6550    124615965 :   tree context;
    6551    124615965 :   bool was_public;
    6552    124615965 :   int flags;
    6553    124615965 :   bool alias;
    6554    124615965 :   tree initial;
    6555              : 
    6556    124615965 :   *pushed_scope_p = NULL_TREE;
    6557              : 
    6558    124615965 :   if (prefix_attributes != error_mark_node)
    6559    124615963 :     attributes = attr_chainon (attributes, prefix_attributes);
    6560              : 
    6561    124615965 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    6562              :                          &attributes);
    6563              : 
    6564    124615965 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    6565    124615965 :       || decl == error_mark_node
    6566    124613829 :       || prefix_attributes == error_mark_node)
    6567         2138 :     return error_mark_node;
    6568              : 
    6569    124613827 :   context = CP_DECL_CONTEXT (decl);
    6570    124613827 :   if (context != global_namespace)
    6571     21574201 :     *pushed_scope_p = push_scope (context);
    6572              : 
    6573    124613827 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    6574              :     {
    6575           27 :       error_at (DECL_SOURCE_LOCATION (decl),
    6576              :                 "typedef %qD is initialized (use %qs instead)",
    6577              :                 decl, "decltype");
    6578           27 :       return error_mark_node;
    6579              :     }
    6580              : 
    6581    124613800 :   if (flag_contracts
    6582        56729 :       && TREE_CODE (decl) == FUNCTION_DECL
    6583        16470 :       && !processing_template_decl
    6584        13021 :       && DECL_RESULT (decl)
    6585    124626761 :       && is_auto (TREE_TYPE (DECL_RESULT (decl))))
    6586            8 :     for (tree ca = get_fn_contract_specifiers (decl); ca; ca = TREE_CHAIN (ca))
    6587            6 :       if (POSTCONDITION_P (CONTRACT_STATEMENT (ca))
    6588            6 :           && POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
    6589              :         {
    6590            2 :           error_at (DECL_SOURCE_LOCATION (decl),
    6591              :                     "postconditions with deduced result name types must only"
    6592              :                     " appear on function definitions");
    6593            2 :           return error_mark_node;
    6594              :         }
    6595              :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    6596              :      with attribute validation.  */
    6597    124613798 :   initial = DECL_INITIAL (decl);
    6598              : 
    6599    124613798 :   if (initialized)
    6600              :     {
    6601     60083816 :       if (! toplevel_bindings_p ()
    6602     60083816 :           && DECL_EXTERNAL (decl))
    6603            3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6604              :                  decl);
    6605     60083816 :       DECL_EXTERNAL (decl) = 0;
    6606     60083816 :       if (toplevel_bindings_p ())
    6607      7091482 :         TREE_STATIC (decl) = 1;
    6608              :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6609              :          even though we might not yet have the initializer expression.  */
    6610     60083816 :       if (!DECL_INITIAL (decl))
    6611     59529616 :         DECL_INITIAL (decl) = error_mark_node;
    6612              :     }
    6613    124613798 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6614              : 
    6615    124613798 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6616         3982 :     record_key_method_defined (decl);
    6617              : 
    6618              :   /* If this is a typedef that names the class for linkage purposes
    6619              :      (7.1.3p8), apply any attributes directly to the type.  */
    6620    124613798 :   if (TREE_CODE (decl) == TYPE_DECL
    6621     21457218 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    6622    133019010 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    6623              :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6624              :   else
    6625              :     flags = 0;
    6626              : 
    6627              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6628    124613798 :   cplus_decl_attributes (&decl, attributes, flags);
    6629              : 
    6630              :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6631              :      assist with attribute validation.  */
    6632    124613798 :   DECL_INITIAL (decl) = initial;
    6633              : 
    6634              :   /* Dllimported symbols cannot be defined.  Static data members (which
    6635              :      can be initialized in-class and dllimported) go through grokfield,
    6636              :      not here, so we don't need to exclude those decls when checking for
    6637              :      a definition.  */
    6638    124613798 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6639              :     {
    6640            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6641              :                 "definition of %q#D is marked %<dllimport%>", decl);
    6642            0 :       DECL_DLLIMPORT_P (decl) = 0;
    6643              :     }
    6644              : 
    6645              :   /* If #pragma weak was used, mark the decl weak now.  */
    6646    124613798 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6647     45680075 :     maybe_apply_pragma_weak (decl);
    6648              : 
    6649    124613798 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6650     36978343 :       && DECL_DECLARED_INLINE_P (decl)
    6651      3142422 :       && DECL_UNINLINABLE (decl)
    6652    124613798 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6653              :     {
    6654            0 :       auto_urlify_attributes sentinel;
    6655            0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6656              :                   "inline function %qD given attribute %qs", decl, "noinline");
    6657            0 :     }
    6658              : 
    6659    124613798 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6660              :     {
    6661       833364 :       bool this_tmpl = (current_template_depth
    6662       833364 :                         > template_class_depth (context));
    6663       833364 :       if (VAR_P (decl))
    6664              :         {
    6665       482977 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6666       482977 :           if (field == NULL_TREE
    6667       482977 :               || !(VAR_P (field) || variable_template_p (field)))
    6668            6 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6669       482971 :           else if (variable_template_p (field)
    6670       482971 :                    && (DECL_LANG_SPECIFIC (decl)
    6671          123 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6672              :             /* OK, specialization was already checked.  */;
    6673       482902 :           else if (variable_template_p (field) && !this_tmpl)
    6674              :             {
    6675            3 :               auto_diagnostic_group d;
    6676            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6677              :                         "non-member-template declaration of %qD", decl);
    6678            3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6679              :                       "member template declaration here");
    6680            3 :               return error_mark_node;
    6681            3 :             }
    6682              :           else
    6683              :             {
    6684       482899 :               if (variable_template_p (field))
    6685           51 :                 field = DECL_TEMPLATE_RESULT (field);
    6686              : 
    6687       482899 :               if (DECL_CONTEXT (field) != context)
    6688              :                 {
    6689            3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6690            3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6691              :                                "to be defined as %<%T::%D%>",
    6692            3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6693            3 :                                context, DECL_NAME (decl));
    6694            3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6695              :                 }
    6696              :               /* Static data member are tricky; an in-class initialization
    6697              :                  still doesn't provide a definition, so the in-class
    6698              :                  declaration will have DECL_EXTERNAL set, but will have an
    6699              :                  initialization.  Thus, duplicate_decls won't warn
    6700              :                  about this situation, and so we check here.  */
    6701       482899 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6702            9 :                 error ("duplicate initialization of %qD", decl);
    6703       482899 :               field = duplicate_decls (decl, field);
    6704       482899 :               if (field == error_mark_node)
    6705              :                 return error_mark_node;
    6706       482843 :               else if (field)
    6707       482843 :                 decl = field;
    6708              :             }
    6709              :         }
    6710              :       else
    6711              :         {
    6712       350399 :           tree field = check_classfn (context, decl,
    6713              :                                       this_tmpl
    6714           12 :                                       ? current_template_parms
    6715              :                                       : NULL_TREE);
    6716       350312 :           if (field && field != error_mark_node
    6717       700699 :               && duplicate_decls (decl, field))
    6718       350312 :             decl = field;
    6719              :         }
    6720              : 
    6721              :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6722       833305 :       DECL_IN_AGGR_P (decl) = 0;
    6723              :       /* Do not mark DECL as an explicit specialization if it was not
    6724              :          already marked as an instantiation; a declaration should
    6725              :          never be marked as a specialization unless we know what
    6726              :          template is being specialized.  */
    6727       833305 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6728              :         {
    6729       348479 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6730       348479 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6731       328390 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6732       328390 :                                   && DECL_NONGNU_INLINE_P (decl));
    6733              :           else
    6734        20089 :             DECL_COMDAT (decl) = false;
    6735              : 
    6736              :           /* [temp.expl.spec] An explicit specialization of a static data
    6737              :              member of a template is a definition if the declaration
    6738              :              includes an initializer; otherwise, it is a declaration.
    6739              : 
    6740              :              We check for processing_specialization so this only applies
    6741              :              to the new specialization syntax.  */
    6742       348479 :           if (!initialized && processing_specialization)
    6743       348277 :             DECL_EXTERNAL (decl) = 1;
    6744              :         }
    6745              : 
    6746      1181630 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6747              :           /* Aliases are definitions. */
    6748       833341 :           && !alias)
    6749              :         {
    6750            9 :           permerror (declarator->id_loc,
    6751              :                        "declaration of %q#D outside of class is not definition",
    6752              :                        decl);
    6753              :         }
    6754              :     }
    6755              : 
    6756              :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6757    124613739 :   if (initialized == SD_DECOMPOSITION)
    6758       448810 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6759              : 
    6760    124613739 :   was_public = TREE_PUBLIC (decl);
    6761              : 
    6762    212239324 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6763    125167963 :       && current_function_decl)
    6764              :     {
    6765              :       /* A function-scope decl of some namespace-scope decl.  */
    6766        59595 :       DECL_LOCAL_DECL_P (decl) = true;
    6767        59595 :       if (named_module_attach_p ())
    6768            3 :         error_at (declarator->id_loc,
    6769              :                   "block-scope extern declaration %q#D must not be"
    6770              :                   " attached to a named module", decl);
    6771              :     }
    6772              : 
    6773              :   /* Enter this declaration into the symbol table.  Don't push the plain
    6774              :      VAR_DECL for a variable template.  */
    6775    124613739 :   if (!template_parm_scope_p ()
    6776    124613739 :       || !VAR_P (decl))
    6777    120683293 :     decl = maybe_push_decl (decl);
    6778              : 
    6779    124613739 :   if (processing_template_decl)
    6780     78928494 :     decl = push_template_decl (decl);
    6781              : 
    6782    124613739 :   if (decl == error_mark_node)
    6783              :     return error_mark_node;
    6784              : 
    6785    124613313 :   if (VAR_P (decl)
    6786     66177940 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6787        66953 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6788              :       /* But not templated variables.  */
    6789    124641508 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6790              :     {
    6791              :       /* This is a const variable with implicit 'static'.  Set
    6792              :          DECL_THIS_STATIC so we can tell it from variables that are
    6793              :          !TREE_PUBLIC because of the anonymous namespace.  */
    6794        28195 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6795        28195 :       DECL_THIS_STATIC (decl) = 1;
    6796              :     }
    6797              : 
    6798     70432186 :   if (current_function_decl && VAR_P (decl)
    6799     58289160 :       && maybe_constexpr_fn (current_function_decl)
    6800    139063432 :       && cxx_dialect < cxx23)
    6801              :     {
    6802     12502223 :       bool ok = false;
    6803     12502223 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6804              :         {
    6805            9 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6806           18 :             error_at (DECL_SOURCE_LOCATION (decl),
    6807              :                       "%qD defined %<thread_local%> in %qs function only "
    6808              :                       "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6809            9 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6810              :                       ? "consteval" : "constexpr");
    6811              :         }
    6812     12502214 :       else if (TREE_STATIC (decl))
    6813              :         {
    6814           50 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6815           72 :             error_at (DECL_SOURCE_LOCATION (decl),
    6816              :                       "%qD defined %<static%> in %qs function only available "
    6817              :                       "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6818           36 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6819              :                       ? "consteval" : "constexpr");
    6820              :         }
    6821              :       else
    6822              :         ok = true;
    6823           45 :       if (!ok)
    6824           59 :         cp_function_chain->invalid_constexpr = true;
    6825              :     }
    6826              : 
    6827    124613313 :   if (!processing_template_decl && VAR_P (decl))
    6828      8337450 :     start_decl_1 (decl, initialized);
    6829              : 
    6830    124613310 :   return decl;
    6831              : }
    6832              : 
    6833              : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6834              :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6835              :    variable is initialized via an implicitly-called constructor.)
    6836              :    This function must be called for ordinary variables (including, for
    6837              :    example, implicit instantiations of templates), but must not be
    6838              :    called for template declarations.  */
    6839              : 
    6840              : void
    6841      8345556 : start_decl_1 (tree decl, bool initialized)
    6842              : {
    6843      8345556 :   gcc_checking_assert (!processing_template_decl);
    6844              : 
    6845      8345556 :   if (error_operand_p (decl))
    6846              :     return;
    6847              : 
    6848      8345541 :   gcc_checking_assert (VAR_P (decl));
    6849              : 
    6850      8345541 :   tree type = TREE_TYPE (decl);
    6851      8345541 :   bool complete_p = COMPLETE_TYPE_P (type);
    6852      8345541 :   bool aggregate_definition_p
    6853      8345541 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6854              : 
    6855              :   /* If an explicit initializer is present, or if this is a definition
    6856              :      of an aggregate, then we need a complete type at this point.
    6857              :      (Scalars are always complete types, so there is nothing to
    6858              :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6859              :      are issued below.  */
    6860      4316684 :   if ((initialized || aggregate_definition_p)
    6861      7338847 :       && !complete_p
    6862      5922099 :       && COMPLETE_TYPE_P (complete_type (type)))
    6863              :     {
    6864       326555 :       complete_p = true;
    6865              :       /* We will not yet have set TREE_READONLY on DECL if the type
    6866              :          was "const", but incomplete, before this point.  But, now, we
    6867              :          have a complete type, so we can try again.  */
    6868       326555 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6869              :     }
    6870              : 
    6871      8345538 :   if (initialized)
    6872              :     /* Is it valid for this decl to have an initializer at all?  */
    6873              :     {
    6874              :       /* Don't allow initializations for incomplete types except for
    6875              :          arrays which might be completed by the initialization.  */
    6876      6609894 :       if (complete_p)
    6877              :         ;                       /* A complete type is ok.  */
    6878      1278623 :       else if (type_uses_auto (type))
    6879              :         ;                       /* An auto type is ok.  */
    6880       119017 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6881              :         {
    6882           27 :           auto_diagnostic_group d;
    6883           27 :           error ("variable %q#D has initializer but incomplete type", decl);
    6884           48 :           maybe_suggest_missing_header (input_location,
    6885           27 :                                         TYPE_IDENTIFIER (type),
    6886           27 :                                         CP_TYPE_CONTEXT (type));
    6887           27 :           type = TREE_TYPE (decl) = error_mark_node;
    6888           27 :         }
    6889       118990 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6890              :         {
    6891            0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6892            0 :             error ("elements of array %q#D have incomplete type", decl);
    6893              :           /* else we already gave an error in start_decl.  */
    6894              :         }
    6895              :     }
    6896      1735644 :   else if (aggregate_definition_p && !complete_p)
    6897              :     {
    6898          234 :       if (type_uses_auto (type))
    6899           69 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6900              :       else
    6901              :         {
    6902          165 :           auto_diagnostic_group d;
    6903          165 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6904              :                  decl);
    6905          285 :           maybe_suggest_missing_header (input_location,
    6906          165 :                                         TYPE_IDENTIFIER (type),
    6907          165 :                                         CP_TYPE_CONTEXT (type));
    6908              :           /* Change the type so that assemble_variable will give
    6909              :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6910          165 :           type = TREE_TYPE (decl) = error_mark_node;
    6911          165 :         }
    6912              :     }
    6913              : 
    6914              :   /* Create a new scope to hold this declaration if necessary.
    6915              :      Whether or not a new scope is necessary cannot be determined
    6916              :      until after the type has been completed; if the type is a
    6917              :      specialization of a class template it is not until after
    6918              :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6919              :      will be set correctly.  */
    6920      8345538 :   maybe_push_cleanup_level (type);
    6921              : }
    6922              : 
    6923              : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6924              :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6925              : 
    6926              : tree
    6927          295 : do_aggregate_paren_init (tree init, tree type)
    6928              : {
    6929          295 :   tree val = TREE_VALUE (init);
    6930              : 
    6931          295 :   if (TREE_CHAIN (init) == NULL_TREE)
    6932              :     {
    6933              :       /* If the list has a single element and it's a string literal,
    6934              :          then it's the initializer for the array as a whole.  */
    6935          179 :       if (TREE_CODE (type) == ARRAY_TYPE
    6936          179 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6937          225 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6938              :              == STRING_CST)
    6939              :         return val;
    6940              :       /* Handle non-standard extensions like compound literals.  This also
    6941              :          prevents triggering aggregate parenthesized-initialization in
    6942              :          compiler-generated code for =default.  */
    6943          140 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6944          140 :                                                           TREE_TYPE (val)))
    6945              :         return val;
    6946              :     }
    6947              : 
    6948          200 :   init = build_constructor_from_list (init_list_type_node, init);
    6949          200 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6950          200 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6951          200 :   return init;
    6952              : }
    6953              : 
    6954              : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6955              :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6956              :    but will be set to a new CLEANUP_STMT if a temporary is created
    6957              :    that must be destroyed subsequently.
    6958              : 
    6959              :    Returns an initializer expression to use to initialize DECL, or
    6960              :    NULL if the initialization can be performed statically.
    6961              : 
    6962              :    Quotes on semantics can be found in ARM 8.4.3.  */
    6963              : 
    6964              : static tree
    6965       557671 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6966              : {
    6967       557671 :   if (init == NULL_TREE)
    6968              :     {
    6969           15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6970            3 :            || DECL_IN_AGGR_P (decl) == 0)
    6971           18 :           && ! DECL_THIS_EXTERN (decl))
    6972           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    6973              :                   "%qD declared as reference but not initialized", decl);
    6974           15 :       return NULL_TREE;
    6975              :     }
    6976              : 
    6977       557656 :   tree ttype = TREE_TYPE (type);
    6978       557656 :   if (TREE_CODE (init) == TREE_LIST)
    6979              :     {
    6980              :       /* This handles (C++20 only) code like
    6981              : 
    6982              :            const A& r(1, 2, 3);
    6983              : 
    6984              :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    6985         1161 :       if (TREE_TYPE (init) == NULL_TREE
    6986         1161 :           && CP_AGGREGATE_TYPE_P (ttype)
    6987           69 :           && !DECL_DECOMPOSITION_P (decl)
    6988         1227 :           && (cxx_dialect >= cxx20))
    6989              :         {
    6990              :           /* We don't know yet if we should treat const A& r(1) as
    6991              :              const A& r{1}.  */
    6992           60 :           if (list_length (init) == 1)
    6993              :             {
    6994           39 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    6995           39 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    6996              :                                                       tf_warning_or_error);
    6997              :             }
    6998              :           /* If the list had more than one element, the code is ill-formed
    6999              :              pre-C++20, so we can build a constructor right away.  */
    7000              :           else
    7001           21 :             init = do_aggregate_paren_init (init, ttype);
    7002              :         }
    7003              :       else
    7004         1101 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    7005              :                                                 tf_warning_or_error);
    7006              :     }
    7007              : 
    7008       557656 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    7009       557656 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    7010              :     /* Note: default conversion is only called in very special cases.  */
    7011           12 :     init = decay_conversion (init, tf_warning_or_error);
    7012              : 
    7013              :   /* check_initializer handles this for non-reference variables, but for
    7014              :      references we need to do it here or the initializer will get the
    7015              :      incomplete array type and confuse later calls to
    7016              :      cp_complete_array_type.  */
    7017       557656 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    7018        22269 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    7019       557739 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    7020           50 :           || TREE_CODE (init) == STRING_CST))
    7021              :     {
    7022           33 :       cp_complete_array_type (&ttype, init, false);
    7023           33 :       if (ttype != TREE_TYPE (type))
    7024           33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    7025              :     }
    7026              : 
    7027              :   /* Convert INIT to the reference type TYPE.  This may involve the
    7028              :      creation of a temporary, whose lifetime must be the same as that
    7029              :      of the reference.  If so, a DECL_EXPR for the temporary will be
    7030              :      added just after the DECL_EXPR for DECL.  That's why we don't set
    7031              :      DECL_INITIAL for local references (instead assigning to them
    7032              :      explicitly); we need to allow the temporary to be initialized
    7033              :      first.  */
    7034       557656 :   return initialize_reference (type, init, flags,
    7035       557656 :                                tf_warning_or_error);
    7036              : }
    7037              : 
    7038              : /* Designated initializers in arrays are not supported in GNU C++.
    7039              :    The parser cannot detect this error since it does not know whether
    7040              :    a given brace-enclosed initializer is for a class type or for an
    7041              :    array.  This function checks that CE does not use a designated
    7042              :    initializer.  If it does, an error is issued.  Returns true if CE
    7043              :    is valid, i.e., does not have a designated initializer.  */
    7044              : 
    7045              : bool
    7046    147410415 : check_array_designated_initializer (constructor_elt *ce,
    7047              :                                     unsigned HOST_WIDE_INT index)
    7048              : {
    7049              :   /* Designated initializers for array elements are not supported.  */
    7050    147410415 :   if (ce->index)
    7051              :     {
    7052              :       /* The parser only allows identifiers as designated
    7053              :          initializers.  */
    7054     99464968 :       if (ce->index == error_mark_node)
    7055              :         {
    7056            0 :           error ("name used in a GNU-style designated "
    7057              :                  "initializer for an array");
    7058            0 :           return false;
    7059              :         }
    7060     99464968 :       else if (identifier_p (ce->index))
    7061              :         {
    7062           19 :           error ("name %qD used in a GNU-style designated "
    7063              :                  "initializer for an array", ce->index);
    7064           19 :           ce->index = error_mark_node;
    7065           19 :           return false;
    7066              :         }
    7067              : 
    7068     99464949 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    7069              :                                                   ce->index, true);
    7070     99464949 :       if (ce_index
    7071     99464946 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    7072    198929892 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    7073              :               == INTEGER_CST))
    7074              :         {
    7075              :           /* A C99 designator is OK if it matches the current index.  */
    7076     99464943 :           if (wi::to_wide (ce_index) == index)
    7077              :             {
    7078     99464937 :               ce->index = ce_index;
    7079     99464937 :               return true;
    7080              :             }
    7081              :           else
    7082            6 :             sorry ("non-trivial designated initializers not supported");
    7083              :         }
    7084              :       else
    7085            6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    7086              :                   "C99 designator %qE is not an integral constant-expression",
    7087              :                   ce->index);
    7088              : 
    7089           12 :       return false;
    7090              :     }
    7091              : 
    7092              :   return true;
    7093              : }
    7094              : 
    7095              : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    7096              :    array until we finish parsing the initializer.  If that's the
    7097              :    situation we're in, update DECL accordingly.  */
    7098              : 
    7099              : static void
    7100     83229752 : maybe_deduce_size_from_array_init (tree decl, tree init)
    7101              : {
    7102     83229752 :   tree type = TREE_TYPE (decl);
    7103              : 
    7104     83229752 :   if (TREE_CODE (type) == ARRAY_TYPE
    7105      1031379 :       && TYPE_DOMAIN (type) == NULL_TREE
    7106     83909072 :       && TREE_CODE (decl) != TYPE_DECL)
    7107              :     {
    7108              :       /* do_default is really a C-ism to deal with tentative definitions.
    7109              :          But let's leave it here to ease the eventual merge.  */
    7110       679320 :       int do_default = !DECL_EXTERNAL (decl);
    7111       679320 :       tree initializer = init ? init : DECL_INITIAL (decl);
    7112       679320 :       int failure = 0;
    7113              : 
    7114              :       /* Check that there are no designated initializers in INIT, as
    7115              :          those are not supported in GNU C++, and as the middle-end
    7116              :          will crash if presented with a non-numeric designated
    7117              :          initializer.  */
    7118       679320 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    7119              :         {
    7120       140212 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    7121       140212 :           constructor_elt *ce;
    7122       140212 :           HOST_WIDE_INT i, j = 0;
    7123     46218080 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    7124              :             {
    7125     46078573 :               if (instantiation_dependent_expression_p (ce->index))
    7126     83229752 :                 return;
    7127     46078567 :               if (!check_array_designated_initializer (ce, j))
    7128            1 :                 failure = 1;
    7129              :               /* If an un-designated initializer is type-dependent, we can't
    7130              :                  check brace elision yet.  */
    7131     46078567 :               if (ce->index == NULL_TREE
    7132     46078567 :                   && type_dependent_expression_p (ce->value))
    7133              :                 return;
    7134     46077868 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7135          196 :                 j += RAW_DATA_LENGTH (ce->value);
    7136              :               else
    7137     46077672 :                 ++j;
    7138              :             }
    7139              :         }
    7140              : 
    7141       139507 :       if (failure)
    7142            1 :         TREE_TYPE (decl) = error_mark_node;
    7143              :       else
    7144              :         {
    7145       678614 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    7146              :                                             do_default);
    7147       678614 :           if (failure == 1)
    7148              :             {
    7149           33 :               error_at (cp_expr_loc_or_loc (initializer,
    7150           30 :                                          DECL_SOURCE_LOCATION (decl)),
    7151              :                         "initializer fails to determine size of %qD", decl);
    7152              :             }
    7153       678584 :           else if (failure == 2)
    7154              :             {
    7155           30 :               if (do_default)
    7156              :                 {
    7157            6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    7158              :                             "array size missing in %qD", decl);
    7159              :                 }
    7160              :               /* If a `static' var's size isn't known, make it extern as
    7161              :                  well as static, so it does not get allocated.  If it's not
    7162              :                  `static', then don't mark it extern; finish_incomplete_decl
    7163              :                  will give it a default size and it will get allocated.  */
    7164           24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    7165            0 :                 DECL_EXTERNAL (decl) = 1;
    7166              :             }
    7167       678554 :           else if (failure == 3)
    7168              :             {
    7169            6 :               error_at (DECL_SOURCE_LOCATION (decl),
    7170              :                         "zero-size array %qD", decl);
    7171              :             }
    7172              :         }
    7173              : 
    7174       678615 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    7175              : 
    7176       678615 :       relayout_decl (decl);
    7177              : 
    7178              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    7179       678615 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7180              :         {
    7181          208 :           tree tmpl = template_for_substitution (decl);
    7182          208 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    7183           50 :             TREE_TYPE (tmpl) = TREE_TYPE (decl);
    7184              :         }
    7185              :     }
    7186              : }
    7187              : 
    7188              : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    7189              :    any appropriate error messages regarding the layout.  */
    7190              : 
    7191              : static void
    7192     73910718 : layout_var_decl (tree decl)
    7193              : {
    7194     73910718 :   tree type;
    7195              : 
    7196     73910718 :   type = TREE_TYPE (decl);
    7197     73910718 :   if (type == error_mark_node)
    7198              :     return;
    7199              : 
    7200              :   /* If we haven't already laid out this declaration, do so now.
    7201              :      Note that we must not call complete type for an external object
    7202              :      because it's type might involve templates that we are not
    7203              :      supposed to instantiate yet.  (And it's perfectly valid to say
    7204              :      `extern X x' for some incomplete type `X'.)  */
    7205     73910671 :   if (!DECL_EXTERNAL (decl))
    7206     63486729 :     complete_type (type);
    7207     73910671 :   if (!DECL_SIZE (decl)
    7208       598134 :       && TREE_TYPE (decl) != error_mark_node
    7209     74508805 :       && complete_or_array_type_p (type))
    7210       455401 :     layout_decl (decl, 0);
    7211              : 
    7212     73910671 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    7213              :     {
    7214              :       /* An automatic variable with an incomplete type: that is an error.
    7215              :          Don't talk about array types here, since we took care of that
    7216              :          message in grokdeclarator.  */
    7217           17 :       error_at (DECL_SOURCE_LOCATION (decl),
    7218              :                 "storage size of %qD isn%'t known", decl);
    7219           17 :       TREE_TYPE (decl) = error_mark_node;
    7220              :     }
    7221              : #if 0
    7222              :   /* Keep this code around in case we later want to control debug info
    7223              :      based on whether a type is "used".  (jason 1999-11-11) */
    7224              : 
    7225              :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    7226              :     /* Let debugger know it should output info for this type.  */
    7227              :     note_debug_info_needed (ttype);
    7228              : 
    7229              :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    7230              :     note_debug_info_needed (DECL_CONTEXT (decl));
    7231              : #endif
    7232              : 
    7233    137397400 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    7234     43065516 :       && DECL_SIZE (decl) != NULL_TREE
    7235    116705016 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    7236              :     {
    7237            6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7238            6 :           && !DECL_LOCAL_DECL_P (decl))
    7239            0 :         constant_expression_warning (DECL_SIZE (decl));
    7240              :       else
    7241              :         {
    7242            6 :           error_at (DECL_SOURCE_LOCATION (decl),
    7243              :                     "storage size of %qD isn%'t constant", decl);
    7244            6 :           TREE_TYPE (decl) = error_mark_node;
    7245            6 :           type = error_mark_node;
    7246              :         }
    7247              :     }
    7248              : 
    7249              :   /* If the final element initializes a flexible array field, adjust
    7250              :      the size of the DECL with the initializer based on whether the
    7251              :      DECL is a union or a structure.  */
    7252     73910671 :   if (type != error_mark_node
    7253     73910665 :       && DECL_INITIAL (decl)
    7254     42990785 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    7255      6092128 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    7256      4248416 :       && DECL_SIZE (decl) != NULL_TREE
    7257      4248416 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7258      4248416 :       && COMPLETE_TYPE_P (type)
    7259      4248416 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    7260     78159087 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    7261              :     {
    7262      4248416 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    7263      4248416 :       if (elt.index)
    7264              :         {
    7265      2005633 :           tree itype = TREE_TYPE (elt.index);
    7266      2005633 :           tree vtype = TREE_TYPE (elt.value);
    7267      2005633 :           if (TREE_CODE (itype) == ARRAY_TYPE
    7268        79811 :               && TYPE_DOMAIN (itype) == NULL
    7269          275 :               && TREE_CODE (vtype) == ARRAY_TYPE
    7270      2005908 :               && COMPLETE_TYPE_P (vtype))
    7271              :             {
    7272              :               /* For a structure, add the size of the initializer to the DECL's
    7273              :                  size.  */
    7274          275 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    7275              :                 {
    7276          260 :                   DECL_SIZE (decl)
    7277          260 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    7278              :                                   TYPE_SIZE (vtype));
    7279          260 :                   DECL_SIZE_UNIT (decl)
    7280          520 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    7281              :                                   TYPE_SIZE_UNIT (vtype));
    7282              :                 }
    7283              :               /* For a union, the DECL's size is the maximum of the current size
    7284              :                  and the size of the initializer.  */
    7285              :               else
    7286              :                 {
    7287           15 :                   DECL_SIZE (decl)
    7288           15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    7289              :                                   TYPE_SIZE (vtype));
    7290           15 :                   DECL_SIZE_UNIT (decl)
    7291           30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    7292              :                                   TYPE_SIZE_UNIT (vtype));
    7293              :                 }
    7294              :             }
    7295              :         }
    7296              :     }
    7297              : }
    7298              : 
    7299              : /* If a local static variable is declared in an inline function, or if
    7300              :    we have a weak definition, we must endeavor to create only one
    7301              :    instance of the variable at link-time.  */
    7302              : 
    7303              : void
    7304     92760516 : maybe_commonize_var (tree decl)
    7305              : {
    7306              :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    7307              :      bindings.  */
    7308     92760516 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    7309              :     return;
    7310              : 
    7311              :   /* Static data in a function with comdat linkage also has comdat
    7312              :      linkage.  */
    7313     87199616 :   if ((TREE_STATIC (decl)
    7314     56150270 :        && DECL_FUNCTION_SCOPE_P (decl)
    7315       168015 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    7316    199617627 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    7317              :     {
    7318     49518554 :       if (flag_weak)
    7319              :         {
    7320              :           /* With weak symbols, we simply make the variable COMDAT;
    7321              :              that will cause copies in multiple translations units to
    7322              :              be merged.  */
    7323     49518527 :           comdat_linkage (decl);
    7324              :         }
    7325              :       else
    7326              :         {
    7327           27 :           if (DECL_INITIAL (decl) == NULL_TREE
    7328           27 :               || DECL_INITIAL (decl) == error_mark_node)
    7329              :             {
    7330              :               /* Without weak symbols, we can use COMMON to merge
    7331              :                  uninitialized variables.  */
    7332           24 :               TREE_PUBLIC (decl) = 1;
    7333           24 :               DECL_COMMON (decl) = 1;
    7334              :             }
    7335              :           else
    7336              :             {
    7337              :               /* While for initialized variables, we must use internal
    7338              :                  linkage -- which means that multiple copies will not
    7339              :                  be merged.  */
    7340            3 :               TREE_PUBLIC (decl) = 0;
    7341            3 :               DECL_COMMON (decl) = 0;
    7342            3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    7343            3 :               const char *msg;
    7344            3 :               if (DECL_INLINE_VAR_P (decl))
    7345              :                 msg = G_("sorry: semantics of inline variable "
    7346              :                          "%q#D are wrong (you%'ll wind up with "
    7347              :                          "multiple copies)");
    7348              :               else
    7349              :                 msg = G_("sorry: semantics of inline function "
    7350              :                          "static data %q#D are wrong (you%'ll wind "
    7351              :                          "up with multiple copies)");
    7352            3 :               auto_diagnostic_group d;
    7353            3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    7354              :                               msg, decl))
    7355            3 :                 inform (DECL_SOURCE_LOCATION (decl),
    7356              :                         "you can work around this by removing the initializer");
    7357            3 :             }
    7358              :         }
    7359              :     }
    7360              : }
    7361              : 
    7362              : /* Issue an error message if DECL is an uninitialized const variable.
    7363              :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    7364              :    context from potential_constant_expression.  Returns true if all is well,
    7365              :    false otherwise.  */
    7366              : 
    7367              : bool
    7368     11879003 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    7369              :                                    tsubst_flags_t complain)
    7370              : {
    7371     11879003 :   tree type = strip_array_types (TREE_TYPE (decl));
    7372              : 
    7373              :   /* ``Unless explicitly declared extern, a const object does not have
    7374              :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    7375              :      7.1.6 */
    7376     11879003 :   if (VAR_P (decl)
    7377     11879003 :       && !TYPE_REF_P (type)
    7378     11820510 :       && (CP_TYPE_CONST_P (type)
    7379              :           /* C++20 permits trivial default initialization in constexpr
    7380              :              context (P1331R2).  */
    7381      9574625 :           || (cxx_dialect < cxx20
    7382       136336 :               && (constexpr_context_p
    7383       122989 :                   || var_in_constexpr_fn (decl))))
    7384     14140314 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    7385              :     {
    7386       623174 :       tree field = default_init_uninitialized_part (type);
    7387       623174 :       if (!field)
    7388              :         return true;
    7389              : 
    7390         3899 :       auto_diagnostic_group d;
    7391         3899 :       bool show_notes = true;
    7392              : 
    7393         3899 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    7394              :         {
    7395          173 :           if (CP_TYPE_CONST_P (type))
    7396              :             {
    7397           90 :               if (complain & tf_error)
    7398           84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    7399              :                                         "uninitialized %<const %D%>", decl);
    7400              :             }
    7401              :           else
    7402              :             {
    7403           83 :               if (!is_instantiation_of_constexpr (current_function_decl)
    7404           83 :                   && (complain & tf_error))
    7405           21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    7406              :                           "uninitialized variable %qD in %<constexpr%> "
    7407              :                           "function", decl);
    7408              :               else
    7409              :                 show_notes = false;
    7410           83 :               cp_function_chain->invalid_constexpr = true;
    7411              :             }
    7412              :         }
    7413         3726 :       else if (complain & tf_error)
    7414            2 :         error_at (DECL_SOURCE_LOCATION (decl),
    7415              :                   "uninitialized variable %qD in %<constexpr%> context",
    7416              :                   decl);
    7417              : 
    7418         3899 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    7419              :         {
    7420           62 :           tree defaulted_ctor;
    7421              : 
    7422           62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    7423              :                   "%q#T has no user-provided default constructor", type);
    7424           62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    7425           62 :           if (defaulted_ctor)
    7426           33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    7427              :                     "constructor is not user-provided because it is "
    7428              :                     "explicitly defaulted in the class body");
    7429           62 :           inform (DECL_SOURCE_LOCATION (field),
    7430              :                   "and the implicitly-defined constructor does not "
    7431              :                   "initialize %q#D", field);
    7432              :         }
    7433              : 
    7434         3899 :       return false;
    7435         3899 :     }
    7436              : 
    7437              :   return true;
    7438              : }
    7439              : 
    7440              : /* Structure holding the current initializer being processed by reshape_init.
    7441              :    CUR is a pointer to the current element being processed, END is a pointer
    7442              :    after the last element present in the initializer and RAW_IDX is index into
    7443              :    RAW_DATA_CST if that is CUR elt.  */
    7444              : struct reshape_iter
    7445              : {
    7446              :   constructor_elt *cur;
    7447              :   constructor_elt *end;
    7448              :   unsigned raw_idx;
    7449              : };
    7450              : 
    7451              : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    7452              : 
    7453              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7454              :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    7455              :    initialized as if for an aggregate class.  If there are no more such fields,
    7456              :    the return value will be NULL.  */
    7457              : 
    7458              : tree
    7459     16610195 : next_aggregate_field (tree field)
    7460              : {
    7461     16610195 :   while (field
    7462     64677977 :          && (TREE_CODE (field) != FIELD_DECL
    7463     10875258 :              || DECL_UNNAMED_BIT_FIELD (field)
    7464     10875103 :              || (DECL_ARTIFICIAL (field)
    7465              :                  /* In C++17, aggregates can have bases.  */
    7466       160959 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    7467     48067782 :     field = DECL_CHAIN (field);
    7468              : 
    7469     16610195 :   return field;
    7470              : }
    7471              : 
    7472              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7473              :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    7474              :    to a subobject.  If there are no more such fields, the return value will be
    7475              :    NULL.  */
    7476              : 
    7477              : tree
    7478     76978330 : next_subobject_field (tree field)
    7479              : {
    7480     76978330 :   while (field
    7481    980535583 :          && (TREE_CODE (field) != FIELD_DECL
    7482     36660162 :              || DECL_UNNAMED_BIT_FIELD (field)
    7483     36660030 :              || (DECL_ARTIFICIAL (field)
    7484      8709752 :                  && !DECL_FIELD_IS_BASE (field)
    7485      1849717 :                  && !DECL_VIRTUAL_P (field))))
    7486    903557253 :     field = DECL_CHAIN (field);
    7487              : 
    7488     76978330 :   return field;
    7489              : }
    7490              : 
    7491              : /* Return true for [dcl.init.list] direct-list-initialization from
    7492              :    single element of enumeration with a fixed underlying type.  */
    7493              : 
    7494              : bool
    7495    198322192 : is_direct_enum_init (tree type, tree init)
    7496              : {
    7497    198322192 :   if (cxx_dialect >= cxx17
    7498    196277345 :       && TREE_CODE (type) == ENUMERAL_TYPE
    7499      8735115 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    7500      6393039 :       && TREE_CODE (init) == CONSTRUCTOR
    7501       527674 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    7502       324508 :       && CONSTRUCTOR_NELTS (init) == 1
    7503          208 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    7504              :       /* DR 2374: The single element needs to be implicitly
    7505              :          convertible to the underlying type of the enum.  */
    7506          208 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    7507    198322398 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    7508          206 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    7509          206 :                           CONSTRUCTOR_ELT (init, 0)->value,
    7510              :                           LOOKUP_IMPLICIT, tf_none))
    7511              :     return true;
    7512              :   return false;
    7513              : }
    7514              : 
    7515              : /* Helper function for reshape_init*.  Split first element of
    7516              :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    7517              :    to true if the whole d->cur has been consumed.  */
    7518              : 
    7519              : static tree
    7520     60157206 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    7521              : {
    7522     60157206 :   *inc_cur = true;
    7523     60157206 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    7524              :     return NULL_TREE;
    7525        30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    7526        30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    7527        30588 :     *inc_cur = false;
    7528              :   else
    7529          132 :     d->raw_idx = 0;
    7530              :   return ret;
    7531              : }
    7532              : 
    7533              : /* Wrapper around that which for RAW_DATA_CST in INIT
    7534              :    (as well as in D->cur->value) peels off the first element
    7535              :    of the raw data and returns it, otherwise increments
    7536              :    D->cur and returns INIT.  */
    7537              : 
    7538              : static tree
    7539     60157190 : consume_init (tree init, reshape_iter *d)
    7540              : {
    7541     60157190 :   bool inc_cur;
    7542     60157190 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7543        30720 :     init = raw_init;
    7544     60157190 :   if (inc_cur)
    7545     60126602 :     d->cur++;
    7546     60157190 :   return init;
    7547              : }
    7548              : 
    7549              : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    7550              :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    7551              :    INTEGER_CST representing the size of the array minus one (the maximum index),
    7552              :    or NULL_TREE if the array was declared without specifying the size. D is
    7553              :    the iterator within the constructor.  */
    7554              : 
    7555              : static tree
    7556       468804 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    7557              :                       tree first_initializer_p, bool vector_p,
    7558              :                       tsubst_flags_t complain)
    7559              : {
    7560       468804 :   tree new_init;
    7561       468804 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    7562       468804 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    7563       468804 :   unsigned HOST_WIDE_INT index;
    7564              : 
    7565              :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    7566              :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    7567              :      to build a new one.  But don't reuse if not complaining; if this is
    7568              :      tentative, we might also reshape to another type (95319).  */
    7569       468804 :   bool reuse = (first_initializer_p
    7570       415917 :                 && (complain & tf_error)
    7571       414699 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    7572       821774 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    7573       120293 :   if (reuse)
    7574              :     new_init = first_initializer_p;
    7575              :   else
    7576       120293 :     new_init = build_constructor (init_list_type_node, NULL);
    7577              : 
    7578       468804 :   if (sized_array_p)
    7579              :     {
    7580       289029 :       poly_uint64 midx;
    7581              :       /* Minus 1 is used for zero sized arrays.  */
    7582       289029 :       if (integer_all_onesp (max_index))
    7583           24 :         return new_init;
    7584              : 
    7585       289005 :       if (tree_fits_poly_uint64_p (max_index))
    7586       289005 :         midx = tree_to_poly_uint64 (max_index);
    7587              :       /* sizetype is sign extended, not zero extended.  */
    7588              :       else
    7589            0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    7590              : 
    7591              :       /* For VLA vectors, we restict the number of elements in the constructor
    7592              :          to lower bound of the VLA elements.  */
    7593       289005 :       max_index_cst = constant_lower_bound (midx);
    7594              :     }
    7595              : 
    7596       468780 :   constructor_elt *first_cur = d->cur;
    7597              :   /* Loop until there are no more initializers.  */
    7598     53911902 :   for (index = 0;
    7599     53911902 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    7600              :        ++index)
    7601              :     {
    7602     53443302 :       tree elt_init;
    7603     53443302 :       constructor_elt *old_cur = d->cur;
    7604     53443302 :       unsigned int old_raw_idx = d->raw_idx;
    7605     53443302 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    7606              : 
    7607     53443302 :       if (d->cur->index)
    7608      5518822 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7609     53443302 :       check_array_designated_initializer (d->cur, index);
    7610     53443302 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7611        32706 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7612        10233 :               || is_byte_access_type (elt_type))
    7613        22473 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7614         1812 :           && (!sized_array_p || index < max_index_cst)
    7615     53445102 :           && !vector_p)
    7616              :         {
    7617          480 :           elt_init = d->cur->value;
    7618          480 :           unsigned int off = d->raw_idx;
    7619          480 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7620          480 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7621              :             {
    7622          471 :               d->cur++;
    7623          471 :               d->raw_idx = 0;
    7624              :             }
    7625              :           else
    7626              :             {
    7627            9 :               len = max_index_cst - index + 1;
    7628            9 :               d->raw_idx += len;
    7629              :             }
    7630          480 :           if (!reuse || off || d->cur == old_cur)
    7631              :             {
    7632           27 :               elt_init = copy_node (elt_init);
    7633           27 :               RAW_DATA_LENGTH (elt_init) = len;
    7634           27 :               RAW_DATA_POINTER (elt_init) += off;
    7635              :             }
    7636          480 :           TREE_TYPE (elt_init) = elt_type;
    7637              :         }
    7638              :       else
    7639     53442822 :         elt_init = reshape_init_r (elt_type, d,
    7640              :                                    /*first_initializer_p=*/NULL_TREE,
    7641              :                                    complain);
    7642     53443302 :       if (elt_init == error_mark_node)
    7643              :         return error_mark_node;
    7644     53443125 :       tree idx = size_int (index);
    7645     53443125 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7646              :         {
    7647              :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7648              :              ctor had to be split.  */
    7649           72 :           new_init = build_constructor (init_list_type_node, NULL);
    7650           72 :           if (index)
    7651              :             {
    7652           72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7653           72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7654           72 :                       (d->cur - first_cur)
    7655              :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7656           72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7657              :                 {
    7658              :                   unsigned int j;
    7659              :                   tree nidx, nval;
    7660            4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7661              :                                             j, nidx, nval)
    7662            4 :                     if (nidx)
    7663              :                       {
    7664            4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7665            4 :                         (void) nval;
    7666            4 :                         break;
    7667              :                       }
    7668              :                 }
    7669              :             }
    7670              :           reuse = false;
    7671              :         }
    7672     53443053 :       if (reuse)
    7673              :         {
    7674     52304613 :           old_cur->index = idx;
    7675     52304613 :           old_cur->value = elt_init;
    7676              :         }
    7677              :       else
    7678      1138512 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7679              :                                 idx, elt_init);
    7680     53443125 :       if (!TREE_CONSTANT (elt_init))
    7681       192310 :         TREE_CONSTANT (new_init) = false;
    7682              : 
    7683              :       /* This can happen with an invalid initializer (c++/54501).  */
    7684     53443125 :       if (d->cur == old_cur
    7685        32082 :           && !sized_array_p
    7686        14085 :           && d->raw_idx == old_raw_idx)
    7687              :         break;
    7688              : 
    7689     53443122 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7690          480 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7691              :     }
    7692              : 
    7693              :   return new_init;
    7694              : }
    7695              : 
    7696              : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7697              :    Parameters are the same of reshape_init_r.  */
    7698              : 
    7699              : static tree
    7700       422625 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7701              :                     tsubst_flags_t complain)
    7702              : {
    7703       422625 :   tree max_index = NULL_TREE;
    7704              : 
    7705       422625 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7706              : 
    7707       422625 :   if (TYPE_DOMAIN (type))
    7708       242898 :     max_index = array_type_nelts_minus_one (type);
    7709              : 
    7710       422625 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7711       422625 :                                first_initializer_p, false, complain);
    7712              : }
    7713              : 
    7714              : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7715              :    Parameters are the same of reshape_init_r.  */
    7716              : 
    7717              : static tree
    7718        46179 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7719              : {
    7720        46179 :   tree max_index = NULL_TREE;
    7721              : 
    7722        46179 :   gcc_assert (VECTOR_TYPE_P (type));
    7723              : 
    7724        46179 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7725              :     {
    7726            0 :       tree value = d->cur->value;
    7727            0 :       if (!same_type_p (TREE_TYPE (value), type))
    7728              :         {
    7729            0 :           if (complain & tf_error)
    7730            0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7731            0 :                    TREE_TYPE (d->cur->value), type);
    7732            0 :           value = error_mark_node;
    7733              :         }
    7734            0 :       ++d->cur;
    7735            0 :       return value;
    7736              :     }
    7737              : 
    7738              :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7739        46179 :   if (VECTOR_TYPE_P (type))
    7740        46179 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7741              : 
    7742        46179 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7743        46179 :                                NULL_TREE, true, complain);
    7744              : }
    7745              : 
    7746              : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7747              :    INIT, in isolation from any designator or other initializers.  */
    7748              : 
    7749              : static tree
    7750      1447815 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7751              : {
    7752              :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7753              :      calling reshape_init, but this way can just live on the stack.  */
    7754      1447815 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7755      1447815 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7756      1447815 :   return reshape_init_r (type, &iter,
    7757              :                          /*first_initializer_p=*/NULL_TREE,
    7758      1447815 :                          complain);
    7759              : }
    7760              : 
    7761              : /* Subroutine of reshape_init_r, processes the initializers for classes
    7762              :    or union. Parameters are the same of reshape_init_r.  */
    7763              : 
    7764              : static tree
    7765      3813562 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7766              :                     tsubst_flags_t complain)
    7767              : {
    7768      3813562 :   tree field;
    7769      3813562 :   tree new_init;
    7770              : 
    7771      3813562 :   gcc_assert (CLASS_TYPE_P (type));
    7772              : 
    7773              :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7774      3813562 :   new_init = build_constructor (init_list_type_node, NULL);
    7775              : 
    7776      3813562 :   int binfo_idx = -1;
    7777      3813562 :   tree binfo = TYPE_BINFO (type);
    7778      3813562 :   tree base_binfo = NULL_TREE;
    7779      3813562 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7780              :     {
    7781              :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7782              :          deduction.  In this case we need to look through the binfo because a
    7783              :          template doesn't have base fields.  */
    7784          943 :       binfo_idx = 0;
    7785          943 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7786              :     }
    7787           67 :   if (base_binfo)
    7788              :     field = base_binfo;
    7789              :   else
    7790      3813495 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7791              : 
    7792      3813562 :   if (!field)
    7793              :     {
    7794              :       /* [dcl.init.aggr]
    7795              : 
    7796              :         An initializer for an aggregate member that is an
    7797              :         empty class shall have the form of an empty
    7798              :         initializer-list {}.  */
    7799          322 :       if (!first_initializer_p)
    7800              :         {
    7801          268 :           if (complain & tf_error)
    7802           13 :             error ("initializer for %qT must be brace-enclosed", type);
    7803          268 :           return error_mark_node;
    7804              :         }
    7805              :       return new_init;
    7806              :     }
    7807              : 
    7808              :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7809              :   tree last_was_pack_expansion = NULL_TREE;
    7810              : 
    7811              :   /* Loop through the initializable fields, gathering initializers.  */
    7812     11706007 :   while (d->cur != d->end)
    7813              :     {
    7814      7996573 :       tree field_init;
    7815      7996573 :       constructor_elt *old_cur = d->cur;
    7816      7996573 :       unsigned old_raw_idx = d->raw_idx;
    7817      7996573 :       bool direct_desig = false;
    7818              : 
    7819              :       /* Handle C++20 designated initializers.  */
    7820      7996573 :       if (d->cur->index)
    7821              :         {
    7822      1447981 :           if (d->cur->index == error_mark_node)
    7823              :             return error_mark_node;
    7824              : 
    7825      1447975 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7826              :             {
    7827              :               /* We already reshaped this; we should have returned early from
    7828              :                  reshape_init.  */
    7829            0 :               gcc_checking_assert (false);
    7830              :               if (field != d->cur->index)
    7831              :                 {
    7832              :                   if (tree id = DECL_NAME (d->cur->index))
    7833              :                     gcc_checking_assert (d->cur->index
    7834              :                                          == get_class_binding (type, id));
    7835              :                   field = d->cur->index;
    7836              :                 }
    7837              :             }
    7838      1447975 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7839              :             {
    7840      1447969 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7841      1447969 :               field = get_class_binding (type, d->cur->index);
    7842      1447969 :               direct_desig = true;
    7843              :             }
    7844              :           else
    7845              :             {
    7846            6 :               if (complain & tf_error)
    7847            6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7848              :                        " for class %qT", d->cur->index, type);
    7849            6 :               return error_mark_node;
    7850              :             }
    7851              : 
    7852      1447969 :           if (!field && ANON_AGGR_TYPE_P (type))
    7853              :             /* Apparently the designator isn't for a member of this anonymous
    7854              :                struct, so head back to the enclosing class.  */
    7855              :             break;
    7856              : 
    7857      1447966 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    7858              :             {
    7859           18 :               if (complain & tf_error)
    7860              :                 {
    7861            6 :                   if (field && TREE_CODE (field) == TREE_LIST)
    7862              :                     {
    7863            3 :                       auto_diagnostic_group g;
    7864            3 :                       error ("request for member %qD is ambiguous",
    7865            3 :                              d->cur->index);
    7866            3 :                       print_candidates (input_location, field);
    7867            3 :                     }
    7868              :                   else
    7869            3 :                     error ("%qT has no non-static data member named %qD", type,
    7870            3 :                            d->cur->index);
    7871              :                 }
    7872           18 :               return error_mark_node;
    7873              :             }
    7874              : 
    7875              :           /* If the element is an anonymous union object and the initializer
    7876              :              list is a designated-initializer-list, the anonymous union object
    7877              :              is initialized by the designated-initializer-list { D }, where D
    7878              :              is the designated-initializer-clause naming a member of the
    7879              :              anonymous union object.  */
    7880      1447948 :           tree ictx = DECL_CONTEXT (field);
    7881      1447948 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    7882              :             {
    7883              :               /* Find the anon aggr that is a direct member of TYPE.  */
    7884          146 :               while (ANON_AGGR_TYPE_P (ictx))
    7885              :                 {
    7886          143 :                   tree cctx = TYPE_CONTEXT (ictx);
    7887          143 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    7888          130 :                     goto found;
    7889              :                   ictx = cctx;
    7890              :                 }
    7891              : 
    7892              :               /* Not found, e.g. FIELD is a member of a base class.  */
    7893            3 :               if (complain & tf_error)
    7894            3 :                 error ("%qD is not a direct member of %qT", field, type);
    7895            3 :               return error_mark_node;
    7896              : 
    7897          130 :             found:
    7898              :               /* Now find the TYPE member with that anon aggr type.  */
    7899          130 :               tree aafield = TYPE_FIELDS (type);
    7900         1110 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    7901         1110 :                 if (TREE_TYPE (aafield) == ictx)
    7902              :                   break;
    7903            0 :               gcc_assert (aafield);
    7904              :               field = aafield;
    7905              :               direct_desig = false;
    7906              :             }
    7907              :         }
    7908              : 
    7909              :       /* If we processed all the member of the class, we are done.  */
    7910      7996407 :       if (!field)
    7911              :         break;
    7912              : 
    7913     15992153 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    7914      7996086 :                                  ? field : NULL_TREE);
    7915      7996086 :       if (last_was_pack_expansion)
    7916              :         /* Each non-trailing aggregate element that is a pack expansion is
    7917              :            assumed to correspond to no elements of the initializer list.  */
    7918           19 :         goto continue_;
    7919              : 
    7920      7996067 :       if (direct_desig)
    7921              :         {
    7922              :           /* The designated field F is initialized from this one element.
    7923              : 
    7924              :              Note that we don't want to do this if we found the designator
    7925              :              inside an anon aggr above; we use the normal code to implement:
    7926              : 
    7927              :              "If the element is an anonymous union member and the initializer
    7928              :              list is a brace-enclosed designated- initializer-list, the element
    7929              :              is initialized by the designated-initializer-list { D }, where D
    7930              :              is the designated- initializer-clause naming a member of the
    7931              :              anonymous union member."  */
    7932      1447815 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    7933      1447815 :           field_init = reshape_single_init (TREE_TYPE (field),
    7934              :                                             d->cur->value, complain);
    7935      1447815 :           d->cur++;
    7936              :         }
    7937              :       else
    7938      6548252 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    7939              :                                      /*first_initializer_p=*/NULL_TREE,
    7940              :                                      complain);
    7941              : 
    7942      7996067 :       if (field_init == error_mark_node)
    7943              :         return error_mark_node;
    7944              : 
    7945      7995780 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    7946              :         {
    7947              :           /* This can happen with an invalid initializer for a flexible
    7948              :              array member (c++/54441).  */
    7949            0 :           if (complain & tf_error)
    7950            0 :             error ("invalid initializer for %q#D", field);
    7951            0 :           return error_mark_node;
    7952              :         }
    7953              : 
    7954      7995780 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    7955              : 
    7956              :       /* [dcl.init.aggr]
    7957              : 
    7958              :         When a union  is  initialized with a brace-enclosed
    7959              :         initializer, the braces shall only contain an
    7960              :         initializer for the first member of the union.  */
    7961      7995780 :       if (TREE_CODE (type) == UNION_TYPE)
    7962              :         break;
    7963              : 
    7964      7892748 :     continue_:
    7965      7892767 :       if (base_binfo)
    7966              :         {
    7967           82 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    7968              :             field = base_binfo;
    7969              :           else
    7970           35 :             field = next_aggregate_field (TYPE_FIELDS (type));
    7971              :         }
    7972              :       else
    7973      7892685 :         field = next_aggregate_field (DECL_CHAIN (field));
    7974              :     }
    7975              : 
    7976              :   /* A trailing aggregate element that is a pack expansion is assumed to
    7977              :      correspond to all remaining elements of the initializer list (if any).  */
    7978      3812920 :   if (last_was_pack_expansion)
    7979              :     {
    7980           16 :       tree init = d->cur->value;
    7981           16 :       bool inc_cur;
    7982           16 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7983            0 :         init = raw_init;
    7984           16 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7985              :                               last_was_pack_expansion, init);
    7986           46 :       while (d->cur != d->end)
    7987           30 :         d->cur++;
    7988              :     }
    7989              : 
    7990              :   return new_init;
    7991              : }
    7992              : 
    7993              : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    7994              :    designators are not valid; either complain or return true to indicate
    7995              :    that reshape_init_r should return error_mark_node.  */
    7996              : 
    7997              : static bool
    7998       238875 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    7999              : {
    8000       238875 :   if (d->cur->index)
    8001              :     {
    8002           30 :       if (complain & tf_error)
    8003           45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    8004              :                   "C99 designator %qE outside aggregate initializer",
    8005              :                   d->cur->index);
    8006              :       else
    8007              :         return true;
    8008              :     }
    8009              :   return false;
    8010              : }
    8011              : 
    8012              : /* Subroutine of reshape_init, which processes a single initializer (part of
    8013              :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    8014              :    iterator within the CONSTRUCTOR which points to the initializer to process.
    8015              :    If this is the first initializer of the outermost CONSTRUCTOR node,
    8016              :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    8017              : 
    8018              : static tree
    8019     65952479 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    8020              :                 tsubst_flags_t complain)
    8021              : {
    8022     65952479 :   tree init = d->cur->value;
    8023              : 
    8024     65952479 :   if (error_operand_p (init))
    8025          126 :     return error_mark_node;
    8026              : 
    8027      4513467 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    8028     66191049 :       && has_designator_problem (d, complain))
    8029            0 :     return error_mark_node;
    8030              : 
    8031     65952353 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    8032              : 
    8033     65952353 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    8034              :     {
    8035              :       /* A complex type can be initialized from one or two initializers,
    8036              :          but braces are not elided.  */
    8037          675 :       init = consume_init (init, d);
    8038          675 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    8039              :         {
    8040            9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    8041              :             {
    8042            0 :               if (complain & tf_error)
    8043            0 :                 error ("too many initializers for %qT", type);
    8044              :               else
    8045            0 :                 return error_mark_node;
    8046              :             }
    8047              :         }
    8048          666 :       else if (first_initializer_p && d->cur != d->end)
    8049              :         {
    8050           36 :           if (error_operand_p (d->cur->value)
    8051           36 :               || has_designator_problem (d, complain))
    8052            0 :             return error_mark_node;
    8053           36 :           vec<constructor_elt, va_gc> *v = 0;
    8054           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8055           36 :           init = consume_init (d->cur->value, d);
    8056           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8057           36 :           init = build_constructor (init_list_type_node, v);
    8058              :         }
    8059          675 :       return init;
    8060              :     }
    8061              : 
    8062              :   /* A non-aggregate type is always initialized with a single
    8063              :      initializer.  */
    8064    131848376 :   if (!CP_AGGREGATE_TYPE_P (type)
    8065              :       /* As is an array with dependent bound, which we can see
    8066              :          during C++20 aggregate CTAD.  */
    8067     71696000 :       || (cxx_dialect >= cxx20
    8068      5694356 :           && TREE_CODE (type) == ARRAY_TYPE
    8069       513294 :           && uses_template_parms (TYPE_DOMAIN (type))))
    8070              :     {
    8071              :       /* It is invalid to initialize a non-aggregate type with a
    8072              :          brace-enclosed initializer before C++0x.
    8073              :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    8074              :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    8075              :          a CONSTRUCTOR (with a record type).  */
    8076     60152387 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    8077              :           /* Don't complain about a capture-init.  */
    8078       290950 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    8079     60433584 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    8080              :         {
    8081       281158 :           if (SCALAR_TYPE_P (type))
    8082              :             {
    8083          476 :               if (cxx_dialect < cxx11)
    8084              :                 {
    8085           16 :                   if (complain & tf_error)
    8086           16 :                     error ("braces around scalar initializer for type %qT",
    8087              :                            type);
    8088           16 :                   init = error_mark_node;
    8089              :                 }
    8090          460 :               else if (first_initializer_p
    8091          460 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    8092          296 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    8093              :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    8094              :                 {
    8095           13 :                   if (complain & tf_error)
    8096           13 :                     error ("too many braces around scalar initializer "
    8097              :                            "for type %qT", type);
    8098           13 :                   init = error_mark_node;
    8099              :                 }
    8100              :             }
    8101              :           else
    8102       280682 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8103              :         }
    8104     60152387 :       return consume_init (init, d);
    8105              :     }
    8106              : 
    8107              :   /* "If T is a class type and the initializer list has a single element of
    8108              :      type cv U, where U is T or a class derived from T, the object is
    8109              :      initialized from that element."  Even if T is an aggregate.  */
    8110      5775337 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    8111      5236535 :       && first_initializer_p
    8112              :       /* But not if it's a designated init.  */
    8113      3844279 :       && !d->cur->index
    8114      3274663 :       && d->end - d->cur == 1
    8115       576244 :       && TREE_CODE (init) != RAW_DATA_CST
    8116      6375535 :       && reference_related_p (type, TREE_TYPE (init)))
    8117              :     {
    8118          416 :       d->cur++;
    8119          416 :       return init;
    8120              :     }
    8121              : 
    8122              :   /* [dcl.init.aggr]
    8123              : 
    8124              :      All implicit type conversions (clause _conv_) are considered when
    8125              :      initializing the aggregate member with an initializer from an
    8126              :      initializer-list.  If the initializer can initialize a member,
    8127              :      the member is initialized.  Otherwise, if the member is itself a
    8128              :      non-empty subaggregate, brace elision is assumed and the
    8129              :      initializer is considered for the initialization of the first
    8130              :      member of the subaggregate.  */
    8131      2204484 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    8132              :       /* But don't try this for the first initializer, since that would be
    8133              :          looking through the outermost braces; A a2 = { a1 }; is not a
    8134              :          valid aggregate initialization.  */
    8135      3594454 :       && !first_initializer_p
    8136      5811873 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    8137         8942 :           || can_convert_arg (type, TREE_TYPE (init),
    8138         8942 :                               TREE_CODE (init) == RAW_DATA_CST
    8139      5800481 :                               ? build_int_cst (integer_type_node,
    8140         1606 :                                                *(const unsigned char *)
    8141         1606 :                                                RAW_DATA_POINTER (init))
    8142              :                               : init,
    8143              :                               LOOKUP_NORMAL, complain)))
    8144         4092 :     return consume_init (init, d);
    8145              : 
    8146              :   /* [dcl.init.string]
    8147              : 
    8148              :       A char array (whether plain char, signed char, or unsigned char)
    8149              :       can be initialized by a string-literal (optionally enclosed in
    8150              :       braces); a wchar_t array can be initialized by a wide
    8151              :       string-literal (optionally enclosed in braces).  */
    8152      5794783 :   if (TREE_CODE (type) == ARRAY_TYPE
    8153      5794783 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    8154              :     {
    8155       138432 :       tree str_init = init;
    8156       138432 :       tree stripped_str_init = stripped_init;
    8157       138432 :       reshape_iter stripd = {};
    8158              : 
    8159              :       /* Strip one level of braces if and only if they enclose a single
    8160              :          element (as allowed by [dcl.init.string]).  */
    8161       138432 :       if (!first_initializer_p
    8162        11775 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    8163       149086 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    8164              :         {
    8165          392 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    8166          392 :           str_init = stripd.cur->value;
    8167          392 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    8168              :         }
    8169              : 
    8170              :       /* If it's a string literal, then it's the initializer for the array
    8171              :          as a whole. Otherwise, continue with normal initialization for
    8172              :          array types (one value per array element).  */
    8173       138432 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    8174              :         {
    8175           72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    8176         1062 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    8177          990 :             return error_mark_node;
    8178          990 :           d->cur++;
    8179          990 :           return str_init;
    8180              :         }
    8181              :     }
    8182              : 
    8183              :   /* The following cases are about aggregates. If we are not within a full
    8184              :      initializer already, and there is not a CONSTRUCTOR, it means that there
    8185              :      is a missing set of braces (that is, we are processing the case for
    8186              :      which reshape_init exists).  */
    8187      5793793 :   bool braces_elided_p = false;
    8188      5793793 :   if (!first_initializer_p)
    8189              :     {
    8190      1519510 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    8191              :         {
    8192      1511458 :           tree init_type = TREE_TYPE (init);
    8193      1511458 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    8194              :             /* There is no need to call reshape_init for pointer-to-member
    8195              :                function initializers, as they are always constructed correctly
    8196              :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    8197              :                which is missing outermost braces.  We should warn below, and
    8198              :                one of the routines below will wrap it in additional { }.  */;
    8199              :           /* For a nested compound literal, proceed to specialized routines,
    8200              :              to handle initialization of arrays and similar.  */
    8201      1511449 :           else if (COMPOUND_LITERAL_P (stripped_init))
    8202            7 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8203              :           /* If we have an unresolved designator, we need to find the member it
    8204              :              designates within TYPE, so proceed to the routines below.  For
    8205              :              FIELD_DECL or INTEGER_CST designators, we're already initializing
    8206              :              the designated element.  */
    8207      1511442 :           else if (d->cur->index
    8208           30 :                    && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    8209              :             /* Brace elision with designators is only permitted for anonymous
    8210              :                aggregates.  */
    8211           15 :             gcc_checking_assert (ANON_AGGR_TYPE_P (type));
    8212              :           /* A CONSTRUCTOR of the target's type is a previously
    8213              :              digested initializer.  */
    8214      1511427 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    8215              :             {
    8216            0 :               ++d->cur;
    8217            0 :               return init;
    8218              :             }
    8219              :           else
    8220              :             {
    8221              :               /* Something that hasn't been reshaped yet.  */
    8222      1511427 :               ++d->cur;
    8223      1511427 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8224      1511427 :               return reshape_init (type, init, complain);
    8225              :             }
    8226              :         }
    8227              : 
    8228         8083 :       if (complain & tf_warning)
    8229         6936 :         warning (OPT_Wmissing_braces,
    8230              :                  "missing braces around initializer for %qT",
    8231              :                  type);
    8232              :       braces_elided_p = true;
    8233              :     }
    8234              : 
    8235              :   /* Dispatch to specialized routines.  */
    8236      4282366 :   tree new_init;
    8237      4282366 :   if (CLASS_TYPE_P (type))
    8238      3813562 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    8239       468804 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    8240       422625 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    8241        46179 :   else if (VECTOR_TYPE_P (type))
    8242        46179 :     new_init = reshape_init_vector (type, d, complain);
    8243              :   else
    8244            0 :     gcc_unreachable ();
    8245              : 
    8246      4282366 :   if (braces_elided_p
    8247         8083 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    8248         7809 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    8249              : 
    8250              :   return new_init;
    8251              : }
    8252              : 
    8253              : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    8254              :    brace-enclosed aggregate initializer.
    8255              : 
    8256              :    INIT is the CONSTRUCTOR containing the list of initializers describing
    8257              :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    8258              :    It may not presently match the shape of the TYPE; for example:
    8259              : 
    8260              :      struct S { int a; int b; };
    8261              :      struct S a[] = { 1, 2, 3, 4 };
    8262              : 
    8263              :    Here INIT will hold a vector of four elements, rather than a
    8264              :    vector of two elements, each itself a vector of two elements.  This
    8265              :    routine transforms INIT from the former form into the latter.  The
    8266              :    revised CONSTRUCTOR node is returned.  */
    8267              : 
    8268              : tree
    8269     12943926 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    8270              : {
    8271     12943926 :   vec<constructor_elt, va_gc> *v;
    8272     12943926 :   reshape_iter d;
    8273     12943926 :   tree new_init;
    8274              : 
    8275     12943926 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    8276              : 
    8277     12943926 :   v = CONSTRUCTOR_ELTS (init);
    8278              : 
    8279              :   /* An empty constructor does not need reshaping, and it is always a valid
    8280              :      initializer.  */
    8281     12944662 :   if (vec_safe_is_empty (v))
    8282              :     return init;
    8283              : 
    8284      4514526 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    8285              :     /* Already reshaped.  */
    8286              :     return init;
    8287              : 
    8288              :   /* Brace elision is not performed for a CONSTRUCTOR representing
    8289              :      parenthesized aggregate initialization.  */
    8290      4514389 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    8291              :     {
    8292          633 :       tree elt = (*v)[0].value;
    8293              :       /* If we're initializing a char array from a string-literal that is
    8294              :          enclosed in braces, unwrap it here.  */
    8295          633 :       if (TREE_CODE (type) == ARRAY_TYPE
    8296          266 :           && vec_safe_length (v) == 1
    8297          144 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    8298          672 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    8299              :         return elt;
    8300          599 :       return init;
    8301              :     }
    8302              : 
    8303              :   /* Handle [dcl.init.list] direct-list-initialization from
    8304              :      single element of enumeration with a fixed underlying type.  */
    8305      4513756 :   if (is_direct_enum_init (type, init))
    8306              :     {
    8307          166 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    8308          166 :       type = cv_unqualified (type);
    8309          166 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    8310              :         {
    8311          151 :           warning_sentinel w (warn_useless_cast);
    8312          151 :           warning_sentinel w2 (warn_ignored_qualifiers);
    8313          151 :           return cp_build_c_cast (input_location, type, elt,
    8314              :                                   tf_warning_or_error);
    8315          151 :         }
    8316              :       else
    8317           15 :         return error_mark_node;
    8318              :     }
    8319              : 
    8320              :   /* Recurse on this CONSTRUCTOR.  */
    8321      4513590 :   d.cur = &(*v)[0];
    8322      4513590 :   d.end = d.cur + v->length ();
    8323      4513590 :   d.raw_idx = 0;
    8324              : 
    8325      4513590 :   new_init = reshape_init_r (type, &d, init, complain);
    8326      4513590 :   if (new_init == error_mark_node)
    8327              :     return error_mark_node;
    8328              : 
    8329              :   /* Make sure all the element of the constructor were used. Otherwise,
    8330              :      issue an error about exceeding initializers.  */
    8331      4512970 :   if (d.cur != d.end)
    8332              :     {
    8333          207 :       if (complain & tf_error)
    8334           63 :         error ("too many initializers for %qT", type);
    8335          207 :       return error_mark_node;
    8336              :     }
    8337              : 
    8338      4512763 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    8339      4512763 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8340       944277 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    8341      4512763 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    8342      4512763 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8343        51125 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    8344              :                          || seen_error ());
    8345              : 
    8346              :   return new_init;
    8347              : }
    8348              : 
    8349              : /* Verify array initializer.  Returns true if errors have been reported.  */
    8350              : 
    8351              : bool
    8352      1303657 : check_array_initializer (tree decl, tree type, tree init)
    8353              : {
    8354      1303657 :   tree element_type = TREE_TYPE (type);
    8355              : 
    8356              :   /* Structured binding when initialized with an array type needs
    8357              :      to have complete type.  */
    8358      1303657 :   if (decl
    8359      1293543 :       && DECL_DECOMPOSITION_P (decl)
    8360          459 :       && DECL_DECOMP_IS_BASE (decl)
    8361      1304116 :       && !COMPLETE_TYPE_P (type))
    8362              :     {
    8363            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    8364              :                 "structured binding has incomplete type %qT", type);
    8365            0 :       TREE_TYPE (decl) = error_mark_node;
    8366            0 :       return true;
    8367              :     }
    8368              : 
    8369              :   /* The array type itself need not be complete, because the
    8370              :      initializer may tell us how many elements are in the array.
    8371              :      But, the elements of the array must be complete.  */
    8372      1303657 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    8373              :     {
    8374           15 :       if (decl)
    8375            9 :         error_at (DECL_SOURCE_LOCATION (decl),
    8376              :                   "elements of array %q#D have incomplete type", decl);
    8377              :       else
    8378            6 :         error ("elements of array %q#T have incomplete type", type);
    8379           15 :       return true;
    8380              :     }
    8381              : 
    8382      1303642 :   location_t loc = (decl ? location_of (decl) : input_location);
    8383      1303642 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    8384              :     return true;
    8385              : 
    8386              :   /* A compound literal can't have variable size.  */
    8387      1303642 :   if (init && !decl
    8388      1303642 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    8389        10105 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    8390              :     {
    8391            3 :       error ("variable-sized compound literal");
    8392            3 :       return true;
    8393              :     }
    8394              :   return false;
    8395              : }
    8396              : 
    8397              : /* Subroutine of check_initializer; args are passed down from that function.
    8398              :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    8399              : 
    8400              : static tree
    8401      4972464 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    8402              : {
    8403      4972464 :   gcc_assert (stmts_are_full_exprs_p ());
    8404      4972464 :   if (init)
    8405      3727046 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    8406      4972464 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    8407              : }
    8408              : 
    8409              : /* Verify INIT (the initializer for DECL), and record the
    8410              :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    8411              :    grok_reference_init.
    8412              : 
    8413              :    If the return value is non-NULL, it is an expression that must be
    8414              :    evaluated dynamically to initialize DECL.  */
    8415              : 
    8416              : static tree
    8417     66877738 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    8418              : {
    8419     66877738 :   tree type;
    8420     66877738 :   tree init_code = NULL;
    8421     66877738 :   tree core_type;
    8422              : 
    8423              :   /* Things that are going to be initialized need to have complete
    8424              :      type.  */
    8425     66877738 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    8426              : 
    8427     66877738 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    8428              :     {
    8429              :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    8430              :          it doesn't have storage to be initialized.  */
    8431          108 :       gcc_assert (init == NULL_TREE);
    8432              :       return NULL_TREE;
    8433              :     }
    8434              : 
    8435     66877630 :   if (type == error_mark_node)
    8436              :     /* We will have already complained.  */
    8437              :     return NULL_TREE;
    8438              : 
    8439     66877630 :   if (TREE_CODE (type) == ARRAY_TYPE)
    8440              :     {
    8441      1293543 :       if (check_array_initializer (decl, type, init))
    8442              :         return NULL_TREE;
    8443              :     }
    8444     65584087 :   else if (!COMPLETE_TYPE_P (type))
    8445              :     {
    8446           37 :       error_at (DECL_SOURCE_LOCATION (decl),
    8447              :                 "%q#D has incomplete type", decl);
    8448           37 :       TREE_TYPE (decl) = error_mark_node;
    8449           37 :       return NULL_TREE;
    8450              :     }
    8451              :   else
    8452              :     /* There is no way to make a variable-sized class type in GNU C++.  */
    8453     65584050 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    8454              : 
    8455     66877584 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    8456              :     {
    8457      3368966 :       int init_len = CONSTRUCTOR_NELTS (init);
    8458      3368966 :       if (SCALAR_TYPE_P (type))
    8459              :         {
    8460       187795 :           if (init_len == 0)
    8461              :             {
    8462       156517 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8463       156517 :               init = build_zero_init (type, NULL_TREE, false);
    8464              :             }
    8465        31278 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    8466              :             {
    8467           12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8468              :                         "scalar object %qD requires one element in "
    8469              :                         "initializer", decl);
    8470            6 :               TREE_TYPE (decl) = error_mark_node;
    8471            6 :               return NULL_TREE;
    8472              :             }
    8473              :         }
    8474              :     }
    8475              : 
    8476     66877578 :   if (TREE_CODE (decl) == CONST_DECL)
    8477              :     {
    8478            0 :       gcc_assert (!TYPE_REF_P (type));
    8479              : 
    8480            0 :       DECL_INITIAL (decl) = init;
    8481              : 
    8482            0 :       gcc_assert (init != NULL_TREE);
    8483              :       init = NULL_TREE;
    8484              :     }
    8485     66877578 :   else if (!init && DECL_REALLY_EXTERN (decl))
    8486              :     ;
    8487     66877578 :   else if (flag_openmp
    8488       188331 :            && VAR_P (decl)
    8489       188331 :            && DECL_LANG_SPECIFIC (decl)
    8490       110528 :            && DECL_OMP_DECLARE_MAPPER_P (decl)
    8491     66877578 :            && TREE_CODE (init) == OMP_DECLARE_MAPPER)
    8492              :     return NULL_TREE;
    8493      5389679 :   else if (init || type_build_ctor_call (type)
    8494     71021836 :            || TYPE_REF_P (type))
    8495              :     {
    8496     62733335 :       if (TYPE_REF_P (type))
    8497              :         {
    8498       557671 :           init = grok_reference_init (decl, type, init, flags);
    8499       557671 :           flags |= LOOKUP_ALREADY_DIGESTED;
    8500              :         }
    8501     62175664 :       else if (!init)
    8502      1245421 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8503              :                                            tf_warning_or_error);
    8504              :       /* Do not reshape constructors of vectors (they don't need to be
    8505              :          reshaped.  */
    8506     60930243 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    8507              :         {
    8508      3212122 :           if (is_std_init_list (type))
    8509              :             {
    8510          333 :               init = perform_implicit_conversion (type, init,
    8511              :                                                   tf_warning_or_error);
    8512          333 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8513              :             }
    8514      3211789 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    8515              :             {
    8516              :               /* Don't reshape if the class has constructors.  */
    8517       444667 :               if (cxx_dialect == cxx98)
    8518            6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8519              :                           "in C++98 %qD must be initialized by "
    8520              :                           "constructor, not by %<{...}%>",
    8521              :                           decl);
    8522              :             }
    8523      2767122 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    8524              :             {
    8525            0 :               error ("opaque vector types cannot be initialized");
    8526            0 :               init = error_mark_node;
    8527              :             }
    8528              :           else
    8529              :             {
    8530      2767122 :               init = reshape_init (type, init, tf_warning_or_error);
    8531      2767122 :               flags |= LOOKUP_NO_NARROWING;
    8532              :             }
    8533              :         }
    8534              :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    8535              :          is initialized as follows..."  So handle things like
    8536              : 
    8537              :           int a[](1, 2, 3);
    8538              : 
    8539              :          which is permitted in C++20 by P0960.  */
    8540     57718121 :       else if (TREE_CODE (init) == TREE_LIST
    8541      1043735 :                && TREE_TYPE (init) == NULL_TREE
    8542      1043735 :                && TREE_CODE (type) == ARRAY_TYPE
    8543          165 :                && !DECL_DECOMPOSITION_P (decl)
    8544     57718265 :                && (cxx_dialect >= cxx20))
    8545          134 :         init = do_aggregate_paren_init (init, type);
    8546     57717987 :       else if (TREE_CODE (init) == TREE_LIST
    8547      1043601 :                && TREE_TYPE (init) != unknown_type_node
    8548     58761588 :                && !MAYBE_CLASS_TYPE_P (type))
    8549              :         {
    8550       126588 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8551              : 
    8552              :           /* We get here with code like `int a (2);' */
    8553       126588 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    8554              :                                                   tf_warning_or_error);
    8555              :         }
    8556              : 
    8557              :       /* If DECL has an array type without a specific bound, deduce the
    8558              :          array size from the initializer.  */
    8559     62733335 :       maybe_deduce_size_from_array_init (decl, init);
    8560     62733335 :       type = TREE_TYPE (decl);
    8561     62733335 :       if (type == error_mark_node)
    8562              :         return NULL_TREE;
    8563              : 
    8564    119970076 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    8565      7477717 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    8566      7477384 :            && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
    8567      2951227 :                 && CP_AGGREGATE_TYPE_P (type)
    8568      2506560 :                 && (CLASS_TYPE_P (type)
    8569              :                     /* The call to build_aggr_init below could end up
    8570              :                        calling build_vec_init, which may break when we
    8571              :                        are processing a template.  */
    8572         1381 :                     || processing_template_decl
    8573         1312 :                     || !TYPE_NEEDS_CONSTRUCTING (type)
    8574         1280 :                     || type_has_extended_temps (type))))
    8575    120494618 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    8576              :         {
    8577      4972464 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    8578              : 
    8579              :           /* A constructor call is a non-trivial initializer even if
    8580              :              it isn't explicitly written.  */
    8581      4972464 :           if (TREE_SIDE_EFFECTS (init_code))
    8582      4950734 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    8583              : 
    8584              :           /* If this is a constexpr initializer, expand_default_init will
    8585              :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    8586              :              case, pull the initializer back out and pass it down into
    8587              :              store_init_value.  */
    8588     13392831 :           while (true)
    8589              :             {
    8590     13392831 :               if (TREE_CODE (init_code) == EXPR_STMT
    8591      8444567 :                   || TREE_CODE (init_code) == STMT_EXPR
    8592      8408508 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    8593      8384355 :                 init_code = TREE_OPERAND (init_code, 0);
    8594      5008476 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    8595        36012 :                 init_code = BIND_EXPR_BODY (init_code);
    8596              :               else
    8597              :                 break;
    8598              :             }
    8599      4972464 :           if (TREE_CODE (init_code) == INIT_EXPR)
    8600              :             {
    8601              :               /* In C++20, the call to build_aggr_init could have created
    8602              :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    8603              :                  A(1, 2).  */
    8604      3419162 :               tree rhs = TREE_OPERAND (init_code, 1);
    8605      3419162 :               if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
    8606              :                 /* Avoid leaking TARGET_EXPR into template trees.  */
    8607        18038 :                 rhs = build_implicit_conv_flags (type, init, flags);
    8608      3419162 :               init = rhs;
    8609              : 
    8610      3419162 :               init_code = NULL_TREE;
    8611              :               /* Don't call digest_init; it's unnecessary and will complain
    8612              :                  about aggregate initialization of non-aggregate classes.  */
    8613      3419138 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8614              :             }
    8615      1553302 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    8616      3088333 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8617              :             {
    8618              :               /* Declared constexpr or constinit, but no suitable initializer;
    8619              :                  massage init appropriately so we can pass it into
    8620              :                  store_init_value for the error.  */
    8621        18289 :               tree new_init = NULL_TREE;
    8622        18289 :               if (!processing_template_decl
    8623          291 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8624          232 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8625        18033 :               else if (CLASS_TYPE_P (type)
    8626        36090 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8627        17973 :                 new_init = build_functional_cast (input_location, type,
    8628              :                                                   init, tf_none);
    8629        18205 :               if (new_init)
    8630              :                 {
    8631        18205 :                   init = new_init;
    8632        18205 :                   if (TREE_CODE (init) == TARGET_EXPR
    8633          257 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8634          257 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8635              :                 }
    8636              :               init_code = NULL_TREE;
    8637              :             }
    8638              :           else
    8639              :             init = NULL_TREE;
    8640              :         }
    8641              : 
    8642     61198318 :       if (init && TREE_CODE (init) != TREE_VEC)
    8643              :         {
    8644     61198303 :           init_code = store_init_value (decl, init, cleanups, flags);
    8645              : 
    8646     61195606 :           if (DECL_INITIAL (decl)
    8647     42993119 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8648     65081077 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8649              :             {
    8650      2041666 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8651      2041666 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8652      2041666 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8653           36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8654              :             }
    8655              : 
    8656      1674334 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8657        55319 :               && DECL_INITIAL (decl)
    8658        54795 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8659     61246943 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8660            6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8661            3 :                                          DECL_SOURCE_LOCATION (decl)),
    8662            3 :                         0, "array %qD initialized by parenthesized "
    8663              :                         "string literal %qE",
    8664            3 :                         decl, DECL_INITIAL (decl));
    8665              :           init = NULL_TREE;
    8666              :         }
    8667              :     }
    8668      4144243 :   else if (!init && REFLECTION_TYPE_P (type))
    8669              :     {
    8670              :       /* [dcl.init.general]: To default-initialize an object of type
    8671              :          std::meta::info means that the object is zero-initialized.  */
    8672           75 :       DECL_INITIAL (decl)
    8673           75 :         = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
    8674           75 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    8675           75 :       TREE_CONSTANT (decl) = true;
    8676           75 :       init = NULL_TREE;
    8677              :     }
    8678              :   else
    8679              :     {
    8680      8288336 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    8681      4854439 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    8682       710258 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    8683           19 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    8684              :                                                   /*complain=*/true);
    8685              : 
    8686      4144168 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8687              :                                          tf_warning_or_error);
    8688              :     }
    8689              : 
    8690           75 :   if (init && init != error_mark_node)
    8691            0 :     init_code = cp_build_init_expr (decl, init);
    8692              : 
    8693     19954670 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    8694     66928626 :       && init_code != error_mark_node)
    8695              :     init_code = NULL_TREE;
    8696              : 
    8697     66823382 :   if (init_code)
    8698              :     {
    8699              :       /* We might have set these in cp_finish_decl.  */
    8700     19903175 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    8701     19903175 :       TREE_CONSTANT (decl) = false;
    8702              :     }
    8703              : 
    8704     19903175 :   if (init_code
    8705     19903175 :       && DECL_IN_AGGR_P (decl)
    8706            6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8707              :     {
    8708            0 :       static int explained = 0;
    8709              : 
    8710            0 :       auto_diagnostic_group d;
    8711            0 :       if (cxx_dialect < cxx11)
    8712            0 :         error ("initializer invalid for static member with constructor");
    8713            0 :       else if (cxx_dialect < cxx17)
    8714            0 :         error ("non-constant in-class initialization invalid for static "
    8715              :                "member %qD", decl);
    8716              :       else
    8717            0 :         error ("non-constant in-class initialization invalid for non-inline "
    8718              :                "static member %qD", decl);
    8719            0 :       if (!explained)
    8720              :         {
    8721            0 :           inform (input_location,
    8722              :                   "(an out of class initialization is required)");
    8723            0 :           explained = 1;
    8724              :         }
    8725            0 :       return NULL_TREE;
    8726            0 :     }
    8727              : 
    8728              :   return init_code;
    8729              : }
    8730              : 
    8731              : /* If DECL is not a local variable, give it RTL.  */
    8732              : 
    8733              : static void
    8734    130151757 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    8735              : {
    8736    130151757 :   int toplev = toplevel_bindings_p ();
    8737    130151757 :   int defer_p;
    8738              : 
    8739              :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    8740    130151757 :   if (asmspec)
    8741              :     {
    8742              :       /* The `register' keyword, when used together with an
    8743              :          asm-specification, indicates that the variable should be
    8744              :          placed in a particular register.  */
    8745       971891 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    8746              :         {
    8747           87 :           if (TREE_ADDRESSABLE (decl))
    8748            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    8749              :                       "address of explicit register variable %qD requested",
    8750              :                       decl);
    8751              :           else
    8752              :             {
    8753           84 :               set_user_assembler_name (decl, asmspec);
    8754           84 :               DECL_HARD_REGISTER (decl) = 1;
    8755              :             }
    8756              :         }
    8757              :       else
    8758              :         {
    8759       971804 :           if (TREE_CODE (decl) == FUNCTION_DECL
    8760       971804 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    8761        76524 :             set_builtin_user_assembler_name (decl, asmspec);
    8762       971804 :           set_user_assembler_name (decl, asmspec);
    8763       971804 :           if (DECL_LOCAL_DECL_P (decl))
    8764            6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    8765              :               /* We have to propagate the name to the ns-alias.
    8766              :                  This is horrible, as we're affecting a
    8767              :                  possibly-shared decl.  Again, a one-true-decl
    8768              :                  model breaks down.  */
    8769            6 :               if (ns_decl != error_mark_node)
    8770            6 :                 set_user_assembler_name (ns_decl, asmspec);
    8771              :         }
    8772              :     }
    8773              : 
    8774              :   /* Handle non-variables up front.  */
    8775    130151757 :   if (!VAR_P (decl))
    8776              :     {
    8777     56382205 :       rest_of_decl_compilation (decl, toplev, at_eof);
    8778     56382205 :       return;
    8779              :     }
    8780              : 
    8781              :   /* If we see a class member here, it should be a static data
    8782              :      member.  */
    8783     73769552 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    8784              :     {
    8785      5521197 :       gcc_assert (TREE_STATIC (decl));
    8786              :       /* An in-class declaration of a static data member should be
    8787              :          external; it is only a declaration, and not a definition.  */
    8788      5521197 :       if (init == NULL_TREE)
    8789      5521169 :         gcc_assert (DECL_EXTERNAL (decl)
    8790              :                     || !TREE_PUBLIC (decl));
    8791              :     }
    8792              : 
    8793              :   /* We don't create any RTL for local variables.  */
    8794     73769552 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8795              :     return;
    8796              : 
    8797              :   /* Don't output reflection variables.  */
    8798     42924524 :   if (consteval_only_p (decl))
    8799              :     {
    8800              :       /* Disable assemble_variable.  */
    8801          698 :       DECL_EXTERNAL (decl) = true;
    8802              :       /* Undo make_decl_one_only.  */
    8803          698 :       if (DECL_COMDAT_GROUP (decl))
    8804              :         {
    8805          118 :           symtab_node *node = symtab_node::get (decl);
    8806          118 :           node->set_comdat_group (NULL);
    8807          118 :           node->dissolve_same_comdat_group_list ();
    8808              :         }
    8809          698 :       return;
    8810              :     }
    8811              : 
    8812              :   /* We defer emission of local statics until the corresponding
    8813              :      DECL_EXPR is expanded.  But with constexpr its function might never
    8814              :      be expanded, so go ahead and tell cgraph about the variable now.  */
    8815     85847652 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    8816       168537 :               && !var_in_maybe_constexpr_fn (decl))
    8817     85679743 :              || DECL_VIRTUAL_P (decl));
    8818              : 
    8819              :   /* Defer template instantiations.  */
    8820     42923826 :   if (DECL_LANG_SPECIFIC (decl)
    8821     42923826 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    8822              :     defer_p = 1;
    8823              : 
    8824              :   /* If we're not deferring, go ahead and assemble the variable.  */
    8825     19645366 :   if (!defer_p)
    8826     17195574 :     rest_of_decl_compilation (decl, toplev, at_eof);
    8827              : }
    8828              : 
    8829              : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    8830              : 
    8831              : static tree
    8832     16018254 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    8833              : {
    8834              :   /* Stop at types or full-expression boundaries.  */
    8835     16018254 :   if (TYPE_P (*stmt_p)
    8836     16018043 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    8837              :     {
    8838          441 :       *walk_subtrees = 0;
    8839          441 :       return NULL_TREE;
    8840              :     }
    8841              : 
    8842     16017813 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    8843              :     {
    8844       451020 :       tree guard = (tree)data;
    8845       451020 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    8846              : 
    8847       208905 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    8848       640075 :           && !expr_noexcept_p (tcleanup, tf_none))
    8849              :         {
    8850          145 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    8851              :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    8852              :              cleanup.  */
    8853          145 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    8854          145 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    8855              :         }
    8856              :     }
    8857              : 
    8858              :   return NULL_TREE;
    8859              : }
    8860              : 
    8861              : /* We're initializing a local variable which has a cleanup GUARD.  If there
    8862              :    are any temporaries used in the initializer INIT of this variable, we
    8863              :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    8864              :    variable will be cleaned up properly if one of them throws.
    8865              : 
    8866              :    Unfortunately, there's no way to express this properly in terms of
    8867              :    nesting, as the regions for the temporaries overlap the region for the
    8868              :    variable itself; if there are two temporaries, the variable needs to be
    8869              :    the first thing destroyed if either of the temporary destructors throws.
    8870              :    However, we only want to run the variable's cleanup if it actually got
    8871              :    constructed.  So we need to guard the temporary cleanups with the
    8872              :    variable's cleanup if they are run on the normal path, but not if they
    8873              :    are run on the exceptional path.  We implement this by telling
    8874              :    honor_protect_cleanup_actions to strip the variable cleanup from the
    8875              :    exceptional path.
    8876              : 
    8877              :    Another approach could be to make the variable cleanup region enclose
    8878              :    initialization, but depend on a flag to indicate that the variable is
    8879              :    initialized; that's effectively what we do for arrays.  But the current
    8880              :    approach works fine for non-arrays, and has no code overhead in the usual
    8881              :    case where the temporary destructors are noexcept.  */
    8882              : 
    8883              : static void
    8884      1380516 : wrap_temporary_cleanups (tree init, tree guard)
    8885              : {
    8886      1380516 :   if (TREE_CODE (guard) == BIND_EXPR)
    8887              :     {
    8888              :       /* An array cleanup region already encloses any temporary cleanups,
    8889              :          don't wrap it around them again.  */
    8890          405 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    8891              :       return;
    8892              :     }
    8893      1380111 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    8894              : }
    8895              : 
    8896              : /* Generate code to initialize DECL (a local variable).  */
    8897              : 
    8898              : static void
    8899     30845010 : initialize_local_var (tree decl, tree init, bool decomp)
    8900              : {
    8901     30845010 :   tree type = TREE_TYPE (decl);
    8902     30845010 :   tree cleanup;
    8903     30845010 :   int already_used;
    8904              : 
    8905     30845010 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    8906     30845010 :   gcc_assert (!TREE_STATIC (decl));
    8907              : 
    8908     30845010 :   if (DECL_SIZE (decl) == NULL_TREE)
    8909              :     {
    8910              :       /* If we used it already as memory, it must stay in memory.  */
    8911            0 :       DECL_INITIAL (decl) = NULL_TREE;
    8912            0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    8913            0 :       return;
    8914              :     }
    8915              : 
    8916     30845010 :   if (type == error_mark_node)
    8917              :     return;
    8918              : 
    8919              :   /* Compute and store the initial value.  */
    8920     30845010 :   already_used = TREE_USED (decl) || TREE_USED (type);
    8921     30845010 :   if (TREE_USED (type))
    8922           32 :     DECL_READ_P (decl) = 1;
    8923              : 
    8924              :   /* Generate a cleanup, if necessary.  */
    8925     30845010 :   cleanup = (decomp ? NULL_TREE
    8926     30779863 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    8927              : 
    8928              :   /* Perform the initialization.  */
    8929     30845010 :   if (init)
    8930              :     {
    8931     19889020 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    8932     19889020 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    8933     17690340 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    8934     26903175 :           && TREE_OPERAND (init, 0) == decl)
    8935              :         {
    8936              :           /* Stick simple initializers in DECL_INITIAL so that
    8937              :              -Wno-init-self works (c++/34772).  */
    8938      9212835 :           DECL_INITIAL (decl) = rinit;
    8939              : 
    8940      9212835 :           if (warn_init_self && TYPE_REF_P (type))
    8941              :             {
    8942         2541 :               STRIP_NOPS (rinit);
    8943         2541 :               if (rinit == decl)
    8944            3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    8945            3 :                             OPT_Winit_self,
    8946              :                             "reference %qD is initialized with itself", decl);
    8947              :             }
    8948              :         }
    8949              :       else
    8950              :         {
    8951     10676185 :           int saved_stmts_are_full_exprs_p;
    8952              : 
    8953              :           /* If we're only initializing a single object, guard the
    8954              :              destructors of any temporaries used in its initializer with
    8955              :              its destructor.  */
    8956     10676185 :           if (cleanup)
    8957      1361216 :             wrap_temporary_cleanups (init, cleanup);
    8958              : 
    8959     10676185 :           gcc_assert (building_stmt_list_p ());
    8960     10676185 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    8961              :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    8962              :              bases, those will have CLEANUP_POINT_EXPR at the end of
    8963              :              code emitted by cp_finish_decomp.  */
    8964     10676185 :           if (decomp)
    8965        64702 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    8966              :           else
    8967     10611483 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    8968     10676185 :           finish_expr_stmt (init);
    8969     10676185 :           current_stmt_tree ()->stmts_are_full_exprs_p
    8970     10676185 :             = saved_stmts_are_full_exprs_p;
    8971              :         }
    8972              :     }
    8973              : 
    8974              :   /* Set this to 0 so we can tell whether an aggregate which was
    8975              :      initialized was ever used.  Don't do this if it has a
    8976              :      destructor, so we don't complain about the 'resource
    8977              :      allocation is initialization' idiom.  Now set
    8978              :      attribute((unused)) on types so decls of that type will be
    8979              :      marked used. (see TREE_USED, above.)  */
    8980     30845010 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    8981      3833967 :       && ! already_used
    8982        22043 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8983     30848310 :       && DECL_NAME (decl))
    8984         3272 :     TREE_USED (decl) = 0;
    8985     30841738 :   else if (already_used)
    8986     27917262 :     TREE_USED (decl) = 1;
    8987              : 
    8988     30845010 :   if (cleanup)
    8989      1374305 :     finish_decl_cleanup (decl, cleanup);
    8990              : }
    8991              : 
    8992              : /* DECL is a VAR_DECL for a compiler-generated variable with static
    8993              :    storage duration (like a virtual table) whose initializer is a
    8994              :    compile-time constant.  Initialize the variable and provide it to the
    8995              :    back end.  */
    8996              : 
    8997              : void
    8998      2242783 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    8999              : {
    9000      2242783 :   tree init;
    9001      2242783 :   gcc_assert (DECL_ARTIFICIAL (decl));
    9002      2242783 :   init = build_constructor (TREE_TYPE (decl), v);
    9003      2242783 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    9004      2242783 :   DECL_INITIAL (decl) = init;
    9005      2242783 :   DECL_INITIALIZED_P (decl) = 1;
    9006              :   /* Mark the decl as constexpr so that we can access its content
    9007              :      at compile time.  */
    9008      2242783 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    9009      2242783 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    9010      2242783 :   determine_visibility (decl);
    9011      2242783 :   layout_var_decl (decl);
    9012      2242783 :   maybe_commonize_var (decl);
    9013      2242783 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    9014      2242783 : }
    9015              : 
    9016              : /* INIT is the initializer for a variable, as represented by the
    9017              :    parser.  Returns true iff INIT is value-dependent.  */
    9018              : 
    9019              : static bool
    9020      9284068 : value_dependent_init_p (tree init)
    9021              : {
    9022      9284068 :   if (TREE_CODE (init) == TREE_LIST)
    9023              :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    9024        19893 :     return any_value_dependent_elements_p (init);
    9025      9264175 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    9026              :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    9027              :     {
    9028        68559 :       if (dependent_type_p (TREE_TYPE (init)))
    9029              :         return true;
    9030              : 
    9031        68553 :       vec<constructor_elt, va_gc> *elts;
    9032        68553 :       size_t nelts;
    9033        68553 :       size_t i;
    9034              : 
    9035        68553 :       elts = CONSTRUCTOR_ELTS (init);
    9036        68553 :       nelts = vec_safe_length (elts);
    9037       595191 :       for (i = 0; i < nelts; ++i)
    9038       554265 :         if (value_dependent_init_p ((*elts)[i].value))
    9039              :           return true;
    9040              :     }
    9041              :   else
    9042              :     /* It must be a simple expression, e.g., int i = 3;  */
    9043      9195616 :     return value_dependent_expression_p (init);
    9044              : 
    9045              :   return false;
    9046              : }
    9047              : 
    9048              : /* A helper function to be called via walk_tree.  If any label exists
    9049              :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    9050              : 
    9051              : static tree
    9052          337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    9053              : {
    9054          337 :   if (TYPE_P (*tp))
    9055            0 :     *walk_subtrees = 0;
    9056          337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    9057            6 :     cfun->has_forced_label_in_static = 1;
    9058          337 :   return NULL_TREE;
    9059              : }
    9060              : 
    9061              : /* Return true if DECL has either a trivial destructor, or for C++20
    9062              :    is constexpr and has a constexpr destructor.  */
    9063              : 
    9064              : static bool
    9065     70253711 : decl_maybe_constant_destruction (tree decl, tree type)
    9066              : {
    9067     70253711 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9068     70253711 :           || (cxx_dialect >= cxx20
    9069      4919765 :               && VAR_P (decl)
    9070      4919456 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    9071          328 :               && type_has_constexpr_destructor (strip_array_types (type))));
    9072              : }
    9073              : 
    9074              : static tree declare_simd_adjust_this (tree *, int *, void *);
    9075              : 
    9076              : /* Helper function of omp_declare_variant_finalize.  Finalize one
    9077              :    "omp declare variant base" attribute.  Return true if it should be
    9078              :    removed.  */
    9079              : 
    9080              : static bool
    9081         1751 : omp_declare_variant_finalize_one (tree decl, tree attr)
    9082              : {
    9083         1751 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9084              :     {
    9085          164 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9086              :                  DECL_ARGUMENTS (decl), NULL);
    9087          164 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9088              :                  DECL_ARGUMENTS (decl), NULL);
    9089              :     }
    9090              : 
    9091         1751 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    9092         1751 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    9093              :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    9094         1751 :   if (simd)
    9095              :     {
    9096           51 :       TREE_VALUE (simd)
    9097           51 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    9098           51 :                                                  OMP_TS_PROPERTIES (simd));
    9099              :       /* FIXME, adjusting simd args unimplemented.  */
    9100           51 :       return true;
    9101              :     }
    9102              : 
    9103         1700 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    9104         1700 :   location_t varid_loc
    9105         1700 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    9106         1700 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    9107         1700 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    9108         1700 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    9109              : 
    9110         1700 :   location_t save_loc = input_location;
    9111         1700 :   input_location = varid_loc;
    9112              : 
    9113         1700 :   releasing_vec args;
    9114         1700 :   tree parm = DECL_ARGUMENTS (decl);
    9115         1700 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9116          164 :     parm = DECL_CHAIN (parm);
    9117         3022 :   for (; parm; parm = DECL_CHAIN (parm))
    9118         1322 :     vec_safe_push (args, forward_parm (parm));
    9119              : 
    9120         1700 :   unsigned nappend_args = 0;
    9121         1700 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9122         1700 :   if (append_args_list)
    9123              :     {
    9124          354 :       append_args_list = TREE_VALUE (append_args_list);
    9125          354 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    9126          591 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    9127              :                           : NULL_TREE);
    9128          741 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9129          387 :         nappend_args++;
    9130          354 :       if (nappend_args)
    9131              :         {
    9132          237 :           tree type;
    9133          237 :           if ((type = lookup_qualified_name (global_namespace,
    9134              :                                              "omp_interop_t",
    9135              :                                              LOOK_want::NORMAL,
    9136              :                                              /*complain*/false)) == NULL_TREE
    9137          237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    9138              :             {
    9139           24 :               location_t loc = input_location;
    9140           24 :               variant = tree_strip_any_location_wrapper (variant);
    9141           24 :               if (!identifier_p (variant))
    9142              :                 {
    9143           21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    9144           21 :                     variant = OVL_FIRST (variant);
    9145           21 :                   loc = EXPR_LOC_OR_LOC (variant,
    9146              :                                          DECL_SOURCE_LOCATION (variant));
    9147              :                 }
    9148           24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    9149           24 :                         args->length () + 1, variant);
    9150           24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9151              :                       "%<append_args%> specified here");
    9152           24 :               return true;
    9153              :             }
    9154          564 :           for (unsigned i = 0; i < nappend_args; i++)
    9155          351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    9156              :         }
    9157              :     }
    9158              : 
    9159         1676 :   bool koenig_p = false;
    9160         1676 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    9161              :     {
    9162         1606 :       if (identifier_p (variant)
    9163              :           /* In C++20, we may need to perform ADL for a template
    9164              :              name.  */
    9165         1582 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    9166           18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    9167              :         {
    9168           24 :           if (!args->is_empty ())
    9169              :             {
    9170           24 :               koenig_p = true;
    9171           24 :               if (!any_type_dependent_arguments_p (args))
    9172           21 :                 variant = perform_koenig_lookup (variant, args,
    9173              :                                                  tf_warning_or_error);
    9174              :             }
    9175              :           else
    9176            0 :             variant = unqualified_fn_lookup_error (variant);
    9177              :         }
    9178         1582 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    9179              :         {
    9180          830 :           tree fn = get_first_fn (variant);
    9181          830 :           fn = STRIP_TEMPLATE (fn);
    9182          830 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    9183          830 :                  || DECL_FUNCTION_MEMBER_P (fn)
    9184          717 :                  || DECL_LOCAL_DECL_P (fn)))
    9185              :             {
    9186          717 :               koenig_p = true;
    9187          717 :               if (!any_type_dependent_arguments_p (args))
    9188          666 :                 variant = perform_koenig_lookup (variant, args,
    9189              :                                                  tf_warning_or_error);
    9190              :             }
    9191              :         }
    9192              :     }
    9193              : 
    9194         1676 :   if (idk == CP_ID_KIND_QUALIFIED)
    9195            6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    9196              :                                 koenig_p, tf_warning_or_error);
    9197         1670 :   else if (idk == CP_ID_KIND_NONE
    9198           64 :            && TREE_CODE (variant) == FUNCTION_DECL
    9199           64 :            && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
    9200         1718 :            && CLASS_TYPE_P (DECL_CONTEXT (decl)))
    9201              :     {
    9202           48 :       tree saved_ccp = current_class_ptr;
    9203           48 :       tree saved_ccr = current_class_ref;
    9204           48 :       current_class_ptr = NULL_TREE;
    9205           48 :       current_class_ref = NULL_TREE;
    9206           48 :       inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
    9207           48 :       variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9208              :                                   koenig_p, tf_warning_or_error);
    9209           48 :       current_class_ptr = saved_ccp;
    9210           48 :       current_class_ref = saved_ccr;
    9211              :     }
    9212              :   else
    9213         1622 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9214              :                                 koenig_p, tf_warning_or_error);
    9215         1676 :   if (variant == error_mark_node && !processing_template_decl)
    9216              :     return true;
    9217              : 
    9218         1610 :   if (TREE_CODE (variant) == TARGET_EXPR)
    9219            9 :     variant = TARGET_EXPR_INITIAL (variant);
    9220              : 
    9221         3211 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    9222         1610 :   input_location = save_loc;
    9223              : 
    9224         1610 :   if (variant == decl)
    9225              :     {
    9226            0 :       error_at (varid_loc, "variant %qD is the same as base function",
    9227              :                 variant);
    9228            0 :       return true;
    9229              :     }
    9230              : 
    9231         1610 :   if (variant)
    9232              :     {
    9233         1526 :       bool fail;
    9234         1526 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    9235         1526 :       if (!nappend_args)
    9236         1367 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9237              :                            COMPARE_STRICT);
    9238              :       else
    9239              :         {
    9240          159 :           unsigned nbase_args = 0;
    9241          159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    9242          756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    9243          240 :             nbase_args++;
    9244          159 :           tree vargs, varg;
    9245          159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    9246          399 :           for (unsigned i = 0; i < nbase_args && varg;
    9247          240 :                i++, varg = TREE_CHAIN (varg))
    9248          240 :             vargs = varg;
    9249          417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    9250          258 :             varg = TREE_CHAIN (varg);
    9251          159 :           tree saved_vargs;
    9252          159 :           int saved_no_named_args_stdarg = 0;
    9253          159 :           if (nbase_args)
    9254              :             {
    9255          111 :               saved_vargs = TREE_CHAIN (vargs);
    9256          111 :               TREE_CHAIN (vargs) = varg;
    9257              :             }
    9258              :           else
    9259              :             {
    9260           48 :               saved_vargs = vargs;
    9261           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    9262           48 :               saved_no_named_args_stdarg
    9263           48 :                 = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
    9264           48 :               if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
    9265           48 :                   && varg == NULL_TREE)
    9266            2 :                 TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
    9267              :             }
    9268              :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    9269          159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9270              :                              COMPARE_STRUCTURAL);
    9271          159 :           if (nbase_args)
    9272          111 :             TREE_CHAIN (vargs) = saved_vargs;
    9273              :           else
    9274              :             {
    9275           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    9276           48 :               TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
    9277           96 :                 = saved_no_named_args_stdarg;
    9278              :             }
    9279          159 :           varg = saved_vargs;
    9280          159 :           if (!fail && !processing_template_decl)
    9281          402 :             for (unsigned i = 0; i < nappend_args;
    9282          246 :                  i++, varg = TREE_CHAIN (varg))
    9283          507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    9284              :                 {
    9285            9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    9286              :                             "argument %d of %qD must be of %<omp_interop_t%>",
    9287            9 :                             nbase_args + i + 1, variant);
    9288            9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9289              :                           "%<append_args%> specified here");
    9290            9 :                   break;
    9291              :                 }
    9292              :         }
    9293         1526 :       if (fail)
    9294              :         {
    9295           69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    9296              :                                "types", variant, decl);
    9297           69 :           return true;
    9298              :         }
    9299         1457 :       if (fndecl_built_in_p (variant)
    9300         1457 :           && (startswith (varname, "__builtin_")
    9301            0 :               || startswith (varname, "__sync_")
    9302            0 :               || startswith (varname, "__atomic_")))
    9303              :         {
    9304            6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    9305            6 :           return true;
    9306              :         }
    9307              :       else
    9308              :         {
    9309         1451 :           tree construct
    9310         1451 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    9311         1451 :           omp_mark_declare_variant (match_loc, variant, construct);
    9312         1451 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    9313              :             return true;
    9314         1039 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    9315              : 
    9316              :           // Prepend adjust_args list to variant attributes
    9317         1039 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9318         1039 :           if (adjust_args_list != NULL_TREE)
    9319              :             {
    9320          507 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    9321          285 :                   && TREE_VALUE (adjust_args_list))
    9322              :                 {
    9323              :                   /* Shift arg position for the added 'this' pointer.  */
    9324              :                   /* Handle need_device_ptr  */
    9325           21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    9326           51 :                        t; t = TREE_CHAIN (t))
    9327           30 :                     TREE_VALUE (t)
    9328           30 :                       = build_int_cst (TREE_TYPE (t),
    9329           30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    9330              :                 }
    9331          264 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    9332              :                 {
    9333              :                   /* Shift likewise the number of args after which the
    9334              :                      interop object should be added.  */
    9335            6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    9336            6 :                   TREE_PURPOSE (nargs)
    9337            6 :                     = build_int_cst (TREE_TYPE (nargs),
    9338            6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    9339              :                 }
    9340          528 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9341          264 :                 TREE_VALUE (t)
    9342          264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    9343          528 :               DECL_ATTRIBUTES (variant) = tree_cons (
    9344              :                 get_identifier ("omp declare variant variant args"),
    9345          528 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    9346              :             }
    9347              :         }
    9348              :     }
    9349           84 :   else if (!processing_template_decl)
    9350              :     {
    9351            0 :       error_at (varid_loc, "could not find variant declaration");
    9352            0 :       return true;
    9353              :     }
    9354              : 
    9355              :   return false;
    9356         1700 : }
    9357              : 
    9358              : /* Helper function, finish up "omp declare variant base" attribute
    9359              :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    9360              :    attribute.  */
    9361              : 
    9362              : void
    9363         1546 : omp_declare_variant_finalize (tree decl, tree attr)
    9364              : {
    9365         1546 :   size_t attr_len = strlen ("omp declare variant base");
    9366         1546 :   tree *list = &DECL_ATTRIBUTES (decl);
    9367         1546 :   bool remove_all = false;
    9368         1546 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    9369         1546 :   if (TREE_CHAIN (TREE_VALUE (attr))
    9370         1546 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    9371         3092 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    9372         1546 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    9373         3092 :   if (DECL_CONSTRUCTOR_P (decl))
    9374              :     {
    9375           27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    9376           27 :       remove_all = true;
    9377              :     }
    9378         1519 :   else if (DECL_DESTRUCTOR_P (decl))
    9379              :     {
    9380            9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    9381            9 :       remove_all = true;
    9382              :     }
    9383         1510 :   else if (DECL_DEFAULTED_FN (decl))
    9384              :     {
    9385            2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    9386            2 :       remove_all = true;
    9387              :     }
    9388         1508 :   else if (DECL_DELETED_FN (decl))
    9389              :     {
    9390            2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    9391            2 :       remove_all = true;
    9392              :     }
    9393         1506 :   else if (DECL_VIRTUAL_P (decl))
    9394              :     {
    9395            0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    9396            0 :       remove_all = true;
    9397              :     }
    9398              :   /* This loop is like private_lookup_attribute, except that it works
    9399              :      with tree * rather than tree, as we might want to remove the
    9400              :      attributes that are diagnosed as errorneous.  */
    9401         3349 :   while (*list)
    9402              :     {
    9403         1803 :       tree attr = get_attribute_name (*list);
    9404         1803 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    9405         4729 :       if (cmp_attribs ("omp declare variant base", attr_len,
    9406         1803 :                        IDENTIFIER_POINTER (attr), ident_len))
    9407              :         {
    9408         1791 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    9409              :             {
    9410          668 :               *list = TREE_CHAIN (*list);
    9411          668 :               continue;
    9412              :             }
    9413              :         }
    9414         1135 :       list = &TREE_CHAIN (*list);
    9415              :     }
    9416         1546 : }
    9417              : 
    9418              : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    9419              : 
    9420              : /* Finish processing of a declaration;
    9421              :    install its line number and initial value.
    9422              :    If the length of an array type is not known before,
    9423              :    it must be determined now, from the initial value, or it is an error.
    9424              : 
    9425              :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    9426              :    true, then INIT is an integral constant expression.
    9427              : 
    9428              :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    9429              :    if the (init) syntax was used.
    9430              : 
    9431              :    DECOMP is first identifier's DECL and identifier count in a structured
    9432              :    bindings, nullptr if not a structured binding.  */
    9433              : 
    9434              : void
    9435    330463223 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    9436              :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    9437              : {
    9438    330463223 :   vec<tree, va_gc> *cleanups = NULL;
    9439    330463223 :   const char *asmspec = NULL;
    9440    330463223 :   int was_readonly = 0;
    9441    330463223 :   bool var_definition_p = false;
    9442    330463223 :   tree auto_node;
    9443    330463223 :   auto_vec<tree> extra_cleanups;
    9444    330463223 :   tree aggregates1 = NULL_TREE;
    9445    330463223 :   struct decomp_cleanup {
    9446              :     tree decl;
    9447              :     cp_decomp *&decomp;
    9448    330460526 :     ~decomp_cleanup ()
    9449              :     {
    9450    330460526 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    9451       218416 :         cp_finish_decomp (decl, decomp);
    9452    330460526 :     }
    9453    330463223 :   } decomp_cl = { decl, decomp };
    9454              : 
    9455    330463223 :   if (decl == error_mark_node)
    9456              :     return;
    9457    330463183 :   else if (! decl)
    9458              :     {
    9459            0 :       if (init)
    9460            0 :         error ("assignment (not initialization) in declaration");
    9461            0 :       return;
    9462              :     }
    9463              : 
    9464    330463183 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    9465              :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    9466    330463183 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    9467              : 
    9468    330463183 :   tree type = TREE_TYPE (decl);
    9469    330463183 :   if (type == error_mark_node)
    9470              :     return;
    9471              : 
    9472    330462600 :   if (VAR_P (decl) && is_copy_initialization (init))
    9473    103943119 :     flags |= LOOKUP_ONLYCONVERTING;
    9474              : 
    9475              :   /* Warn about register storage specifiers except when in GNU global
    9476              :      or local register variable extension.  */
    9477    330462600 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    9478              :     {
    9479         1931 :       if (cxx_dialect >= cxx17)
    9480         1282 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9481              :                  "ISO C++17 does not allow %<register%> storage "
    9482              :                  "class specifier");
    9483              :       else
    9484          649 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9485              :                     "%<register%> storage class specifier used");
    9486              :     }
    9487              : 
    9488              :   /* If a name was specified, get the string.  */
    9489    330462600 :   if (at_namespace_scope_p ())
    9490     73037044 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    9491    330462600 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    9492       971900 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    9493              : 
    9494    330462600 :   bool in_class_decl
    9495    330462600 :     = (current_class_type
    9496    207094116 :        && CP_DECL_CONTEXT (decl) == current_class_type
    9497    133003074 :        && TYPE_BEING_DEFINED (current_class_type)
    9498    461212931 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    9499              : 
    9500    125600365 :   if (in_class_decl
    9501    125600365 :       && (DECL_INITIAL (decl) || init))
    9502     92241982 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    9503              : 
    9504    330462600 :   if (VAR_P (decl)
    9505    330462600 :       && (auto_node = type_uses_auto (type)))
    9506              :     {
    9507     14721955 :       tree d_init;
    9508     14721955 :       if (init == NULL_TREE)
    9509              :         {
    9510         1784 :           if (DECL_LANG_SPECIFIC (decl)
    9511         1701 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    9512         3482 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    9513              :             {
    9514              :               /* init is null because we're deferring instantiating the
    9515              :                  initializer until we need it.  Well, we need it now.  */
    9516         1692 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    9517         1692 :               return;
    9518              :             }
    9519              : 
    9520           92 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9521              :             /* Class deduction with no initializer is OK.  */;
    9522              :           else
    9523              :             {
    9524              :               /* Ordinary auto deduction without an initializer, a situation
    9525              :                  which grokdeclarator already detects and rejects for the most
    9526              :                  part.  But we can still get here if we're instantiating a
    9527              :                  variable template before we've fully parsed (and attached) its
    9528              :                  initializer, e.g. template<class> auto x = x<int>;  */
    9529            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    9530              :                         "declaration of %q#D has no initializer", decl);
    9531            3 :               TREE_TYPE (decl) = error_mark_node;
    9532            3 :               return;
    9533              :             }
    9534              :         }
    9535     14720260 :       d_init = init;
    9536     14720260 :       if (d_init)
    9537              :         {
    9538     14720171 :           if (TREE_CODE (d_init) == TREE_LIST
    9539     14770833 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9540        27632 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    9541              :                                                       tf_warning_or_error);
    9542     14720171 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    9543              :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    9544              :              on deprecated-14.C.  */
    9545     14720171 :           mark_single_function (d_init, tf_none);
    9546              :         }
    9547     14720260 :       enum auto_deduction_context adc = adc_variable_type;
    9548     14720260 :       if (DECL_DECOMPOSITION_P (decl))
    9549              :         adc = adc_decomp_type;
    9550     14720260 :       tree outer_targs = NULL_TREE;
    9551     14720260 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    9552          303 :           && DECL_LANG_SPECIFIC (decl)
    9553          126 :           && DECL_TEMPLATE_INFO (decl)
    9554     14720317 :           && !DECL_FUNCTION_SCOPE_P (decl))
    9555              :         /* The outer template arguments might be needed for satisfaction.
    9556              :            (For function scope variables, do_auto_deduction will obtain the
    9557              :            outer template arguments from current_function_decl.)  */
    9558           57 :         outer_targs = DECL_TI_ARGS (decl);
    9559     14720260 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    9560              :                                                    tf_warning_or_error, adc,
    9561              :                                                    outer_targs, flags);
    9562     14720260 :       if (type == error_mark_node)
    9563              :         return;
    9564     14719310 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    9565              :         {
    9566            3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    9567              :                  "did you forget the %<()%>?", decl);
    9568            3 :           TREE_TYPE (decl) = error_mark_node;
    9569            3 :           return;
    9570              :         }
    9571              :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    9572     14719307 :       if (!processing_template_decl
    9573      4621830 :           && !type_uses_auto (type)
    9574     19341130 :           && !COMPLETE_TYPE_P (complete_type (type)))
    9575              :         {
    9576           18 :           auto_diagnostic_group d;
    9577           18 :           error_at (location_of (decl),
    9578              :                     "deduced type %qT for %qD is incomplete", type, decl);
    9579           18 :           cxx_incomplete_type_inform (type);
    9580           18 :           TREE_TYPE (decl) = error_mark_node;
    9581           18 :           return;
    9582           18 :         }
    9583              : 
    9584              :       /* Now that we have a type, try these again.  */
    9585     14719289 :       layout_decl (decl, 0);
    9586     14719289 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    9587              : 
    9588              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    9589     14719289 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    9590              :         {
    9591        33088 :           tree tmpl = template_for_substitution (decl);
    9592        33088 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    9593        30763 :             TREE_TYPE (tmpl) = type;
    9594              :         }
    9595              :     }
    9596              : 
    9597    330459934 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    9598              :     {
    9599           65 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    9600           65 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    9601              :         {
    9602            6 :           init = NULL_TREE;
    9603            6 :           DECL_EXTERNAL (decl) = 1;
    9604              :         }
    9605              :     }
    9606              : 
    9607    330459934 :   if (VAR_P (decl)
    9608    131577209 :       && DECL_CLASS_SCOPE_P (decl)
    9609     19713415 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    9610              :                               TCTX_STATIC_STORAGE, type)
    9611    350173349 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    9612     18399255 :     check_static_variable_definition (decl, type);
    9613              : 
    9614    330459934 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    9615              :     {
    9616     40684296 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    9617     40684296 :                                    ? TCTX_THREAD_STORAGE
    9618              :                                    : TCTX_STATIC_STORAGE);
    9619     40684296 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    9620              :     }
    9621              : 
    9622    330459934 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    9623              :     {
    9624       554209 :       tree clone;
    9625       554209 :       if (init == ridpointers[(int)RID_DELETE]
    9626       554209 :           || (TREE_CODE (init) == STRING_CST
    9627           30 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    9628              :         {
    9629              :           /* FIXME check this is 1st decl.  */
    9630       532206 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    9631              :             {
    9632              :               /* [basic.start.main]/3: A program that defines main as deleted
    9633              :                  is ill-formed.  */
    9634            3 :               error ("%<::main%> cannot be deleted");
    9635            3 :               DECL_INITIAL (decl) = NULL_TREE;
    9636              :             }
    9637              :           else
    9638              :             {
    9639       532203 :               DECL_DELETED_FN (decl) = 1;
    9640       532203 :               DECL_DECLARED_INLINE_P (decl) = 1;
    9641       532203 :               DECL_INITIAL (decl)
    9642       532203 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    9643       532221 :               FOR_EACH_CLONE (clone, decl)
    9644              :                 {
    9645           18 :                   DECL_DELETED_FN (clone) = 1;
    9646           18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    9647           18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    9648              :                 }
    9649              :             }
    9650       532206 :           init = NULL_TREE;
    9651              :         }
    9652        22003 :       else if (init == ridpointers[(int)RID_DEFAULT])
    9653              :         {
    9654        21991 :           if (defaultable_fn_check (decl))
    9655        21967 :             DECL_DEFAULTED_FN (decl) = 1;
    9656              :           else
    9657           24 :             DECL_INITIAL (decl) = NULL_TREE;
    9658              :         }
    9659              :     }
    9660              : 
    9661    330459934 :   if (init && VAR_P (decl))
    9662              :     {
    9663    114218100 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    9664              :       /* If DECL is a reference, then we want to know whether init is a
    9665              :          reference constant; init_const_expr_p as passed tells us whether
    9666              :          it's an rvalue constant.  */
    9667    114218100 :       if (TYPE_REF_P (type))
    9668      2449197 :         init_const_expr_p = potential_constant_expression (init);
    9669    114218100 :       if (init_const_expr_p)
    9670              :         {
    9671              :           /* Set these flags now for templates.  We'll update the flags in
    9672              :              store_init_value for instantiations.  */
    9673    100142684 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    9674    100142684 :           if (decl_maybe_constant_var_p (decl)
    9675              :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    9676    100142684 :               && !TYPE_REF_P (type))
    9677     44838732 :             TREE_CONSTANT (decl) = true;
    9678              :         }
    9679              :       /* This is handled mostly by gimplify.cc, but we have to deal with
    9680              :          not warning about int x = x; as it is a GCC extension to turn off
    9681              :          this warning but only if warn_init_self is zero.  */
    9682    114218100 :       if (!DECL_EXTERNAL (decl)
    9683    112647145 :           && !TREE_STATIC (decl)
    9684     75021303 :           && decl == tree_strip_any_location_wrapper (init)
    9685    114221902 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    9686         3778 :         suppress_warning (decl, OPT_Winit_self);
    9687              :     }
    9688    216241834 :   else if (VAR_P (decl)
    9689     17359109 :            && COMPLETE_TYPE_P (type)
    9690     13918248 :            && !TYPE_REF_P (type)
    9691     13917883 :            && !dependent_type_p (type)
    9692    229866521 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    9693              :     /* We have no initializer but there's nothing to initialize anyway.
    9694              :        Treat DECL as constant due to c++/109876.  */
    9695       568116 :     TREE_CONSTANT (decl) = true;
    9696              : 
    9697    330459934 :   if (flag_openmp
    9698       841736 :       && TREE_CODE (decl) == FUNCTION_DECL
    9699              :       /* #pragma omp declare variant on methods handled in finish_struct
    9700              :          instead.  */
    9701    330822556 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
    9702       139374 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    9703       223711 :     if (tree attr = lookup_attribute ("omp declare variant base",
    9704       223711 :                                       DECL_ATTRIBUTES (decl)))
    9705          970 :       omp_declare_variant_finalize (decl, attr);
    9706              : 
    9707    330459934 :   if (processing_template_decl)
    9708              :     {
    9709    181784575 :       bool type_dependent_p;
    9710              : 
    9711              :       /* Add this declaration to the statement-tree.  */
    9712    181784575 :       if (at_function_scope_p ())
    9713     65774270 :         add_decl_expr (decl);
    9714              : 
    9715    181784575 :       type_dependent_p = dependent_type_p (type);
    9716              : 
    9717    181784575 :       if (check_for_bare_parameter_packs (init))
    9718              :         {
    9719            3 :           init = NULL_TREE;
    9720            3 :           DECL_INITIAL (decl) = NULL_TREE;
    9721              :         }
    9722              : 
    9723              :       /* Generally, initializers in templates are expanded when the
    9724              :          template is instantiated.  But, if DECL is a variable constant
    9725              :          then it can be used in future constant expressions, so its value
    9726              :          must be available. */
    9727              : 
    9728    181784575 :       bool dep_init = false;
    9729              : 
    9730    181784575 :       if (!VAR_P (decl) || type_dependent_p)
    9731              :         /* We can't do anything if the decl has dependent type.  */;
    9732     22743035 :       else if (init
    9733     21098337 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    9734     17157542 :                && !TYPE_REF_P (type)
    9735     17125951 :                && decl_maybe_constant_var_p (decl)
    9736     31472838 :                && !(dep_init = value_dependent_init_p (init)))
    9737              :         {
    9738              :           /* This variable seems to be a non-dependent constant, so process
    9739              :              its initializer.  If check_initializer returns non-null the
    9740              :              initialization wasn't constant after all.  */
    9741      2246618 :           tree init_code;
    9742      2246618 :           cleanups = make_tree_vector ();
    9743      2246618 :           init_code = check_initializer (decl, init, flags, &cleanups);
    9744      2246618 :           if (init_code == NULL_TREE)
    9745      2246618 :             init = NULL_TREE;
    9746      2246618 :           release_tree_vector (cleanups);
    9747              :         }
    9748              :       else
    9749              :         {
    9750     20496417 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    9751              :           /* Try to deduce array size.  */
    9752     20496417 :           maybe_deduce_size_from_array_init (decl, init);
    9753              :           /* And complain about multiple initializers.  */
    9754     18851719 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    9755     20602937 :               && !MAYBE_CLASS_TYPE_P (type))
    9756            7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    9757              :                                                     tf_warning_or_error);
    9758              :         }
    9759              : 
    9760    181784575 :       if (init)
    9761     54403163 :         DECL_INITIAL (decl) = init;
    9762              : 
    9763    181784575 :       if (dep_init)
    9764              :         {
    9765      6483185 :           retrofit_lang_decl (decl);
    9766      6483185 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    9767              :         }
    9768              : 
    9769    181784575 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    9770              :         {
    9771            9 :           if (TREE_ADDRESSABLE (decl))
    9772            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    9773              :                       "address of explicit register variable %qD requested",
    9774              :                       decl);
    9775              :           else
    9776              :             {
    9777            6 :               set_user_assembler_name (decl, asmspec);
    9778            6 :               DECL_HARD_REGISTER (decl) = 1;
    9779              :             }
    9780              :         }
    9781    181784575 :       return;
    9782              :     }
    9783              : 
    9784              :   /* Just store non-static data member initializers for later.  */
    9785    148675359 :   if (init && TREE_CODE (decl) == FIELD_DECL)
    9786       580126 :     DECL_INITIAL (decl) = init;
    9787              : 
    9788              :   /* Take care of TYPE_DECLs up front.  */
    9789    148675359 :   if (TREE_CODE (decl) == TYPE_DECL)
    9790              :     {
    9791     11732398 :       if (type != error_mark_node
    9792     11732398 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
    9793              :         {
    9794      5850817 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
    9795            0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
    9796      5850817 :           set_identifier_type_value (DECL_NAME (decl), decl);
    9797              :         }
    9798              : 
    9799              :       /* If we have installed this as the canonical typedef for this
    9800              :          type, and that type has not been defined yet, delay emitting
    9801              :          the debug information for it, as we will emit it later.  */
    9802     11732398 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
    9803     11732398 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9804       662490 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    9805              : 
    9806     11732398 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
    9807              :                                 at_eof);
    9808     11732398 :       return;
    9809              :     }
    9810              : 
    9811              :   /* A reference will be modified here, as it is initialized.  */
    9812    136942961 :   if (! DECL_EXTERNAL (decl)
    9813     72671140 :       && TREE_READONLY (decl)
    9814    179046475 :       && TYPE_REF_P (type))
    9815              :     {
    9816       345960 :       was_readonly = 1;
    9817       345960 :       TREE_READONLY (decl) = 0;
    9818              :     }
    9819              : 
    9820              :   /* This needs to happen before extend_ref_init_temps.  */
    9821    136942961 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9822              :     {
    9823    127911695 :       if (VAR_P (decl))
    9824     71529490 :         maybe_commonize_var (decl);
    9825    127911695 :       determine_visibility (decl);
    9826              :     }
    9827              : 
    9828    136942961 :   if (VAR_P (decl))
    9829              :     {
    9830     71529490 :       duration_kind dk = decl_storage_duration (decl);
    9831              :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
    9832              :          only to a declaration of a variable with static or thread storage
    9833              :          duration."  */
    9834     71529490 :       if (DECL_DECLARED_CONSTINIT_P (decl)
    9835     71529490 :           && !(dk == dk_thread || dk == dk_static))
    9836              :         {
    9837           24 :           error_at (DECL_SOURCE_LOCATION (decl),
    9838              :                     "%<constinit%> can only be applied to a variable with "
    9839              :                     "static or thread storage duration");
    9840           24 :           return;
    9841              :         }
    9842              : 
    9843     71529466 :       if (decomp)
    9844              :         {
    9845       108990 :           if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
    9846           40 :             pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    9847              :                      "%<constinit%> can be applied to structured binding "
    9848              :                      "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
    9849       108990 :           cp_maybe_mangle_decomp (decl, decomp);
    9850       108990 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
    9851              :             {
    9852          500 :               if (CP_DECL_THREAD_LOCAL_P (decl))
    9853           37 :                 aggregates1 = tls_aggregates;
    9854              :               else
    9855          463 :                 aggregates1 = static_aggregates;
    9856              :             }
    9857              :         }
    9858              : 
    9859              :       /* Detect stuff like 'info r = ^^int;' outside a manifestly
    9860              :          constant-evaluated context.  */
    9861     71529466 :       check_out_of_consteval_use (decl);
    9862              : 
    9863              :       /* If this is a local variable that will need a mangled name,
    9864              :          register it now.  We must do this before processing the
    9865              :          initializer for the variable, since the initialization might
    9866              :          require a guard variable, and since the mangled name of the
    9867              :          guard variable will depend on the mangled name of this
    9868              :          variable.  */
    9869    143058932 :       if (DECL_FUNCTION_SCOPE_P (decl)
    9870     31013640 :           && TREE_STATIC (decl)
    9871       168612 :           && !DECL_ARTIFICIAL (decl)
    9872     71697160 :           && !consteval_only_p (decl))
    9873              :         {
    9874              :           /* The variable holding an anonymous union will have had its
    9875              :              discriminator set in finish_anon_union, after which it's
    9876              :              NAME will have been cleared.  */
    9877       167629 :           if (DECL_NAME (decl))
    9878       167584 :             determine_local_discriminator (decl);
    9879              :           /* Normally has_forced_label_in_static is set during GIMPLE
    9880              :              lowering, but [cd]tors are never actually compiled directly.
    9881              :              We need to set this early so we can deal with the label
    9882              :              address extension.  */
    9883       167629 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
    9884       167600 :                || DECL_DESTRUCTOR_P (current_function_decl))
    9885       167639 :               && init)
    9886              :             {
    9887           29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
    9888           29 :               add_local_decl (cfun, decl);
    9889              :             }
    9890              :           /* And make sure it's in the symbol table for
    9891              :              c_parse_final_cleanups to find.  */
    9892       167629 :           varpool_node::get_create (decl);
    9893              :         }
    9894              : 
    9895     71529466 :       if (flag_openmp
    9896       192915 :           && VAR_P (decl)
    9897       192915 :           && DECL_LANG_SPECIFIC (decl)
    9898       115398 :           && DECL_OMP_DECLARE_MAPPER_P (decl)
    9899     71529470 :           && init)
    9900              :         {
    9901            3 :           gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
    9902            3 :           DECL_INITIAL (decl) = init;
    9903              :         }
    9904              :       /* Convert the initializer to the type of DECL, if we have not
    9905              :          already initialized DECL.  */
    9906     71529463 :       else if (!DECL_INITIALIZED_P (decl)
    9907              :                /* If !DECL_EXTERNAL then DECL is being defined.  In the
    9908              :                   case of a static data member initialized inside the
    9909              :                   class-specifier, there can be an initializer even if DECL
    9910              :                   is *not* defined.  */
    9911     71529463 :                && (!DECL_EXTERNAL (decl) || init))
    9912              :         {
    9913     64631120 :           cleanups = make_tree_vector ();
    9914     64631120 :           init = check_initializer (decl, init, flags, &cleanups);
    9915              : 
    9916              :           /* Handle:
    9917              : 
    9918              :              [dcl.init]
    9919              : 
    9920              :              The memory occupied by any object of static storage
    9921              :              duration is zero-initialized at program startup before
    9922              :              any other initialization takes place.
    9923              : 
    9924              :              We cannot create an appropriate initializer until after
    9925              :              the type of DECL is finalized.  If DECL_INITIAL is set,
    9926              :              then the DECL is statically initialized, and any
    9927              :              necessary zero-initialization has already been performed.  */
    9928     64628423 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
    9929       497611 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
    9930              :                                                    /*nelts=*/NULL_TREE,
    9931              :                                                    /*static_storage_p=*/true);
    9932              :           /* Remember that the initialization for this variable has
    9933              :              taken place.  */
    9934     64628423 :           DECL_INITIALIZED_P (decl) = 1;
    9935              :           /* This declaration is the definition of this variable,
    9936              :              unless we are initializing a static data member within
    9937              :              the class specifier.  */
    9938     64628423 :           if (!DECL_EXTERNAL (decl))
    9939     71526769 :             var_definition_p = true;
    9940              :         }
    9941              :       /* If the variable has an array type, lay out the type, even if
    9942              :          there is no initializer.  It is valid to index through the
    9943              :          array, and we must get TYPE_ALIGN set correctly on the array
    9944              :          type.  */
    9945      6898343 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    9946       210293 :         layout_type (type);
    9947              : 
    9948     71526769 :       if (TREE_STATIC (decl)
    9949     40135486 :           && !at_function_scope_p ()
    9950    111493643 :           && current_function_decl == NULL)
    9951              :         /* So decl is a global variable or a static member of a
    9952              :            non local class. Record the types it uses
    9953              :            so that we can decide later to emit debug info for them.  */
    9954     39966862 :         record_types_used_by_current_var_decl (decl);
    9955              :     }
    9956              : 
    9957              :   /* Add this declaration to the statement-tree.  This needs to happen
    9958              :      after the call to check_initializer so that the DECL_EXPR for a
    9959              :      reference temp is added before the DECL_EXPR for the reference itself.  */
    9960    136940240 :   if (DECL_FUNCTION_SCOPE_P (decl))
    9961              :     {
    9962              :       /* If we're building a variable sized type, and we might be
    9963              :          reachable other than via the top of the current binding
    9964              :          level, then create a new BIND_EXPR so that we deallocate
    9965              :          the object at the right time.  */
    9966     31013640 :       if (VAR_P (decl)
    9967     31013640 :           && DECL_SIZE (decl)
    9968     30954291 :           && !TREE_CONSTANT (DECL_SIZE (decl))
    9969     31014670 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    9970              :         {
    9971            3 :           tree bind;
    9972            3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    9973            3 :           TREE_SIDE_EFFECTS (bind) = 1;
    9974            3 :           add_stmt (bind);
    9975            3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
    9976              :         }
    9977     31013640 :       add_decl_expr (decl);
    9978              :     }
    9979              : 
    9980    136940240 :   tree decomp_init = NULL_TREE;
    9981              :   /* Let the middle end know about variables and functions -- but not
    9982              :      static data members in uninstantiated class templates.  */
    9983    136940240 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9984              :     {
    9985    127908974 :       if (VAR_P (decl))
    9986              :         {
    9987     71526769 :           layout_var_decl (decl);
    9988     71526769 :           if (!flag_weak)
    9989              :             /* Check again now that we have an initializer.  */
    9990           57 :             maybe_commonize_var (decl);
    9991              :           /* A class-scope constexpr variable with an out-of-class declaration.
    9992              :              C++17 makes them implicitly inline, but still force it out.  */
    9993     93537185 :           if (DECL_INLINE_VAR_P (decl)
    9994     32035104 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
    9995     12775487 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
    9996     49854241 :               && !in_class_decl)
    9997          103 :             mark_needed (decl);
    9998              :         }
    9999              : 
   10000    127908974 :       if (var_definition_p
   10001              :           /* With -fmerge-all-constants, gimplify_init_constructor
   10002              :              might add TREE_STATIC to aggregate variables.  */
   10003     63485486 :           && (TREE_STATIC (decl)
   10004     30845170 :               || (flag_merge_constants >= 2
   10005           38 :                   && AGGREGATE_TYPE_P (type))))
   10006              :         {
   10007              :           /* If a TREE_READONLY variable needs initialization
   10008              :              at runtime, it is no longer readonly and we need to
   10009              :              avoid MEM_READONLY_P being set on RTL created for it.  */
   10010     32640319 :           if (init)
   10011              :             {
   10012        14147 :               if (TREE_READONLY (decl))
   10013          506 :                 TREE_READONLY (decl) = 0;
   10014              :               was_readonly = 0;
   10015              :             }
   10016     32626172 :           else if (was_readonly)
   10017         2265 :             TREE_READONLY (decl) = 1;
   10018              : 
   10019              :           /* Likewise if it needs destruction.  */
   10020     32640319 :           if (!decl_maybe_constant_destruction (decl, type))
   10021         3314 :             TREE_READONLY (decl) = 0;
   10022              :         }
   10023     95268655 :       else if (VAR_P (decl)
   10024     38886450 :                && CP_DECL_THREAD_LOCAL_P (decl)
   10025        18540 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
   10026        18540 :                && (was_readonly || TREE_READONLY (decl))
   10027     95268670 :                && var_needs_tls_wrapper (decl))
   10028              :         {
   10029              :           /* TLS variables need dynamic initialization by the TLS wrapper
   10030              :              function, we don't want to hoist accesses to it before the
   10031              :              wrapper.  */
   10032            6 :           was_readonly = 0;
   10033            6 :           TREE_READONLY (decl) = 0;
   10034              :         }
   10035              : 
   10036    127908974 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
   10037              : 
   10038              :       /* Check for abstractness of the type.  */
   10039    127908974 :       if (var_definition_p)
   10040     63485486 :         abstract_virtuals_error (decl, type);
   10041              : 
   10042    127908974 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
   10043        43598 :         decomp = NULL;
   10044              : 
   10045    127908974 :       if (TREE_TYPE (decl) == error_mark_node)
   10046              :         /* No initialization required.  */
   10047              :         ;
   10048    127908904 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
   10049              :         {
   10050     56382205 :           if (init)
   10051              :             {
   10052          575 :               if (init == ridpointers[(int)RID_DEFAULT])
   10053              :                 {
   10054              :                   /* An out-of-class default definition is defined at
   10055              :                      the point where it is explicitly defaulted.  */
   10056          563 :                   if (DECL_DELETED_FN (decl))
   10057            6 :                     maybe_explain_implicit_delete (decl);
   10058          557 :                   else if (DECL_INITIAL (decl) == error_mark_node)
   10059          533 :                     synthesize_method (decl);
   10060              :                 }
   10061              :               else
   10062           24 :                 error_at (cp_expr_loc_or_loc (init,
   10063           12 :                                               DECL_SOURCE_LOCATION (decl)),
   10064              :                           "function %q#D is initialized like a variable",
   10065              :                           decl);
   10066              :             }
   10067              :           /* else no initialization required.  */
   10068              :         }
   10069     71526699 :       else if (DECL_EXTERNAL (decl)
   10070     71526699 :                && ! (DECL_LANG_SPECIFIC (decl)
   10071      7740723 :                      && DECL_NOT_REALLY_EXTERN (decl)))
   10072              :         {
   10073              :           /* check_initializer will have done any constant initialization.  */
   10074              :         }
   10075              :       /* A variable definition.  */
   10076     65441252 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
   10077              :         {
   10078              :           /* Initialize the local variable.  */
   10079     30845010 :           if (!decomp)
   10080     30779863 :             initialize_local_var (decl, init, false);
   10081              :           else
   10082              :             {
   10083        65147 :               tree cleanup = NULL_TREE;
   10084        65147 :               if (DECL_SIZE (decl))
   10085        65147 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10086              :               /* If cp_finish_decomp needs to emit any code, we need to emit that
   10087              :                  code after code emitted by initialize_local_var in a single
   10088              :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
   10089              :                  after the cp_finish_decomp emitted code.
   10090              :                  If there are any cleanups, either extend_ref_init_temps
   10091              :                  created ones or e.g. array destruction, push those first
   10092              :                  with the cleanups guarded on a bool temporary, initially
   10093              :                  set to false and set to true after initialize_local_var
   10094              :                  emitted code.  */
   10095        65147 :               tree guard = NULL_TREE;
   10096        65147 :               if (cleanups || cleanup)
   10097              :                 {
   10098        65147 :                   guard = get_internal_target_expr (boolean_false_node);
   10099        65147 :                   add_stmt (guard);
   10100        65147 :                   guard = TARGET_EXPR_SLOT (guard);
   10101              :                 }
   10102        65147 :               tree sl = push_stmt_list ();
   10103        65147 :               initialize_local_var (decl, init, true);
   10104        65147 :               if (guard)
   10105              :                 {
   10106        65147 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
   10107              :                                     guard, boolean_true_node));
   10108        65165 :                   for (tree &t : *cleanups)
   10109           18 :                     t = build3 (COND_EXPR, void_type_node,
   10110              :                                 guard, t, void_node);
   10111        65147 :                   if (cleanup)
   10112           25 :                     cleanup = build3 (COND_EXPR, void_type_node,
   10113              :                                       guard, cleanup, void_node);
   10114              :                 }
   10115        65147 :               unsigned before = stmt_list_stack->length ();
   10116        65147 :               cp_finish_decomp (decl, decomp);
   10117        65147 :               decomp = NULL;
   10118        65147 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
   10119        65147 :               sl = pop_stmt_list (sl);
   10120        65147 :               if (n_extra_cleanups)
   10121              :                 {
   10122              :                   /* If cp_finish_decomp needs any cleanups, such as for
   10123              :                      extend_ref_init_temps created vars, pop_stmt_list
   10124              :                      popped that all, so push those extra cleanups around
   10125              :                      the whole sequence with a guard variable.  */
   10126           15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
   10127           15 :                   guard = get_internal_target_expr (integer_zero_node);
   10128           15 :                   add_stmt (guard);
   10129           15 :                   guard = TARGET_EXPR_SLOT (guard);
   10130           63 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
   10131              :                     {
   10132           48 :                       tree_stmt_iterator tsi = tsi_last (sl);
   10133           48 :                       gcc_assert (!tsi_end_p (tsi));
   10134           48 :                       tree last = tsi_stmt (tsi);
   10135           48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
   10136              :                                   && !CLEANUP_EH_ONLY (last));
   10137           48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
   10138           96 :                       tree cl = build3 (COND_EXPR, void_type_node,
   10139              :                                         build2 (GE_EXPR, boolean_type_node,
   10140              :                                                 guard, cst),
   10141           48 :                                         CLEANUP_EXPR (last), void_node);
   10142           48 :                       extra_cleanups.safe_push (cl);
   10143           48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
   10144              :                                                      integer_type_node,
   10145              :                                                      guard, cst),
   10146              :                                        TSI_SAME_STMT);
   10147           48 :                       tree sl2 = CLEANUP_BODY (last);
   10148           48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
   10149           48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
   10150           48 :                       tsi_delink (&tsi);
   10151              :                     }
   10152              :                 }
   10153        65147 :               decomp_init = maybe_cleanup_point_expr_void (sl);
   10154        65147 :               if (cleanup)
   10155           25 :                 finish_decl_cleanup (decl, cleanup);
   10156              :             }
   10157              :         }
   10158              : 
   10159              :       /* If a variable is defined, and then a subsequent
   10160              :          definition with external linkage is encountered, we will
   10161              :          get here twice for the same variable.  We want to avoid
   10162              :          calling expand_static_init more than once.  For variables
   10163              :          that are not static data members, we can call
   10164              :          expand_static_init only when we actually process the
   10165              :          initializer.  It is not legal to redeclare a static data
   10166              :          member, so this issue does not arise in that case.  */
   10167     34596242 :       else if (var_definition_p && TREE_STATIC (decl))
   10168              :         {
   10169     32639605 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
   10170              :             {
   10171          100 :               tree sl = push_stmt_list ();
   10172          100 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
   10173          100 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
   10174          100 :               expand_static_init (decl, init);
   10175          100 :               current_stmt_tree ()->stmts_are_full_exprs_p
   10176          100 :                 = saved_stmts_are_full_exprs_p;
   10177          100 :               cp_finish_decomp (decl, decomp);
   10178          100 :               decomp = NULL;
   10179          100 :               sl = pop_stmt_list (sl);
   10180          100 :               sl = maybe_cleanup_point_expr_void (sl);
   10181          100 :               add_stmt (sl);
   10182              :             }
   10183              :           else
   10184     32639505 :             expand_static_init (decl, init);
   10185              :         }
   10186              :     }
   10187              : 
   10188              :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
   10189              :      reference, insert it in the statement-tree now.  */
   10190    136940240 :   if (cleanups)
   10191              :     {
   10192     64647723 :       for (tree t : *cleanups)
   10193              :         {
   10194        19300 :           push_cleanup (NULL_TREE, t, false);
   10195              :           /* As in initialize_local_var.  */
   10196        19300 :           wrap_temporary_cleanups (init, t);
   10197              :         }
   10198     64628423 :       release_tree_vector (cleanups);
   10199              :     }
   10200              : 
   10201    136940318 :   for (tree t : &extra_cleanups)
   10202           48 :     push_cleanup (NULL_TREE, t, false);
   10203              : 
   10204    136940240 :   if (decomp_init)
   10205        65147 :     add_stmt (decomp_init);
   10206              : 
   10207    136940240 :   if (decomp
   10208          145 :       && var_definition_p
   10209          145 :       && TREE_STATIC (decl)
   10210    136940385 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10211              :     {
   10212          145 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
   10213          145 :                            ? tls_aggregates : static_aggregates);
   10214          145 :       tree aggregates2 = aggregates3;
   10215          145 :       if (aggregates2 != aggregates1)
   10216              :         {
   10217           66 :           cp_finish_decomp (decl, decomp);
   10218           66 :           decomp = NULL;
   10219           66 :           if (aggregates3 != aggregates2)
   10220              :             {
   10221              :               /* If there are dynamic initializers for the structured
   10222              :                  binding base or associated extended ref temps and also
   10223              :                  dynamic initializers for the structured binding non-base
   10224              :                  vars, mark them.  */
   10225          315 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
   10226          252 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
   10227          150 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
   10228           87 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
   10229              :             }
   10230              :         }
   10231              :     }
   10232              : 
   10233    136940240 :   if (was_readonly)
   10234       345379 :     TREE_READONLY (decl) = 1;
   10235              : 
   10236    136940240 :   if (flag_openmp
   10237       436019 :       && VAR_P (decl)
   10238    137133155 :       && lookup_attribute ("omp declare target implicit",
   10239       192915 :                            DECL_ATTRIBUTES (decl)))
   10240              :     {
   10241           52 :       DECL_ATTRIBUTES (decl)
   10242           52 :         = remove_attribute ("omp declare target implicit",
   10243           52 :                             DECL_ATTRIBUTES (decl));
   10244           52 :       complete_type (TREE_TYPE (decl));
   10245           52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
   10246              :         {
   10247           30 :           auto_diagnostic_group d;
   10248           30 :           error ("%q+D in declare target directive does not have mappable"
   10249              :                  " type", decl);
   10250           30 :           if (TREE_TYPE (decl) != error_mark_node
   10251           30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10252           30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
   10253           30 :         }
   10254           22 :       else if (!lookup_attribute ("omp declare target",
   10255           22 :                                   DECL_ATTRIBUTES (decl))
   10256           44 :                && !lookup_attribute ("omp declare target link",
   10257           22 :                                      DECL_ATTRIBUTES (decl)))
   10258              :         {
   10259           22 :           DECL_ATTRIBUTES (decl)
   10260           22 :             = tree_cons (get_identifier ("omp declare target"),
   10261           22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
   10262           22 :           symtab_node *node = symtab_node::get (decl);
   10263           22 :           if (node != NULL)
   10264              :             {
   10265           19 :               node->offloadable = 1;
   10266           19 :               if (ENABLE_OFFLOADING)
   10267              :                 {
   10268              :                   g->have_offload = true;
   10269              :                   if (is_a <varpool_node *> (node))
   10270              :                     vec_safe_push (offload_vars, decl);
   10271              :                 }
   10272              :             }
   10273              :         }
   10274              :     }
   10275              : 
   10276              :   /* This is the last point we can lower alignment so give the target the
   10277              :      chance to do so.  */
   10278    136940240 :   if (VAR_P (decl)
   10279     71526769 :       && !is_global_var (decl)
   10280    167785410 :       && !DECL_HARD_REGISTER (decl))
   10281     30845117 :     targetm.lower_local_decl_alignment (decl);
   10282              : 
   10283    136940240 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
   10284    330460526 : }
   10285              : 
   10286              : /* For class TYPE return itself or some its bases that contain
   10287              :    any direct non-static data members.  Return error_mark_node if an
   10288              :    error has been diagnosed.  */
   10289              : 
   10290              : static tree
   10291        61170 : find_decomp_class_base (location_t loc, tree type, tree ret,
   10292              :                         tsubst_flags_t complain)
   10293              : {
   10294       122340 :   if (LAMBDA_TYPE_P (type))
   10295              :     {
   10296           12 :       if (complain & tf_error)
   10297              :         {
   10298           12 :           auto_diagnostic_group d;
   10299           12 :           error_at (loc, "cannot decompose lambda closure type %qT", type);
   10300           12 :           inform (location_of (type), "lambda declared here");
   10301           12 :         }
   10302           12 :       return error_mark_node;
   10303              :     }
   10304              : 
   10305        61158 :   bool member_seen = false;
   10306       708857 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   10307      1172485 :     if (TREE_CODE (field) != FIELD_DECL
   10308       123121 :         || DECL_ARTIFICIAL (field)
   10309       770765 :         || DECL_UNNAMED_BIT_FIELD (field))
   10310       524747 :       continue;
   10311       122991 :     else if (ret)
   10312              :       return type;
   10313       122965 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   10314              :       {
   10315            8 :         if ((complain & tf_error) == 0)
   10316            0 :           return error_mark_node;
   10317            8 :         auto_diagnostic_group d;
   10318            8 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
   10319            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10320              :                          "anonymous struct member", type);
   10321              :         else
   10322            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10323              :                          "anonymous union member", type);
   10324            8 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
   10325            8 :         return error_mark_node;
   10326            8 :       }
   10327       122957 :     else if (!accessible_p (type, field, true))
   10328              :       {
   10329            5 :         if ((complain & tf_error) == 0)
   10330            0 :           return error_mark_node;
   10331            5 :         auto_diagnostic_group d;
   10332            5 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
   10333              :                   field, type);
   10334            5 :         inform (DECL_SOURCE_LOCATION (field),
   10335            5 :                 TREE_PRIVATE (field)
   10336              :                 ? G_("declared private here")
   10337              :                 : G_("declared protected here"));
   10338            5 :         return error_mark_node;
   10339            5 :       }
   10340              :     else
   10341              :       member_seen = true;
   10342              : 
   10343        61119 :   tree base_binfo, binfo;
   10344        61119 :   tree orig_ret = ret;
   10345        61119 :   int i;
   10346        61119 :   if (member_seen)
   10347        61022 :     ret = type;
   10348        61177 :   for (binfo = TYPE_BINFO (type), i = 0;
   10349        61177 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   10350              :     {
   10351           78 :       auto_diagnostic_group d;
   10352           78 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
   10353              :                                        complain);
   10354           78 :       if (t == error_mark_node)
   10355              :         {
   10356            3 :           if (complain & tf_error)
   10357            3 :             inform (location_of (type), "in base class of %qT", type);
   10358            3 :           return error_mark_node;
   10359              :         }
   10360           75 :       if (t != NULL_TREE && t != ret)
   10361              :         {
   10362           48 :           if (ret == type)
   10363              :             {
   10364           10 :               if (complain & tf_error)
   10365           10 :                 error_at (loc, "cannot decompose class type %qT: both it and "
   10366              :                                "its base class %qT have non-static data "
   10367              :                                "members", type, t);
   10368           10 :               return error_mark_node;
   10369              :             }
   10370           38 :           else if (orig_ret != NULL_TREE)
   10371              :             return t;
   10372           38 :           else if (ret != NULL_TREE)
   10373              :             {
   10374            7 :               if (complain & tf_error)
   10375            7 :                 error_at (loc, "cannot decompose class type %qT: its base "
   10376              :                                "classes %qT and %qT have non-static data "
   10377              :                                "members", type, ret, t);
   10378            7 :               return error_mark_node;
   10379              :             }
   10380              :           else
   10381              :             ret = t;
   10382              :         }
   10383           78 :     }
   10384              :   return ret;
   10385              : }
   10386              : 
   10387              : /* Return std::tuple_size<TYPE>::value.  */
   10388              : 
   10389              : static tree
   10390       201325 : get_tuple_size (tree type)
   10391              : {
   10392       201325 :   tree args = make_tree_vec (1);
   10393       201325 :   TREE_VEC_ELT (args, 0) = type;
   10394       201325 :   tree inst = lookup_template_class (tuple_size_identifier, args,
   10395              :                                      /*in_decl*/NULL_TREE,
   10396              :                                      /*context*/std_node,
   10397              :                                      tf_none);
   10398       201325 :   inst = complete_type (inst);
   10399       201325 :   if (inst == error_mark_node
   10400       199869 :       || !COMPLETE_TYPE_P (inst)
   10401       341516 :       || !CLASS_TYPE_P (inst))
   10402              :     return NULL_TREE;
   10403       140191 :   tree val = lookup_qualified_name (inst, value_identifier,
   10404              :                                     LOOK_want::NORMAL, /*complain*/false);
   10405       140191 :   if (val == error_mark_node)
   10406              :     return NULL_TREE;
   10407       140185 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
   10408       140185 :     val = maybe_constant_value (val, NULL_TREE, mce_true);
   10409       140185 :   if (TREE_CODE (val) == INTEGER_CST)
   10410              :     return val;
   10411              :   else
   10412            6 :     return error_mark_node;
   10413              : }
   10414              : 
   10415              : /* Return std::tuple_element<I,TYPE>::type.  */
   10416              : 
   10417              : static tree
   10418       150184 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
   10419              : {
   10420       150184 :   tree args = make_tree_vec (2);
   10421       150184 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
   10422       150184 :   TREE_VEC_ELT (args, 1) = type;
   10423       150184 :   tree inst = lookup_template_class (tuple_element_identifier, args,
   10424              :                                      /*in_decl*/NULL_TREE,
   10425              :                                      /*context*/std_node,
   10426              :                                      tf_warning_or_error);
   10427       150184 :   return make_typename_type (inst, type_identifier,
   10428       150184 :                              none_type, tf_warning_or_error);
   10429              : }
   10430              : 
   10431              : /* Return e.get<i>() or get<i>(e).  */
   10432              : 
   10433              : static tree
   10434       150193 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
   10435              : {
   10436       150193 :   tree targs = make_tree_vec (1);
   10437       150193 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
   10438              : 
   10439       150193 :   tree etype = TREE_TYPE (decl);
   10440       150193 :   tree e = convert_from_reference (decl);
   10441              : 
   10442              :   /* [The id-expression] e is an lvalue if the type of the entity e is an
   10443              :      lvalue reference and an xvalue otherwise.  */
   10444       150193 :   if (!TYPE_REF_P (etype)
   10445       150193 :       || TYPE_REF_IS_RVALUE (etype))
   10446       148900 :     e = move (e);
   10447              : 
   10448       150193 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
   10449              :                                     LOOK_want::NORMAL, /*complain*/false);
   10450       150193 :   bool use_member_get = false;
   10451              : 
   10452              :   /* To use a member get, member lookup must find at least one
   10453              :      declaration that is a function template
   10454              :      whose first template parameter is a non-type parameter.  */
   10455       448114 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
   10456              :     {
   10457       150193 :       tree fn = *iter;
   10458       150193 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
   10459              :         {
   10460         2468 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
   10461         2468 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
   10462         2468 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
   10463              :             {
   10464              :               use_member_get = true;
   10465              :               break;
   10466              :             }
   10467              :         }
   10468              :     }
   10469              : 
   10470       150193 :   if (use_member_get)
   10471              :     {
   10472         2465 :       fns = lookup_template_function (fns, targs);
   10473         2465 :       return build_new_method_call (e, fns, /*args*/NULL,
   10474              :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
   10475         2465 :                                     /*fn_p*/NULL, tf_warning_or_error);
   10476              :     }
   10477              :   else
   10478              :     {
   10479       147728 :       releasing_vec args (make_tree_vector_single (e));
   10480       147728 :       fns = lookup_template_function (get__identifier, targs);
   10481       147728 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
   10482       147728 :       return finish_call_expr (fns, &args, /*novirt*/false,
   10483              :                                /*koenig*/true, tf_warning_or_error);
   10484       147728 :     }
   10485              : }
   10486              : 
   10487              : /* It's impossible to recover the decltype of a tuple decomposition variable
   10488              :    based on the actual type of the variable, so store it in a hash table.  */
   10489              : 
   10490              : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
   10491              : 
   10492              : tree
   10493          587 : lookup_decomp_type (tree v)
   10494              : {
   10495          587 :   if (decomp_type_table)
   10496          460 :     if (tree *slot = decomp_type_table->get (v))
   10497          396 :       return *slot;
   10498              :   return NULL_TREE;
   10499              : }
   10500              : 
   10501              : /* Mangle a decomposition declaration if needed.  Arguments like
   10502              :    in cp_finish_decomp.  */
   10503              : 
   10504              : static void
   10505       108990 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
   10506              : {
   10507       108990 :   if (!processing_template_decl
   10508       108990 :       && !error_operand_p (decl)
   10509       217980 :       && TREE_STATIC (decl))
   10510              :     {
   10511          761 :       auto_vec<tree, 16> v;
   10512          761 :       v.safe_grow (decomp->count, true);
   10513          761 :       tree d = decomp->decl;
   10514         2633 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
   10515         1872 :         v[decomp->count - i - 1] = d;
   10516          761 :       if (DECL_FUNCTION_SCOPE_P (decl))
   10517              :         {
   10518              :           size_t sz = 3;
   10519          915 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10520          654 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
   10521          261 :           char *name = XALLOCAVEC (char, sz);
   10522          261 :           name[0] = 'D';
   10523          261 :           name[1] = 'C';
   10524          261 :           char *p = name + 2;
   10525          915 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10526              :             {
   10527          654 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
   10528          654 :               *p++ = ' ';
   10529          654 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
   10530          654 :               p += len;
   10531              :             }
   10532          261 :           *p = '\0';
   10533          261 :           determine_local_discriminator (decl, get_identifier (name));
   10534              :         }
   10535          761 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
   10536          761 :       maybe_apply_pragma_weak (decl);
   10537          761 :     }
   10538       108990 : }
   10539              : 
   10540              : /* Append #i to DECL_NAME (decl) or for name independent decls
   10541              :    clear DECL_NAME (decl).  */
   10542              : 
   10543              : static void
   10544         2055 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
   10545              : {
   10546         2055 :   if (name_independent_decl_p (decl))
   10547              :     /* Only "_" names are treated as name independent, "_#0" etc. is not and
   10548              :        because we pushdecl the individual decl elements of structured binding
   10549              :        pack, we could get redeclaration errors if there are 2 or more name
   10550              :        independent structured binding packs in the same scope.  */
   10551          312 :     DECL_NAME (decl) = NULL_TREE;
   10552              :   else
   10553              :     {
   10554         1743 :       tree name = DECL_NAME (decl);
   10555         1743 :       size_t len = IDENTIFIER_LENGTH (name) + 22;
   10556         1743 :       char *n = XALLOCAVEC (char, len);
   10557         1743 :       snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
   10558         1743 :                 IDENTIFIER_POINTER (name), i);
   10559         1743 :       DECL_NAME (decl) = get_identifier (n);
   10560              :     }
   10561         2055 : }
   10562              : 
   10563              : /* Return structured binding size of TYPE or -1 if erroneous.  */
   10564              : 
   10565              : HOST_WIDE_INT
   10566          468 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
   10567              : {
   10568          468 :   if (TYPE_REF_P (type))
   10569              :     {
   10570            0 :       type = complete_type (TREE_TYPE (type));
   10571            0 :       if (type == error_mark_node)
   10572              :         return -1;
   10573            0 :       if (!COMPLETE_TYPE_P (type))
   10574              :         {
   10575            0 :           if (complain & tf_error)
   10576            0 :             error_at (loc, "structured binding refers to incomplete type %qT",
   10577              :                       type);
   10578            0 :           return -1;
   10579              :         }
   10580              :     }
   10581              : 
   10582          468 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10583          468 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10584              :     {
   10585          262 :       if (TYPE_DOMAIN (type) == NULL_TREE)
   10586              :         {
   10587            9 :           if (complain & tf_error)
   10588            6 :             error_at (loc, "cannot decompose array of unknown bound %qT",
   10589              :                       type);
   10590            9 :           return -1;
   10591              :         }
   10592          253 :       tree nelts = array_type_nelts_top (type);
   10593          253 :       if (nelts == error_mark_node)
   10594              :         return -1;
   10595          253 :       if (!tree_fits_shwi_p (nelts))
   10596              :         {
   10597            3 :           if (complain & tf_error)
   10598            3 :             error_at (loc, "cannot decompose variable length array %qT", type);
   10599            3 :           return -1;
   10600              :         }
   10601          250 :       return tree_to_shwi (nelts);
   10602              :     }
   10603              :   /* 2 GNU extensions.  */
   10604          206 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10605              :     return 2;
   10606          200 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10607              :     {
   10608           12 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10609              :         {
   10610              :           if (complain & tf_error)
   10611              :             error_at (loc, "cannot decompose variable length vector %qT", type);
   10612              :           return -1;
   10613              :         }
   10614           12 :       return eltscnt;
   10615              :     }
   10616          188 :   else if (tree tsize = get_tuple_size (type))
   10617              :     {
   10618           29 :       if (tsize == error_mark_node
   10619           23 :           || !tree_fits_shwi_p (tsize)
   10620           52 :           || tree_int_cst_sgn (tsize) < 0)
   10621              :         {
   10622            9 :           if (complain & tf_error)
   10623            9 :             error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10624              :                            "constant expression", type);
   10625            9 :           return -1;
   10626              :         }
   10627           20 :       return tree_to_shwi (tsize);
   10628              :     }
   10629          159 :   else if (TREE_CODE (type) == UNION_TYPE)
   10630              :     {
   10631            3 :       if (complain & tf_error)
   10632            3 :         error_at (loc, "cannot decompose union type %qT", type);
   10633            3 :       return -1;
   10634              :     }
   10635          156 :   else if (!CLASS_TYPE_P (type))
   10636              :     {
   10637           21 :       if (complain & tf_error)
   10638           18 :         error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10639           21 :       return -1;
   10640              :     }
   10641          135 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10642              :     return -1;
   10643          135 :   else if (!COMPLETE_TYPE_P (type))
   10644              :     {
   10645            3 :       if (complain & tf_error)
   10646            3 :         error_at (loc, "structured binding refers to incomplete class type "
   10647              :                   "%qT", type);
   10648            3 :       return -1;
   10649              :     }
   10650              :   else
   10651              :     {
   10652          132 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
   10653          132 :       if (btype == error_mark_node)
   10654              :         return -1;
   10655          111 :       else if (btype == NULL_TREE)
   10656              :         return 0;
   10657         1034 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10658         1573 :         if (TREE_CODE (field) != FIELD_DECL
   10659          329 :             || DECL_ARTIFICIAL (field)
   10660         1274 :             || DECL_UNNAMED_BIT_FIELD (field))
   10661          628 :           continue;
   10662              :         else
   10663          317 :           eltscnt++;
   10664           89 :       return eltscnt;
   10665              :     }
   10666              : }
   10667              : 
   10668              : /* Finish a decomposition declaration.  DECL is the underlying declaration
   10669              :    "e", FIRST is the head of a chain of decls for the individual identifiers
   10670              :    chained through DECL_CHAIN in reverse order and COUNT is the number of
   10671              :    those decls.  If TEST_P is true, return true if any code would need to be
   10672              :    actually emitted but don't emit it.  Return false otherwise.  */
   10673              : 
   10674              : bool
   10675       393558 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
   10676              : {
   10677       393558 :   tree first = decomp->decl;
   10678       393558 :   unsigned count = decomp->count;
   10679       393558 :   if (error_operand_p (decl))
   10680              :     {
   10681           57 :      error_out:
   10682          598 :       while (count--)
   10683              :         {
   10684          408 :           TREE_TYPE (first) = error_mark_node;
   10685          408 :           if (DECL_HAS_VALUE_EXPR_P (first))
   10686              :             {
   10687            9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
   10688            9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
   10689              :             }
   10690          408 :           first = DECL_CHAIN (first);
   10691              :         }
   10692          190 :       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
   10693           51 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
   10694          190 :       return false;
   10695              :     }
   10696              : 
   10697       393501 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   10698       393501 :   if (type_dependent_expression_p (decl)
   10699              :       /* This happens for range for when not in templates.
   10700              :          Still add the DECL_VALUE_EXPRs for later processing.  */
   10701       393501 :       || (!processing_template_decl
   10702       174656 :           && type_uses_auto (TREE_TYPE (decl))))
   10703              :     {
   10704       573903 :       for (unsigned int i = 0; i < count; i++)
   10705              :         {
   10706       382632 :           if (!DECL_HAS_VALUE_EXPR_P (first))
   10707              :             {
   10708       382632 :               tree v = build_nt (ARRAY_REF, decl,
   10709       382632 :                                  size_int (count - i - 1),
   10710              :                                  NULL_TREE, NULL_TREE);
   10711       382632 :               SET_DECL_VALUE_EXPR (first, v);
   10712       382632 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
   10713              :             }
   10714       382632 :           if (processing_template_decl)
   10715       382008 :             fit_decomposition_lang_decl (first, decl);
   10716       382632 :           first = DECL_CHAIN (first);
   10717              :         }
   10718              :       return false;
   10719              :     }
   10720              : 
   10721       202230 :   auto_vec<tree, 16> v;
   10722       202230 :   v.safe_grow (count, true);
   10723       202230 :   tree d = first;
   10724       202230 :   int pack = -1;
   10725       608512 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
   10726              :     {
   10727       406282 :       v[count - i - 1] = d;
   10728       406282 :       fit_decomposition_lang_decl (d, decl);
   10729       406282 :       if (DECL_PACK_P (d))
   10730         1018 :         pack = count - i - 1;
   10731              :     }
   10732              : 
   10733       202230 :   tree type = TREE_TYPE (decl);
   10734       202230 :   tree dexp = decl;
   10735              : 
   10736       202230 :   if (TYPE_REF_P (type))
   10737              :     {
   10738         1822 :       dexp = convert_from_reference (dexp);
   10739         1822 :       type = complete_type (TREE_TYPE (type));
   10740         1822 :       if (type == error_mark_node)
   10741          133 :         goto error_out;
   10742         1822 :       if (!COMPLETE_TYPE_P (type))
   10743              :         {
   10744            3 :           error_at (loc, "structured binding refers to incomplete type %qT",
   10745              :                     type);
   10746            3 :           goto error_out;
   10747              :         }
   10748              :     }
   10749              : 
   10750       202227 :   tree eltype = NULL_TREE;
   10751       202227 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10752              :   /* Structured binding packs when initializer is non-dependent should
   10753              :      have their DECL_VALUE_EXPR set to a TREE_VEC.  First two elements
   10754              :      of that TREE_VEC are the base and index, what is normally represented
   10755              :      as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
   10756              :      of the pack first element.  The remaining elements of the TREE_VEC
   10757              :      are VAR_DECLs for the pack elements.  */
   10758       202227 :   tree packv = NULL_TREE;
   10759              : 
   10760       202227 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10761              :     {
   10762          952 :       tree nelts;
   10763          952 :       nelts = array_type_nelts_top (type);
   10764          952 :       if (nelts == error_mark_node)
   10765            0 :         goto error_out;
   10766          952 :       if (DECL_DECOMP_BASE (decl))
   10767              :         {
   10768            9 :           error_at (loc, "array initializer for structured binding "
   10769              :                     "declaration in condition");
   10770            9 :           goto error_out;
   10771              :         }
   10772          943 :       if (!tree_fits_uhwi_p (nelts))
   10773              :         {
   10774            3 :           error_at (loc, "cannot decompose variable length array %qT", type);
   10775            3 :           goto error_out;
   10776              :         }
   10777          940 :       eltscnt = tree_to_uhwi (nelts);
   10778          940 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10779              :         {
   10780           11 :        cnt_mismatch:
   10781           38 :           auto_diagnostic_group d;
   10782           38 :           if (count > eltscnt)
   10783           27 :             error_n (loc, count,
   10784              :                      "%u name provided for structured binding",
   10785              :                      "%u names provided for structured binding", count);
   10786              :           else
   10787           11 :             error_n (loc, count,
   10788              :                      "only %u name provided for structured binding",
   10789              :                      "only %u names provided for structured binding", count);
   10790           38 :           inform_n (loc, eltscnt,
   10791              :                     "while %qT decomposes into %wu element",
   10792              :                     "while %qT decomposes into %wu elements",
   10793              :                     type, eltscnt);
   10794           38 :           goto error_out;
   10795              :         }
   10796          929 :       eltype = TREE_TYPE (type);
   10797         3196 :       for (unsigned int i = 0; i < count; i++)
   10798              :         {
   10799         2267 :           if ((unsigned) pack == i)
   10800              :             {
   10801          165 :               packv = make_tree_vec (eltscnt - count + 3);
   10802          447 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10803              :                 {
   10804          282 :                   tree t;
   10805          282 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10806          282 :                   set_sb_pack_name (t, j);
   10807          282 :                   maybe_push_decl (t);
   10808          282 :                   TREE_TYPE (t) = eltype;
   10809          282 :                   layout_decl (t, 0);
   10810          282 :                   if (!processing_template_decl)
   10811              :                     {
   10812          195 :                       tree a = unshare_expr (dexp);
   10813          195 :                       a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
   10814              :                                   NULL_TREE, NULL_TREE);
   10815          195 :                       SET_DECL_VALUE_EXPR (t, a);
   10816          195 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10817              :                     }
   10818              :                 }
   10819         2267 :               continue;
   10820          165 :             }
   10821         2102 :           TREE_TYPE (v[i]) = eltype;
   10822         2102 :           layout_decl (v[i], 0);
   10823         2102 :           if (processing_template_decl)
   10824          136 :             continue;
   10825         1966 :           tree t = unshare_expr (dexp);
   10826         1966 :           unsigned HOST_WIDE_INT j = i;
   10827         1966 :           if (pack != -1 && (unsigned) pack < i)
   10828           64 :             j = i + eltscnt - count;
   10829         1966 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   10830         1966 :           SET_DECL_VALUE_EXPR (v[i], t);
   10831         1966 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10832              :         }
   10833              :     }
   10834              :   /* 2 GNU extensions.  */
   10835       201275 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10836              :     {
   10837           78 :       eltscnt = 2;
   10838           78 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10839            3 :         goto cnt_mismatch;
   10840           75 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10841          213 :       for (unsigned int i = 0; i < count; i++)
   10842              :         {
   10843          138 :           if ((unsigned) pack == i)
   10844              :             {
   10845           60 :               packv = make_tree_vec (eltscnt - count + 3);
   10846          132 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10847              :                 {
   10848           72 :                   tree t;
   10849           72 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10850           72 :                   set_sb_pack_name (t, j);
   10851           72 :                   maybe_push_decl (t);
   10852           72 :                   TREE_TYPE (t) = eltype;
   10853           72 :                   layout_decl (t, 0);
   10854           72 :                   if (!processing_template_decl)
   10855              :                     {
   10856           72 :                       tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
   10857              :                                        unshare_expr (dexp));
   10858           48 :                       SET_DECL_VALUE_EXPR (t, a);
   10859           48 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10860              :                     }
   10861              :                 }
   10862           60 :               continue;
   10863           60 :             }
   10864           78 :           TREE_TYPE (v[i]) = eltype;
   10865           78 :           layout_decl (v[i], 0);
   10866           78 :           if (processing_template_decl)
   10867           16 :             continue;
   10868           62 :           tree t = unshare_expr (dexp);
   10869           62 :           unsigned HOST_WIDE_INT j = i;
   10870           62 :           if (pack != -1 && (unsigned) pack < i)
   10871           16 :             j = i + eltscnt - count;
   10872           93 :           t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
   10873           62 :           SET_DECL_VALUE_EXPR (v[i], t);
   10874           62 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10875              :         }
   10876              :     }
   10877       201197 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10878              :     {
   10879           60 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10880              :         {
   10881              :           error_at (loc, "cannot decompose variable length vector %qT", type);
   10882              :           goto error_out;
   10883              :         }
   10884           60 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10885            3 :         goto cnt_mismatch;
   10886           57 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10887          249 :       for (unsigned int i = 0; i < count; i++)
   10888              :         {
   10889          192 :           if ((unsigned) pack == i)
   10890              :             {
   10891           48 :               packv = make_tree_vec (eltscnt - count + 3);
   10892          708 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10893              :                 {
   10894          660 :                   tree t;
   10895          660 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10896          660 :                   set_sb_pack_name (t, j);
   10897          660 :                   maybe_push_decl (t);
   10898          660 :                   TREE_TYPE (t) = eltype;
   10899          660 :                   layout_decl (t, 0);
   10900          660 :                   if (!processing_template_decl)
   10901              :                     {
   10902          440 :                       tree a = unshare_expr (dexp);
   10903          440 :                       location_t loc = DECL_SOURCE_LOCATION (t);
   10904          440 :                       tree s = size_int (j + pack);
   10905          440 :                       convert_vector_to_array_for_subscript (loc, &a, s);
   10906          440 :                       a = build4 (ARRAY_REF, eltype, a, s,
   10907              :                                   NULL_TREE, NULL_TREE);
   10908          440 :                       SET_DECL_VALUE_EXPR (t, a);
   10909          440 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10910              :                     }
   10911              :                 }
   10912           84 :               continue;
   10913           48 :             }
   10914          144 :           TREE_TYPE (v[i]) = eltype;
   10915          144 :           layout_decl (v[i], 0);
   10916          144 :           if (processing_template_decl)
   10917           36 :             continue;
   10918          108 :           tree t = unshare_expr (dexp);
   10919          108 :           unsigned HOST_WIDE_INT j = i;
   10920          108 :           if (pack != -1 && (unsigned) pack < i)
   10921           24 :             j = i + eltscnt - count;
   10922          108 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
   10923          108 :                                                  &t, size_int (j));
   10924          108 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   10925          108 :           SET_DECL_VALUE_EXPR (v[i], t);
   10926          108 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10927              :         }
   10928              :     }
   10929       201137 :   else if (tree tsize = get_tuple_size (type))
   10930              :     {
   10931       140156 :       if (tsize == error_mark_node)
   10932              :         {
   10933            0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10934              :                          "constant expression", type);
   10935            0 :           goto error_out;
   10936              :         }
   10937       140156 :       if (!tree_fits_uhwi_p (tsize))
   10938              :         {
   10939           12 :           auto_diagnostic_group d;
   10940           12 :           error_n (loc, count,
   10941              :                    "%u name provided for structured binding",
   10942              :                    "%u names provided for structured binding", count);
   10943           12 :           inform (loc, "while %qT decomposes into %E elements",
   10944              :                   type, tsize);
   10945           12 :           goto error_out;
   10946           12 :         }
   10947       140144 :       eltscnt = tree_to_uhwi (tsize);
   10948       140144 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10949            6 :         goto cnt_mismatch;
   10950       140138 :       if (test_p && eltscnt)
   10951       202097 :         return true;
   10952        74746 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
   10953              :         {
   10954              :           /* For structured bindings used in conditions we need to evaluate
   10955              :              the conversion of decl (aka e in the standard) to bool or
   10956              :              integral/enumeral type (the latter for switch conditions)
   10957              :              before the get methods.  */
   10958           86 :           tree cond = convert_from_reference (decl);
   10959           86 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   10960              :             /* switch condition.  */
   10961           18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   10962              :                                                cond, true);
   10963              :           else
   10964              :             /* if/while/for condition.  */
   10965           68 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   10966           86 :           if (cond && !error_operand_p (cond))
   10967              :             {
   10968              :               /* Wrap that value into a TARGET_EXPR, emit it right
   10969              :                  away and save for later uses in the cp_parse_condition
   10970              :                  or its instantiation.  */
   10971           86 :               cond = get_internal_target_expr (cond);
   10972           86 :               add_stmt (cond);
   10973           86 :               DECL_DECOMP_BASE (decl) = cond;
   10974              :             }
   10975              :         }
   10976        74746 :       int save_read = DECL_READ_P (decl);
   10977       224638 :       for (unsigned i = 0; i < count; ++i)
   10978              :         {
   10979       149913 :           location_t sloc = input_location;
   10980       149913 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   10981              : 
   10982       149913 :           if ((unsigned) pack == i)
   10983              :             {
   10984          276 :               packv = make_tree_vec (eltscnt - count + 3);
   10985          832 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10986              :                 {
   10987          556 :                   tree t;
   10988          556 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10989          556 :                   set_sb_pack_name (t, j);
   10990          556 :                   input_location = dloc;
   10991          556 :                   tree init = get_tuple_decomp_init (decl, j + pack);
   10992          556 :                   tree eltype = (init == error_mark_node ? error_mark_node
   10993          556 :                                  : get_tuple_element_type (type, j + pack));
   10994          556 :                   input_location = sloc;
   10995              : 
   10996          556 :                   if (VOID_TYPE_P (eltype))
   10997              :                     {
   10998            0 :                       error ("%<std::tuple_element<%wu, %T>::type%> is "
   10999              :                              "%<void%>", j + pack, type);
   11000            0 :                       eltype = error_mark_node;
   11001              :                     }
   11002          556 :                   if (init == error_mark_node || eltype == error_mark_node)
   11003              :                     {
   11004            0 :                       inform (dloc, "in initialization of structured binding "
   11005            0 :                               "pack %qD", v[pack]);
   11006            0 :                       goto error_out;
   11007              :                     }
   11008          556 :                   maybe_push_decl (t);
   11009              :                   /* Save the decltype away before reference collapse.  */
   11010          556 :                   hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
   11011          556 :                   eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11012          556 :                   TREE_TYPE (t) = eltype;
   11013          556 :                   layout_decl (t, 0);
   11014          556 :                   DECL_HAS_VALUE_EXPR_P (t) = 0;
   11015          556 :                   if (!processing_template_decl)
   11016              :                     {
   11017          456 :                       copy_linkage (t, decl);
   11018          456 :                       tree name = DECL_NAME (t);
   11019          456 :                       if (TREE_STATIC (decl))
   11020           36 :                         DECL_NAME (t) = DECL_NAME (v[pack]);
   11021          456 :                       cp_finish_decl (t, init, /*constexpr*/false,
   11022              :                                       /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11023          456 :                       if (TREE_STATIC (decl))
   11024              :                         {
   11025           36 :                           DECL_ASSEMBLER_NAME (t);
   11026           36 :                           DECL_NAME (t) = name;
   11027              :                         }
   11028              :                     }
   11029              :                 }
   11030          276 :               continue;
   11031          276 :             }
   11032              : 
   11033       149637 :           unsigned HOST_WIDE_INT j = i;
   11034       149637 :           if (pack != -1 && (unsigned) pack < i)
   11035          238 :             j = i + eltscnt - count;
   11036       149637 :           input_location = dloc;
   11037       149637 :           tree init = get_tuple_decomp_init (decl, j);
   11038       149637 :           tree eltype = (init == error_mark_node ? error_mark_node
   11039       149628 :                          : get_tuple_element_type (type, j));
   11040       149637 :           input_location = sloc;
   11041              : 
   11042       149637 :           if (VOID_TYPE_P (eltype))
   11043              :             {
   11044            3 :               error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
   11045              :                      j, type);
   11046            3 :               eltype = error_mark_node;
   11047              :             }
   11048       149637 :           if (init == error_mark_node || eltype == error_mark_node)
   11049              :             {
   11050           21 :               inform (dloc, "in initialization of structured binding "
   11051           21 :                       "variable %qD", v[i]);
   11052           21 :               goto error_out;
   11053              :             }
   11054              :           /* Save the decltype away before reference collapse.  */
   11055       149616 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   11056       149616 :           eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11057       149616 :           TREE_TYPE (v[i]) = eltype;
   11058       149616 :           layout_decl (v[i], 0);
   11059       149616 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   11060              :             {
   11061              :               /* In this case the names are variables, not just proxies.  */
   11062          220 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   11063          220 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   11064              :             }
   11065       149616 :           if (!processing_template_decl)
   11066              :             {
   11067       130884 :               copy_linkage (v[i], decl);
   11068       130884 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   11069              :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11070              :             }
   11071              :         }
   11072              :       /* Ignore reads from the underlying decl performed during initialization
   11073              :          of the individual variables.  If those will be read, we'll mark
   11074              :          the underlying decl as read at that point.  */
   11075        74725 :       DECL_READ_P (decl) = save_read;
   11076              :     }
   11077        60981 :   else if (TREE_CODE (type) == UNION_TYPE)
   11078              :     {
   11079            3 :       error_at (loc, "cannot decompose union type %qT", type);
   11080            3 :       goto error_out;
   11081              :     }
   11082        60978 :   else if (!CLASS_TYPE_P (type))
   11083              :     {
   11084           16 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   11085           16 :       goto error_out;
   11086              :     }
   11087        60962 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   11088            0 :     goto error_out;
   11089        60962 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   11090            2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   11091              :              type);
   11092              :   else
   11093              :     {
   11094        60960 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE,
   11095              :                                            tf_warning_or_error);
   11096        60960 :       if (btype == error_mark_node)
   11097           21 :         goto error_out;
   11098        60939 :       else if (btype == NULL_TREE)
   11099              :         {
   11100           23 :           if (pack == 0 && count == 1)
   11101              :             {
   11102           16 :               eltscnt = 0;
   11103           16 :               packv = make_tree_vec (2);
   11104           16 :               goto done;
   11105              :             }
   11106            7 :           error_at (loc, "cannot decompose class type %qT without non-static "
   11107              :                          "data members", type);
   11108            7 :           goto error_out;
   11109              :         }
   11110       706195 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11111      1167943 :         if (TREE_CODE (field) != FIELD_DECL
   11112       122631 :             || DECL_ARTIFICIAL (field)
   11113       767906 :             || DECL_UNNAMED_BIT_FIELD (field))
   11114       522664 :           continue;
   11115              :         else
   11116       122615 :           eltscnt++;
   11117        60916 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11118           15 :         goto cnt_mismatch;
   11119        60901 :       tree t = dexp;
   11120        60901 :       if (type != btype)
   11121              :         {
   11122           18 :           t = convert_to_base (t, btype, /*check_access*/true,
   11123              :                                /*nonnull*/false, tf_warning_or_error);
   11124           18 :           type = btype;
   11125              :         }
   11126        60901 :       unsigned HOST_WIDE_INT j = 0;
   11127        60901 :       unsigned int i = 0;
   11128       705984 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11129      1167588 :         if (TREE_CODE (field) != FIELD_DECL
   11130       122594 :             || DECL_ARTIFICIAL (field)
   11131       767673 :             || DECL_UNNAMED_BIT_FIELD (field))
   11132       522505 :           continue;
   11133              :         else
   11134              :           {
   11135       122578 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   11136              :                                                      NULL_TREE);
   11137       122578 :             if (REFERENCE_REF_P (tt))
   11138           30 :               tt = TREE_OPERAND (tt, 0);
   11139       122578 :             if (pack != -1 && j >= (unsigned) pack)
   11140              :               {
   11141          666 :                 if (j == (unsigned) pack)
   11142              :                   {
   11143          220 :                     packv = make_tree_vec (eltscnt - count + 3);
   11144          220 :                     i++;
   11145              :                   }
   11146          666 :                 if (j < (unsigned) pack + eltscnt - (count - 1))
   11147              :                   {
   11148          485 :                     tree t;
   11149          485 :                     TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
   11150          485 :                     set_sb_pack_name (t, j + 1 - i);
   11151          485 :                     maybe_push_decl (t);
   11152          485 :                     TREE_TYPE (t) = TREE_TYPE (tt);
   11153          485 :                     layout_decl (t, 0);
   11154          485 :                     if (!processing_template_decl)
   11155              :                       {
   11156          364 :                         SET_DECL_VALUE_EXPR (t, tt);
   11157          364 :                         DECL_HAS_VALUE_EXPR_P (t) = 1;
   11158              :                       }
   11159              :                     else
   11160          121 :                       DECL_HAS_VALUE_EXPR_P (t) = 0;
   11161          485 :                     j++;
   11162          485 :                     continue;
   11163          485 :                   }
   11164              :               }
   11165       122093 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   11166       122093 :             layout_decl (v[i], 0);
   11167       122093 :             if (!processing_template_decl)
   11168              :               {
   11169        85427 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   11170        85427 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11171              :               }
   11172       122093 :             i++;
   11173       122093 :             j++;
   11174              :           }
   11175        60901 :       if (pack != -1 && j == (unsigned) pack)
   11176              :         {
   11177           20 :           gcc_checking_assert (eltscnt == count - 1);
   11178           20 :           packv = make_tree_vec (2);
   11179              :         }
   11180              :     }
   11181       136705 :  done:
   11182       136705 :   if (packv)
   11183              :     {
   11184          805 :       gcc_checking_assert (pack != -1);
   11185          805 :       TREE_VEC_ELT (packv, 0) = decl;
   11186          805 :       TREE_VEC_ELT (packv, 1) = size_int (pack);
   11187          805 :       SET_DECL_VALUE_EXPR (v[pack], packv);
   11188          805 :       DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
   11189          805 :       DECL_IGNORED_P (v[pack]) = 1;
   11190          805 :       if (!processing_template_decl)
   11191         2065 :         for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
   11192         1503 :           pushdecl (TREE_VEC_ELT (packv, 2 + i));
   11193              :     }
   11194       136705 :   if (processing_template_decl)
   11195              :     {
   11196        83645 :       for (unsigned int i = 0; i < count; i++)
   11197        55831 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   11198              :           {
   11199        55441 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   11200              :                                NULL_TREE, NULL_TREE);
   11201        55441 :             SET_DECL_VALUE_EXPR (v[i], a);
   11202        55441 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11203              :           }
   11204              :     }
   11205       108891 :   else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
   11206              :     {
   11207          366 :       tree attr = NULL_TREE, *pa = &attr;
   11208         1277 :       for (unsigned int i = 0; i < count; i++)
   11209          911 :         if ((unsigned) pack != i
   11210          911 :             && DECL_HAS_VALUE_EXPR_P (v[i])
   11211         1482 :             && !DECL_IGNORED_P (v[i]))
   11212              :           {
   11213          571 :             (*debug_hooks->early_global_decl) (v[i]);
   11214          571 :             *pa = build_tree_list (NULL_TREE, v[i]);
   11215          571 :             pa = &TREE_CHAIN (*pa);
   11216              :           }
   11217          366 :       if (attr)
   11218          251 :         DECL_ATTRIBUTES (decl)
   11219          502 :           = tree_cons (get_identifier ("structured bindings"),
   11220          251 :                        attr, DECL_ATTRIBUTES (decl));
   11221              :     }
   11222              :   return false;
   11223              : }
   11224              : 
   11225              : /* Returns a declaration for a VAR_DECL as if:
   11226              : 
   11227              :      extern "C" TYPE NAME;
   11228              : 
   11229              :    had been seen.  Used to create compiler-generated global
   11230              :    variables.  */
   11231              : 
   11232              : static tree
   11233         2171 : declare_global_var (tree name, tree type)
   11234              : {
   11235         2171 :   auto cookie = push_abi_namespace (global_namespace);
   11236         2171 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   11237         2171 :   TREE_PUBLIC (decl) = 1;
   11238         2171 :   DECL_EXTERNAL (decl) = 1;
   11239         2171 :   DECL_ARTIFICIAL (decl) = 1;
   11240         2171 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   11241              :   /* If the user has explicitly declared this variable (perhaps
   11242              :      because the code we are compiling is part of a low-level runtime
   11243              :      library), then it is possible that our declaration will be merged
   11244              :      with theirs by pushdecl.  */
   11245         2171 :   decl = pushdecl (decl);
   11246         2171 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   11247         2171 :   pop_abi_namespace (cookie, global_namespace);
   11248              : 
   11249         2171 :   return decl;
   11250              : }
   11251              : 
   11252              : /* Returns the type for the argument to "atexit" corresponding to the function
   11253              :    to be called when the program exits.  */
   11254              : 
   11255              : static tree
   11256           24 : get_atexit_fn_ptr_type ()
   11257              : {
   11258           24 :   if (!atexit_fn_ptr_type_node)
   11259              :     {
   11260           12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   11261           12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   11262              :     }
   11263              : 
   11264           24 :   return atexit_fn_ptr_type_node;
   11265              : }
   11266              : 
   11267              : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   11268              :    or "__cxa_throw" corresponding to the destructor to be called when the
   11269              :    program exits.  */
   11270              : 
   11271              : tree
   11272        18165 : get_cxa_atexit_fn_ptr_type ()
   11273              : {
   11274        18165 :   if (!cleanup_type)
   11275              :     {
   11276        13675 :       tree fntype = build_function_type_list (void_type_node,
   11277              :                                               ptr_type_node, NULL_TREE);
   11278        13675 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   11279        13675 :       cleanup_type = build_pointer_type (fntype);
   11280              :     }
   11281              : 
   11282        18165 :   return cleanup_type;
   11283              : }
   11284              : 
   11285              : /* Returns a pointer to the `atexit' function.  Note that if
   11286              :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   11287              :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   11288              : 
   11289              : static tree
   11290         3311 : get_atexit_node (void)
   11291              : {
   11292         3311 :   tree atexit_fndecl;
   11293         3311 :   tree fn_type;
   11294         3311 :   tree fn_ptr_type;
   11295         3311 :   const char *name;
   11296         3311 :   bool use_aeabi_atexit;
   11297         3311 :   tree ctx = global_namespace;
   11298              : 
   11299         3311 :   if (atexit_node)
   11300              :     return atexit_node;
   11301              : 
   11302         2137 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   11303              :     {
   11304              :       /* The declaration for `__cxa_atexit' is:
   11305              : 
   11306              :            int __cxa_atexit (void (*)(void *), void *, void *)
   11307              : 
   11308              :          We build up the argument types and then the function type
   11309              :          itself.  */
   11310         2125 :       tree argtype0, argtype1, argtype2;
   11311              : 
   11312         2125 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   11313              :       /* First, build the pointer-to-function type for the first
   11314              :          argument.  */
   11315         2125 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   11316              :       /* Then, build the rest of the argument types.  */
   11317         2125 :       argtype2 = ptr_type_node;
   11318         2125 :       if (use_aeabi_atexit)
   11319              :         {
   11320              :           argtype1 = fn_ptr_type;
   11321              :           argtype0 = ptr_type_node;
   11322              :         }
   11323              :       else
   11324              :         {
   11325         2125 :           argtype1 = ptr_type_node;
   11326         2125 :           argtype0 = fn_ptr_type;
   11327              :         }
   11328              :       /* And the final __cxa_atexit type.  */
   11329         2125 :       fn_type = build_function_type_list (integer_type_node,
   11330              :                                           argtype0, argtype1, argtype2,
   11331              :                                           NULL_TREE);
   11332              :       /* ... which needs noexcept.  */
   11333         2125 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11334         2125 :       if (use_aeabi_atexit)
   11335              :         {
   11336            0 :           name = "__aeabi_atexit";
   11337            0 :           push_to_top_level ();
   11338            0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   11339            0 :           ctx = current_namespace;
   11340            0 :           while (n--)
   11341            0 :             pop_namespace ();
   11342            0 :           pop_from_top_level ();
   11343              :         }
   11344              :       else
   11345              :         {
   11346         2125 :           name = "__cxa_atexit";
   11347         2125 :           ctx = abi_node;
   11348              :         }
   11349              :     }
   11350              :   else
   11351              :     {
   11352              :       /* The declaration for `atexit' is:
   11353              : 
   11354              :            int atexit (void (*)());
   11355              : 
   11356              :          We build up the argument types and then the function type
   11357              :          itself.  */
   11358           12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   11359              :       /* Build the final atexit type.  */
   11360           12 :       fn_type = build_function_type_list (integer_type_node,
   11361              :                                           fn_ptr_type, NULL_TREE);
   11362              :       /* ... which needs noexcept.  */
   11363           12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11364           12 :       name = "atexit";
   11365              :     }
   11366              : 
   11367              :   /* Now, build the function declaration.  */
   11368         2137 :   push_lang_context (lang_name_c);
   11369         2137 :   auto cookie = push_abi_namespace (ctx);
   11370         2137 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   11371         2137 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11372              :   /* Install as hidden builtin so we're (a) more relaxed about
   11373              :     exception spec matching and (b) will not give a confusing location
   11374              :     in diagnostic and (c) won't magically appear in user-visible name
   11375              :     lookups.  */
   11376         2137 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11377         2137 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11378         2137 :   pop_abi_namespace (cookie, ctx);
   11379         2137 :   mark_used (atexit_fndecl);
   11380         2137 :   pop_lang_context ();
   11381         2137 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11382              : 
   11383         2137 :   return atexit_node;
   11384              : }
   11385              : 
   11386              : /* Like get_atexit_node, but for thread-local cleanups.  */
   11387              : 
   11388              : static tree
   11389           86 : get_thread_atexit_node (void)
   11390              : {
   11391           86 :   if (thread_atexit_node)
   11392              :     return thread_atexit_node;
   11393              : 
   11394              :   /* The declaration for `__cxa_thread_atexit' is:
   11395              : 
   11396              :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   11397           56 :   tree fn_type = build_function_type_list (integer_type_node,
   11398              :                                            get_cxa_atexit_fn_ptr_type (),
   11399              :                                            ptr_type_node, ptr_type_node,
   11400              :                                            NULL_TREE);
   11401              : 
   11402              :   /* Now, build the function declaration, as with __cxa_atexit.  */
   11403           56 :   unsigned flags = push_abi_namespace ();
   11404           56 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   11405              :                                              ECF_LEAF | ECF_NOTHROW);
   11406           56 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11407           56 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11408           56 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11409           56 :   pop_abi_namespace (flags);
   11410           56 :   mark_used (atexit_fndecl);
   11411           56 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11412              : 
   11413           56 :   return thread_atexit_node;
   11414              : }
   11415              : 
   11416              : /* Returns the __dso_handle VAR_DECL.  */
   11417              : 
   11418              : static tree
   11419         3385 : get_dso_handle_node (void)
   11420              : {
   11421         3385 :   if (dso_handle_node)
   11422              :     return dso_handle_node;
   11423              : 
   11424              :   /* Declare the variable.  */
   11425         2171 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   11426              :                                         ptr_type_node);
   11427              : 
   11428              : #ifdef HAVE_GAS_HIDDEN
   11429         2171 :   if (dso_handle_node != error_mark_node)
   11430              :     {
   11431         2168 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   11432         2168 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   11433              :     }
   11434              : #endif
   11435              : 
   11436         2171 :   return dso_handle_node;
   11437              : }
   11438              : 
   11439              : /* Begin a new function with internal linkage whose job will be simply
   11440              :    to destroy some particular DECL.  OB_PARM is true if object pointer
   11441              :    is passed to the cleanup function, otherwise no argument is passed.  */
   11442              : 
   11443              : static tree
   11444          366 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   11445              : {
   11446          366 :   push_to_top_level ();
   11447              : 
   11448              :   /* No need to mangle this.  */
   11449          366 :   push_lang_context (lang_name_c);
   11450              : 
   11451              :   /* Build the name of the function.  */
   11452          366 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   11453          366 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   11454          366 :   dname = targetm.strip_name_encoding (dname);
   11455          729 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   11456              : 
   11457          366 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   11458              :                                    : get_atexit_fn_ptr_type ());
   11459              :   /* Build the function declaration.  */
   11460          366 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   11461          366 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   11462              :   /* It's a function with internal linkage, generated by the
   11463              :      compiler.  */
   11464          366 :   TREE_PUBLIC (fndecl) = 0;
   11465          366 :   DECL_ARTIFICIAL (fndecl) = 1;
   11466              :   /* Make the function `inline' so that it is only emitted if it is
   11467              :      actually needed.  It is unlikely that it will be inlined, since
   11468              :      it is only called via a function pointer, but we avoid unnecessary
   11469              :      emissions this way.  */
   11470          366 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   11471          366 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   11472          366 :   if (ob_parm)
   11473              :     {
   11474              :       /* Build the parameter.  */
   11475          354 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   11476          354 :       TREE_USED (parmdecl) = 1;
   11477          354 :       DECL_READ_P (parmdecl) = 1;
   11478          354 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   11479              :     }
   11480              : 
   11481          366 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   11482          366 :   if (omp_target)
   11483              :     {
   11484            3 :       DECL_ATTRIBUTES (fndecl)
   11485            3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   11486            3 :                      DECL_ATTRIBUTES (fndecl));
   11487            3 :       DECL_ATTRIBUTES (fndecl)
   11488            6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   11489            3 :                      DECL_ATTRIBUTES (fndecl));
   11490              :     }
   11491          366 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   11492              : 
   11493          366 :   pop_lang_context ();
   11494              : 
   11495          366 :   return current_function_decl;
   11496              : }
   11497              : 
   11498              : /* Finish the cleanup function begun by start_cleanup_fn.  */
   11499              : 
   11500              : static void
   11501          366 : end_cleanup_fn (void)
   11502              : {
   11503          366 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   11504              : 
   11505          366 :   pop_from_top_level ();
   11506          366 : }
   11507              : 
   11508              : /* Generate code to handle the destruction of DECL, an object with
   11509              :    static storage duration.  */
   11510              : 
   11511              : tree
   11512        15014 : register_dtor_fn (tree decl, bool omp_target)
   11513              : {
   11514        15014 :   tree cleanup;
   11515        15014 :   tree addr;
   11516        15014 :   tree compound_stmt;
   11517        15014 :   tree fcall;
   11518        15014 :   tree type;
   11519        15014 :   bool ob_parm, dso_parm, use_dtor;
   11520        15014 :   tree arg0, arg1, arg2;
   11521        15014 :   tree atex_node;
   11522              : 
   11523        15014 :   type = TREE_TYPE (decl);
   11524        15014 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   11525        11617 :     return void_node;
   11526              : 
   11527         3397 :   if (decl_maybe_constant_destruction (decl, type)
   11528         3397 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   11529              :     {
   11530            0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11531            0 :       return void_node;
   11532              :     }
   11533              : 
   11534              :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   11535              :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   11536              :      destructor to "__cxa_atexit"; we don't have to build a temporary
   11537              :      function to do the cleanup.  */
   11538         6794 :   dso_parm = (flag_use_cxa_atexit
   11539         3397 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   11540         3397 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   11541         3385 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   11542         3397 :   if (use_dtor)
   11543              :     {
   11544         3031 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   11545              : 
   11546              :       /* Make sure it is accessible.  */
   11547         3031 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   11548              :                                      tf_warning_or_error);
   11549              :     }
   11550              :   else
   11551              :     {
   11552              :       /* Call build_cleanup before we enter the anonymous function so
   11553              :          that any access checks will be done relative to the current
   11554              :          scope, rather than the scope of the anonymous function.  */
   11555          366 :       build_cleanup (decl);
   11556              : 
   11557              :       /* Now start the function.  */
   11558          366 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   11559              : 
   11560              :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   11561              :          to the original function, rather than the anonymous one.  That
   11562              :          will make the back end think that nested functions are in use,
   11563              :          which causes confusion.  */
   11564          366 :       push_deferring_access_checks (dk_no_check);
   11565          366 :       fcall = build_cleanup (decl);
   11566          366 :       pop_deferring_access_checks ();
   11567              : 
   11568              :       /* Create the body of the anonymous function.  */
   11569          366 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   11570          366 :       finish_expr_stmt (fcall);
   11571          366 :       finish_compound_stmt (compound_stmt);
   11572          366 :       end_cleanup_fn ();
   11573              :     }
   11574              : 
   11575              :   /* Call atexit with the cleanup function.  */
   11576         3397 :   mark_used (cleanup);
   11577         3397 :   cleanup = build_address (cleanup);
   11578              : 
   11579         3397 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   11580           86 :     atex_node = get_thread_atexit_node ();
   11581              :   else
   11582         3311 :     atex_node = get_atexit_node ();
   11583              : 
   11584         3397 :   if (use_dtor)
   11585              :     {
   11586              :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   11587              :          expects.  */
   11588         3031 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   11589              :       /* "__cxa_atexit" will pass the address of DECL to the
   11590              :          cleanup function.  */
   11591         3031 :       mark_used (decl);
   11592         3031 :       addr = build_address (decl);
   11593              :       /* The declared type of the parameter to "__cxa_atexit" is
   11594              :          "void *".  For plain "T*", we could just let the
   11595              :          machinery in cp_build_function_call convert it -- but if the
   11596              :          type is "cv-qualified T *", then we need to convert it
   11597              :          before passing it in, to avoid spurious errors.  */
   11598         3031 :       addr = build_nop (ptr_type_node, addr);
   11599              :     }
   11600              :   else
   11601              :     /* Since the cleanup functions we build ignore the address
   11602              :        they're given, there's no reason to pass the actual address
   11603              :        in, and, in general, it's cheaper to pass NULL than any
   11604              :        other value.  */
   11605          366 :     addr = null_pointer_node;
   11606              : 
   11607         3397 :   if (dso_parm)
   11608         3385 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   11609              :                                tf_warning_or_error);
   11610           12 :   else if (ob_parm)
   11611              :     /* Just pass NULL to the dso handle parm if we don't actually
   11612              :        have a DSO handle on this target.  */
   11613            0 :     arg2 = null_pointer_node;
   11614              :   else
   11615              :     arg2 = NULL_TREE;
   11616              : 
   11617         3385 :   if (ob_parm)
   11618              :     {
   11619         3385 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   11620         3385 :           && targetm.cxx.use_aeabi_atexit ())
   11621              :         {
   11622              :           arg1 = cleanup;
   11623              :           arg0 = addr;
   11624              :         }
   11625              :       else
   11626              :         {
   11627              :           arg1 = addr;
   11628              :           arg0 = cleanup;
   11629              :         }
   11630              :     }
   11631              :   else
   11632              :     {
   11633              :       arg0 = cleanup;
   11634              :       arg1 = NULL_TREE;
   11635              :     }
   11636         3397 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   11637         3397 :                                       arg0, arg1, arg2, NULL_TREE);
   11638              : }
   11639              : 
   11640              : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   11641              :    is its initializer.  Generate code to handle the construction
   11642              :    and destruction of DECL.  */
   11643              : 
   11644              : static void
   11645     32639605 : expand_static_init (tree decl, tree init)
   11646              : {
   11647     32639605 :   gcc_assert (VAR_P (decl));
   11648     32639605 :   gcc_assert (TREE_STATIC (decl));
   11649              : 
   11650              :   /* Some variables require no dynamic initialization.  */
   11651     32639605 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   11652              :     {
   11653              :       /* Make sure the destructor is callable.  */
   11654     32636294 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11655     32636294 :       if (!init)
   11656              :         return;
   11657              :     }
   11658              : 
   11659        15824 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   11660        14901 :       && !DECL_FUNCTION_SCOPE_P (decl))
   11661              :     {
   11662           15 :       auto_diagnostic_group d;
   11663           15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   11664           15 :       if (init)
   11665           12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11666              :                   "needs dynamic initialization", decl);
   11667              :       else
   11668            3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11669              :                   "has a non-trivial destructor", decl);
   11670           15 :       static bool informed;
   11671           15 :       if (!informed)
   11672              :         {
   11673            6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   11674              :                   "initialization and destruction");
   11675            6 :           informed = true;
   11676              :         }
   11677           15 :       return;
   11678           15 :     }
   11679              : 
   11680        14857 :   if (DECL_FUNCTION_SCOPE_P (decl))
   11681              :     {
   11682              :       /* Emit code to perform this initialization but once.  */
   11683         3859 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   11684         3859 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   11685         3859 :       tree guard, guard_addr;
   11686         3859 :       tree flag, begin;
   11687              :       /* We don't need thread-safety code for thread-local vars.  */
   11688         3859 :       bool thread_guard = (flag_threadsafe_statics
   11689         3859 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   11690              : 
   11691              :       /* Emit code to perform this initialization but once.  This code
   11692              :          looks like:
   11693              : 
   11694              :            static <type> guard;
   11695              :            if (!__atomic_load (guard.first_byte)) {
   11696              :              if (__cxa_guard_acquire (&guard)) {
   11697              :                bool flag = false;
   11698              :                try {
   11699              :                  // Do initialization.
   11700              :                  flag = true; __cxa_guard_release (&guard);
   11701              :                  // Register variable for destruction at end of program.
   11702              :                } catch {
   11703              :                  if (!flag) __cxa_guard_abort (&guard);
   11704              :                }
   11705              :              }
   11706              :            }
   11707              : 
   11708              :          Note that the `flag' variable is only set to 1 *after* the
   11709              :          initialization is complete.  This ensures that an exception,
   11710              :          thrown during the construction, will cause the variable to
   11711              :          reinitialized when we pass through this code again, as per:
   11712              : 
   11713              :            [stmt.dcl]
   11714              : 
   11715              :            If the initialization exits by throwing an exception, the
   11716              :            initialization is not complete, so it will be tried again
   11717              :            the next time control enters the declaration.
   11718              : 
   11719              :          This process should be thread-safe, too; multiple threads
   11720              :          should not be able to initialize the variable more than
   11721              :          once.  */
   11722              : 
   11723              :       /* Create the guard variable.  */
   11724         3859 :       guard = get_guard (decl);
   11725              : 
   11726              :       /* Begin the conditional initialization.  */
   11727         3859 :       if_stmt = begin_if_stmt ();
   11728              : 
   11729         3859 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   11730         3859 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11731              : 
   11732         3859 :       if (thread_guard)
   11733              :         {
   11734         3714 :           tree vfntype = NULL_TREE;
   11735         3714 :           tree acquire_name, release_name, abort_name;
   11736         3714 :           tree acquire_fn, release_fn, abort_fn;
   11737         3714 :           guard_addr = build_address (guard);
   11738              : 
   11739         3714 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   11740         3714 :           release_name = get_identifier ("__cxa_guard_release");
   11741         3714 :           abort_name = get_identifier ("__cxa_guard_abort");
   11742         3714 :           acquire_fn = get_global_binding (acquire_name);
   11743         3714 :           release_fn = get_global_binding (release_name);
   11744         3714 :           abort_fn = get_global_binding (abort_name);
   11745         3714 :           if (!acquire_fn)
   11746         2111 :             acquire_fn = push_library_fn
   11747         2111 :               (acquire_name, build_function_type_list (integer_type_node,
   11748         2111 :                                                        TREE_TYPE (guard_addr),
   11749              :                                                        NULL_TREE),
   11750              :                NULL_TREE, ECF_NOTHROW);
   11751         3714 :           if (!release_fn || !abort_fn)
   11752         2114 :             vfntype = build_function_type_list (void_type_node,
   11753         2114 :                                                 TREE_TYPE (guard_addr),
   11754              :                                                 NULL_TREE);
   11755         2114 :           if (!release_fn)
   11756         2114 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   11757              :                                           ECF_NOTHROW);
   11758         3714 :           if (!abort_fn)
   11759         2114 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   11760              :                                         ECF_NOTHROW | ECF_LEAF);
   11761              : 
   11762         3714 :           inner_if_stmt = begin_if_stmt ();
   11763         3714 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   11764              :                                inner_if_stmt);
   11765              : 
   11766         3714 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11767         3714 :           begin = get_internal_target_expr (boolean_false_node);
   11768         3714 :           flag = TARGET_EXPR_SLOT (begin);
   11769              : 
   11770         3714 :           TARGET_EXPR_CLEANUP (begin)
   11771         3714 :             = build3 (COND_EXPR, void_type_node, flag,
   11772              :                       void_node,
   11773              :                       build_call_n (abort_fn, 1, guard_addr));
   11774         3714 :           CLEANUP_EH_ONLY (begin) = 1;
   11775              : 
   11776              :           /* Do the initialization itself.  */
   11777         3714 :           init = add_stmt_to_compound (begin, init);
   11778         3714 :           init = add_stmt_to_compound (init,
   11779              :                                        build2 (MODIFY_EXPR, void_type_node,
   11780              :                                                flag, boolean_true_node));
   11781              : 
   11782              :           /* Use atexit to register a function for destroying this static
   11783              :              variable.  Do this before calling __cxa_guard_release.  */
   11784         3714 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   11785              : 
   11786         3714 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   11787              :                                                            guard_addr));
   11788              :         }
   11789              :       else
   11790              :         {
   11791          145 :           init = add_stmt_to_compound (init, set_guard (guard));
   11792              : 
   11793              :           /* Use atexit to register a function for destroying this static
   11794              :              variable.  */
   11795          145 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   11796              :         }
   11797              : 
   11798         3859 :       finish_expr_stmt (init);
   11799              : 
   11800         3859 :       if (thread_guard)
   11801              :         {
   11802         3714 :           finish_compound_stmt (inner_then_clause);
   11803         3714 :           finish_then_clause (inner_if_stmt);
   11804         3714 :           finish_if_stmt (inner_if_stmt);
   11805              :         }
   11806              : 
   11807         3859 :       finish_compound_stmt (then_clause);
   11808         3859 :       finish_then_clause (if_stmt);
   11809         3859 :       finish_if_stmt (if_stmt);
   11810              :     }
   11811        10998 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   11812          795 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   11813              :   else
   11814        10203 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   11815              : }
   11816              : 
   11817              : 
   11818              : /* Make TYPE a complete type based on INITIAL_VALUE.
   11819              :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   11820              :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   11821              :    3 if the initializer list is empty (in pedantic mode). */
   11822              : 
   11823              : int
   11824       680332 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   11825              : {
   11826       680332 :   int failure;
   11827       680332 :   tree type, elt_type;
   11828              : 
   11829              :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   11830       680302 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   11831       141167 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   11832       680662 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   11833              :     return 1;
   11834              : 
   11835       680329 :   if (initial_value)
   11836              :     {
   11837              :       /* An array of character type can be initialized from a
   11838              :          brace-enclosed string constant so call reshape_init to
   11839              :          remove the optional braces from a braced string literal.  */
   11840       680299 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   11841       680299 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   11842        48220 :         initial_value = reshape_init (*ptype, initial_value,
   11843              :                                       tf_warning_or_error);
   11844              : 
   11845              :       /* If any of the elements are parameter packs, we can't actually
   11846              :          complete this type now because the array size is dependent.  */
   11847       680299 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   11848     46507056 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   11849     46083971 :           if (PACK_EXPANSION_P (e.value))
   11850              :             return 0;
   11851              :     }
   11852              : 
   11853       680329 :   failure = complete_array_type (ptype, initial_value, do_default);
   11854              : 
   11855              :   /* We can create the array before the element type is complete, which
   11856              :      means that we didn't have these two bits set in the original type
   11857              :      either.  In completing the type, we are expected to propagate these
   11858              :      bits.  See also complete_type which does the same thing for arrays
   11859              :      of fixed size.  */
   11860       680329 :   type = *ptype;
   11861      1360655 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   11862              :     {
   11863       680302 :       elt_type = TREE_TYPE (type);
   11864       680302 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   11865      1360604 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   11866       680302 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   11867              :     }
   11868              : 
   11869              :   return failure;
   11870              : }
   11871              : 
   11872              : /* As above, but either give an error or reject zero-size arrays, depending
   11873              :    on COMPLAIN.  */
   11874              : 
   11875              : int
   11876         1192 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   11877              :                                  bool do_default, tsubst_flags_t complain)
   11878              : {
   11879         1192 :   int failure;
   11880         1192 :   bool sfinae = !(complain & tf_error);
   11881              :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   11882         1192 :   if (sfinae)
   11883            3 :     ++pedantic;
   11884         1192 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   11885         1192 :   if (sfinae)
   11886            3 :     --pedantic;
   11887         1192 :   if (failure)
   11888              :     {
   11889            3 :       if (sfinae)
   11890              :         /* Not an error.  */;
   11891            0 :       else if (failure == 1)
   11892            0 :         error ("initializer fails to determine size of %qT", *ptype);
   11893            0 :       else if (failure == 2)
   11894              :         {
   11895            0 :           if (do_default)
   11896            0 :             error ("array size missing in %qT", *ptype);
   11897              :         }
   11898            0 :       else if (failure == 3)
   11899            0 :         error ("zero-size array %qT", *ptype);
   11900            3 :       *ptype = error_mark_node;
   11901              :     }
   11902         1192 :   return failure;
   11903              : }
   11904              : 
   11905              : /* Return zero if something is declared to be a member of type
   11906              :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   11907              :    message to print in that case.  Otherwise, quietly return 1.  */
   11908              : 
   11909              : static int
   11910     25824856 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   11911              : {
   11912     25824856 :   if (ctype && ctype != cur_type)
   11913              :     {
   11914            0 :       if (flags == DTOR_FLAG)
   11915            0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   11916              :       else
   11917            0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   11918            0 :       return 0;
   11919              :     }
   11920              :   return 1;
   11921              : }
   11922              : 
   11923              : /* Subroutine of `grokdeclarator'.  */
   11924              : 
   11925              : /* Generate errors possibly applicable for a given set of specifiers.
   11926              :    This is for ARM $7.1.2.  */
   11927              : 
   11928              : static void
   11929    431632195 : bad_specifiers (tree object,
   11930              :                 enum bad_spec_place type,
   11931              :                 int virtualp,
   11932              :                 int quals,
   11933              :                 int inlinep,
   11934              :                 int friendp,
   11935              :                 int raises,
   11936              :                 const location_t* locations)
   11937              : {
   11938    431632195 :   switch (type)
   11939              :     {
   11940     66650567 :       case BSP_VAR:
   11941     66650567 :         if (virtualp)
   11942            0 :           error_at (locations[ds_virtual],
   11943              :                     "%qD declared as a %<virtual%> variable", object);
   11944     66650567 :         if (quals)
   11945            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   11946              :                  "%qD invalid in variable declaration", object);
   11947              :         break;
   11948    286883265 :       case BSP_PARM:
   11949    286883265 :         if (virtualp)
   11950            0 :           error_at (locations[ds_virtual],
   11951              :                     "%qD declared as a %<virtual%> parameter", object);
   11952    286883265 :         if (inlinep)
   11953            6 :           error_at (locations[ds_inline],
   11954              :                     "%qD declared as an %<inline%> parameter", object);
   11955    286883265 :         if (quals)
   11956            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   11957              :                  "%qD invalid in parameter declaration", object);
   11958              :         break;
   11959     46055868 :       case BSP_TYPE:
   11960     46055868 :         if (virtualp)
   11961            0 :           error_at (locations[ds_virtual],
   11962              :                     "%qD declared as a %<virtual%> type", object);
   11963     46055868 :         if (inlinep)
   11964            6 :           error_at (locations[ds_inline],
   11965              :                     "%qD declared as an %<inline%> type", object);
   11966     46055868 :         if (quals)
   11967            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   11968              :                  "%qD invalid in type declaration", object);
   11969              :         break;
   11970     32042495 :       case BSP_FIELD:
   11971     32042495 :         if (virtualp)
   11972            6 :           error_at (locations[ds_virtual],
   11973              :                     "%qD declared as a %<virtual%> field", object);
   11974     32042495 :         if (inlinep)
   11975            6 :           error_at (locations[ds_inline],
   11976              :                     "%qD declared as an %<inline%> field", object);
   11977     32042495 :         if (quals)
   11978            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   11979              :                  "%qD invalid in field declaration", object);
   11980              :         break;
   11981            0 :       default:
   11982            0 :         gcc_unreachable();
   11983              :     }
   11984    431632195 :   if (friendp)
   11985            0 :     error ("%q+D declared as a friend", object);
   11986    431632195 :   if (raises
   11987          113 :       && !flag_noexcept_type
   11988    431632216 :       && (TREE_CODE (object) == TYPE_DECL
   11989           15 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   11990            5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   11991            4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   11992            6 :     error ("%q+D declared with an exception specification", object);
   11993    431632195 : }
   11994              : 
   11995              : /* DECL is a member function or static data member and is presently
   11996              :    being defined.  Check that the definition is taking place in a
   11997              :    valid namespace.  */
   11998              : 
   11999              : static void
   12000     95231225 : check_class_member_definition_namespace (tree decl)
   12001              : {
   12002              :   /* These checks only apply to member functions and static data
   12003              :      members.  */
   12004     95231225 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   12005              :   /* We check for problems with specializations in pt.cc in
   12006              :      check_specialization_namespace, where we can issue better
   12007              :      diagnostics.  */
   12008     95231225 :   if (processing_specialization)
   12009              :     return;
   12010              :   /* We check this in check_explicit_instantiation_namespace.  */
   12011     95092790 :   if (processing_explicit_instantiation)
   12012              :     return;
   12013              :   /* [class.mfct]
   12014              : 
   12015              :      A member function definition that appears outside of the
   12016              :      class definition shall appear in a namespace scope enclosing
   12017              :      the class definition.
   12018              : 
   12019              :      [class.static.data]
   12020              : 
   12021              :      The definition for a static data member shall appear in a
   12022              :      namespace scope enclosing the member's class definition.  */
   12023     95092700 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   12024           18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   12025           18 :                decl, DECL_CONTEXT (decl));
   12026              : }
   12027              : 
   12028              : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   12029              :    METHOD_TYPE for a non-static member function; QUALS are the
   12030              :    cv-qualifiers that apply to the function.  */
   12031              : 
   12032              : tree
   12033    236871158 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   12034              : {
   12035    236871158 :   tree this_type;
   12036    236871158 :   tree qual_type;
   12037    236871158 :   tree parm;
   12038    236871158 :   cp_cv_quals this_quals;
   12039              : 
   12040    236871158 :   if (CLASS_TYPE_P (type))
   12041              :     {
   12042    101813897 :       this_type
   12043    101813897 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   12044    101813897 :       this_type = build_pointer_type (this_type);
   12045              :     }
   12046              :   else
   12047    135057261 :     this_type = type_of_this_parm (type);
   12048              :   /* The `this' parameter is implicitly `const'; it cannot be
   12049              :      assigned to.  */
   12050    236871158 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   12051    236871158 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   12052    236871158 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   12053    236871158 :   cp_apply_type_quals_to_decl (this_quals, parm);
   12054    236871158 :   return parm;
   12055              : }
   12056              : 
   12057              : /* DECL is a static member function.  Complain if it was declared
   12058              :    with function-cv-quals.  */
   12059              : 
   12060              : static void
   12061     10170656 : check_static_quals (tree decl, cp_cv_quals quals)
   12062              : {
   12063            0 :   if (quals != TYPE_UNQUALIFIED)
   12064            6 :     error ("static member function %q#D declared with type qualifiers",
   12065              :            decl);
   12066            0 : }
   12067              : 
   12068              : /* Helper function.  Replace the temporary this parameter injected
   12069              :    during cp_finish_omp_declare_simd with the real this parameter.  */
   12070              : 
   12071              : static tree
   12072         2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   12073              : {
   12074         2692 :   tree this_parm = (tree) data;
   12075         2692 :   if (TREE_CODE (*tp) == PARM_DECL
   12076          450 :       && DECL_NAME (*tp) == this_identifier
   12077         2965 :       && *tp != this_parm)
   12078          273 :     *tp = this_parm;
   12079         2419 :   else if (TYPE_P (*tp))
   12080           33 :     *walk_subtrees = 0;
   12081         2692 :   return NULL_TREE;
   12082              : }
   12083              : 
   12084              : /* CTYPE is class type, or null if non-class.
   12085              :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   12086              :    or METHOD_TYPE.
   12087              :    DECLARATOR is the function's name.
   12088              :    PARMS is a chain of PARM_DECLs for the function.
   12089              :    VIRTUALP is truthvalue of whether the function is virtual or not.
   12090              :    FLAGS are to be passed through to `grokclassfn'.
   12091              :    QUALS are qualifiers indicating whether the function is `const'
   12092              :    or `volatile'.
   12093              :    RAISES is a list of exceptions that this function can raise.
   12094              :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   12095              :    not look, and -1 if we should not call `grokclassfn' at all.
   12096              : 
   12097              :    SFK is the kind of special function (if any) for the new function.
   12098              : 
   12099              :    Returns `NULL_TREE' if something goes wrong, after issuing
   12100              :    applicable error messages.  */
   12101              : 
   12102              : static tree
   12103    183858265 : grokfndecl (tree ctype,
   12104              :             tree type,
   12105              :             tree declarator,
   12106              :             tree parms,
   12107              :             tree orig_declarator,
   12108              :             const cp_decl_specifier_seq *declspecs,
   12109              :             tree decl_reqs,
   12110              :             int virtualp,
   12111              :             enum overload_flags flags,
   12112              :             cp_cv_quals quals,
   12113              :             cp_ref_qualifier rqual,
   12114              :             tree raises,
   12115              :             int check,
   12116              :             int friendp,
   12117              :             int publicp,
   12118              :             int inlinep,
   12119              :             int initialized,
   12120              :             bool xobj_func_p,
   12121              :             special_function_kind sfk,
   12122              :             bool funcdef_flag,
   12123              :             bool late_return_type_p,
   12124              :             int template_count,
   12125              :             tree in_namespace,
   12126              :             tree* attrlist,
   12127              :             tree contract_specifiers,
   12128              :             location_t location)
   12129              : {
   12130    183858265 :   tree decl;
   12131    183858265 :   tree t;
   12132              : 
   12133    183858265 :   if (location == UNKNOWN_LOCATION)
   12134            0 :     location = input_location;
   12135              : 
   12136              :   /* Was the concept specifier present?  */
   12137    183858265 :   bool concept_p = inlinep & 4;
   12138              : 
   12139    183858265 :   if (concept_p)
   12140              :     {
   12141           15 :       error_at (location, "function concepts are no longer supported");
   12142           15 :       return NULL_TREE;
   12143              :     }
   12144              : 
   12145    183858250 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   12146              : 
   12147    183858250 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   12148              : 
   12149              :   /* Set the constraints on the declaration. */
   12150    183858250 :   if (flag_concepts)
   12151              :     {
   12152    179626718 :       tree tmpl_reqs = NULL_TREE;
   12153    179626718 :       tree ctx = friendp ? current_class_type : ctype;
   12154    179626718 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   12155    179626718 :       bool memtmpl = (!block_local
   12156    179626718 :                       && (current_template_depth
   12157    179571608 :                           > template_class_depth (ctx)));
   12158     49263405 :       if (memtmpl)
   12159              :         {
   12160     49263405 :           if (!current_template_parms)
   12161              :             /* If there are no template parameters, something must have
   12162              :                gone wrong.  */
   12163            0 :             gcc_assert (seen_error ());
   12164              :           else
   12165     49263405 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   12166              :         }
   12167    179626718 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   12168              :       /* C++20 CA378: Remove non-templated constrained functions.  */
   12169              :       /* [temp.friend]/9 A non-template friend declaration with a
   12170              :          requires-clause shall be a definition. A friend function template with
   12171              :          a constraint that depends on a template parameter from an enclosing
   12172              :          template shall be a definition. */
   12173    179626718 :       if (ci
   12174      9128288 :           && (block_local
   12175      9128285 :               || !processing_template_decl
   12176      9128225 :               || (friendp && !memtmpl && !funcdef_flag)))
   12177              :         {
   12178           72 :           if (!friendp || !processing_template_decl)
   12179           63 :             error_at (location, "constraints on a non-templated function");
   12180              :           else
   12181            9 :             error_at (location, "constrained non-template friend declaration"
   12182              :                       " must be a definition");
   12183              :           ci = NULL_TREE;
   12184              :         }
   12185    179626718 :       set_constraints (decl, ci);
   12186      1129640 :       if (ci && friendp && memtmpl && !funcdef_flag
   12187    179662700 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   12188            6 :         error_at (location, "friend function template with constraints that "
   12189              :                   "depend on outer template parameters must be a definition");
   12190              :     }
   12191              : 
   12192    183858250 :   if (TREE_CODE (type) == METHOD_TYPE)
   12193              :     {
   12194     99616477 :       tree parm = build_this_parm (decl, type, quals);
   12195     99616477 :       DECL_CHAIN (parm) = parms;
   12196     99616477 :       parms = parm;
   12197              : 
   12198              :       /* Allocate space to hold the vptr bit if needed.  */
   12199     99616477 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   12200              :     }
   12201              : 
   12202    183858250 :   DECL_ARGUMENTS (decl) = parms;
   12203    555220665 :   for (t = parms; t; t = DECL_CHAIN (t))
   12204    371362415 :     DECL_CONTEXT (t) = decl;
   12205              : 
   12206              :   /* Propagate volatile out from type to decl.  */
   12207    183858250 :   if (TYPE_VOLATILE (type))
   12208            0 :     TREE_THIS_VOLATILE (decl) = 1;
   12209              : 
   12210              :   /* Setup decl according to sfk.  */
   12211    183858250 :   switch (sfk)
   12212              :     {
   12213     23580099 :     case sfk_constructor:
   12214     23580099 :     case sfk_copy_constructor:
   12215     23580099 :     case sfk_move_constructor:
   12216     23580099 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   12217     23580099 :       DECL_NAME (decl) = ctor_identifier;
   12218     23580099 :       break;
   12219      3184968 :     case sfk_destructor:
   12220      3184968 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   12221      3184968 :       DECL_NAME (decl) = dtor_identifier;
   12222      3184968 :       break;
   12223      1166650 :     case sfk_deduction_guide:
   12224              :       /* Give deduction guides a definition even though they don't really
   12225              :          have one: the restriction that you can't repeat a deduction guide
   12226              :          makes them more like a definition anyway.  */
   12227      1166650 :       DECL_INITIAL (decl) = void_node;
   12228              :       /* But to ensure that external-linkage deduction guides in header units
   12229              :          don't fall afoul of [module.import] p6, mark them as inline.  */
   12230      1166650 :       DECL_DECLARED_INLINE_P (decl) = true;
   12231      1166650 :       break;
   12232              :     default:
   12233              :       break;
   12234              :     }
   12235              : 
   12236    183858250 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   12237              :     {
   12238        90005 :       if (funcdef_flag)
   12239            3 :         error_at (location,
   12240              :                   "defining explicit specialization %qD in friend declaration",
   12241              :                   orig_declarator);
   12242              :       else
   12243              :         {
   12244        90002 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   12245        90002 :           tree args = TREE_OPERAND (orig_declarator, 1);
   12246              : 
   12247        90002 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   12248              :             {
   12249              :               /* Something like `template <class T> friend void f<T>()'.  */
   12250            6 :               error_at (location,
   12251              :                         "invalid use of template-id %qD in declaration "
   12252              :                         "of primary template",
   12253              :                         orig_declarator);
   12254            6 :               return NULL_TREE;
   12255              :             }
   12256              : 
   12257              :           /* A friend declaration of the form friend void f<>().  Record
   12258              :              the information in the TEMPLATE_ID_EXPR.  */
   12259        89996 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   12260              : 
   12261        89996 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   12262        89996 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   12263              : 
   12264              :           /* Remember the befriending class like push_template_decl does for
   12265              :              template friends.  */
   12266        89996 :           gcc_checking_assert (!DECL_CHAIN (decl));
   12267        89996 :           DECL_CHAIN (decl) = current_scope ();
   12268              : 
   12269       291734 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   12270       201743 :             if (TREE_PURPOSE (t)
   12271       201743 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   12272              :             {
   12273            5 :               error_at (defparse_location (TREE_PURPOSE (t)),
   12274              :                         "default arguments are not allowed in declaration "
   12275              :                         "of friend template specialization %qD",
   12276              :                         decl);
   12277            5 :               return NULL_TREE;
   12278              :             }
   12279              : 
   12280        89991 :           if (inlinep & 1)
   12281              :             {
   12282            5 :               error_at (declspecs->locations[ds_inline],
   12283              :                         "%<inline%> is not allowed in declaration of friend "
   12284              :                         "template specialization %qD",
   12285              :                         decl);
   12286            5 :               return NULL_TREE;
   12287              :             }
   12288              :         }
   12289              :     }
   12290              : 
   12291              :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   12292              :      expression, that declaration shall be a definition..."  */
   12293    183858234 :   if (friendp && !funcdef_flag)
   12294              :     {
   12295      1773915 :       bool has_errored = false;
   12296      1773915 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   12297      4984141 :            t && t != void_list_node; t = TREE_CHAIN (t))
   12298      3210226 :         if (TREE_PURPOSE (t))
   12299              :           {
   12300           48 :             enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
   12301              :             /* For templates, mark the default argument as erroneous and give a
   12302              :                hard error.  */
   12303           48 :             if (processing_template_decl)
   12304              :               {
   12305           30 :                 diag_kind = diagnostics::kind::error;
   12306           30 :                 TREE_PURPOSE (t) = error_mark_node;
   12307              :               }
   12308           48 :             if (!has_errored)
   12309              :               {
   12310           45 :                 has_errored = true;
   12311           45 :                 emit_diagnostic (diag_kind,
   12312           45 :                                  DECL_SOURCE_LOCATION (decl),
   12313           45 :                                  /*diagnostics::option_id=*/0,
   12314              :                                  "friend declaration of %qD specifies default "
   12315              :                                  "arguments and isn%'t a definition", decl);
   12316              :               }
   12317              :           }
   12318              :     }
   12319              : 
   12320              :   /* If this decl has namespace scope, set that up.  */
   12321    183858234 :   if (in_namespace)
   12322       219327 :     set_decl_namespace (decl, in_namespace, friendp);
   12323    183638907 :   else if (ctype)
   12324    109696337 :     DECL_CONTEXT (decl) = ctype;
   12325              :   else
   12326     73942570 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   12327              : 
   12328              :   /* `main' and builtins have implicit 'C' linkage.  */
   12329    183858234 :   if (ctype == NULL_TREE
   12330     74161897 :       && DECL_FILE_SCOPE_P (decl)
   12331     30870211 :       && current_lang_name == lang_name_cplusplus
   12332    186786285 :       && (MAIN_NAME_P (declarator)
   12333      2894923 :           || (IDENTIFIER_LENGTH (declarator) > 10
   12334      2078975 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   12335      1624793 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   12336       339784 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   12337              :                              "builtin_"))
   12338      2894905 :           || (targetcm.cxx_implicit_extern_c
   12339            0 :               && (targetcm.cxx_implicit_extern_c
   12340            0 :                   (IDENTIFIER_POINTER (declarator))))))
   12341        33146 :     SET_DECL_LANGUAGE (decl, lang_c);
   12342              : 
   12343    183858234 :   DECL_STATIC_FUNCTION_P (decl)
   12344    183858234 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   12345    183858234 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   12346              : 
   12347    183858234 :   if (initialized == SD_DELETED)
   12348      4074685 :     DECL_DELETED_FN (decl) = 1;
   12349              : 
   12350    183858234 :   if (ctype && funcdef_flag)
   12351     94748149 :     check_class_member_definition_namespace (decl);
   12352              : 
   12353    183858234 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12354              :     {
   12355        33134 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   12356            9 :         error_at (location, "cannot declare %<::main%> to be a template");
   12357        33134 :       if (inlinep & 1)
   12358            3 :         error_at (declspecs->locations[ds_inline],
   12359              :                   "cannot declare %<::main%> to be inline");
   12360        33134 :       if (inlinep & 2)
   12361            6 :         error_at (declspecs->locations[ds_constexpr],
   12362              :                   "cannot declare %<::main%> to be %qs", "constexpr");
   12363        33134 :       if (inlinep & 8)
   12364            3 :         error_at (declspecs->locations[ds_consteval],
   12365              :                   "cannot declare %<::main%> to be %qs", "consteval");
   12366        33134 :       if (!publicp)
   12367            0 :         error_at (location, "cannot declare %<::main%> to be static");
   12368        33134 :       if (current_lang_name != lang_name_cplusplus)
   12369           12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   12370              :                  " linkage specification other than %<extern \"C++\"%>");
   12371        33134 :       if (module_attach_p ())
   12372              :         {
   12373            3 :           auto_diagnostic_group adg;
   12374            3 :           error_at (location, "cannot attach %<::main%> to a named module");
   12375            3 :           inform (location, "use %<extern \"C++\"%> to attach it to the "
   12376              :                   "global module instead");
   12377            3 :         }
   12378              :       inlinep = 0;
   12379              :       publicp = 1;
   12380              :     }
   12381              : 
   12382              :   /* Members of anonymous types and local classes have no linkage; make
   12383              :      them internal.  If a typedef is made later, this will be changed.  */
   12384    183858234 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   12385              :     publicp = 0;
   12386    183845558 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   12387              :     /* But members of local classes in a module CMI should have their
   12388              :        definitions exported, in case they are (directly or indirectly)
   12389              :        used by an importer.  We don't just use module_has_cmi_p here
   12390              :        because for entities in the GMF we don't yet know whether this
   12391              :        module will have a CMI, so we'll conservatively assume it might.  */
   12392      2457532 :     publicp = module_maybe_has_cmi_p ();
   12393              : 
   12394    183845558 :   if (publicp && cxx_dialect == cxx98)
   12395              :     {
   12396              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12397              :          or enumeration declared in a local scope) shall not be used to
   12398              :          declare an entity with linkage.
   12399              : 
   12400              :          DR 757 relaxes this restriction for C++0x.  */
   12401      1100120 :       no_linkage_error (decl);
   12402              :     }
   12403              : 
   12404    183858234 :   TREE_PUBLIC (decl) = publicp;
   12405    183858234 :   if (! publicp)
   12406              :     {
   12407      2572660 :       DECL_INTERFACE_KNOWN (decl) = 1;
   12408      2572660 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   12409              :     }
   12410              : 
   12411              :   /* If the declaration was declared inline, mark it as such.  */
   12412    183858234 :   if (inlinep)
   12413              :     {
   12414     69202115 :       DECL_DECLARED_INLINE_P (decl) = 1;
   12415     69202115 :       if (publicp)
   12416     68967149 :         DECL_COMDAT (decl) = 1;
   12417              :     }
   12418     69202115 :   if (inlinep & 2)
   12419     50552703 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12420    133305531 :   else if (inlinep & 8)
   12421              :     {
   12422       929312 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12423       929312 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   12424              :     }
   12425              : 
   12426    183858234 :   DECL_EXTERNAL (decl) = 1;
   12427    183858234 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12428              :     {
   12429     84241757 :       if (quals || rqual)
   12430          272 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   12431              :                                               TYPE_UNQUALIFIED,
   12432              :                                               REF_QUAL_NONE);
   12433     84241757 :       auto_diagnostic_group d;
   12434     84241757 :       if (quals)
   12435          423 :         error (!ctype
   12436              :                ? G_("non-member function %qD cannot have cv-qualifier")
   12437              :                : !xobj_func_p
   12438          198 :                  ? G_("static member function %qD cannot have cv-qualifier")
   12439              :                  : G_("explicit object member function "
   12440              :                       "%qD cannot have cv-qualifier"),
   12441              :                decl);
   12442     84241757 :       if (rqual)
   12443          355 :         error (!ctype
   12444              :                ? G_("non-member function %qD cannot have ref-qualifier")
   12445              :                : !xobj_func_p
   12446          176 :                  ? G_("static member function %qD cannot have ref-qualifier")
   12447              :                  : G_("explicit object member function "
   12448              :                       "%qD cannot have ref-qualifier"),
   12449              :                  decl);
   12450              : 
   12451     84241757 :       if (xobj_func_p && (quals || rqual))
   12452          242 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   12453              :                 "explicit object parameter declared here");
   12454     84241757 :       quals = TYPE_UNQUALIFIED;
   12455     84241757 :       rqual = REF_QUAL_NONE;
   12456              : 
   12457     84241757 :     }
   12458              : 
   12459    183858234 :   if (deduction_guide_p (decl))
   12460              :     {
   12461      1166650 :       tree type = TREE_TYPE (DECL_NAME (decl));
   12462      1166650 :       if (in_namespace == NULL_TREE
   12463      1166650 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   12464              :         {
   12465            3 :           auto_diagnostic_group d;
   12466            3 :           error_at (location, "deduction guide %qD must be declared in the "
   12467              :                               "same scope as %qT", decl, type);
   12468            3 :           inform (location_of (type), "  declared here");
   12469            3 :           return NULL_TREE;
   12470            3 :         }
   12471      2333294 :       if (DECL_CLASS_SCOPE_P (decl)
   12472      1166687 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   12473              :         {
   12474            3 :           auto_diagnostic_group d;
   12475            3 :           error_at (location, "deduction guide %qD must have the same access "
   12476              :                               "as %qT", decl, type);
   12477            3 :           inform (location_of (type), "  declared here");
   12478            3 :         }
   12479      1166647 :       if (funcdef_flag)
   12480            3 :         error_at (location,
   12481              :                   "deduction guide %qD must not have a function body", decl);
   12482              :     }
   12483    340577762 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   12484    194234679 :            && !grok_op_properties (decl, /*complain=*/true))
   12485              :     return NULL_TREE;
   12486    182691437 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   12487              :     {
   12488       299134 :       bool long_long_unsigned_p;
   12489       299134 :       bool long_double_p;
   12490       299134 :       const char *suffix = NULL;
   12491              :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   12492       299134 :       if (DECL_LANGUAGE (decl) == lang_c)
   12493              :         {
   12494            6 :           auto_diagnostic_group d;
   12495            6 :           error_at (location, "literal operator with C linkage");
   12496            6 :           maybe_show_extern_c_location ();
   12497            6 :           return NULL_TREE;
   12498            6 :         }
   12499              : 
   12500       299128 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   12501              :         {
   12502       299122 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   12503              :                                             &long_double_p))
   12504              :             {
   12505           42 :               error_at (location, "%qD has invalid argument list", decl);
   12506           42 :               return NULL_TREE;
   12507              :             }
   12508              : 
   12509       299080 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   12510       299080 :           if (long_long_unsigned_p)
   12511              :             {
   12512        45142 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   12513           68 :                 warning_at (location, 0, "integer suffix %qs"
   12514              :                             " shadowed by implementation", suffix);
   12515              :             }
   12516       253938 :           else if (long_double_p)
   12517              :             {
   12518        82888 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   12519           80 :                 warning_at (location, 0, "floating-point suffix %qs"
   12520              :                             " shadowed by implementation", suffix);
   12521              :             }
   12522              :           /* 17.6.3.3.5  */
   12523       299080 :           if (suffix[0] != '_'
   12524       298506 :               && !current_function_decl && !(friendp && !funcdef_flag))
   12525       298500 :             warning_at (location, OPT_Wliteral_suffix,
   12526              :                         "literal operator suffixes not preceded by %<_%>"
   12527              :                         " are reserved for future standardization");
   12528              :         }
   12529              :       else
   12530              :         {
   12531            6 :           error_at (location, "%qD must be a non-member function", decl);
   12532            6 :           return NULL_TREE;
   12533              :         }
   12534              :     }
   12535              : 
   12536    182691386 :   if (funcdef_flag)
   12537              :     /* Make the init_value nonzero so pushdecl knows this is not
   12538              :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   12539    129514338 :     DECL_INITIAL (decl) = error_mark_node;
   12540              : 
   12541    183858030 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   12542     69679839 :     TREE_NOTHROW (decl) = 1;
   12543              : 
   12544    183858030 :   if (flag_openmp || flag_openmp_simd)
   12545              :     {
   12546              :       /* Adjust "omp declare simd" attributes.  */
   12547       473536 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   12548       473536 :       if (ods)
   12549              :         {
   12550              :           tree attr;
   12551         2033 :           for (attr = ods; attr;
   12552         1078 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   12553              :             {
   12554         1078 :               if (TREE_CODE (type) == METHOD_TYPE)
   12555          204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   12556              :                            DECL_ARGUMENTS (decl), NULL);
   12557         1078 :               if (TREE_VALUE (attr) != NULL_TREE)
   12558              :                 {
   12559          872 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   12560          872 :                   cl = c_omp_declare_simd_clauses_to_numbers
   12561          872 :                                                 (DECL_ARGUMENTS (decl), cl);
   12562          872 :                   if (cl)
   12563          872 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   12564              :                   else
   12565            0 :                     TREE_VALUE (attr) = NULL_TREE;
   12566              :                 }
   12567              :             }
   12568              :         }
   12569              :     }
   12570              : 
   12571              :   /* Caller will do the rest of this.  */
   12572    183858030 :   if (check < 0)
   12573              :     {
   12574      6212956 :       if (decl && decl != error_mark_node && contract_specifiers)
   12575           16 :         set_fn_contract_specifiers (decl, contract_specifiers);
   12576      6212956 :       return decl;
   12577              :     }
   12578              : 
   12579    177645074 :   if (ctype != NULL_TREE)
   12580    109696034 :     grokclassfn (ctype, decl, flags);
   12581              : 
   12582              :   /* 12.4/3  */
   12583    177645074 :   if (cxx_dialect >= cxx11
   12584    353107650 :       && DECL_DESTRUCTOR_P (decl)
   12585      3164652 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   12586    177807063 :       && !processing_template_decl)
   12587        82828 :     deduce_noexcept_on_destructor (decl);
   12588              : 
   12589    177645074 :   set_originating_module (decl);
   12590              : 
   12591    177645074 :   decl = check_explicit_specialization (orig_declarator, decl,
   12592              :                                         template_count,
   12593    177645074 :                                         2 * funcdef_flag +
   12594    177645074 :                                         4 * (friendp != 0),
   12595              :                                         *attrlist);
   12596    177645074 :   if (decl == error_mark_node)
   12597              :     return NULL_TREE;
   12598              : 
   12599    177644827 :   if (DECL_STATIC_FUNCTION_P (decl))
   12600     10001952 :     check_static_quals (decl, quals);
   12601              : 
   12602    177644827 :   if (attrlist)
   12603              :     {
   12604    177644827 :       cplus_decl_attributes (&decl, *attrlist, 0);
   12605    177644827 :       *attrlist = NULL_TREE;
   12606              :     }
   12607              : 
   12608              :   /* Update now we have a decl and maybe know the return type.  */
   12609    177644827 :   if (contract_specifiers)
   12610              :     {
   12611          545 :       tree t = decl;
   12612          545 :       if (TREE_CODE (decl) == TEMPLATE_DECL)
   12613            2 :         t = DECL_TEMPLATE_RESULT (decl);
   12614          545 :       set_fn_contract_specifiers (t, contract_specifiers);
   12615          545 :       rebuild_postconditions (t);
   12616              :     }
   12617              : 
   12618              :   /* Check main's type after attributes have been applied.  */
   12619    177644827 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12620              :     {
   12621        33122 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   12622              :                         integer_type_node))
   12623              :         {
   12624           20 :           tree dtype = TREE_TYPE (decl);
   12625           20 :           tree oldtypeargs = TYPE_ARG_TYPES (dtype);
   12626           20 :           tree newtype;
   12627           20 :           error_at (declspecs->locations[ds_type_spec],
   12628              :                     "%<::main%> must return %<int%>");
   12629           60 :           newtype = build_function_type (integer_type_node, oldtypeargs,
   12630           20 :                                          TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
   12631           20 :           TREE_TYPE (decl) = newtype;
   12632              :         }
   12633        33122 :       if (warn_main)
   12634        33100 :         check_main_parameter_types (decl);
   12635              :     }
   12636              : 
   12637    177644827 :   if (ctype != NULL_TREE && check)
   12638              :     {
   12639      8779931 :       tree old_decl = check_classfn (ctype, decl,
   12640      8779931 :                                      (current_template_depth
   12641      8779931 :                                       > template_class_depth (ctype))
   12642      2125187 :                                      ? current_template_parms
   12643              :                                      : NULL_TREE);
   12644              : 
   12645      8779931 :       if (old_decl == error_mark_node)
   12646              :         return NULL_TREE;
   12647              : 
   12648      8779823 :       if (old_decl)
   12649              :         {
   12650      8392084 :           tree ok;
   12651      8392084 :           tree pushed_scope;
   12652              : 
   12653      8392084 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   12654              :             /* Because grokfndecl is always supposed to return a
   12655              :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   12656              :                here.  We depend on our callers to figure out that its
   12657              :                really a template that's being returned.  */
   12658      2125175 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   12659              : 
   12660      8392084 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   12661      8392084 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   12662              :             {
   12663              :               /* Remove the `this' parm added by grokclassfn.  */
   12664       168704 :               revert_static_member_fn (decl);
   12665       168704 :               check_static_quals (decl, quals);
   12666              :             }
   12667      8392084 :           if (DECL_ARTIFICIAL (old_decl))
   12668              :             {
   12669            9 :               error ("definition of implicitly-declared %qD", old_decl);
   12670            9 :               return NULL_TREE;
   12671              :             }
   12672      8392075 :           else if (DECL_DEFAULTED_FN (old_decl))
   12673              :             {
   12674            3 :               auto_diagnostic_group d;
   12675            3 :               error ("definition of explicitly-defaulted %q+D", decl);
   12676            3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   12677              :                       "%q#D explicitly defaulted here", old_decl);
   12678            3 :               return NULL_TREE;
   12679            3 :             }
   12680              : 
   12681              :           /* Since we've smashed OLD_DECL to its
   12682              :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   12683      8392072 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   12684         1116 :             decl = DECL_TEMPLATE_RESULT (decl);
   12685              : 
   12686              :           /* Attempt to merge the declarations.  This can fail, in
   12687              :              the case of some invalid specialization declarations.  */
   12688      8392072 :           pushed_scope = push_scope (ctype);
   12689      8392072 :           ok = duplicate_decls (decl, old_decl);
   12690      8392072 :           if (pushed_scope)
   12691      8392072 :             pop_scope (pushed_scope);
   12692      8392072 :           if (!ok)
   12693              :             {
   12694            0 :               error ("no %q#D member function declared in class %qT",
   12695              :                      decl, ctype);
   12696            0 :               return NULL_TREE;
   12697              :             }
   12698      8392072 :           if (ok == error_mark_node)
   12699              :             return NULL_TREE;
   12700              :           return old_decl;
   12701              :         }
   12702              :     }
   12703              : 
   12704    338505270 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   12705              :     return NULL_TREE;
   12706              : 
   12707              :   /* Don't call check_consteval_only_fn for defaulted functions.  Those are
   12708              :      immediate-escalating functions but at this point DECL_DEFAULTED_P has
   12709              :      not been set.  */
   12710    169252632 :   if (initialized != SD_DEFAULTED)
   12711    162847523 :     check_consteval_only_fn (decl);
   12712              : 
   12713    169252632 :   if (ctype == NULL_TREE || check)
   12714     68336589 :     return decl;
   12715              : 
   12716    100916043 :   if (virtualp)
   12717      4060446 :     DECL_VIRTUAL_P (decl) = 1;
   12718              : 
   12719    100916043 :   return decl;
   12720              : }
   12721              : 
   12722              : /* decl is a FUNCTION_DECL.
   12723              :    specifiers are the parsed virt-specifiers.
   12724              : 
   12725              :    Set flags to reflect the virt-specifiers.
   12726              : 
   12727              :    Returns decl.  */
   12728              : 
   12729              : static tree
   12730    107129096 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   12731              : {
   12732    107129096 :   if (decl == NULL_TREE)
   12733              :     return decl;
   12734    107128999 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   12735       319193 :     DECL_OVERRIDE_P (decl) = 1;
   12736    107128999 :   if (specifiers & VIRT_SPEC_FINAL)
   12737         9546 :     DECL_FINAL_P (decl) = 1;
   12738              :   return decl;
   12739              : }
   12740              : 
   12741              : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   12742              :    the linkage that DECL will receive in the object file.  */
   12743              : 
   12744              : static void
   12745     13106819 : set_linkage_for_static_data_member (tree decl)
   12746              : {
   12747              :   /* A static data member always has static storage duration and
   12748              :      external linkage.  Note that static data members are forbidden in
   12749              :      local classes -- the only situation in which a class has
   12750              :      non-external linkage.  */
   12751     13106819 :   TREE_PUBLIC (decl) = 1;
   12752     13106819 :   TREE_STATIC (decl) = 1;
   12753              :   /* For non-template classes, static data members are always put
   12754              :      out in exactly those files where they are defined, just as
   12755              :      with ordinary namespace-scope variables.  */
   12756     13106819 :   if (!processing_template_decl)
   12757      9970593 :     DECL_INTERFACE_KNOWN (decl) = 1;
   12758     13106819 : }
   12759              : 
   12760              : /* Create a VAR_DECL named NAME with the indicated TYPE.
   12761              : 
   12762              :    If SCOPE is non-NULL, it is the class type or namespace containing
   12763              :    the variable.  If SCOPE is NULL, the variable should is created in
   12764              :    the innermost enclosing scope.  */
   12765              : 
   12766              : static tree
   12767     66650619 : grokvardecl (tree type,
   12768              :              tree name,
   12769              :              tree orig_declarator,
   12770              :              const cp_decl_specifier_seq *declspecs,
   12771              :              int initialized,
   12772              :              int type_quals,
   12773              :              int inlinep,
   12774              :              bool conceptp,
   12775              :              int template_count,
   12776              :              tree scope,
   12777              :              location_t location)
   12778              : {
   12779     66650619 :   tree decl;
   12780     66650619 :   tree explicit_scope;
   12781              : 
   12782     66650619 :   gcc_assert (!name || identifier_p (name));
   12783              : 
   12784     66650619 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   12785     66650619 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   12786              : 
   12787              :   /* Compute the scope in which to place the variable, but remember
   12788              :      whether or not that scope was explicitly specified by the user.   */
   12789     66650619 :   explicit_scope = scope;
   12790     66650619 :   if (!scope)
   12791              :     {
   12792              :       /* An explicit "extern" specifier indicates a namespace-scope
   12793              :          variable.  */
   12794     66153758 :       if (declspecs->storage_class == sc_extern)
   12795       544383 :         scope = current_decl_namespace ();
   12796     65609375 :       else if (!at_function_scope_p ())
   12797      6849231 :         scope = current_scope ();
   12798              :     }
   12799              : 
   12800     66153758 :   if (scope
   12801      7890475 :       && (/* If the variable is a namespace-scope variable declared in a
   12802              :              template, we need DECL_LANG_SPECIFIC.  */
   12803      7890475 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   12804              :           /* Similarly for namespace-scope variables with language linkage
   12805              :              other than C++.  */
   12806      7407399 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   12807      4289293 :               && current_lang_name != lang_name_cplusplus)
   12808              :           /* Similarly for static data members.  */
   12809      4544840 :           || TYPE_P (scope)
   12810              :           /* Similarly for explicit specializations.  */
   12811      4061764 :           || (orig_declarator
   12812      4061106 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   12813      4641262 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   12814              :   else
   12815     62009357 :     decl = build_decl (location, VAR_DECL, name, type);
   12816              : 
   12817     66650619 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   12818        13785 :     set_decl_namespace (decl, explicit_scope, 0);
   12819              :   else
   12820     66636834 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   12821              : 
   12822     66650619 :   if (declspecs->storage_class == sc_extern)
   12823              :     {
   12824       544383 :       DECL_THIS_EXTERN (decl) = 1;
   12825       544383 :       DECL_EXTERNAL (decl) = !initialized;
   12826              :     }
   12827              : 
   12828     66650619 :   if (DECL_CLASS_SCOPE_P (decl))
   12829              :     {
   12830       483076 :       set_linkage_for_static_data_member (decl);
   12831              :       /* This function is only called with out-of-class definitions.  */
   12832       483076 :       DECL_EXTERNAL (decl) = 0;
   12833       483076 :       check_class_member_definition_namespace (decl);
   12834              :     }
   12835              :   /* At top level, either `static' or no s.c. makes a definition
   12836              :      (perhaps tentative), and absence of `static' makes it public.  */
   12837     66167543 :   else if (toplevel_bindings_p ())
   12838              :     {
   12839     14812498 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   12840      7406249 :                             && (DECL_THIS_EXTERN (decl)
   12841      6824155 :                                 || ! constp
   12842      6824155 :                                 || volatilep
   12843      6748104 :                                 || inlinep
   12844       514110 :                                 || in_template_context
   12845        28428 :                                 || processing_specialization
   12846        28359 :                                 || module_attach_p ()));
   12847      7406249 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   12848              :     }
   12849              :   /* Not at top level, only `static' makes a static definition.  */
   12850              :   else
   12851              :     {
   12852     58761294 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   12853     58761294 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   12854              :     }
   12855              : 
   12856     66650619 :   set_originating_module (decl);
   12857              : 
   12858     66650619 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   12859              :     {
   12860        19321 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   12861              :         {
   12862        19313 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   12863              :           // NB: Set a tentative TLS model to avoid tls_model attribute
   12864              :           // warnings due to lack of thread storage duration.  It will
   12865              :           // be updated by cplus_decl_attributes later.
   12866        19313 :           if (!processing_template_decl)
   12867        19189 :             set_decl_tls_model (decl, TLS_MODEL_REAL);
   12868              :         }
   12869        19321 :       if (declspecs->gnu_thread_keyword_p)
   12870        18325 :         SET_DECL_GNU_TLS_P (decl);
   12871              :     }
   12872              : 
   12873              :   /* If the type of the decl has no linkage, make sure that we'll
   12874              :      notice that in mark_used.  */
   12875     66650619 :   if (cxx_dialect > cxx98
   12876     66362323 :       && decl_linkage (decl) != lk_none
   12877     65687982 :       && DECL_LANG_SPECIFIC (decl) == NULL
   12878     60969844 :       && !DECL_EXTERN_C_P (decl)
   12879    127620463 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   12880         4206 :     retrofit_lang_decl (decl);
   12881              : 
   12882     66650619 :   if (TREE_PUBLIC (decl))
   12883              :     {
   12884              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12885              :          or enumeration declared in a local scope) shall not be used to
   12886              :          declare an entity with linkage.
   12887              : 
   12888              :          DR 757 relaxes this restriction for C++0x.  */
   12889      7823261 :       if (cxx_dialect < cxx11)
   12890        22226 :         no_linkage_error (decl);
   12891              :     }
   12892              :   else
   12893     58827358 :     DECL_INTERFACE_KNOWN (decl) = 1;
   12894              : 
   12895     66650619 :   if (DECL_NAME (decl)
   12896     66650619 :       && MAIN_NAME_P (DECL_NAME (decl)))
   12897              :     {
   12898           12 :       if (scope == global_namespace)
   12899            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   12900              :                   "cannot declare %<::main%> to be a global variable");
   12901            6 :       else if (DECL_EXTERN_C_P (decl))
   12902            3 :         error_at (DECL_SOURCE_LOCATION (decl),
   12903              :                   "an entity named %<main%> cannot be declared with "
   12904              :                   "C language linkage");
   12905              :     }
   12906              : 
   12907              :   /* Check if a variable is being declared as a concept.  */
   12908     66650619 :   if (conceptp)
   12909              :     {
   12910           30 :       if (!processing_template_decl)
   12911           13 :         error_at (declspecs->locations[ds_concept],
   12912              :                   "a non-template variable cannot be %<concept%>");
   12913           17 :       else if (!at_namespace_scope_p ())
   12914            2 :         error_at (declspecs->locations[ds_concept],
   12915              :                   "concept must be defined at namespace scope");
   12916              :       else
   12917           15 :         error_at (declspecs->locations[ds_concept],
   12918              :                   "variable concepts are no longer supported");
   12919           30 :       return NULL_TREE;
   12920              :     }
   12921     66650589 :   else if (flag_concepts
   12922     66650589 :            && current_template_depth > template_class_depth (scope))
   12923              :     {
   12924     57308181 :       tree ci = current_template_constraints ();
   12925     57308181 :       set_constraints (decl, ci);
   12926              :     }
   12927              : 
   12928              :   // Handle explicit specializations and instantiations of variable templates.
   12929     66650589 :   if (orig_declarator)
   12930     65967654 :     decl = check_explicit_specialization (orig_declarator, decl,
   12931              :                                           template_count, 0);
   12932              : 
   12933     66650589 :   return decl != error_mark_node ? decl : NULL_TREE;
   12934              : }
   12935              : 
   12936              : /* Create and return a canonical pointer to member function type, for
   12937              :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   12938              : 
   12939              : tree
   12940      3081341 : build_ptrmemfunc_type (tree type)
   12941              : {
   12942      3081341 :   tree field, fields;
   12943      3081341 :   tree t;
   12944              : 
   12945      3081341 :   if (type == error_mark_node)
   12946              :     return type;
   12947              : 
   12948              :   /* Make sure that we always have the unqualified pointer-to-member
   12949              :      type first.  */
   12950      3081341 :   if (cp_cv_quals quals = cp_type_quals (type))
   12951              :     {
   12952            0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   12953            0 :       return cp_build_qualified_type (unqual, quals);
   12954              :     }
   12955              : 
   12956              :   /* If a canonical type already exists for this type, use it.  We use
   12957              :      this method instead of type_hash_canon, because it only does a
   12958              :      simple equality check on the list of field members.  */
   12959              : 
   12960      3081341 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   12961      3081341 :   if (t)
   12962              :     return t;
   12963              : 
   12964      1020003 :   t = make_node (RECORD_TYPE);
   12965              : 
   12966              :   /* Let the front end know this is a pointer to member function.  */
   12967      1020003 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   12968              : 
   12969      1020003 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   12970      1020003 :   DECL_NONADDRESSABLE_P (field) = 1;
   12971      1020003 :   fields = field;
   12972              : 
   12973      1020003 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   12974              :                       delta_type_node);
   12975      1020003 :   DECL_NONADDRESSABLE_P (field) = 1;
   12976      1020003 :   DECL_CHAIN (field) = fields;
   12977      1020003 :   fields = field;
   12978              : 
   12979      1020003 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   12980              : 
   12981              :   /* Zap out the name so that the back end will give us the debugging
   12982              :      information for this anonymous RECORD_TYPE.  */
   12983      1020003 :   TYPE_NAME (t) = NULL_TREE;
   12984              : 
   12985              :   /* Cache this pointer-to-member type so that we can find it again
   12986              :      later.  */
   12987      1020003 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   12988              : 
   12989      1020003 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   12990       495132 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   12991       524871 :   else if (TYPE_CANONICAL (type) != type)
   12992       341541 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   12993              : 
   12994              :   return t;
   12995              : }
   12996              : 
   12997              : /* Create and return a pointer to data member type.  */
   12998              : 
   12999              : tree
   13000       316541 : build_ptrmem_type (tree class_type, tree member_type)
   13001              : {
   13002       316541 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   13003              :     {
   13004        58067 :       cp_cv_quals quals = type_memfn_quals (member_type);
   13005        58067 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   13006        58067 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   13007        58067 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   13008              :     }
   13009              :   else
   13010              :     {
   13011       258474 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   13012       258474 :       return build_offset_type (class_type, member_type);
   13013              :     }
   13014              : }
   13015              : 
   13016              : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   13017              :    Check to see that the definition is valid.  Issue appropriate error
   13018              :    messages.  */
   13019              : 
   13020              : static void
   13021     18399255 : check_static_variable_definition (tree decl, tree type)
   13022              : {
   13023              :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   13024     18399255 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   13025              :     ;
   13026              :   /* Can't check yet if we don't know the type.  */
   13027     16820970 :   else if (dependent_type_p (type))
   13028              :     ;
   13029              :   /* If DECL is declared constexpr, we'll do the appropriate checks
   13030              :      in check_initializer.  Similarly for inline static data members.  */
   13031     16299978 :   else if (DECL_P (decl)
   13032     16299978 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   13033      2639187 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   13034              :     ;
   13035      2638711 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13036              :     {
   13037           56 :       if (!COMPLETE_TYPE_P (type))
   13038           11 :         error_at (DECL_SOURCE_LOCATION (decl),
   13039              :                   "in-class initialization of static data member %q#D of "
   13040              :                   "incomplete type", decl);
   13041           45 :       else if (literal_type_p (type))
   13042           39 :         permerror (DECL_SOURCE_LOCATION (decl),
   13043              :                    "%<constexpr%> needed for in-class initialization of "
   13044              :                    "static data member %q#D of non-integral type", decl);
   13045              :       else
   13046            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13047              :                   "in-class initialization of static data member %q#D of "
   13048              :                   "non-literal type", decl);
   13049              :     }
   13050              :   /* Motion 10 at San Diego: If a static const integral data member is
   13051              :      initialized with an integral constant expression, the initializer
   13052              :      may appear either in the declaration (within the class), or in
   13053              :      the definition, but not both.  If it appears in the class, the
   13054              :      member is a member constant.  The file-scope definition is always
   13055              :      required.  */
   13056      2638655 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   13057           11 :     error_at (DECL_SOURCE_LOCATION (decl),
   13058              :               "invalid in-class initialization of static data member "
   13059              :               "of non-integral type %qT",
   13060              :               type);
   13061      2638644 :   else if (!CP_TYPE_CONST_P (type))
   13062            5 :     error_at (DECL_SOURCE_LOCATION (decl),
   13063              :               "ISO C++ forbids in-class initialization of non-const "
   13064              :               "static member %qD",
   13065              :               decl);
   13066      2638639 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13067            5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   13068              :              "ISO C++ forbids initialization of member constant "
   13069              :              "%qD of non-integral type %qT", decl, type);
   13070     18399255 : }
   13071              : 
   13072              : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   13073              :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   13074              :    expressions out into temporary variables so that walk_tree doesn't
   13075              :    step into them (c++/15764).  */
   13076              : 
   13077              : static tree
   13078         3404 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   13079              : {
   13080         3404 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   13081         3404 :   tree expr = *expr_p;
   13082         3404 :   if (TREE_CODE (expr) == SAVE_EXPR)
   13083              :     {
   13084         1483 :       tree op = TREE_OPERAND (expr, 0);
   13085         1483 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   13086         1483 :       if (TREE_SIDE_EFFECTS (op))
   13087           56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   13088         1483 :       *walk_subtrees = 0;
   13089              :     }
   13090         1921 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   13091         1746 :     *walk_subtrees = 0;
   13092         3404 :   return NULL;
   13093              : }
   13094              : 
   13095              : /* Entry point for the above.  */
   13096              : 
   13097              : static void
   13098         1542 : stabilize_vla_size (tree size)
   13099              : {
   13100         1542 :   hash_set<tree> pset;
   13101              :   /* Break out any function calls into temporary variables.  */
   13102         1542 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   13103         1542 : }
   13104              : 
   13105              : /* Reduce a SIZEOF_EXPR to its value.  */
   13106              : 
   13107              : tree
   13108     14744249 : fold_sizeof_expr (tree t)
   13109              : {
   13110     14744249 :   tree r;
   13111     14744249 :   if (SIZEOF_EXPR_TYPE_P (t))
   13112     13568061 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13113     13568061 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   13114              :                                     SIZEOF_EXPR, false, false);
   13115      1176188 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   13116            0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13117            0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13118              :                                     false, false);
   13119              :   else
   13120      1176188 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   13121      1176188 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13122              :                                     false, false);
   13123     14744249 :   if (r == error_mark_node)
   13124           67 :     r = size_one_node;
   13125     14744249 :   r = cp_fold_convert (size_type_node, r);
   13126     14744249 :   return r;
   13127              : }
   13128              : 
   13129              : /* Given the SIZE (i.e., number of elements) in an array, compute
   13130              :    an appropriate index type for the array.  If non-NULL, NAME is
   13131              :    the name of the entity being declared.  */
   13132              : 
   13133              : static tree
   13134      3557051 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   13135              :                               tsubst_flags_t complain)
   13136              : {
   13137      3557051 :   if (error_operand_p (size))
   13138           32 :     return error_mark_node;
   13139              : 
   13140              :   /* The type of the index being computed.  */
   13141      3557019 :   tree itype;
   13142              : 
   13143              :   /* The original numeric size as seen in the source code before
   13144              :      conversion to size_t.  */
   13145      3557019 :   tree origsize = size;
   13146              : 
   13147      3557019 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   13148              : 
   13149      3557019 :   if (!type_dependent_expression_p (size))
   13150              :     {
   13151      3512347 :       origsize = size = mark_rvalue_use (size);
   13152              : 
   13153        37527 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   13154      3512507 :           && TREE_SIDE_EFFECTS (size))
   13155              :         /* In C++98, we mark a non-constant array bound with a magic
   13156              :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   13157              :       else
   13158              :         {
   13159      3512346 :           size = build_converted_constant_expr (size_type_node, size, complain);
   13160              :           /* Pedantically a constant expression is required here and so
   13161              :              __builtin_is_constant_evaluated () should fold to true if it
   13162              :              is successfully folded into a constant.  */
   13163      3512346 :           size = fold_non_dependent_expr (size, complain,
   13164              :                                           /*manifestly_const_eval=*/true);
   13165              : 
   13166      3512346 :           if (!TREE_CONSTANT (size))
   13167       133955 :             size = origsize;
   13168              :         }
   13169              : 
   13170      3512347 :       if (error_operand_p (size))
   13171            3 :         return error_mark_node;
   13172              : 
   13173              :       /* The array bound must be an integer type.  */
   13174      3512344 :       tree type = TREE_TYPE (size);
   13175      3512344 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   13176              :         {
   13177           21 :           if (!(complain & tf_error))
   13178            0 :             return error_mark_node;
   13179           21 :           if (name)
   13180           18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   13181              :                       name, type);
   13182              :           else
   13183            3 :             error_at (loc, "size of array has non-integral type %qT", type);
   13184           21 :           size = integer_one_node;
   13185              :         }
   13186              :     }
   13187              : 
   13188              :   /* A type is dependent if it is...an array type constructed from any
   13189              :      dependent type or whose size is specified by a constant expression
   13190              :      that is value-dependent.  */
   13191              :   /* We can only call value_dependent_expression_p on integral constant
   13192              :      expressions.  */
   13193      3557016 :   if (processing_template_decl
   13194      1515733 :       && potential_constant_expression (size)
   13195      5072724 :       && value_dependent_expression_p (size))
   13196              :     {
   13197              :       /* Just build the index type and mark that it requires
   13198              :          structural equality checks.  */
   13199       887275 :     in_template:
   13200       887275 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   13201              :                                            size, size_one_node));
   13202       887275 :       TYPE_DEPENDENT_P (itype) = 1;
   13203       887275 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   13204       887275 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   13205       887275 :       return itype;
   13206              :     }
   13207              : 
   13208      2680252 :   if (TREE_CODE (size) != INTEGER_CST)
   13209              :     {
   13210        12418 :       tree folded = cp_fully_fold (size);
   13211        12418 :       if (TREE_CODE (folded) == INTEGER_CST)
   13212              :         {
   13213          211 :           if (name)
   13214          137 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   13215              :                      "integral constant-expression", name);
   13216              :           else
   13217           74 :             pedwarn (loc, OPT_Wpedantic,
   13218              :                      "size of array is not an integral constant-expression");
   13219              :         }
   13220        12418 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   13221              :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   13222              :            folding a conversion from a pointer to integral type.  In that
   13223              :            case issue an error below and don't treat this as a VLA.  */;
   13224              :       else
   13225              :         /* Use the folded result for VLAs, too; it will have resolved
   13226              :            SIZEOF_EXPR.  */
   13227              :         size = folded;
   13228              :     }
   13229              : 
   13230              :   /* Normally, the array-bound will be a constant.  */
   13231      2680252 :   if (TREE_CODE (size) == INTEGER_CST)
   13232              :     {
   13233              :       /* The size to use in diagnostics that reflects the constant
   13234              :          size used in the source, rather than SIZE massaged above.  */
   13235      2668045 :       tree diagsize = size;
   13236              : 
   13237              :       /* If the original size before conversion to size_t was signed
   13238              :          and negative, convert it to ssizetype to restore the sign.  */
   13239      2668045 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   13240              :           && TREE_CODE (size) == INTEGER_CST
   13241      2668045 :           && tree_int_cst_sign_bit (size))
   13242              :         {
   13243          230 :           diagsize = fold_convert (ssizetype, size);
   13244              : 
   13245              :           /* Clear the overflow bit that may have been set as a result
   13246              :              of the conversion from the sizetype of the new size to
   13247              :              ssizetype.  */
   13248          230 :           TREE_OVERFLOW (diagsize) = false;
   13249              :         }
   13250              : 
   13251              :       /* Verify that the array has a positive number of elements
   13252              :          and issue the appropriate diagnostic if it doesn't.  */
   13253      2668045 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   13254              :         {
   13255          461 :           if (!(complain & tf_error))
   13256           15 :             return error_mark_node;
   13257          446 :           size = integer_one_node;
   13258              :         }
   13259              :       /* As an extension we allow zero-sized arrays.  */
   13260      2667584 :       else if (integer_zerop (size))
   13261              :         {
   13262         3187 :           if (!(complain & tf_error))
   13263              :             /* We must fail if performing argument deduction (as
   13264              :                indicated by the state of complain), so that
   13265              :                another substitution can be found.  */
   13266            8 :             return error_mark_node;
   13267         3179 :           else if (name)
   13268         2904 :             pedwarn (loc, OPT_Wpedantic,
   13269              :                      "ISO C++ forbids zero-size array %qD", name);
   13270              :           else
   13271          275 :             pedwarn (loc, OPT_Wpedantic,
   13272              :                      "ISO C++ forbids zero-size array");
   13273              :         }
   13274              :     }
   13275        12207 :   else if (TREE_CONSTANT (size)
   13276              :            /* We don't allow VLAs at non-function scopes, or during
   13277              :               tentative template substitution.  */
   13278        12192 :            || !at_function_scope_p ()
   13279        24266 :            || !(complain & tf_error))
   13280              :     {
   13281          154 :       if (!(complain & tf_error))
   13282          109 :         return error_mark_node;
   13283              :       /* `(int) &fn' is not a valid array bound.  */
   13284           45 :       if (name)
   13285           37 :         error_at (loc,
   13286              :                   "size of array %qD is not an integral constant-expression",
   13287              :                   name);
   13288              :       else
   13289            8 :         error_at (loc, "size of array is not an integral constant-expression");
   13290           45 :       size = integer_one_node;
   13291              :     }
   13292        12053 :   else if (pedantic && warn_vla != 0)
   13293              :     {
   13294           30 :       if (name)
   13295           15 :         pedwarn (name_loc, OPT_Wvla,
   13296              :                  "ISO C++ forbids variable length array %qD", name);
   13297              :       else
   13298           15 :         pedwarn (input_location, OPT_Wvla,
   13299              :                  "ISO C++ forbids variable length array");
   13300              :     }
   13301        12023 :   else if (warn_vla > 0)
   13302              :     {
   13303            3 :       if (name)
   13304            3 :         warning_at (name_loc, OPT_Wvla,
   13305              :                     "variable length array %qD is used", name);
   13306              :       else
   13307            0 :         warning (OPT_Wvla,
   13308              :                  "variable length array is used");
   13309              :     }
   13310              : 
   13311      2680120 :   if (processing_template_decl && !TREE_CONSTANT (size))
   13312        10511 :     goto in_template;
   13313              :   else
   13314              :     {
   13315      2669609 :       if (!TREE_CONSTANT (size))
   13316              :         {
   13317              :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   13318              :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   13319              :              that happens when building TYPE_SIZE.  */
   13320         1542 :           size = variable_size (size);
   13321         1542 :           stabilize_vla_size (size);
   13322              :         }
   13323              : 
   13324              :       /* Compute the index of the largest element in the array.  It is
   13325              :          one less than the number of elements in the array.  We save
   13326              :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   13327              :          cp_build_binary_op will be appropriately folded.  */
   13328      2669609 :       {
   13329      2669609 :         processing_template_decl_sentinel s;
   13330      2669609 :         itype = cp_build_binary_op (input_location,
   13331              :                                     MINUS_EXPR,
   13332              :                                     cp_convert (ssizetype, size, complain),
   13333              :                                     cp_convert (ssizetype, integer_one_node,
   13334              :                                                 complain),
   13335              :                                     complain);
   13336      2669609 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   13337      2669609 :       }
   13338              : 
   13339      2669609 :       if (!TREE_CONSTANT (itype))
   13340              :         {
   13341         1542 :           if (sanitize_flags_p (SANITIZE_VLA)
   13342         1542 :               && current_function_decl != NULL_TREE)
   13343              :             {
   13344              :               /* We have to add 1 -- in the ubsan routine we generate
   13345              :                  LE_EXPR rather than LT_EXPR.  */
   13346           78 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   13347              :                                     build_one_cst (TREE_TYPE (itype)));
   13348           78 :               t = ubsan_instrument_vla (input_location, t);
   13349           78 :               finish_expr_stmt (t);
   13350              :             }
   13351              :         }
   13352              :       /* Make sure that there was no overflow when creating to a signed
   13353              :          index type.  (For example, on a 32-bit machine, an array with
   13354              :          size 2^32 - 1 is too big.)  */
   13355      2668067 :       else if (TREE_CODE (itype) == INTEGER_CST
   13356      2668067 :                && TREE_OVERFLOW (itype))
   13357              :         {
   13358            0 :           if (!(complain & tf_error))
   13359            0 :             return error_mark_node;
   13360            0 :           error ("overflow in array dimension");
   13361            0 :           TREE_OVERFLOW (itype) = 0;
   13362              :         }
   13363              :     }
   13364              : 
   13365              :   /* Create and return the appropriate index type.  */
   13366      2669609 :   itype = build_index_type (itype);
   13367              : 
   13368              :   /* If the index type were dependent, we would have returned early, so
   13369              :      remember that it isn't.  */
   13370      2669609 :   TYPE_DEPENDENT_P (itype) = 0;
   13371      2669609 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   13372      2669609 :   return itype;
   13373              : }
   13374              : 
   13375              : tree
   13376       859804 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   13377              : {
   13378       859804 :   return compute_array_index_type_loc (input_location, name, size, complain);
   13379              : }
   13380              : 
   13381              : /* Returns the scope (if any) in which the entity declared by
   13382              :    DECLARATOR will be located.  If the entity was declared with an
   13383              :    unqualified name, NULL_TREE is returned.  */
   13384              : 
   13385              : tree
   13386    732551400 : get_scope_of_declarator (const cp_declarator *declarator)
   13387              : {
   13388    848849290 :   while (declarator && declarator->kind != cdk_id)
   13389    116297890 :     declarator = declarator->declarator;
   13390              : 
   13391              :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   13392              :      declaration occurs is the first operand.  */
   13393    732551400 :   if (declarator
   13394    731347473 :       && declarator->u.id.qualifying_scope)
   13395              :     return declarator->u.id.qualifying_scope;
   13396              : 
   13397              :   /* Otherwise, the declarator is not a qualified name; the entity will
   13398              :      be declared in the current scope.  */
   13399              :   return NULL_TREE;
   13400              : }
   13401              : 
   13402              : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   13403              :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   13404              :    with this type.  */
   13405              : 
   13406              : static tree
   13407      3481235 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   13408              : {
   13409      3481235 :   tree itype = NULL_TREE;
   13410              : 
   13411              :   /* If things have already gone awry, bail now.  */
   13412      3481235 :   if (type == error_mark_node || size == error_mark_node)
   13413              :     return error_mark_node;
   13414              : 
   13415              :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   13416              :      for a deduced class type.  */
   13417      3481172 :   if (template_placeholder_p (type))
   13418              :     {
   13419            6 :       if (name)
   13420            0 :         error_at (loc, "%qD declared as array of template placeholder "
   13421              :                   "type %qT", name, type);
   13422              :       else
   13423            6 :         error ("creating array of template placeholder type %qT", type);
   13424            6 :       return error_mark_node;
   13425              :     }
   13426              : 
   13427              :   /* If there are some types which cannot be array elements,
   13428              :      issue an error-message and return.  */
   13429      3481166 :   switch (TREE_CODE (type))
   13430              :     {
   13431            3 :     case VOID_TYPE:
   13432            3 :       if (name)
   13433            0 :         error_at (loc, "declaration of %qD as array of void", name);
   13434              :       else
   13435            3 :         error ("creating array of void");
   13436            3 :       return error_mark_node;
   13437              : 
   13438            6 :     case FUNCTION_TYPE:
   13439            6 :       if (name)
   13440            6 :         error_at (loc, "declaration of %qD as array of functions", name);
   13441              :       else
   13442            0 :         error ("creating array of functions");
   13443            6 :       return error_mark_node;
   13444              : 
   13445           21 :     case REFERENCE_TYPE:
   13446           21 :       if (name)
   13447           15 :         error_at (loc, "declaration of %qD as array of references", name);
   13448              :       else
   13449            6 :         error ("creating array of references");
   13450           21 :       return error_mark_node;
   13451              : 
   13452            0 :     case METHOD_TYPE:
   13453            0 :       if (name)
   13454            0 :         error_at (loc, "declaration of %qD as array of function members",
   13455              :                   name);
   13456              :       else
   13457            0 :         error ("creating array of function members");
   13458            0 :       return error_mark_node;
   13459              : 
   13460      3481136 :     default:
   13461      3481136 :       break;
   13462              :     }
   13463              : 
   13464      3481136 :   if (!verify_type_context (name ? loc : input_location,
   13465              :                             TCTX_ARRAY_ELEMENT, type))
   13466            0 :     return error_mark_node;
   13467              : 
   13468              :   /* [dcl.array]
   13469              : 
   13470              :      The constant expressions that specify the bounds of the arrays
   13471              :      can be omitted only for the first member of the sequence.  */
   13472      3481136 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   13473              :     {
   13474           30 :       if (name)
   13475           24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   13476              :                   "have bounds for all dimensions except the first",
   13477              :                   name);
   13478              :       else
   13479            6 :         error ("multidimensional array must have bounds for all "
   13480              :                "dimensions except the first");
   13481              : 
   13482           30 :       return error_mark_node;
   13483              :     }
   13484              : 
   13485              :   /* Figure out the index type for the array.  */
   13486      3481106 :   if (size)
   13487              :     {
   13488      2697247 :       itype = compute_array_index_type_loc (loc, name, size,
   13489              :                                             tf_warning_or_error);
   13490      2697247 :       if (type_uses_auto (type)
   13491      2697247 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   13492              :         {
   13493            9 :           sorry_at (loc, "variable-length array of %<auto%>");
   13494            9 :           return error_mark_node;
   13495              :         }
   13496              :     }
   13497              : 
   13498      3481097 :   return build_cplus_array_type (type, itype);
   13499              : }
   13500              : 
   13501              : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   13502              : 
   13503              : static location_t
   13504   1013650973 : min_location (location_t loca, location_t locb)
   13505              : {
   13506   1013650973 :   if (loca == UNKNOWN_LOCATION
   13507   1013650973 :       || (locb != UNKNOWN_LOCATION
   13508    106430500 :           && linemap_location_before_p (line_table, locb, loca)))
   13509    908364373 :     return locb;
   13510              :   return loca;
   13511              : }
   13512              : 
   13513              : /* Returns the smallest location != UNKNOWN_LOCATION among the
   13514              :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   13515              :    and LOCATIONS[ds_restrict].  */
   13516              : 
   13517              : static location_t
   13518   1011991608 : smallest_type_quals_location (int type_quals, const location_t* locations)
   13519              : {
   13520   1011991608 :   location_t loc = UNKNOWN_LOCATION;
   13521              : 
   13522   1011991608 :   if (type_quals & TYPE_QUAL_CONST)
   13523    105013533 :     loc = locations[ds_const];
   13524              : 
   13525   1011991608 :   if (type_quals & TYPE_QUAL_VOLATILE)
   13526      1659274 :     loc = min_location (loc, locations[ds_volatile]);
   13527              : 
   13528   1011991608 :   if (type_quals & TYPE_QUAL_RESTRICT)
   13529           43 :     loc = min_location (loc, locations[ds_restrict]);
   13530              : 
   13531   1011991608 :   return loc;
   13532              : }
   13533              : 
   13534              : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   13535              : 
   13536              : static location_t
   13537   1011991587 : smallest_type_location (int type_quals, const location_t* locations)
   13538              : {
   13539   1011991587 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   13540   1011991587 :   return min_location (loc, locations[ds_type_spec]);
   13541              : }
   13542              : 
   13543              : static location_t
   13544           26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   13545              : {
   13546           26 :   int type_quals = get_type_quals (declspecs);
   13547           26 :   return smallest_type_location (type_quals, declspecs->locations);
   13548              : }
   13549              : 
   13550              : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   13551              :    strip out the pointer/reference declarator(s).  */
   13552              : 
   13553              : static bool
   13554     28922555 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   13555              : {
   13556     28922555 :   bool indirect_ref_p = false;
   13557     57845257 :   while (declarator && *declarator
   13558     28922702 :          && ((*declarator)->kind == cdk_pointer
   13559     28922702 :              || (*declarator)->kind == cdk_reference))
   13560              :     {
   13561          147 :       indirect_ref_p = true;
   13562          147 :       *declarator = (*declarator)->declarator;
   13563              :     }
   13564     28922555 :   return indirect_ref_p;
   13565              : }
   13566              : 
   13567              : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   13568              :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   13569              :    this function is.  OPTYPE is the type given in a conversion operator
   13570              :    declaration, or the class type for a constructor/destructor.
   13571              :    Returns the actual return type of the function; that may be different
   13572              :    than TYPE if an error occurs, or for certain special functions.  */
   13573              : 
   13574              : static tree
   13575     28922555 : check_special_function_return_type (special_function_kind sfk,
   13576              :                                     tree type,
   13577              :                                     tree optype,
   13578              :                                     int type_quals,
   13579              :                                     const cp_declarator** declarator,
   13580              :                                     const location_t* locations)
   13581              : {
   13582     28922555 :   gcc_assert (declarator);
   13583     28922555 :   location_t rettype_loc = (type
   13584     28922555 :                             ? smallest_type_location (type_quals, locations)
   13585     28922474 :                             : (*declarator)->id_loc);
   13586     28922555 :   switch (sfk)
   13587              :     {
   13588     23580141 :     case sfk_constructor:
   13589     23580141 :       if (maybe_strip_indirect_ref (declarator) || type)
   13590           81 :         error_at (rettype_loc,
   13591              :                   "return type specification for constructor invalid");
   13592     23580060 :       else if (type_quals != TYPE_UNQUALIFIED)
   13593           15 :         error_at (smallest_type_quals_location (type_quals, locations),
   13594              :                   "qualifiers are not allowed on constructor declaration");
   13595              : 
   13596     23580141 :       if (targetm.cxx.cdtor_returns_this ())
   13597            0 :         type = build_pointer_type (optype);
   13598              :       else
   13599     23580141 :         type = void_type_node;
   13600              :       break;
   13601              : 
   13602      3185019 :     case sfk_destructor:
   13603      3185019 :       if (maybe_strip_indirect_ref (declarator) || type)
   13604           45 :         error_at (rettype_loc,
   13605              :                   "return type specification for destructor invalid");
   13606      3184974 :       else if (type_quals != TYPE_UNQUALIFIED)
   13607            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13608              :                   "qualifiers are not allowed on destructor declaration");
   13609              : 
   13610              :       /* We can't use the proper return type here because we run into
   13611              :          problems with ambiguous bases and covariant returns.  */
   13612      3185019 :       if (targetm.cxx.cdtor_returns_this ())
   13613            0 :         type = build_pointer_type (void_type_node);
   13614              :       else
   13615      3185019 :         type = void_type_node;
   13616              :       break;
   13617              : 
   13618       990739 :     case sfk_conversion:
   13619       990739 :       if (maybe_strip_indirect_ref (declarator) || type)
   13620           42 :         error_at (rettype_loc,
   13621              :                   "return type specified for %<operator %T%>", optype);
   13622       990697 :       else if (type_quals != TYPE_UNQUALIFIED)
   13623            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13624              :                   "qualifiers are not allowed on declaration of "
   13625              :                   "%<operator %T%>", optype);
   13626              : 
   13627              :       type = optype;
   13628              :       break;
   13629              : 
   13630      1166656 :     case sfk_deduction_guide:
   13631      1166656 :       if (maybe_strip_indirect_ref (declarator) || type)
   13632            0 :         error_at (rettype_loc,
   13633              :                   "return type specified for deduction guide");
   13634      1166656 :       else if (type_quals != TYPE_UNQUALIFIED)
   13635            0 :         error_at (smallest_type_quals_location (type_quals, locations),
   13636              :                   "qualifiers are not allowed on declaration of "
   13637              :                   "deduction guide");
   13638      1166656 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   13639              :         {
   13640            3 :           error ("template template parameter %qT in declaration of "
   13641              :                  "deduction guide", optype);
   13642            3 :           type = error_mark_node;
   13643              :         }
   13644              :       else
   13645      1166653 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   13646     31499712 :       for (int i = 0; i < ds_last; ++i)
   13647     30333056 :         if (i != ds_explicit && locations[i])
   13648            3 :           error_at (locations[i],
   13649              :                     "%<decl-specifier%> in declaration of deduction guide");
   13650              :       break;
   13651              : 
   13652            0 :     default:
   13653            0 :       gcc_unreachable ();
   13654              :     }
   13655              : 
   13656     28922555 :   return type;
   13657              : }
   13658              : 
   13659              : /* A variable or data member (whose unqualified name is IDENTIFIER)
   13660              :    has been declared with the indicated TYPE.  If the TYPE is not
   13661              :    acceptable, issue an error message and return a type to use for
   13662              :    error-recovery purposes.  */
   13663              : 
   13664              : tree
   13665    331131448 : check_var_type (tree identifier, tree type, location_t loc)
   13666              : {
   13667    331131448 :   if (VOID_TYPE_P (type))
   13668              :     {
   13669           86 :       if (!identifier)
   13670            0 :         error_at (loc, "unnamed variable or field declared void");
   13671           86 :       else if (identifier_p (identifier))
   13672              :         {
   13673           86 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   13674           86 :           error_at (loc, "variable or field %qE declared void",
   13675              :                     identifier);
   13676              :         }
   13677              :       else
   13678            0 :         error_at (loc, "variable or field declared void");
   13679           86 :       type = error_mark_node;
   13680              :     }
   13681              : 
   13682    331131448 :   return type;
   13683              : }
   13684              : 
   13685              : /* Handle declaring DECL as an inline variable.  */
   13686              : 
   13687              : static void
   13688      6407168 : mark_inline_variable (tree decl, location_t loc)
   13689              : {
   13690      6407168 :   bool inlinep = true;
   13691      6407168 :   if (! toplevel_bindings_p ())
   13692              :     {
   13693           24 :       error_at (loc, "%<inline%> specifier invalid for variable "
   13694              :                 "%qD declared at block scope", decl);
   13695           24 :       inlinep = false;
   13696              :     }
   13697      6407144 :   else if (cxx_dialect < cxx17)
   13698          648 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   13699              :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   13700          672 :   if (inlinep)
   13701              :     {
   13702      6407144 :       retrofit_lang_decl (decl);
   13703      6407144 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   13704              :     }
   13705      6407168 : }
   13706              : 
   13707              : 
   13708              : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn.  TYPE is the unnamed class
   13709              :    with a typedef name for linkage purposes with freshly updated TYPE_NAME,
   13710              :    ORIG is the anonymous TYPE_NAME before that change.  */
   13711              : 
   13712              : static bool
   13713           42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
   13714              : {
   13715           42 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
   13716           42 :   tree name = DECL_NAME (TYPE_NAME (type));
   13717           42 :   richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
   13718           42 :   return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
   13719              :                   "anonymous non-C-compatible type given name for linkage "
   13720           42 :                   "purposes by %<typedef%> declaration");
   13721           42 : }
   13722              : 
   13723              : /* Diagnose -Wnon-c-typedef-for-linkage violations on T.  TYPE and ORIG
   13724              :    like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
   13725              :    to TYPE but during recursion can be set to nested classes.  */
   13726              : 
   13727              : static bool
   13728       502768 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
   13729              : {
   13730       502768 :   if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
   13731              :     {
   13732            6 :       auto_diagnostic_group d;
   13733            6 :       if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13734            6 :         inform (DECL_SOURCE_LOCATION (TYPE_NAME (t)),
   13735              :                 "type is not C-compatible because it has a base class");
   13736            6 :       return true;
   13737            6 :     }
   13738      2365772 :   for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
   13739      1863071 :     switch (TREE_CODE (field))
   13740              :       {
   13741            9 :       case VAR_DECL:
   13742              :         /* static data members have been diagnosed already.  */
   13743            9 :         continue;
   13744      1239592 :       case FIELD_DECL:
   13745      1239592 :         if (DECL_INITIAL (field))
   13746              :           {
   13747            4 :             auto_diagnostic_group d;
   13748            4 :             if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13749            4 :               inform (DECL_SOURCE_LOCATION (field),
   13750              :                       "type is not C-compatible because %qD has default "
   13751              :                       "member initializer", field);
   13752            4 :             return true;
   13753            4 :           }
   13754      1239588 :         continue;
   13755            9 :       case CONST_DECL:
   13756            9 :         continue;
   13757       623384 :       case TYPE_DECL:
   13758       623384 :         if (DECL_SELF_REFERENCE_P (field))
   13759       502736 :           continue;
   13760       120648 :         if (DECL_IMPLICIT_TYPEDEF_P (field))
   13761              :           {
   13762       120638 :             if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
   13763            3 :               continue;
   13764       120635 :             if (CLASS_TYPE_P (TREE_TYPE (field)))
   13765              :               {
   13766       120635 :                 tree tf = TREE_TYPE (field);
   13767       120635 :                 if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
   13768              :                                                                     tf))
   13769              :                   return true;
   13770       120610 :                 continue;
   13771       120610 :               }
   13772              :           }
   13773              :         /* FALLTHRU */
   13774           32 :       case FUNCTION_DECL:
   13775           32 :       case TEMPLATE_DECL:
   13776           32 :         {
   13777           32 :           auto_diagnostic_group d;
   13778           32 :           if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13779           32 :             inform (DECL_SOURCE_LOCATION (field),
   13780              :                     "type is not C-compatible because it contains %qD "
   13781              :                     "declaration", field);
   13782           32 :           return true;
   13783           32 :         }
   13784              :       default:
   13785              :         break;
   13786      1239606 :       }
   13787              :   return false;
   13788              : }
   13789              : 
   13790              : /* Assign a typedef-given name to a class or enumeration type declared
   13791              :    as anonymous at first.  This was split out of grokdeclarator
   13792              :    because it is also used in libcc1.  */
   13793              : 
   13794              : void
   13795       383921 : name_unnamed_type (tree type, tree decl)
   13796              : {
   13797      1151763 :   gcc_assert (TYPE_UNNAMED_P (type)
   13798              :               || enum_with_enumerator_for_linkage_p (type));
   13799              : 
   13800              :   /* Replace the anonymous decl with the real decl.  Be careful not to
   13801              :      rename other typedefs (such as the self-reference) of type.  */
   13802       383921 :   tree orig = TYPE_NAME (type);
   13803      1150034 :   for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   13804       766113 :     if (TYPE_NAME (t) == orig)
   13805       383921 :       TYPE_NAME (t) = decl;
   13806              : 
   13807              :   /* If this is a typedef within a template class, the nested
   13808              :      type is a (non-primary) template.  The name for the
   13809              :      template needs updating as well.  */
   13810       383921 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   13811           64 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   13812              : 
   13813              :   /* Adjust linkage now that we aren't unnamed anymore.  */
   13814       383921 :   reset_type_linkage (type);
   13815              : 
   13816       383921 :   if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
   13817       382133 :     maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
   13818              : 
   13819              :   /* FIXME remangle member functions; member functions of a
   13820              :      type with external linkage have external linkage.  */
   13821              : 
   13822              :   /* Check that our job is done, and that it would fail if we
   13823              :      attempted to do it again.  */
   13824       767842 :   gcc_assert (!TYPE_UNNAMED_P (type)
   13825              :               && !enum_with_enumerator_for_linkage_p (type));
   13826       383921 : }
   13827              : 
   13828              : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   13829              :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   13830              :    there was a problem, false otherwise.  */
   13831              : 
   13832              : static bool
   13833    617673346 : check_decltype_auto (location_t loc, tree type)
   13834              : {
   13835    617673346 :   if (tree a = type_uses_auto (type))
   13836              :     {
   13837     17282198 :       if (AUTO_IS_DECLTYPE (a))
   13838              :         {
   13839       586992 :           if (a != type)
   13840              :             {
   13841           33 :               error_at (loc, "%qT as type rather than plain "
   13842              :                         "%<decltype(auto)%>", type);
   13843           33 :               return true;
   13844              :             }
   13845       586959 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   13846              :             {
   13847           37 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   13848           37 :               return true;
   13849              :             }
   13850              :         }
   13851              :     }
   13852              :   return false;
   13853              : }
   13854              : 
   13855              : /* Issue an error about two mutually incompatible declspecs
   13856              :    with the given names and locations
   13857              :    e.g. "error: `signed' and `unsigned' specified together" */
   13858              : 
   13859              : static void
   13860           66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   13861              :                                        const char *name_b, location_t loc_b)
   13862              : {
   13863           66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   13864           66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   13865              :                      nullptr, highlight_colors::rhs);
   13866           66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   13867           66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   13868           66 :   error_at (&richloc, "%e and %e specified together",
   13869              :             &e_name_a, &e_name_b);
   13870           66 : }
   13871              : 
   13872              : /* Given declspecs and a declarator (abstract or otherwise), determine
   13873              :    the name and type of the object declared and construct a DECL node
   13874              :    for it.
   13875              : 
   13876              :    DECLSPECS points to the representation of declaration-specifier
   13877              :    sequence that precedes declarator.
   13878              : 
   13879              :    DECL_CONTEXT says which syntactic context this declaration is in:
   13880              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   13881              :      FUNCDEF for a function definition.  Like NORMAL but a few different
   13882              :       error messages in each case.  Return value may be zero meaning
   13883              :       this definition is too screwy to try to parse.
   13884              :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   13885              :       handle member functions (which have FIELD context).
   13886              :       Return value may be zero meaning this definition is too screwy to
   13887              :       try to parse.
   13888              :      PARM for a parameter declaration (either within a function prototype
   13889              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   13890              :      TPARM for a template parameter declaration.
   13891              :      CATCHPARM for a parameter declaration before a catch clause.
   13892              :      TYPENAME if for a typename (in a cast or sizeof).
   13893              :       Don't make a DECL node; just return the ..._TYPE node.
   13894              :      FIELD for a struct or union field; make a FIELD_DECL.
   13895              :      BITFIELD for a field with specified width.
   13896              : 
   13897              :    INITIALIZED is as for start_decl.
   13898              : 
   13899              :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   13900              :    if there are none; *ATTRLIST may be modified if attributes from inside
   13901              :    the declarator should be applied to the declaration.
   13902              : 
   13903              :    When this function is called, scoping variables (such as
   13904              :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   13905              :    declaration occurs, not the scope in which the new declaration will
   13906              :    be placed.  For example, on:
   13907              : 
   13908              :      void S::f() { ... }
   13909              : 
   13910              :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   13911              :    should not be `S'.
   13912              : 
   13913              :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   13914              :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   13915              :    error occurs. */
   13916              : 
   13917              : tree
   13918   1011991480 : grokdeclarator (const cp_declarator *declarator,
   13919              :                 cp_decl_specifier_seq *declspecs,
   13920              :                 enum decl_context decl_context,
   13921              :                 int initialized,
   13922              :                 tree* attrlist)
   13923              : {
   13924   1011991480 :   tree type = NULL_TREE;
   13925   1011991480 :   int longlong = 0;
   13926   1011991480 :   int explicit_intN = 0;
   13927   1011991480 :   int int_n_alt = 0;
   13928   1011991480 :   int virtualp, explicitp, friendp, inlinep, staticp;
   13929   1011991480 :   int explicit_int = 0;
   13930   1011991480 :   int explicit_char = 0;
   13931   1011991480 :   int defaulted_int = 0;
   13932              : 
   13933   1011991480 :   tree typedef_decl = NULL_TREE;
   13934   1011991480 :   const char *name = NULL;
   13935   1011991480 :   tree typedef_type = NULL_TREE;
   13936              :   /* True if this declarator is a function definition.  */
   13937   1011991480 :   bool funcdef_flag = false;
   13938   1011991480 :   cp_declarator_kind innermost_code = cdk_error;
   13939   1011991480 :   int bitfield = 0;
   13940              : #if 0
   13941              :   /* See the code below that used this.  */
   13942              :   tree decl_attr = NULL_TREE;
   13943              : #endif
   13944              : 
   13945              :   /* Keep track of what sort of function is being processed
   13946              :      so that we can warn about default return values, or explicit
   13947              :      return values which do not match prescribed defaults.  */
   13948   1011991480 :   special_function_kind sfk = sfk_none;
   13949              : 
   13950   1011991480 :   tree dname = NULL_TREE;
   13951   1011991480 :   tree ctor_return_type = NULL_TREE;
   13952   1011991480 :   enum overload_flags flags = NO_SPECIAL;
   13953              :   /* cv-qualifiers that apply to the declarator, for a declaration of
   13954              :      a member function.  */
   13955   1011991480 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   13956              :   /* virt-specifiers that apply to the declarator, for a declaration of
   13957              :      a member function.  */
   13958   1011991480 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   13959              :   /* ref-qualifier that applies to the declarator, for a declaration of
   13960              :      a member function.  */
   13961   1011991480 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   13962              :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   13963   1011991480 :   int type_quals = get_type_quals (declspecs);
   13964   1011991480 :   tree raises = NULL_TREE;
   13965   1011991480 :   int template_count = 0;
   13966   1011991480 :   tree returned_attrs = NULL_TREE;
   13967   1011991480 :   tree contract_specifiers = NULL_TREE;
   13968   1011991480 :   tree parms = NULL_TREE;
   13969   1011991480 :   const cp_declarator *id_declarator;
   13970              :   /* The unqualified name of the declarator; either an
   13971              :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   13972   1011991480 :   tree unqualified_id;
   13973              :   /* The class type, if any, in which this entity is located,
   13974              :      or NULL_TREE if none.  Note that this value may be different from
   13975              :      the current class type; for example if an attempt is made to declare
   13976              :      "A::f" inside "B", this value will be "A".  */
   13977   1011991480 :   tree ctype = current_class_type;
   13978              :   /* The NAMESPACE_DECL for the namespace in which this entity is
   13979              :      located.  If an unqualified name is used to declare the entity,
   13980              :      this value will be NULL_TREE, even if the entity is located at
   13981              :      namespace scope.  */
   13982   1011991480 :   tree in_namespace = NULL_TREE;
   13983   1011991480 :   cp_storage_class storage_class;
   13984   1011991480 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   13985   1011991480 :   bool type_was_error_mark_node = false;
   13986   1011991480 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   13987   1011991480 :   bool template_type_arg = false;
   13988   1011991480 :   bool template_parm_flag = false;
   13989   1011991480 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   13990   1011991480 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   13991   1011991480 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   13992   1011991480 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   13993   1011991480 :   bool late_return_type_p = false;
   13994   1011991480 :   bool array_parameter_p = false;
   13995   1011991480 :   tree reqs = NULL_TREE;
   13996              : 
   13997   1011991480 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   13998   1011991480 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   13999   1011991480 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   14000   1011991480 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   14001   1011991480 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   14002   1011991480 :   explicit_intN = declspecs->explicit_intN_p;
   14003   1011991480 :   int_n_alt = declspecs->int_n_alt;
   14004   1011991480 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   14005              : 
   14006              :   // Was concept_p specified? Note that ds_concept
   14007              :   // implies ds_constexpr!
   14008   1011991480 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   14009   1011991480 :   if (concept_p)
   14010          117 :     constexpr_p = true;
   14011              : 
   14012   1011991480 :   if (decl_context == FUNCDEF)
   14013              :     funcdef_flag = true, decl_context = NORMAL;
   14014              :   else if (decl_context == MEMFUNCDEF)
   14015              :     funcdef_flag = true, decl_context = FIELD;
   14016              :   else if (decl_context == BITFIELD)
   14017              :     bitfield = 1, decl_context = FIELD;
   14018              :   else if (decl_context == TEMPLATE_TYPE_ARG)
   14019              :     template_type_arg = true, decl_context = TYPENAME;
   14020              :   else if (decl_context == TPARM)
   14021     10674706 :     template_parm_flag = true, decl_context = PARM;
   14022              : 
   14023   1011991480 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   14024     10688794 :     funcdef_flag = true;
   14025              : 
   14026   1011991480 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   14027              :                                               (type_quals,
   14028   1011991480 :                                                declspecs->locations));
   14029   1011991480 :   location_t id_loc;
   14030   1011991480 :   location_t init_loc;
   14031   1011991480 :   if (declarator)
   14032              :     {
   14033    611694363 :       id_loc = loc_or_input_loc (declarator->id_loc);
   14034    611694363 :       init_loc = loc_or_input_loc (declarator->init_loc);
   14035              :     }
   14036              :   else
   14037    400297117 :     init_loc = id_loc = input_location;
   14038              : 
   14039              :   /* Look inside a declarator for the name being declared
   14040              :      and get it as a string, for an error message.  */
   14041   1011991480 :   for (id_declarator = declarator;
   14042   1390774505 :        id_declarator;
   14043    378783025 :        id_declarator = id_declarator->declarator)
   14044              :     {
   14045    950232941 :       if (id_declarator->kind != cdk_id)
   14046    378783050 :         innermost_code = id_declarator->kind;
   14047              : 
   14048    950232941 :       switch (id_declarator->kind)
   14049              :         {
   14050    186178445 :         case cdk_function:
   14051    186178445 :           if (id_declarator->declarator
   14052    185816277 :               && id_declarator->declarator->kind == cdk_id)
   14053              :             {
   14054    183995592 :               sfk = id_declarator->declarator->u.id.sfk;
   14055    183995592 :               if (sfk == sfk_destructor)
   14056      3185022 :                 flags = DTOR_FLAG;
   14057              :             }
   14058              :           break;
   14059              : 
   14060    571449891 :         case cdk_id:
   14061    571449891 :           {
   14062    571449891 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   14063    571449891 :             tree decl = id_declarator->u.id.unqualified_name;
   14064    571449891 :             if (!decl)
   14065              :               break;
   14066    571449891 :             if (qualifying_scope)
   14067              :               {
   14068      9496660 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   14069      9496660 :                                                     id_declarator->id_loc))
   14070            6 :                   return error_mark_node;
   14071      9496654 :                 if (at_function_scope_p ())
   14072              :                   {
   14073              :                     /* [dcl.meaning]
   14074              : 
   14075              :                        A declarator-id shall not be qualified except
   14076              :                        for ...
   14077              : 
   14078              :                        None of the cases are permitted in block
   14079              :                        scope.  */
   14080            0 :                     if (qualifying_scope == global_namespace)
   14081            0 :                       error ("invalid use of qualified-name %<::%D%>",
   14082              :                              decl);
   14083            0 :                     else if (TYPE_P (qualifying_scope))
   14084            0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   14085              :                              qualifying_scope, decl);
   14086              :                     else
   14087            0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   14088              :                              qualifying_scope, decl);
   14089            0 :                     return error_mark_node;
   14090              :                   }
   14091      9496654 :                 else if (TYPE_P (qualifying_scope))
   14092              :                   {
   14093      9263500 :                     ctype = qualifying_scope;
   14094      9263500 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   14095              :                       {
   14096            6 :                         error_at (id_declarator->id_loc,
   14097              :                                   "%q#T is not a class or namespace", ctype);
   14098            6 :                         ctype = NULL_TREE;
   14099              :                       }
   14100      9263494 :                     else if (innermost_code != cdk_function
   14101       483127 :                              && current_class_type
   14102      9263509 :                              && !uniquely_derived_from_p (ctype,
   14103              :                                                           current_class_type))
   14104              :                       {
   14105            9 :                         error_at (id_declarator->id_loc,
   14106              :                                   "invalid use of qualified-name %<%T::%D%>",
   14107              :                                   qualifying_scope, decl);
   14108            9 :                         return error_mark_node;
   14109              :                       }
   14110              :                   }
   14111       233154 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   14112    571449876 :                   in_namespace = qualifying_scope;
   14113              :               }
   14114    571449876 :             switch (TREE_CODE (decl))
   14115              :               {
   14116      3185037 :               case BIT_NOT_EXPR:
   14117      3185037 :                 {
   14118      3185037 :                   if (innermost_code != cdk_function)
   14119              :                     {
   14120            6 :                       error_at (EXPR_LOCATION (decl),
   14121              :                                 "declaration of %qE as non-function", decl);
   14122            6 :                       return error_mark_node;
   14123              :                     }
   14124      3185031 :                   else if (!qualifying_scope
   14125      3185031 :                            && !(current_class_type && at_class_scope_p ()))
   14126              :                     {
   14127            9 :                       error_at (EXPR_LOCATION (decl),
   14128              :                                 "declaration of %qE as non-member", decl);
   14129            9 :                       return error_mark_node;
   14130              :                     }
   14131              : 
   14132      3185022 :                   tree type = TREE_OPERAND (decl, 0);
   14133      3185022 :                   if (TYPE_P (type))
   14134      3185019 :                     type = constructor_name (type);
   14135      3185022 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   14136      3185022 :                   dname = decl;
   14137              :                 }
   14138      3185022 :                 break;
   14139              : 
   14140      2664857 :               case TEMPLATE_ID_EXPR:
   14141      2664857 :                 {
   14142      2664857 :                   tree fns = TREE_OPERAND (decl, 0);
   14143              : 
   14144      2664857 :                   dname = fns;
   14145      3581112 :                   if (!identifier_p (dname))
   14146      2664833 :                     dname = OVL_NAME (dname);
   14147              :                 }
   14148              :                 /* Fall through.  */
   14149              : 
   14150    568264839 :               case IDENTIFIER_NODE:
   14151    568264839 :                 if (identifier_p (decl))
   14152    565599982 :                   dname = decl;
   14153              : 
   14154    568264839 :                 if (IDENTIFIER_KEYWORD_P (dname))
   14155              :                   {
   14156            0 :                     error ("declarator-id missing; using reserved word %qD",
   14157              :                            dname);
   14158            0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14159              :                   }
   14160    568264839 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   14161    567274097 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14162              :                 else
   14163              :                   {
   14164       990742 :                     gcc_assert (flags == NO_SPECIAL);
   14165       990742 :                     flags = TYPENAME_FLAG;
   14166       990742 :                     sfk = sfk_conversion;
   14167       990742 :                     tree glob = get_global_binding (dname);
   14168       990742 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   14169            0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14170              :                     else
   14171              :                       name = "<invalid operator>";
   14172              :                   }
   14173              :                 break;
   14174              : 
   14175            0 :               default:
   14176            0 :                 gcc_unreachable ();
   14177              :               }
   14178              :             break;
   14179              :           }
   14180              : 
   14181              :         case cdk_array:
   14182              :         case cdk_pointer:
   14183              :         case cdk_reference:
   14184              :         case cdk_ptrmem:
   14185              :           break;
   14186              : 
   14187              :         case cdk_decomp:
   14188    950232886 :           name = "structured binding";
   14189              :           break;
   14190              : 
   14191           25 :         case cdk_error:
   14192           25 :           return error_mark_node;
   14193              : 
   14194            0 :         default:
   14195            0 :           gcc_unreachable ();
   14196              :         }
   14197    950232886 :       if (id_declarator->kind == cdk_id)
   14198              :         break;
   14199              :     }
   14200              : 
   14201              :   /* [dcl.fct.edf]
   14202              : 
   14203              :      The declarator in a function-definition shall have the form
   14204              :      D1 ( parameter-declaration-clause) ...  */
   14205   1011991425 :   if (funcdef_flag && innermost_code != cdk_function)
   14206              :     {
   14207            3 :       error_at (id_loc, "function definition does not declare parameters");
   14208            3 :       return error_mark_node;
   14209              :     }
   14210              : 
   14211   1011991422 :   if (flags == TYPENAME_FLAG
   14212   1011991422 :       && innermost_code != cdk_function
   14213            3 :       && ! (ctype && !declspecs->any_specifiers_p))
   14214              :     {
   14215            3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   14216            3 :       return error_mark_node;
   14217              :     }
   14218              : 
   14219   1011991419 :   if (dname && identifier_p (dname))
   14220              :     {
   14221    568264833 :       if (UDLIT_OPER_P (dname)
   14222    568264833 :           && innermost_code != cdk_function)
   14223              :         {
   14224            6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   14225            6 :           return error_mark_node;
   14226              :         }
   14227              : 
   14228    568264827 :       if (IDENTIFIER_ANY_OP_P (dname))
   14229              :         {
   14230     36348560 :           if (typedef_p)
   14231              :             {
   14232            3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   14233            3 :               return error_mark_node;
   14234              :             }
   14235     36348557 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14236              :             {
   14237           15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   14238           15 :               return error_mark_node;
   14239              :             }
   14240              :         }
   14241              :     }
   14242              : 
   14243              :   /* Anything declared one level down from the top level
   14244              :      must be one of the parameters of a function
   14245              :      (because the body is at least two levels down).  */
   14246              : 
   14247              :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   14248              :      by not allowing C++ class definitions to specify their parameters
   14249              :      with xdecls (must be spec.d in the parmlist).
   14250              : 
   14251              :      Since we now wait to push a class scope until we are sure that
   14252              :      we are in a legitimate method context, we must set oldcname
   14253              :      explicitly (since current_class_name is not yet alive).
   14254              : 
   14255              :      We also want to avoid calling this a PARM if it is in a namespace.  */
   14256              : 
   14257   1011991395 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   14258              :     {
   14259     70432663 :       cp_binding_level *b = current_binding_level;
   14260     70432663 :       current_binding_level = b->level_chain;
   14261     70432663 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   14262              :         decl_context = PARM;
   14263     70432663 :       current_binding_level = b;
   14264              :     }
   14265              : 
   14266   1011991395 :   if (name == NULL)
   14267    440317628 :     name = decl_context == PARM ? "parameter" : "type name";
   14268              : 
   14269   1011991395 :   if (consteval_p && constexpr_p)
   14270              :     {
   14271            6 :       error_at (declspecs->locations[ds_consteval],
   14272              :                 "both %qs and %qs specified", "constexpr", "consteval");
   14273            6 :       return error_mark_node;
   14274              :     }
   14275              : 
   14276   1011991389 :   if (concept_p && typedef_p)
   14277              :     {
   14278            9 :       error_at (declspecs->locations[ds_concept],
   14279              :                 "%qs cannot appear in a typedef declaration", "concept");
   14280            9 :       return error_mark_node;
   14281              :     }
   14282              : 
   14283   1011991380 :   if (constexpr_p && typedef_p)
   14284              :     {
   14285            3 :       error_at (declspecs->locations[ds_constexpr],
   14286              :                 "%qs cannot appear in a typedef declaration", "constexpr");
   14287            3 :       return error_mark_node;
   14288              :     }
   14289              : 
   14290   1011991377 :   if (consteval_p && typedef_p)
   14291              :     {
   14292            3 :       error_at (declspecs->locations[ds_consteval],
   14293              :                 "%qs cannot appear in a typedef declaration", "consteval");
   14294            3 :       return error_mark_node;
   14295              :     }
   14296              : 
   14297   1011991374 :   if (constinit_p && typedef_p)
   14298              :     {
   14299            3 :       error_at (declspecs->locations[ds_constinit],
   14300              :                 "%qs cannot appear in a typedef declaration", "constinit");
   14301            3 :       return error_mark_node;
   14302              :     }
   14303              : 
   14304              :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   14305              :      keywords shall appear in a decl-specifier-seq."  */
   14306   1011991371 :   if (constinit_p && constexpr_p)
   14307              :     {
   14308            6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   14309            6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   14310            6 :       error_at (&richloc,
   14311              :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   14312              :                 "specifiers");
   14313            6 :       return error_mark_node;
   14314            6 :     }
   14315              : 
   14316              :   /* If there were multiple types specified in the decl-specifier-seq,
   14317              :      issue an error message.  */
   14318   1011991365 :   if (declspecs->multiple_types_p)
   14319              :     {
   14320         1501 :       error_at (typespec_loc,
   14321              :                 "two or more data types in declaration of %qs", name);
   14322         1501 :       return error_mark_node;
   14323              :     }
   14324              : 
   14325   1011989864 :   if (declspecs->conflicting_specifiers_p)
   14326           31 :     return error_mark_node;
   14327              : 
   14328              :   /* Extract the basic type from the decl-specifier-seq.  */
   14329   1011989833 :   type = declspecs->type;
   14330   1011989833 :   if (type == error_mark_node)
   14331              :     {
   14332         1188 :       type = NULL_TREE;
   14333         1188 :       type_was_error_mark_node = true;
   14334              :     }
   14335              : 
   14336              :   /* Ignore erroneous attributes.  */
   14337   1011989833 :   if (attrlist && *attrlist == error_mark_node)
   14338           12 :     *attrlist = NULL_TREE;
   14339              : 
   14340              :   /* An object declared as __attribute__((unavailable)) suppresses
   14341              :      any reports of being declared with unavailable or deprecated
   14342              :      items.  An object declared as __attribute__((deprecated))
   14343              :      suppresses warnings of uses of other deprecated items.  */
   14344   1011989833 :   auto ds = make_temp_override (deprecated_state);
   14345   1011989833 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   14346          171 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   14347   1011989662 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   14348       777762 :     deprecated_state = DEPRECATED_SUPPRESS;
   14349              : 
   14350   1011989833 :   cp_handle_deprecated_or_unavailable (type);
   14351   1011989833 :   if (type && TREE_CODE (type) == TYPE_DECL)
   14352              :     {
   14353    703951140 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   14354    703951140 :       typedef_decl = type;
   14355    703951140 :       type = TREE_TYPE (typedef_decl);
   14356    703951140 :       if (DECL_ARTIFICIAL (typedef_decl))
   14357    511792290 :         cp_handle_deprecated_or_unavailable (type);
   14358              :     }
   14359              :   /* No type at all: default to `int', and set DEFAULTED_INT
   14360              :      because it was not a user-defined typedef.  */
   14361   1011989833 :   if (type == NULL_TREE)
   14362              :     {
   14363     37798037 :       if (signed_p || unsigned_p || long_p || short_p)
   14364              :         {
   14365              :           /* These imply 'int'.  */
   14366      8873894 :           type = integer_type_node;
   14367      8873894 :           defaulted_int = 1;
   14368              :         }
   14369              :       /* If we just have "complex", it is equivalent to "complex double".  */
   14370     28924143 :       else if (!longlong && !explicit_intN
   14371     28924143 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14372              :         {
   14373           81 :           type = double_type_node;
   14374           81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   14375              :                    "ISO C++ does not support plain %<complex%> meaning "
   14376              :                    "%<double complex%>");
   14377              :         }
   14378              :     }
   14379              :   /* Gather flags.  */
   14380   1011989833 :   explicit_int = declspecs->explicit_int_p;
   14381   1011989833 :   explicit_char = declspecs->explicit_char_p;
   14382              : 
   14383              : #if 0
   14384              :   /* See the code below that used this.  */
   14385              :   if (typedef_decl)
   14386              :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   14387              : #endif
   14388   1011989833 :   typedef_type = type;
   14389              : 
   14390   1011989833 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   14391      2157395 :     ctor_return_type = TREE_TYPE (dname);
   14392              :   else
   14393              :     ctor_return_type = ctype;
   14394              : 
   14395   1011989833 :   if (sfk != sfk_none)
   14396              :     {
   14397     28922555 :       type = check_special_function_return_type (sfk, type,
   14398              :                                                  ctor_return_type,
   14399              :                                                  type_quals,
   14400              :                                                  &declarator,
   14401              :                                                  declspecs->locations);
   14402     28922555 :       type_quals = TYPE_UNQUALIFIED;
   14403              :     }
   14404    983067278 :   else if (type == NULL_TREE)
   14405              :     {
   14406         1588 :       int is_main;
   14407              : 
   14408         1588 :       explicit_int = -1;
   14409              : 
   14410              :       /* We handle `main' specially here, because 'main () { }' is so
   14411              :          common.  With no options, it is allowed.  With -Wreturn-type,
   14412              :          it is a warning.  It is only an error with -pedantic-errors.  */
   14413         3176 :       is_main = (funcdef_flag
   14414         3410 :                  && dname && identifier_p (dname)
   14415          234 :                  && MAIN_NAME_P (dname)
   14416           68 :                  && ctype == NULL_TREE
   14417           68 :                  && in_namespace == NULL_TREE
   14418         1656 :                  && current_namespace == global_namespace);
   14419              : 
   14420         1588 :       if (type_was_error_mark_node)
   14421              :         /* We've already issued an error, don't complain more.  */;
   14422          400 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   14423              :         /* Allow it, sigh.  */;
   14424          338 :       else if (! is_main)
   14425          276 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   14426              :                    name);
   14427           62 :       else if (pedantic)
   14428            4 :         pedwarn (id_loc, OPT_Wpedantic,
   14429              :                  "ISO C++ forbids declaration of %qs with no type", name);
   14430              :       else
   14431           58 :         warning_at (id_loc, OPT_Wreturn_type,
   14432              :                     "ISO C++ forbids declaration of %qs with no type", name);
   14433              : 
   14434         1588 :       if (type_was_error_mark_node && template_parm_flag)
   14435              :         /* FIXME we should be able to propagate the error_mark_node as is
   14436              :            for other contexts too.  */
   14437          149 :         type = error_mark_node;
   14438              :       else
   14439         1439 :         type = integer_type_node;
   14440              :     }
   14441              : 
   14442   1011989833 :   ctype = NULL_TREE;
   14443              : 
   14444   1011989833 :   if (explicit_intN)
   14445              :     {
   14446      1069715 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   14447              :         {
   14448            0 :           error_at (declspecs->locations[ds_type_spec],
   14449              :                     "%<__int%d%> is not supported by this target",
   14450            0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   14451            0 :           explicit_intN = false;
   14452              :         }
   14453              :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   14454              :          of "__intN".  */
   14455      1069715 :       else if (!int_n_alt && pedantic)
   14456         6449 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   14457              :                  "ISO C++ does not support %<__int%d%> for %qs",
   14458         6449 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   14459              :     }
   14460              : 
   14461              :   /* Now process the modifiers that were specified
   14462              :      and check for invalid combinations.  */
   14463              : 
   14464              :   /* Long double is a special combination.  */
   14465   1011989833 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   14466              :     {
   14467      8643463 :       long_p = false;
   14468      8643463 :       type = cp_build_qualified_type (long_double_type_node,
   14469              :                                       cp_type_quals (type));
   14470              :     }
   14471              : 
   14472              :   /* Check all other uses of type modifiers.  */
   14473              : 
   14474   1011989833 :   if (unsigned_p || signed_p || long_p || short_p)
   14475              :     {
   14476     20575023 :       location_t loc;
   14477     20575023 :       const char *key;
   14478     20575023 :       if (unsigned_p)
   14479              :         {
   14480     13969321 :           key = "unsigned";
   14481     13969321 :           loc = declspecs->locations[ds_unsigned];
   14482              :         }
   14483      6605702 :       else if (signed_p)
   14484              :         {
   14485      1014522 :           key = "signed";
   14486      1014522 :           loc = declspecs->locations[ds_signed];
   14487              :         }
   14488      5591180 :       else if (longlong)
   14489              :         {
   14490      2179478 :           key = "long long";
   14491      2179478 :           loc = declspecs->locations[ds_long_long];
   14492              :         }
   14493      3411702 :       else if (long_p)
   14494              :         {
   14495      2870008 :           key = "long";
   14496      2870008 :           loc = declspecs->locations[ds_long];
   14497              :         }
   14498              :       else /* if (short_p) */
   14499              :         {
   14500       541694 :           key = "short";
   14501       541694 :           loc = declspecs->locations[ds_short];
   14502              :         }
   14503              : 
   14504     20575023 :       int ok = 0;
   14505              : 
   14506     20575023 :       if (signed_p && unsigned_p)
   14507           54 :         complain_about_incompatible_declspecs
   14508           54 :           ("signed", declspecs->locations[ds_signed],
   14509              :            "unsigned", declspecs->locations[ds_unsigned]);
   14510     20574969 :       else if (long_p && short_p)
   14511           12 :         complain_about_incompatible_declspecs
   14512           12 :           ("long", declspecs->locations[ds_long],
   14513              :            "short", declspecs->locations[ds_short]);
   14514     20574957 :       else if (TREE_CODE (type) != INTEGER_TYPE
   14515     20574944 :                || type == char8_type_node
   14516     20574920 :                || type == char16_type_node
   14517     20574896 :                || type == char32_type_node
   14518     20574872 :                || ((long_p || short_p)
   14519     10780190 :                    && (explicit_char || explicit_intN)))
   14520          418 :         error_at (loc, "%qs specified with %qT", key, type);
   14521     20574539 :       else if (!explicit_int && !defaulted_int
   14522     20574539 :                && !explicit_char && !explicit_intN)
   14523              :         {
   14524           30 :           if (typedef_decl)
   14525              :             {
   14526           27 :               pedwarn (loc, OPT_Wpedantic,
   14527              :                        "%qs specified with typedef-name %qD",
   14528              :                        key, typedef_decl);
   14529           27 :               ok = !flag_pedantic_errors;
   14530              :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   14531              :                  and is not built as a typedef.  */
   14532           27 :               if (is_typedef_decl (typedef_decl))
   14533           18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   14534              :             }
   14535            3 :           else if (declspecs->decltype_p)
   14536            0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   14537              :           else
   14538            3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   14539              :         }
   14540              :       else
   14541              :         ok = 1;
   14542              : 
   14543              :       /* Discard the type modifiers if they are invalid.  */
   14544          514 :       if (! ok)
   14545              :         {
   14546              :           unsigned_p = false;
   14547              :           signed_p = false;
   14548              :           long_p = false;
   14549              :           short_p = false;
   14550              :           longlong = 0;
   14551              :         }
   14552              :     }
   14553              : 
   14554              :   /* Decide whether an integer type is signed or not.
   14555              :      Optionally treat bitfields as signed by default.  */
   14556   1011989343 :   if (unsigned_p
   14557              :       /* [class.bit]
   14558              : 
   14559              :          It is implementation-defined whether a plain (neither
   14560              :          explicitly signed or unsigned) char, short, int, or long
   14561              :          bit-field is signed or unsigned.
   14562              : 
   14563              :          Naturally, we extend this to long long as well.  Note that
   14564              :          this does not include wchar_t.  */
   14565   1011989833 :       || (bitfield && !flag_signed_bitfields
   14566           18 :           && !signed_p
   14567              :           /* A typedef for plain `int' without `signed' can be
   14568              :              controlled just like plain `int', but a typedef for
   14569              :              `signed int' cannot be so controlled.  */
   14570           18 :           && !(typedef_decl
   14571           18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   14572           13 :           && TREE_CODE (type) == INTEGER_TYPE
   14573           10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   14574              :     {
   14575     13969106 :       if (explicit_intN)
   14576       505808 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   14577     13463298 :       else if (longlong)
   14578      1369212 :         type = long_long_unsigned_type_node;
   14579     12094086 :       else if (long_p)
   14580      2246404 :         type = long_unsigned_type_node;
   14581      9847682 :       else if (short_p)
   14582      1371173 :         type = short_unsigned_type_node;
   14583      8476509 :       else if (type == char_type_node)
   14584      1855441 :         type = unsigned_char_type_node;
   14585      6621068 :       else if (typedef_decl)
   14586           25 :         type = c_common_unsigned_type (type);
   14587              :       else
   14588      6621043 :         type = unsigned_type_node;
   14589              :     }
   14590    998020727 :   else if (signed_p && type == char_type_node)
   14591       671657 :     type = signed_char_type_node;
   14592    997349070 :   else if (explicit_intN)
   14593       563907 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   14594    996785163 :   else if (longlong)
   14595      2240752 :     type = long_long_integer_type_node;
   14596    994544411 :   else if (long_p)
   14597      2935121 :     type = long_integer_type_node;
   14598    991609290 :   else if (short_p)
   14599       617195 :     type = short_integer_type_node;
   14600    990992095 :   else if (signed_p && typedef_decl)
   14601            9 :     type = c_common_signed_type (type);
   14602              : 
   14603   1011989833 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14604              :     {
   14605      1162613 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   14606            3 :         error_at (declspecs->locations[ds_complex],
   14607              :                   "complex invalid for %qs", name);
   14608              :       /* If a modifier is specified, the resulting complex is the complex
   14609              :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   14610      1162610 :       else if (type == integer_type_node)
   14611          171 :         type = complex_integer_type_node;
   14612      1162439 :       else if (type == float_type_node)
   14613       334205 :         type = complex_float_type_node;
   14614       828234 :       else if (type == double_type_node)
   14615       334742 :         type = complex_double_type_node;
   14616       493492 :       else if (type == long_double_type_node)
   14617       334246 :         type = complex_long_double_type_node;
   14618              :       else
   14619       159246 :         type = build_complex_type (type);
   14620              :     }
   14621              : 
   14622              :   /* If we're using the injected-class-name to form a compound type or a
   14623              :      declaration, replace it with the underlying class so we don't get
   14624              :      redundant typedefs in the debug output.  But if we are returning the
   14625              :      type unchanged, leave it alone so that it's available to
   14626              :      maybe_get_template_decl_from_type_decl.  */
   14627    199201914 :   if (CLASS_TYPE_P (type)
   14628    199139946 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   14629     33838054 :       && type == TREE_TYPE (TYPE_NAME (type))
   14630   1045827887 :       && (declarator || type_quals))
   14631     32405356 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   14632              : 
   14633   1011989833 :   type_quals |= cp_type_quals (type);
   14634   2023979666 :   type = cp_build_qualified_type
   14635   2023979666 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   14636    819830983 :                           || declspecs->decltype_p)
   14637              :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   14638              :   /* We might have ignored or rejected some of the qualifiers.  */
   14639   1011989833 :   type_quals = cp_type_quals (type);
   14640              : 
   14641    996654382 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   14642     22113670 :       && innermost_code != cdk_function
   14643              :       /* Placeholder in parm gets a better error below.  */
   14644     13639101 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   14645   1025598594 :       && id_declarator && declarator != id_declarator)
   14646      1126709 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   14647              :       {
   14648           16 :         auto_diagnostic_group g;
   14649           16 :         gcc_rich_location richloc (typespec_loc);
   14650           16 :         richloc.add_fixit_insert_after ("<>");
   14651           16 :         error_at (&richloc, "missing template argument list after %qE; "
   14652              :                   "for deduction, template placeholder must be followed "
   14653              :                   "by a simple declarator-id", tmpl);
   14654           16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   14655           16 :         type = error_mark_node;
   14656           16 :       }
   14657              : 
   14658   1011989833 :   staticp = 0;
   14659   1011989833 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   14660   1011989833 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   14661   1011989833 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   14662              : 
   14663   1011989833 :   storage_class = declspecs->storage_class;
   14664   1011989833 :   if (storage_class == sc_static)
   14665     22936256 :     staticp = 1 + (decl_context == FIELD);
   14666    989053577 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   14667              :     /* Treat class-scope deduction guides as static member functions
   14668              :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   14669     22618508 :     staticp = 2;
   14670              : 
   14671   1011989833 :   if (virtualp)
   14672              :     {
   14673      4060569 :       if (staticp == 2)
   14674              :         {
   14675           21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14676           21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   14677           21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   14678              :                     "and %<static%>", dname);
   14679           21 :           storage_class = sc_none;
   14680           21 :           staticp = 0;
   14681           21 :         }
   14682      4060569 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   14683              :         {
   14684            6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14685            6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   14686            6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   14687              :                    "declared both %<virtual%> and %<constexpr%> only in "
   14688              :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   14689            6 :         }
   14690              :     }
   14691   1011989833 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   14692              : 
   14693              :   /* Issue errors about use of storage classes for parameters.  */
   14694   1011989833 :   if (decl_context == PARM)
   14695              :     {
   14696    286883416 :       if (typedef_p)
   14697              :         {
   14698           24 :           error_at (declspecs->locations[ds_typedef],
   14699              :                     "typedef declaration invalid in parameter declaration");
   14700           24 :           return error_mark_node;
   14701              :         }
   14702    286883392 :       else if (template_parm_flag && storage_class != sc_none)
   14703              :         {
   14704           16 :           error_at (min_location (declspecs->locations[ds_thread],
   14705              :                                   declspecs->locations[ds_storage_class]),
   14706              :                     "storage class specified for template parameter %qs",
   14707              :                     name);
   14708           16 :           return error_mark_node;
   14709              :         }
   14710    286883376 :       else if (storage_class == sc_static
   14711    286883376 :                || storage_class == sc_extern
   14712    286883373 :                || thread_p)
   14713              :         {
   14714            9 :           error_at (min_location (declspecs->locations[ds_thread],
   14715              :                                   declspecs->locations[ds_storage_class]),
   14716              :                     "storage class specified for parameter %qs", name);
   14717            9 :           return error_mark_node;
   14718              :         }
   14719              : 
   14720              :       /* Function parameters cannot be concept. */
   14721    286883367 :       if (concept_p)
   14722              :         {
   14723            9 :           error_at (declspecs->locations[ds_concept],
   14724              :                     "a parameter cannot be declared %qs", "concept");
   14725            9 :           concept_p = 0;
   14726            9 :           constexpr_p = 0;
   14727              :         }
   14728              :       /* Function parameters cannot be constexpr.  If we saw one, moan
   14729              :          and pretend it wasn't there.  */
   14730    286883358 :       else if (constexpr_p)
   14731              :         {
   14732            9 :           error_at (declspecs->locations[ds_constexpr],
   14733              :                     "a parameter cannot be declared %qs", "constexpr");
   14734            9 :           constexpr_p = 0;
   14735              :         }
   14736    286883367 :       if (constinit_p)
   14737              :         {
   14738            6 :           error_at (declspecs->locations[ds_constinit],
   14739              :                     "a parameter cannot be declared %qs", "constinit");
   14740            6 :           constinit_p = 0;
   14741              :         }
   14742    286883367 :       if (consteval_p)
   14743              :         {
   14744            3 :           error_at (declspecs->locations[ds_consteval],
   14745              :                     "a parameter cannot be declared %qs", "consteval");
   14746            3 :           consteval_p = 0;
   14747              :         }
   14748              :     }
   14749              : 
   14750              :   /* Give error if `virtual' is used outside of class declaration.  */
   14751   1011989784 :   if (virtualp
   14752      4060569 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   14753              :     {
   14754           68 :       error_at (declspecs->locations[ds_virtual],
   14755              :                 "%<virtual%> outside class declaration");
   14756           68 :       virtualp = 0;
   14757              :     }
   14758              : 
   14759   1011989784 :   if (innermost_code == cdk_decomp)
   14760              :     {
   14761       214273 :       location_t loc = (declarator->kind == cdk_reference
   14762       223936 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   14763       223936 :       if (inlinep)
   14764           29 :         error_at (declspecs->locations[ds_inline],
   14765              :                   "structured binding declaration cannot be %qs", "inline");
   14766       223936 :       if (typedef_p)
   14767           29 :         error_at (declspecs->locations[ds_typedef],
   14768              :                   "structured binding declaration cannot be %qs", "typedef");
   14769       223936 :       if (constexpr_p && !concept_p && cxx_dialect < cxx26)
   14770           96 :         pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
   14771              :                  "structured binding declaration can be %qs only with "
   14772              :                  "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
   14773       223936 :       if (consteval_p)
   14774           13 :         error_at (declspecs->locations[ds_consteval], "structured "
   14775              :                   "binding declaration cannot be %qs", "consteval");
   14776       223936 :       if (thread_p && cxx_dialect < cxx20)
   14777           75 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   14778              :                  "structured binding declaration can be %qs only in "
   14779              :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   14780           75 :                  declspecs->gnu_thread_keyword_p
   14781              :                  ? "__thread" : "thread_local");
   14782       223936 :       if (concept_p)
   14783              :         {
   14784            0 :           error_at (declspecs->locations[ds_concept],
   14785              :                     "structured binding declaration cannot be %qs", "concept");
   14786            0 :           constexpr_p = 0;
   14787              :         }
   14788              :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   14789       223936 :       if (type_quals & TYPE_QUAL_VOLATILE)
   14790           26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   14791              :                     "%<volatile%>-qualified structured binding is deprecated");
   14792       223936 :       switch (storage_class)
   14793              :         {
   14794              :         case sc_none:
   14795              :           break;
   14796           28 :         case sc_register:
   14797           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   14798              :                     "register");
   14799           28 :           break;
   14800          244 :         case sc_static:
   14801          244 :           if (cxx_dialect < cxx20)
   14802          185 :             pedwarn (loc, OPT_Wc__20_extensions,
   14803              :                      "structured binding declaration can be %qs only in "
   14804              :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   14805              :           break;
   14806           29 :         case sc_extern:
   14807           29 :           error_at (loc, "structured binding declaration cannot be %qs",
   14808              :                     "extern");
   14809           29 :           break;
   14810           28 :         case sc_mutable:
   14811           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   14812              :                     "mutable");
   14813           28 :           break;
   14814            0 :         case sc_auto:
   14815            0 :           error_at (loc, "structured binding declaration cannot be "
   14816              :                     "C++98 %<auto%>");
   14817            0 :           break;
   14818            0 :         default:
   14819            0 :           gcc_unreachable ();
   14820              :         }
   14821       223936 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   14822       223936 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   14823              :         {
   14824            3 :           if (type != error_mark_node)
   14825              :             {
   14826            3 :               auto_diagnostic_group d;
   14827            3 :               error_at (loc, "structured binding declaration cannot have "
   14828              :                         "type %qT", type);
   14829            3 :               inform (loc,
   14830              :                       "type must be cv-qualified %<auto%> or reference to "
   14831              :                       "cv-qualified %<auto%>");
   14832            3 :             }
   14833            3 :           type = build_qualified_type (make_auto (), type_quals);
   14834            3 :           declspecs->type = type;
   14835              :         }
   14836       223933 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   14837           51 :         pedwarn (loc, OPT_Wpedantic,
   14838              :                  "structured binding declaration cannot have constrained "
   14839              :                  "%<auto%> type %qT", type);
   14840       223936 :       inlinep = 0;
   14841       223936 :       typedef_p = 0;
   14842       223936 :       consteval_p = 0;
   14843       223936 :       concept_p = 0;
   14844       223936 :       if (storage_class != sc_static)
   14845              :         {
   14846       223692 :           storage_class = sc_none;
   14847       223692 :           declspecs->storage_class = sc_none;
   14848              :         }
   14849              :     }
   14850              : 
   14851              :   /* Static anonymous unions are dealt with here.  */
   14852   1011989784 :   if (staticp && decl_context == TYPENAME
   14853            0 :       && declspecs->type
   14854   1011989784 :       && ANON_AGGR_TYPE_P (declspecs->type))
   14855              :     decl_context = FIELD;
   14856              : 
   14857              :   /* Warn about storage classes that are invalid for certain
   14858              :      kinds of declarations (parameters, typenames, etc.).  */
   14859   1011989784 :   if (thread_p
   14860        19766 :       && ((storage_class
   14861        19766 :            && storage_class != sc_extern
   14862          526 :            && storage_class != sc_static)
   14863        19755 :           || typedef_p))
   14864              :     {
   14865           17 :       location_t loc
   14866           17 :         = min_location (declspecs->locations[ds_thread],
   14867              :                         declspecs->locations[ds_storage_class]);
   14868           17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   14869           17 :       thread_p = false;
   14870              :     }
   14871   1011989784 :   if (decl_context != NORMAL
   14872    847624025 :       && ((storage_class != sc_none
   14873    847624025 :            && storage_class != sc_mutable)
   14874    825005530 :           || thread_p))
   14875              :     {
   14876     22618498 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   14877           36 :           && (storage_class == sc_register
   14878           36 :               || storage_class == sc_auto))
   14879              :         ;
   14880     22618462 :       else if (typedef_p)
   14881              :         ;
   14882     22618462 :       else if (decl_context == FIELD
   14883              :                /* C++ allows static class elements.  */
   14884     22618462 :                && storage_class == sc_static)
   14885              :         /* C++ also allows inlines and signed and unsigned elements,
   14886              :            but in those cases we don't come in here.  */
   14887              :         ;
   14888              :       else
   14889              :         {
   14890           15 :           location_t loc
   14891           15 :             = min_location (declspecs->locations[ds_thread],
   14892              :                             declspecs->locations[ds_storage_class]);
   14893           15 :           if (decl_context == FIELD)
   14894           15 :             error_at (loc, "storage class specified for %qs", name);
   14895            0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14896            0 :             error_at (loc, "storage class specified for parameter %qs", name);
   14897              :           else
   14898            0 :             error_at (loc, "storage class specified for typename");
   14899           15 :           if (storage_class == sc_register
   14900           15 :               || storage_class == sc_auto
   14901           15 :               || storage_class == sc_extern
   14902            3 :               || thread_p)
   14903           15 :             storage_class = sc_none;
   14904              :         }
   14905              :     }
   14906    989371286 :   else if (storage_class == sc_extern && funcdef_flag
   14907    989371286 :            && ! toplevel_bindings_p ())
   14908            0 :     error ("nested function %qs declared %<extern%>", name);
   14909    989371286 :   else if (toplevel_bindings_p ())
   14910              :     {
   14911    460524743 :       if (storage_class == sc_auto)
   14912            2 :         error_at (declspecs->locations[ds_storage_class],
   14913              :                   "top-level declaration of %qs specifies %<auto%>", name);
   14914              :     }
   14915    528846543 :   else if (thread_p
   14916    528846543 :            && storage_class != sc_extern
   14917          237 :            && storage_class != sc_static)
   14918              :     {
   14919          204 :       if (declspecs->gnu_thread_keyword_p)
   14920           49 :         pedwarn (declspecs->locations[ds_thread],
   14921           49 :                  0, "function-scope %qs implicitly auto and "
   14922              :                  "declared %<__thread%>", name);
   14923              : 
   14924              :       /* When thread_local is applied to a variable of block scope the
   14925              :          storage-class-specifier static is implied if it does not appear
   14926              :          explicitly.  */
   14927          204 :       storage_class = declspecs->storage_class = sc_static;
   14928          204 :       staticp = 1;
   14929              :     }
   14930              : 
   14931   1011989784 :   if (storage_class && friendp)
   14932              :     {
   14933           12 :       error_at (min_location (declspecs->locations[ds_thread],
   14934              :                               declspecs->locations[ds_storage_class]),
   14935              :                 "storage class specifiers invalid in friend function "
   14936              :                 "declarations");
   14937           12 :       storage_class = sc_none;
   14938           12 :       staticp = 0;
   14939              :     }
   14940              : 
   14941   1011989784 :   if (!id_declarator)
   14942              :     unqualified_id = NULL_TREE;
   14943              :   else
   14944              :     {
   14945    571448300 :       unqualified_id = id_declarator->u.id.unqualified_name;
   14946    571448300 :       switch (TREE_CODE (unqualified_id))
   14947              :         {
   14948      3185022 :         case BIT_NOT_EXPR:
   14949      3185022 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   14950      3185022 :           if (TYPE_P (unqualified_id))
   14951      3185019 :             unqualified_id = constructor_name (unqualified_id);
   14952              :           break;
   14953              : 
   14954              :         case IDENTIFIER_NODE:
   14955              :         case TEMPLATE_ID_EXPR:
   14956              :           break;
   14957              : 
   14958            0 :         default:
   14959            0 :           gcc_unreachable ();
   14960              :         }
   14961              :     }
   14962              : 
   14963   1011989784 :   if (declspecs->std_attributes)
   14964              :     {
   14965          723 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   14966          723 :       auto_diagnostic_group d;
   14967          723 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   14968          723 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   14969          720 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   14970              :                 "is ignored");
   14971          723 :     }
   14972              : 
   14973              :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   14974              :   bool is_xobj_member_function = false;
   14975              :   /* Determine the type of the entity declared by recurring on the
   14976              :      declarator.  */
   14977   1390546862 :   for (; declarator; declarator = declarator->declarator)
   14978              :     {
   14979    950229340 :       const cp_declarator *inner_declarator;
   14980    950229340 :       tree attrs;
   14981              : 
   14982    950229340 :       if (type == error_mark_node)
   14983          603 :         return error_mark_node;
   14984              : 
   14985    950229013 :       attrs = declarator->attributes;
   14986    950229013 :       if (attrs)
   14987              :         {
   14988        13469 :           int attr_flags;
   14989              : 
   14990        13469 :           attr_flags = 0;
   14991        13469 :           if (declarator->kind == cdk_id)
   14992        12765 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   14993        13469 :           if (declarator->kind == cdk_function)
   14994          687 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   14995        13469 :           if (declarator->kind == cdk_array)
   14996            2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   14997        13469 :           tree late_attrs = NULL_TREE;
   14998        13469 :           if (decl_context != PARM && decl_context != TYPENAME)
   14999              :             /* Assume that any attributes that get applied late to
   15000              :                templates will DTRT when applied to the declaration
   15001              :                as a whole.  */
   15002        13457 :             late_attrs = splice_template_attributes (&attrs, type);
   15003        13469 :           returned_attrs = decl_attributes (&type,
   15004              :                                             attr_chainon (returned_attrs,
   15005              :                                                           attrs),
   15006              :                                             attr_flags);
   15007        13469 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   15008              :         }
   15009              : 
   15010    950229013 :       inner_declarator = declarator->declarator;
   15011              : 
   15012              :       /* We don't want to warn in parameter context because we don't
   15013              :          yet know if the parse will succeed, and this might turn out
   15014              :          to be a constructor call.  */
   15015    950229013 :       if (decl_context != PARM
   15016    950229013 :           && decl_context != TYPENAME
   15017    552087552 :           && !typedef_p
   15018    504949956 :           && declarator->parenthesized != UNKNOWN_LOCATION
   15019              :           /* If the type is class-like and the inner name used a
   15020              :              global namespace qualifier, we need the parens.
   15021              :              Unfortunately all we can tell is whether a qualified name
   15022              :              was used or not.  */
   15023    950229194 :           && !(inner_declarator
   15024          126 :                && inner_declarator->kind == cdk_id
   15025          108 :                && inner_declarator->u.id.qualifying_scope
   15026           18 :                && (MAYBE_CLASS_TYPE_P (type)
   15027           12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   15028              :         {
   15029          169 :           auto_diagnostic_group d;
   15030          169 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   15031              :                           "unnecessary parentheses in declaration of %qs",
   15032              :                           name))
   15033              :             {
   15034           42 :               gcc_rich_location iloc (declarator->parenthesized);
   15035           42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   15036           42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   15037           42 :               inform (&iloc, "remove parentheses");
   15038           42 :             }
   15039          169 :         }
   15040    950229013 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   15041              :         break;
   15042              : 
   15043    378557354 :       switch (declarator->kind)
   15044              :         {
   15045      3481235 :         case cdk_array:
   15046      6962470 :           type = create_array_type_for_decl (dname, type,
   15047      3481235 :                                              declarator->u.array.bounds,
   15048      3481235 :                                              declarator->id_loc);
   15049      3481235 :           if (!valid_array_size_p (dname
   15050              :                                    ? declarator->id_loc : input_location,
   15051              :                                    type, dname))
   15052          267 :             type = error_mark_node;
   15053              : 
   15054      3481235 :           if (declarator->std_attributes)
   15055              :             /* [dcl.array]/1:
   15056              : 
   15057              :                The optional attribute-specifier-seq appertains to the
   15058              :                array type.  */
   15059          193 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15060              :           break;
   15061              : 
   15062    186178409 :         case cdk_function:
   15063    186178409 :           {
   15064    186178409 :             tree arg_types;
   15065    186178409 :             int funcdecl_p;
   15066              : 
   15067              :             /* Declaring a function type.  */
   15068              : 
   15069              :             /* Pick up type qualifiers which should be applied to `this'.  */
   15070    186178409 :             memfn_quals = declarator->u.function.qualifiers;
   15071              :             /* Pick up virt-specifiers.  */
   15072    186178409 :             virt_specifiers = declarator->u.function.virt_specifiers;
   15073              :             /* And ref-qualifier, too */
   15074    186178409 :             rqual = declarator->u.function.ref_qualifier;
   15075              :             /* And tx-qualifier.  */
   15076    186178409 :             tree tx_qual = declarator->u.function.tx_qualifier;
   15077              :             /* Pick up the exception specifications.  */
   15078    186178409 :             raises = declarator->u.function.exception_specification;
   15079              :             /* If the exception-specification is ill-formed, let's pretend
   15080              :                there wasn't one.  */
   15081    186178409 :             if (raises == error_mark_node)
   15082            9 :               raises = NULL_TREE;
   15083              : 
   15084    372356818 :             auto find_xobj_parm = [](tree parm_list)
   15085              :               {
   15086              :                 /* There is no need to iterate over the list,
   15087              :                    only the first parm can be a valid xobj parm.  */
   15088    372138890 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   15089              :                   return NULL_TREE;
   15090              :                 /* If we make it here, we are looking at an xobj parm.
   15091              : 
   15092              :                    Non-null 'purpose' usually means the parm has a default
   15093              :                    argument, we don't want to violate this assumption.  */
   15094        79163 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   15095        79163 :                 return TREE_VALUE (parm_list);
   15096              :               };
   15097              : 
   15098    186178409 :             tree xobj_parm
   15099    186178409 :               = find_xobj_parm (declarator->u.function.parameters);
   15100    186178409 :             is_xobj_member_function = xobj_parm;
   15101              : 
   15102    186178409 :             if (xobj_parm && cxx_dialect < cxx23)
   15103        41943 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   15104              :                        "explicit object member function only available "
   15105              :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   15106              : 
   15107    186178409 :             if (xobj_parm && decl_context == TYPENAME)
   15108              :               {
   15109              :                 /* We inform in every case, just differently depending on what
   15110              :                    case it is.  */
   15111            6 :                 auto_diagnostic_group d;
   15112            6 :                 bool ptr_type = true;
   15113              :                 /* If declarator->kind is cdk_function and we are at the end of
   15114              :                    the declarator chain, we are looking at a function type.  */
   15115            6 :                 if (!declarator->declarator)
   15116              :                   {
   15117            2 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15118              :                               "a function type cannot "
   15119              :                               "have an explicit object parameter");
   15120            2 :                     ptr_type = false;
   15121              :                   }
   15122            4 :                 else if (declarator->declarator->kind == cdk_pointer)
   15123            2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15124              :                             "a pointer to function type cannot "
   15125              :                             "have an explicit object parameter");
   15126            2 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   15127            2 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15128              :                             "a pointer to member function type "
   15129              :                             "cannot have an explicit object parameter");
   15130              :                 else
   15131            0 :                   gcc_unreachable ();
   15132              : 
   15133              :                 /* The locations being used here are probably not correct.  */
   15134            4 :                 if (ptr_type)
   15135            4 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15136              :                           "the type of a pointer to explicit object member "
   15137              :                           "function is a regular pointer to function type");
   15138              :                 else
   15139            2 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15140              :                           "the type of an explicit object "
   15141              :                           "member function is a regular function type");
   15142              :                 /* Ideally we should synthesize the correct syntax
   15143              :                    for the user, perhaps this could be added later.  */
   15144            6 :               }
   15145              :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   15146              :                the first parm node will never erroneously be detected here.  */
   15147    186178409 :             {
   15148    186178409 :               auto_diagnostic_group d;
   15149    186178409 :               bool bad_xobj_parm_encountered = false;
   15150    186178409 :               for (tree parm = declarator->u.function.parameters;
   15151    461517049 :                    parm && parm != void_list_node;
   15152    275338640 :                    parm = TREE_CHAIN (parm))
   15153              :                 {
   15154    275338640 :                   if (TREE_PURPOSE (parm) != this_identifier)
   15155    275338634 :                     continue;
   15156            6 :                   bad_xobj_parm_encountered = true;
   15157            6 :                   TREE_PURPOSE (parm) = NULL_TREE;
   15158            6 :                   gcc_rich_location bad_xobj_parm
   15159            6 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   15160            6 :                   error_at (&bad_xobj_parm,
   15161              :                             "only the first parameter of a member function "
   15162              :                             "can be declared as an explicit object parameter");
   15163            6 :                 }
   15164    186178409 :               if (bad_xobj_parm_encountered && xobj_parm)
   15165            0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   15166              :                         "valid explicit object parameter declared here");
   15167    186178409 :             }
   15168              : 
   15169    186178409 :             if (reqs)
   15170            3 :               error_at (location_of (reqs), "requires-clause on return type");
   15171    186178409 :             reqs = declarator->u.function.requires_clause;
   15172              : 
   15173              :             /* Say it's a definition only for the CALL_EXPR
   15174              :                closest to the identifier.  */
   15175    186178409 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   15176              : 
   15177              :             /* Handle a late-specified return type.  */
   15178    186178409 :             tree late_return_type = declarator->u.function.late_return_type;
   15179    186178409 :             if (tree auto_node = type_uses_auto (type))
   15180              :               {
   15181      8486013 :                 if (!late_return_type)
   15182              :                   {
   15183      5019141 :                     if (!funcdecl_p)
   15184              :                       /* auto (*fp)() = f; is OK.  */;
   15185      5019107 :                     else if (current_class_type
   15186      9268206 :                              && LAMBDA_TYPE_P (current_class_type))
   15187              :                       /* OK for C++11 lambdas.  */;
   15188      3087332 :                     else if (cxx_dialect < cxx14)
   15189              :                       {
   15190            7 :                         auto_diagnostic_group d;
   15191            7 :                         error_at (typespec_loc, "%qs function uses "
   15192              :                                   "%<auto%> type specifier without "
   15193              :                                   "trailing return type", name);
   15194            7 :                         inform (typespec_loc,
   15195              :                                 "deduced return type only available "
   15196              :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   15197            7 :                       }
   15198      3087325 :                     else if (virtualp)
   15199              :                       {
   15200            6 :                         error_at (typespec_loc, "virtual function "
   15201              :                                   "cannot have deduced return type");
   15202            6 :                         virtualp = false;
   15203              :                       }
   15204              :                   }
   15205      3466872 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   15206              :                   {
   15207           15 :                     error_at (typespec_loc, "%qs function with trailing "
   15208              :                               "return type has %qT as its type rather "
   15209              :                               "than plain %<auto%>", name, type);
   15210          273 :                     return error_mark_node;
   15211              :                   }
   15212      3466857 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   15213              :                   {
   15214            9 :                     if (funcdecl_p)
   15215            3 :                       error_at (typespec_loc,
   15216              :                                 "%qs function with trailing return type "
   15217              :                                 "has %<decltype(auto)%> as its type "
   15218              :                                 "rather than plain %<auto%>", name);
   15219              :                     else
   15220            6 :                       error_at (typespec_loc,
   15221              :                                 "invalid use of %<decltype(auto)%>");
   15222            9 :                     return error_mark_node;
   15223              :                   }
   15224      3466848 :                 else if (is_constrained_auto (type))
   15225              :                   {
   15226            6 :                     if (funcdecl_p)
   15227            3 :                       error_at (typespec_loc,
   15228              :                                 "%qs function with trailing return type "
   15229              :                                 "has constrained %<auto%> type specifier "
   15230              :                                 "rather than plain %<auto%>",
   15231              :                                 name);
   15232              :                     else
   15233            3 :                       error_at (typespec_loc,
   15234              :                                 "invalid use of constrained %<auto%> type");
   15235            6 :                     return error_mark_node;
   15236              :                   }
   15237      8485983 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   15238      8485983 :                 if (!tmpl)
   15239      7319323 :                   if (tree late_auto = type_uses_auto (late_return_type))
   15240        34823 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   15241      7319323 :                 if (tmpl)
   15242              :                   {
   15243      1166664 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   15244              :                       {
   15245           11 :                         auto_diagnostic_group g;
   15246           11 :                         error_at (typespec_loc, "deduced class "
   15247              :                                   "type %qD in function return type",
   15248           11 :                                   DECL_NAME (tmpl));
   15249           11 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15250              :                                 "%qD declared here", tmpl);
   15251           11 :                         return error_mark_node;
   15252           11 :                       }
   15253      1166653 :                     else if (!late_return_type)
   15254              :                       {
   15255            3 :                         auto_diagnostic_group d;
   15256            3 :                         error_at (declarator->id_loc, "deduction guide "
   15257              :                                   "for %qT must have trailing return "
   15258            3 :                                   "type", TREE_TYPE (tmpl));
   15259            3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15260              :                                 "%qD declared here", tmpl);
   15261            3 :                         return error_mark_node;
   15262            3 :                       }
   15263      1166650 :                     else if (CLASS_TYPE_P (late_return_type)
   15264      1166650 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   15265      2333300 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   15266              :                                   == tmpl))
   15267              :                       /* OK */;
   15268              :                     else
   15269            0 :                       error ("trailing return type %qT of deduction guide "
   15270              :                               "is not a specialization of %qT",
   15271            0 :                               late_return_type, TREE_TYPE (tmpl));
   15272              :                   }
   15273              :               }
   15274    177692396 :             else if (late_return_type
   15275    177692396 :                      && sfk != sfk_conversion)
   15276              :               {
   15277           37 :                 if (late_return_type == error_mark_node)
   15278              :                   return error_mark_node;
   15279           37 :                 if (cxx_dialect < cxx11)
   15280              :                   /* Not using maybe_warn_cpp0x because this should
   15281              :                      always be an error.  */
   15282            1 :                   error_at (typespec_loc,
   15283              :                             "trailing return type only available "
   15284              :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   15285              :                 else
   15286           36 :                   error_at (typespec_loc, "%qs function with trailing "
   15287              :                             "return type not declared with %<auto%> "
   15288              :                             "type specifier", name);
   15289           37 :                 return error_mark_node;
   15290              :               }
   15291    186178328 :             if (late_return_type && sfk == sfk_conversion)
   15292              :               {
   15293           14 :                 error ("a conversion function cannot have a trailing return type");
   15294           14 :                 return error_mark_node;
   15295              :               }
   15296    186178314 :             type = splice_late_return_type (type, late_return_type);
   15297    186178314 :             if (type == error_mark_node)
   15298              :               return error_mark_node;
   15299              : 
   15300    186178237 :             if (late_return_type)
   15301              :               {
   15302      3466753 :                 late_return_type_p = true;
   15303      3466753 :                 type_quals = cp_type_quals (type);
   15304              :               }
   15305              : 
   15306    186178237 :             if (type_quals != TYPE_UNQUALIFIED)
   15307              :               {
   15308              :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   15309              :                    warning for
   15310              :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   15311              :                     because there the qualifier matters.  */
   15312        11690 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   15313          232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   15314              :                               "qualifiers ignored on function return type");
   15315              :                 /* [dcl.fct] "A volatile-qualified return type is
   15316              :                    deprecated."  */
   15317        11690 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   15318          599 :                   warning_at (typespec_loc, OPT_Wvolatile,
   15319              :                               "%<volatile%>-qualified return type is "
   15320              :                               "deprecated");
   15321              : 
   15322              :                 /* We now know that the TYPE_QUALS don't apply to the
   15323              :                    decl, but to its return type.  */
   15324              :                 type_quals = TYPE_UNQUALIFIED;
   15325              :               }
   15326              : 
   15327              :             /* Error about some types functions can't return.  */
   15328              : 
   15329    186178237 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   15330              :               {
   15331           30 :                 error_at (typespec_loc, "%qs declared as function returning "
   15332              :                           "a function", name);
   15333           30 :                 return error_mark_node;
   15334              :               }
   15335    186178207 :             if (TREE_CODE (type) == ARRAY_TYPE)
   15336              :               {
   15337            6 :                 error_at (typespec_loc, "%qs declared as function returning "
   15338              :                           "an array", name);
   15339            6 :                 return error_mark_node;
   15340              :               }
   15341    186178201 :             if (constinit_p && funcdecl_p)
   15342              :               {
   15343           15 :                 error_at (declspecs->locations[ds_constinit],
   15344              :                           "%<constinit%> on function return type is not "
   15345              :                           "allowed");
   15346           15 :                 return error_mark_node;
   15347              :               }
   15348              : 
   15349    186178186 :             if (check_decltype_auto (typespec_loc, type))
   15350           50 :               return error_mark_node;
   15351              : 
   15352    186178136 :             if (ctype == NULL_TREE
   15353    186178136 :                 && decl_context == FIELD
   15354              :                 && funcdecl_p
   15355    107446146 :                 && friendp == 0)
   15356    100916326 :               ctype = current_class_type;
   15357              : 
   15358    186178136 :             if (ctype && (sfk == sfk_constructor
   15359    100916326 :                           || sfk == sfk_destructor))
   15360              :               {
   15361              :                 /* We are within a class's scope. If our declarator name
   15362              :                    is the same as the class name, and we are defining
   15363              :                    a function, then it is a constructor/destructor, and
   15364              :                    therefore returns a void type.  */
   15365              : 
   15366              :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   15367              :                    const or volatile.  A destructor may not be static.
   15368              :                    A destructor may not be declared with ref-qualifier.
   15369              : 
   15370              :                    ISO C++ 12.1.  A constructor may not be declared
   15371              :                    const or volatile.  A constructor may not be
   15372              :                    virtual.  A constructor may not be static.
   15373              :                    A constructor may not be declared with ref-qualifier. */
   15374     25824856 :                 if (staticp == 2)
   15375            9 :                   error_at (declspecs->locations[ds_storage_class],
   15376              :                             (flags == DTOR_FLAG)
   15377              :                             ? G_("destructor cannot be static member "
   15378              :                                  "function")
   15379              :                             : G_("constructor cannot be static member "
   15380              :                                  "function"));
   15381     25824856 :                 if (memfn_quals)
   15382              :                   {
   15383            9 :                     error ((flags == DTOR_FLAG)
   15384              :                            ? G_("destructors may not be cv-qualified")
   15385              :                            : G_("constructors may not be cv-qualified"));
   15386            9 :                     memfn_quals = TYPE_UNQUALIFIED;
   15387              :                   }
   15388              : 
   15389     25824856 :                 if (rqual)
   15390              :                   {
   15391            6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   15392            6 :                     error ((flags == DTOR_FLAG)
   15393              :                            ? G_("destructors may not be ref-qualified")
   15394              :                            : G_("constructors may not be ref-qualified"));
   15395            6 :                     rqual = REF_QUAL_NONE;
   15396              :                   }
   15397              : 
   15398     25824856 :                 if (decl_context == FIELD
   15399     25824856 :                     && !member_function_or_else (ctype,
   15400              :                                                  current_class_type,
   15401              :                                                  flags))
   15402            0 :                   return error_mark_node;
   15403              : 
   15404     25824856 :                 if (flags != DTOR_FLAG)
   15405              :                   {
   15406              :                     /* It's a constructor.  */
   15407     22803278 :                     if (explicitp == 1)
   15408      5361624 :                       explicitp = 2;
   15409     22803278 :                     if (virtualp)
   15410              :                       {
   15411            3 :                         permerror (declspecs->locations[ds_virtual],
   15412              :                                    "constructors cannot be declared %<virtual%>");
   15413            3 :                         virtualp = 0;
   15414              :                       }
   15415     22803278 :                     if (decl_context == FIELD
   15416     22803278 :                         && sfk != sfk_constructor)
   15417            0 :                       return error_mark_node;
   15418              :                   }
   15419     25824856 :                 if (decl_context == FIELD)
   15420     25824856 :                   staticp = 0;
   15421              :               }
   15422    160353280 :             else if (friendp)
   15423              :               {
   15424      6213047 :                 if (virtualp)
   15425              :                   {
   15426              :                     /* Cannot be both friend and virtual.  */
   15427           12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15428           12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   15429           12 :                     error_at (&richloc, "virtual functions cannot be friends");
   15430           12 :                     friendp = 0;
   15431           12 :                   }
   15432      6213047 :                 if (decl_context == NORMAL)
   15433            0 :                   error_at (declarator->id_loc,
   15434              :                             "friend declaration not in class definition");
   15435      6213047 :                 if (current_function_decl && funcdef_flag)
   15436              :                   {
   15437            9 :                     error_at (declarator->id_loc,
   15438              :                               "cannot define friend function %qs in a local "
   15439              :                               "class definition", name);
   15440            9 :                     friendp = 0;
   15441              :                   }
   15442              :                 /* [class.friend]/6: A function can be defined in a friend
   15443              :                    declaration if the function name is unqualified.  */
   15444      6213047 :                 if (funcdef_flag && in_namespace)
   15445              :                   {
   15446            6 :                     if (in_namespace == global_namespace)
   15447            3 :                       error_at (declarator->id_loc,
   15448              :                                 "friend function definition %qs cannot have "
   15449              :                                 "a name qualified with %<::%>", name);
   15450              :                     else
   15451            3 :                       error_at (declarator->id_loc,
   15452              :                                 "friend function definition %qs cannot have "
   15453              :                                 "a name qualified with %<%D::%>", name,
   15454              :                                 in_namespace);
   15455              :                   }
   15456              :               }
   15457    154140233 :             else if (ctype && sfk == sfk_conversion)
   15458              :               {
   15459       990288 :                 if (explicitp == 1)
   15460              :                   {
   15461       463569 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   15462       463569 :                     explicitp = 2;
   15463              :                   }
   15464              :               }
   15465    153149945 :             else if (sfk == sfk_deduction_guide)
   15466              :               {
   15467      1166650 :                 if (explicitp == 1)
   15468    186178136 :                   explicitp = 2;
   15469              :               }
   15470              : 
   15471    186178136 :             if (xobj_parm)
   15472              :               {
   15473        79163 :                 if (!ctype
   15474        79163 :                     && decl_context == NORMAL
   15475           49 :                     && (in_namespace
   15476           49 :                         || !declarator->declarator->u.id.qualifying_scope))
   15477            4 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15478              :                             "a non-member function cannot have "
   15479              :                             "an explicit object parameter");
   15480              :                 else
   15481              :                   {
   15482        79159 :                     if (virtualp)
   15483              :                       {
   15484           16 :                         auto_diagnostic_group d;
   15485           16 :                         error_at (declspecs->locations[ds_virtual],
   15486              :                                   "an explicit object member function cannot "
   15487              :                                   "be %<virtual%>");
   15488           16 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15489              :                                 "explicit object parameter declared here");
   15490           16 :                         virtualp = false;
   15491           16 :                       }
   15492        79159 :                     if (staticp >= 2)
   15493              :                       {
   15494            2 :                         auto_diagnostic_group d;
   15495            2 :                         error_at (declspecs->locations[ds_storage_class],
   15496              :                                   "an explicit object member function cannot "
   15497              :                                   "be %<static%>");
   15498            2 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15499              :                                 "explicit object parameter declared here");
   15500            2 :                       }
   15501        79159 :                     if (unqualified_id
   15502    186257289 :                         && identifier_p (unqualified_id)
   15503       158312 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15504            8 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15505              :                                 "%qD cannot be an explicit object member "
   15506              :                                 "function", unqualified_id);
   15507              :                   }
   15508              :               }
   15509    186178136 :             tree pushed_scope = NULL_TREE;
   15510    186178136 :             if (funcdecl_p
   15511    186178136 :                 && decl_context != FIELD
   15512     76865957 :                 && inner_declarator->u.id.qualifying_scope
   15513    194959483 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   15514      8780024 :               pushed_scope
   15515      8780024 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   15516              : 
   15517    186178136 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   15518              : 
   15519    186178136 :             if (pushed_scope)
   15520      8780024 :               pop_scope (pushed_scope);
   15521              : 
   15522    186178136 :             if (inner_declarator
   15523    185815985 :                 && inner_declarator->kind == cdk_id
   15524    183995330 :                 && inner_declarator->u.id.sfk == sfk_destructor
   15525      3185013 :                 && arg_types != void_list_node)
   15526              :               {
   15527           20 :                 error_at (declarator->id_loc,
   15528              :                           "destructors may not have parameters");
   15529           20 :                 arg_types = void_list_node;
   15530           20 :                 parms = NULL_TREE;
   15531           20 :                 is_xobj_member_function = false;
   15532              :               }
   15533              : 
   15534    186178136 :             type = cp_build_function_type (type, arg_types);
   15535              : 
   15536    186178136 :             tree attrs = declarator->std_attributes;
   15537    186178136 :             if (tx_qual)
   15538              :               {
   15539          242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   15540              :                 /* transaction_safe applies to the type, but
   15541              :                    transaction_safe_dynamic applies to the function.  */
   15542          242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   15543          213 :                   attrs = attr_chainon (attrs, att);
   15544              :                 else
   15545           29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   15546              :               }
   15547              : 
   15548              :             /* Actually apply the contract attributes to the declaration.  */
   15549    186178136 :             if (flag_contracts)
   15550        75769 :               contract_specifiers
   15551        75769 :                 = attr_chainon (contract_specifiers,
   15552        75769 :                                 declarator->u.function.contract_specifiers);
   15553              : 
   15554    186178136 :             if (attrs)
   15555              :               /* [dcl.fct]/2:
   15556              : 
   15557              :                  The optional attribute-specifier-seq appertains to
   15558              :                  the function type.  */
   15559          497 :               cplus_decl_attributes (&type, attrs, 0);
   15560              : 
   15561    186178136 :             if (raises)
   15562     74075913 :               type = build_exception_variant (type, raises);
   15563              :           }
   15564    186178136 :           break;
   15565              : 
   15566    188897710 :         case cdk_pointer:
   15567    188897710 :         case cdk_reference:
   15568    188897710 :         case cdk_ptrmem:
   15569              :           /* Filter out pointers-to-references and references-to-references.
   15570              :              We can get these if a TYPE_DECL is used.  */
   15571              : 
   15572    188897710 :           if (TYPE_REF_P (type))
   15573              :             {
   15574          239 :               if (declarator->kind != cdk_reference)
   15575              :                 {
   15576            3 :                   error ("cannot declare pointer to %q#T", type);
   15577            3 :                   type = TREE_TYPE (type);
   15578              :                 }
   15579              : 
   15580              :               /* In C++0x, we allow reference to reference declarations
   15581              :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   15582              :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   15583              :                  check for direct reference to reference declarations, which
   15584              :                  are still forbidden, occurs below. Reasoning behind the change
   15585              :                  can be found in DR106, DR540, and the rvalue reference
   15586              :                  proposals. */
   15587          236 :               else if (cxx_dialect == cxx98)
   15588              :                 {
   15589            0 :                   error ("cannot declare reference to %q#T", type);
   15590            0 :                   type = TREE_TYPE (type);
   15591              :                 }
   15592              :             }
   15593    188897471 :           else if (VOID_TYPE_P (type))
   15594              :             {
   15595      4951709 :               if (declarator->kind == cdk_reference)
   15596            4 :                 error ("cannot declare reference to %q#T", type);
   15597      4951705 :               else if (declarator->kind == cdk_ptrmem)
   15598            3 :                 error ("cannot declare pointer to %q#T member", type);
   15599              :             }
   15600              : 
   15601              :           /* We now know that the TYPE_QUALS don't apply to the decl,
   15602              :              but to the target of the pointer.  */
   15603    188897710 :           type_quals = TYPE_UNQUALIFIED;
   15604              : 
   15605              :           /* This code used to handle METHOD_TYPE, but I don't think it's
   15606              :              possible to get it here anymore.  */
   15607    188897710 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   15608    188897710 :           if (declarator->kind == cdk_ptrmem
   15609      1084337 :               && TREE_CODE (type) == FUNCTION_TYPE)
   15610              :             {
   15611       878035 :               memfn_quals |= type_memfn_quals (type);
   15612      1756070 :               type = build_memfn_type (type,
   15613       878035 :                                        declarator->u.pointer.class_type,
   15614              :                                        memfn_quals,
   15615              :                                        rqual);
   15616       878035 :               if (type == error_mark_node)
   15617              :                 return error_mark_node;
   15618              : 
   15619              :               rqual = REF_QUAL_NONE;
   15620              :               memfn_quals = TYPE_UNQUALIFIED;
   15621              :             }
   15622              : 
   15623    188897707 :           if (TREE_CODE (type) == FUNCTION_TYPE
   15624    188897707 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   15625      1013520 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   15626           15 :             error (declarator->kind == cdk_reference
   15627              :                    ? G_("cannot declare reference to qualified function type %qT")
   15628              :                    : G_("cannot declare pointer to qualified function type %qT"),
   15629              :                    type);
   15630              : 
   15631              :           /* When the pointed-to type involves components of variable size,
   15632              :              care must be taken to ensure that the size evaluation code is
   15633              :              emitted early enough to dominate all the possible later uses
   15634              :              and late enough for the variables on which it depends to have
   15635              :              been assigned.
   15636              : 
   15637              :              This is expected to happen automatically when the pointed-to
   15638              :              type has a name/declaration of it's own, but special attention
   15639              :              is required if the type is anonymous.
   15640              : 
   15641              :              We handle the NORMAL and FIELD contexts here by inserting a
   15642              :              dummy statement that just evaluates the size at a safe point
   15643              :              and ensures it is not deferred until e.g. within a deeper
   15644              :              conditional context (c++/43555).
   15645              : 
   15646              :              We expect nothing to be needed here for PARM or TYPENAME.
   15647              :              Evaluating the size at this point for TYPENAME would
   15648              :              actually be incorrect, as we might be in the middle of an
   15649              :              expression with side effects on the pointed-to type size
   15650              :              "arguments" prior to the pointer declaration point and the
   15651              :              size evaluation could end up prior to the side effects.  */
   15652              : 
   15653    188897707 :           if (!TYPE_NAME (type)
   15654      5381068 :               && (decl_context == NORMAL || decl_context == FIELD)
   15655       610485 :               && at_function_scope_p ()
   15656    188937512 :               && variably_modified_type_p (type, NULL_TREE))
   15657              :             {
   15658          119 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   15659              :                                              NULL_TREE, type);
   15660          119 :               add_decl_expr (TYPE_NAME (type));
   15661              :             }
   15662              : 
   15663    188897707 :           if (declarator->kind == cdk_reference)
   15664              :             {
   15665              :               /* In C++0x, the type we are creating a reference to might be
   15666              :                  a typedef which is itself a reference type. In that case,
   15667              :                  we follow the reference collapsing rules in
   15668              :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   15669              : 
   15670              :                  "If a typedef TD names a type that is a reference to a type
   15671              :                  T, an attempt to create the type 'lvalue reference to cv TD'
   15672              :                  creates the type 'lvalue reference to T,' while an attempt
   15673              :                  to create the type "rvalue reference to cv TD' creates the
   15674              :                  type TD."
   15675              :               */
   15676    126453250 :               if (VOID_TYPE_P (type))
   15677              :                 /* We already gave an error.  */;
   15678    126453246 :               else if (TYPE_REF_P (type))
   15679              :                 {
   15680          236 :                   if (declarator->u.reference.rvalue_ref)
   15681              :                     /* Leave type alone.  */;
   15682              :                   else
   15683          116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   15684              :                 }
   15685              :               else
   15686    126453010 :                 type = cp_build_reference_type
   15687    126453010 :                   (type, declarator->u.reference.rvalue_ref);
   15688              : 
   15689              :               /* In C++0x, we need this check for direct reference to
   15690              :                  reference declarations, which are forbidden by
   15691              :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   15692              :                  are only allowed indirectly through typedefs and template
   15693              :                  type arguments. Example:
   15694              : 
   15695              :                    void foo(int & &);      // invalid ref-to-ref decl
   15696              : 
   15697              :                    typedef int & int_ref;
   15698              :                    void foo(int_ref &);    // valid ref-to-ref decl
   15699              :               */
   15700    126453250 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   15701            1 :                 error ("cannot declare reference to %q#T, which is not "
   15702              :                        "a typedef or a template type argument", type);
   15703              :             }
   15704     62444457 :           else if (TREE_CODE (type) == METHOD_TYPE)
   15705       878032 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   15706     61566425 :           else if (declarator->kind == cdk_ptrmem)
   15707              :             {
   15708       206302 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   15709              :                           != NAMESPACE_DECL);
   15710       206302 :               if (declarator->u.pointer.class_type == error_mark_node)
   15711              :                 /* We will already have complained.  */
   15712            3 :                 type = error_mark_node;
   15713              :               else
   15714       206299 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   15715              :                                           type);
   15716              :             }
   15717              :           else
   15718     61360123 :             type = build_pointer_type (type);
   15719              : 
   15720              :           /* Process a list of type modifier keywords (such as
   15721              :              const or volatile) that were given inside the `*' or `&'.  */
   15722              : 
   15723    188897707 :           if (declarator->u.pointer.qualifiers)
   15724              :             {
   15725      8299157 :               type
   15726      8299157 :                 = cp_build_qualified_type (type,
   15727              :                                            declarator->u.pointer.qualifiers);
   15728      8299157 :               type_quals = cp_type_quals (type);
   15729              :             }
   15730              : 
   15731              :           /* Apply C++11 attributes to the pointer, and not to the
   15732              :              type pointed to.  This is unlike what is done for GNU
   15733              :              attributes above.  It is to comply with [dcl.ptr]/1:
   15734              : 
   15735              :                  [the optional attribute-specifier-seq (7.6.1) appertains
   15736              :                   to the pointer and not to the object pointed to].  */
   15737    188897707 :           if (declarator->std_attributes)
   15738          173 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15739              : 
   15740              :           ctype = NULL_TREE;
   15741              :           break;
   15742              : 
   15743              :         case cdk_error:
   15744              :           break;
   15745              : 
   15746            0 :         default:
   15747            0 :           gcc_unreachable ();
   15748              :         }
   15749              :     }
   15750              : 
   15751   1011989181 :   id_loc = declarator ? declarator->id_loc : input_location;
   15752              : 
   15753   1011989181 :   if (innermost_code != cdk_function
   15754              :     /* Don't check this if it can be the artifical decltype(auto)
   15755              :        we created when building a constraint in a compound-requirement:
   15756              :        that the type-constraint is plain is going to be checked in
   15757              :        cp_parser_compound_requirement.  */
   15758   1011989181 :       && decl_context != TYPENAME
   15759   1011989181 :       && check_decltype_auto (id_loc, type))
   15760           20 :     return error_mark_node;
   15761              : 
   15762              :   /* A `constexpr' specifier used in an object declaration declares
   15763              :      the object as `const'.  */
   15764   1011989161 :   if (constexpr_p && innermost_code != cdk_function)
   15765              :     {
   15766              :       /* DR1688 says that a `constexpr' specifier in combination with
   15767              :          `volatile' is valid.  */
   15768              : 
   15769     18938622 :       if (!TYPE_REF_P (type))
   15770              :         {
   15771     18926566 :           type_quals |= TYPE_QUAL_CONST;
   15772     18926566 :           type = cp_build_qualified_type (type, type_quals);
   15773              :         }
   15774              :     }
   15775              : 
   15776    571447706 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   15777      2664855 :       && !FUNC_OR_METHOD_TYPE_P (type)
   15778   1013737737 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   15779              :     {
   15780            0 :       error ("template-id %qD used as a declarator",
   15781              :              unqualified_id);
   15782            0 :       unqualified_id = dname;
   15783              :     }
   15784              : 
   15785              :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   15786              :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   15787              :      we know that the function is static.  We take advantage of this
   15788              :      opportunity to do other processing that pertains to entities
   15789              :      explicitly declared to be class members.  Note that if DECLARATOR
   15790              :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   15791              :      would not have exited the loop above.  */
   15792   1011989161 :   if (declarator
   15793    571671642 :       && declarator->kind == cdk_id
   15794    571447706 :       && declarator->u.id.qualifying_scope
   15795   1021485806 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   15796              :     {
   15797      9263485 :       ctype = declarator->u.id.qualifying_scope;
   15798      9263485 :       ctype = TYPE_MAIN_VARIANT (ctype);
   15799      9263485 :       template_count = num_template_headers_for_class (ctype);
   15800              : 
   15801      9263485 :       if (ctype == current_class_type)
   15802              :         {
   15803           54 :           if (friendp)
   15804              :             {
   15805           15 :               permerror (declspecs->locations[ds_friend],
   15806              :                          "member functions are implicitly "
   15807              :                          "friends of their class");
   15808           15 :               friendp = 0;
   15809              :             }
   15810              :           else
   15811           39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   15812              :                        ctype, name);
   15813              :         }
   15814      9263431 :       else if (/* If the qualifying type is already complete, then we
   15815              :                   can skip the following checks.  */
   15816      9263431 :                !COMPLETE_TYPE_P (ctype)
   15817          154 :                && (/* If the function is being defined, then
   15818              :                       qualifying type must certainly be complete.  */
   15819              :                    funcdef_flag
   15820              :                    /* A friend declaration of "T::f" is OK, even if
   15821              :                       "T" is a template parameter.  But, if this
   15822              :                       function is not a friend, the qualifying type
   15823              :                       must be a class.  */
   15824          117 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   15825              :                    /* For a declaration, the type need not be
   15826              :                       complete, if either it is dependent (since there
   15827              :                       is no meaningful definition of complete in that
   15828              :                       case) or the qualifying class is currently being
   15829              :                       defined.  */
   15830          129 :                    || !(dependent_type_p (ctype)
   15831           24 :                         || currently_open_class (ctype)))
   15832              :                /* Check that the qualifying type is complete.  */
   15833      9263495 :                && !complete_type_or_else (ctype, NULL_TREE))
   15834           64 :         return error_mark_node;
   15835      9263367 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   15836              :         {
   15837      8780270 :           if (current_class_type
   15838          273 :               && (!friendp || funcdef_flag || initialized))
   15839              :             {
   15840           57 :               error_at (id_loc, funcdef_flag || initialized
   15841              :                         ? G_("cannot define member function %<%T::%s%> "
   15842              :                              "within %qT")
   15843              :                         : G_("cannot declare member function %<%T::%s%> "
   15844              :                              "within %qT"),
   15845              :                         ctype, name, current_class_type);
   15846           48 :               return error_mark_node;
   15847              :             }
   15848              :         }
   15849       483097 :       else if (typedef_p && current_class_type)
   15850              :         {
   15851            0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   15852              :                     ctype, name, current_class_type);
   15853            0 :           return error_mark_node;
   15854              :         }
   15855              :     }
   15856              : 
   15857   1011989049 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   15858     56640979 :     ctype = current_class_type;
   15859              : 
   15860              :   /* Now TYPE has the actual type.  */
   15861              : 
   15862   1011989049 :   if (returned_attrs)
   15863              :     {
   15864         2934 :       if (attrlist)
   15865         2934 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   15866              :       else
   15867              :         attrlist = &returned_attrs;
   15868              :     }
   15869              : 
   15870   1011989049 :   if (declarator
   15871    571671530 :       && declarator->kind == cdk_id
   15872    571447594 :       && declarator->std_attributes
   15873       549340 :       && attrlist != NULL)
   15874              :     {
   15875              :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   15876              :          a declarator-id appertains to the entity that is declared.  */
   15877       549337 :       if (declarator->std_attributes != error_mark_node)
   15878       549319 :         *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   15879              :       else
   15880              :         /* We should have already diagnosed the issue (c++/78344).  */
   15881           18 :         gcc_assert (seen_error ());
   15882              :     }
   15883              : 
   15884              :   /* Handle parameter packs. */
   15885   1011989049 :   if (parameter_pack_p)
   15886              :     {
   15887      2954564 :       if (decl_context == PARM)
   15888              :         /* Turn the type into a pack expansion.*/
   15889      2954564 :         type = make_pack_expansion (type);
   15890              :       else
   15891            0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   15892              :     }
   15893              : 
   15894   1011989049 :   if ((decl_context == FIELD || decl_context == PARM)
   15895    450653575 :       && !processing_template_decl
   15896   1156521801 :       && variably_modified_type_p (type, NULL_TREE))
   15897              :     {
   15898           12 :       if (decl_context == FIELD)
   15899            6 :         error_at (id_loc,
   15900              :                   "data member may not have variably modified type %qT", type);
   15901              :       else
   15902            6 :         error_at (id_loc,
   15903              :                   "parameter may not have variably modified type %qT", type);
   15904           12 :       type = error_mark_node;
   15905              :     }
   15906              : 
   15907   1011989049 :   if (explicitp == 1 || (explicitp && friendp))
   15908              :     {
   15909              :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   15910              :          in the declaration of a constructor or conversion function within
   15911              :          a class definition.  */
   15912           74 :       if (!current_class_type)
   15913           59 :         error_at (declspecs->locations[ds_explicit],
   15914              :                   "%<explicit%> outside class declaration");
   15915           15 :       else if (friendp)
   15916           12 :         error_at (declspecs->locations[ds_explicit],
   15917              :                   "%<explicit%> in friend declaration");
   15918              :       else
   15919            3 :         error_at (declspecs->locations[ds_explicit],
   15920              :                   "only declarations of constructors and conversion operators "
   15921              :                   "can be %<explicit%>");
   15922              :       explicitp = 0;
   15923              :     }
   15924              : 
   15925   1011989049 :   if (storage_class == sc_mutable)
   15926              :     {
   15927       146232 :       location_t sloc = declspecs->locations[ds_storage_class];
   15928       146232 :       if (decl_context != FIELD || friendp)
   15929              :         {
   15930           30 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   15931              :                     name);
   15932           30 :           storage_class = sc_none;
   15933              :         }
   15934       146202 :       else if (decl_context == TYPENAME || typedef_p)
   15935              :         {
   15936            0 :           error_at (sloc,
   15937              :                     "non-object member %qs cannot be declared %<mutable%>",
   15938              :                     name);
   15939            0 :           storage_class = sc_none;
   15940              :         }
   15941       146202 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   15942              :         {
   15943            3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   15944              :                     name);
   15945            3 :           storage_class = sc_none;
   15946              :         }
   15947       146199 :       else if (staticp)
   15948              :         {
   15949            0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   15950              :                     name);
   15951            0 :           storage_class = sc_none;
   15952              :         }
   15953       146199 :       else if (type_quals & TYPE_QUAL_CONST)
   15954              :         {
   15955            9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   15956              :                     name);
   15957            9 :           storage_class = sc_none;
   15958              :         }
   15959       146190 :       else if (TYPE_REF_P (type))
   15960              :         {
   15961            6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   15962              :                      name);
   15963            6 :           storage_class = sc_none;
   15964              :         }
   15965              :     }
   15966              : 
   15967              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   15968   1011989049 :   if (typedef_p && decl_context != TYPENAME)
   15969              :     {
   15970     46055874 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   15971     46055874 :       tree decl;
   15972              : 
   15973     46055874 :       if (funcdef_flag)
   15974              :         {
   15975            6 :           if (decl_context == NORMAL)
   15976            3 :             error_at (id_loc,
   15977              :                       "typedef may not be a function definition");
   15978              :           else
   15979            3 :             error_at (id_loc,
   15980              :                       "typedef may not be a member function definition");
   15981            6 :           return error_mark_node;
   15982              :         }
   15983              : 
   15984              :       /* This declaration:
   15985              : 
   15986              :            typedef void f(int) const;
   15987              : 
   15988              :          declares a function type which is not a member of any
   15989              :          particular class, but which is cv-qualified; for
   15990              :          example "f S::*" declares a pointer to a const-qualified
   15991              :          member function of S.  We record the cv-qualification in the
   15992              :          function type.  */
   15993     46055868 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   15994              :         {
   15995           62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   15996              : 
   15997              :           /* We have now dealt with these qualifiers.  */
   15998           62 :           memfn_quals = TYPE_UNQUALIFIED;
   15999           62 :           rqual = REF_QUAL_NONE;
   16000              :         }
   16001              : 
   16002     46055868 :       if (type_uses_auto (type))
   16003              :         {
   16004           62 :           if (alias_p)
   16005           20 :             error_at (declspecs->locations[ds_type_spec],
   16006              :                       "%<auto%> not allowed in alias declaration");
   16007              :           else
   16008           42 :             error_at (declspecs->locations[ds_type_spec],
   16009              :                       "typedef declared %<auto%>");
   16010           62 :           type = error_mark_node;
   16011              :         }
   16012              : 
   16013     46055868 :       if (reqs)
   16014            3 :         error_at (location_of (reqs), "requires-clause on typedef");
   16015              : 
   16016     46055868 :       if (id_declarator && declarator->u.id.qualifying_scope)
   16017              :         {
   16018           21 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   16019           21 :           type = error_mark_node;
   16020              :         }
   16021              : 
   16022     46055868 :       if (decl_context == FIELD)
   16023     24598623 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   16024              :       else
   16025     21457245 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   16026              : 
   16027     46055868 :       if (decl_context != FIELD)
   16028              :         {
   16029     21457245 :           if (!current_function_decl)
   16030      9372625 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   16031     12084620 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   16032              :             /* The TYPE_DECL is "abstract" because there will be
   16033              :                clones of this constructor/destructor, and there will
   16034              :                be copies of this TYPE_DECL generated in those
   16035              :                clones.  The decloning optimization (for space) may
   16036              :                revert this subsequently if it determines that
   16037              :                the clones should share a common implementation.  */
   16038       156440 :             DECL_ABSTRACT_P (decl) = true;
   16039              : 
   16040     21457245 :           set_originating_module (decl);
   16041              :         }
   16042     24598623 :       else if (current_class_type
   16043     24598623 :                && constructor_name_p (unqualified_id, current_class_type))
   16044            3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   16045              :                    "as enclosing class",
   16046              :                    unqualified_id);
   16047              : 
   16048              :       /* If the user declares "typedef struct {...} foo" then the
   16049              :          struct will have an anonymous name.  Fill that name in now.
   16050              :          Nothing can refer to it, so nothing needs know about the name
   16051              :          change.  */
   16052     46055868 :       if (type != error_mark_node
   16053     46055785 :           && unqualified_id
   16054     46055782 :           && TYPE_NAME (type)
   16055     42859455 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   16056     85600951 :           && (TYPE_UNNAMED_P (type)
   16057              :               /* An enum may have previously used an enumerator for linkage
   16058              :                  purposes, but we want the typedef name to take priority.  */
   16059     42475851 :               || enum_with_enumerator_for_linkage_p (type))
   16060       384012 :           && declspecs->type_definition_p
   16061       383942 :           && attributes_naming_typedef_ok (*attrlist)
   16062     46439807 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   16063       383921 :         name_unnamed_type (type, decl);
   16064              : 
   16065     46055868 :       if (signed_p
   16066     46055868 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   16067       368263 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   16068              : 
   16069     46055868 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   16070              :                       memfn_quals != TYPE_UNQUALIFIED,
   16071              :                       inlinep, friendp, raises != NULL_TREE,
   16072              :                       declspecs->locations);
   16073              : 
   16074     46055868 :       if (alias_p)
   16075              :         /* Acknowledge that this was written:
   16076              :              `using analias = atype;'.  */
   16077     20590124 :         TYPE_DECL_ALIAS_P (decl) = 1;
   16078              : 
   16079     46055868 :       return decl;
   16080              :     }
   16081              : 
   16082              :   /* Detect the case of an array type of unspecified size
   16083              :      which came, as such, direct from a typedef name.
   16084              :      We must copy the type, so that the array's domain can be
   16085              :      individually set by the object's initializer.  */
   16086              : 
   16087    965933175 :   if (type && typedef_type
   16088    937009312 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   16089    966511994 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   16090           81 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16091              : 
   16092              :   /* Detect where we're using a typedef of function type to declare a
   16093              :      function. PARMS will not be set, so we must create it now.  */
   16094              : 
   16095    965933175 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   16096              :     {
   16097        15251 :       tree decls = NULL_TREE;
   16098        15251 :       tree args;
   16099              : 
   16100        15251 :       for (args = TYPE_ARG_TYPES (type);
   16101        32970 :            args && args != void_list_node;
   16102        17719 :            args = TREE_CHAIN (args))
   16103              :         {
   16104        17719 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   16105        17719 :                                           TREE_VALUE (args));
   16106              : 
   16107        17719 :           DECL_CHAIN (decl) = decls;
   16108        17719 :           decls = decl;
   16109              :         }
   16110              : 
   16111        15251 :       parms = nreverse (decls);
   16112              : 
   16113        15251 :       if (decl_context != TYPENAME)
   16114              :         {
   16115              :           /* The qualifiers on the function type become the qualifiers on
   16116              :              the non-static member function. */
   16117        14536 :           memfn_quals |= type_memfn_quals (type);
   16118        14536 :           rqual = type_memfn_rqual (type);
   16119        14536 :           type_quals = TYPE_UNQUALIFIED;
   16120        14536 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   16121              :         }
   16122              :     }
   16123              : 
   16124              :   /* If this is a type name (such as, in a cast or sizeof),
   16125              :      compute the type and return it now.  */
   16126              : 
   16127    965932460 :   if (decl_context == TYPENAME)
   16128              :     {
   16129              :       /* Note that here we don't care about type_quals.  */
   16130              : 
   16131              :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   16132    396498353 :       if (friendp)
   16133              :         {
   16134            0 :           if (inlinep)
   16135              :             {
   16136            0 :               error ("%<inline%> specified for friend class declaration");
   16137            0 :               inlinep = 0;
   16138              :             }
   16139              : 
   16140            0 :           if (!current_aggr)
   16141              :             {
   16142              :               /* Don't allow friend declaration without a class-key.  */
   16143            0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   16144            0 :                 permerror (input_location, "template parameters cannot be friends");
   16145            0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   16146            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16147              :                            "i.e. %<friend class %T::%D%>",
   16148            0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   16149              :               else
   16150            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16151              :                            "i.e. %<friend %#T%>",
   16152              :                            type);
   16153              :             }
   16154              : 
   16155              :           /* Only try to do this stuff if we didn't already give up.  */
   16156            0 :           if (type != integer_type_node)
   16157              :             {
   16158              :               /* A friendly class?  */
   16159            0 :               if (current_class_type)
   16160            0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   16161              :                                    /*complain=*/true);
   16162              :               else
   16163            0 :                 error ("trying to make class %qT a friend of global scope",
   16164              :                        type);
   16165              : 
   16166            0 :               type = void_type_node;
   16167              :             }
   16168              :         }
   16169    396498353 :       else if (memfn_quals || rqual)
   16170              :         {
   16171        10040 :           if (ctype == NULL_TREE
   16172        10040 :               && TREE_CODE (type) == METHOD_TYPE)
   16173            0 :             ctype = TYPE_METHOD_BASETYPE (type);
   16174              : 
   16175        10040 :           if (ctype)
   16176            0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   16177              :           /* Core issue #547: need to allow this in template type args.
   16178              :              Allow it in general in C++11 for alias-declarations.  */
   16179        10040 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   16180        10038 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   16181        10036 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   16182              :           else
   16183            4 :             error ("invalid qualifiers on non-member function type");
   16184              :         }
   16185              : 
   16186    396498353 :       if (reqs)
   16187            3 :         error_at (location_of (reqs), "requires-clause on type-id");
   16188              : 
   16189    396498353 :       return type;
   16190              :     }
   16191    569434822 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   16192       814268 :            && decl_context != CATCHPARM
   16193       355573 :            && TREE_CODE (type) != UNION_TYPE
   16194       355269 :            && ! bitfield
   16195       355269 :            && innermost_code != cdk_decomp)
   16196              :     {
   16197            9 :       error ("abstract declarator %qT used as declaration", type);
   16198            9 :       return error_mark_node;
   16199              :     }
   16200              : 
   16201    569434813 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   16202              :     {
   16203              :       /* Only functions may be declared using an operator-function-id.  */
   16204    385477404 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   16205              :         {
   16206            8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   16207            8 :           return error_mark_node;
   16208              :         }
   16209              : 
   16210    385477396 :       if (reqs)
   16211           15 :         error_at (location_of (reqs),
   16212              :                   "requires-clause on declaration of non-function type %qT",
   16213              :                   type);
   16214              :     }
   16215              : 
   16216              :   /* We don't check parameter types here because we can emit a better
   16217              :      error message later.  */
   16218    569434805 :   if (decl_context != PARM)
   16219              :     {
   16220    282551540 :       type = check_var_type (unqualified_id, type, id_loc);
   16221    282551540 :       if (type == error_mark_node)
   16222              :         return error_mark_node;
   16223              :     }
   16224              : 
   16225              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   16226              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   16227              : 
   16228    569434725 :   if (decl_context == PARM || decl_context == CATCHPARM)
   16229              :     {
   16230    287355065 :       if (ctype || in_namespace)
   16231            0 :         error ("cannot use %<::%> in parameter declaration");
   16232              : 
   16233    287355065 :       tree auto_node = type_uses_auto (type);
   16234    287355065 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   16235              :         {
   16236          120 :           bool err_p = true;
   16237          120 :           if (cxx_dialect >= cxx14)
   16238              :             {
   16239          212 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   16240            3 :                 error_at (typespec_loc,
   16241              :                           "cannot declare a parameter with %<decltype(auto)%>");
   16242          109 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16243              :                 {
   16244            5 :                   auto_diagnostic_group g;
   16245            5 :                   gcc_rich_location richloc (typespec_loc);
   16246            5 :                   richloc.add_fixit_insert_after ("<>");
   16247            5 :                   error_at (&richloc,
   16248              :                             "missing template argument list after %qE; template "
   16249              :                             "placeholder not permitted in parameter", c);
   16250            5 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   16251            4 :                     inform (typespec_loc, "or use %<auto%> for an "
   16252              :                             "abbreviated function template");
   16253            5 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   16254            5 :                 }
   16255          104 :               else if (decl_context == CATCHPARM || template_parm_flag)
   16256           14 :                 error_at (typespec_loc,
   16257              :                           "%<auto%> parameter not permitted in this context");
   16258              :               else
   16259              :                 /* Do not issue an error while tentatively parsing a function
   16260              :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   16261              :                    parameter, we don't know yet that this construct won't be
   16262              :                    a function declaration.  Defer the checking to
   16263              :                    cp_parser_parameter_declaration_clause.  */
   16264              :                 err_p = false;
   16265              :             }
   16266              :           else
   16267            8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   16268           30 :           if (err_p)
   16269           30 :             type = error_mark_node;
   16270              :         }
   16271              : 
   16272              :       /* A parameter declared as an array of T is really a pointer to T.
   16273              :          One declared as a function is really a pointer to a function.
   16274              :          One declared as a member is really a pointer to member.  */
   16275              : 
   16276    287355065 :       if (TREE_CODE (type) == ARRAY_TYPE)
   16277              :         {
   16278              :           /* Transfer const-ness of array into that of type pointed to.  */
   16279       744058 :           type = build_pointer_type (TREE_TYPE (type));
   16280       744058 :           type_quals = TYPE_UNQUALIFIED;
   16281       744058 :           array_parameter_p = true;
   16282              :         }
   16283    286611007 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16284        99084 :         type = build_pointer_type (type);
   16285              :     }
   16286              : 
   16287    142221959 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   16288              :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   16289    109696382 :       && !is_xobj_member_function
   16290    669057238 :       && !(unqualified_id
   16291    199238654 :            && identifier_p (unqualified_id)
   16292     99622132 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   16293              :     {
   16294     99616522 :       cp_cv_quals real_quals = memfn_quals;
   16295     99616522 :       if (cxx_dialect < cxx14 && constexpr_p
   16296       685519 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   16297         3820 :         real_quals |= TYPE_QUAL_CONST;
   16298     99616522 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   16299              :     }
   16300              : 
   16301    569434725 :   {
   16302    569434725 :     tree decl = NULL_TREE;
   16303              : 
   16304    569434725 :     if (decl_context == PARM)
   16305              :       {
   16306    286883265 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   16307    286883265 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   16308              : 
   16309    286883265 :         bad_specifiers (decl, BSP_PARM, virtualp,
   16310              :                         memfn_quals != TYPE_UNQUALIFIED,
   16311              :                         inlinep, friendp, raises != NULL_TREE,
   16312              :                         declspecs->locations);
   16313              :       }
   16314    282551460 :     else if (decl_context == FIELD)
   16315              :       {
   16316    139171672 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   16317     19418758 :           if (tree auto_node = type_uses_auto (type))
   16318              :             {
   16319           24 :               location_t tloc = declspecs->locations[ds_type_spec];
   16320           24 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16321            6 :                 error_at (tloc, "invalid use of template-name %qE without an "
   16322              :                           "argument list",
   16323            6 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   16324              :               else
   16325           18 :                 error_at (tloc, "non-static data member declared with "
   16326              :                           "placeholder %qT", auto_node);
   16327           24 :               type = error_mark_node;
   16328              :             }
   16329              : 
   16330              :         /* The C99 flexible array extension.  */
   16331    116553209 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   16332    140265697 :             && TYPE_DOMAIN (type) == NULL_TREE)
   16333              :           {
   16334         1399 :             if (ctype
   16335         1399 :                 && (TREE_CODE (ctype) == UNION_TYPE
   16336         1399 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   16337           84 :               pedwarn (id_loc, OPT_Wpedantic,
   16338              :                        "flexible array member in union is a GCC extension");
   16339              : 
   16340              :             else
   16341              :               {
   16342              :                 /* Array is a flexible member.  */
   16343         1315 :                 if (name)
   16344         1315 :                   pedwarn (id_loc, OPT_Wpedantic,
   16345              :                            "ISO C++ forbids flexible array member %qs", name);
   16346              :                 else
   16347              :                   pedwarn (input_location, OPT_Wpedantic,
   16348              :                            "ISO C++ forbids flexible array members");
   16349              : 
   16350              :                 /* Flexible array member has a null domain.  */
   16351         1315 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16352              :               }
   16353              :           }
   16354              : 
   16355    139171672 :         if (type == error_mark_node)
   16356              :           {
   16357              :             /* Happens when declaring arrays of sizes which
   16358              :                are error_mark_node, for example.  */
   16359           24 :             decl = NULL_TREE;
   16360              :           }
   16361    139171648 :         else if (in_namespace && !friendp)
   16362              :           {
   16363              :             /* Something like struct S { int N::j; };  */
   16364            6 :             error_at (id_loc, "invalid use of %<::%>");
   16365            6 :             return error_mark_node;
   16366              :           }
   16367    139171642 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   16368              :           {
   16369    107129150 :             int publicp = 0;
   16370    107129150 :             tree function_context;
   16371              : 
   16372    107129150 :             if (friendp == 0)
   16373              :               {
   16374              :                 /* This should never happen in pure C++ (the check
   16375              :                    could be an assert).  It could happen in
   16376              :                    Objective-C++ if someone writes invalid code that
   16377              :                    uses a function declaration for an instance
   16378              :                    variable or property (instance variables and
   16379              :                    properties are parsed as FIELD_DECLs, but they are
   16380              :                    part of an Objective-C class, not a C++ class).
   16381              :                    That code is invalid and is caught by this
   16382              :                    check.  */
   16383    100916160 :                 if (!ctype)
   16384              :                   {
   16385            0 :                     error ("declaration of function %qD in invalid context",
   16386              :                            unqualified_id);
   16387            0 :                     return error_mark_node;
   16388              :                   }
   16389              : 
   16390              :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   16391              :                    ARM 9.5 */
   16392    100916160 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   16393              :                   {
   16394            3 :                     error_at (declspecs->locations[ds_virtual],
   16395              :                               "function %qD declared %<virtual%> inside a union",
   16396              :                               unqualified_id);
   16397            3 :                     return error_mark_node;
   16398              :                   }
   16399              : 
   16400      4060455 :                 if (virtualp
   16401    111189602 :                     && identifier_p (unqualified_id)
   16402      4060455 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16403              :                   {
   16404            9 :                     error_at (declspecs->locations[ds_virtual],
   16405              :                               "%qD cannot be declared %<virtual%>, since it "
   16406              :                               "is always static", unqualified_id);
   16407            9 :                     virtualp = 0;
   16408              :                   }
   16409              :               }
   16410              : 
   16411              :             /* Check that the name used for a destructor makes sense.  */
   16412    107129147 :             if (sfk == sfk_destructor)
   16413              :               {
   16414      3021614 :                 tree uqname = id_declarator->u.id.unqualified_name;
   16415              : 
   16416      3021614 :                 if (!ctype)
   16417              :                   {
   16418           12 :                     gcc_assert (friendp);
   16419           12 :                     error_at (id_loc, "expected qualified name in friend "
   16420              :                               "declaration for destructor %qD", uqname);
   16421           12 :                     return error_mark_node;
   16422              :                   }
   16423              : 
   16424      3021602 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   16425              :                   {
   16426            9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   16427              :                               uqname, ctype);
   16428            9 :                     return error_mark_node;
   16429              :                   }
   16430      3021593 :                 if (concept_p)
   16431              :                   {
   16432            9 :                     error_at (declspecs->locations[ds_concept],
   16433              :                               "a destructor cannot be %qs", "concept");
   16434            9 :                     return error_mark_node;
   16435              :                   }
   16436      3021584 :                 if (constexpr_p && cxx_dialect < cxx20)
   16437              :                   {
   16438            6 :                     error_at (declspecs->locations[ds_constexpr],
   16439              :                               "%<constexpr%> destructors only available"
   16440              :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   16441            6 :                     return error_mark_node;
   16442              :                   }
   16443      3021578 :                 if (consteval_p)
   16444              :                   {
   16445            3 :                     error_at (declspecs->locations[ds_consteval],
   16446              :                               "a destructor cannot be %qs", "consteval");
   16447            3 :                     return error_mark_node;
   16448              :                   }
   16449              :               }
   16450    104107533 :             else if (sfk == sfk_constructor && friendp && !ctype)
   16451              :               {
   16452            0 :                 error ("expected qualified name in friend declaration "
   16453              :                        "for constructor %qD",
   16454            0 :                        id_declarator->u.id.unqualified_name);
   16455            0 :                 return error_mark_node;
   16456              :               }
   16457    107129108 :             if (sfk == sfk_constructor)
   16458     22803302 :               if (concept_p)
   16459              :                 {
   16460            9 :                   error_at (declspecs->locations[ds_concept],
   16461              :                             "a constructor cannot be %<concept%>");
   16462            9 :                   return error_mark_node;
   16463              :                 }
   16464     84325806 :             if (concept_p)
   16465              :               {
   16466            9 :                 error_at (declspecs->locations[ds_concept],
   16467              :                           "a concept cannot be a member function");
   16468            9 :                 concept_p = false;
   16469              :               }
   16470    107129090 :             else if (consteval_p
   16471    107852309 :                      && identifier_p (unqualified_id)
   16472    107852300 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16473              :               {
   16474            9 :                 error_at (declspecs->locations[ds_consteval],
   16475              :                           "%qD cannot be %qs", unqualified_id, "consteval");
   16476            9 :                 consteval_p = false;
   16477              :               }
   16478              : 
   16479    107129099 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16480              :               {
   16481        90026 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   16482        90026 :                 if (variable_template_p (tmpl))
   16483              :                   {
   16484            3 :                     auto_diagnostic_group d;
   16485            3 :                     error_at (id_loc, "specialization of variable template "
   16486              :                               "%qD declared as function", tmpl);
   16487            3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   16488              :                             "variable template declared here");
   16489            3 :                     return error_mark_node;
   16490            3 :                   }
   16491              :               }
   16492              : 
   16493              :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   16494    107129096 :             function_context
   16495              :               = (ctype != NULL_TREE
   16496    107129096 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   16497    214258192 :             publicp = ((! friendp || ! staticp)
   16498    107129096 :                        && function_context == NULL_TREE);
   16499              : 
   16500    107129096 :             decl = grokfndecl (ctype, type,
   16501    107129096 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   16502              :                                ? unqualified_id : dname,
   16503              :                                parms,
   16504              :                                unqualified_id,
   16505              :                                declspecs,
   16506              :                                reqs,
   16507              :                                virtualp, flags, memfn_quals, rqual, raises,
   16508              :                                friendp ? -1 : 0, friendp, publicp,
   16509    107129096 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   16510    107129096 :                                        | (8 * consteval_p),
   16511              :                                initialized,
   16512              :                                is_xobj_member_function, sfk,
   16513              :                                funcdef_flag, late_return_type_p,
   16514              :                                template_count, in_namespace,
   16515              :                                attrlist, contract_specifiers, id_loc);
   16516    107129096 :             decl = set_virt_specifiers (decl, virt_specifiers);
   16517    107129096 :             if (decl == NULL_TREE)
   16518           97 :               return error_mark_node;
   16519              : #if 0
   16520              :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   16521              :             /* The decl and setting of decl_attr is also turned off.  */
   16522              :             decl = build_decl_attribute_variant (decl, decl_attr);
   16523              : #endif
   16524              : 
   16525              :             /* [class.conv.ctor]
   16526              : 
   16527              :                A constructor declared without the function-specifier
   16528              :                explicit that can be called with a single parameter
   16529              :                specifies a conversion from the type of its first
   16530              :                parameter to the type of its class.  Such a constructor
   16531              :                is called a converting constructor.  */
   16532    107128999 :             if (explicitp == 2)
   16533      5825193 :               DECL_NONCONVERTING_P (decl) = 1;
   16534              : 
   16535    107128999 :             if (declspecs->explicit_specifier)
   16536       385208 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   16537              :           }
   16538     32042492 :         else if (!staticp
   16539     32042492 :                  && ((current_class_type
   16540     19418749 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   16541              :                                       current_class_type))
   16542     19418653 :                      || (!dependent_type_p (type)
   16543     11793321 :                          && !COMPLETE_TYPE_P (complete_type (type))
   16544         1447 :                          && (!complete_or_array_type_p (type)
   16545         1372 :                              || initialized == SD_UNINITIALIZED))))
   16546              :           {
   16547         1510 :             if (TREE_CODE (type) != ARRAY_TYPE
   16548         1510 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   16549              :               {
   16550          171 :                 if (unqualified_id)
   16551              :                   {
   16552          126 :                     auto_diagnostic_group d;
   16553          126 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   16554              :                               unqualified_id, type);
   16555          126 :                     cxx_incomplete_type_inform (strip_array_types (type));
   16556          126 :                   }
   16557              :                 else
   16558           45 :                   error ("name %qT has incomplete type", type);
   16559              : 
   16560          171 :                 type = error_mark_node;
   16561          171 :                 decl = NULL_TREE;
   16562              :               }
   16563              :           }
   16564     51458209 :         else if (!verify_type_context (input_location,
   16565              :                                        staticp
   16566              :                                        ? TCTX_STATIC_STORAGE
   16567              :                                        : TCTX_FIELD, type))
   16568              :           {
   16569            0 :             type = error_mark_node;
   16570            0 :             decl = NULL_TREE;
   16571              :           }
   16572              :         else
   16573              :           {
   16574     32040976 :             if (friendp)
   16575              :               {
   16576           12 :                 if (unqualified_id)
   16577            9 :                   error_at (id_loc,
   16578              :                             "%qE is neither function nor member function; "
   16579              :                             "cannot be declared friend", unqualified_id);
   16580              :                 else
   16581            3 :                   error ("unnamed field is neither function nor member "
   16582              :                          "function; cannot be declared friend");
   16583           12 :                 return error_mark_node;
   16584              :               }
   16585     32040964 :             decl = NULL_TREE;
   16586              :           }
   16587              : 
   16588    139171497 :         if (friendp)
   16589              :           {
   16590              :             /* Packages tend to use GNU attributes on friends, so we only
   16591              :                warn for standard attributes.  */
   16592      6212959 :             if (attrlist
   16593      6212959 :                 && !funcdef_flag
   16594      6212959 :                 && cxx11_attribute_p (*attrlist))
   16595              :               {
   16596           27 :                 *attrlist = NULL_TREE;
   16597           27 :                 auto_diagnostic_group d;
   16598           27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   16599           27 :                   inform (id_loc, "an attribute that appertains to a friend "
   16600              :                           "declaration that is not a definition is ignored");
   16601           27 :               }
   16602              :             /* Friends are treated specially.  */
   16603      6212959 :             if (ctype == current_class_type)
   16604              :               ;  /* We already issued a permerror.  */
   16605      6212959 :             else if (decl && DECL_NAME (decl))
   16606              :               {
   16607      6212956 :                 set_originating_module (decl, true);
   16608              : 
   16609      6212956 :                 if (initialized)
   16610              :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   16611              :                      in-class defaulted functions, but that breaks grokfndecl.
   16612              :                      So set it here.  */
   16613       206497 :                   funcdef_flag = true;
   16614              : 
   16615      6212956 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   16616      6212956 :                 *attrlist = NULL_TREE;
   16617              : 
   16618      6212956 :                 tree scope = ctype ? ctype : in_namespace;
   16619      6212956 :                 decl = do_friend (scope, unqualified_id, decl,
   16620              :                                   flags, funcdef_flag);
   16621      6212956 :                 return decl;
   16622              :               }
   16623              :             else
   16624            3 :               return error_mark_node;
   16625              :           }
   16626              : 
   16627              :         /* Structure field.  It may not be a function, except for C++.  */
   16628              : 
   16629    132958538 :         if (decl == NULL_TREE)
   16630              :           {
   16631     32042495 :             if (staticp)
   16632              :               {
   16633              :                 /* C++ allows static class members.  All other work
   16634              :                    for this is done by grokfield.  */
   16635     12623743 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   16636              :                                             dname, type);
   16637     12623743 :                 if (unqualified_id
   16638     12623740 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16639              :                   {
   16640        41065 :                     decl = check_explicit_specialization (unqualified_id, decl,
   16641              :                                                           template_count,
   16642              :                                                           concept_p * 8);
   16643        41065 :                     if (decl == error_mark_node)
   16644              :                       return error_mark_node;
   16645              :                   }
   16646     12623743 :                 set_linkage_for_static_data_member (decl);
   16647     12623743 :                 if (concept_p)
   16648           15 :                   error_at (declspecs->locations[ds_concept],
   16649              :                             "static data member %qE declared %qs",
   16650              :                             unqualified_id, "concept");
   16651     12623728 :                 else if (constexpr_p && !initialized)
   16652              :                   {
   16653            9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   16654              :                               "%<constexpr%> static data member %qD must "
   16655              :                               "have an initializer", decl);
   16656            9 :                     constexpr_p = false;
   16657              :                   }
   16658     12623743 :                 if (consteval_p)
   16659            3 :                   error_at (declspecs->locations[ds_consteval],
   16660              :                             "static data member %qE declared %qs",
   16661              :                             unqualified_id, "consteval");
   16662              : 
   16663     12623743 :                 if (inlinep)
   16664        21488 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   16665              : 
   16666     12623743 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   16667     12623743 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   16668              :                   /* Even if there is an in-class initialization, DECL
   16669              :                      is considered undefined until an out-of-class
   16670              :                      definition is provided, unless this is an inline
   16671              :                      variable.  */
   16672      1791956 :                   DECL_EXTERNAL (decl) = 1;
   16673              : 
   16674     12623743 :                 if (thread_p)
   16675              :                   {
   16676          421 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   16677          421 :                     if (!processing_template_decl)
   16678          375 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   16679          421 :                     if (declspecs->gnu_thread_keyword_p)
   16680           34 :                       SET_DECL_GNU_TLS_P (decl);
   16681              :                   }
   16682              : 
   16683              :                 /* Set the constraints on the declaration.  */
   16684     12623743 :                 bool memtmpl = (current_template_depth
   16685     12623743 :                                 > template_class_depth (current_class_type));
   16686     12623743 :                 if (memtmpl)
   16687              :                   {
   16688       373268 :                     tree ci = current_template_constraints ();
   16689       373268 :                     set_constraints (decl, ci);
   16690              :                   }
   16691              :               }
   16692              :             else
   16693              :               {
   16694     19418752 :                 if (concept_p)
   16695              :                   {
   16696           12 :                     error_at (declspecs->locations[ds_concept],
   16697              :                               "non-static data member %qE declared %qs",
   16698              :                               unqualified_id, "concept");
   16699           12 :                     concept_p = false;
   16700           12 :                     constexpr_p = false;
   16701              :                   }
   16702     19418740 :                 else if (constexpr_p)
   16703              :                   {
   16704            9 :                     error_at (declspecs->locations[ds_constexpr],
   16705              :                               "non-static data member %qE declared %qs",
   16706              :                               unqualified_id, "constexpr");
   16707            9 :                     constexpr_p = false;
   16708              :                   }
   16709     19418752 :                 if (constinit_p)
   16710              :                   {
   16711            6 :                     error_at (declspecs->locations[ds_constinit],
   16712              :                               "non-static data member %qE declared %qs",
   16713              :                               unqualified_id, "constinit");
   16714            6 :                     constinit_p = false;
   16715              :                   }
   16716     19418752 :                 if (consteval_p)
   16717              :                   {
   16718            3 :                     error_at (declspecs->locations[ds_consteval],
   16719              :                               "non-static data member %qE declared %qs",
   16720              :                               unqualified_id, "consteval");
   16721            3 :                     consteval_p = false;
   16722              :                   }
   16723     19418752 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   16724     19418752 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   16725     19418752 :                 if (bitfield && !unqualified_id)
   16726       131315 :                   DECL_PADDING_P (decl) = 1;
   16727              : 
   16728     19418752 :                 if (storage_class == sc_mutable)
   16729              :                   {
   16730       146184 :                     DECL_MUTABLE_P (decl) = 1;
   16731       146184 :                     storage_class = sc_none;
   16732              :                   }
   16733              : 
   16734     19418752 :                 if (initialized)
   16735              :                   {
   16736              :                     /* An attempt is being made to initialize a non-static
   16737              :                        member.  This is new in C++11.  */
   16738      2231785 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   16739              : 
   16740              :                     /* If this has been parsed with static storage class, but
   16741              :                        errors forced staticp to be cleared, ensure NSDMI is
   16742              :                        not present.  */
   16743      2231785 :                     if (declspecs->storage_class == sc_static)
   16744            3 :                       DECL_INITIAL (decl) = error_mark_node;
   16745              :                   }
   16746              :               }
   16747              : 
   16748     51461247 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   16749              :                             memfn_quals != TYPE_UNQUALIFIED,
   16750              :                             staticp ? false : inlinep, friendp,
   16751              :                             raises != NULL_TREE,
   16752              :                             declspecs->locations);
   16753              :           }
   16754              :       }
   16755    143379788 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   16756              :       {
   16757     76729169 :         tree original_name;
   16758     76729169 :         int publicp = 0;
   16759              : 
   16760     76729169 :         if (!unqualified_id)
   16761            0 :           return error_mark_node;
   16762              : 
   16763     76729169 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16764              :           original_name = dname;
   16765              :         else
   16766     75902922 :           original_name = unqualified_id;
   16767              :         // FIXME:gcc_assert (original_name == dname);
   16768              : 
   16769     76729169 :         if (storage_class == sc_auto)
   16770            1 :           error_at (declspecs->locations[ds_storage_class],
   16771              :                     "storage class %<auto%> invalid for function %qs", name);
   16772     76729168 :         else if (storage_class == sc_register)
   16773            7 :           error_at (declspecs->locations[ds_storage_class],
   16774              :                     "storage class %<register%> invalid for function %qs",
   16775              :                     name);
   16776     76729161 :         else if (thread_p)
   16777              :           {
   16778           12 :             if (declspecs->gnu_thread_keyword_p)
   16779           12 :               error_at (declspecs->locations[ds_thread],
   16780              :                         "storage class %<__thread%> invalid for function %qs",
   16781              :                         name);
   16782              :             else
   16783            0 :               error_at (declspecs->locations[ds_thread],
   16784              :                         "storage class %<thread_local%> invalid for "
   16785              :                         "function %qs", name);
   16786              :           }
   16787     76729149 :         else if (constinit_p)
   16788            3 :           error_at (declspecs->locations[ds_constinit],
   16789              :                     "%<constinit%> specifier invalid for function %qs", name);
   16790              : 
   16791     76729169 :         if (virt_specifiers)
   16792            6 :           error ("virt-specifiers in %qs not allowed outside a class "
   16793              :                  "definition", name);
   16794              :         /* Function declaration not at top level.
   16795              :            Storage classes other than `extern' are not allowed
   16796              :            and `extern' makes no difference.  */
   16797     76729169 :         if (! toplevel_bindings_p ()
   16798        58469 :             && (storage_class == sc_static
   16799        58460 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   16800     76729181 :             && pedantic)
   16801              :           {
   16802            9 :             if (storage_class == sc_static)
   16803            6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   16804              :                        "%<static%> specifier invalid for function %qs "
   16805              :                        "declared out of global scope", name);
   16806              :             else
   16807            3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   16808              :                        "%<inline%> specifier invalid for function %qs "
   16809              :                        "declared out of global scope", name);
   16810              :           }
   16811              : 
   16812     76729169 :         if (ctype == NULL_TREE)
   16813              :           {
   16814     67949178 :             if (virtualp)
   16815              :               {
   16816            0 :                 error ("virtual non-class function %qs", name);
   16817            0 :                 virtualp = 0;
   16818              :               }
   16819     67949178 :             else if (sfk == sfk_constructor
   16820     67949178 :                      || sfk == sfk_destructor)
   16821              :               {
   16822            3 :                 error (funcdef_flag
   16823              :                        ? G_("%qs defined in a non-class scope")
   16824              :                        : G_("%qs declared in a non-class scope"), name);
   16825            3 :                 sfk = sfk_none;
   16826              :               }
   16827              :           }
   16828     76729169 :         if (consteval_p
   16829     76934479 :             && identifier_p (unqualified_id)
   16830     76934479 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16831              :           {
   16832            9 :             error_at (declspecs->locations[ds_consteval],
   16833              :                       "%qD cannot be %qs", unqualified_id, "consteval");
   16834            9 :             consteval_p = false;
   16835              :           }
   16836              : 
   16837              :         /* Record whether the function is public.  */
   16838     76729169 :         publicp = (ctype != NULL_TREE
   16839     76729169 :                    || storage_class != sc_static);
   16840              : 
   16841    153458338 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   16842              :                            declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
   16843              :                            1, friendp,
   16844              :                            publicp,
   16845     76729169 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   16846     76729169 :                                    | (8 * consteval_p),
   16847              :                            initialized,
   16848              :                            is_xobj_member_function, sfk,
   16849              :                            funcdef_flag,
   16850              :                            late_return_type_p,
   16851              :                            template_count, in_namespace, attrlist,
   16852              :                            contract_specifiers, id_loc);
   16853     76729169 :         if (decl == NULL_TREE)
   16854          532 :           return error_mark_node;
   16855              : 
   16856     76728637 :         if (explicitp == 2)
   16857        10294 :           DECL_NONCONVERTING_P (decl) = 1;
   16858     76728637 :         if (staticp == 1)
   16859              :           {
   16860       109319 :             int invalid_static = 0;
   16861              : 
   16862              :             /* Don't allow a static member function in a class, and forbid
   16863              :                declaring main to be static.  */
   16864       109319 :             if (TREE_CODE (type) == METHOD_TYPE)
   16865              :               {
   16866            0 :                 permerror (input_location, "cannot declare member function %qD to have "
   16867              :                            "static linkage", decl);
   16868            0 :                 invalid_static = 1;
   16869              :               }
   16870       109319 :             else if (current_function_decl)
   16871              :               {
   16872              :                 /* 7.1.1: There can be no static function declarations within a
   16873              :                    block.  */
   16874            9 :                 error_at (declspecs->locations[ds_storage_class],
   16875              :                           "cannot declare static function inside another function");
   16876            9 :                 invalid_static = 1;
   16877              :               }
   16878              : 
   16879            9 :             if (invalid_static)
   16880              :               {
   16881     76728637 :                 staticp = 0;
   16882              :                 storage_class = sc_none;
   16883              :               }
   16884              :           }
   16885     76728637 :         if (declspecs->explicit_specifier)
   16886            3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   16887              :       }
   16888              :     else
   16889              :       {
   16890              :         /* It's a variable.  */
   16891              : 
   16892              :         /* An uninitialized decl with `extern' is a reference.  */
   16893    132818162 :         decl = grokvardecl (type, dname, unqualified_id,
   16894              :                             declspecs,
   16895              :                             initialized,
   16896              :                             type_quals,
   16897              :                             inlinep,
   16898              :                             concept_p,
   16899              :                             template_count,
   16900              :                             ctype ? ctype : in_namespace,
   16901              :                             id_loc);
   16902     66650619 :         if (decl == NULL_TREE)
   16903           52 :           return error_mark_node;
   16904              : 
   16905     66650567 :         bad_specifiers (decl, BSP_VAR, virtualp,
   16906              :                         memfn_quals != TYPE_UNQUALIFIED,
   16907              :                         inlinep, friendp, raises != NULL_TREE,
   16908              :                         declspecs->locations);
   16909              : 
   16910     66650567 :         if (ctype)
   16911              :           {
   16912       483070 :             DECL_CONTEXT (decl) = ctype;
   16913       483070 :             if (staticp == 1)
   16914              :               {
   16915            6 :                 permerror (declspecs->locations[ds_storage_class],
   16916              :                            "%<static%> may not be used when defining "
   16917              :                            "(as opposed to declaring) a static data member");
   16918            6 :                 staticp = 0;
   16919            6 :                 storage_class = sc_none;
   16920              :               }
   16921       483070 :             if (storage_class == sc_register && TREE_STATIC (decl))
   16922              :               {
   16923            0 :                 error ("static member %qD declared %<register%>", decl);
   16924            0 :                 storage_class = sc_none;
   16925              :               }
   16926       483070 :             if (storage_class == sc_extern && pedantic)
   16927              :               {
   16928            0 :                 pedwarn (input_location, OPT_Wpedantic,
   16929              :                          "cannot explicitly declare member %q#D to have "
   16930              :                          "extern linkage", decl);
   16931            0 :                 storage_class = sc_none;
   16932              :               }
   16933              :           }
   16934     66167497 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   16935              :           {
   16936           12 :             error_at (DECL_SOURCE_LOCATION (decl),
   16937              :                       "declaration of %<constexpr%> variable %qD "
   16938              :                       "is not a definition", decl);
   16939           12 :             constexpr_p = false;
   16940              :           }
   16941     66650567 :         if (consteval_p)
   16942              :           {
   16943           13 :             error_at (DECL_SOURCE_LOCATION (decl),
   16944              :                       "a variable cannot be declared %<consteval%>");
   16945           13 :             consteval_p = false;
   16946              :           }
   16947              : 
   16948     66650567 :         if (inlinep)
   16949      6385680 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   16950     66650567 :         if (innermost_code == cdk_decomp)
   16951              :           {
   16952       223936 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   16953       223936 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   16954       223936 :             DECL_ARTIFICIAL (decl) = 1;
   16955       223936 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   16956              :           }
   16957              :       }
   16958              : 
   16959    563221007 :     if (VAR_P (decl) && !initialized)
   16960      7331400 :       if (tree auto_node = type_uses_auto (type))
   16961           99 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16962              :           {
   16963           18 :             location_t loc = declspecs->locations[ds_type_spec];
   16964           18 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   16965           18 :             TREE_TYPE (decl) = error_mark_node;
   16966              :           }
   16967              : 
   16968    563221007 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   16969              :       {
   16970          268 :         if (toplevel_bindings_p ())
   16971              :           {
   16972              :             /* It's common practice (and completely valid) to have a const
   16973              :                be initialized and declared extern.  */
   16974          244 :             if (!(type_quals & TYPE_QUAL_CONST))
   16975           20 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   16976              :                           "%qs initialized and declared %<extern%>", name);
   16977              :           }
   16978              :         else
   16979              :           {
   16980           24 :             error_at (DECL_SOURCE_LOCATION (decl),
   16981              :                       "%qs has both %<extern%> and initializer", name);
   16982           24 :             return error_mark_node;
   16983              :           }
   16984              :       }
   16985              : 
   16986              :     /* Record `register' declaration for warnings on &
   16987              :        and in case doing stupid register allocation.  */
   16988              : 
   16989    563220983 :     if (storage_class == sc_register)
   16990              :       {
   16991         2069 :         DECL_REGISTER (decl) = 1;
   16992              :         /* Warn about register storage specifiers on PARM_DECLs.  */
   16993         2069 :         if (TREE_CODE (decl) == PARM_DECL)
   16994              :           {
   16995           35 :             if (cxx_dialect >= cxx17)
   16996           24 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   16997              :                        "ISO C++17 does not allow %<register%> storage "
   16998              :                        "class specifier");
   16999              :             else
   17000           11 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17001              :                           "%<register%> storage class specifier used");
   17002              :           }
   17003              :       }
   17004    563218914 :     else if (storage_class == sc_extern)
   17005     30332207 :       DECL_THIS_EXTERN (decl) = 1;
   17006    532886707 :     else if (storage_class == sc_static)
   17007     22936361 :       DECL_THIS_STATIC (decl) = 1;
   17008              : 
   17009    563220983 :     if (VAR_P (decl))
   17010              :       {
   17011              :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   17012     79274286 :         if (constexpr_p)
   17013     18938550 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   17014              :         /* And the constinit flag (which only applies to variables).  */
   17015     60335736 :         else if (constinit_p)
   17016          438 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   17017              :       }
   17018    483946697 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   17019              :       {
   17020              :         /* If we saw a return type, record its location.  */
   17021    177644680 :         location_t loc = declspecs->locations[ds_type_spec];
   17022    177644680 :         if (loc == UNKNOWN_LOCATION)
   17023              :           /* Build DECL_RESULT in start_preparsed_function.  */;
   17024    145168725 :         else if (!DECL_RESULT (decl))
   17025              :           {
   17026    145132459 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   17027    145132459 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   17028    145132459 :             DECL_ARTIFICIAL (resdecl) = 1;
   17029    145132459 :             DECL_IGNORED_P (resdecl) = 1;
   17030    145132459 :             DECL_RESULT (decl) = resdecl;
   17031              :           }
   17032        36266 :         else if (funcdef_flag)
   17033            3 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   17034              :       }
   17035              : 
   17036              :     /* Record constancy and volatility on the DECL itself .  There's
   17037              :        no need to do this when processing a template; we'll do this
   17038              :        for the instantiated declaration based on the type of DECL.  */
   17039    563220983 :     if (!processing_template_decl
   17040              :         /* Don't do it for instantiated variable templates either,
   17041              :            cp_apply_type_quals_to_decl should have been called on it
   17042              :            already and might have been overridden in cp_finish_decl
   17043              :            if initializer needs runtime initialization.  */
   17044    563220983 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   17045    189066828 :       cp_apply_type_quals_to_decl (type_quals, decl);
   17046              : 
   17047    563220983 :     return decl;
   17048              :   }
   17049   1011989827 : }
   17050              : 
   17051              : /* Subroutine of start_function.  Ensure that each of the parameter
   17052              :    types (as listed in PARMS) is complete, as is required for a
   17053              :    function definition.  */
   17054              : 
   17055              : static void
   17056    166164470 : require_complete_types_for_parms (tree parms)
   17057              : {
   17058    490534912 :   for (; parms; parms = DECL_CHAIN (parms))
   17059              :     {
   17060    324370442 :       if (dependent_type_p (TREE_TYPE (parms)))
   17061    172683440 :         continue;
   17062    151687002 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   17063    151687002 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   17064              :         {
   17065    151686921 :           relayout_decl (parms);
   17066    151686921 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   17067              : 
   17068    151686921 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   17069    151686921 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   17070    151686921 :                                DECL_SOURCE_LOCATION (parms));
   17071              :         }
   17072              :       else
   17073              :         /* grokparms or complete_type_or_else will have already issued
   17074              :            an error.  */
   17075           81 :         TREE_TYPE (parms) = error_mark_node;
   17076              :     }
   17077    166164470 : }
   17078              : 
   17079              : /* Returns nonzero if T is a local variable.  */
   17080              : 
   17081              : int
   17082    242575570 : local_variable_p (const_tree t)
   17083              : {
   17084    242575570 :   if ((VAR_P (t)
   17085     99216104 :        && (DECL_LOCAL_DECL_P (t)
   17086     99216104 :            || !DECL_CONTEXT (t)
   17087     99175513 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   17088    248909502 :       || (TREE_CODE (t) == PARM_DECL))
   17089    220087262 :     return 1;
   17090              : 
   17091              :   return 0;
   17092              : }
   17093              : 
   17094              : /* Like local_variable_p, but suitable for use as a tree-walking
   17095              :    function.  */
   17096              : 
   17097              : static tree
   17098      5857738 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   17099              :                          void * /*data*/)
   17100              : {
   17101      5857738 :   if (unevaluated_p (TREE_CODE (*tp)))
   17102              :     {
   17103              :       /* DR 2082 permits local variables in unevaluated contexts
   17104              :          within a default argument.  */
   17105           15 :       *walk_subtrees = 0;
   17106           15 :       return NULL_TREE;
   17107              :     }
   17108              : 
   17109      5857723 :   if (local_variable_p (*tp)
   17110      5857723 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   17111              :     return *tp;
   17112      5857723 :   else if (TYPE_P (*tp))
   17113           33 :     *walk_subtrees = 0;
   17114              : 
   17115              :   return NULL_TREE;
   17116              : }
   17117              : 
   17118              : /* Check that ARG, which is a default-argument expression for a
   17119              :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   17120              :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   17121              :    DECL, if there is no DECL available.  */
   17122              : 
   17123              : tree
   17124      2818188 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   17125              : {
   17126      2818188 :   tree var;
   17127      2818188 :   tree decl_type;
   17128              : 
   17129      2818188 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   17130              :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   17131              :        with a default argument.  Ignore the argument for now; we'll
   17132              :        deal with it after the class is complete.  */
   17133              :     return arg;
   17134              : 
   17135      2033990 :   if (TYPE_P (decl))
   17136              :     {
   17137              :       decl_type = decl;
   17138              :       decl = NULL_TREE;
   17139              :     }
   17140              :   else
   17141       556923 :     decl_type = TREE_TYPE (decl);
   17142              : 
   17143      2033990 :   if (arg == error_mark_node
   17144      2033871 :       || decl == error_mark_node
   17145      2033862 :       || TREE_TYPE (arg) == error_mark_node
   17146      4067852 :       || decl_type == error_mark_node)
   17147              :     /* Something already went wrong.  There's no need to check
   17148              :        further.  */
   17149              :     return error_mark_node;
   17150              : 
   17151              :   /* [dcl.fct.default]
   17152              : 
   17153              :      A default argument expression is implicitly converted to the
   17154              :      parameter type.  */
   17155      2033862 :   ++cp_unevaluated_operand;
   17156              :   /* Avoid digest_init clobbering the initializer.  */
   17157      2033862 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   17158      2033862 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   17159              :                                      LOOKUP_IMPLICIT);
   17160      2033862 :   --cp_unevaluated_operand;
   17161              : 
   17162              :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   17163              :      the call sites.  */
   17164      1633871 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   17165       400006 :       && null_ptr_cst_p (arg)
   17166              :       /* Don't lose side-effects as in PR90473.  */
   17167      2412677 :       && !TREE_SIDE_EFFECTS (arg))
   17168       378812 :     return nullptr_node;
   17169              : 
   17170              :   /* [dcl.fct.default]
   17171              : 
   17172              :      Local variables shall not be used in default argument
   17173              :      expressions.
   17174              : 
   17175              :      The keyword `this' shall not be used in a default argument of a
   17176              :      member function.  */
   17177      1655050 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   17178      1655050 :   if (var)
   17179              :     {
   17180            0 :       if (complain & tf_warning_or_error)
   17181              :         {
   17182            0 :           if (DECL_NAME (var) == this_identifier)
   17183            0 :             permerror (input_location, "default argument %qE uses %qD",
   17184              :                        arg, var);
   17185              :           else
   17186            0 :             error ("default argument %qE uses local variable %qD", arg, var);
   17187              :         }
   17188            0 :       return error_mark_node;
   17189              :     }
   17190              : 
   17191              :   /* All is well.  */
   17192      1655050 :   return arg;
   17193              : }
   17194              : 
   17195              : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   17196              : 
   17197              : static tree
   17198    274417437 : type_is_deprecated (tree type)
   17199              : {
   17200    404807532 :   enum tree_code code;
   17201    404807532 :   if (TREE_DEPRECATED (type))
   17202              :     return type;
   17203    404767963 :   if (TYPE_NAME (type))
   17204              :     {
   17205    270328037 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   17206              :         return type;
   17207              :       else
   17208              :         {
   17209    270328031 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17210    270328031 :           return NULL_TREE;
   17211              :         }
   17212              :     }
   17213              : 
   17214              :   /* Do warn about using typedefs to a deprecated class.  */
   17215    134439926 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17216            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17217              : 
   17218    134439926 :   code = TREE_CODE (type);
   17219              : 
   17220    134439926 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17221    134439926 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17222              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17223    130276910 :     return type_is_deprecated (TREE_TYPE (type));
   17224              : 
   17225       113185 :   if (TYPE_PTRMEMFUNC_P (type))
   17226       113185 :     return type_is_deprecated
   17227       113185 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17228              : 
   17229              :   return NULL_TREE;
   17230              : }
   17231              : 
   17232              : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   17233              : 
   17234              : static tree
   17235    275601440 : type_is_unavailable (tree type)
   17236              : {
   17237    406697544 :   enum tree_code code;
   17238    406697544 :   if (TREE_UNAVAILABLE (type))
   17239              :     return type;
   17240    406697538 :   if (TYPE_NAME (type))
   17241              :     {
   17242    271551549 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   17243              :         return type;
   17244              :       else
   17245              :         {
   17246    271551543 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17247    271551543 :           return NULL_TREE;
   17248              :         }
   17249              :     }
   17250              : 
   17251              :   /* Do warn about using typedefs to a deprecated class.  */
   17252    135145989 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17253            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17254              : 
   17255    135145989 :   code = TREE_CODE (type);
   17256              : 
   17257    135145989 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17258    135145989 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17259              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17260    130876631 :     return type_is_unavailable (TREE_TYPE (type));
   17261              : 
   17262       219473 :   if (TYPE_PTRMEMFUNC_P (type))
   17263       219473 :     return type_is_unavailable
   17264       219473 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17265              : 
   17266              :   return NULL_TREE;
   17267              : }
   17268              : 
   17269              : /* Decode the list of parameter types for a function type.
   17270              :    Given the list of things declared inside the parens,
   17271              :    return a list of types.
   17272              : 
   17273              :    If this parameter does not end with an ellipsis, we append
   17274              :    void_list_node.
   17275              : 
   17276              :    *PARMS is set to the chain of PARM_DECLs created.  */
   17277              : 
   17278              : tree
   17279    188922668 : grokparms (tree parmlist, tree *parms)
   17280              : {
   17281    188922668 :   tree result = NULL_TREE;
   17282    188922668 :   tree decls = NULL_TREE;
   17283    188922668 :   tree parm;
   17284    188922668 :   int any_error = 0;
   17285              : 
   17286    465130393 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   17287              :     {
   17288    462831528 :       tree type = NULL_TREE;
   17289    462831528 :       tree init = TREE_PURPOSE (parm);
   17290    462831528 :       tree decl = TREE_VALUE (parm);
   17291              : 
   17292    462831528 :       if (parm == void_list_node || parm == explicit_void_list_node)
   17293              :         break;
   17294              : 
   17295    276207738 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   17296              :         {
   17297          186 :           any_error = 1;
   17298          186 :           continue;
   17299              :         }
   17300              : 
   17301    276207552 :       type = TREE_TYPE (decl);
   17302    276207552 :       if (VOID_TYPE_P (type))
   17303              :         {
   17304           79 :           if (same_type_p (type, void_type_node)
   17305           70 :               && !init
   17306           58 :               && !DECL_NAME (decl) && !result
   17307          104 :               && TREE_CHAIN (parm) == void_list_node)
   17308              :             /* DR 577: A parameter list consisting of a single
   17309              :                unnamed parameter of non-dependent type 'void'.  */
   17310              :             break;
   17311           66 :           else if (cv_qualified_p (type))
   17312            9 :             error_at (DECL_SOURCE_LOCATION (decl),
   17313              :                       "invalid use of cv-qualified type %qT in "
   17314              :                       "parameter declaration", type);
   17315              :           else
   17316           57 :             error_at (DECL_SOURCE_LOCATION (decl),
   17317              :                       "invalid use of type %<void%> in parameter "
   17318              :                       "declaration");
   17319              :           /* It's not a good idea to actually create parameters of
   17320              :              type `void'; other parts of the compiler assume that a
   17321              :              void type terminates the parameter list.  */
   17322           66 :           type = error_mark_node;
   17323           66 :           TREE_TYPE (decl) = error_mark_node;
   17324              :         }
   17325              : 
   17326    276207539 :       if (type != error_mark_node)
   17327              :         {
   17328    276207473 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17329              :             {
   17330    275601440 :               tree unavailtype = type_is_unavailable (type);
   17331    275601440 :               if (unavailtype)
   17332           12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   17333              :             }
   17334    276207473 :           if (deprecated_state != DEPRECATED_SUPPRESS
   17335    276207473 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17336              :             {
   17337    274417437 :               tree deptype = type_is_deprecated (type);
   17338    274417437 :               if (deptype)
   17339        39575 :                 cp_handle_deprecated_or_unavailable (deptype);
   17340              :             }
   17341              : 
   17342              :           /* [dcl.fct] "A parameter with volatile-qualified type is
   17343              :              deprecated."  */
   17344    276207473 :           if (CP_TYPE_VOLATILE_P (type))
   17345          504 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   17346              :                         "%<volatile%>-qualified parameter is "
   17347              :                         "deprecated");
   17348              : 
   17349              :           /* Top-level qualifiers on the parameters are
   17350              :              ignored for function types.  */
   17351    276207473 :           type = cp_build_qualified_type (type, 0);
   17352    276207473 :           if (TREE_CODE (type) == METHOD_TYPE)
   17353              :             {
   17354            0 :               error ("parameter %qD invalidly declared method type", decl);
   17355            0 :               type = build_pointer_type (type);
   17356            0 :               TREE_TYPE (decl) = type;
   17357              :             }
   17358    276207473 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   17359              :             {
   17360              :               /* Before C++17 DR 393:
   17361              :                  [dcl.fct]/6, parameter types cannot contain pointers
   17362              :                  (references) to arrays of unknown bound.  */
   17363      1684873 :               tree t = TREE_TYPE (type);
   17364      1684873 :               int ptr = TYPE_PTR_P (type);
   17365              : 
   17366      1847665 :               while (1)
   17367              :                 {
   17368      1766269 :                   if (TYPE_PTR_P (t))
   17369              :                     ptr = 1;
   17370      1688048 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   17371              :                     break;
   17372         3185 :                   else if (!TYPE_DOMAIN (t))
   17373              :                     break;
   17374        81396 :                   t = TREE_TYPE (t);
   17375              :                 }
   17376      1684873 :               if (TREE_CODE (t) == ARRAY_TYPE)
   17377           16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   17378              :                          ptr
   17379              :                          ? G_("parameter %qD includes pointer to array of "
   17380              :                               "unknown bound %qT")
   17381              :                          : G_("parameter %qD includes reference to array of "
   17382              :                               "unknown bound %qT"),
   17383              :                          decl, t);
   17384              :             }
   17385              : 
   17386    276207473 :           if (init && !processing_template_decl)
   17387      1341112 :             init = check_default_argument (decl, init, tf_warning_or_error);
   17388              :         }
   17389              : 
   17390    276207539 :       DECL_CHAIN (decl) = decls;
   17391    276207539 :       decls = decl;
   17392    276207539 :       result = tree_cons (init, type, result);
   17393              :     }
   17394    188922668 :   decls = nreverse (decls);
   17395    188922668 :   result = nreverse (result);
   17396    188922668 :   if (parm)
   17397    186623803 :     result = chainon (result, void_list_node);
   17398    188922668 :   *parms = decls;
   17399    188922668 :   if (any_error)
   17400          172 :     result = NULL_TREE;
   17401              : 
   17402          172 :   if (any_error)
   17403              :     /* We had parm errors, recover by giving the function (...) type.  */
   17404          172 :     result = NULL_TREE;
   17405              : 
   17406    188922668 :   return result;
   17407              : }
   17408              : 
   17409              : 
   17410              : /* D is a constructor or overloaded `operator='.
   17411              : 
   17412              :    Let T be the class in which D is declared. Then, this function
   17413              :    returns:
   17414              : 
   17415              :    -1 if D's is an ill-formed constructor or copy assignment operator
   17416              :       whose first parameter is of type `T'.
   17417              :    0  if D is not a copy constructor or copy assignment
   17418              :       operator.
   17419              :    1  if D is a copy constructor or copy assignment operator whose
   17420              :       first parameter is a reference to non-const qualified T.
   17421              :    2  if D is a copy constructor or copy assignment operator whose
   17422              :       first parameter is a reference to const qualified T.
   17423              : 
   17424              :    This function can be used as a predicate. Positive values indicate
   17425              :    a copy constructor and nonzero values indicate a copy assignment
   17426              :    operator.  */
   17427              : 
   17428              : int
   17429    380574121 : copy_fn_p (const_tree d)
   17430              : {
   17431    380574121 :   tree args;
   17432    380574121 :   tree arg_type;
   17433    380574121 :   int result = 1;
   17434              : 
   17435    380574121 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   17436              : 
   17437    380574121 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17438    380574121 :       || (DECL_TEMPLATE_INFO (d)
   17439    171189234 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17440              :     /* Instantiations of template member functions are never copy
   17441              :        functions.  Note that member functions of templated classes are
   17442              :        represented as template functions internally, and we must
   17443              :        accept those as copy functions.  */
   17444              :     return 0;
   17445              : 
   17446    326254109 :   if (!DECL_CONSTRUCTOR_P (d)
   17447    326254109 :       && DECL_NAME (d) != assign_op_identifier)
   17448              :     return 0;
   17449              : 
   17450    325464101 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17451              :     {
   17452          126 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17453          126 :       if (!TYPE_REF_P (object_param)
   17454          120 :           || TYPE_REF_IS_RVALUE (object_param)
   17455              :           /* Reject unrelated object parameters. */
   17456          108 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17457          234 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17458           24 :         return 0;
   17459          102 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17460              :     }
   17461              :   else
   17462    325463975 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17463    325464077 :   if (!args)
   17464              :     return 0;
   17465              : 
   17466    325456553 :   arg_type = TREE_VALUE (args);
   17467    325456553 :   if (arg_type == error_mark_node)
   17468              :     return 0;
   17469              : 
   17470    325456518 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   17471              :     {
   17472              :       /* Pass by value copy assignment operator.  */
   17473              :       result = -1;
   17474              :     }
   17475    325455307 :   else if (TYPE_REF_P (arg_type)
   17476    208777061 :            && !TYPE_REF_IS_RVALUE (arg_type)
   17477    460780295 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   17478              :     {
   17479    112715650 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   17480    112551916 :         result = 2;
   17481              :     }
   17482              :   else
   17483              :     return 0;
   17484              : 
   17485    112716861 :   args = TREE_CHAIN (args);
   17486              : 
   17487    115461922 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17488              :     /* There are more non-optional args.  */
   17489              :     return 0;
   17490              : 
   17491              :   return result;
   17492              : }
   17493              : 
   17494              : /* D is a constructor or overloaded `operator='.
   17495              : 
   17496              :    Let T be the class in which D is declared. Then, this function
   17497              :    returns true when D is a move constructor or move assignment
   17498              :    operator, false otherwise.  */
   17499              : 
   17500              : bool
   17501    176093875 : move_fn_p (const_tree d)
   17502              : {
   17503    176093875 :   if (cxx_dialect == cxx98)
   17504              :     /* There are no move constructors if we are in C++98 mode.  */
   17505              :     return false;
   17506              : 
   17507    176022618 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17508    176022618 :       || (DECL_TEMPLATE_INFO (d)
   17509     73450212 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17510              :     /* Instantiations of template member functions are never move
   17511              :        functions.  Note that member functions of templated classes are
   17512              :        represented as template functions internally, and we must
   17513              :        accept those as move functions.  */
   17514              :     return 0;
   17515              : 
   17516    145051924 :   return move_signature_fn_p (d);
   17517              : }
   17518              : 
   17519              : /* D is a constructor or overloaded `operator='.
   17520              : 
   17521              :    Then, this function returns true when D has the same signature as a move
   17522              :    constructor or move assignment operator (because either it is such a
   17523              :    ctor/op= or it is a template specialization with the same signature),
   17524              :    false otherwise.  */
   17525              : 
   17526              : bool
   17527    145051924 : move_signature_fn_p (const_tree d)
   17528              : {
   17529    145051924 :   tree args;
   17530    145051924 :   tree arg_type;
   17531    145051924 :   bool result = false;
   17532              : 
   17533    145051924 :   if (!DECL_CONSTRUCTOR_P (d)
   17534    145051924 :       && DECL_NAME (d) != assign_op_identifier)
   17535              :     return 0;
   17536              : 
   17537    145051855 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17538              :     {
   17539           68 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17540           68 :       if (!TYPE_REF_P (object_param)
   17541           64 :           || TYPE_REF_IS_RVALUE (object_param)
   17542              :           /* Reject unrelated object parameters. */
   17543           56 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17544          124 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17545           16 :         return 0;
   17546           52 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17547              :     }
   17548              :   else
   17549    145051787 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17550    145051839 :   if (!args)
   17551              :     return 0;
   17552              : 
   17553    145049049 :   arg_type = TREE_VALUE (args);
   17554    145049049 :   if (arg_type == error_mark_node)
   17555              :     return 0;
   17556              : 
   17557    145049041 :   if (TYPE_REF_P (arg_type)
   17558     72128416 :       && TYPE_REF_IS_RVALUE (arg_type)
   17559    202787681 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   17560              :                       DECL_CONTEXT (d)))
   17561              :     result = true;
   17562              : 
   17563    145049041 :   args = TREE_CHAIN (args);
   17564              : 
   17565    160498460 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17566              :     /* There are more non-optional args.  */
   17567              :     return false;
   17568              : 
   17569              :   return result;
   17570              : }
   17571              : 
   17572              : /* Remember any special properties of member function DECL.  */
   17573              : 
   17574              : void
   17575    362865503 : grok_special_member_properties (tree decl)
   17576              : {
   17577    362865503 :   tree class_type;
   17578              : 
   17579    362865503 :   if (TREE_CODE (decl) == USING_DECL
   17580    362865503 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   17581              :     return;
   17582              : 
   17583    341690731 :   class_type = DECL_CONTEXT (decl);
   17584    341690731 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   17585              :     {
   17586    156498560 :       int ctor = copy_fn_p (decl);
   17587              : 
   17588    156498560 :       if (!DECL_ARTIFICIAL (decl))
   17589    104028554 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   17590              : 
   17591    156498560 :       if (ctor > 0)
   17592              :         {
   17593              :           /* [class.copy]
   17594              : 
   17595              :              A non-template constructor for class X is a copy
   17596              :              constructor if its first parameter is of type X&, const
   17597              :              X&, volatile X& or const volatile X&, and either there
   17598              :              are no other parameters or else all other parameters have
   17599              :              default arguments.  */
   17600     33108877 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   17601     33108877 :           if (ctor > 1)
   17602     33032747 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   17603              :         }
   17604              : 
   17605    156498560 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   17606     33810871 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   17607              : 
   17608    156498560 :       if (is_list_ctor (decl))
   17609      1488579 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   17610              : 
   17611    156498560 :       if (maybe_constexpr_fn (decl)
   17612    156498560 :           && !ctor && !move_fn_p (decl))
   17613     55170886 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   17614              :     }
   17615    185192171 :   else if (DECL_NAME (decl) == assign_op_identifier)
   17616              :     {
   17617              :       /* [class.copy]
   17618              : 
   17619              :          A non-template assignment operator for class X is a copy
   17620              :          assignment operator if its parameter is of type X, X&, const
   17621              :          X&, volatile X& or const volatile X&.  */
   17622              : 
   17623     15119602 :       int assop = copy_fn_p (decl);
   17624              : 
   17625     15119602 :       if (assop)
   17626              :         {
   17627      7729350 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   17628      7729350 :           if (assop != 1)
   17629      7701756 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   17630              :         }
   17631              :     }
   17632    170072569 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   17633      2899415 :     TYPE_HAS_CONVERSION (class_type) = true;
   17634              : 
   17635              :   /* Destructors are handled in check_methods.  */
   17636              : }
   17637              : 
   17638              : /* Check a constructor DECL has the correct form.  Complains
   17639              :    if the class has a constructor of the form X(X).  */
   17640              : 
   17641              : bool
   17642     47835326 : grok_ctor_properties (const_tree ctype, const_tree decl)
   17643              : {
   17644     47835326 :   int ctor_parm = copy_fn_p (decl);
   17645              : 
   17646     47835326 :   if (ctor_parm < 0)
   17647              :     {
   17648              :       /* [class.copy]
   17649              : 
   17650              :          A declaration of a constructor for a class X is ill-formed if
   17651              :          its first parameter is of type (optionally cv-qualified) X
   17652              :          and either there are no other parameters or else all other
   17653              :          parameters have default arguments.
   17654              : 
   17655              :          We *don't* complain about member template instantiations that
   17656              :          have this form, though; they can occur as we try to decide
   17657              :          what constructor to use during overload resolution.  Since
   17658              :          overload resolution will never prefer such a constructor to
   17659              :          the non-template copy constructor (which is either explicitly
   17660              :          or implicitly defined), there's no need to worry about their
   17661              :          existence.  Theoretically, they should never even be
   17662              :          instantiated, but that's hard to forestall.  */
   17663            9 :       error_at (DECL_SOURCE_LOCATION (decl),
   17664              :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   17665              :                 ctype, ctype);
   17666            9 :       return false;
   17667              :     }
   17668              : 
   17669              :   return true;
   17670              : }
   17671              : 
   17672              : /* DECL is a declaration for an overloaded or conversion operator.  If
   17673              :    COMPLAIN is true, errors are issued for invalid declarations.  */
   17674              : 
   17675              : bool
   17676     60478874 : grok_op_properties (tree decl, bool complain)
   17677              : {
   17678     60478874 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   17679     60478874 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   17680     60478874 :   tree name = DECL_NAME (decl);
   17681     60478874 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   17682              : 
   17683     60478874 :   tree class_type = DECL_CONTEXT (decl);
   17684     60478874 :   if (class_type && !CLASS_TYPE_P (class_type))
   17685              :     class_type = NULL_TREE;
   17686              : 
   17687     60478874 :   tree_code operator_code;
   17688     60478874 :   unsigned op_flags;
   17689     60478874 :   if (IDENTIFIER_CONV_OP_P (name))
   17690              :     {
   17691              :       /* Conversion operators are TYPE_EXPR for the purposes of this
   17692              :          function.  */
   17693              :       operator_code = TYPE_EXPR;
   17694              :       op_flags = OVL_OP_FLAG_UNARY;
   17695              :     }
   17696              :   else
   17697              :     {
   17698     57962704 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   17699              : 
   17700     57962704 :       operator_code = ovl_op->tree_code;
   17701     57962704 :       op_flags = ovl_op->flags;
   17702     57962704 :       gcc_checking_assert (operator_code != ERROR_MARK);
   17703     57962704 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   17704              :     }
   17705              : 
   17706     57962704 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   17707              :     {
   17708              :       /* operator new and operator delete are quite special.  */
   17709       326337 :       if (class_type)
   17710         7143 :         switch (op_flags)
   17711              :           {
   17712         4797 :           case OVL_OP_FLAG_ALLOC:
   17713         4797 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   17714         4797 :             break;
   17715              : 
   17716         2075 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   17717         2075 :             TYPE_GETS_DELETE (class_type) |= 1;
   17718         2075 :             break;
   17719              : 
   17720          132 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   17721          132 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   17722          132 :             break;
   17723              : 
   17724          139 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   17725          139 :             TYPE_GETS_DELETE (class_type) |= 2;
   17726          139 :             break;
   17727              : 
   17728            0 :           default:
   17729            0 :             gcc_unreachable ();
   17730              :           }
   17731              : 
   17732              :       /* [basic.std.dynamic.allocation]/1:
   17733              : 
   17734              :          A program is ill-formed if an allocation function is declared
   17735              :          in a namespace scope other than global scope or declared
   17736              :          static in global scope.
   17737              : 
   17738              :          The same also holds true for deallocation functions.  */
   17739       326337 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   17740              :         {
   17741       319194 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   17742              :             {
   17743            6 :               error_at (loc, "%qD may not be declared within a namespace",
   17744              :                         decl);
   17745            6 :               return false;
   17746              :             }
   17747              : 
   17748       319188 :           if (!TREE_PUBLIC (decl))
   17749              :             {
   17750            6 :               error_at (loc, "%qD may not be declared as static", decl);
   17751            6 :               return false;
   17752              :             }
   17753              :         }
   17754              : 
   17755              :       /* Check for replaceable global new/delete operators with
   17756              :          const std::nothrow_t & last argument, other replaceable global
   17757              :          new/delete operators are marked in cxx_init_decl_processing.  */
   17758       326325 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   17759              :         {
   17760       319182 :           tree args = argtypes;
   17761       319182 :           if (args
   17762       319170 :               && args != void_list_node
   17763       957504 :               && same_type_p (TREE_VALUE (args),
   17764              :                               (op_flags & OVL_OP_FLAG_DELETE)
   17765              :                               ? ptr_type_node : size_type_node))
   17766              :             {
   17767       319140 :               args = TREE_CHAIN (args);
   17768       319140 :               if (aligned_allocation_fn_p (decl))
   17769       102724 :                 args = TREE_CHAIN (args);
   17770       319140 :               if (args
   17771       319134 :                   && args != void_list_node
   17772       532153 :                   && TREE_CHAIN (args) == void_list_node)
   17773              :                 {
   17774       187288 :                   tree t = TREE_VALUE (args);
   17775       187288 :                   if (TYPE_REF_P (t)
   17776       106235 :                       && !TYPE_REF_IS_RVALUE (t)
   17777       106235 :                       && (t = TREE_TYPE (t))
   17778       106235 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   17779       293063 :                       && is_std_class (t, "nothrow_t"))
   17780       105775 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   17781              :                 }
   17782              :             }
   17783              :         }
   17784              : 
   17785       326325 :       if (op_flags & OVL_OP_FLAG_DELETE)
   17786              :         {
   17787       186894 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   17788       186894 :           coerce_delete_type (decl, loc);
   17789              :         }
   17790              :       else
   17791              :         {
   17792       139431 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   17793       139431 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   17794              :         }
   17795              : 
   17796       326325 :       return true;
   17797              :     }
   17798              : 
   17799              :   /* An operator function must either be a non-static member function
   17800              :      or have at least one parameter of a class, a reference to a class,
   17801              :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   17802     60152537 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   17803              :     {
   17804     14996764 :       if (operator_code == TYPE_EXPR
   17805     14996764 :           || operator_code == COMPONENT_REF
   17806     14996743 :           || operator_code == NOP_EXPR)
   17807              :         {
   17808           33 :           error_at (loc, "%qD must be a non-static member function", decl);
   17809           33 :           return false;
   17810              :         }
   17811              : 
   17812     14996731 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   17813              :         {
   17814       121707 :           if (! DECL_STATIC_FUNCTION_P (decl))
   17815              :             {
   17816           12 :               error_at (loc, "%qD must be a member function", decl);
   17817           12 :               return false;
   17818              :             }
   17819       121695 :           if (cxx_dialect < cxx23
   17820              :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   17821       209614 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   17822              :               /* For instantiations, we have diagnosed this already.  */
   17823       226488 :               && ! DECL_USE_TEMPLATE (decl))
   17824       104787 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   17825              :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   17826              :                      decl);
   17827       121695 :           if (operator_code == ARRAY_REF)
   17828              :             /* static operator[] should have exactly one argument
   17829              :                for C++20 and earlier, so that it isn't multidimensional.  */
   17830              :             op_flags = OVL_OP_FLAG_UNARY;
   17831              :         }
   17832     14875024 :       else if (DECL_STATIC_FUNCTION_P (decl))
   17833              :         {
   17834            9 :           error_at (loc, "%qD must be either a non-static member "
   17835              :                     "function or a non-member function", decl);
   17836            9 :           return false;
   17837              :         }
   17838              :       else
   17839       413224 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   17840              :           {
   17841     15288239 :             if (!arg || arg == void_list_node)
   17842              :               {
   17843           18 :                 if (complain)
   17844           15 :                   error_at (loc, "%qD must have an argument of class or "
   17845              :                             "enumerated type", decl);
   17846           18 :                 return false;
   17847              :               }
   17848              : 
   17849     15288221 :             tree type = non_reference (TREE_VALUE (arg));
   17850     15288221 :             if (type == error_mark_node)
   17851              :               return false;
   17852              : 
   17853              :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   17854              :                because these checks are performed even on template
   17855              :                functions.  */
   17856     15288218 :             if (MAYBE_CLASS_TYPE_P (type)
   17857      1384340 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   17858              :               break;
   17859       413224 :           }
   17860              :     }
   17861              : 
   17862     60152424 :   if (operator_code == CALL_EXPR)
   17863              :     /* There are no further restrictions on the arguments to an overloaded
   17864              :        "operator ()".  */
   17865              :     return true;
   17866              : 
   17867              :   /* C++23 allows an arbitrary number of parameters and default arguments for
   17868              :      operator[], and none of the other checks below apply.  */
   17869     49082457 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   17870              :     return true;
   17871              : 
   17872     48883785 :   if (operator_code == COND_EXPR)
   17873              :     {
   17874              :       /* 13.4.0.3 */
   17875            6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   17876            6 :       return false;
   17877              :     }
   17878              : 
   17879              :   /* Count the number of arguments and check for ellipsis.  */
   17880              :   int arity = 0;
   17881    138725508 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   17882              :     {
   17883     89841744 :       if (!arg)
   17884              :         {
   17885           15 :           error_at (loc, "%qD must not have variable number of arguments",
   17886              :                     decl);
   17887           15 :           return false;
   17888              :         }
   17889     89841729 :       ++arity;
   17890              :     }
   17891              :   /* FIXME: We need tests for these errors with xobj member functions.  */
   17892              :   /* Verify correct number of arguments.  */
   17893     48883764 :   switch (op_flags)
   17894              :     {
   17895     10127630 :     case OVL_OP_FLAG_AMBIARY:
   17896     10127630 :       if (arity == 1)
   17897              :         {
   17898              :           /* We have a unary instance of an ambi-ary op.  Remap to the
   17899              :              unary one.  */
   17900      4383559 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   17901      4383559 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   17902      4383559 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   17903      4383559 :           operator_code = ovl_op->tree_code;
   17904      4383559 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   17905              :         }
   17906      5744071 :       else if (arity != 2)
   17907              :         {
   17908              :           /* This was an ambiguous operator but is invalid. */
   17909            3 :           error_at (loc,
   17910              :                     methodp
   17911              :                     ? G_("%qD must have either zero or one argument")
   17912              :                     : G_("%qD must have either one or two arguments"), decl);
   17913            3 :           return false;
   17914              :         }
   17915      5744068 :       else if ((operator_code == POSTINCREMENT_EXPR
   17916      5744068 :                 || operator_code == POSTDECREMENT_EXPR)
   17917      2697937 :                && ! processing_template_decl
   17918              :                /* x++ and x--'s second argument must be an int.  */
   17919      7549772 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   17920              :                                  integer_type_node))
   17921              :         {
   17922           15 :           error_at (loc,
   17923              :                     methodp
   17924              :                     ? G_("postfix %qD must have %<int%> as its argument")
   17925              :                     : G_("postfix %qD must have %<int%> as its second argument"),
   17926              :                     decl);
   17927           15 :           return false;
   17928              :         }
   17929              :       break;
   17930              : 
   17931      3542270 :     case OVL_OP_FLAG_UNARY:
   17932      3542270 :       if (arity != 1)
   17933              :         {
   17934            9 :           error_at (loc,
   17935              :                     methodp
   17936              :                     ? G_("%qD must have no arguments")
   17937              :                     : G_("%qD must have exactly one argument"), decl);
   17938            9 :           return false;
   17939              :         }
   17940              :       break;
   17941              : 
   17942     35213864 :     case OVL_OP_FLAG_BINARY:
   17943     35213864 :       if (arity != 2)
   17944              :         {
   17945            3 :           error_at (loc,
   17946              :                     methodp
   17947              :                     ? G_("%qD must have exactly one argument")
   17948              :                     : G_("%qD must have exactly two arguments"), decl);
   17949            3 :           return false;
   17950              :         }
   17951              :       break;
   17952              : 
   17953            0 :     default:
   17954            0 :       gcc_unreachable ();
   17955              :     }
   17956              : 
   17957              :   /* There can be no default arguments.  */
   17958    138725367 :   for (tree arg = argtypes; arg && arg != void_list_node;
   17959     89841633 :        arg = TREE_CHAIN (arg))
   17960     89841648 :     if (TREE_PURPOSE (arg))
   17961              :       {
   17962           15 :         TREE_PURPOSE (arg) = NULL_TREE;
   17963           15 :         error_at (loc, "%qD cannot have default arguments", decl);
   17964           15 :         return false;
   17965              :       }
   17966              : 
   17967              :   /* At this point the declaration is well-formed.  It may not be
   17968              :      sensible though.  */
   17969              : 
   17970              :   /* Check member function warnings only on the in-class declaration.
   17971              :      There's no point warning on an out-of-class definition.  */
   17972     48883719 :   if (class_type && class_type != current_class_type)
   17973              :     return true;
   17974              : 
   17975              :   /* Warn about conversion operators that will never be used.  */
   17976     47052349 :   if (IDENTIFIER_CONV_OP_P (name)
   17977      2515724 :       && ! DECL_TEMPLATE_INFO (decl)
   17978     48042628 :       && warn_class_conversion)
   17979              :     {
   17980       990246 :       tree t = TREE_TYPE (name);
   17981       990246 :       int ref = TYPE_REF_P (t);
   17982              : 
   17983       990246 :       if (ref)
   17984        20881 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   17985              : 
   17986       990246 :       if (VOID_TYPE_P (t))
   17987            9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   17988              :                     "will never use a type conversion operator", class_type);
   17989       990237 :       else if (class_type)
   17990              :         {
   17991       990237 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   17992           24 :             warning_at (loc, OPT_Wclass_conversion,
   17993              :                         ref
   17994              :                         ? G_("converting %qT to a reference to the same type "
   17995              :                              "will never use a type conversion operator")
   17996              :                         : G_("converting %qT to the same type "
   17997              :                              "will never use a type conversion operator"),
   17998              :                         class_type);
   17999              :           /* Don't force t to be complete here.  */
   18000       990222 :           else if (MAYBE_CLASS_TYPE_P (t)
   18001       566713 :                    && COMPLETE_TYPE_P (t)
   18002       151845 :                    && DERIVED_FROM_P (t, class_type))
   18003           30 :             warning_at (loc, OPT_Wclass_conversion,
   18004              :                         ref
   18005              :                         ? G_("converting %qT to a reference to a base class "
   18006              :                              "%qT will never use a type conversion operator")
   18007              :                         : G_("converting %qT to a base class %qT "
   18008              :                              "will never use a type conversion operator"),
   18009              :                         class_type, t);
   18010              :         }
   18011              :     }
   18012              : 
   18013     47052349 :   if (!warn_ecpp)
   18014              :     return true;
   18015              : 
   18016              :   /* Effective C++ rules below.  */
   18017              : 
   18018              :   /* More Effective C++ rule 7.  */
   18019           54 :   if (operator_code == TRUTH_ANDIF_EXPR
   18020           54 :       || operator_code == TRUTH_ORIF_EXPR
   18021           54 :       || operator_code == COMPOUND_EXPR)
   18022            0 :     warning_at (loc, OPT_Weffc__,
   18023              :                 "user-defined %qD always evaluates both arguments", decl);
   18024              : 
   18025              :   /* More Effective C++ rule 6.  */
   18026           54 :   if (operator_code == POSTINCREMENT_EXPR
   18027              :       || operator_code == POSTDECREMENT_EXPR
   18028              :       || operator_code == PREINCREMENT_EXPR
   18029           54 :       || operator_code == PREDECREMENT_EXPR)
   18030              :     {
   18031            0 :       tree arg = TREE_VALUE (argtypes);
   18032            0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   18033            0 :       if (methodp || TYPE_REF_P (arg))
   18034            0 :         arg = TREE_TYPE (arg);
   18035            0 :       arg = TYPE_MAIN_VARIANT (arg);
   18036              : 
   18037            0 :       if (operator_code == PREINCREMENT_EXPR
   18038              :           || operator_code == PREDECREMENT_EXPR)
   18039              :         {
   18040            0 :           if (!TYPE_REF_P (ret)
   18041            0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   18042            0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   18043              :                         build_reference_type (arg));
   18044              :         }
   18045              :       else
   18046              :         {
   18047            0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   18048            0 :             warning_at (loc, OPT_Weffc__,
   18049              :                         "postfix %qD should return %qT", decl, arg);
   18050              :         }
   18051              :     }
   18052              : 
   18053              :   /* Effective C++ rule 23.  */
   18054           54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   18055              :       && (operator_code == PLUS_EXPR
   18056            9 :           || operator_code == MINUS_EXPR
   18057            9 :           || operator_code == TRUNC_DIV_EXPR
   18058              :           || operator_code == MULT_EXPR
   18059              :           || operator_code == TRUNC_MOD_EXPR)
   18060           60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   18061            3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   18062              : 
   18063              :   return true;
   18064              : }
   18065              : 
   18066              : /* Return a string giving the keyword associate with CODE.  */
   18067              : 
   18068              : const char *
   18069         3330 : tag_name (enum tag_types code)
   18070              : {
   18071         3330 :   switch (code)
   18072              :     {
   18073              :     case record_type:
   18074              :       return "struct";
   18075          107 :     case class_type:
   18076          107 :       return "class";
   18077            3 :     case union_type:
   18078            3 :       return "union";
   18079            9 :     case enum_type:
   18080            9 :       return "enum";
   18081         3122 :     case typename_type:
   18082         3122 :     case none_type:
   18083         3122 :       return "typename";
   18084           29 :     case scope_type:
   18085           29 :       return nullptr;
   18086              :     }
   18087            0 :   gcc_unreachable ();
   18088              : }
   18089              : 
   18090              : /* Name lookup in an elaborated-type-specifier (after the keyword
   18091              :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   18092              :    elaborated-type-specifier is invalid, issue a diagnostic and return
   18093              :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   18094              :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   18095              : 
   18096              : tree
   18097     11853324 : check_elaborated_type_specifier (enum tag_types tag_code,
   18098              :                                  tree decl,
   18099              :                                  bool allow_template_p)
   18100              : {
   18101     11853324 :   tree type;
   18102              : 
   18103              :   /* In the case of:
   18104              : 
   18105              :        struct S { struct S *p; };
   18106              : 
   18107              :      name lookup will find the TYPE_DECL for the implicit "S::S"
   18108              :      typedef.  Adjust for that here.  */
   18109     11853324 :   if (DECL_SELF_REFERENCE_P (decl))
   18110       400385 :     decl = TYPE_NAME (TREE_TYPE (decl));
   18111              : 
   18112     11853324 :   type = TREE_TYPE (decl);
   18113              : 
   18114              :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   18115              :      is false for this case as well.  */
   18116     11853324 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   18117              :     {
   18118            9 :       error ("using template type parameter %qT after %qs",
   18119              :              type, tag_name (tag_code));
   18120            9 :       return error_mark_node;
   18121              :     }
   18122              :   /* Accept template template parameters.  */
   18123     11853315 :   else if (allow_template_p
   18124      6631346 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   18125      6631334 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   18126              :     ;
   18127              :   /*   [dcl.type.elab]
   18128              : 
   18129              :        If the identifier resolves to a typedef-name or the
   18130              :        simple-template-id resolves to an alias template
   18131              :        specialization, the elaborated-type-specifier is ill-formed.
   18132              : 
   18133              :      In other words, the only legitimate declaration to use in the
   18134              :      elaborated type specifier is the implicit typedef created when
   18135              :      the type is declared.  */
   18136     11853300 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   18137       400509 :            && !DECL_SELF_REFERENCE_P (decl)
   18138     11853424 :            && tag_code != typename_type)
   18139              :     {
   18140           78 :       auto_diagnostic_group d;
   18141           78 :       if (alias_template_specialization_p (type, nt_opaque))
   18142           21 :         error ("using alias template specialization %qT after %qs",
   18143              :                type, tag_name (tag_code));
   18144              :       else
   18145           57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   18146           78 :       inform (DECL_SOURCE_LOCATION (decl),
   18147              :               "%qD has a previous declaration here", decl);
   18148           78 :       return error_mark_node;
   18149           78 :     }
   18150     11853222 :   else if (TREE_CODE (type) != RECORD_TYPE
   18151     11853222 :            && TREE_CODE (type) != UNION_TYPE
   18152              :            && tag_code != enum_type
   18153        69678 :            && tag_code != typename_type)
   18154              :     {
   18155            6 :       auto_diagnostic_group d;
   18156            6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   18157            6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18158            6 :       return error_mark_node;
   18159            6 :     }
   18160     11853216 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   18161     11783580 :            && tag_code == enum_type)
   18162              :     {
   18163            3 :       auto_diagnostic_group d;
   18164            3 :       error ("%qT referred to as enum", type);
   18165            3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18166            3 :       return error_mark_node;
   18167            3 :     }
   18168     11853213 :   else if (!allow_template_p
   18169      5221909 :            && TREE_CODE (type) == RECORD_TYPE
   18170     16954010 :            && CLASSTYPE_IS_TEMPLATE (type))
   18171              :     {
   18172              :       /* If a class template appears as elaborated type specifier
   18173              :          without a template header such as:
   18174              : 
   18175              :            template <class T> class C {};
   18176              :            void f(class C);             // No template header here
   18177              : 
   18178              :          then the required template argument is missing.  */
   18179           18 :       error ("template argument required for %<%s %T%>",
   18180              :              tag_name (tag_code),
   18181           18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   18182           18 :       return error_mark_node;
   18183              :     }
   18184              : 
   18185              :   return type;
   18186              : }
   18187              : 
   18188              : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   18189              :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   18190              :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   18191              :    error.  */
   18192              : 
   18193              : static tree
   18194     25590590 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   18195              :                       TAG_how how, bool template_header_p)
   18196              : {
   18197     25590590 :   tree decl;
   18198     25590590 :   if (how == TAG_how::GLOBAL)
   18199              :     {
   18200              :       /* First try ordinary name lookup, ignoring hidden class name
   18201              :          injected via friend declaration.  */
   18202      2089681 :       decl = lookup_name (name, LOOK_want::TYPE);
   18203              :       /* If that fails, the name will be placed in the smallest
   18204              :          non-class, non-function-prototype scope according to 3.3.1/5.
   18205              :          We may already have a hidden name declared as friend in this
   18206              :          scope.  So lookup again but not ignoring hidden names.
   18207              :          If we find one, that name will be made visible rather than
   18208              :          creating a new tag.  */
   18209      2089681 :       if (!decl)
   18210        18000 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   18211              :     }
   18212              :   else
   18213     23500909 :     decl = lookup_elaborated_type (name, how);
   18214              : 
   18215     23518909 :   if (!decl)
   18216              :     /* We found nothing.  */
   18217              :     return NULL_TREE;
   18218              : 
   18219      5812463 :   if (TREE_CODE (decl) == TREE_LIST)
   18220              :     {
   18221            3 :       auto_diagnostic_group d;
   18222            3 :       error ("reference to %qD is ambiguous", name);
   18223            3 :       print_candidates (input_location, decl);
   18224            3 :       return error_mark_node;
   18225            3 :     }
   18226              : 
   18227      2334904 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18228      2334898 :       && !template_header_p
   18229      8147358 :       && how == TAG_how::CURRENT_ONLY)
   18230              :     {
   18231           12 :       auto_diagnostic_group d;
   18232           12 :       error ("class template %qD redeclared as non-template", name);
   18233           12 :       inform (location_of (decl), "previous declaration here");
   18234           12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   18235           12 :       return error_mark_node;
   18236           12 :     }
   18237              : 
   18238      2334892 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18239              :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   18240              :          so ignore a template template parameter.  */
   18241      5812454 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   18242      2334889 :     decl = DECL_TEMPLATE_RESULT (decl);
   18243              : 
   18244      5812448 :   if (TREE_CODE (decl) != TYPE_DECL)
   18245              :     /* Found not-a-type.  */
   18246              :     return NULL_TREE;
   18247              : 
   18248              :   /* Look for invalid nested type:
   18249              :      class C {
   18250              :      class C {};
   18251              :      };  */
   18252      5812427 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   18253              :     {
   18254            6 :       error ("%qD has the same name as the class in which it is "
   18255              :              "declared", decl);
   18256            6 :       return error_mark_node;
   18257              :     }
   18258              : 
   18259              :   /* Two cases we need to consider when deciding if a class
   18260              :      template is allowed as an elaborated type specifier:
   18261              :      1. It is a self reference to its own class.
   18262              :      2. It comes with a template header.
   18263              : 
   18264              :      For example:
   18265              : 
   18266              :      template <class T> class C {
   18267              :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   18268              :        class D;
   18269              :      };
   18270              :      template <class U> class C; // template_header_p is true
   18271              :      template <class T> class C<T>::D {
   18272              :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   18273              :      };  */
   18274              : 
   18275     17437263 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   18276              :                                             template_header_p
   18277     11224472 :                                             | DECL_SELF_REFERENCE_P (decl));
   18278      2504854 :   if (template_header_p && t && CLASS_TYPE_P (t)
   18279      8317257 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   18280      2504818 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   18281              :     {
   18282           21 :       auto_diagnostic_group d;
   18283           21 :       error ("%qT is not a template", t);
   18284           21 :       inform (location_of (t), "previous declaration here");
   18285           42 :       if (TYPE_CLASS_SCOPE_P (t)
   18286           24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   18287            3 :         inform (input_location,
   18288              :                 "perhaps you want to explicitly add %<%T::%>",
   18289            3 :                 TYPE_CONTEXT (t));
   18290           21 :       return error_mark_node;
   18291           21 :     }
   18292              : 
   18293              :   return t;
   18294              : }
   18295              : 
   18296              : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   18297              :    Define the tag as a forward-reference if it is not defined.
   18298              : 
   18299              :    If a declaration is given, process it here, and report an error if
   18300              :    multiple declarations are not identical.
   18301              : 
   18302              :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   18303              :    the current frame for the name (since C++ allows new names in any
   18304              :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   18305              :    declaration.  Only look beginning from the current scope outward up
   18306              :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   18307              : 
   18308              :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   18309              :    a set of template parameters.  */
   18310              : 
   18311              : tree
   18312     25721321 : xref_tag (enum tag_types tag_code, tree name,
   18313              :           TAG_how how, bool template_header_p)
   18314              : {
   18315     25721321 :   enum tree_code code;
   18316     25721321 :   tree context = NULL_TREE;
   18317              : 
   18318     25721321 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   18319              : 
   18320     25721321 :   gcc_assert (identifier_p (name));
   18321              : 
   18322     25721321 :   switch (tag_code)
   18323              :     {
   18324              :     case record_type:
   18325              :     case class_type:
   18326              :       code = RECORD_TYPE;
   18327              :       break;
   18328              :     case union_type:
   18329              :       code = UNION_TYPE;
   18330              :       break;
   18331              :     case enum_type:
   18332              :       code = ENUMERAL_TYPE;
   18333              :       break;
   18334            0 :     default:
   18335            0 :       gcc_unreachable ();
   18336              :     }
   18337              : 
   18338              :   /* In case of anonymous name, xref_tag is only called to
   18339              :      make type node and push name.  Name lookup is not required.  */
   18340     25721321 :   tree t = NULL_TREE;
   18341     25721321 :   if (!IDENTIFIER_ANON_P (name))
   18342     23232308 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   18343              : 
   18344     25721321 :   if (t == error_mark_node)
   18345              :     return error_mark_node;
   18346              : 
   18347      2792305 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   18348      1328886 :       && template_class_depth (current_class_type)
   18349     26311497 :       && template_header_p)
   18350              :     {
   18351       348344 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   18352              :         return t;
   18353              : 
   18354              :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   18355              :          a definition of this tag.  Since, in addition, we are
   18356              :          currently processing a (member) template declaration of a
   18357              :          template class, we must be very careful; consider:
   18358              : 
   18359              :            template <class X> struct S1
   18360              : 
   18361              :            template <class U> struct S2
   18362              :            {
   18363              :              template <class V> friend struct S1;
   18364              :            };
   18365              : 
   18366              :          Here, the S2::S1 declaration should not be confused with the
   18367              :          outer declaration.  In particular, the inner version should
   18368              :          have a template parameter of level 2, not level 1.
   18369              : 
   18370              :          On the other hand, when presented with:
   18371              : 
   18372              :            template <class T> struct S1
   18373              :            {
   18374              :              template <class U> struct S2 {};
   18375              :              template <class U> friend struct S2;
   18376              :            };
   18377              : 
   18378              :          the friend must find S1::S2 eventually.  We accomplish this
   18379              :          by making sure that the new type we create to represent this
   18380              :          declaration has the right TYPE_CONTEXT.  */
   18381       348341 :       context = TYPE_CONTEXT (t);
   18382       348341 :       t = NULL_TREE;
   18383              :     }
   18384              : 
   18385     25721207 :   if (! t)
   18386              :     {
   18387              :       /* If no such tag is yet defined, create a forward-reference node
   18388              :          and record it as the "definition".
   18389              :          When a real declaration of this type is found,
   18390              :          the forward-reference will be altered into a real type.  */
   18391     20291188 :       if (code == ENUMERAL_TYPE)
   18392              :         {
   18393           13 :           error ("use of enum %q#D without previous declaration", name);
   18394           13 :           return error_mark_node;
   18395              :         }
   18396              : 
   18397     20291175 :       t = make_class_type (code);
   18398     20291175 :       TYPE_CONTEXT (t) = context;
   18399     20291175 :       if (IDENTIFIER_LAMBDA_P (name))
   18400              :         /* Mark it as a lambda type right now.  Our caller will
   18401              :            correct the value.  */
   18402      1773912 :         SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
   18403     20291175 :       t = pushtag (name, t, how);
   18404              :     }
   18405              :   else
   18406              :     {
   18407      5430019 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   18408              :         {
   18409              :           /* Check that we aren't trying to overload a class with different
   18410              :              constraints.  */
   18411      2156474 :           if (!redeclare_class_template (t, current_template_parms,
   18412              :                                          current_template_constraints ()))
   18413           60 :             return error_mark_node;
   18414              :         }
   18415      3273545 :       else if (!processing_template_decl
   18416      2939638 :                && CLASS_TYPE_P (t)
   18417      6186878 :                && CLASSTYPE_IS_TEMPLATE (t))
   18418              :         {
   18419            0 :           auto_diagnostic_group d;
   18420            0 :           error ("redeclaration of %qT as a non-template", t);
   18421            0 :           inform (location_of (t), "previous declaration %qD", t);
   18422            0 :           return error_mark_node;
   18423            0 :         }
   18424              : 
   18425      5429959 :       if (modules_p ()
   18426      5429959 :           && how == TAG_how::CURRENT_ONLY)
   18427              :         {
   18428         9083 :           tree decl = TYPE_NAME (t);
   18429         9083 :           if (!module_may_redeclare (decl))
   18430           15 :             return error_mark_node;
   18431              : 
   18432         9068 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   18433         9068 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   18434         4315 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   18435           54 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   18436         9110 :               && module_exporting_p ())
   18437              :             {
   18438            6 :               auto_diagnostic_group d;
   18439            6 :               error ("conflicting exporting for declaration %qD", decl);
   18440            6 :               inform (DECL_SOURCE_LOCATION (decl),
   18441              :                       "previously declared here without exporting");
   18442            6 :             }
   18443              : 
   18444         9068 :           tree maybe_tmpl = decl;
   18445         9068 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   18446         6742 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   18447              : 
   18448              :           /* FIXME: we should do a more precise check for redefinitions
   18449              :              of a conflicting using-declaration here, as these diagnostics
   18450              :              are not ideal.  */
   18451         9068 :           if (DECL_LANG_SPECIFIC (decl)
   18452         4315 :               && DECL_MODULE_IMPORT_P (decl)
   18453         9117 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   18454              :             {
   18455              :               /* Push it into this TU's symbol slot.  */
   18456           46 :               if (maybe_tmpl != decl)
   18457              :                 /* We're in the template parm binding level.
   18458              :                    Pushtag has logic to slide under that, but we're
   18459              :                    not pushing a *new* type.  */
   18460           20 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   18461              : 
   18462           46 :               pushdecl (maybe_tmpl);
   18463           46 :               if (maybe_tmpl != decl)
   18464           20 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   18465              :             }
   18466              : 
   18467         9068 :           set_instantiating_module (maybe_tmpl);
   18468              :         }
   18469              :     }
   18470              : 
   18471              :   return t;
   18472     25721321 : }
   18473              : 
   18474              : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   18475              :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   18476              :    access_* node, and the TREE_VALUE is the type of the base-class.
   18477              :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   18478              : 
   18479              : void
   18480     74584526 : xref_basetypes (tree ref, tree base_list)
   18481              : {
   18482     74584526 :   tree *basep;
   18483     74584526 :   tree binfo, base_binfo;
   18484     74584526 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   18485     74584526 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   18486     74584526 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   18487              :   /* Highest direct base index with annotations.  */
   18488     74584526 :   unsigned max_annotated_base = 0;
   18489     74584526 :   int i;
   18490     74584526 :   tree default_access;
   18491     74584526 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   18492              : 
   18493     74584526 :   if (ref == error_mark_node)
   18494           12 :     return;
   18495              : 
   18496              :   /* The base of a derived class is private by default, all others are
   18497              :      public.  */
   18498     74584526 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   18499     73984867 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   18500     74584526 :                     ? access_private_node : access_public_node);
   18501              : 
   18502              :   /* First, make sure that any templates in base-classes are
   18503              :      instantiated.  This ensures that if we call ourselves recursively
   18504              :      we do not get confused about which classes are marked and which
   18505              :      are not.  */
   18506     74584526 :   basep = &base_list;
   18507    109056192 :   while (*basep)
   18508              :     {
   18509     34471666 :       tree basetype = TREE_VALUE (*basep);
   18510              : 
   18511              :       /* The dependent_type_p call below should really be dependent_scope_p
   18512              :          so that we give a hard error about using an incomplete type as a
   18513              :          base, but we allow it with a pedwarn for backward
   18514              :          compatibility.  */
   18515     34471666 :       if (processing_template_decl
   18516     34471666 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   18517            3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
   18518              :                                         diagnostics::kind::pedwarn);
   18519     34471666 :       if (!dependent_type_p (basetype)
   18520     34471666 :           && !complete_type_or_else (basetype, NULL))
   18521              :         /* An incomplete type.  Remove it from the list.  */
   18522           15 :         *basep = TREE_CHAIN (*basep);
   18523              :       else
   18524              :         {
   18525     34471651 :           max_bases++;
   18526     34471651 :           if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
   18527           14 :             max_annotated_base = max_bases;
   18528     34471651 :           if (TREE_TYPE (*basep))
   18529        66976 :             max_dvbases++;
   18530     34471651 :           if (CLASS_TYPE_P (basetype))
   18531     33690470 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18532     34471651 :           basep = &TREE_CHAIN (*basep);
   18533              :         }
   18534              :     }
   18535     74584526 :   max_vbases += max_dvbases;
   18536              : 
   18537     74584526 :   TYPE_MARKED_P (ref) = 1;
   18538              : 
   18539              :   /* The binfo slot should be empty, unless this is an (ill-formed)
   18540              :      redefinition.  */
   18541     74584526 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   18542              : 
   18543     74584526 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   18544              : 
   18545     74584526 :   binfo = make_tree_binfo (max_bases);
   18546              : 
   18547     74584526 :   TYPE_BINFO (ref) = binfo;
   18548     74584526 :   BINFO_OFFSET (binfo) = size_zero_node;
   18549     74584526 :   BINFO_TYPE (binfo) = ref;
   18550              : 
   18551              :   /* Apply base-class info set up to the variants of this type.  */
   18552     74584526 :   fixup_type_variants (ref);
   18553              : 
   18554     74584526 :   if (max_bases)
   18555              :     {
   18556     33578214 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
   18557     33578214 :       BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
   18558              :       /* A C++98 POD cannot have base classes.  */
   18559     33578214 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   18560              : 
   18561     33578214 :       if (TREE_CODE (ref) == UNION_TYPE)
   18562              :         {
   18563           12 :           error ("derived union %qT invalid", ref);
   18564           12 :           return;
   18565              :         }
   18566              :     }
   18567              : 
   18568     33578202 :   if (max_bases > 1)
   18569       707288 :     warning (OPT_Wmultiple_inheritance,
   18570              :              "%qT defined with multiple direct bases", ref);
   18571              : 
   18572     74584514 :   if (max_vbases)
   18573              :     {
   18574              :       /* An aggregate can't have virtual base classes.  */
   18575       199813 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   18576              : 
   18577       199813 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   18578              : 
   18579       199813 :       if (max_dvbases)
   18580        65769 :         warning (OPT_Wvirtual_inheritance,
   18581              :                  "%qT defined with direct virtual base", ref);
   18582              :     }
   18583              : 
   18584    109056153 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   18585              :     {
   18586     34471639 :       tree access = TREE_PURPOSE (base_list);
   18587     34471639 :       tree annotations = NULL_TREE;
   18588     34471639 :       if (TREE_CODE (access) == TREE_LIST)
   18589              :         {
   18590           14 :           annotations = TREE_VALUE (access);
   18591           14 :           access = TREE_PURPOSE (access);
   18592           39 :           for (tree *d = &annotations; *d; )
   18593              :             {
   18594           25 :               if (annotation_p (*d))
   18595              :                 {
   18596           25 :                   tree name = get_attribute_name (*d);
   18597           25 :                   tree args = TREE_VALUE (*d);
   18598           25 :                   const attribute_spec *as
   18599           25 :                     = lookup_attribute_spec (TREE_PURPOSE (*d));
   18600           25 :                   bool no_add_attrs = false;
   18601           25 :                   as->handler (&binfo, name, args, 0, &no_add_attrs);
   18602           25 :                   if (no_add_attrs)
   18603              :                     {
   18604            1 :                       *d = TREE_CHAIN (*d);
   18605            1 :                       continue;
   18606              :                     }
   18607              :                 }
   18608           24 :               d = &TREE_CHAIN (*d);
   18609              :             }
   18610              :         }
   18611     34471639 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   18612     34471639 :       tree basetype = TREE_VALUE (base_list);
   18613              : 
   18614     34471639 :       if (access == access_default_node)
   18615      4364844 :         access = default_access;
   18616              : 
   18617              :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   18618              :          aggregate can't have virtual, private, or protected base classes.  */
   18619     34471639 :       if (cxx_dialect < cxx17
   18620     34256288 :           || access != access_public_node
   18621     33275572 :           || via_virtual)
   18622      1259837 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   18623              : 
   18624     34471639 :       if (PACK_EXPANSION_P (basetype))
   18625        28162 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   18626     34471639 :       if (TREE_CODE (basetype) == TYPE_DECL)
   18627            0 :         basetype = TREE_TYPE (basetype);
   18628     34471639 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   18629              :         {
   18630           24 :           error ("base type %qT fails to be a struct or class type",
   18631              :                  basetype);
   18632           24 :           goto dropped_base;
   18633              :         }
   18634              : 
   18635     34471615 :       base_binfo = NULL_TREE;
   18636     34471615 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   18637              :         {
   18638     27734063 :           base_binfo = TYPE_BINFO (basetype);
   18639              :           /* The original basetype could have been a typedef'd type.  */
   18640     27734063 :           basetype = BINFO_TYPE (base_binfo);
   18641              : 
   18642              :           /* Inherit flags from the base.  */
   18643     83202189 :           TYPE_HAS_NEW_OPERATOR (ref)
   18644     27734063 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   18645     83202189 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   18646     27734063 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   18647     27734063 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   18648     27734063 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   18649     83202189 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   18650     27734063 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   18651     83202189 :           CLASSTYPE_REPEATED_BASE_P (ref)
   18652     27734063 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   18653              :         }
   18654              : 
   18655              :       /* We must do this test after we've seen through a typedef
   18656              :          type.  */
   18657     34471615 :       if (TYPE_MARKED_P (basetype))
   18658              :         {
   18659           18 :           if (basetype == ref)
   18660            0 :             error ("recursive type %qT undefined", basetype);
   18661              :           else
   18662           18 :             error ("duplicate base type %qT invalid", basetype);
   18663           18 :           goto dropped_base;
   18664              :         }
   18665              : 
   18666     34471597 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   18667              :         /* Regenerate the pack expansion for the bases. */
   18668        28162 :         basetype = make_pack_expansion (basetype);
   18669              : 
   18670     34471597 :       TYPE_MARKED_P (basetype) = 1;
   18671              : 
   18672     34471597 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   18673              :                                &igo_prev, via_virtual);
   18674     34471597 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   18675     34404636 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   18676              : 
   18677     34471597 :       unsigned len;
   18678     34471597 :       len = BINFO_N_BASE_BINFOS (binfo);
   18679     34471597 :       BINFO_BASE_APPEND (binfo, base_binfo);
   18680     34471597 :       BINFO_BASE_ACCESS (binfo, len) = access;
   18681     34471597 :       if (len < max_annotated_base)
   18682           17 :         BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
   18683     34471597 :       continue;
   18684              : 
   18685           42 :     dropped_base:
   18686              :       /* Update max_vbases to reflect the reality that we are dropping
   18687              :          this base:  if it reaches zero we want to undo the vec_alloc
   18688              :          above to avoid inconsistencies during error-recovery: eg, in
   18689              :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   18690              :          and vtt null (c++/27952).  */
   18691           42 :       if (via_virtual)
   18692           12 :         max_vbases--;
   18693           42 :       if (CLASS_TYPE_P (basetype))
   18694           30 :         max_vbases
   18695           33 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18696     34471597 :     }
   18697              : 
   18698     74584514 :   unsigned len = BINFO_N_BASE_BINFOS (binfo);
   18699     74584514 :   if (len < max_bases)
   18700              :     {
   18701           42 :       if (len && max_annotated_base)
   18702            0 :         memmove (&BINFO_BASE_ACCESS (binfo, len),
   18703            0 :                  &BINFO_BASE_ACCESS (binfo, max_bases),
   18704            0 :                  MIN (max_annotated_base, len) * sizeof (tree));
   18705           42 :       BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
   18706              :                                                         len));
   18707              :     }
   18708              : 
   18709     74584514 :   if (CLASSTYPE_VBASECLASSES (ref)
   18710     74584514 :       && max_vbases == 0)
   18711           24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   18712              : 
   18713     74784315 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   18714              :     /* If we didn't get max_vbases vbases, we must have shared at
   18715              :        least one of them, and are therefore diamond shaped.  */
   18716        21678 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   18717              : 
   18718              :   /* Unmark all the types.  */
   18719    109056111 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   18720     34471597 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   18721     74584514 :   TYPE_MARKED_P (ref) = 0;
   18722              : 
   18723              :   /* Now see if we have a repeated base type.  */
   18724     74584514 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   18725              :     {
   18726    187760343 :       for (base_binfo = binfo; base_binfo;
   18727    113176263 :            base_binfo = TREE_CHAIN (base_binfo))
   18728              :         {
   18729    113176980 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   18730              :             {
   18731          717 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   18732          717 :               break;
   18733              :             }
   18734    113176263 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   18735              :         }
   18736    187760343 :       for (base_binfo = binfo; base_binfo;
   18737    113176263 :            base_binfo = TREE_CHAIN (base_binfo))
   18738    113176980 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   18739    113176263 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   18740              :         else
   18741              :           break;
   18742              :     }
   18743              : }
   18744              : 
   18745              : 
   18746              : /* Copies the enum-related properties from type SRC to type DST.
   18747              :    Used with the underlying type of an enum and the enum itself.  */
   18748              : static void
   18749      2013567 : copy_type_enum (tree dst, tree src)
   18750              : {
   18751      2013567 :   tree t;
   18752      4027152 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   18753              :     {
   18754      2013585 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   18755      2013585 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   18756      2013585 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   18757      2013585 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   18758      2013585 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   18759      2013585 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   18760      2013585 :       unsigned valign = TYPE_ALIGN (src);
   18761      2013585 :       if (TYPE_USER_ALIGN (t))
   18762           12 :         valign = MAX (valign, TYPE_ALIGN (t));
   18763              :       else
   18764      2013573 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   18765      2013585 :       SET_TYPE_ALIGN (t, valign);
   18766      2013585 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   18767              :     }
   18768      2013567 : }
   18769              : 
   18770              : /* Begin compiling the definition of an enumeration type.
   18771              :    NAME is its name,
   18772              : 
   18773              :    if ENUMTYPE is not NULL_TREE then the type has alredy been found.
   18774              : 
   18775              :    UNDERLYING_TYPE is the type that will be used as the storage for
   18776              :    the enumeration type. This should be NULL_TREE if no storage type
   18777              :    was specified.
   18778              : 
   18779              :    ATTRIBUTES are any attributes specified after the enum-key.
   18780              : 
   18781              :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   18782              : 
   18783              :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   18784              : 
   18785              :    Returns the type object, as yet incomplete.
   18786              :    Also records info about it so that build_enumerator
   18787              :    may be used to declare the individual values as they are read.  */
   18788              : 
   18789              : tree
   18790      2358412 : start_enum (tree name, tree enumtype, tree underlying_type,
   18791              :             tree attributes, bool scoped_enum_p, bool *is_new)
   18792              : {
   18793      2358412 :   tree prevtype = NULL_TREE;
   18794      2358412 :   gcc_assert (identifier_p (name));
   18795              : 
   18796      2358412 :   if (is_new)
   18797      1829774 :     *is_new = false;
   18798              :   /* [C++0x dcl.enum]p5:
   18799              : 
   18800              :     If not explicitly specified, the underlying type of a scoped
   18801              :     enumeration type is int.  */
   18802      2358412 :   if (!underlying_type && scoped_enum_p)
   18803       167100 :     underlying_type = integer_type_node;
   18804              : 
   18805      2358412 :   if (underlying_type)
   18806       573611 :     underlying_type = cv_unqualified (underlying_type);
   18807              : 
   18808              :   /* If this is the real definition for a previous forward reference,
   18809              :      fill in the contents in the same object that used to be the
   18810              :      forward reference.  */
   18811      2358412 :   if (!enumtype)
   18812      2358282 :     enumtype = lookup_and_check_tag (enum_type, name,
   18813              :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   18814              :                                      /*template_header_p=*/false);
   18815              : 
   18816              :   /* In case of a template_decl, the only check that should be deferred
   18817              :      to instantiation time is the comparison of underlying types.  */
   18818      2358412 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   18819              :     {
   18820              :       /* Attempt to set the declaring module.  */
   18821        34095 :       if (modules_p ())
   18822              :         {
   18823          168 :           tree decl = TYPE_NAME (enumtype);
   18824          168 :           if (!module_may_redeclare (decl))
   18825            3 :             enumtype = error_mark_node;
   18826              :           else
   18827          165 :             set_instantiating_module (decl);
   18828              :         }
   18829              : 
   18830        34095 :       if (enumtype == error_mark_node)
   18831              :         ;
   18832        34293 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   18833              :         {
   18834            6 :           auto_diagnostic_group d;
   18835            6 :           error_at (input_location, "scoped/unscoped mismatch "
   18836              :                     "in enum %q#T", enumtype);
   18837            6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18838              :                   "previous definition here");
   18839            6 :           enumtype = error_mark_node;
   18840            6 :         }
   18841        34086 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   18842              :         {
   18843            0 :           auto_diagnostic_group d;
   18844            0 :           error_at (input_location, "underlying type mismatch "
   18845              :                     "in enum %q#T", enumtype);
   18846            0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18847              :                   "previous definition here");
   18848            0 :           enumtype = error_mark_node;
   18849            0 :         }
   18850        34071 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   18851        68157 :                && !same_type_p (underlying_type,
   18852              :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   18853              :         {
   18854           26 :           auto_diagnostic_group d;
   18855           26 :           error_at (input_location, "different underlying type "
   18856              :                     "in enum %q#T", enumtype);
   18857           26 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18858              :                   "previous definition here");
   18859           26 :           underlying_type = NULL_TREE;
   18860           26 :         }
   18861              :     }
   18862              : 
   18863      2358412 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   18864        34086 :       || processing_template_decl)
   18865              :     {
   18866              :       /* In case of error, make a dummy enum to allow parsing to
   18867              :          continue.  */
   18868      2324416 :       if (enumtype == error_mark_node)
   18869              :         {
   18870            9 :           name = make_anon_name ();
   18871            9 :           enumtype = NULL_TREE;
   18872              :         }
   18873              : 
   18874              :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   18875              :          of an opaque enum, or an opaque enum of an already defined
   18876              :          enumeration (C++11).
   18877              :          In any other case, it'll be NULL_TREE. */
   18878      2324416 :       if (!enumtype)
   18879              :         {
   18880      2324323 :           if (is_new)
   18881      1795688 :             *is_new = true;
   18882              :         }
   18883      2324416 :       prevtype = enumtype;
   18884              : 
   18885              :       /* Do not push the decl more than once.  */
   18886      2324416 :       if (!enumtype
   18887           93 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   18888              :         {
   18889      2324326 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   18890      2324326 :           enumtype = pushtag (name, enumtype);
   18891              : 
   18892      2324326 :           if (enumtype != error_mark_node)
   18893              :             {
   18894              :               /* The enum is considered opaque until the opening '{' of the
   18895              :                  enumerator list.  */
   18896      2324308 :               SET_OPAQUE_ENUM_P (enumtype, true);
   18897      2324308 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   18898              : 
   18899              :               /* std::byte aliases anything.  */
   18900      2324308 :               if (TYPE_CONTEXT (enumtype) == std_node
   18901      2670017 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   18902        12682 :                 TYPE_ALIAS_SET (enumtype) = 0;
   18903              :             }
   18904              :         }
   18905              :       else
   18906           90 :           enumtype = xref_tag (enum_type, name);
   18907              : 
   18908      2324416 :       if (enumtype == error_mark_node)
   18909              :         return error_mark_node;
   18910              :     }
   18911              : 
   18912      2358394 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   18913              : 
   18914      2358394 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   18915              : 
   18916      2358394 :   if (underlying_type)
   18917              :     {
   18918       573582 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   18919              :         /* We already checked that it matches, don't change it to a different
   18920              :            typedef variant.  */;
   18921       539537 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   18922              :         {
   18923       539471 :           copy_type_enum (enumtype, underlying_type);
   18924       539471 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   18925              :         }
   18926           66 :       else if (dependent_type_p (underlying_type))
   18927           53 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   18928              :       else
   18929              :         {
   18930           13 :           error ("underlying type %qT of %qT must be an integral type",
   18931              :                  underlying_type, enumtype);
   18932           13 :           copy_type_enum (enumtype, integer_type_node);
   18933           13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   18934              :         }
   18935              :     }
   18936              : 
   18937              :   /* If into a template class, the returned enum is always the first
   18938              :      declaration (opaque or not) seen. This way all the references to
   18939              :      this type will be to the same declaration. The following ones are used
   18940              :      only to check for definition errors.  */
   18941      2358394 :   if (prevtype && processing_template_decl)
   18942              :     return prevtype;
   18943              :   else
   18944      2358304 :     return enumtype;
   18945              : }
   18946              : 
   18947              : /* Returns true if TYPE is an enum that uses an enumerator name for
   18948              :    linkage purposes at namespace scope.  The term is defined in [dcl.enum]/12
   18949              :    for all enums, not just those at namespace scope, but for backward ABI
   18950              :    compatibility we want to treat those not at namespace scope the old way
   18951              :    and e.g. mangle the class scope ones based on their position within the
   18952              :    class rather than the first enumerator.  */
   18953              : 
   18954              : bool
   18955    433327326 : enum_with_enumerator_for_linkage_p (tree type)
   18956              : {
   18957    433327326 :   return (cxx_dialect >= cxx20
   18958    428786620 :           && UNSCOPED_ENUM_P (type)
   18959     19866578 :           && TYPE_ANON_P (type)
   18960      3157178 :           && TYPE_VALUES (type)
   18961    435282517 :           && TYPE_NAMESPACE_SCOPE_P (type));
   18962              : }
   18963              : 
   18964              : /* After processing and defining all the values of an enumeration type,
   18965              :    install their decls in the enumeration type.
   18966              :    ENUMTYPE is the type object.  */
   18967              : 
   18968              : void
   18969      2258492 : finish_enum_value_list (tree enumtype)
   18970              : {
   18971      2258492 :   tree values;
   18972      2258492 :   tree underlying_type;
   18973      2258492 :   tree decl;
   18974      2258492 :   tree value;
   18975      2258492 :   tree minnode, maxnode;
   18976      2258492 :   tree t;
   18977              : 
   18978      2258492 :   ENUM_BEING_DEFINED_P (enumtype) = 0;
   18979              : 
   18980      2258492 :   bool fixed_underlying_type_p
   18981      2258492 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   18982              : 
   18983              :   /* We built up the VALUES in reverse order.  */
   18984      2258492 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   18985              : 
   18986              :   /* For an enum defined in a template, just set the type of the values;
   18987              :      all further processing is postponed until the template is
   18988              :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   18989              :      works.  */
   18990      2258492 :   if (processing_template_decl)
   18991              :     {
   18992       430164 :       for (values = TYPE_VALUES (enumtype);
   18993       768190 :            values;
   18994       430164 :            values = TREE_CHAIN (values))
   18995       430164 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   18996              :       return;
   18997              :     }
   18998              : 
   18999              :   /* Determine the minimum and maximum values of the enumerators.  */
   19000      1920466 :   if (TYPE_VALUES (enumtype))
   19001              :     {
   19002              :       minnode = maxnode = NULL_TREE;
   19003              : 
   19004     11148126 :       for (values = TYPE_VALUES (enumtype);
   19005     13033847 :            values;
   19006     11148126 :            values = TREE_CHAIN (values))
   19007              :         {
   19008     11148126 :           decl = TREE_VALUE (values);
   19009              : 
   19010              :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   19011              :              each enumerator has the type of its enumeration.  Prior to the
   19012              :              closing brace, the type of each enumerator is the type of its
   19013              :              initializing value.  */
   19014     11148126 :           TREE_TYPE (decl) = enumtype;
   19015              : 
   19016              :           /* Update the minimum and maximum values, if appropriate.  */
   19017     11148126 :           value = DECL_INITIAL (decl);
   19018     11148126 :           if (TREE_CODE (value) != INTEGER_CST)
   19019            4 :             value = integer_zero_node;
   19020              :           /* Figure out what the minimum and maximum values of the
   19021              :              enumerators are.  */
   19022     11148126 :           if (!minnode)
   19023              :             minnode = maxnode = value;
   19024      9262405 :           else if (tree_int_cst_lt (maxnode, value))
   19025              :             maxnode = value;
   19026      1445617 :           else if (tree_int_cst_lt (value, minnode))
   19027       162843 :             minnode = value;
   19028              :         }
   19029              :     }
   19030              :   else
   19031              :     /* [dcl.enum]
   19032              : 
   19033              :        If the enumerator-list is empty, the underlying type is as if
   19034              :        the enumeration had a single enumerator with value 0.  */
   19035        34745 :     minnode = maxnode = integer_zero_node;
   19036              : 
   19037      1920466 :   if (!fixed_underlying_type_p)
   19038              :     {
   19039              :       /* Compute the number of bits require to represent all values of the
   19040              :          enumeration.  We must do this before the type of MINNODE and
   19041              :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   19042              :          on the TREE_TYPE of the value it is passed.  */
   19043      1474083 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   19044      1474083 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   19045      1474083 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   19046      1474083 :       int precision = MAX (lowprec, highprec);
   19047      1474083 :       unsigned int itk;
   19048      1474083 :       bool use_short_enum;
   19049              : 
   19050              :       /* Determine the underlying type of the enumeration.
   19051              : 
   19052              :          [dcl.enum]
   19053              : 
   19054              :          The underlying type of an enumeration is an integral type that
   19055              :          can represent all the enumerator values defined in the
   19056              :          enumeration.  It is implementation-defined which integral type is
   19057              :          used as the underlying type for an enumeration except that the
   19058              :          underlying type shall not be larger than int unless the value of
   19059              :          an enumerator cannot fit in an int or unsigned int.
   19060              : 
   19061              :          We use "int" or an "unsigned int" as the underlying type, even if
   19062              :          a smaller integral type would work, unless the user has
   19063              :          explicitly requested that we use the smallest possible type.  The
   19064              :          user can request that for all enumerations with a command line
   19065              :          flag, or for just one enumeration with an attribute.  */
   19066              : 
   19067      2948166 :       use_short_enum = flag_short_enums
   19068      1474083 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   19069              : 
   19070              :       /* If the precision of the type was specified with an attribute and it
   19071              :          was too small, give an error.  Otherwise, use it.  */
   19072      1474083 :       if (TYPE_PRECISION (enumtype))
   19073              :         {
   19074           11 :           if (precision > TYPE_PRECISION (enumtype))
   19075            0 :             error ("specified mode too small for enumerated values");
   19076              :           else
   19077              :             {
   19078           11 :               use_short_enum = true;
   19079           11 :               precision = TYPE_PRECISION (enumtype);
   19080              :             }
   19081              :         }
   19082              : 
   19083      2870321 :       for (itk = (use_short_enum ? itk_char : itk_int);
   19084      2870321 :            itk != itk_none;
   19085              :            itk++)
   19086              :         {
   19087      2870318 :           underlying_type = integer_types[itk];
   19088      2870318 :           if (underlying_type != NULL_TREE
   19089      2870300 :               && TYPE_PRECISION (underlying_type) >= precision
   19090      5738557 :               && TYPE_SIGN (underlying_type) == sgn)
   19091              :             break;
   19092              :         }
   19093      1474083 :       if (itk == itk_none)
   19094              :         {
   19095              :           /* DR 377
   19096              : 
   19097              :              IF no integral type can represent all the enumerator values, the
   19098              :              enumeration is ill-formed.  */
   19099            3 :           error ("no integral type can represent all of the enumerator values "
   19100              :                  "for %qT", enumtype);
   19101            3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   19102            3 :           underlying_type = integer_types[itk_unsigned_long_long];
   19103              :         }
   19104              : 
   19105              :       /* [dcl.enum]
   19106              : 
   19107              :          The value of sizeof() applied to an enumeration type, an object
   19108              :          of an enumeration type, or an enumerator, is the value of sizeof()
   19109              :          applied to the underlying type.  */
   19110      1474083 :       copy_type_enum (enumtype, underlying_type);
   19111              : 
   19112              :       /* Compute the minimum and maximum values for the type.
   19113              : 
   19114              :          [dcl.enum]
   19115              : 
   19116              :          For an enumeration where emin is the smallest enumerator and emax
   19117              :          is the largest, the values of the enumeration are the values of the
   19118              :          underlying type in the range bmin to bmax, where bmin and bmax are,
   19119              :          respectively, the smallest and largest values of the smallest bit-
   19120              :          field that can store emin and emax.  */
   19121              : 
   19122              :       /* The middle-end currently assumes that types with TYPE_PRECISION
   19123              :          narrower than their underlying type are suitably zero or sign
   19124              :          extended to fill their mode.  Similarly, it assumes that the front
   19125              :          end assures that a value of a particular type must be within
   19126              :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   19127              : 
   19128              :          We used to set these fields based on bmin and bmax, but that led
   19129              :          to invalid assumptions like optimizing away bounds checking.  So
   19130              :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   19131              :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   19132              :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   19133      1474083 :       ENUM_UNDERLYING_TYPE (enumtype)
   19134      1474083 :         = build_distinct_type_copy (underlying_type);
   19135      1474083 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   19136      1474083 :       set_min_and_max_values_for_integral_type
   19137      1474083 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   19138              : 
   19139              :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   19140      1474083 :       if (flag_strict_enums)
   19141           38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   19142              : 
   19143      1474083 :       if (use_short_enum)
   19144              :         {
   19145          122 :           TYPE_PACKED (enumtype) = use_short_enum;
   19146          122 :           fixup_attribute_variants (enumtype);
   19147              :         }
   19148              :     }
   19149              :   else
   19150       446383 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   19151              : 
   19152              :   /* If the enum is exported, mark the consts too.  */
   19153      1920466 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   19154      1547939 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   19155      1921045 :                    && at_namespace_scope_p ());
   19156              : 
   19157              :   /* Convert each of the enumerators to the type of the underlying
   19158              :      type of the enumeration.  */
   19159     13068592 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   19160              :     {
   19161     11148126 :       decl = TREE_VALUE (values);
   19162     11148126 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   19163     11148126 :       if (fixed_underlying_type_p)
   19164              :         /* If the enumeration type has a fixed underlying type, we
   19165              :            already checked all of the enumerator values.  */
   19166      3795736 :         value = DECL_INITIAL (decl);
   19167              :       else
   19168      7352390 :         value = perform_implicit_conversion (underlying_type,
   19169      7352390 :                                              DECL_INITIAL (decl),
   19170              :                                              tf_warning_or_error);
   19171              :       /* Do not clobber shared ints.  But do share identical enumerators.  */
   19172     11148126 :       value = fold_convert (enumtype, value);
   19173              : 
   19174     11148126 :       DECL_INITIAL (decl) = value;
   19175     11148126 :       if (export_p)
   19176         3549 :         DECL_MODULE_EXPORT_P (decl) = true;
   19177     11148126 :     }
   19178              : 
   19179              :   /* Fix up all variant types of this enum type.  */
   19180      3840961 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   19181      1920495 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   19182              : 
   19183      1920466 :   if (at_class_scope_p ()
   19184      1067136 :       && COMPLETE_TYPE_P (current_class_type)
   19185      1920527 :       && UNSCOPED_ENUM_P (enumtype))
   19186              :     {
   19187           42 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   19188              :       /* TYPE_FIELDS needs fixup.  */
   19189           42 :       fixup_type_variants (current_class_type);
   19190              :     }
   19191              : 
   19192              :   /* P2115: An unnamed enum uses the name of its first enumerator for
   19193              :      linkage purposes; reset the type linkage if that is the case.  */
   19194      1920466 :   if (enum_with_enumerator_for_linkage_p (enumtype))
   19195       327315 :     reset_type_linkage (enumtype);
   19196              : 
   19197              :   /* Finish debugging output for this type.  */
   19198      1920466 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   19199              : 
   19200              :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   19201              :      so that this change in types doesn't confuse us later on.  */
   19202      1920466 :   clear_cv_and_fold_caches ();
   19203              : }
   19204              : 
   19205              : /* Finishes the enum type. This is called only the first time an
   19206              :    enumeration is seen, be it opaque or odinary.
   19207              :    ENUMTYPE is the type object.  */
   19208              : 
   19209              : void
   19210      2247949 : finish_enum (tree enumtype)
   19211              : {
   19212      2247949 :   if (processing_template_decl)
   19213              :     {
   19214       338054 :       if (at_function_scope_p ())
   19215         9129 :         add_stmt (build_min (TAG_DEFN, enumtype));
   19216       338054 :       return;
   19217              :     }
   19218              : 
   19219              :   /* If this is a forward declaration, there should not be any variants,
   19220              :      though we can get a variant in the middle of an enum-specifier with
   19221              :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   19222      3819790 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   19223              :               && (TYPE_VALUES (enumtype)
   19224              :                   || !TYPE_NEXT_VARIANT (enumtype)));
   19225              : }
   19226              : 
   19227              : /* Build and install a CONST_DECL for an enumeration constant of the
   19228              :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   19229              :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   19230              :    Assignment of sequential values by default is handled here.  */
   19231              : 
   19232              : tree
   19233     11578267 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   19234              :                   location_t loc)
   19235              : {
   19236     11578267 :   tree decl;
   19237     11578267 :   tree context;
   19238     11578267 :   tree type;
   19239              : 
   19240              :   /* scalar_constant_value will pull out this expression, so make sure
   19241              :      it's folded as appropriate.
   19242              : 
   19243              :      Creating a TARGET_EXPR in a template breaks when substituting, and
   19244              :      here we would create it for instance when using a class prvalue with
   19245              :      a user-defined conversion function.  So don't use such a tree.  We
   19246              :      instantiate VALUE here to get errors about bad enumerators even in
   19247              :      a template that does not get instantiated.  */
   19248     11578267 :   if (processing_template_decl)
   19249       430164 :     value = maybe_fold_non_dependent_expr (value);
   19250              : 
   19251              :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   19252              :      result in the enum being assigned the next value in sequence.  */
   19253     11578267 :   if (value == error_mark_node)
   19254              :     value = NULL_TREE;
   19255              : 
   19256              :   /* Remove no-op casts from the value.  */
   19257     11578229 :   if (value)
   19258      8652159 :     STRIP_TYPE_NOPS (value);
   19259              : 
   19260     11578267 :   if (! processing_template_decl)
   19261              :     {
   19262              :       /* Validate and default VALUE.  */
   19263     11148103 :       if (value != NULL_TREE)
   19264              :         {
   19265      5005304 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   19266              :             {
   19267      2653311 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   19268              :                                                            value, true);
   19269      2653311 :               if (tmp_value)
   19270      5005304 :                 value = tmp_value;
   19271              :             }
   19272      2351993 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19273              :                    (TREE_TYPE (value)))
   19274           39 :             value = perform_implicit_conversion_flags
   19275           39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   19276              :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   19277              : 
   19278      5005304 :           if (value == error_mark_node)
   19279              :             value = NULL_TREE;
   19280              : 
   19281      5005283 :           if (value != NULL_TREE)
   19282              :             {
   19283      5005283 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19284              :                   (TREE_TYPE (value)))
   19285              :                 {
   19286           17 :                   error_at (cp_expr_loc_or_input_loc (value),
   19287              :                             "enumerator value for %qD must have integral or "
   19288              :                             "unscoped enumeration type", name);
   19289           17 :                   value = NULL_TREE;
   19290              :                 }
   19291              :               else
   19292              :                 {
   19293      5005266 :                   value = cxx_constant_value (value);
   19294              : 
   19295      5005266 :                   if (TREE_CODE (value) != INTEGER_CST)
   19296              :                     {
   19297           47 :                       error ("enumerator value for %qD is not an integer "
   19298              :                              "constant", name);
   19299           47 :                       value = NULL_TREE;
   19300              :                     }
   19301              :                 }
   19302              :             }
   19303              :         }
   19304              : 
   19305              :       /* Default based on previous value.  */
   19306           64 :       if (value == NULL_TREE)
   19307              :         {
   19308      6142884 :           if (TYPE_VALUES (enumtype))
   19309              :             {
   19310      5615514 :               tree prev_value;
   19311              : 
   19312              :               /* C++03 7.2/4: If no initializer is specified for the first
   19313              :                  enumerator, the type is an unspecified integral
   19314              :                  type. Otherwise the type is the same as the type of the
   19315              :                  initializing value of the preceding enumerator unless the
   19316              :                  incremented value is not representable in that type, in
   19317              :                  which case the type is an unspecified integral type
   19318              :                  sufficient to contain the incremented value.  */
   19319      5615514 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   19320      5615514 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   19321            2 :                 value = error_mark_node;
   19322              :               else
   19323              :                 {
   19324      5615512 :                   wi::overflow_type overflowed;
   19325      5615512 :                   tree type = TREE_TYPE (prev_value);
   19326      5615512 :                   signop sgn = TYPE_SIGN (type);
   19327      5615512 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   19328      5615512 :                                            &overflowed);
   19329      5615512 :                   if (!overflowed)
   19330              :                     {
   19331      5615512 :                       bool pos = !wi::neg_p (wi, sgn);
   19332      5615512 :                       if (!wi::fits_to_tree_p (wi, type))
   19333              :                         {
   19334              :                           unsigned int itk;
   19335           53 :                           for (itk = itk_int; itk != itk_none; itk++)
   19336              :                             {
   19337           53 :                               type = integer_types[itk];
   19338           53 :                               if (type != NULL_TREE
   19339           53 :                                   && (pos || !TYPE_UNSIGNED (type))
   19340          106 :                                   && wi::fits_to_tree_p (wi, type))
   19341              :                                 break;
   19342              :                             }
   19343           17 :                           if (type && cxx_dialect < cxx11
   19344            6 :                               && itk > itk_unsigned_long)
   19345            3 :                             pedwarn (input_location, OPT_Wlong_long,
   19346              :                                      pos ? G_("\
   19347              : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   19348              : incremented enumerator value is too large for %<long%>"));
   19349              :                         }
   19350      5615512 :                       if (type == NULL_TREE)
   19351            0 :                         overflowed = wi::OVF_UNKNOWN;
   19352              :                       else
   19353      5615512 :                         value = wide_int_to_tree (type, wi);
   19354              :                     }
   19355              : 
   19356      5615512 :                   if (overflowed)
   19357              :                     {
   19358            0 :                       error ("overflow in enumeration values at %qD", name);
   19359            0 :                       value = error_mark_node;
   19360              :                     }
   19361      5615512 :                 }
   19362              :             }
   19363              :           else
   19364       527370 :             value = integer_zero_node;
   19365              :         }
   19366              : 
   19367              :       /* Remove no-op casts from the value.  */
   19368     11148103 :       STRIP_TYPE_NOPS (value);
   19369              : 
   19370              :       /* If the underlying type of the enum is fixed, check whether
   19371              :          the enumerator values fits in the underlying type.  If it
   19372              :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   19373     11148103 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   19374              :           && value
   19375     11148103 :           && TREE_CODE (value) == INTEGER_CST)
   19376              :         {
   19377      3795711 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   19378            9 :             error ("enumerator value %qE is outside the range of underlying "
   19379            9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   19380              : 
   19381              :           /* Convert the value to the appropriate type.  */
   19382      3795711 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   19383              :         }
   19384              :     }
   19385              : 
   19386              :   /* C++ associates enums with global, function, or class declarations.  */
   19387     11578267 :   context = current_scope ();
   19388              : 
   19389              :   /* Build the actual enumeration constant.  Note that the enumeration
   19390              :      constants have the underlying type of the enum (if it is fixed)
   19391              :      or the type of their initializer (if the underlying type of the
   19392              :      enum is not fixed):
   19393              : 
   19394              :       [ C++0x dcl.enum ]
   19395              : 
   19396              :         If the underlying type is fixed, the type of each enumerator
   19397              :         prior to the closing brace is the underlying type; if the
   19398              :         initializing value of an enumerator cannot be represented by
   19399              :         the underlying type, the program is ill-formed. If the
   19400              :         underlying type is not fixed, the type of each enumerator is
   19401              :         the type of its initializing value.
   19402              : 
   19403              :     If the underlying type is not fixed, it will be computed by
   19404              :     finish_enum and we will reset the type of this enumerator.  Of
   19405              :     course, if we're processing a template, there may be no value.  */
   19406     11578267 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   19407              : 
   19408     11578267 :   decl = build_decl (loc, CONST_DECL, name, type);
   19409              : 
   19410     11578267 :   DECL_CONTEXT (decl) = enumtype;
   19411     11578267 :   TREE_CONSTANT (decl) = 1;
   19412     11578267 :   TREE_READONLY (decl) = 1;
   19413     11578267 :   DECL_INITIAL (decl) = value;
   19414              : 
   19415     11578267 :   if (attributes)
   19416       122030 :     cplus_decl_attributes (&decl, attributes, 0);
   19417              : 
   19418     11578267 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   19419              :     {
   19420              :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   19421              :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   19422              :          things like `S::i' later.)  */
   19423              : 
   19424              :       /* The enumerator may be getting declared outside of its enclosing
   19425              :          class, like so:
   19426              : 
   19427              :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   19428              : 
   19429              :          For which case we need to make sure that the access of `S::i'
   19430              :          matches the access of `S::E'.  */
   19431      2089680 :       auto cas = make_temp_override (current_access_specifier);
   19432      2089680 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   19433      2089680 :       finish_member_declaration (decl);
   19434      2089680 :     }
   19435              :   else
   19436      9488587 :     pushdecl (decl);
   19437              : 
   19438              :   /* Add this enumeration constant to the list for this type.  */
   19439     11578267 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   19440              : 
   19441     11578267 :   return decl;
   19442              : }
   19443              : 
   19444              : /* Look for an enumerator with the given NAME within the enumeration
   19445              :    type ENUMTYPE.  This routine is used primarily for qualified name
   19446              :    lookup into an enumerator in C++0x, e.g.,
   19447              : 
   19448              :      enum class Color { Red, Green, Blue };
   19449              : 
   19450              :      Color color = Color::Red;
   19451              : 
   19452              :    Returns the value corresponding to the enumerator, or
   19453              :    NULL_TREE if no such enumerator was found.  */
   19454              : tree
   19455     26886389 : lookup_enumerator (tree enumtype, tree name)
   19456              : {
   19457     26886389 :   tree e;
   19458     26886389 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   19459              : 
   19460     26886389 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   19461     53772633 :   return e? TREE_VALUE (e) : NULL_TREE;
   19462              : }
   19463              : 
   19464              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   19465              : 
   19466              : tree
   19467            0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   19468              :                         vec<string_int_pair> *values)
   19469              : {
   19470            0 :   location_t saved_loc = input_location;
   19471            0 :   input_location = loc;
   19472              : 
   19473            0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   19474              :                               NULL_TREE, false, NULL);
   19475            0 :   if (!OPAQUE_ENUM_P (enumtype))
   19476              :     {
   19477            0 :       auto_diagnostic_group d;
   19478            0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   19479            0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19480              :               "previous definition here");
   19481            0 :       return enumtype;
   19482            0 :     }
   19483            0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   19484            0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   19485              : 
   19486            0 :   for (const string_int_pair &value : values)
   19487            0 :     build_enumerator (get_identifier (value.first),
   19488            0 :                       build_int_cst (integer_type_node, value.second),
   19489              :                       enumtype, NULL_TREE, loc);
   19490              : 
   19491            0 :   finish_enum_value_list (enumtype);
   19492            0 :   finish_enum (enumtype);
   19493              : 
   19494            0 :   input_location = saved_loc;
   19495            0 :   return enumtype;
   19496              : }
   19497              : 
   19498              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   19499              : 
   19500              : tree
   19501            0 : cxx_simulate_record_decl (location_t loc, const char *name,
   19502              :                           array_slice<const tree> fields)
   19503              : {
   19504            0 :   iloc_sentinel ils (loc);
   19505              : 
   19506            0 :   tree ident = get_identifier (name);
   19507            0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   19508            0 :   if (type != error_mark_node
   19509            0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   19510              :     {
   19511            0 :       error ("redefinition of %q#T", type);
   19512            0 :       type = error_mark_node;
   19513              :     }
   19514            0 :   if (type == error_mark_node)
   19515            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19516              : 
   19517            0 :   xref_basetypes (type, NULL_TREE);
   19518            0 :   type = begin_class_definition (type);
   19519            0 :   if (type == error_mark_node)
   19520            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19521              : 
   19522            0 :   for (tree field : fields)
   19523            0 :     finish_member_declaration (field);
   19524              : 
   19525            0 :   type = finish_struct (type, NULL_TREE);
   19526              : 
   19527            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   19528            0 :   set_underlying_type (decl);
   19529            0 :   lang_hooks.decls.pushdecl (decl);
   19530              : 
   19531            0 :   return type;
   19532            0 : }
   19533              : 
   19534              : /* We're defining DECL.  Make sure that its type is OK.  */
   19535              : 
   19536              : static void
   19537    166164470 : check_function_type (tree decl, tree current_function_parms)
   19538              : {
   19539    166164470 :   tree fntype = TREE_TYPE (decl);
   19540    166164470 :   tree return_type = complete_type (TREE_TYPE (fntype));
   19541              : 
   19542              :   /* In a function definition, arg types must be complete.  */
   19543    166164470 :   require_complete_types_for_parms (current_function_parms);
   19544              : 
   19545    166164470 :   if (dependent_type_p (return_type)
   19546    166164470 :       || type_uses_auto (return_type))
   19547     50831364 :     return;
   19548    115333106 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   19549              :     {
   19550           12 :       tree args = TYPE_ARG_TYPES (fntype);
   19551              : 
   19552           12 :       error ("return type %q#T is incomplete", return_type);
   19553              : 
   19554              :       /* Make it return void instead.  */
   19555           12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   19556            3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   19557              :                                              void_type_node,
   19558            3 :                                              TREE_CHAIN (args));
   19559              :       else
   19560           18 :         fntype = build_function_type (void_type_node, args,
   19561            9 :                                       TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
   19562           12 :       fntype = (cp_build_type_attribute_variant
   19563           12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   19564           12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   19565           12 :       TREE_TYPE (decl) = fntype;
   19566              :     }
   19567              :   else
   19568              :     {
   19569    115333094 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   19570    115333094 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   19571    115333094 :                            DECL_SOURCE_LOCATION (decl));
   19572              :     }
   19573              : }
   19574              : 
   19575              : /* True iff FN is an implicitly-defined default constructor.  */
   19576              : 
   19577              : static bool
   19578     18959870 : implicit_default_ctor_p (tree fn)
   19579              : {
   19580     18959870 :   return (DECL_CONSTRUCTOR_P (fn)
   19581     18959870 :           && !user_provided_p (fn)
   19582     21969093 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   19583              : }
   19584              : 
   19585              : /* Clobber the contents of *this to let the back end know that the object
   19586              :    storage is dead when we enter the constructor or leave the destructor.  */
   19587              : 
   19588              : static tree
   19589      1557397 : build_clobber_this (clobber_kind kind)
   19590              : {
   19591              :   /* Clobbering an empty base is pointless, and harmful if its one byte
   19592              :      TYPE_SIZE overlays real data.  */
   19593      1557397 :   if (is_empty_class (current_class_type))
   19594            0 :     return void_node;
   19595              : 
   19596              :   /* If we have virtual bases, clobber the whole object, but only if we're in
   19597              :      charge.  If we don't have virtual bases, clobber the as-base type so we
   19598              :      don't mess with tail padding.  */
   19599      1557397 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   19600              : 
   19601      1557397 :   tree ctype = current_class_type;
   19602      1557397 :   if (!vbases)
   19603      1550480 :     ctype = CLASSTYPE_AS_BASE (ctype);
   19604              : 
   19605      1557397 :   tree clobber = build_clobber (ctype, kind);
   19606              : 
   19607      1557397 :   tree thisref = current_class_ref;
   19608      1557397 :   if (ctype != current_class_type)
   19609              :     {
   19610       166736 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   19611       166736 :       thisref = convert_from_reference (thisref);
   19612              :     }
   19613              : 
   19614      1557397 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   19615      1557397 :   if (kind == CLOBBER_OBJECT_BEGIN)
   19616            0 :     TREE_SET_CODE (exprstmt, INIT_EXPR);
   19617      1557397 :   if (vbases)
   19618         6917 :     exprstmt = build_if_in_charge (exprstmt);
   19619              : 
   19620              :   return exprstmt;
   19621              : }
   19622              : 
   19623              : /* Create the FUNCTION_DECL for a function definition.
   19624              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   19625              :    they describe the function's name and the type it returns,
   19626              :    but twisted together in a fashion that parallels the syntax of C.
   19627              : 
   19628              :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   19629              :    DECLARATOR is really the DECL for the function we are about to
   19630              :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   19631              :    indicating that the function is an inline defined in-class.
   19632              : 
   19633              :    This function creates a binding context for the function body
   19634              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   19635              : 
   19636              :    For C++, we must first check whether that datum makes any sense.
   19637              :    For example, "class A local_a(1,2);" means that variable local_a
   19638              :    is an aggregate of type A, which should have a constructor
   19639              :    applied to it with the argument list [1, 2].
   19640              : 
   19641              :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   19642              :    or may be a BLOCK if the function has been defined previously
   19643              :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   19644              :    error_mark_node if the function has never been defined, or
   19645              :    a BLOCK if the function has been defined somewhere.  */
   19646              : 
   19647              : bool
   19648    166164506 : start_preparsed_function (tree decl1, tree attrs, int flags)
   19649              : {
   19650    166164506 :   tree ctype = NULL_TREE;
   19651    166164506 :   bool doing_friend = false;
   19652              : 
   19653              :   /* Sanity check.  */
   19654    166164506 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   19655    166164506 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   19656              : 
   19657    166164506 :   tree fntype = TREE_TYPE (decl1);
   19658    166164506 :   if (DECL_CLASS_SCOPE_P (decl1))
   19659    123916335 :     ctype = DECL_CONTEXT (decl1);
   19660              :   else
   19661              :     {
   19662     84496342 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   19663              : 
   19664     42248170 :       if (ctype)
   19665    166164506 :         doing_friend = true;
   19666              :     }
   19667              : 
   19668              :   /* Adjust for #pragma target/optimize if this is an artificial function that
   19669              :      (probably) didn't go through grokfndecl.  We particularly don't want this
   19670              :      for deferred instantiations, which should match their template.  */
   19671    166164506 :   if (DECL_ARTIFICIAL (decl1))
   19672      4563509 :     decl_attributes (&decl1, NULL_TREE, 0);
   19673              : 
   19674    166164506 :   if (DECL_DECLARED_INLINE_P (decl1)
   19675    166164506 :       && lookup_attribute ("noinline", attrs))
   19676              :     {
   19677            0 :       auto_urlify_attributes sentinel;
   19678            0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   19679              :                   "inline function %qD given attribute %qs", decl1, "noinline");
   19680            0 :     }
   19681              : 
   19682              :   /* Handle gnu_inline attribute.  */
   19683    166164506 :   if (GNU_INLINE_P (decl1))
   19684              :     {
   19685      1868240 :       DECL_EXTERNAL (decl1) = 1;
   19686      1868240 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   19687      1868240 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   19688      1868240 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   19689              :     }
   19690              : 
   19691    166164506 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   19692              :     /* This is a constructor, we must ensure that any default args
   19693              :        introduced by this definition are propagated to the clones
   19694              :        now. The clones are used directly in overload resolution.  */
   19695     20499000 :     adjust_clone_args (decl1);
   19696              : 
   19697              :   /* Sometimes we don't notice that a function is a static member, and
   19698              :      build a METHOD_TYPE for it.  Fix that up now.  */
   19699    166164506 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   19700              :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   19701              : 
   19702              :   /* Set up current_class_type, and enter the scope of the class, if
   19703              :      appropriate.  */
   19704    166164506 :   if (ctype)
   19705    128338981 :     push_nested_class (ctype);
   19706              : 
   19707              :   /* Now that we have entered the scope of the class, we must restore
   19708              :      the bindings for any template parameters surrounding DECL1, if it
   19709              :      is an inline member template.  (Order is important; consider the
   19710              :      case where a template parameter has the same name as a field of
   19711              :      the class.)  It is not until after this point that
   19712              :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   19713    166164506 :   if (flags & SF_INCLASS_INLINE)
   19714     80853522 :     maybe_begin_member_template_processing (decl1);
   19715              : 
   19716              :   /* Effective C++ rule 15.  */
   19717    166164506 :   if (warn_ecpp
   19718          123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   19719           30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   19720    166164536 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   19721            0 :     warning (OPT_Weffc__,
   19722              :              "%<operator=%> should return a reference to %<*this%>");
   19723              : 
   19724              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   19725              :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   19726    166164506 :   if (!DECL_INITIAL (decl1))
   19727     43174166 :     DECL_INITIAL (decl1) = error_mark_node;
   19728              : 
   19729              :   /* This function exists in static storage.
   19730              :      (This does not mean `static' in the C sense!)  */
   19731    166164506 :   TREE_STATIC (decl1) = 1;
   19732              : 
   19733              :   /* We must call push_template_decl after current_class_type is set
   19734              :      up.  (If we are processing inline definitions after exiting a
   19735              :      class scope, current_class_type will be NULL_TREE until set above
   19736              :      by push_nested_class.)  */
   19737    166164506 :   if (processing_template_decl)
   19738              :     {
   19739     92216973 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   19740     92216973 :       if (newdecl1 == error_mark_node)
   19741              :         {
   19742           36 :           if (ctype)
   19743            9 :             pop_nested_class ();
   19744           36 :           return false;
   19745              :         }
   19746     92216937 :       decl1 = newdecl1;
   19747              :     }
   19748              : 
   19749              :   /* Make sure the parameter and return types are reasonable.  When
   19750              :      you declare a function, these types can be incomplete, but they
   19751              :      must be complete when you define the function.  */
   19752    166164470 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   19753              : 
   19754              :   /* Build the return declaration for the function.  */
   19755    166164470 :   tree restype = TREE_TYPE (fntype);
   19756              : 
   19757    166164470 :   if (DECL_RESULT (decl1) == NULL_TREE)
   19758              :     {
   19759              :       /* In a template instantiation, copy the return type location.  When
   19760              :          parsing, the location will be set in grokdeclarator.  */
   19761     73705808 :       location_t loc = input_location;
   19762     73705808 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   19763              :         {
   19764     39150701 :           tree tmpl = template_for_substitution (decl1);
   19765     39150701 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   19766     37228538 :             loc = DECL_SOURCE_LOCATION (res);
   19767              :         }
   19768              : 
   19769     73705808 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   19770     73705808 :       DECL_ARTIFICIAL (resdecl) = 1;
   19771     73705808 :       DECL_IGNORED_P (resdecl) = 1;
   19772     73705808 :       DECL_RESULT (decl1) = resdecl;
   19773              : 
   19774     73705808 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   19775              :     }
   19776              : 
   19777              :   /* Record the decl so that the function name is defined.
   19778              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   19779              :      use the old decl.  */
   19780    166164470 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   19781              :     {
   19782              :       /* A specialization is not used to guide overload resolution.  */
   19783     19476969 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   19784     19457848 :           && !(DECL_USE_TEMPLATE (decl1) &&
   19785        12399 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   19786              :         {
   19787      9321455 :           tree olddecl = pushdecl (decl1);
   19788              : 
   19789      9321455 :           if (olddecl == error_mark_node)
   19790              :             /* If something went wrong when registering the declaration,
   19791              :                use DECL1; we have to have a FUNCTION_DECL to use when
   19792              :                parsing the body of the function.  */
   19793              :             ;
   19794              :           else
   19795              :             {
   19796              :               /* Otherwise, OLDDECL is either a previous declaration
   19797              :                  of the same function or DECL1 itself.  */
   19798              : 
   19799      9321245 :               if (warn_missing_declarations
   19800           21 :                   && olddecl == decl1
   19801           15 :                   && !DECL_MAIN_P (decl1)
   19802           15 :                   && TREE_PUBLIC (decl1)
   19803      9321257 :                   && !DECL_DECLARED_INLINE_P (decl1))
   19804              :                 {
   19805            9 :                   tree context;
   19806              : 
   19807              :                   /* Check whether DECL1 is in an anonymous
   19808              :                      namespace.  */
   19809            9 :                   for (context = DECL_CONTEXT (decl1);
   19810           18 :                        context;
   19811            9 :                        context = DECL_CONTEXT (context))
   19812              :                     {
   19813           12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   19814           12 :                           && DECL_NAME (context) == NULL_TREE)
   19815              :                         break;
   19816              :                     }
   19817              : 
   19818            9 :                   if (context == NULL)
   19819            6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   19820            6 :                                 OPT_Wmissing_declarations,
   19821              :                                 "no previous declaration for %qD", decl1);
   19822              :                 }
   19823              : 
   19824      9321245 :               decl1 = olddecl;
   19825              :             }
   19826              :         }
   19827              :       else
   19828              :         {
   19829              :           /* We need to set the DECL_CONTEXT.  */
   19830       802539 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   19831            0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   19832              :         }
   19833     10123994 :       fntype = TREE_TYPE (decl1);
   19834     10123994 :       restype = TREE_TYPE (fntype);
   19835              : 
   19836              :       /* If #pragma weak applies, mark the decl appropriately now.
   19837              :          The pragma only applies to global functions.  Because
   19838              :          determining whether or not the #pragma applies involves
   19839              :          computing the mangled name for the declaration, we cannot
   19840              :          apply the pragma until after we have merged this declaration
   19841              :          with any previous declarations; if the original declaration
   19842              :          has a linkage specification, that specification applies to
   19843              :          the definition as well, and may affect the mangled name.  */
   19844     10123994 :       if (DECL_FILE_SCOPE_P (decl1))
   19845      2486197 :         maybe_apply_pragma_weak (decl1);
   19846              :     }
   19847              : 
   19848              :   /* We are now in the scope of the function being defined.  */
   19849    166164470 :   current_function_decl = decl1;
   19850              : 
   19851              :   /* Save the parm names or decls from this function's declarator
   19852              :      where store_parm_decls will find them.  */
   19853    166164470 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   19854              : 
   19855              :   /* Let the user know we're compiling this function.  */
   19856    166164470 :   announce_function (decl1);
   19857              : 
   19858    166164470 :   gcc_assert (DECL_INITIAL (decl1));
   19859              : 
   19860              :   /* This function may already have been parsed, in which case just
   19861              :      return; our caller will skip over the body without parsing.  */
   19862    166164470 :   if (DECL_INITIAL (decl1) != error_mark_node)
   19863              :     return true;
   19864              : 
   19865              :   /* Initialize RTL machinery.  We cannot do this until
   19866              :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   19867              :      even when processing a template; this is how we get
   19868              :      CFUN set up, and our per-function variables initialized.
   19869              :      FIXME factor out the non-RTL stuff.  */
   19870    166164470 :   cp_binding_level *bl = current_binding_level;
   19871    166164470 :   allocate_struct_function (decl1, processing_template_decl);
   19872              : 
   19873              :   /* Initialize the language data structures.  Whenever we start
   19874              :      a new function, we destroy temporaries in the usual way.  */
   19875    166164470 :   cfun->language = ggc_cleared_alloc<language_function> ();
   19876    166164470 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   19877    166164470 :   current_binding_level = bl;
   19878              : 
   19879              :   /* If we are (erroneously) defining a function that we have already
   19880              :      defined before, wipe out what we knew before.  */
   19881    166164470 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   19882    166164470 :   FNDECL_USED_AUTO (decl1) = false;
   19883    166164470 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   19884              : 
   19885    166164470 :   if (!processing_template_decl && type_uses_auto (restype))
   19886              :     {
   19887      2225154 :       FNDECL_USED_AUTO (decl1) = true;
   19888      2225154 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   19889              :     }
   19890              : 
   19891              :   /* Start the statement-tree, start the tree now.  */
   19892    166164470 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   19893              : 
   19894    166164470 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   19895              :     {
   19896              :       /* We know that this was set up by `grokclassfn'.  We do not
   19897              :          wait until `store_parm_decls', since evil parse errors may
   19898              :          never get us to that point.  Here we keep the consistency
   19899              :          between `current_class_type' and `current_class_ptr'.  */
   19900    109677448 :       tree t = DECL_ARGUMENTS (decl1);
   19901              : 
   19902    109677448 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   19903    109677448 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   19904              : 
   19905    109677448 :       cp_function_chain->x_current_class_ref
   19906    109677448 :         = cp_build_fold_indirect_ref (t);
   19907              :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   19908    109677448 :       cp_function_chain->x_current_class_ptr = t;
   19909              : 
   19910              :       /* Constructors and destructors need to know whether they're "in
   19911              :          charge" of initializing virtual base classes.  */
   19912    109677448 :       t = DECL_CHAIN (t);
   19913    109677448 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   19914              :         {
   19915        16317 :           current_in_charge_parm = t;
   19916        16317 :           t = DECL_CHAIN (t);
   19917              :         }
   19918    109677448 :       if (DECL_HAS_VTT_PARM_P (decl1))
   19919              :         {
   19920        32677 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   19921        32677 :           current_vtt_parm = t;
   19922              :         }
   19923              :     }
   19924              : 
   19925    293129850 :   bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
   19926              :                           /* Implicitly-defined methods (like the
   19927              :                              destructor for a class in which no destructor
   19928              :                              is explicitly declared) must not be defined
   19929              :                              until their definition is needed.  So, we
   19930              :                              ignore interface specifications for
   19931              :                              compiler-generated functions.  */
   19932    200776214 :                           && !DECL_ARTIFICIAL (decl1));
   19933    166164470 :   struct c_fileinfo *finfo
   19934    166164470 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   19935              : 
   19936    166164470 :   if (processing_template_decl)
   19937              :     /* Don't mess with interface flags.  */;
   19938     73947533 :   else if (DECL_INTERFACE_KNOWN (decl1))
   19939              :     {
   19940     21114479 :       tree ctx = decl_function_context (decl1);
   19941              : 
   19942     21114479 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   19943     17495611 :         DECL_EXTERNAL (decl1) = 0;
   19944              : 
   19945     21114479 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   19946              :         /* This is a function in a local class in an extern inline
   19947              :            or template function.  */
   19948      4013324 :         comdat_linkage (decl1);
   19949              :     }
   19950              :   /* If this function belongs to an interface, it is public.
   19951              :      If it belongs to someone else's interface, it is also external.
   19952              :      This only affects inlines and template instantiations.  */
   19953     52833054 :   else if (!finfo->interface_unknown && honor_interface)
   19954              :     {
   19955          106 :       if (DECL_DECLARED_INLINE_P (decl1)
   19956          106 :           || DECL_TEMPLOID_INSTANTIATION (decl1))
   19957              :         {
   19958           82 :           DECL_EXTERNAL (decl1)
   19959          164 :             = (finfo->interface_only
   19960           82 :                || (DECL_DECLARED_INLINE_P (decl1)
   19961           36 :                    && ! flag_implement_inlines
   19962            0 :                    && !DECL_VINDEX (decl1)));
   19963              : 
   19964              :           /* For WIN32 we also want to put these in linkonce sections.  */
   19965           82 :           maybe_make_one_only (decl1);
   19966              :         }
   19967              :       else
   19968           24 :         DECL_EXTERNAL (decl1) = 0;
   19969          106 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   19970              :       /* If this function is in an interface implemented in this file,
   19971              :          make sure that the back end knows to emit this function
   19972              :          here.  */
   19973          106 :       if (!DECL_EXTERNAL (decl1))
   19974           60 :         mark_needed (decl1);
   19975              :     }
   19976     52832948 :   else if (finfo->interface_unknown && finfo->interface_only
   19977            0 :            && honor_interface)
   19978              :     {
   19979              :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   19980              :          interface, we will have both finfo->interface_unknown and
   19981              :          finfo->interface_only set.  In that case, we don't want to
   19982              :          use the normal heuristics because someone will supply a
   19983              :          #pragma implementation elsewhere, and deducing it here would
   19984              :          produce a conflict.  */
   19985            0 :       comdat_linkage (decl1);
   19986            0 :       DECL_EXTERNAL (decl1) = 0;
   19987            0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   19988            0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   19989              :     }
   19990              :   else
   19991              :     {
   19992              :       /* This is a definition, not a reference.
   19993              :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   19994     52832948 :       if (!GNU_INLINE_P (decl1))
   19995     52832945 :         DECL_EXTERNAL (decl1) = 0;
   19996              : 
   19997     52832948 :       if ((DECL_DECLARED_INLINE_P (decl1)
   19998      2004769 :            || DECL_TEMPLOID_INSTANTIATION (decl1))
   19999     54601094 :           && ! DECL_INTERFACE_KNOWN (decl1))
   20000     52596325 :         DECL_DEFER_OUTPUT (decl1) = 1;
   20001              :       else
   20002       236623 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   20003              :     }
   20004              : 
   20005              :   /* Determine the ELF visibility attribute for the function.  We must not
   20006              :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   20007              :      to merge any attributes appropriately.  We also need to wait until
   20008              :      linkage is set.  */
   20009    166164470 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   20010    148596024 :     determine_visibility (decl1);
   20011              : 
   20012    166164470 :   if (!processing_template_decl)
   20013     73947533 :     maybe_instantiate_noexcept (decl1);
   20014              : 
   20015    166164470 :   begin_scope (sk_function_parms, decl1);
   20016              : 
   20017    166164470 :   ++function_depth;
   20018              : 
   20019    166164470 :   start_fname_decls ();
   20020              : 
   20021    166164470 :   store_parm_decls (current_function_parms);
   20022              : 
   20023    166164470 :   start_function_contracts (decl1);
   20024              : 
   20025    166164470 :   if (!processing_template_decl
   20026     73947533 :       && flag_lifetime_dse > 1
   20027    147885754 :       && DECL_CONSTRUCTOR_P (decl1)
   20028              :       /* Clobbering an empty base is harmful if it overlays real data.  */
   20029     20813141 :       && !is_empty_class (current_class_type)
   20030              :       /* We can't clobber safely for an implicitly-defined default constructor
   20031              :          because part of the initialization might happen before we enter the
   20032              :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   20033     18959234 :       && !implicit_default_ctor_p (decl1)
   20034    182888205 :       && !lookup_attribute ("clobber *this",
   20035     16723735 :                             DECL_ATTRIBUTES (current_class_ptr)))
   20036     16715675 :     DECL_ATTRIBUTES (current_class_ptr)
   20037     33431350 :       = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
   20038     16715675 :                    DECL_ATTRIBUTES (current_class_ptr));
   20039              : 
   20040    166164470 :   if (!processing_template_decl
   20041    147895066 :       && DECL_CONSTRUCTOR_P (decl1)
   20042     20814383 :       && sanitize_flags_p (SANITIZE_VPTR)
   20043         1908 :       && !DECL_CLONED_FUNCTION_P (decl1)
   20044    166165106 :       && !implicit_default_ctor_p (decl1))
   20045          480 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   20046              : 
   20047    166164470 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   20048    166163901 :     start_lambda_scope (decl1);
   20049              : 
   20050              :   return true;
   20051              : }
   20052              : 
   20053              : 
   20054              : /* Like start_preparsed_function, except that instead of a
   20055              :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   20056              : 
   20057              :    Returns true on success.  If the DECLARATOR is not suitable
   20058              :    for a function, we return false, which tells the parser to
   20059              :    skip the entire function.  */
   20060              : 
   20061              : bool
   20062     37815754 : start_function (cp_decl_specifier_seq *declspecs,
   20063              :                 const cp_declarator *declarator,
   20064              :                 tree attrs)
   20065              : {
   20066     37815754 :   tree decl1;
   20067              : 
   20068     37815754 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   20069     37815754 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   20070     37815754 :   if (decl1 == error_mark_node)
   20071              :     return false;
   20072              : 
   20073     37815435 :   if (DECL_MAIN_P (decl1))
   20074              :     /* main must return int.  grokfndecl should have corrected it
   20075              :        (and issued a diagnostic) if the user got it wrong.  */
   20076        33077 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   20077              :                              integer_type_node));
   20078              : 
   20079     37815435 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   20080              : }
   20081              : 
   20082              : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   20083              :    FN.  */
   20084              : 
   20085              : bool
   20086    318416545 : use_eh_spec_block (tree fn)
   20087              : {
   20088    316495792 :   return (flag_exceptions && flag_enforce_eh_specs
   20089    316495792 :           && !processing_template_decl
   20090              :           /* We insert the EH_SPEC_BLOCK only in the original
   20091              :              function; then, it is copied automatically to the
   20092              :              clones.  */
   20093    130839044 :           && !DECL_CLONED_FUNCTION_P (fn)
   20094              :           /* Implicitly-generated constructors and destructors have
   20095              :              exception specifications.  However, those specifications
   20096              :              are the union of the possible exceptions specified by the
   20097              :              constructors/destructors for bases and members, so no
   20098              :              unallowed exception will ever reach this function.  By
   20099              :              not creating the EH_SPEC_BLOCK we save a little memory,
   20100              :              and we avoid spurious warnings about unreachable
   20101              :              code.  */
   20102    113311165 :           && !DECL_DEFAULTED_FN (fn)
   20103    428505994 :           && !type_throw_all_p (TREE_TYPE (fn)));
   20104              : }
   20105              : 
   20106              : /* Helper function to push ARGS into the current lexical scope.  DECL
   20107              :    is the function declaration.  NONPARMS is used to handle enum
   20108              :    constants.  */
   20109              : 
   20110              : void
   20111    161082401 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   20112              : {
   20113              :   /* If we're doing semantic analysis, then we'll call pushdecl
   20114              :      for each of these.  We must do them in reverse order so that
   20115              :      they end in the correct forward order.  */
   20116    161082401 :   args = nreverse (args);
   20117              : 
   20118    161082401 :   tree next;
   20119    492412046 :   for (tree parm = args; parm; parm = next)
   20120              :     {
   20121    331329645 :       next = DECL_CHAIN (parm);
   20122    331329645 :       if (TREE_CODE (parm) == PARM_DECL)
   20123    331329645 :         pushdecl (parm);
   20124            0 :       else if (nonparms)
   20125              :         {
   20126              :           /* If we find an enum constant or a type tag, put it aside for
   20127              :              the moment.  */
   20128            0 :           TREE_CHAIN (parm) = NULL_TREE;
   20129            0 :           *nonparms = chainon (*nonparms, parm);
   20130              :         }
   20131              :     }
   20132              : 
   20133              :   /* Get the decls in their original chain order and record in the
   20134              :      function.  This is all and only the PARM_DECLs that were
   20135              :      pushed into scope by the loop above.  */
   20136    161082401 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   20137    161082401 : }
   20138              : 
   20139              : /* Store the parameter declarations into the current function declaration.
   20140              :    This is called after parsing the parameter declarations, before
   20141              :    digesting the body of the function.
   20142              : 
   20143              :    Also install to binding contour return value identifier, if any.  */
   20144              : 
   20145              : static void
   20146    166164470 : store_parm_decls (tree current_function_parms)
   20147              : {
   20148    166164470 :   tree fndecl = current_function_decl;
   20149              : 
   20150              :   /* This is a chain of any other decls that came in among the parm
   20151              :      declarations.  If a parm is declared with  enum {foo, bar} x;
   20152              :      then CONST_DECLs for foo and bar are put here.  */
   20153    166164470 :   tree nonparms = NULL_TREE;
   20154              : 
   20155    166164470 :   if (current_function_parms)
   20156              :     {
   20157              :       /* This case is when the function was defined with an ANSI prototype.
   20158              :          The parms already have decls, so we need not do anything here
   20159              :          except record them as in effect
   20160              :          and complain if any redundant old-style parm decls were written.  */
   20161              : 
   20162    157794050 :       tree specparms = current_function_parms;
   20163              : 
   20164              :       /* Must clear this because it might contain TYPE_DECLs declared
   20165              :              at class level.  */
   20166    157794050 :       current_binding_level->names = NULL;
   20167              : 
   20168    157794050 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   20169              :     }
   20170              :   else
   20171      8370420 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   20172              : 
   20173              :   /* Now store the final chain of decls for the arguments
   20174              :      as the decl-chain of the current lexical scope.
   20175              :      Put the enumerators in as well, at the front so that
   20176              :      DECL_ARGUMENTS is not modified.  */
   20177    166164470 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   20178              : 
   20179    166164470 :   if (use_eh_spec_block (current_function_decl))
   20180     25581090 :     current_eh_spec_block = begin_eh_spec_block ();
   20181    166164470 : }
   20182              : 
   20183              : 
   20184              : /* Mark CDTOR's implicit THIS argument for returning, if required by
   20185              :    the ABI..  Return the decl for THIS, if it is to be returned, and
   20186              :    NULL otherwise.  */
   20187              : 
   20188              : tree
   20189    147307990 : maybe_prepare_return_this (tree cdtor)
   20190              : {
   20191    147307990 :   if (targetm.cxx.cdtor_returns_this ())
   20192            0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   20193              :       {
   20194            0 :         suppress_warning (val, OPT_Wuse_after_free);
   20195            0 :         return val;
   20196              :       }
   20197              : 
   20198              :   return NULL_TREE;
   20199              : }
   20200              : 
   20201              : /* Set the return value of the [cd]tor if the ABI wants that.  */
   20202              : 
   20203              : void
   20204      8924860 : maybe_return_this ()
   20205              : {
   20206      8924860 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   20207              :     {
   20208              :       /* Return the address of the object.  */
   20209            0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   20210            0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   20211            0 :                     DECL_RESULT (current_function_decl), val);
   20212            0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   20213            0 :       add_stmt (exprstmt);
   20214              :     }
   20215      8924860 : }
   20216              : 
   20217              : /* Do all the processing for the beginning of a destructor; set up the
   20218              :    vtable pointers and cleanups for bases and members.  */
   20219              : 
   20220              : static void
   20221      1693685 : begin_destructor_body (void)
   20222              : {
   20223      1693685 :   tree compound_stmt;
   20224              : 
   20225              :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   20226              :      issued an error message.  We still want to try to process the
   20227              :      body of the function, but initialize_vtbl_ptrs will crash if
   20228              :      TYPE_BINFO is NULL.  */
   20229      1693685 :   if (COMPLETE_TYPE_P (current_class_type))
   20230              :     {
   20231      1693685 :       compound_stmt = begin_compound_stmt (0);
   20232              :       /* Make all virtual function table pointers in non-virtual base
   20233              :          classes point to CURRENT_CLASS_TYPE's virtual function
   20234              :          tables.  */
   20235      1693685 :       initialize_vtbl_ptrs (current_class_ptr);
   20236      1693685 :       finish_compound_stmt (compound_stmt);
   20237              : 
   20238      1693685 :       if (flag_lifetime_dse
   20239              :           /* Clobbering an empty base is harmful if it overlays real data.  */
   20240      1693685 :           && !is_empty_class (current_class_type))
   20241              :       {
   20242      1557460 :         if (sanitize_flags_p (SANITIZE_VPTR)
   20243          236 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   20244      1557523 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   20245              :           {
   20246           63 :             tree binfo = TYPE_BINFO (current_class_type);
   20247           63 :             tree ref
   20248           63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   20249              : 
   20250           63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   20251           63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   20252           63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   20253              :                                               NOP_EXPR, vtbl,
   20254              :                                               tf_warning_or_error);
   20255              :             /* If the vptr is shared with some virtual nearly empty base,
   20256              :                don't clear it if not in charge, the dtor of the virtual
   20257              :                nearly empty base will do that later.  */
   20258           63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   20259              :               {
   20260              :                 tree c = current_class_type;
   20261           66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   20262              :                   {
   20263           63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   20264              :                       {
   20265           36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   20266              :                                                 tf_warning_or_error);
   20267           36 :                         stmt = build_if_in_charge (stmt);
   20268           36 :                         break;
   20269              :                       }
   20270           27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   20271              :                   }
   20272              :               }
   20273           63 :             finish_decl_cleanup (NULL_TREE, stmt);
   20274              :           }
   20275              :         else
   20276      1557397 :           finish_decl_cleanup (NULL_TREE,
   20277              :                                build_clobber_this (CLOBBER_OBJECT_END));
   20278              :       }
   20279              : 
   20280              :       /* And insert cleanups for our bases and members so that they
   20281              :          will be properly destroyed if we throw.  */
   20282      1693685 :       push_base_cleanups ();
   20283              :     }
   20284      1693685 : }
   20285              : 
   20286              : /* Do the necessary processing for the beginning of a function body, which
   20287              :    in this case includes member-initializers, but not the catch clauses of
   20288              :    a function-try-block.  Currently, this means opening a binding level
   20289              :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   20290              :    and capture proxies (in a lambda operator()).  */
   20291              : 
   20292              : tree
   20293    125346904 : begin_function_body (void)
   20294              : {
   20295    258649824 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   20296              :     return NULL_TREE;
   20297              : 
   20298     25886491 :   if (processing_template_decl)
   20299              :     /* Do nothing now.  */;
   20300              :   else
   20301              :     /* Always keep the BLOCK node associated with the outermost pair of
   20302              :        curly braces of a function.  These are needed for correct
   20303              :        operation of dwarfout.c.  */
   20304      9813250 :     keep_next_level (true);
   20305              : 
   20306     25886491 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   20307     25886491 :   current_binding_level->artificial = 1;
   20308              : 
   20309     25886491 :   if (processing_template_decl)
   20310              :     /* Do nothing now.  */;
   20311     19626500 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   20312      1693685 :     begin_destructor_body ();
   20313              : 
   20314              :   return stmt;
   20315              : }
   20316              : 
   20317              : /* Do the processing for the end of a function body.  Currently, this means
   20318              :    closing out the cleanups for fully-constructed bases and members, and in
   20319              :    the case of the destructor, deleting the object if desired.  Again, this
   20320              :    is only meaningful for [cd]tors, since they are the only functions where
   20321              :    there is a significant distinction between the main body and any
   20322              :    function catch clauses.  Handling, say, main() return semantics here
   20323              :    would be wrong, as flowing off the end of a function catch clause for
   20324              :    main() would also need to return 0.  */
   20325              : 
   20326              : void
   20327    125346880 : finish_function_body (tree compstmt)
   20328              : {
   20329    125346880 :   if (compstmt == NULL_TREE)
   20330              :     return;
   20331              : 
   20332              :   /* Close the block.  */
   20333     25886491 :   finish_compound_stmt (compstmt);
   20334              : 
   20335     25886491 :   if (processing_template_decl)
   20336              :     /* Do nothing now.  */;
   20337      9813250 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   20338      9813250 :            || DECL_DESTRUCTOR_P (current_function_decl))
   20339      8627840 :     maybe_return_this ();
   20340              : }
   20341              : 
   20342              : /* Given a function, returns the BLOCK corresponding to the outermost level
   20343              :    of curly braces, skipping the artificial block created for constructor
   20344              :    initializers.  */
   20345              : 
   20346              : tree
   20347       388055 : outer_curly_brace_block (tree fndecl)
   20348              : {
   20349       388055 :   tree block = DECL_INITIAL (fndecl);
   20350       388055 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20351              :     return block;
   20352         1025 :   block = BLOCK_SUBBLOCKS (block);
   20353         1025 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20354              :     return block;
   20355            0 :   block = BLOCK_SUBBLOCKS (block);
   20356            0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   20357              :   return block;
   20358              : }
   20359              : 
   20360              : /* If FNDECL is a class's key method, add the class to the list of
   20361              :    keyed classes that should be emitted.  */
   20362              : 
   20363              : static void
   20364    166168416 : record_key_method_defined (tree fndecl)
   20365              : {
   20366    222659360 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   20367    109757378 :       && DECL_VIRTUAL_P (fndecl)
   20368    169106690 :       && !processing_template_decl)
   20369              :     {
   20370      1624879 :       tree fnclass = DECL_CONTEXT (fndecl);
   20371      1624879 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   20372              :         {
   20373        19702 :           tree classdecl = TYPE_NAME (fnclass);
   20374              :           /* Classes attached to a named module are already handled.  */
   20375        19702 :           if (!DECL_LANG_SPECIFIC (classdecl)
   20376        20014 :               || !DECL_MODULE_ATTACH_P (classdecl))
   20377        19657 :             vec_safe_push (keyed_classes, fnclass);
   20378              :         }
   20379              :     }
   20380    166168416 : }
   20381              : 
   20382              : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   20383              :    of "return *this;" immediately before its location, using FNDECL's
   20384              :    first statement (if any) to give the indentation, if appropriate.  */
   20385              : 
   20386              : static void
   20387           18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   20388              : {
   20389           18 :   location_t indent = UNKNOWN_LOCATION;
   20390           18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   20391           18 :   if (stmts)
   20392            9 :     indent = EXPR_LOCATION (stmts);
   20393           18 :   richloc->add_fixit_insert_formatted ("return *this;",
   20394              :                                        richloc->get_loc (),
   20395              :                                        indent);
   20396           18 : }
   20397              : 
   20398              : /* Finish up a function declaration and compile that function
   20399              :    all the way to assembler language output.  The free the storage
   20400              :    for the function definition. INLINE_P is TRUE if we just
   20401              :    finished processing the body of an in-class inline function
   20402              :    definition.  (This processing will have taken place after the
   20403              :    class definition is complete.)  */
   20404              : 
   20405              : tree
   20406    166164434 : finish_function (bool inline_p)
   20407              : {
   20408    166164434 :   tree fndecl = current_function_decl;
   20409    166164434 :   tree fntype, ctype = NULL_TREE;
   20410    166164434 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   20411              : 
   20412              :   /* When we get some parse errors, we can end up without a
   20413              :      current_function_decl, so cope.  */
   20414    166164434 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   20415            0 :     return error_mark_node;
   20416              : 
   20417    166164434 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20418    166163865 :     finish_lambda_scope ();
   20419              : 
   20420    166164434 :   if (c_dialect_objc ())
   20421            0 :     objc_finish_function ();
   20422              : 
   20423    166164434 :   record_key_method_defined (fndecl);
   20424              : 
   20425    166164434 :   fntype = TREE_TYPE (fndecl);
   20426              : 
   20427              :   /*  TREE_READONLY (fndecl) = 1;
   20428              :       This caused &foo to be of type ptr-to-const-function
   20429              :       which then got a warning when stored in a ptr-to-function variable.  */
   20430              : 
   20431    166164434 :   gcc_assert (building_stmt_list_p ());
   20432              :   /* The current function is being defined, so its DECL_INITIAL should
   20433              :      be set, and unless there's a multiple definition, it should be
   20434              :      error_mark_node.  */
   20435    166164434 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   20436              : 
   20437    166164434 :   cp_coroutine_transform *coroutine = nullptr;
   20438    166164434 :   if (flag_coroutines
   20439    163418786 :       && !processing_template_decl
   20440     72175343 :       && DECL_COROUTINE_P (fndecl)
   20441    166169285 :       && !DECL_RAMP_FN (fndecl))
   20442              :     {
   20443         1673 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   20444              :                            && !DECL_DEFAULTED_FN (fndecl));
   20445         1673 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   20446         1673 :       if (coroutine && coroutine->cp_valid_coroutine ())
   20447         1673 :         coroutine->apply_transforms ();
   20448              : 
   20449              :       /* We should handle coroutine IFNs in middle end lowering.  */
   20450         1673 :       cfun->coroutine_component = true;
   20451              : 
   20452              :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   20453         1673 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   20454          360 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20455              :                               (TREE_TYPE (fndecl)),
   20456          360 :                               current_eh_spec_block);
   20457              : 
   20458              :      /* If outlining succeeded, then add contracts handling if needed.  */
   20459         1673 :      if (coroutine->cp_valid_coroutine ())
   20460         1589 :         maybe_apply_function_contracts (fndecl);
   20461              :     }
   20462              :   else
   20463              :   /* For a cloned function, we've already got all the code we need;
   20464              :      there's no need to add any extra bits.  */
   20465    166162761 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   20466              :     {
   20467              :       /* Make it so that `main' always returns 0 by default.  */
   20468    148594315 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   20469    148627377 :           && !TREE_THIS_VOLATILE (current_function_decl))
   20470        33062 :         finish_return_stmt (integer_zero_node);
   20471              : 
   20472    148594315 :       if (use_eh_spec_block (current_function_decl))
   20473     25580727 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20474              :                               (TREE_TYPE (current_function_decl)),
   20475     25580727 :                               current_eh_spec_block);
   20476              : 
   20477    148594315 :       maybe_apply_function_contracts (current_function_decl);
   20478              : 
   20479              :     }
   20480              : 
   20481              :   /* If we're saving up tree structure, tie off the function now.  */
   20482    166164434 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   20483              : 
   20484    166164434 :   finish_fname_decls ();
   20485              : 
   20486              :   /* This must come after expand_function_end because cleanups might
   20487              :      have declarations (from inline functions) that need to go into
   20488              :      this function's blocks.  */
   20489              : 
   20490              :   /* If the current binding level isn't the outermost binding level
   20491              :      for this function, either there is a bug, or we have experienced
   20492              :      syntax errors and the statement tree is malformed.  */
   20493    166164434 :   if (current_binding_level->kind != sk_function_parms)
   20494              :     {
   20495              :       /* Make sure we have already experienced errors.  */
   20496           12 :       gcc_assert (errorcount);
   20497              : 
   20498              :       /* Throw away the broken statement tree and extra binding
   20499              :          levels.  */
   20500           12 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   20501              : 
   20502           27 :       while (current_binding_level->kind != sk_function_parms)
   20503              :         {
   20504           15 :           if (current_binding_level->kind == sk_class)
   20505            0 :             pop_nested_class ();
   20506              :           else
   20507           15 :             poplevel (0, 0, 0);
   20508              :         }
   20509              :     }
   20510    166164434 :   poplevel (1, 0, 1);
   20511              : 
   20512              :   /* Statements should always be full-expressions at the outermost set
   20513              :      of curly braces for a function.  */
   20514    166164434 :   gcc_assert (stmts_are_full_exprs_p ());
   20515              : 
   20516              :   /* If there are no return statements in a function with auto return type,
   20517              :      the return type is void.  But if the declared type is something like
   20518              :      auto*, this is an error.  */
   20519     73947497 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   20520    168389588 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20521              :     {
   20522       649763 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20523       649748 :           && !current_function_returns_value
   20524      1299306 :           && !current_function_returns_null)
   20525              :         {
   20526              :           /* We haven't applied return type deduction because we haven't
   20527              :              seen any return statements. Do that now.  */
   20528       649543 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20529       649543 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   20530              :                              void_node, node, tf_warning_or_error,
   20531              :                              adc_return_type);
   20532              : 
   20533       649543 :           apply_deduced_return_type (fndecl, void_type_node);
   20534       649543 :           fntype = TREE_TYPE (fndecl);
   20535              :         }
   20536          220 :       else if (!current_function_returns_value
   20537            6 :                && !current_function_returns_null)
   20538              :         {
   20539            6 :           auto_diagnostic_group d;
   20540           12 :           error ("no return statements in function returning %qT",
   20541            6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20542            6 :           inform (input_location, "only plain %<auto%> return type can be "
   20543              :                   "deduced to %<void%>");
   20544            6 :         }
   20545              :     }
   20546              : 
   20547    166164434 :   if (FNDECL_USED_AUTO (fndecl)
   20548    166164434 :       && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20549      2224934 :     if (location_t fcloc = failed_completion_location (fndecl))
   20550              :       {
   20551            6 :         auto_diagnostic_group adg;
   20552            6 :         if (warning (OPT_Wsfinae_incomplete_,
   20553              :                      "defining %qD, which previously failed to be deduced "
   20554              :                      "in a SFINAE context", fndecl)
   20555            6 :             && warn_sfinae_incomplete == 1)
   20556            6 :           inform (fcloc, "here.  Use %qs for a diagnostic at that point",
   20557              :                   "-Wsfinae-incomplete=2");
   20558            6 :       }
   20559              : 
   20560              :   /* Remember that we were in class scope.  */
   20561    166164434 :   if (current_class_name)
   20562    128338969 :     ctype = current_class_type;
   20563              : 
   20564    166164434 :   if (DECL_DELETED_FN (fndecl))
   20565              :     {
   20566           90 :       DECL_INITIAL (fndecl) = error_mark_node;
   20567           90 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   20568           90 :       goto cleanup;
   20569              :     }
   20570              : 
   20571    166164344 :   if (flag_openmp)
   20572       323312 :     if (tree attr = lookup_attribute ("omp declare variant base",
   20573       323312 :                                       DECL_ATTRIBUTES (fndecl)))
   20574          265 :       omp_declare_variant_finalize (fndecl, attr);
   20575              : 
   20576              :   /* Complain if there's just no return statement.  */
   20577    166164344 :   if ((warn_return_type
   20578        47005 :        || (cxx_dialect >= cxx14
   20579        38998 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   20580    166134595 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   20581    103675412 :       && !dependent_type_p (TREE_TYPE (fntype))
   20582     55074209 :       && !current_function_returns_value && !current_function_returns_null
   20583              :       /* Don't complain if we abort or throw.  */
   20584       187497 :       && !current_function_returns_abnormally
   20585              :       /* Don't complain if there's an infinite loop.  */
   20586          945 :       && !current_function_infinite_loop
   20587              :       /* Don't complain if we are declared noreturn.  */
   20588          877 :       && !TREE_THIS_VOLATILE (fndecl)
   20589          871 :       && !DECL_NAME (DECL_RESULT (fndecl))
   20590          871 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   20591              :       /* Structor return values (if any) are set by the compiler.  */
   20592         1254 :       && !DECL_CONSTRUCTOR_P (fndecl)
   20593          627 :       && !DECL_DESTRUCTOR_P (fndecl)
   20594    166164971 :       && targetm.warn_func_return (fndecl))
   20595              :     {
   20596          621 :       gcc_rich_location richloc (input_location);
   20597              :       /* Potentially add a "return *this;" fix-it hint for
   20598              :          assignment operators.  */
   20599          621 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   20600              :         {
   20601           39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   20602           39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   20603           32 :               && current_class_ref
   20604           26 :               && same_type_ignoring_top_level_qualifiers_p
   20605           26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   20606           71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   20607           18 :             add_return_star_this_fixit (&richloc, fndecl);
   20608              :         }
   20609          621 :       if (cxx_dialect >= cxx14
   20610          621 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   20611            2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   20612              :                             "returning non-void");
   20613          619 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   20614              :                            "no return statement in function returning "
   20615              :                            "non-void"))
   20616          169 :         suppress_warning (fndecl, OPT_Wreturn_type);
   20617          621 :     }
   20618              : 
   20619              :   /* Lambda closure members are implicitly constexpr if possible.  */
   20620    166164344 :   if (cxx_dialect >= cxx17
   20621    288869651 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   20622      2575491 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   20623      2575491 :       = ((processing_template_decl
   20624      1352539 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   20625      5150096 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   20626              : 
   20627              :   /* Invoke the pre-genericize plugin before we start munging things.  */
   20628    166164344 :   if (!processing_template_decl)
   20629     73947407 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   20630              : 
   20631              :   /* Fold away non-ODR usages of constants so that we don't need to
   20632              :      try and stream them in modules if they're internal.  */
   20633    166164344 :   if (!processing_template_decl)
   20634     73947407 :     cp_fold_function_non_odr_use (fndecl);
   20635              : 
   20636              :   /* Save constexpr function body before it gets munged by
   20637              :      the NRV transformation.   */
   20638    166164344 :   maybe_save_constexpr_fundef (fndecl);
   20639              : 
   20640              :   /* Perform delayed folding before NRV transformation.  */
   20641    166164344 :   if (!processing_template_decl
   20642    147894814 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   20643    238697630 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20644     72532847 :     cp_fold_function (fndecl);
   20645              : 
   20646              :   /* Set up the named return value optimization, if we can.  Candidate
   20647              :      variables are selected in check_return_expr.  */
   20648    166164344 :   if (tree r = current_function_return_value)
   20649              :     {
   20650     46127245 :       if (r != error_mark_node)
   20651       253667 :         finalize_nrv (fndecl, r);
   20652     46127245 :       current_function_return_value = NULL_TREE;
   20653              :     }
   20654              : 
   20655              :   /* Must mark the RESULT_DECL as being in this function.  */
   20656    166164344 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   20657              : 
   20658              :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   20659              :      to the FUNCTION_DECL node itself.  */
   20660    166164344 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   20661              : 
   20662              :   /* Store the end of the function, so that we get good line number
   20663              :      info for the epilogue.  */
   20664    166164344 :   cfun->function_end_locus = input_location;
   20665              : 
   20666              :   /* Complain about parameters that are only set, but never otherwise used.  */
   20667    166164344 :   if (warn_unused_but_set_parameter
   20668       938731 :       && !processing_template_decl
   20669       484461 :       && errorcount == unused_but_set_errorcount
   20670    166648802 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   20671              :     {
   20672       379246 :       tree decl;
   20673              : 
   20674       379246 :       for (decl = DECL_ARGUMENTS (fndecl);
   20675      1013565 :            decl;
   20676       634319 :            decl = DECL_CHAIN (decl))
   20677       634319 :         if (TREE_USED (decl)
   20678       526122 :             && TREE_CODE (decl) == PARM_DECL
   20679       526122 :             && !DECL_READ_P (decl)
   20680          225 :             && DECL_NAME (decl)
   20681          225 :             && !DECL_ARTIFICIAL (decl)
   20682          225 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
   20683          225 :             && !DECL_IN_SYSTEM_HEADER (decl)
   20684          225 :             && TREE_TYPE (decl) != error_mark_node
   20685          225 :             && !TYPE_REF_P (TREE_TYPE (decl))
   20686       634544 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   20687            0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   20688          225 :           warning_at (DECL_SOURCE_LOCATION (decl),
   20689          225 :                       OPT_Wunused_but_set_parameter_,
   20690              :                       "parameter %qD set but not used", decl);
   20691       379246 :       unused_but_set_errorcount = errorcount;
   20692              :     }
   20693              : 
   20694              :   /* Complain about locally defined typedefs that are not used in this
   20695              :      function.  */
   20696    166164344 :   maybe_warn_unused_local_typedefs ();
   20697              : 
   20698              :   /* Possibly warn about unused parameters.  */
   20699    166164344 :   if (warn_unused_parameter
   20700       669341 :       && !processing_template_decl
   20701    166491404 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   20702       251698 :     do_warn_unused_parameter (fndecl);
   20703              : 
   20704              :   /* Genericize before inlining.  */
   20705    166164344 :   if (!processing_template_decl
   20706    147894814 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   20707    238696152 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20708     72531369 :     cp_genericize (fndecl);
   20709              : 
   20710              :   /* If this function can't throw any exceptions, remember that.  */
   20711    166164344 :   if (!processing_template_decl
   20712     73947407 :       && !cp_function_chain->can_throw
   20713     54397199 :       && !flag_non_call_exceptions
   20714     54388446 :       && !decl_replaceable_p (fndecl,
   20715     54388446 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   20716    220314190 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   20717     54147360 :     TREE_NOTHROW (fndecl) = 1;
   20718              : 
   20719    166164434 :  cleanup:
   20720              : 
   20721              :   /* We're leaving the context of this function, so zap cfun.  It's still in
   20722              :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   20723    166164434 :   set_cfun (NULL);
   20724    166164434 :   current_function_decl = NULL;
   20725              : 
   20726              :   /* If this is an in-class inline definition, we may have to pop the
   20727              :      bindings for the template parameters that we added in
   20728              :      maybe_begin_member_template_processing when start_function was
   20729              :      called.  */
   20730    166164434 :   if (inline_p)
   20731     80853950 :     maybe_end_member_template_processing ();
   20732              : 
   20733              :   /* Leave the scope of the class.  */
   20734    166164434 :   if (ctype)
   20735    128338969 :     pop_nested_class ();
   20736              : 
   20737    166164434 :   --function_depth;
   20738              : 
   20739              :   /* Clean up.  */
   20740    166164434 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   20741              : 
   20742              :   /* Build outlined functions for coroutines and contracts.  */
   20743              : 
   20744    166164434 :   if (coroutine)
   20745              :     {
   20746              :       /* Emit the resumer and destroyer functions now, providing that we have
   20747              :          not encountered some fatal error.  */
   20748         1673 :       if (coroutine->cp_valid_coroutine ())
   20749              :         {
   20750         1589 :           coroutine->finish_transforms ();
   20751         1589 :           resumer = coroutine->get_resumer ();
   20752         1589 :           destroyer = coroutine->get_destroyer ();
   20753         1589 :           expand_or_defer_fn (resumer);
   20754         1589 :           expand_or_defer_fn (destroyer);
   20755              :         }
   20756         1673 :       delete coroutine;
   20757              :     }
   20758              : 
   20759              :   /* If we have used outlined contracts checking functions, build and emit
   20760              :      them here.  */
   20761    166164434 :   finish_function_outlined_contracts (fndecl);
   20762              : 
   20763    166164434 :   return fndecl;
   20764              : }
   20765              : 
   20766              : /* Create the FUNCTION_DECL for a function definition.
   20767              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   20768              :    they describe the return type and the name of the function,
   20769              :    but twisted together in a fashion that parallels the syntax of C.
   20770              : 
   20771              :    This function creates a binding context for the function body
   20772              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   20773              : 
   20774              :    Returns a FUNCTION_DECL on success.
   20775              : 
   20776              :    If the DECLARATOR is not suitable for a function (it defines a datum
   20777              :    instead), we return 0, which tells yyparse to report a parse error.
   20778              : 
   20779              :    May return void_type_node indicating that this method is actually
   20780              :    a friend.  See grokfield for more details.
   20781              : 
   20782              :    Came here with a `.pushlevel' .
   20783              : 
   20784              :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   20785              :    CHANGES TO CODE IN `grokfield'.  */
   20786              : 
   20787              : tree
   20788     81010054 : grokmethod (cp_decl_specifier_seq *declspecs,
   20789              :             const cp_declarator *declarator, tree attrlist)
   20790              : {
   20791     81010054 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   20792     81010054 :                                 &attrlist);
   20793              : 
   20794     81010054 :   if (fndecl == error_mark_node)
   20795              :     return error_mark_node;
   20796              : 
   20797     81009950 :   if (attrlist)
   20798            0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   20799              : 
   20800              :   /* Pass friends other than inline friend functions back.  */
   20801     81009950 :   if (fndecl == void_type_node)
   20802              :     return fndecl;
   20803              : 
   20804     81009950 :   if (DECL_IN_AGGR_P (fndecl))
   20805              :     {
   20806            0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   20807            0 :         error ("%qD is already defined in class %qT", fndecl,
   20808            0 :                DECL_CONTEXT (fndecl));
   20809            0 :       return error_mark_node;
   20810              :     }
   20811              : 
   20812     81009950 :   check_template_shadow (fndecl);
   20813              : 
   20814              :   /* p1779 ABI-Isolation makes inline not a default for in-class
   20815              :      definitions attached to a named module.  If the user explicitly
   20816              :      made it inline, grokdeclarator will already have done the right
   20817              :      things.  */
   20818     81009950 :   if ((!named_module_attach_p ()
   20819          815 :        || flag_module_implicit_inline
   20820              :       /* Lambda's operator function remains inline.  */
   20821         1594 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   20822              :       /* If the user explicitly asked for this to be inline, we don't
   20823              :          need to do more, but more importantly we want to warn if we
   20824              :          can't inline it.  */
   20825     81009505 :       && !DECL_DECLARED_INLINE_P (fndecl))
   20826              :     {
   20827     46760724 :       if (TREE_PUBLIC (fndecl))
   20828     44473653 :         DECL_COMDAT (fndecl) = 1;
   20829     46760724 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   20830              :       /* It's ok if we can't inline this.  */
   20831     46760724 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   20832              :     }
   20833              : 
   20834              :   /* We process method specializations in finish_struct_1.  */
   20835     81009950 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   20836              :     {
   20837              :       /* Avoid calling decl_spec_seq... until we have to.  */
   20838     64775974 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   20839     64775974 :       fndecl = push_template_decl (fndecl, friendp);
   20840     64775974 :       if (fndecl == error_mark_node)
   20841              :         return fndecl;
   20842              :     }
   20843              : 
   20844     81009942 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   20845              :     {
   20846            0 :       fndecl = copy_node (fndecl);
   20847            0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   20848              :     }
   20849              : 
   20850     81009942 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   20851              : 
   20852     81009942 :   DECL_IN_AGGR_P (fndecl) = 1;
   20853     81009942 :   return fndecl;
   20854              : }
   20855              : 
   20856              : 
   20857              : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   20858              :    we can lay it out later, when and if its type becomes complete.
   20859              : 
   20860              :    Also handle constexpr variables where the initializer involves
   20861              :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   20862              : 
   20863              : void
   20864    110108024 : maybe_register_incomplete_var (tree var)
   20865              : {
   20866    110108024 :   gcc_assert (VAR_P (var));
   20867              : 
   20868              :   /* Keep track of variables with incomplete types.  */
   20869     53861566 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   20870    163967893 :       && DECL_EXTERNAL (var))
   20871              :     {
   20872      6625753 :       tree inner_type = TREE_TYPE (var);
   20873              : 
   20874      6777240 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   20875       151487 :         inner_type = TREE_TYPE (inner_type);
   20876      6625753 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   20877              : 
   20878      6768100 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   20879              :           /* RTTI TD entries are created while defining the type_info.  */
   20880      6625753 :           || (TYPE_LANG_SPECIFIC (inner_type)
   20881      2382027 :               && TYPE_BEING_DEFINED (inner_type)))
   20882              :         {
   20883       142347 :           incomplete_var iv = {var, inner_type};
   20884       142347 :           vec_safe_push (incomplete_vars, iv);
   20885              :         }
   20886     12668480 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   20887      3525907 :                && DECL_CLASS_SCOPE_P (var)
   20888      1068093 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   20889      1068093 :                && decl_constant_var_p (var)
   20890      7167879 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   20891              :         {
   20892              :           /* When the outermost open class is complete we can resolve any
   20893              :              pointers-to-members.  */
   20894           20 :           tree context = outermost_open_class ();
   20895           20 :           incomplete_var iv = {var, context};
   20896           20 :           vec_safe_push (incomplete_vars, iv);
   20897              :         }
   20898              :     }
   20899    110108024 : }
   20900              : 
   20901              : /* Called when a class type (given by TYPE) is defined.  If there are
   20902              :    any existing VAR_DECLs whose type has been completed by this
   20903              :    declaration, update them now.  */
   20904              : 
   20905              : void
   20906     74475598 : complete_vars (tree type)
   20907              : {
   20908     74475598 :   unsigned ix;
   20909     74475598 :   incomplete_var *iv;
   20910              : 
   20911     75000038 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   20912              :     {
   20913       524440 :       if (same_type_p (type, iv->incomplete_type))
   20914              :         {
   20915       141204 :           tree var = iv->decl;
   20916       141204 :           tree type = TREE_TYPE (var);
   20917              : 
   20918       141204 :           if (type != error_mark_node
   20919       141204 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   20920       141201 :                   == iv->incomplete_type))
   20921              :             {
   20922              :               /* Complete the type of the variable.  */
   20923       141181 :               complete_type (type);
   20924       141181 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   20925       141181 :               if (COMPLETE_TYPE_P (type))
   20926       141166 :                 layout_var_decl (var);
   20927              :             }
   20928              : 
   20929              :           /* Remove this entry from the list.  */
   20930       141204 :           incomplete_vars->unordered_remove (ix);
   20931              :         }
   20932              :       else
   20933       383236 :         ix++;
   20934              :     }
   20935     74475598 : }
   20936              : 
   20937              : /* If DECL is of a type which needs a cleanup, build and return an
   20938              :    expression to perform that cleanup here.  Return NULL_TREE if no
   20939              :    cleanup need be done.  DECL can also be a _REF when called from
   20940              :    split_nonconstant_init_1.  */
   20941              : 
   20942              : tree
   20943    111943529 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   20944              : {
   20945    111943529 :   tree type;
   20946    111943529 :   tree attr;
   20947    111943529 :   tree cleanup;
   20948              : 
   20949              :   /* Assume no cleanup is required.  */
   20950    111943529 :   cleanup = NULL_TREE;
   20951              : 
   20952    111943529 :   if (!decl || error_operand_p (decl))
   20953              :     return cleanup;
   20954              : 
   20955              :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   20956              :      before the destructor since the destructor is what actually
   20957              :      terminates the lifetime of the object.  */
   20958    111943529 :   if (DECL_P (decl))
   20959    110946113 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   20960              :   else
   20961              :     attr = NULL_TREE;
   20962    110946113 :   if (attr)
   20963              :     {
   20964          159 :       tree id;
   20965          159 :       tree fn;
   20966          159 :       tree arg;
   20967              : 
   20968              :       /* Get the name specified by the user for the cleanup function.  */
   20969          159 :       id = TREE_VALUE (TREE_VALUE (attr));
   20970              :       /* Look up the name to find the cleanup function to call.  It is
   20971              :          important to use lookup_name here because that is what is
   20972              :          used in c-common.cc:handle_cleanup_attribute when performing
   20973              :          initial checks on the attribute.  Note that those checks
   20974              :          include ensuring that the function found is not an overloaded
   20975              :          function, or an object with an overloaded call operator,
   20976              :          etc.; we can rely on the fact that the function found is an
   20977              :          ordinary FUNCTION_DECL.  */
   20978          159 :       fn = lookup_name (id);
   20979          159 :       arg = build_address (decl);
   20980          159 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   20981            0 :         return error_mark_node;
   20982          159 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   20983          159 :       if (cleanup == error_mark_node)
   20984              :         return error_mark_node;
   20985              :     }
   20986              :   /* Handle ordinary C++ destructors.  */
   20987    111943517 :   type = TREE_TYPE (decl);
   20988    111943517 :   if (type_build_dtor_call (type))
   20989              :     {
   20990      7663442 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   20991      7663442 :       tree addr;
   20992      7663442 :       tree call;
   20993              : 
   20994      7663442 :       if (TREE_CODE (type) == ARRAY_TYPE)
   20995              :         addr = decl;
   20996              :       else
   20997      7660182 :         addr = build_address (decl);
   20998              : 
   20999      7663442 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   21000              :                            sfk_complete_destructor, flags, 0, complain);
   21001      7663442 :       if (call == error_mark_node)
   21002              :         cleanup = error_mark_node;
   21003      7663397 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   21004              :         /* Discard the call.  */;
   21005      4970390 :       else if (decl_maybe_constant_destruction (decl, type)
   21006      4970533 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   21007          143 :         cxx_constant_dtor (call, decl);
   21008      4970247 :       else if (cleanup)
   21009            3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   21010              :       else
   21011              :         cleanup = call;
   21012              :     }
   21013              : 
   21014              :   /* build_delete sets the location of the destructor call to the
   21015              :      current location, even though the destructor is going to be
   21016              :      called later, at the end of the current scope.  This can lead to
   21017              :      a "jumpy" behavior for users of debuggers when they step around
   21018              :      the end of the block.  So let's unset the location of the
   21019              :      destructor call instead.  */
   21020    111943517 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   21021    111943517 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   21022            0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   21023              : 
   21024            0 :   if (cleanup
   21025      4970436 :       && DECL_P (decl)
   21026      4969998 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   21027              :       /* Treat objects with destructors as used; the destructor may do
   21028              :          something substantive.  */
   21029      4969992 :       && !mark_used (decl, complain) && !(complain & tf_error))
   21030            0 :     return error_mark_node;
   21031              : 
   21032      4970436 :   if (cleanup && cfun && !processing_template_decl
   21033    116437958 :       && !expr_noexcept_p (cleanup, tf_none))
   21034         5291 :     cp_function_chain->throwing_cleanup = true;
   21035              : 
   21036              :   return cleanup;
   21037              : }
   21038              : 
   21039              : 
   21040              : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   21041              :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   21042              :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   21043              : 
   21044              : tree
   21045      5975797 : static_fn_type (tree memfntype)
   21046              : {
   21047      5975797 :   tree fntype;
   21048      5975797 :   tree args;
   21049              : 
   21050      5975797 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   21051        19983 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   21052      5975797 :   if (INDIRECT_TYPE_P (memfntype)
   21053      5280156 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   21054      5810699 :     memfntype = TREE_TYPE (memfntype);
   21055      5975797 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   21056              :     return memfntype;
   21057       889849 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   21058       889849 :   args = TYPE_ARG_TYPES (memfntype);
   21059       889849 :   fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   21060       889849 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   21061       889849 :   fntype = (cp_build_type_attribute_variant
   21062       889849 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   21063       889849 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   21064       889849 :   return fntype;
   21065              : }
   21066              : 
   21067              : /* DECL was originally constructed as a non-static member function,
   21068              :    but turned out to be static.  Update it accordingly.  */
   21069              : 
   21070              : void
   21071       169905 : revert_static_member_fn (tree decl)
   21072              : {
   21073       169905 :   tree stype = static_fn_type (decl);
   21074       169905 :   cp_cv_quals quals = type_memfn_quals (stype);
   21075       169905 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   21076              : 
   21077       169905 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   21078            9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   21079              : 
   21080       169905 :   TREE_TYPE (decl) = stype;
   21081              : 
   21082       169905 :   if (DECL_ARGUMENTS (decl))
   21083       169905 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   21084       169905 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   21085       169905 : }
   21086              : 
   21087              : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   21088              :    one of the language-independent trees.  */
   21089              : 
   21090              : enum cp_tree_node_structure_enum
   21091  38853846024 : cp_tree_node_structure (union lang_tree_node * t)
   21092              : {
   21093  38853846024 :   switch (TREE_CODE (&t->generic))
   21094              :     {
   21095              :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   21096    161160843 :     case BASELINK:              return TS_CP_BASELINK;
   21097     79667714 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   21098     12319624 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   21099      5879572 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   21100   2012306366 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   21101      3277894 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   21102       229832 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   21103    728419263 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   21104         1106 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   21105     15665194 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   21106    681142091 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   21107   1610487036 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   21108    686161144 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   21109     14827078 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   21110            6 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   21111      3508861 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   21112  32838792400 :     default:                    return TS_CP_GENERIC;
   21113              :     }
   21114              : }
   21115              : 
   21116              : bool
   21117         9063 : cp_missing_noreturn_ok_p (tree decl)
   21118              : {
   21119              :   /* A missing noreturn is ok for the `main' function.  */
   21120         9063 :   return DECL_MAIN_P (decl);
   21121              : }
   21122              : 
   21123              : /* Return the decl used to identify the COMDAT group into which DECL should
   21124              :    be placed.  */
   21125              : 
   21126              : tree
   21127    144728895 : cxx_comdat_group (tree decl)
   21128              : {
   21129              :   /* Virtual tables, construction virtual tables, and virtual table
   21130              :      tables all go in a single COMDAT group, named after the primary
   21131              :      virtual table.  */
   21132    144728895 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   21133       611839 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   21134              :   /* For all other DECLs, the COMDAT group is the mangled name of the
   21135              :      declaration itself.  */
   21136              :   else
   21137              :     {
   21138    144117056 :       while (DECL_THUNK_P (decl))
   21139              :         {
   21140              :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   21141              :              into the same section as the target function.  In that case
   21142              :              we must return target's name.  */
   21143            0 :           tree target = THUNK_TARGET (decl);
   21144            0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   21145            0 :               && DECL_SECTION_NAME (target) != NULL
   21146            0 :               && DECL_ONE_ONLY (target))
   21147              :             decl = target;
   21148              :           else
   21149              :             break;
   21150              :         }
   21151              :       /* If a ctor/dtor has already set the comdat group by
   21152              :          maybe_clone_body, don't override it.  */
   21153    144117056 :       if (SUPPORTS_ONE_ONLY
   21154    144117056 :           && TREE_CODE (decl) == FUNCTION_DECL
   21155    144117056 :           && DECL_CLONED_FUNCTION_P (decl))
   21156     20053646 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   21157              :           return comdat;
   21158              :     }
   21159              : 
   21160              :   return decl;
   21161              : }
   21162              : 
   21163              : /* Returns the return type for FN as written by the user, which may include
   21164              :    a placeholder for a deduced return type.  */
   21165              : 
   21166              : tree
   21167    463562576 : fndecl_declared_return_type (tree fn)
   21168              : {
   21169    463562576 :   fn = STRIP_TEMPLATE (fn);
   21170    463562576 :   if (FNDECL_USED_AUTO (fn))
   21171         4383 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   21172              : 
   21173    463558193 :   return TREE_TYPE (TREE_TYPE (fn));
   21174              : }
   21175              : 
   21176              : /* Returns true iff DECL is a variable or function declared with an auto type
   21177              :    that has not yet been deduced to a real type.  */
   21178              : 
   21179              : bool
   21180   1222583284 : undeduced_auto_decl (tree decl)
   21181              : {
   21182   1222583284 :   if (cxx_dialect < cxx11)
   21183              :     return false;
   21184   1220090051 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   21185    601583183 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   21186    108343848 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   21187   1713468418 :           && type_uses_auto (TREE_TYPE (decl)));
   21188              : }
   21189              : 
   21190              : /* Complain if DECL has an undeduced return type.  */
   21191              : 
   21192              : bool
   21193    434536578 : require_deduced_type (tree decl, tsubst_flags_t complain)
   21194              : {
   21195    434536578 :   if (undeduced_auto_decl (decl))
   21196              :     {
   21197         9991 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21198         9964 :           && fndecl_built_in_p (decl, BUILT_IN_FRONTEND)
   21199        19354 :           && DECL_FE_FUNCTION_CODE (decl) == CP_BUILT_IN_SOURCE_LOCATION)
   21200              :         {
   21201              :           /* Set the return type of __builtin_source_location.  */
   21202         9363 :           tree type = get_source_location_impl_type ();
   21203         9363 :           if (type == error_mark_node)
   21204              :             {
   21205           33 :               inform (input_location, "using %qs", "__builtin_source_location");
   21206           33 :               return false;
   21207              :             }
   21208         9330 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   21209         9330 :           type = build_pointer_type (type);
   21210         9330 :           apply_deduced_return_type (decl, type);
   21211         9330 :           return true;
   21212              :         }
   21213              : 
   21214          628 :       if (warning_suppressed_p (decl) && seen_error ())
   21215              :         /* We probably already complained about deduction failure.  */;
   21216          475 :       else if (complain & tf_error)
   21217           70 :         error ("use of %qD before deduction of %<auto%>", decl);
   21218          628 :       note_failed_type_completion (decl, complain);
   21219          628 :       return false;
   21220              :     }
   21221              :   return true;
   21222              : }
   21223              : 
   21224              : /* Create a representation of the explicit-specifier with
   21225              :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   21226              : 
   21227              : tree
   21228      8090409 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   21229              : {
   21230      8090409 :   if (check_for_bare_parameter_packs (expr))
   21231            3 :     return error_mark_node;
   21232              : 
   21233      8090406 :   if (instantiation_dependent_expression_p (expr))
   21234              :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   21235              :     return expr;
   21236              : 
   21237      6564559 :   expr = build_converted_constant_bool_expr (expr, complain);
   21238      6564559 :   expr = instantiate_non_dependent_expr (expr, complain);
   21239      6564559 :   expr = cxx_constant_value (expr, complain);
   21240      6564559 :   return expr;
   21241              : }
   21242              : 
   21243              : #include "gt-cp-decl.h"
        

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