LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.7 % 9699 9184
Test Date: 2026-06-20 15:32:29 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    246815390 : current_tmpl_spec_kind (int n_class_scopes)
     312              : {
     313    246815390 :   int n_template_parm_scopes = 0;
     314    246815390 :   int seen_specialization_p = 0;
     315    246815390 :   int innermost_specialization_p = 0;
     316    246815390 :   cp_binding_level *b;
     317              : 
     318              :   /* Scan through the template parameter scopes.  */
     319    246815390 :   for (b = current_binding_level;
     320    307689384 :        b->kind == sk_template_parms;
     321     60873994 :        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     60873994 :       if (b->explicit_spec_p)
     333              :         {
     334      1424129 :           if (n_template_parm_scopes == 0)
     335              :             innermost_specialization_p = 1;
     336              :           else
     337         1143 :             seen_specialization_p = 1;
     338              :         }
     339     59449865 :       else if (seen_specialization_p == 1)
     340              :         return tsk_invalid_member_spec;
     341              : 
     342     60873994 :       ++n_template_parm_scopes;
     343              :     }
     344              : 
     345              :   /* Handle explicit instantiations.  */
     346    246815390 :   if (processing_explicit_instantiation)
     347              :     {
     348      1928276 :       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      1928276 :         return tsk_expl_inst;
     358              :     }
     359              : 
     360    244887114 :   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    244887114 :   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     52916928 :   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    104875609 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     394              : }
     395              : 
     396              : /* Exit the current scope.  */
     397              : 
     398              : void
     399     96621660 : finish_scope (void)
     400              : {
     401     96621660 :   poplevel (0, 0, 0);
     402     96621660 : }
     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        20796 : check_label_used (tree label)
     409              : {
     410        20796 :   if (!processing_template_decl)
     411              :     {
     412        20487 :       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        20478 :         warn_for_unused_label (label);
     424              :     }
     425        20796 : }
     426              : 
     427              : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     428              : 
     429              : static int
     430       234110 : sort_labels (const void *a, const void *b)
     431              : {
     432       234110 :   tree label1 = *(tree const *) a;
     433       234110 :   tree label2 = *(tree const *) b;
     434              : 
     435              :   /* DECL_UIDs can never be equal.  */
     436       234110 :   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    159124616 : pop_labels (tree block)
     508              : {
     509    159124616 :   if (!named_labels)
     510    159119949 :     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         4667 :   auto_vec<tree, 32> labels (named_labels->elements ());
     518         4667 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     519              : 
     520         4667 :   if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
     521          709 :       && !processing_template_decl)
     522              :     {
     523         6382 :       for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     524              :         {
     525         2516 :           named_label_entry *ent = *iter;
     526         2516 :           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        46193 :   for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
     537              :     {
     538        20763 :       named_label_entry *ent = *iter;
     539              : 
     540        20763 :       gcc_checking_assert (!ent->outer);
     541        20763 :       if (ent->label_decl)
     542        20577 :         labels.quick_push (ent->label_decl);
     543        20763 :       ggc_free (ent);
     544              :     }
     545         4667 :   named_labels = NULL;
     546         4667 :   labels.qsort (sort_labels);
     547              : 
     548        25244 :   while (labels.length ())
     549              :     {
     550        20577 :       tree label = labels.pop ();
     551              : 
     552        20577 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     553        20577 :       BLOCK_VARS (block) = label;
     554              : 
     555        20577 :       check_label_used (label);
     556              :     }
     557         4667 : }
     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      1566701 : level_for_constexpr_if (cp_binding_level *b)
     618              : {
     619      1562627 :   return (b->kind == sk_cond && b->this_entity
     620          296 :           && TREE_CODE (b->this_entity) == IF_STMT
     621      1566997 :           && 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      1566677 : level_for_consteval_if (cp_binding_level *b)
     628              : {
     629      1562603 :   return (b->kind == sk_cond && b->this_entity
     630          272 :           && TREE_CODE (b->this_entity) == IF_STMT
     631      1566949 :           && 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       155886 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     652              : {
     653       155886 :   named_label_entry *ent = *slot;
     654       155886 :   cp_binding_level *obl = bl->level_chain;
     655              : 
     656       155886 :   if (ent->binding_level == bl)
     657              :     {
     658        10235 :       tree decl;
     659              : 
     660              :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     661              :          TREE_LISTs representing OVERLOADs, so be careful.  */
     662        15147 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     663         4985 :                                                      ? DECL_CHAIN (decl)
     664           73 :                                                      : TREE_CHAIN (decl)))
     665         4912 :         if (decl_jump_unsafe (decl))
     666              :           {
     667         1879 :             vec_safe_push (ent->bad_decls, decl);
     668         1879 :             ent->has_bad_decls = true;
     669              :           }
     670         3033 :         else if (decl_instrument_init_bypass_p (decl))
     671          440 :           vec_safe_push (ent->bad_decls, decl);
     672              : 
     673        10235 :       ent->binding_level = obl;
     674        10235 :       ent->names_in_scope = obl->names;
     675        10235 :       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         4119 :         case sk_block:
     693         4119 :           if (level_for_constexpr_if (obl))
     694           15 :             ent->in_constexpr_if = true;
     695         4104 :           else if (level_for_consteval_if (obl))
     696           30 :             ent->in_consteval_if = true;
     697              :           break;
     698              :         default:
     699              :           break;
     700              :         }
     701              :     }
     702       145651 :   else if (ent->uses)
     703              :     {
     704              :       struct named_label_use_entry *use;
     705              : 
     706        22857 :       for (use = ent->uses; use ; use = use->next)
     707        15533 :         if (use->binding_level == bl)
     708              :           {
     709         5985 :             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         5985 :             use->binding_level = obl;
     719         5985 :             use->names_in_scope = obl->names;
     720         5985 :             if (bl->kind == sk_omp)
     721           12 :               use->in_omp_scope = true;
     722              :           }
     723              :     }
     724              : 
     725       155886 :   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    667696189 : poplevel (int keep, int reverse, int functionbody)
     749              : {
     750    667696189 :   tree link;
     751              :   /* The chain of decls was accumulated in reverse order.
     752              :      Put it into forward order, just for cleanliness.  */
     753    667696189 :   tree decls;
     754    667696189 :   tree subblocks;
     755    667696189 :   tree block;
     756    667696189 :   tree decl;
     757    667696189 :   scope_kind kind;
     758              : 
     759    667696189 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     760    667696495 :  restart:
     761              : 
     762    667696495 :   block = NULL_TREE;
     763              : 
     764    667696495 :   gcc_assert (current_binding_level->kind != sk_class
     765              :               && current_binding_level->kind != sk_namespace);
     766              : 
     767    667696495 :   if (current_binding_level->kind == sk_cleanup)
     768              :     functionbody = 0;
     769    667696495 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     770              : 
     771    667696495 :   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    667696495 :   gcc_assert (keep == 0 || keep == 1);
     777              : 
     778    667696495 :   if (current_binding_level->keep)
     779      8199777 :     keep = 1;
     780              : 
     781              :   /* Any uses of undefined labels, and any defined labels, now operate
     782              :      under constraints of next binding contour.  */
     783    667696495 :   if (cfun && !functionbody && named_labels)
     784        43672 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     785       199558 :                    (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    667696495 :   decls = current_binding_level->names;
     792    667696495 :   if (reverse)
     793              :     {
     794    366021633 :       decls = nreverse (decls);
     795    366021633 :       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    667696495 :   block = NULL_TREE;
     802              :   /* Avoid function body block if possible.  */
     803    708370861 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     804              :     keep = 0;
     805    627022390 :   else if (keep == 1 || functionbody)
     806    200532697 :     block = make_node (BLOCK);
     807    200532697 :   if (block != NULL_TREE)
     808              :     {
     809    200532697 :       BLOCK_VARS (block) = decls;
     810    200532697 :       BLOCK_SUBBLOCKS (block) = subblocks;
     811              :     }
     812              : 
     813              :   /* In each subblock, record that this is its superior.  */
     814    667696495 :   if (keep >= 0)
     815    749777956 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     816     82081461 :       BLOCK_SUPERCONTEXT (link) = block;
     817              : 
     818              :   /* Before we remove the declarations first check for unused variables.  */
     819    667696495 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     820      6723667 :       && current_binding_level->kind != sk_template_parms
     821      5665681 :       && !processing_template_decl)
     822      6481996 :     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      3284687 :         tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     828      3284687 :         decl = strip_using_decl (udecl);
     829              : 
     830      3284687 :         tree type = TREE_TYPE (decl);
     831      3284687 :         if (VAR_P (decl)
     832       386358 :             && (!TREE_USED (decl) || !DECL_READ_P (decl))
     833         3452 :             && !DECL_IN_SYSTEM_HEADER (udecl)
     834              :             /* For structured bindings, consider only real variables, not
     835              :                subobjects.  */
     836         3440 :             && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
     837         3217 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     838              :             /* Don't warn about name-independent declarations.  */
     839          896 :             && !name_independent_decl_p (decl)
     840          740 :             && type != error_mark_node
     841      3288833 :             && (!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          706 :             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          398 :             else if (DECL_CONTEXT (decl) == current_function_decl
     862              :                      // For -Wunused-but-set-variable leave references alone.
     863          374 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     864          772 :                      && errorcount == unused_but_set_errorcount)
     865              :               {
     866          365 :                 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          353 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     872          353 :                               OPT_Wunused_but_set_variable_,
     873              :                               "variable %qD set but not used", decl);
     874          365 :                 unused_but_set_errorcount = errorcount;
     875              :               }
     876              :           }
     877              :       }
     878              : 
     879              :   /* Remove declarations for all the DECLs in this level.  */
     880   1350871044 :   for (link = decls; link; link = TREE_CHAIN (link))
     881              :     {
     882    683174549 :       tree name;
     883    683174549 :       if (TREE_CODE (link) == TREE_LIST)
     884              :         {
     885     12996982 :           decl = TREE_VALUE (link);
     886     12996982 :           name = TREE_PURPOSE (link);
     887     12996982 :           gcc_checking_assert (name);
     888              :         }
     889              :       else
     890              :         {
     891    670177567 :           decl = link;
     892    670177567 :           name = DECL_NAME (decl);
     893              :         }
     894              : 
     895              :       /* Remove the binding.  */
     896    683174549 :       if (TREE_CODE (decl) == LABEL_DECL)
     897          219 :         pop_local_label (name, decl);
     898              :       else
     899    683174330 :         pop_local_binding (name, decl);
     900              :     }
     901              : 
     902              :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     903    667696495 :   for (link = current_binding_level->type_shadowed;
     904    910892552 :        link; link = TREE_CHAIN (link))
     905    243196057 :     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    667696495 :   if (block)
     915              :     {
     916    200532697 :       tree* d;
     917              : 
     918    528217480 :       for (d = &BLOCK_VARS (block); *d; )
     919              :         {
     920    327684783 :           if (TREE_CODE (*d) == TREE_LIST
     921    327684783 :               || (!processing_template_decl
     922    103540472 :                   && undeduced_auto_decl (*d)))
     923     12997034 :             *d = TREE_CHAIN (*d);
     924              :           else
     925    314687749 :             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    667696495 :   if (functionbody)
     932              :     {
     933    159124616 :       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    118450511 :           BLOCK_VARS (block) = 0;
     939    118450511 :           pop_labels (block);
     940              :         }
     941              :       else
     942     40674105 :         pop_labels (subblocks);
     943              :     }
     944              : 
     945    667696495 :   kind = current_binding_level->kind;
     946    667696495 :   if (kind == sk_cleanup)
     947              :     {
     948          306 :       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          306 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     954          306 :       stmt = c_build_bind_expr (input_location, block, stmt);
     955          306 :       add_stmt (stmt);
     956              :     }
     957              : 
     958    667696495 :   leave_scope ();
     959    667696495 :   if (functionbody)
     960              :     {
     961              :       /* The current function is being defined, so its DECL_INITIAL
     962              :          should be error_mark_node.  */
     963    159124616 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     964    199798721 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     965    159124616 :       if (subblocks)
     966              :         {
     967     77262988 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
     968     50390663 :               && BLOCK_SUBBLOCKS (subblocks))
     969      1280326 :             BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     970              :           else
     971     39394040 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     972              :         }
     973              :     }
     974    508571879 :   else if (block)
     975     82082186 :     current_binding_level->blocks
     976    164164372 :       = 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    426489693 :   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    667696495 :   if (block)
     991    200532697 :     TREE_USED (block) = 1;
     992              : 
     993              :   /* All temporary bindings created for cleanups are popped silently.  */
     994    667696495 :   if (kind == sk_cleanup)
     995          306 :     goto restart;
     996              : 
     997   1335392378 :   return block;
     998    667696189 : }
     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       143706 : wrapup_namespace_globals ()
    1006              : {
    1007       143706 :   if (vec<tree, va_gc> *statics = static_decls)
    1008              :     {
    1009     17434386 :       for (tree decl : *statics)
    1010              :         {
    1011     17316552 :           if (warn_unused_function
    1012       998152 :               && TREE_CODE (decl) == FUNCTION_DECL
    1013       748928 :               && DECL_INITIAL (decl) == 0
    1014         7580 :               && DECL_EXTERNAL (decl)
    1015         7568 :               && !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     18314704 :               && 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     17316552 :           if (VAR_P (decl)
    1025      5761711 :               && DECL_EXTERNAL (decl)
    1026              :               /* We mark consteval-only variables DECL_EXTERNAL, but
    1027              :                   extern constexpr inline std::meta::info i{};
    1028              :                  is a definition (the extern is redundant).  */
    1029      1984553 :               && !DECL_INITIAL (decl)
    1030      1983184 :               && DECL_INLINE_VAR_P (decl)
    1031     17316581 :               && DECL_ODR_USED (decl))
    1032            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    1033              :                       "odr-used inline variable %qD is not defined", decl);
    1034              :         }
    1035              : 
    1036              :       /* Clear out the list, so we don't rescan next time.  */
    1037       117834 :       static_decls = NULL;
    1038              : 
    1039              :       /* Write out any globals that need to be output.  */
    1040       117834 :       return wrapup_global_declarations (statics->address (),
    1041       117834 :                                          statics->length ());
    1042              :     }
    1043              :   return 0;
    1044              : }
    1045              : 
    1046              : /* In C++, you don't have to write `struct S' to refer to `S'; you
    1047              :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
    1048              :    if the user had written `typedef struct S S'.  Create and return
    1049              :    the TYPE_DECL for TYPE.  */
    1050              : 
    1051              : tree
    1052    179274937 : create_implicit_typedef (tree name, tree type)
    1053              : {
    1054    179274937 :   tree decl;
    1055              : 
    1056    179274937 :   decl = build_decl (input_location, TYPE_DECL, name, type);
    1057    179274937 :   DECL_ARTIFICIAL (decl) = 1;
    1058              :   /* There are other implicit type declarations, like the one *within*
    1059              :      a class that allows you to write `S::S'.  We must distinguish
    1060              :      amongst these.  */
    1061    179274937 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
    1062    179274937 :   TYPE_NAME (type) = decl;
    1063    179274937 :   TYPE_STUB_DECL (type) = decl;
    1064              : 
    1065    179274937 :   return decl;
    1066              : }
    1067              : 
    1068              : /* Function-scope local entities that need discriminators.  Each entry
    1069              :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
    1070              :    smashed, so we cannot rely on DECL_NAME.  */
    1071              : 
    1072              : static GTY((deletable)) vec<tree, va_gc> *local_entities;
    1073              : 
    1074              : /* Determine the mangling discriminator of local DECL.  There are
    1075              :    generally very few of these in any particular function.  */
    1076              : 
    1077              : void
    1078       725494 : determine_local_discriminator (tree decl, tree name)
    1079              : {
    1080       725494 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    1081       725494 :   retrofit_lang_decl (decl);
    1082       725494 :   tree ctx = DECL_CONTEXT (decl);
    1083       725494 :   size_t nelts = vec_safe_length (local_entities);
    1084       725494 :   if (name == NULL_TREE)
    1085       725229 :     name = (TREE_CODE (decl) == TYPE_DECL
    1086      1181860 :             && TYPE_UNNAMED_P (TREE_TYPE (decl))
    1087      1312109 :             ? NULL_TREE : DECL_NAME (decl));
    1088     21208343 :   for (size_t i = 0; i < nelts; i += 2)
    1089              :     {
    1090     20483515 :       tree *pair = &(*local_entities)[i];
    1091     20483515 :       tree d = pair[0];
    1092     20483515 :       tree n = pair[1];
    1093     20483515 :       gcc_checking_assert (d != decl);
    1094     20483515 :       if (name == n
    1095      3623809 :           && TREE_CODE (decl) == TREE_CODE (d)
    1096     24107315 :           && ctx == DECL_CONTEXT (d))
    1097              :         {
    1098          666 :           tree disc = integer_one_node;
    1099          666 :           if (DECL_DISCRIMINATOR (d))
    1100          366 :             disc = build_int_cst (TREE_TYPE (disc),
    1101          366 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
    1102          666 :           DECL_DISCRIMINATOR (decl) = disc;
    1103              :           /* Replace the saved decl.  */
    1104          666 :           pair[0] = decl;
    1105          666 :           decl = NULL_TREE;
    1106          666 :           break;
    1107              :         }
    1108              :     }
    1109              : 
    1110       725494 :   if (decl)
    1111              :     {
    1112       724828 :       vec_safe_reserve (local_entities, 2);
    1113       724828 :       local_entities->quick_push (decl);
    1114       724828 :       local_entities->quick_push (name);
    1115              :     }
    1116       725494 : }
    1117              : 
    1118              : 
    1119              : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
    1120              : 
    1121              :    A non-template friend declaration with a requires-clause shall be a
    1122              :    definition. A friend function template with a constraint that depends on a
    1123              :    template parameter from an enclosing template shall be a definition. Such a
    1124              :    constrained friend function or function template declaration does not
    1125              :    declare the same function or function template as a declaration in any other
    1126              :    scope.
    1127              : 
    1128              :    The ABI calls this a "member-like constrained friend" and mangles it like a
    1129              :    member function to avoid collisions.  */
    1130              : 
    1131              : bool
    1132   2409359978 : member_like_constrained_friend_p (tree decl)
    1133              : {
    1134   2409359978 :   return (TREE_CODE (decl) == FUNCTION_DECL
    1135    796094778 :           && DECL_UNIQUE_FRIEND_P (decl)
    1136    190584196 :           && DECL_FRIEND_CONTEXT (decl)
    1137     78286669 :           && get_constraints (decl)
    1138      5950878 :           && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
    1139   2412328136 :           && (!DECL_TEMPLATE_INFO (decl)
    1140      2968158 :               || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
    1141         6373 :               || (uses_outer_template_parms_in_constraints
    1142         6373 :                   (most_general_template (decl)))));
    1143              : }
    1144              : 
    1145              : /* Returns true if functions FN1 and FN2 have equivalent trailing
    1146              :    requires clauses.  */
    1147              : 
    1148              : static bool
    1149     66530289 : function_requirements_equivalent_p (tree newfn, tree oldfn)
    1150              : {
    1151              :   /* [temp.friend]/9 "Such a constrained friend function does not declare the
    1152              :      same function as a declaration in any other scope."  So no need to
    1153              :      actually compare the requirements.  */
    1154     66530289 :   if (member_like_constrained_friend_p (newfn)
    1155     66530289 :       || member_like_constrained_friend_p (oldfn))
    1156           97 :     return false;
    1157              : 
    1158              :   /* Compare only trailing requirements.  */
    1159     66530192 :   tree reqs1 = get_trailing_function_requirements (newfn);
    1160     66530192 :   tree reqs2 = get_trailing_function_requirements (oldfn);
    1161     66530192 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
    1162              :     return false;
    1163              : 
    1164              :   /* Substitution is needed when friends are involved.  */
    1165     66403395 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
    1166     66403395 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
    1167              : 
    1168     66403395 :   return cp_tree_equal (reqs1, reqs2);
    1169              : }
    1170              : 
    1171              : /* Two functions of the same name correspond [basic.scope.scope] if
    1172              : 
    1173              :    + both declare functions with the same non-object-parameter-type-list,
    1174              :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
    1175              :    specified in [temp.friend]), and, if both are non-static members, they have
    1176              :    corresponding object parameters, or
    1177              : 
    1178              :    + both declare function templates with equivalent
    1179              :    non-object-parameter-type-lists, return types (if any), template-heads, and
    1180              :    trailing requires-clauses (if any), and, if both are non-static members,
    1181              :    they have corresponding object parameters.
    1182              : 
    1183              :    This is a subset of decls_match: it identifies declarations that cannot be
    1184              :    overloaded with one another.  This function does not consider DECL_NAME.  */
    1185              : 
    1186              : bool
    1187   1410074972 : fns_correspond (tree newdecl, tree olddecl)
    1188              : {
    1189   1410074972 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1190              :     return false;
    1191              : 
    1192   1310639249 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1193              :     {
    1194   1309283198 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1195              :         return 0;
    1196    311487229 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1197    311487229 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1198              :     }
    1199              : 
    1200    312843280 :   tree f1 = TREE_TYPE (newdecl);
    1201    312843280 :   tree f2 = TREE_TYPE (olddecl);
    1202              : 
    1203    312843280 :   int rq1 = type_memfn_rqual (f1);
    1204    312843280 :   int rq2 = type_memfn_rqual (f2);
    1205              : 
    1206              :   /* If only one is a non-static member function, ignore ref-quals.  */
    1207    312843280 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1208              :     rq1 = rq2;
    1209              :   /* Two non-static member functions have corresponding object parameters if:
    1210              :      + exactly one is an implicit object member function with no ref-qualifier
    1211              :      and the types of their object parameters ([dcl.fct]), after removing
    1212              :      top-level references, are the same, or
    1213              :      + their object parameters have the same type.  */
    1214              :   /* ??? We treat member functions of different classes as corresponding even
    1215              :      though that means the object parameters have different types.  */
    1216    312843280 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1217            0 :     rq1 = rq2;
    1218              : 
    1219    312843280 :   bool types_match = rq1 == rq2;
    1220              : 
    1221    312843280 :   if (types_match)
    1222              :     {
    1223    312843280 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1224    312843280 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1225    312843280 :       types_match = compparms (p1, p2);
    1226              :     }
    1227              : 
    1228              :   /* Two function declarations match if either has a requires-clause
    1229              :      then both have a requires-clause and their constraints-expressions
    1230              :      are equivalent.  */
    1231    312843280 :   if (types_match && flag_concepts)
    1232     38595661 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1233              : 
    1234              :   return types_match;
    1235              : }
    1236              : 
    1237              : /* Subroutine of duplicate_decls: return truthvalue of whether
    1238              :    or not types of these decls match.
    1239              : 
    1240              :    For C++, we must compare the parameter list so that `int' can match
    1241              :    `int&' in a parameter position, but `int&' is not confused with
    1242              :    `const int&'.  */
    1243              : 
    1244              : int
    1245    804584773 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1246              : {
    1247    804584773 :   int types_match;
    1248              : 
    1249    804584773 :   if (newdecl == olddecl)
    1250              :     return 1;
    1251              : 
    1252    804471263 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1253              :     /* If the two DECLs are not even the same kind of thing, we're not
    1254              :        interested in their types.  */
    1255              :     return 0;
    1256              : 
    1257    412755775 :   gcc_assert (DECL_P (newdecl));
    1258              : 
    1259    412755775 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1260              :     {
    1261              :       /* Specializations of different templates are different functions
    1262              :          even if they have the same type.  */
    1263    263948491 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1264    263948491 :                  ? DECL_TI_TEMPLATE (newdecl)
    1265       628935 :                  : NULL_TREE);
    1266    263948491 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1267    263948491 :                  ? DECL_TI_TEMPLATE (olddecl)
    1268      3993358 :                  : NULL_TREE);
    1269    263948491 :       if (t1 != t2)
    1270              :         return 0;
    1271              : 
    1272    260583985 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1273    263480976 :           && ! (DECL_EXTERN_C_P (newdecl)
    1274      2896991 :                 && DECL_EXTERN_C_P (olddecl)))
    1275              :         return 0;
    1276              : 
    1277              :       /* A new declaration doesn't match a built-in one unless it
    1278              :          is also extern "C".  */
    1279    239672513 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1280    239672513 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1281              :         return 0;
    1282              : 
    1283    239033443 :       tree f1 = TREE_TYPE (newdecl);
    1284    239033443 :       tree f2 = TREE_TYPE (olddecl);
    1285    239033443 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1286              :         return 0;
    1287              : 
    1288              :       /* A declaration with deduced return type should use its pre-deduction
    1289              :          type for declaration matching.  */
    1290    238861709 :       tree r2 = fndecl_declared_return_type (olddecl);
    1291    238861709 :       tree r1 = fndecl_declared_return_type (newdecl);
    1292              : 
    1293              :       /* For memchr et al, allow const void* return type (as specified by C++)
    1294              :          when we expect void* (as in C).  */
    1295    238861709 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1296      6429264 :           && DECL_EXTERN_C_P (olddecl)
    1297      3949779 :           && !same_type_p (r1, r2)
    1298           70 :           && TREE_CODE (r1) == POINTER_TYPE
    1299           15 :           && TREE_CODE (r2) == POINTER_TYPE
    1300    238861721 :           && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
    1301              :         r2 = r1;
    1302              : 
    1303    238861709 :       tree p1 = TYPE_ARG_TYPES (f1);
    1304    238861709 :       tree p2 = TYPE_ARG_TYPES (f2);
    1305              : 
    1306    238861709 :       if (same_type_p (r1, r2))
    1307              :         {
    1308    164648218 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1309    164648190 :               && fndecl_built_in_p (olddecl))
    1310              :             {
    1311           50 :               types_match = self_promoting_args_p (p1);
    1312           50 :               if (p1 == void_list_node)
    1313            3 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1314              :             }
    1315              :           else
    1316    164648084 :             types_match =
    1317    164648084 :               compparms (p1, p2)
    1318     28418065 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1319    193065779 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1320      1213780 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1321      1213780 :                                            TREE_TYPE (olddecl)) != 0);
    1322              :         }
    1323              :       else
    1324              :         types_match = 0;
    1325              : 
    1326              :       /* Two function declarations match if either has a requires-clause
    1327              :          then both have a requires-clause and their constraints-expressions
    1328              :          are equivalent.  */
    1329     28417724 :       if (types_match && flag_concepts)
    1330     27934596 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1331              : 
    1332              :       /* The decls dont match if they correspond to two different versions
    1333              :          of the same function.   Disallow extern "C" functions to be
    1334              :          versions for now.  */
    1335     28417724 :       if (types_match
    1336     28227184 :           && !DECL_EXTERN_C_P (newdecl)
    1337     20584020 :           && !DECL_EXTERN_C_P (olddecl)
    1338     48997938 :           && disjoint_version_decls (newdecl, olddecl))
    1339              :         {
    1340         8868 :           if (record_versions)
    1341         8781 :             maybe_version_functions (newdecl, olddecl);
    1342         8868 :           return 0;
    1343              :         }
    1344              :     }
    1345    148807284 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1346              :     {
    1347    147086907 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1348              :         return 0;
    1349              : 
    1350     48182500 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1351     48182500 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1352              : 
    1353     48182500 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1354              :         return 0;
    1355              : 
    1356              :       /* Two template types match if they are the same. Otherwise, compare
    1357              :          the underlying declarations.  */
    1358     48182494 :       if (TREE_CODE (newres) == TYPE_DECL)
    1359           30 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1360              :       else
    1361     48182464 :         types_match = decls_match (newres, oldres);
    1362              :     }
    1363              :   else
    1364              :     {
    1365              :       /* Need to check scope for variable declaration (VAR_DECL).
    1366              :          For typedef (TYPE_DECL), scope is ignored.  */
    1367      1720377 :       if (VAR_P (newdecl)
    1368      1177249 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1369              :           /* [dcl.link]
    1370              :              Two declarations for an object with C language linkage
    1371              :              with the same name (ignoring the namespace that qualify
    1372              :              it) that appear in different namespace scopes refer to
    1373              :              the same object.  */
    1374      1905707 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1375              :         return 0;
    1376              : 
    1377      1535095 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1378            0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1379      1535095 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1380            0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1381      1535095 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1382              :         types_match = 0;
    1383              :       else
    1384      1535095 :         types_match = comptypes (TREE_TYPE (newdecl),
    1385      1535095 :                                  TREE_TYPE (olddecl),
    1386              :                                  COMPARE_REDECLARATION);
    1387              :     }
    1388              : 
    1389              :   return types_match;
    1390              : }
    1391              : 
    1392              : /* Mark DECL as versioned if it isn't already.  */
    1393              : 
    1394              : void
    1395        17652 : maybe_mark_function_versioned (tree decl)
    1396              : {
    1397        17652 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1398              :     {
    1399              :       /* We need to insert function version now to make sure the correct
    1400              :          pre-mangled assembler name is recorded.  */
    1401         1065 :       cgraph_node *node = cgraph_node::get_create (decl);
    1402              : 
    1403         1065 :       if (!node->function_version ())
    1404         1065 :         node->insert_new_function_version ();
    1405              : 
    1406         1065 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1407              :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1408              :          to include the version marker.  */
    1409         1065 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1410         1059 :         mangle_decl (decl);
    1411              :     }
    1412        17652 : }
    1413              : 
    1414              : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1415              :    different versions adjust them, record function versions, and return
    1416              :    true.  */
    1417              : 
    1418              : bool
    1419       198508 : maybe_version_functions (tree newdecl, tree olddecl)
    1420              : {
    1421       198508 :   if (!disjoint_version_decls (newdecl, olddecl))
    1422              :     return false;
    1423              : 
    1424         8808 :   maybe_mark_function_versioned (olddecl);
    1425         8808 :   if (DECL_LOCAL_DECL_P (olddecl))
    1426              :     {
    1427           18 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1428           18 :       maybe_mark_function_versioned (olddecl);
    1429              :     }
    1430              : 
    1431         8808 :   maybe_mark_function_versioned (newdecl);
    1432         8808 :   if (DECL_LOCAL_DECL_P (newdecl))
    1433              :     {
    1434              :       /* Unfortunately, we can get here before pushdecl naturally calls
    1435              :          push_local_extern_decl_alias, so we need to call it directly.  */
    1436           18 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1437            6 :         push_local_extern_decl_alias (newdecl);
    1438           18 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1439           18 :       maybe_mark_function_versioned (newdecl);
    1440              :     }
    1441              : 
    1442              :   /* Add the new version to the function version structure.  */
    1443         8808 :   cgraph_node *fn_node = cgraph_node::get_create (olddecl);
    1444         8808 :   cgraph_function_version_info *fn_v = fn_node->function_version ();
    1445         8808 :   if (!fn_v)
    1446           15 :     fn_v = fn_node->insert_new_function_version ();
    1447              : 
    1448         8808 :   cgraph_node::add_function_version (fn_v, newdecl);
    1449              : 
    1450         8808 :   return true;
    1451              : }
    1452              : 
    1453              : /* If NEWDECL is `static' and an `extern' was seen previously,
    1454              :    warn about it.  OLDDECL is the previous declaration.
    1455              : 
    1456              :    Note that this does not apply to the C++ case of declaring
    1457              :    a variable `extern const' and then later `const'.
    1458              : 
    1459              :    Don't complain about built-in functions, since they are beyond
    1460              :    the user's control.  */
    1461              : 
    1462              : void
    1463     19311012 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1464              : {
    1465     19311012 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1466     19264474 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1467     15368005 :       || TREE_CODE (newdecl) == CONST_DECL
    1468     15368005 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1469     19311000 :     return;
    1470              : 
    1471              :   /* Don't get confused by static member functions; that's a different
    1472              :      use of `static'.  */
    1473     15368005 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1474     15368005 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1475              :     return;
    1476              : 
    1477              :   /* If the old declaration was `static', or the new one isn't, then
    1478              :      everything is OK.  */
    1479     15196025 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1480              :     return;
    1481              : 
    1482              :   /* It's OK to declare a builtin function as `static'.  */
    1483           12 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1484           12 :       && DECL_ARTIFICIAL (olddecl))
    1485              :     return;
    1486              : 
    1487           12 :   auto_diagnostic_group d;
    1488           12 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1489              :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1490           12 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1491              :             "previous declaration of %qD", olddecl);
    1492           12 : }
    1493              : 
    1494              : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1495              :    function templates.  If their exception specifications do not
    1496              :    match, issue a diagnostic.  */
    1497              : 
    1498              : static void
    1499     18769117 : check_redeclaration_exception_specification (tree new_decl,
    1500              :                                              tree old_decl)
    1501              : {
    1502     18769117 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1503     18769117 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1504              : 
    1505              :   /* Two default specs are equivalent, don't force evaluation.  */
    1506      7170163 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1507     18910391 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1508              :     return;
    1509              : 
    1510     18759500 :   if (!type_dependent_expression_p (old_decl))
    1511              :     {
    1512     11455358 :       maybe_instantiate_noexcept (new_decl);
    1513     11455358 :       maybe_instantiate_noexcept (old_decl);
    1514              :     }
    1515     18759500 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1516     18759500 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1517              : 
    1518              :   /* [except.spec]
    1519              : 
    1520              :      If any declaration of a function has an exception-specification,
    1521              :      all declarations, including the definition and an explicit
    1522              :      specialization, of that function shall have an
    1523              :      exception-specification with the same set of type-ids.  */
    1524     18759500 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1525     14929041 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1526     33688444 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1527              :     {
    1528          326 :       const char *const msg
    1529              :         = G_("declaration of %qF has a different exception specifier");
    1530          326 :       bool complained = true;
    1531          326 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1532          326 :       auto_diagnostic_group d;
    1533              : 
    1534              :       /* Be permissive about C++98 vs C++11 operator new declarations.  */
    1535          652 :       bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
    1536            1 :                          && CP_DECL_CONTEXT (new_decl) == global_namespace
    1537          328 :                          && (nothrow_spec_p (new_exceptions)
    1538            1 :                              == nothrow_spec_p (old_exceptions)));
    1539              : 
    1540          326 :       if (DECL_IN_SYSTEM_HEADER (old_decl)
    1541          326 :           && (global_new || DECL_EXTERN_C_P (old_decl)))
    1542              :         /* Don't fuss about the C library; the C library functions are not
    1543              :            specified to have exception specifications (just behave as if they
    1544              :            have them), but some implementations include them.  */
    1545          233 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1546           93 :       else if (!flag_exceptions)
    1547              :         /* We used to silently permit mismatched eh specs with
    1548              :            -fno-exceptions, so only complain if -pedantic.  */
    1549            3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1550           90 :       else if (!new_exceptions || global_new)
    1551              :         /* Reduce to pedwarn for omitted exception specification.  No warning
    1552              :            flag for this; silence the warning by correcting the code.  */
    1553           21 :         complained = pedwarn (new_loc, 0, msg, new_decl);
    1554              :       else
    1555           69 :         error_at (new_loc, msg, new_decl);
    1556              : 
    1557          326 :       if (complained)
    1558           96 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1559              :                 "from previous declaration %qF", old_decl);
    1560              : 
    1561              :       /* Copy the old exception specification if new_decl has none.  Unless the
    1562              :          old decl is extern "C", as obscure code might depend on the type of
    1563              :          the new declaration (e.g. noexcept-type19.C).  */
    1564          326 :       if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
    1565           20 :         TREE_TYPE (new_decl)
    1566           40 :           = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
    1567          326 :     }
    1568              : }
    1569              : 
    1570              : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1571              :    Otherwise issue diagnostics.  */
    1572              : 
    1573              : bool
    1574     19311534 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1575              : {
    1576     19311534 :   old_decl = STRIP_TEMPLATE (old_decl);
    1577     19311534 :   new_decl = STRIP_TEMPLATE (new_decl);
    1578     19311534 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1579     19264972 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1580              :     return true;
    1581     19264972 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1582     19264972 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1583              :     {
    1584     19118404 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1585              :         return true;
    1586     37539056 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1587     18769528 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1588              :         return true;
    1589              :     }
    1590       146574 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1591              :     {
    1592              :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1593              :          keyword.  */
    1594           71 :       if (flag_implicit_constexpr
    1595           71 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1596            0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1597              :         return true;
    1598           71 :       if (fndecl_built_in_p (old_decl))
    1599              :         {
    1600              :           /* Hide a built-in declaration.  */
    1601            0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1602            0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1603            0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1604            0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1605            0 :           return true;
    1606              :         }
    1607              :       /* 7.1.5 [dcl.constexpr]
    1608              :          Note: An explicit specialization can differ from the template
    1609              :          declaration with respect to the constexpr specifier.  */
    1610           71 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1611           71 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1612              :         return true;
    1613              : 
    1614           42 :       const char *kind = "constexpr";
    1615           42 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1616           72 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1617              :         kind = "consteval";
    1618           42 :       auto_diagnostic_group d;
    1619           42 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1620              :                 "redeclaration %qD differs in %qs "
    1621              :                 "from previous declaration", new_decl,
    1622              :                 kind);
    1623           42 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1624              :               "previous declaration %qD", old_decl);
    1625           42 :       return false;
    1626           42 :     }
    1627              :   return true;
    1628              : }
    1629              : 
    1630              : /* DECL is a redeclaration of a function or function template.  If
    1631              :    it does have default arguments issue a diagnostic.  Note: this
    1632              :    function is used to enforce the requirements in C++11 8.3.6 about
    1633              :    no default arguments in redeclarations.  */
    1634              : 
    1635              : static void
    1636     11274141 : check_redeclaration_no_default_args (tree decl)
    1637              : {
    1638     11274141 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1639              : 
    1640     11274141 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1641     33236584 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1642     21962500 :     if (TREE_PURPOSE (t))
    1643              :       {
    1644           57 :         permerror (DECL_SOURCE_LOCATION (decl),
    1645              :                    "redeclaration of %q#D may not have default "
    1646              :                    "arguments", decl);
    1647           57 :         return;
    1648              :       }
    1649              : }
    1650              : 
    1651              : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1652              :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1653              :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1654              :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1655              :    "If a friend declaration specifies a default argument expression, that
    1656              :    declaration shall be a definition and shall be the only declaration of
    1657              :    the function or function template in the translation unit."  */
    1658              : 
    1659              : static void
    1660      6888308 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1661              : {
    1662     13082003 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1663              :     return;
    1664              : 
    1665      3438342 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1666      1719171 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1667      4571337 :        t1 && t1 != void_list_node;
    1668      2852166 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1669      4093296 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1670      8125906 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1671              :       {
    1672           36 :         auto_diagnostic_group d;
    1673           36 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1674              :                        "friend declaration of %q#D specifies default "
    1675              :                        "arguments and isn%'t the only declaration", newdecl))
    1676           36 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1677              :                   "previous declaration of %q#D", olddecl);
    1678           36 :         return;
    1679           36 :       }
    1680              : }
    1681              : 
    1682              : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1683              :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1684              : 
    1685              : static void
    1686     18220433 : merge_attribute_bits (tree newdecl, tree olddecl)
    1687              : {
    1688     18220433 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1689     18220433 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1690     18220433 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1691     18220433 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1692     18220433 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1693     18220433 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1694     18220433 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1695     18220433 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1696     18220433 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1697     18220433 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1698     18220433 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1699     18220433 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1700     18220433 :   TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
    1701     18220433 :   TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
    1702     18220433 :   TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
    1703     18220433 :   TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
    1704     18220433 : }
    1705              : 
    1706              : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1707              :                           && lookup_attribute ("gnu_inline",          \
    1708              :                                                DECL_ATTRIBUTES (fn)))
    1709              : 
    1710              : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1711              :    ambiguates olddecl.  Returns true if an error occurs.  */
    1712              : 
    1713              : static bool
    1714    143190282 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1715              : {
    1716    143190282 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1717    143190282 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1718              :   /* Function template declarations can be differentiated by parameter
    1719              :      and return type.  */
    1720    143190282 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1721    143190282 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1722    143190282 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1723              :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1724              :     {
    1725              :       /* ... and also by their template-heads and requires-clauses.  */
    1726         6717 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1727         6717 :           && function_requirements_equivalent_p (newres, oldres))
    1728              :         {
    1729            0 :           auto_diagnostic_group d;
    1730            0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1731            0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1732              :                   "old declaration %q#D", olddecl);
    1733            0 :           return true;
    1734            0 :         }
    1735              : 
    1736              :       /* FIXME: The types are the same but the are differences
    1737              :          in either the template heads or function requirements.
    1738              :          We should be able to diagnose a set of common errors
    1739              :          stemming from these declarations. For example:
    1740              : 
    1741              :            template<typename T> requires C void f(...);
    1742              :            template<typename T> void f(...) requires C;
    1743              : 
    1744              :          These are functionally equivalent but not equivalent.  */
    1745              :     }
    1746              : 
    1747              :   return false;
    1748              : }
    1749              : 
    1750              : /* OLD_PARMS is the innermost set of template parameters for some template
    1751              :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1752              :    for a redeclaration of that template.  Merge the default arguments within
    1753              :    these two sets of parameters.  CLASS_P is true iff the template in
    1754              :    question is a class template.  */
    1755              : 
    1756              : bool
    1757      8659677 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1758              : {
    1759      8659677 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1760              :                        == TREE_VEC_LENGTH (old_parms));
    1761     24509570 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1762              :     {
    1763     15849923 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1764     15849923 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1765     15849923 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1766     15849923 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1767     15849923 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1768              :         return false;
    1769     15849920 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1770              :         {
    1771           27 :           auto_diagnostic_group d;
    1772           27 :           error ("redefinition of default argument for %q+#D", new_parm);
    1773           27 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1774              :                   "original definition appeared here");
    1775           27 :           return false;
    1776           27 :         }
    1777     15849893 :       else if (new_default != NULL_TREE)
    1778              :         /* Update the previous template parameters (which are the ones
    1779              :            that will really count) with the new default value.  */
    1780       226389 :         old_default = new_default;
    1781     15623504 :       else if (class_p && old_default != NULL_TREE)
    1782              :         /* Update the new parameters, too; they'll be used as the
    1783              :            parameters for any members.  */
    1784       979544 :         new_default = old_default;
    1785              :     }
    1786              :   return true;
    1787              : }
    1788              : 
    1789              : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
    1790              :    Merge parameter attributes and names between NEWDECL and OLDDECL.
    1791              :    NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
    1792              :    duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
    1793              :    push_local_extern_decl_alias.  */
    1794              : 
    1795              : void
    1796     14873088 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
    1797              :                       bool types_match, bool extern_alias)
    1798              : {
    1799     14873088 :   tree oldarg, newarg, type = NULL_TREE;
    1800     14873088 :   tree first_user_parm = NULL_TREE;
    1801     14873088 :   if (extern_alias)
    1802          185 :     first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
    1803     14873088 :   for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
    1804     41626661 :        oldarg && newarg;
    1805     26753573 :        oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
    1806              :     {
    1807     26753573 :       DECL_ATTRIBUTES (newarg)
    1808     26753573 :         = (*targetm.merge_decl_attributes) (oldarg, newarg);
    1809     26753573 :       if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
    1810     26753642 :           && !lookup_attribute (NULL, "indeterminate",
    1811           69 :                                 DECL_ATTRIBUTES (oldarg)))
    1812              :         {
    1813           18 :           auto_diagnostic_group d;
    1814           18 :           error_at (DECL_SOURCE_LOCATION (newarg),
    1815              :                     "%<indeterminate%> attribute not specified for parameter "
    1816              :                     "%qD on the first declaration of its function", newarg);
    1817           18 :           inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
    1818           18 :         }
    1819              :       /* ??? Should attributes propagate out from a block extern?  If so,
    1820              :          we should do that for the function itself, not just parameters.  */
    1821     26753573 :       if (!extern_alias || flag_reflection)
    1822     26753410 :         DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1823     26753573 :       if (!flag_reflection)
    1824     26399523 :         continue;
    1825              :       /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
    1826              :          if the local extern has a default argument for that parameter.  */
    1827       354050 :       if (extern_alias)
    1828              :         {
    1829           36 :           if (newarg == first_user_parm)
    1830           12 :             type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1831           24 :           else if (type)
    1832           24 :             type = TREE_CHAIN (type);
    1833           72 :           if (type && TREE_PURPOSE (type))
    1834            4 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1835              :         }
    1836              :       else
    1837              :         {
    1838              :           /* Otherwise propagate the flag.  */
    1839       354014 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
    1840            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
    1841       354014 :           if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
    1842            0 :             DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
    1843              :         }
    1844              :       /* Merge names for std::meta::has_identifier and
    1845              :          std::meta::{,u8}identifier_of purposes.  If they are different and
    1846              :          both oldarg and newarg are named, add flag to force that
    1847              :          std::meta::has_identifier returns false.  If one is named and one is
    1848              :          unnamed, if neither is a olddecl nor newdecl is definition, propagate
    1849              :          DECL_NAME to both.  Otherwise stash the old name into "old parm name"
    1850              :          artificial attribute.  */
    1851       354050 :       if (DECL_NAME (oldarg) != DECL_NAME (newarg))
    1852              :         {
    1853        39212 :           if (DECL_NAME (oldarg) && DECL_NAME (newarg))
    1854              :             {
    1855              :               /* Different names.  */
    1856         9048 :               MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1857         9048 :               MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1858              :             }
    1859        30164 :           else if (!new_defines_function
    1860        30164 :                    && types_match
    1861        30164 :                    && DECL_INITIAL (olddecl) == NULL_TREE)
    1862              :             {
    1863              :               /* For 2 non-definitions with matching types, one is named and
    1864              :                  one unnamed, propagate name to both.  */
    1865         5882 :               if (DECL_NAME (oldarg))
    1866         5082 :                 DECL_NAME (newarg) = DECL_NAME (oldarg);
    1867              :               else
    1868          800 :                 DECL_NAME (oldarg) = DECL_NAME (newarg);
    1869              :             }
    1870              :           /* Depending on which PARM_DECL we'll keep, look at the other
    1871              :              PARM_DECL's name.  */
    1872        24282 :           else if (tree name = ((new_defines_function || !types_match)
    1873        24282 :                                 ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
    1874              :             {
    1875          158 :               tree opn = lookup_attribute ("old parm name",
    1876          158 :                                            DECL_ATTRIBUTES (oldarg));
    1877          158 :               if (opn)
    1878              :                 {
    1879            4 :                   if (TREE_VALUE (TREE_VALUE (opn)) == name)
    1880              :                     /* Name already in "old parm name" attribute.  */;
    1881              :                   else
    1882              :                     {
    1883              :                       /* Different names.  */
    1884            0 :                       MULTIPLE_NAMES_PARM_P (oldarg) = 1;
    1885            0 :                       MULTIPLE_NAMES_PARM_P (newarg) = 1;
    1886              :                     }
    1887              :                 }
    1888              :               else
    1889              :                 {
    1890              :                   /* Save name into attribute.  */
    1891          154 :                   DECL_ATTRIBUTES (newarg)
    1892          154 :                     = tree_cons (get_identifier ("old parm name"),
    1893              :                                  tree_cons (NULL_TREE, name, NULL_TREE),
    1894          154 :                                  DECL_ATTRIBUTES (newarg));
    1895          154 :                   DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    1896              :                 }
    1897              :             }
    1898        24124 :           else if (extern_alias)
    1899            2 :             DECL_NAME (newarg) = DECL_NAME (oldarg);
    1900              :         }
    1901              :     }
    1902     14873088 : }
    1903              : 
    1904              : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1905              :    If the redeclaration is invalid, a diagnostic is issued, and the
    1906              :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1907              : 
    1908              :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1909              :    returned.
    1910              : 
    1911              :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1912              :    if the old decl was hidden.
    1913              : 
    1914              :    Hidden decls can be anticipated builtins, injected friends, or
    1915              :    (coming soon) injected from a local-extern decl.   */
    1916              : 
    1917              : tree
    1918    294464347 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1919              : {
    1920    294464347 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1921    294464347 :   int types_match = 0;
    1922    294464347 :   int new_defines_function = 0;
    1923    294464347 :   tree new_template_info;
    1924    294464347 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1925    294464347 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1926              : 
    1927    294464347 :   if (newdecl == olddecl)
    1928              :     return olddecl;
    1929              : 
    1930    293667898 :   types_match = decls_match (newdecl, olddecl);
    1931              : 
    1932              :   /* If either the type of the new decl or the type of the old decl is an
    1933              :      error_mark_node, then that implies that we have already issued an
    1934              :      error (earlier) for some bogus type specification, and in that case,
    1935              :      it is rather pointless to harass the user with yet more error message
    1936              :      about the same declaration, so just pretend the types match here.  */
    1937    293667898 :   if (TREE_TYPE (newdecl) == error_mark_node
    1938    293667898 :       || TREE_TYPE (olddecl) == error_mark_node)
    1939              :     return error_mark_node;
    1940              : 
    1941              :   /* Check for redeclaration and other discrepancies.  */
    1942    293667872 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1943    293667872 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1944              :     {
    1945      6199523 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1946              :         {
    1947              :           /* Avoid warnings redeclaring built-ins which have not been
    1948              :              explicitly declared.  */
    1949       190325 :           if (was_hidden)
    1950              :             {
    1951       190283 :               if (TREE_PUBLIC (newdecl)
    1952       190283 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1953           12 :                 warning_at (newdecl_loc,
    1954           12 :                             OPT_Wbuiltin_declaration_mismatch,
    1955              :                             "built-in function %qD declared as non-function",
    1956              :                             newdecl);
    1957       190283 :               return NULL_TREE;
    1958              :             }
    1959              : 
    1960              :           /* If you declare a built-in or predefined function name as static,
    1961              :              the old definition is overridden, but optionally warn this was a
    1962              :              bad choice of name.  */
    1963           42 :           if (! TREE_PUBLIC (newdecl))
    1964              :             {
    1965           42 :               warning_at (newdecl_loc,
    1966           42 :                           OPT_Wshadow,
    1967           42 :                           fndecl_built_in_p (olddecl)
    1968              :                           ? G_("shadowing built-in function %q#D")
    1969              :                           : G_("shadowing library function %q#D"), olddecl);
    1970              :               /* Discard the old built-in function.  */
    1971           42 :               return NULL_TREE;
    1972              :             }
    1973              :           /* If the built-in is not ansi, then programs can override
    1974              :              it even globally without an error.  */
    1975            0 :           else if (! fndecl_built_in_p (olddecl))
    1976            0 :             warning_at (newdecl_loc, 0,
    1977              :                         "library function %q#D redeclared as non-function %q#D",
    1978              :                         olddecl, newdecl);
    1979              :           else
    1980            0 :             error_at (newdecl_loc,
    1981              :                       "declaration of %q#D conflicts with built-in "
    1982              :                       "declaration %q#D", newdecl, olddecl);
    1983            0 :           return NULL_TREE;
    1984              :         }
    1985      6009198 :       else if (!types_match)
    1986              :         {
    1987              :           /* Avoid warnings redeclaring built-ins which have not been
    1988              :              explicitly declared.  */
    1989      2178739 :           if (was_hidden)
    1990              :             {
    1991       780423 :               tree t1, t2;
    1992              : 
    1993              :               /* A new declaration doesn't match a built-in one unless it
    1994              :                  is also extern "C".  */
    1995       780423 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1996       780423 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1997       780423 :               if (!DECL_EXTERN_C_P (newdecl))
    1998              :                 return NULL_TREE;
    1999              : 
    2000       141353 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2001       141353 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2002       243396 :                    t1 || t2;
    2003       102043 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    2004              :                 {
    2005       243378 :                   if (!t1 || !t2)
    2006              :                     break;
    2007              :                   /* FILE, tm types are not known at the time
    2008              :                      we create the builtins.  */
    2009       749659 :                   for (unsigned i = 0;
    2010       992875 :                        i < sizeof (builtin_structptr_types)
    2011              :                            / sizeof (builtin_structptr_type);
    2012              :                        ++i)
    2013       890826 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    2014              :                       {
    2015       141167 :                         tree t = TREE_VALUE (t1);
    2016              : 
    2017       141167 :                         if (TYPE_PTR_P (t)
    2018       282334 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    2019       141167 :                             == get_identifier (builtin_structptr_types[i].str)
    2020       282319 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    2021              :                           {
    2022       141152 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    2023              : 
    2024       141152 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    2025       141152 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    2026       141152 :                             types_match = decls_match (newdecl, olddecl);
    2027       141152 :                             if (types_match)
    2028       141152 :                               return duplicate_decls (newdecl, olddecl,
    2029       141152 :                                                       hiding, was_hidden);
    2030            0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    2031              :                           }
    2032           15 :                         goto next_arg;
    2033              :                       }
    2034              : 
    2035       102049 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    2036              :                     break;
    2037       102043 :                 next_arg:;
    2038              :                 }
    2039              : 
    2040          201 :               warning_at (newdecl_loc,
    2041          201 :                           OPT_Wbuiltin_declaration_mismatch,
    2042              :                           "declaration of %q#D conflicts with built-in "
    2043              :                           "declaration %q#D", newdecl, olddecl);
    2044              :             }
    2045      1398316 :           else if ((DECL_EXTERN_C_P (newdecl)
    2046           15 :                     && DECL_EXTERN_C_P (olddecl))
    2047      2796617 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2048      1398301 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    2049              :             {
    2050              :               /* Don't really override olddecl for __* prefixed builtins
    2051              :                  except for __[^b]*_chk, the compiler might be using those
    2052              :                  explicitly.  */
    2053           15 :               if (fndecl_built_in_p (olddecl))
    2054              :                 {
    2055           15 :                   tree id = DECL_NAME (olddecl);
    2056           15 :                   const char *name = IDENTIFIER_POINTER (id);
    2057           15 :                   size_t len;
    2058              : 
    2059           15 :                   if (name[0] == '_'
    2060           15 :                       && name[1] == '_'
    2061           30 :                       && (startswith (name + 2, "builtin_")
    2062            6 :                           || (len = strlen (name)) <= strlen ("___chk")
    2063            6 :                           || memcmp (name + len - strlen ("_chk"),
    2064              :                                      "_chk", strlen ("_chk") + 1) != 0))
    2065              :                     {
    2066           15 :                       if (DECL_INITIAL (newdecl))
    2067              :                         {
    2068            6 :                           error_at (newdecl_loc,
    2069              :                                     "definition of %q#D ambiguates built-in "
    2070              :                                     "declaration %q#D", newdecl, olddecl);
    2071            6 :                           return error_mark_node;
    2072              :                         }
    2073            9 :                       auto_diagnostic_group d;
    2074            9 :                       if (permerror (newdecl_loc,
    2075              :                                      "new declaration %q#D ambiguates built-in"
    2076              :                                      " declaration %q#D", newdecl, olddecl)
    2077            9 :                           && flag_permissive)
    2078            3 :                         inform (newdecl_loc,
    2079              :                                 "ignoring the %q#D declaration", newdecl);
    2080            9 :                       return flag_permissive ? olddecl : error_mark_node;
    2081            9 :                     }
    2082              :                 }
    2083              : 
    2084              :               /* A near match; override the builtin.  */
    2085              : 
    2086            0 :               if (TREE_PUBLIC (newdecl))
    2087            0 :                 warning_at (newdecl_loc,
    2088            0 :                             OPT_Wbuiltin_declaration_mismatch,
    2089              :                             "new declaration %q#D ambiguates built-in "
    2090              :                             "declaration %q#D", newdecl, olddecl);
    2091              :               else
    2092            0 :                 warning (OPT_Wshadow,
    2093              :                          fndecl_built_in_p (olddecl)
    2094              :                          ? G_("shadowing built-in function %q#D")
    2095              :                          : G_("shadowing library function %q#D"), olddecl);
    2096              :             }
    2097              :           else
    2098              :             /* Discard the old built-in function.  */
    2099              :             return NULL_TREE;
    2100              : 
    2101              :           /* Replace the old RTL to avoid problems with inlining.  */
    2102          201 :           COPY_DECL_RTL (newdecl, olddecl);
    2103              :         }
    2104              :       else
    2105              :         {
    2106              :           /* Even if the types match, prefer the new declarations type
    2107              :              for built-ins which have not been explicitly declared,
    2108              :              for exception lists, etc...  */
    2109      3830459 :           tree type = TREE_TYPE (newdecl);
    2110      3830459 :           tree attribs = (*targetm.merge_type_attributes)
    2111      3830459 :             (TREE_TYPE (olddecl), type);
    2112              : 
    2113      3830459 :           type = cp_build_type_attribute_variant (type, attribs);
    2114      3830459 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    2115              :         }
    2116              : 
    2117              :       /* If a function is explicitly declared "throw ()", propagate that to
    2118              :          the corresponding builtin.  */
    2119      3830660 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    2120      3667195 :           && was_hidden
    2121      3667152 :           && TREE_NOTHROW (newdecl)
    2122      7239871 :           && !TREE_NOTHROW (olddecl))
    2123              :         {
    2124        26947 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    2125        26947 :           tree tmpdecl = builtin_decl_explicit (fncode);
    2126        26947 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    2127        26947 :             TREE_NOTHROW (tmpdecl)  = 1;
    2128              :         }
    2129              : 
    2130              :       /* Whether or not the builtin can throw exceptions has no
    2131              :          bearing on this declarator.  */
    2132      3830660 :       TREE_NOTHROW (olddecl) = 0;
    2133              : 
    2134      3830660 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    2135              :         {
    2136              :           /* If a builtin function is redeclared as `static', merge
    2137              :              the declarations, but make the original one static.  */
    2138            3 :           DECL_THIS_STATIC (olddecl) = 1;
    2139            3 :           TREE_PUBLIC (olddecl) = 0;
    2140              : 
    2141              :           /* Make the old declaration consistent with the new one so
    2142              :              that all remnants of the builtin-ness of this function
    2143              :              will be banished.  */
    2144            3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2145            3 :           COPY_DECL_RTL (newdecl, olddecl);
    2146              :         }
    2147              :     }
    2148    287468349 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    2149              :     {
    2150              :       /* C++ Standard, 3.3, clause 4:
    2151              :          "[Note: a namespace name or a class template name must be unique
    2152              :          in its declarative region (7.3.2, clause 14). ]"  */
    2153     69035621 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    2154     69035594 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    2155              :         /* Namespace conflicts with not namespace.  */;
    2156     33775664 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    2157    102811246 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    2158              :         /* Class template conflicts.  */;
    2159     69035576 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    2160     33775664 :                 && DECL_TEMPLATE_RESULT (olddecl)
    2161     33775664 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    2162    102811234 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    2163     35212792 :                    && DECL_TEMPLATE_RESULT (newdecl)
    2164     35212792 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    2165              :         /* Variable template conflicts.  */;
    2166     69035567 :       else if (concept_definition_p (olddecl)
    2167    138071128 :                || concept_definition_p (newdecl))
    2168              :         /* Concept conflicts.  */;
    2169     69035555 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    2170     33813380 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    2171     69073283 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    2172     35212805 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    2173              :         {
    2174              :           /* One is a function and the other is a template
    2175              :              function.  */
    2176     68988420 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    2177              :             return NULL_TREE;
    2178              : 
    2179              :           /* There can only be one!  */
    2180        55687 :           auto_diagnostic_group d;
    2181        55687 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    2182        55687 :               && check_raw_literal_operator (olddecl))
    2183            3 :             error_at (newdecl_loc,
    2184              :                       "literal operator %q#D conflicts with"
    2185              :                       " raw literal operator", newdecl);
    2186        55684 :           else if (check_raw_literal_operator (newdecl))
    2187            3 :             error_at (newdecl_loc,
    2188              :                       "raw literal operator %q#D conflicts with"
    2189              :                       " literal operator template", newdecl);
    2190              :           else
    2191              :             return NULL_TREE;
    2192              : 
    2193            6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2194            6 :           return error_mark_node;
    2195        55687 :         }
    2196        47135 :       else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
    2197              :         /* A structured binding must be unique in its declarative region.  */;
    2198        37880 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2199        47132 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    2200              :         /* One is an implicit typedef, that's ok.  */
    2201              :         return NULL_TREE;
    2202              : 
    2203          153 :       auto_diagnostic_group d;
    2204          153 :       error ("%q#D redeclared as different kind of entity", newdecl);
    2205          153 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    2206              : 
    2207          153 :       return error_mark_node;
    2208          153 :     }
    2209    218432728 :   else if (!types_match)
    2210              :     {
    2211    202919432 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    2212              :         /* These are certainly not duplicate declarations; they're
    2213              :            from different scopes.  */
    2214              :         return NULL_TREE;
    2215              : 
    2216    202919372 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2217              :         {
    2218    143190300 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    2219    143190300 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    2220              : 
    2221              :           /* The name of a class template may not be declared to refer to
    2222              :              any other template, class, function, object, namespace, value,
    2223              :              or type in the same scope.  */
    2224    143190300 :           if (TREE_CODE (oldres) == TYPE_DECL
    2225    143190294 :               || TREE_CODE (newres) == TYPE_DECL)
    2226              :             {
    2227            9 :               auto_diagnostic_group d;
    2228            9 :               error_at (newdecl_loc,
    2229              :                         "conflicting declaration of template %q#D", newdecl);
    2230            9 :               inform (olddecl_loc,
    2231              :                       "previous declaration %q#D", olddecl);
    2232            9 :               return error_mark_node;
    2233            9 :             }
    2234              : 
    2235    143190291 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    2236    143190282 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    2237              :             {
    2238    143190282 :               if (duplicate_function_template_decls (newdecl, olddecl))
    2239            0 :                 return error_mark_node;
    2240              :               return NULL_TREE;
    2241              :             }
    2242              :           return NULL_TREE;
    2243              :         }
    2244     59729072 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2245              :         {
    2246     59728915 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    2247              :             {
    2248           57 :               auto_diagnostic_group d;
    2249           57 :               error_at (newdecl_loc,
    2250              :                         "conflicting declaration of C function %q#D",
    2251              :                         newdecl);
    2252           57 :               inform (olddecl_loc,
    2253              :                       "previous declaration %q#D", olddecl);
    2254           57 :               return error_mark_node;
    2255           57 :             }
    2256              :           /* For function versions, params and types match, but they
    2257              :              are not ambiguous.  */
    2258     59728858 :           else if (((!DECL_FUNCTION_VERSIONED (newdecl)
    2259     59720536 :                      && !DECL_FUNCTION_VERSIONED (olddecl))
    2260         8367 :                     || !same_type_p (fndecl_declared_return_type (newdecl),
    2261              :                                      fndecl_declared_return_type (olddecl)))
    2262              :                    /* Let constrained hidden friends coexist for now, we'll
    2263              :                       check satisfaction later.  */
    2264     59720491 :                    && !member_like_constrained_friend_p (newdecl)
    2265     57255049 :                    && !member_like_constrained_friend_p (olddecl)
    2266              :                    // The functions have the same parameter types.
    2267     56805135 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    2268     56805135 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    2269              :                    // And the same constraints.
    2270     59728927 :                    && equivalently_constrained (newdecl, olddecl))
    2271              :             {
    2272           69 :               auto_diagnostic_group d;
    2273           69 :               error_at (newdecl_loc,
    2274              :                         "ambiguating new declaration of %q#D", newdecl);
    2275           69 :               inform (olddecl_loc,
    2276              :                       "old declaration %q#D", olddecl);
    2277           69 :               return error_mark_node;
    2278           69 :             }
    2279              :           else
    2280     59728789 :             return NULL_TREE;
    2281              :         }
    2282              :       else
    2283              :         {
    2284          157 :           auto_diagnostic_group d;
    2285          157 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    2286          157 :           inform (olddecl_loc,
    2287              :                   "previous declaration as %q#D", olddecl);
    2288          157 :           return error_mark_node;
    2289          157 :         }
    2290              :     }
    2291     15513296 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2292     15513296 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    2293              :     {
    2294              :       /* OMP UDRs are never duplicates. */
    2295           33 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    2296           33 :       auto_diagnostic_group d;
    2297           33 :       error_at (newdecl_loc,
    2298              :                 "redeclaration of %<pragma omp declare reduction%>");
    2299           33 :       inform (olddecl_loc,
    2300              :               "previous %<pragma omp declare reduction%> declaration");
    2301           33 :       return error_mark_node;
    2302           33 :     }
    2303     15513263 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2304     15513263 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    2305          224 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    2306          224 :                      || (DECL_TI_TEMPLATE (newdecl)
    2307          224 :                          != DECL_TI_TEMPLATE (olddecl))))
    2308     11042528 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2309       548950 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    2310       548950 :                         || (DECL_TI_TEMPLATE (olddecl)
    2311       548950 :                             != DECL_TI_TEMPLATE (newdecl))))))
    2312              :     /* It's OK to have a template specialization and a non-template
    2313              :        with the same type, or to have specializations of two
    2314              :        different templates with the same type.  Note that if one is a
    2315              :        specialization, and the other is an instantiation of the same
    2316              :        template, that we do not exit at this point.  That situation
    2317              :        can occur if we instantiate a template class, and then
    2318              :        specialize one of its methods.  This situation is valid, but
    2319              :        the declarations must be merged in the usual way.  */
    2320              :     return NULL_TREE;
    2321     15513263 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    2322     15513263 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    2323       628628 :                 && !DECL_USE_TEMPLATE (newdecl))
    2324     11042528 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    2325        79902 :                    && !DECL_USE_TEMPLATE (olddecl))))
    2326              :     /* One of the declarations is a template instantiation, and the
    2327              :        other is not a template at all.  That's OK.  */
    2328              :     return NULL_TREE;
    2329     15513263 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2330              :     {
    2331              :       /* In [namespace.alias] we have:
    2332              : 
    2333              :            In a declarative region, a namespace-alias-definition can be
    2334              :            used to redefine a namespace-alias declared in that declarative
    2335              :            region to refer only to the namespace to which it already
    2336              :            refers.
    2337              : 
    2338              :          Therefore, if we encounter a second alias directive for the same
    2339              :          alias, we can just ignore the second directive.  */
    2340           28 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2341           28 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2342           25 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2343              :         return olddecl;
    2344              : 
    2345              :       /* Leave it to update_binding to merge or report error.  */
    2346              :       return NULL_TREE;
    2347              :     }
    2348              :   /* Check if the two decls are non-mergeable versioned decls.  */
    2349     15513235 :   else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
    2350              :            && diagnose_versioned_decls (olddecl, newdecl))
    2351              :     return error_mark_node;
    2352              :   else
    2353              :     {
    2354     15513235 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2355     15513235 :       if (errmsg)
    2356              :         {
    2357          621 :           auto_diagnostic_group d;
    2358          621 :           error_at (newdecl_loc, errmsg, newdecl);
    2359          621 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2360          621 :             inform (olddecl_loc,
    2361          621 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2362              :                     ? G_("%q#D previously defined here")
    2363              :                     : G_("%q#D previously declared here"), olddecl);
    2364          621 :           if (cxx_dialect >= cxx26
    2365          147 :               && DECL_NAME (newdecl)
    2366          147 :               && id_equal (DECL_NAME (newdecl), "_")
    2367          634 :               && !name_independent_decl_p (newdecl))
    2368              :             {
    2369           13 :               if (TREE_CODE (newdecl) == PARM_DECL)
    2370            2 :                 inform (newdecl_loc,
    2371              :                         "parameter declaration is not name-independent");
    2372           11 :               else if (DECL_DECOMPOSITION_P (newdecl))
    2373              :                 {
    2374            3 :                   if (at_namespace_scope_p ())
    2375            2 :                     inform (newdecl_loc,
    2376              :                             "structured binding at namespace scope is not "
    2377              :                             "name-independent");
    2378            1 :                   else if (TREE_STATIC (newdecl))
    2379            1 :                     inform (newdecl_loc,
    2380              :                             "static structured binding is not "
    2381              :                             "name-independent");
    2382            0 :                   else if (DECL_EXTERNAL (newdecl))
    2383            0 :                     inform (newdecl_loc,
    2384              :                             "extern structured binding is not "
    2385              :                             "name-independent");
    2386              :                 }
    2387            8 :               else if (at_class_scope_p ()
    2388            0 :                        && VAR_P (newdecl)
    2389            8 :                        && TREE_STATIC (newdecl))
    2390            0 :                 inform (newdecl_loc,
    2391              :                         "static data member is not name-independent");
    2392            8 :               else if (VAR_P (newdecl) && at_namespace_scope_p ())
    2393            3 :                 inform (newdecl_loc,
    2394              :                         "variable at namespace scope is not name-independent");
    2395            5 :               else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
    2396            3 :                 inform (newdecl_loc,
    2397              :                         "static variable is not name-independent");
    2398            2 :               else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
    2399            0 :                 inform (newdecl_loc,
    2400              :                         "extern variable is not name-independent");
    2401              :             }
    2402          621 :           return error_mark_node;
    2403          621 :         }
    2404     15512614 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2405     11042288 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2406        15606 :                && !prototype_p (TREE_TYPE (olddecl))
    2407     15512614 :                && prototype_p (TREE_TYPE (newdecl)))
    2408              :         {
    2409              :           /* Prototype decl follows defn w/o prototype.  */
    2410            0 :           auto_diagnostic_group d;
    2411            0 :           if (warning_at (newdecl_loc, 0,
    2412              :                           "prototype specified for %q#D", newdecl))
    2413            0 :             inform (olddecl_loc,
    2414              :                     "previous non-prototype definition here");
    2415            0 :         }
    2416     15017512 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2417     26554902 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2418              :         {
    2419              :           /* [dcl.link]
    2420              :              If two declarations of the same function or object
    2421              :              specify different linkage-specifications ..., the program
    2422              :              is ill-formed.... Except for functions with C++ linkage,
    2423              :              a function declaration without a linkage specification
    2424              :              shall not precede the first linkage specification for
    2425              :              that function.  A function can be declared without a
    2426              :              linkage specification after an explicit linkage
    2427              :              specification has been seen; the linkage explicitly
    2428              :              specified in the earlier declaration is not affected by
    2429              :              such a function declaration.
    2430              : 
    2431              :              DR 563 raises the question why the restrictions on
    2432              :              functions should not also apply to objects.  Older
    2433              :              versions of G++ silently ignore the linkage-specification
    2434              :              for this example:
    2435              : 
    2436              :                namespace N {
    2437              :                  extern int i;
    2438              :                  extern "C" int i;
    2439              :                }
    2440              : 
    2441              :              which is clearly wrong.  Therefore, we now treat objects
    2442              :              like functions.  */
    2443         1792 :           if (current_lang_depth () == 0)
    2444              :             {
    2445              :               /* There is no explicit linkage-specification, so we use
    2446              :                  the linkage from the previous declaration.  */
    2447         1780 :               retrofit_lang_decl (newdecl);
    2448         1780 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2449              :             }
    2450              :           else
    2451              :             {
    2452           12 :               auto_diagnostic_group d;
    2453           12 :               error_at (newdecl_loc,
    2454              :                         "conflicting declaration of %q#D with %qL linkage",
    2455           12 :                         newdecl, DECL_LANGUAGE (newdecl));
    2456           12 :               inform (olddecl_loc,
    2457              :                       "previous declaration with %qL linkage",
    2458           12 :                       DECL_LANGUAGE (olddecl));
    2459           12 :             }
    2460              :         }
    2461              : 
    2462     15512614 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2463              :         ;
    2464     14863828 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2465              :         {
    2466              :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2467     12997875 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2468     10413445 :               && (/* grokfndecl passes member function templates too
    2469              :                      as FUNCTION_DECLs.  */
    2470      8000887 :                   DECL_TEMPLATE_INFO (olddecl)
    2471              :                   /* C++11 8.3.6/6.
    2472              :                      Default arguments for a member function of a class
    2473              :                      template shall be specified on the initial declaration
    2474              :                      of the member function within the class template.  */
    2475       678674 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2476              :             {
    2477      7399639 :               check_redeclaration_no_default_args (newdecl);
    2478              : 
    2479      7399639 :               if (DECL_TEMPLATE_INFO (olddecl)
    2480      7399639 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2481              :                 {
    2482      2138675 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2483      2138675 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2484      2138675 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2485      2138675 :                   tree old_parms
    2486      2138675 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2487      2138675 :                   merge_default_template_args (new_parms, old_parms,
    2488              :                                                /*class_p=*/false);
    2489              :                 }
    2490              :             }
    2491              :           else
    2492              :             {
    2493      3013806 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2494      3013806 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2495      3013806 :               int i = 1;
    2496              : 
    2497      7790775 :               for (; t1 && t1 != void_list_node;
    2498      4776969 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2499      4778782 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2500              :                   {
    2501           57 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2502           57 :                                           TREE_PURPOSE (t2)) == 1)
    2503              :                       {
    2504           24 :                         auto_diagnostic_group d;
    2505           24 :                         if (permerror (newdecl_loc,
    2506              :                                        "default argument given for parameter "
    2507              :                                        "%d of %q#D", i, newdecl))
    2508           24 :                           inform (olddecl_loc,
    2509              :                                   "previous specification in %q#D here",
    2510              :                                   olddecl);
    2511           24 :                       }
    2512              :                     else
    2513              :                       {
    2514           33 :                         auto_diagnostic_group d;
    2515           33 :                         error_at (newdecl_loc,
    2516              :                                   "default argument given for parameter %d "
    2517              :                                   "of %q#D", i, newdecl);
    2518           33 :                         inform (olddecl_loc,
    2519              :                                 "previous specification in %q#D here",
    2520              :                                 olddecl);
    2521           33 :                       }
    2522              :                   }
    2523              : 
    2524              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2525              :                  argument expression, that declaration... shall be the only
    2526              :                  declaration of the function or function template in the
    2527              :                  translation unit."  */
    2528      3013806 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2529              :             }
    2530              :         }
    2531              :     }
    2532              : 
    2533              :   /* Do not merge an implicit typedef with an explicit one.  In:
    2534              : 
    2535              :        class A;
    2536              :        ...
    2537              :        typedef class A A __attribute__ ((foo));
    2538              : 
    2539              :      the attribute should apply only to the typedef.  */
    2540     19343274 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2541     19343274 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2542        46541 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2543              :     return NULL_TREE;
    2544              : 
    2545     19311078 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2546              :     return NULL_TREE;
    2547              : 
    2548     19311066 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2549           30 :     return error_mark_node;
    2550              : 
    2551     19311036 :   if (modules_p ()
    2552        60879 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2553     19346882 :       && TREE_CODE (olddecl) != NAMESPACE_DECL)
    2554              :     {
    2555        35846 :       if (!module_may_redeclare (olddecl, newdecl))
    2556           24 :         return error_mark_node;
    2557              : 
    2558        35822 :       if (!hiding)
    2559              :         {
    2560              :           /* The old declaration should match the exportingness of the new
    2561              :              declaration.  But hidden friend declarations just keep the
    2562              :              exportingness of the old declaration; see CWG2588.  */
    2563        31564 :           tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2564        31564 :           if (DECL_LANG_SPECIFIC (not_tmpl)
    2565        31467 :               && DECL_MODULE_ATTACH_P (not_tmpl)
    2566              :               /* Typedefs are not entities and so are OK to be redeclared
    2567              :                  as exported: see [module.interface]/p6.  */
    2568        31755 :               && TREE_CODE (olddecl) != TYPE_DECL)
    2569              :             {
    2570          179 :               if (DECL_MODULE_EXPORT_P (newdecl)
    2571          179 :                   && !DECL_MODULE_EXPORT_P (not_tmpl))
    2572              :                 {
    2573           15 :                   auto_diagnostic_group d;
    2574           15 :                   error ("conflicting exporting for declaration %qD", newdecl);
    2575           15 :                   inform (olddecl_loc,
    2576              :                           "previously declared here without exporting");
    2577           15 :                 }
    2578              :             }
    2579        31385 :           else if (DECL_MODULE_EXPORT_P (newdecl))
    2580        10322 :             DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2581              :         }
    2582              :     }
    2583              : 
    2584              :   /* We have committed to returning OLDDECL at this point.  */
    2585              : 
    2586              :   /* If new decl is `static' and an `extern' was seen previously,
    2587              :      warn about it.  */
    2588     19311012 :   warn_extern_redeclared_static (newdecl, olddecl);
    2589              : 
    2590              :   /* True to merge attributes between the declarations, false to
    2591              :      set OLDDECL's attributes to those of NEWDECL (for template
    2592              :      explicit specializations that specify their own attributes
    2593              :      independent of those specified for the primary template).  */
    2594     19311012 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2595     14872903 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2596     19859947 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2597              : 
    2598     19311012 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2599              :     {
    2600     14872903 :       if (merge_attr)
    2601              :         {
    2602     14324177 :           {
    2603     14324177 :             auto_diagnostic_group d;
    2604     14324177 :             if (diagnose_mismatched_attributes (olddecl, newdecl))
    2605           36 :               inform (olddecl_loc, DECL_INITIAL (olddecl)
    2606              :                       ? G_("previous definition of %qD here")
    2607              :                       : G_("previous declaration of %qD here"), olddecl);
    2608     14324177 :           }
    2609              : 
    2610              :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2611              :              specify the noreturn attribute if any declaration of that function
    2612              :              specifies the noreturn attribute.  */
    2613     14324177 :           tree a;
    2614     14324177 :           if (TREE_THIS_VOLATILE (newdecl)
    2615        92816 :               && !TREE_THIS_VOLATILE (olddecl)
    2616              :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2617           76 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2618           54 :               && cxx11_attribute_p (a)
    2619     14324198 :               && get_attribute_namespace (a) == NULL_TREE)
    2620              :             {
    2621            9 :               auto_diagnostic_group d;
    2622            9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2623              :                         "but its first declaration was not", newdecl);
    2624            9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2625            9 :             }
    2626              :         }
    2627              : 
    2628              :       /* Now that functions must hold information normally held
    2629              :          by field decls, there is extra work to do so that
    2630              :          declaration information does not get destroyed during
    2631              :          definition.  */
    2632     14872903 :       if (DECL_VINDEX (olddecl))
    2633       153978 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2634     14872903 :       if (DECL_CONTEXT (olddecl))
    2635     14872903 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2636     14872903 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2637     14872903 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2638     14872903 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2639     14872903 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2640     14872903 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2641     14872903 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2642     14872903 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2643     14872903 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2644     14872903 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2645     14872903 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2646     14872903 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2647      2681289 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2648      5362578 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2649     14872903 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2650              : 
    2651     14872903 :       check_redecl_contract (newdecl, olddecl);
    2652              : 
    2653              :       /* Optionally warn about more than one declaration for the same
    2654              :          name, but don't warn about a function declaration followed by a
    2655              :          definition.  */
    2656           27 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2657           27 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2658              :           /* Don't warn about extern decl followed by definition.  */
    2659           27 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2660              :           /* Don't warn if at least one is/was hidden.  */
    2661           27 :           && !(hiding || was_hidden)
    2662              :           /* Don't warn about declaration followed by specialization.  */
    2663     14872915 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2664            9 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2665              :         {
    2666            6 :           auto_diagnostic_group d;
    2667            6 :           if (warning_at (newdecl_loc,
    2668            6 :                           OPT_Wredundant_decls,
    2669              :                           "redundant redeclaration of %qD in same scope",
    2670              :                           newdecl))
    2671            6 :             inform (olddecl_loc,
    2672              :                     "previous declaration of %qD", olddecl);
    2673            6 :         }
    2674              : 
    2675              :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2676              :          first declaration of the function or, for an explicit specialization
    2677              :          of a function template, the first declaration of that
    2678              :          specialization.  */
    2679     14872903 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2680       628628 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2681              :         {
    2682     14324177 :           if (DECL_DELETED_FN (newdecl))
    2683              :             {
    2684           21 :               auto_diagnostic_group d;
    2685           21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2686              :                            "is not first declaration", newdecl))
    2687           21 :                 inform (olddecl_loc,
    2688              :                         "previous declaration of %qD", olddecl);
    2689           21 :             }
    2690     14324177 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2691     14324177 :           if (DECL_DELETED_FN (olddecl)
    2692            6 :               && DECL_INITIAL (olddecl)
    2693     14324183 :               && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
    2694            3 :             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2695              :         }
    2696              :     }
    2697              : 
    2698              :   /* Deal with C++: must preserve virtual function table size.  */
    2699     19311012 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2700              :     {
    2701        46538 :       tree newtype = TREE_TYPE (newdecl);
    2702        46538 :       tree oldtype = TREE_TYPE (olddecl);
    2703              : 
    2704        46538 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2705        93076 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2706       127524 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2707        42508 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2708              : 
    2709        46538 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2710              :     }
    2711              : 
    2712              :   /* Copy all the DECL_... slots specified in the new decl except for
    2713              :      any that we copy here from the old type.  */
    2714     19311012 :   if (merge_attr)
    2715     18762286 :     DECL_ATTRIBUTES (newdecl)
    2716     37524572 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2717              :   else
    2718       548726 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2719              : 
    2720              :   /* Transfer purviewness and importingness to the old decl.  */
    2721     19311012 :   transfer_defining_module (olddecl, newdecl);
    2722              : 
    2723     19311012 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2724              :     {
    2725      3896469 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2726      3896469 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2727      3896469 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2728              : 
    2729              :       /* The new decl should not already have gathered any
    2730              :          specializations.  */
    2731      3896469 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2732              : 
    2733              :       /* Make sure the contracts are equivalent.  */
    2734      3896469 :       check_redecl_contract (newdecl, olddecl);
    2735              : 
    2736      3896469 :       DECL_ATTRIBUTES (old_result)
    2737      3896469 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2738              : 
    2739      3896469 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2740              :         {
    2741      3896439 :           if (DECL_SOURCE_LOCATION (newdecl)
    2742      3896439 :               != DECL_SOURCE_LOCATION (olddecl))
    2743              :             {
    2744              :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2745              :                  later declarations of a function template.  */
    2746      3874502 :               check_redeclaration_no_default_args (newdecl);
    2747              :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2748              :                  argument expression, that declaration... shall be the only
    2749              :                  declaration of the function or function template in the
    2750              :                  translation unit."  */
    2751      3874502 :               check_no_redeclaration_friend_default_args
    2752      3874502 :                 (old_result, new_result);
    2753              : 
    2754      3874502 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2755      3874502 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2756      3874502 :               merge_default_template_args (new_parms, old_parms,
    2757              :                                            /*class_p=*/false);
    2758              :             }
    2759      3896439 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2760      2897829 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2761              : 
    2762      3896439 :           check_default_args (newdecl);
    2763              : 
    2764      7792866 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2765      3896439 :               && DECL_INITIAL (new_result))
    2766              :             {
    2767           24 :               if (DECL_INITIAL (old_result))
    2768           12 :                 DECL_UNINLINABLE (old_result) = 1;
    2769              :               else
    2770           12 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2771           24 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2772           72 :               DECL_NOT_REALLY_EXTERN (old_result)
    2773           24 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2774           48 :               DECL_INTERFACE_KNOWN (old_result)
    2775           24 :                 = DECL_INTERFACE_KNOWN (new_result);
    2776           24 :               DECL_DECLARED_INLINE_P (old_result)
    2777           24 :                 = DECL_DECLARED_INLINE_P (new_result);
    2778           24 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2779           24 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2780              :             }
    2781              :           else
    2782              :             {
    2783      3896415 :               DECL_DECLARED_INLINE_P (old_result)
    2784      3896415 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2785      3896415 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2786      3896415 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2787      3896415 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2788              : 
    2789      3896415 :               merge_attribute_bits (new_result, old_result);
    2790              :             }
    2791              :         }
    2792              : 
    2793              :       /* If the new declaration is a definition, update the file and
    2794              :          line information on the declaration, and also make
    2795              :          the old declaration the same definition.  */
    2796      3896469 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2797              :         {
    2798      5392558 :           DECL_SOURCE_LOCATION (olddecl)
    2799      5392558 :             = DECL_SOURCE_LOCATION (old_result)
    2800      2696279 :             = DECL_SOURCE_LOCATION (newdecl);
    2801      2696279 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2802      2696279 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2803              :             {
    2804      2696279 :               update_contract_arguments (new_result, old_result);
    2805              : 
    2806      2696279 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2807      9721572 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2808      7025293 :                 DECL_CONTEXT (p) = old_result;
    2809              : 
    2810      5392558 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2811           18 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2812              :             }
    2813              :         }
    2814              : 
    2815      3896469 :       return olddecl;
    2816              :     }
    2817              : 
    2818     15414543 :   if (types_match)
    2819              :     {
    2820     15414342 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2821     14872702 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2822              : 
    2823              :       /* Automatically handles default parameters.  */
    2824     15414342 :       tree oldtype = TREE_TYPE (olddecl);
    2825     15414342 :       tree newtype;
    2826              : 
    2827              :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2828              :          at newdecl, which will be ggc_freed.  */
    2829     15414342 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2830              :         {
    2831              :           /* But NEWTYPE might have an attribute, honor that.  */
    2832        46538 :           tree tem = TREE_TYPE (newdecl);
    2833        46538 :           newtype = oldtype;
    2834              : 
    2835        46538 :           if (TYPE_USER_ALIGN (tem))
    2836              :             {
    2837           21 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2838            6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2839           21 :               TYPE_USER_ALIGN (newtype) = true;
    2840              :             }
    2841              : 
    2842              :           /* And remove the new type from the variants list.  */
    2843        46538 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2844              :             {
    2845           24 :               tree remove = TREE_TYPE (newdecl);
    2846           24 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2847              :                 {
    2848            9 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2849              :                   /* If remove is the main variant, no need to remove that
    2850              :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2851              :                      variants, e.g. created for aligned attribute, might still
    2852              :                      refer to the newdecl TYPE_DECL though, so remove that one
    2853              :                      in that case.  */
    2854            9 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2855            6 :                     if (orig != remove)
    2856            6 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2857            0 :                            t = TYPE_MAIN_VARIANT (t))
    2858            6 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2859              :                           {
    2860           12 :                             TYPE_NEXT_VARIANT (t)
    2861            6 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2862            6 :                             break;
    2863              :                           }
    2864              :                 }
    2865              :               else
    2866           15 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2867            0 :                      t = TYPE_NEXT_VARIANT (t))
    2868           15 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2869              :                     {
    2870           15 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2871           15 :                       break;
    2872              :                     }
    2873              :             }
    2874              :         }
    2875     15367804 :       else if (merge_attr)
    2876     14819078 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2877              :       else
    2878       548726 :         newtype = TREE_TYPE (newdecl);
    2879              : 
    2880     15414342 :       if (VAR_P (newdecl))
    2881              :         {
    2882       495102 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2883              :           /* For already initialized vars, TREE_READONLY could have been
    2884              :              cleared in cp_finish_decl, because the var needs runtime
    2885              :              initialization or destruction.  Make sure not to set
    2886              :              TREE_READONLY on it again.  */
    2887       495102 :           if (DECL_INITIALIZED_P (olddecl)
    2888         1217 :               && !DECL_EXTERNAL (olddecl)
    2889       495189 :               && !TREE_READONLY (olddecl))
    2890           32 :             TREE_READONLY (newdecl) = 0;
    2891       495102 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2892       990204 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2893       495102 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2894       495102 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2895       104729 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2896       990204 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2897       495102 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2898       495102 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2899       495102 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2900       990204 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2901       495102 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2902              : 
    2903              :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2904       495102 :           if (DECL_LANG_SPECIFIC (olddecl)
    2905       986606 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2906              :             {
    2907              :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2908           41 :               retrofit_lang_decl (newdecl);
    2909           41 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2910              :             }
    2911              :         }
    2912              : 
    2913              :       /* An explicit specialization of a function template or of a member
    2914              :          function of a class template can be declared transaction_safe
    2915              :          independently of whether the corresponding template entity is declared
    2916              :          transaction_safe. */
    2917         1207 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2918         1072 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2919           78 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2920           54 :           && tx_safe_fn_type_p (newtype)
    2921     15414342 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2922            0 :         newtype = tx_unsafe_fn_variant (newtype);
    2923              : 
    2924     15414342 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2925              : 
    2926     15414342 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2927     14872702 :         check_default_args (newdecl);
    2928              : 
    2929              :       /* Lay the type out, unless already done.  */
    2930     15414342 :       if (! same_type_p (newtype, oldtype)
    2931          368 :           && TREE_TYPE (newdecl) != error_mark_node
    2932     15414710 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2933          285 :         layout_type (TREE_TYPE (newdecl));
    2934              : 
    2935     15414342 :       if ((VAR_P (newdecl)
    2936     14919240 :            || TREE_CODE (newdecl) == PARM_DECL
    2937     14919240 :            || TREE_CODE (newdecl) == RESULT_DECL
    2938     14919240 :            || TREE_CODE (newdecl) == FIELD_DECL
    2939     14919240 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2940     15460880 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2941       380466 :         layout_decl (newdecl, 0);
    2942              : 
    2943              :       /* Merge deprecatedness.  */
    2944     15414342 :       if (TREE_DEPRECATED (newdecl))
    2945        11324 :         TREE_DEPRECATED (olddecl) = 1;
    2946              : 
    2947              :       /* Merge unavailability.  */
    2948     15414342 :       if (TREE_UNAVAILABLE (newdecl))
    2949            3 :         TREE_UNAVAILABLE (olddecl) = 1;
    2950              : 
    2951              :       /* Preserve function specific target and optimization options */
    2952     15414342 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2953              :         {
    2954     14872702 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2955     14872702 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2956            0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2957            0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2958              : 
    2959     14872702 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2960     14872702 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2961           55 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2962           55 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2963              : 
    2964     14872702 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2965     14359864 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2966              :         }
    2967              :       else
    2968              :         {
    2969              :           /* Merge the const type qualifier.  */
    2970       541640 :           if (TREE_READONLY (newdecl))
    2971       147839 :             TREE_READONLY (olddecl) = 1;
    2972              :           /* Merge the volatile type qualifier.  */
    2973       541640 :           if (TREE_THIS_VOLATILE (newdecl))
    2974            5 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2975              :         }
    2976              : 
    2977              :       /* Merge the initialization information.  */
    2978     15414342 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2979     15414342 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2980              :         {
    2981       179808 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2982       179808 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2983       179808 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2984              :             {
    2985        15522 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2986        15522 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2987              :             }
    2988              :         }
    2989              : 
    2990     15414342 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2991              :         {
    2992     14872702 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2993     14872702 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2994     14872702 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2995     14872702 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2996        55233 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2997     14872702 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2998     14872702 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2999     14872702 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    3000     14872702 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    3001              : 
    3002     14872702 :           if (merge_attr)
    3003     14323976 :             merge_attribute_bits (newdecl, olddecl);
    3004              :           else
    3005              :             {
    3006              :               /* Merge the noreturn bit.  */
    3007       548726 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3008       548726 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3009       548726 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3010       548726 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    3011       548726 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    3012              :             }
    3013              :           /* Keep the old RTL.  */
    3014     14872702 :           COPY_DECL_RTL (olddecl, newdecl);
    3015              :         }
    3016       541640 :       else if (VAR_P (newdecl)
    3017       541640 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    3018              :         {
    3019              :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    3020              :              declaration was for an incomplete object and the new
    3021              :              declaration is not since many attributes of the RTL will
    3022              :              change.  */
    3023       495028 :           COPY_DECL_RTL (olddecl, newdecl);
    3024              :         }
    3025              :     }
    3026              :   /* If cannot merge, then use the new type and qualifiers,
    3027              :      and don't preserve the old rtl.  */
    3028              :   else
    3029              :     {
    3030              :       /* Clean out any memory we had of the old declaration.  */
    3031          201 :       tree oldstatic = value_member (olddecl, static_aggregates);
    3032          201 :       if (oldstatic)
    3033            0 :         TREE_VALUE (oldstatic) = error_mark_node;
    3034              : 
    3035          201 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    3036          201 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    3037          201 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    3038          201 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    3039          201 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    3040              :     }
    3041              : 
    3042              :   /* Merge the storage class information.  */
    3043     15414543 :   merge_weak (newdecl, olddecl);
    3044              : 
    3045     15414543 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    3046     15414543 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    3047     15414543 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    3048     15414543 :   if (! DECL_EXTERNAL (olddecl))
    3049        51196 :     DECL_EXTERNAL (newdecl) = 0;
    3050     15414543 :   if (! DECL_COMDAT (olddecl))
    3051      6579178 :     DECL_COMDAT (newdecl) = 0;
    3052              : 
    3053     15414543 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    3054              :     {
    3055           78 :       if (!DECL_LOCAL_DECL_P (olddecl))
    3056              :         /* This can happen if olddecl was brought in from the
    3057              :            enclosing namespace via a using-decl.  The new decl is
    3058              :            then not a block-scope extern at all.  */
    3059            3 :         DECL_LOCAL_DECL_P (newdecl) = false;
    3060              :       else
    3061              :         {
    3062           75 :           retrofit_lang_decl (newdecl);
    3063           75 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    3064           75 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    3065           75 :           if (alias != error_mark_node)
    3066              :             {
    3067           72 :               DECL_ATTRIBUTES (alias)
    3068           72 :                 = (*targetm.merge_decl_attributes) (alias, newdecl);
    3069           72 :               if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3070           42 :                 merge_attribute_bits (newdecl, alias);
    3071              :             }
    3072              :         }
    3073              :     }
    3074              : 
    3075     15414543 :   new_template_info = NULL_TREE;
    3076     15414543 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    3077              :     {
    3078     15364425 :       bool new_redefines_gnu_inline = false;
    3079              : 
    3080     15364425 :       if (new_defines_function
    3081     15364425 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    3082         1250 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    3083      9025143 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    3084            0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    3085              :                       == FUNCTION_DECL))))
    3086         2500 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    3087              : 
    3088              :       if (!new_redefines_gnu_inline)
    3089              :         {
    3090     15364347 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    3091     15364347 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    3092     15364347 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    3093              :         }
    3094              : 
    3095     15364425 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    3096              :         {
    3097     15364361 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    3098     15364361 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    3099     15364361 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    3100              : 
    3101              :           /* If the OLDDECL is an instantiation and/or specialization,
    3102              :              then the NEWDECL must be too.  But, it may not yet be marked
    3103              :              as such if the caller has created NEWDECL, but has not yet
    3104              :              figured out that it is a redeclaration.  */
    3105     15364361 :           if (!DECL_USE_TEMPLATE (newdecl))
    3106     14735515 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    3107              : 
    3108     15364361 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3109     14815407 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    3110     29630814 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    3111              :         }
    3112              : 
    3113              :       /* Don't really know how much of the language-specific
    3114              :          values we should copy from old to new.  */
    3115     15364425 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    3116              : 
    3117     15364425 :       if (LANG_DECL_HAS_MIN (newdecl))
    3118              :         {
    3119     15364425 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    3120     15364425 :           if (DECL_TEMPLATE_INFO (newdecl))
    3121              :             {
    3122       628879 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    3123       628879 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3124       628879 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    3125              :                 /* Remember the presence of explicit specialization args.  */
    3126      1097458 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    3127      1097458 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    3128              :             }
    3129              : 
    3130              :           /* We don't want to copy template info from a non-templated friend
    3131              :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    3132     15364425 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    3133              :                                || !non_templated_friend_p (olddecl));
    3134     15364425 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    3135              :         }
    3136              : 
    3137     15364425 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    3138              :         {
    3139              :           /* Only functions have these fields.  */
    3140     14872903 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    3141     14872903 :           DECL_BEFRIENDING_CLASSES (newdecl)
    3142     14872903 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    3143     14872903 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    3144              :           /* DECL_THUNKS is only valid for virtual functions,
    3145              :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    3146     14872903 :           if (DECL_VIRTUAL_P (newdecl))
    3147       612922 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    3148     28519962 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    3149       369110 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    3150              :         }
    3151       491522 :       else if (VAR_P (newdecl))
    3152              :         {
    3153              :           /* Only variables have this field.  */
    3154       491458 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    3155          198 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    3156              :         }
    3157              :     }
    3158              : 
    3159     15414543 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3160              :     {
    3161     14872903 :       merge_decl_arguments (newdecl, olddecl, new_defines_function,
    3162              :                             types_match, false);
    3163              : 
    3164     14872903 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    3165     14872903 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    3166              :         {
    3167              :           /* If newdecl is not a specialization, then it is not a
    3168              :              template-related function at all.  And that means that we
    3169              :              should have exited above, returning 0.  */
    3170       548726 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    3171              : 
    3172       548726 :           if (DECL_ODR_USED (olddecl))
    3173              :             /* From [temp.expl.spec]:
    3174              : 
    3175              :                If a template, a member template or the member of a class
    3176              :                template is explicitly specialized then that
    3177              :                specialization shall be declared before the first use of
    3178              :                that specialization that would cause an implicit
    3179              :                instantiation to take place, in every translation unit in
    3180              :                which such a use occurs.  */
    3181            0 :             error ("explicit specialization of %qD after first use",
    3182              :                       olddecl);
    3183              : 
    3184       548726 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    3185       548726 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    3186      1097299 :                                    && DECL_NONGNU_INLINE_P (newdecl));
    3187              : 
    3188              :           /* Don't propagate visibility from the template to the
    3189              :              specialization here.  We'll do that in determine_visibility if
    3190              :              appropriate.  */
    3191       548726 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    3192              : 
    3193              :           /* [temp.expl.spec/14] We don't inline explicit specialization
    3194              :              just because the primary template says so.  */
    3195       548726 :           gcc_assert (!merge_attr);
    3196              : 
    3197       548726 :           DECL_DECLARED_INLINE_P (olddecl)
    3198       548726 :             = DECL_DECLARED_INLINE_P (newdecl);
    3199              : 
    3200       548726 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3201       548726 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    3202              : 
    3203       548726 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    3204              :         }
    3205     14324177 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    3206              :         {
    3207              :           /* Never inline re-defined extern inline functions.
    3208              :              FIXME: this could be better handled by keeping both
    3209              :              function as separate declarations.  */
    3210           78 :           DECL_UNINLINABLE (newdecl) = 1;
    3211              :         }
    3212              :       else
    3213              :         {
    3214     14324099 :           if (DECL_PENDING_INLINE_P (olddecl))
    3215              :             {
    3216            6 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    3217            6 :               DECL_PENDING_INLINE_INFO (newdecl)
    3218           12 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    3219              :             }
    3220     14324093 :           else if (DECL_PENDING_INLINE_P (newdecl))
    3221              :             ;
    3222     14324093 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    3223     14324093 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    3224     28648186 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    3225              : 
    3226     14324099 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    3227              : 
    3228     42972297 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    3229     28648198 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    3230              : 
    3231     28648198 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3232     14324099 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    3233     14324099 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    3234     28251191 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    3235              :         }
    3236              : 
    3237              :       /* Preserve abstractness on cloned [cd]tors.  */
    3238     14872903 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    3239              : 
    3240              :       /* Update newdecl's parms to point at olddecl.  */
    3241     47302694 :       for (tree parm = DECL_ARGUMENTS (newdecl); parm;
    3242     32429791 :            parm = DECL_CHAIN (parm))
    3243     32429791 :         DECL_CONTEXT (parm) = olddecl;
    3244              : 
    3245     14872903 :       if (! types_match)
    3246              :         {
    3247          201 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    3248          201 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    3249          201 :           COPY_DECL_RTL (newdecl, olddecl);
    3250              :         }
    3251     14872903 :       if (! types_match || new_defines_function)
    3252              :         {
    3253              :           /* Update the contracts to reflect the new parameter names. */
    3254      9026594 :           update_contract_arguments (newdecl, olddecl);
    3255              : 
    3256              :           /* Mark the old PARM_DECLs in case std::meta::parameters_of has
    3257              :              been called on the old declaration and reflections of those
    3258              :              arguments are held across this point and used later.
    3259              :              Such PARM_DECLs are no longer present in
    3260              :              DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain.  */
    3261      9026594 :           for (tree oldarg = DECL_ARGUMENTS (olddecl);
    3262     31655327 :                oldarg; oldarg = DECL_CHAIN (oldarg))
    3263     22628733 :             OLD_PARM_DECL_P (oldarg) = 1;
    3264              : 
    3265              :           /* These need to be copied so that the names are available.
    3266              :              Note that if the types do match, we'll preserve inline
    3267              :              info and other bits, but if not, we won't.  */
    3268      9026594 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    3269      9026594 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    3270              :         }
    3271              :       /* If redeclaring a builtin function, it stays built in
    3272              :          if newdecl is a gnu_inline definition, or if newdecl is just
    3273              :          a declaration.  */
    3274     14872903 :       if (fndecl_built_in_p (olddecl)
    3275     14927990 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    3276              :         {
    3277      3912933 :           copy_decl_built_in_function (newdecl, olddecl);
    3278              :           /* If we're keeping the built-in definition, keep the rtl,
    3279              :              regardless of declaration matches.  */
    3280      3912933 :           COPY_DECL_RTL (olddecl, newdecl);
    3281      3912933 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    3282              :             {
    3283      3912927 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    3284      3912927 :               if (builtin_decl_explicit_p (fncode))
    3285              :                 {
    3286              :                   /* A compatible prototype of these builtin functions
    3287              :                      is seen, assume the runtime implements it with
    3288              :                      the expected semantics.  */
    3289      3912927 :                   switch (fncode)
    3290              :                     {
    3291         9741 :                     case BUILT_IN_STPCPY:
    3292         9741 :                       set_builtin_decl_implicit_p (fncode, true);
    3293         9741 :                       break;
    3294      3903186 :                     default:
    3295      3903186 :                       set_builtin_decl_declared_p (fncode, true);
    3296      3903186 :                       break;
    3297              :                     }
    3298              :                 }
    3299              : 
    3300      3912927 :               copy_attributes_to_builtin (newdecl);
    3301              :             }
    3302              :         }
    3303     14872903 :       if (new_defines_function)
    3304              :         /* If defining a function declared with other language
    3305              :            linkage, use the previously declared language linkage.  */
    3306      9026393 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    3307      5846510 :       else if (types_match)
    3308              :         {
    3309      5846309 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    3310              :           /* Don't clear out the arguments if we're just redeclaring a
    3311              :              function.  */
    3312      5846309 :           if (DECL_ARGUMENTS (olddecl))
    3313      1897574 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    3314              :         }
    3315              :     }
    3316       541640 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    3317            0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    3318              : 
    3319              :   /* Now preserve various other info from the definition.  */
    3320     15414543 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    3321     15414543 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    3322     15414543 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    3323     15414543 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    3324              : 
    3325              :   /* Warn about conflicting visibility specifications.  */
    3326     15414543 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    3327      5442350 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    3328     15426015 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    3329              :     {
    3330           12 :       auto_diagnostic_group d;
    3331           12 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    3332              :                       "%qD: visibility attribute ignored because it "
    3333              :                       "conflicts with previous declaration", newdecl))
    3334           12 :         inform (olddecl_loc,
    3335              :                 "previous declaration of %qD", olddecl);
    3336           12 :     }
    3337              :   /* Choose the declaration which specified visibility.  */
    3338     15414543 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    3339              :     {
    3340      5442350 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    3341      5442350 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    3342              :     }
    3343              :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3344              :      so keep this behavior.  */
    3345     15414543 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3346              :     {
    3347           10 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3348           10 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3349              :     }
    3350              :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3351     15414543 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3352              :     {
    3353           54 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3354           54 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3355              :     }
    3356     15414489 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3357     15414489 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3358            3 :     DECL_USER_ALIGN (newdecl) = 1;
    3359              : 
    3360     15414543 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3361     30829086 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3362     15414543 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3363            0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3364              :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3365     15414543 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3366            0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3367              : 
    3368              :   /* Merge module entity mapping information.  */
    3369     15414543 :   if (DECL_LANG_SPECIFIC (olddecl)
    3370     30779014 :       && (DECL_MODULE_ENTITY_P (olddecl)
    3371     15364138 :           || DECL_MODULE_KEYED_DECLS_P (olddecl)))
    3372              :     {
    3373          333 :       retrofit_lang_decl (newdecl);
    3374          333 :       DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
    3375          333 :       DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
    3376              :     }
    3377              : 
    3378              :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3379              :      with that from NEWDECL below.  */
    3380     15414543 :   if (DECL_LANG_SPECIFIC (olddecl))
    3381              :     {
    3382     15364471 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3383              :                            != DECL_LANG_SPECIFIC (newdecl));
    3384     15364471 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3385              :     }
    3386              : 
    3387              :   /* Merge the USED information.  */
    3388     15414543 :   if (TREE_USED (olddecl))
    3389       487544 :     TREE_USED (newdecl) = 1;
    3390     14926999 :   else if (TREE_USED (newdecl))
    3391           62 :     TREE_USED (olddecl) = 1;
    3392              : 
    3393     15414543 :   if (VAR_P (newdecl))
    3394              :     {
    3395       495102 :       if (DECL_READ_P (olddecl))
    3396        42454 :         DECL_READ_P (newdecl) = 1;
    3397       452648 :       else if (DECL_READ_P (newdecl))
    3398            3 :         DECL_READ_P (olddecl) = 1;
    3399              :     }
    3400              : 
    3401     15414543 :   if (DECL_PRESERVE_P (olddecl))
    3402           48 :     DECL_PRESERVE_P (newdecl) = 1;
    3403     15414495 :   else if (DECL_PRESERVE_P (newdecl))
    3404           75 :     DECL_PRESERVE_P (olddecl) = 1;
    3405              : 
    3406              :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3407              :      to olddecl and deleted.  */
    3408     15414543 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3409     30287446 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3410              :     {
    3411              :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3412          258 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3413              :       /* newdecl will be purged after copying to olddecl and is no longer
    3414              :          a version.  */
    3415          258 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3416              :     }
    3417              : 
    3418     15414543 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3419              :     {
    3420     14872903 :       int function_size;
    3421     14872903 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3422              : 
    3423     14872903 :       function_size = sizeof (struct tree_decl_common);
    3424              : 
    3425     14872903 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3426              :               (char *) newdecl + sizeof (struct tree_common),
    3427              :               function_size - sizeof (struct tree_common));
    3428              : 
    3429     14872903 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3430              :               (char *) newdecl + sizeof (struct tree_decl_common),
    3431              :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3432              : 
    3433              :       /* Preserve symtab node mapping.  */
    3434     14872903 :       olddecl->decl_with_vis.symtab_node = snode;
    3435              : 
    3436     14872903 :       if (new_template_info)
    3437              :         /* If newdecl is a template instantiation, it is possible that
    3438              :            the following sequence of events has occurred:
    3439              : 
    3440              :            o A friend function was declared in a class template.  The
    3441              :            class template was instantiated.
    3442              : 
    3443              :            o The instantiation of the friend declaration was
    3444              :            recorded on the instantiation list, and is newdecl.
    3445              : 
    3446              :            o Later, however, instantiate_class_template called pushdecl
    3447              :            on the newdecl to perform name injection.  But, pushdecl in
    3448              :            turn called duplicate_decls when it discovered that another
    3449              :            declaration of a global function with the same name already
    3450              :            existed.
    3451              : 
    3452              :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3453              : 
    3454              :            If we're going to do that, we'd better make sure that
    3455              :            olddecl, and not newdecl, is on the list of
    3456              :            instantiations so that if we try to do the instantiation
    3457              :            again we won't get the clobbered declaration.  */
    3458       628870 :         reregister_specialization (newdecl,
    3459              :                                    new_template_info,
    3460              :                                    olddecl);
    3461              :     }
    3462              :   else
    3463              :     {
    3464       541640 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3465              : 
    3466       541640 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3467              :               (char *) newdecl + sizeof (struct tree_common),
    3468              :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3469              : 
    3470       541640 :       switch (TREE_CODE (newdecl))
    3471              :         {
    3472       541640 :         case LABEL_DECL:
    3473       541640 :         case VAR_DECL:
    3474       541640 :         case RESULT_DECL:
    3475       541640 :         case PARM_DECL:
    3476       541640 :         case FIELD_DECL:
    3477       541640 :         case TYPE_DECL:
    3478       541640 :         case CONST_DECL:
    3479       541640 :           {
    3480       541640 :             struct symtab_node *snode = NULL;
    3481              : 
    3482       541640 :             if (VAR_P (newdecl)
    3483       541640 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3484            3 :                     || DECL_EXTERNAL (olddecl)))
    3485       495102 :               snode = symtab_node::get (olddecl);
    3486       541640 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3487              :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3488              :                     size - sizeof (struct tree_decl_common)
    3489       541640 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3490       541640 :             if (VAR_P (newdecl))
    3491       495102 :               olddecl->decl_with_vis.symtab_node = snode;
    3492              :           }
    3493              :           break;
    3494            0 :         default:
    3495            0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3496              :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3497              :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3498            0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3499            0 :           break;
    3500              :         }
    3501              :     }
    3502              : 
    3503     15414543 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3504              :     {
    3505     15368005 :       if (DECL_EXTERNAL (olddecl)
    3506       496479 :           || TREE_PUBLIC (olddecl)
    3507     15368074 :           || TREE_STATIC (olddecl))
    3508              :         {
    3509              :           /* Merge the section attribute.
    3510              :              We want to issue an error if the sections conflict but that must be
    3511              :              done later in decl_attributes since we are called before attributes
    3512              :              are assigned.  */
    3513     15368005 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3514            7 :             set_decl_section_name (olddecl, newdecl);
    3515              : 
    3516     15368005 :           if (DECL_ONE_ONLY (newdecl))
    3517              :             {
    3518            0 :               struct symtab_node *oldsym, *newsym;
    3519            0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3520            0 :                 oldsym = cgraph_node::get_create (olddecl);
    3521              :               else
    3522            0 :                 oldsym = varpool_node::get_create (olddecl);
    3523            0 :               newsym = symtab_node::get (newdecl);
    3524            0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3525              :             }
    3526              :         }
    3527              : 
    3528     15368005 :       if (VAR_P (newdecl)
    3529     15368005 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3530              :         {
    3531          404 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3532          404 :           if (!processing_template_decl)
    3533          371 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3534              :         }
    3535              :     }
    3536              : 
    3537     15414543 :   DECL_UID (olddecl) = olddecl_uid;
    3538              : 
    3539              :   /* NEWDECL contains the merged attribute lists.
    3540              :      Update OLDDECL to be the same.  */
    3541     15414543 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3542              : 
    3543              :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3544              :     so that encode_section_info has a chance to look at the new decl
    3545              :     flags and attributes.  */
    3546     15414543 :   if (DECL_RTL_SET_P (olddecl)
    3547     15414558 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3548           15 :           || (VAR_P (olddecl)
    3549           15 :               && TREE_STATIC (olddecl))))
    3550           15 :     make_decl_rtl (olddecl);
    3551              : 
    3552              :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3553              :      declaration of a member results in a call to duplicate_decls,
    3554              :      freeing these nodes represents in a significant savings.
    3555              : 
    3556              :      Before releasing the node, be sore to remove function from symbol
    3557              :      table that might have been inserted there to record comdat group.
    3558              :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3559              :      structure is shared in between newdecl and oldecl.  */
    3560     15414543 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3561     14872903 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3562     15414543 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3563              :     {
    3564     15368005 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3565     15368005 :       if (snode)
    3566          399 :         snode->remove ();
    3567              :     }
    3568              : 
    3569     15414543 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3570              :     {
    3571     14872903 :       tree clone;
    3572     15398652 :       FOR_EACH_CLONE (clone, olddecl)
    3573              :         {
    3574       525749 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3575       525749 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3576              :         }
    3577              :     }
    3578              : 
    3579              :   /* Remove the associated constraints for newdecl, if any, before
    3580              :      reclaiming memory. */
    3581     15414543 :   if (flag_concepts)
    3582     15149625 :     remove_constraints (newdecl);
    3583              : 
    3584     15414543 :   if (flag_contracts)
    3585              :     /* Remove the specifiers, and then remove the decl from the lookup.  */
    3586      1089047 :     remove_decl_with_fn_contracts_specifiers (newdecl);
    3587              : 
    3588              :   /* And similarly for any module tracking data.  */
    3589     15414543 :   if (modules_p ())
    3590        43460 :     remove_defining_module (newdecl);
    3591              : 
    3592     15414543 :   ggc_free (newdecl);
    3593              : 
    3594     15414543 :   return olddecl;
    3595              : }
    3596              : 
    3597              : /* Return zero if the declaration NEWDECL is valid
    3598              :    when the declaration OLDDECL (assumed to be for the same name)
    3599              :    has already been seen.
    3600              :    Otherwise return an error message format string with a %s
    3601              :    where the identifier should go.  */
    3602              : 
    3603              : static const char *
    3604     15513235 : redeclaration_error_message (tree newdecl, tree olddecl)
    3605              : {
    3606     15513271 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3607              :     {
    3608              :       /* Because C++ can put things into name space for free,
    3609              :          constructs like "typedef struct foo { ... } foo"
    3610              :          would look like an erroneous redeclaration.  */
    3611        78770 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3612              :         return NULL;
    3613              :       else
    3614              :         return G_("redefinition of %q#D");
    3615              :     }
    3616     15434501 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3617              :     {
    3618              :       /* If this is a pure function, its olddecl will actually be
    3619              :          the original initialization to `0' (which we force to call
    3620              :          abort()).  Don't complain about redefinition in this case.  */
    3621     22085056 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3622     11042546 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3623              :         return NULL;
    3624              : 
    3625              :       /* If both functions come from different namespaces, this is not
    3626              :          a redeclaration - this is a conflict with a used function.  */
    3627     22085026 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3628      2596557 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3629     11042516 :           && ! decls_match (olddecl, newdecl))
    3630              :         return G_("%qD conflicts with used function");
    3631              : 
    3632              :       /* We'll complain about linkage mismatches in
    3633              :          warn_extern_redeclared_static.  */
    3634              : 
    3635              :       /* Defining the same name twice is no good.  */
    3636     11042513 :       if (decl_defined_p (olddecl)
    3637     11042513 :           && decl_defined_p (newdecl))
    3638              :         {
    3639          306 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3640              :             return G_("%q#D not declared in class");
    3641          447 :           else if (!GNU_INLINE_P (olddecl)
    3642          393 :                    || GNU_INLINE_P (newdecl))
    3643          222 :             return G_("redefinition of %q#D");
    3644              :         }
    3645              : 
    3646     12789681 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3647              :         {
    3648      1698994 :           bool olda = GNU_INLINE_P (olddecl);
    3649      1698994 :           bool newa = GNU_INLINE_P (newdecl);
    3650              : 
    3651      1698994 :           if (olda != newa)
    3652              :             {
    3653           15 :               if (newa)
    3654              :                 return G_("%q+D redeclared inline with "
    3655              :                           "%<gnu_inline%> attribute");
    3656              :               else
    3657              :                 return G_("%q+D redeclared inline without "
    3658              :                           "%<gnu_inline%> attribute");
    3659              :             }
    3660              :         }
    3661              : 
    3662              :       /* [class.compare.default]: A definition of a comparison operator as
    3663              :          defaulted that appears in a class shall be the first declaration of
    3664              :          that function.  */
    3665     11042276 :       special_function_kind sfk = special_function_p (olddecl);
    3666     11042276 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3667              :         return G_("comparison operator %q+D defaulted after "
    3668              :                   "its first declaration");
    3669              : 
    3670     11042273 :       check_abi_tag_redeclaration
    3671     11042273 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3672     11042273 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3673              : 
    3674     11042273 :       return NULL;
    3675              :     }
    3676      4391973 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3677              :     {
    3678      3896508 :       tree nt, ot;
    3679              : 
    3680      3896508 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3681              :         return G_("redefinition of %q#D");
    3682              : 
    3683      3896502 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3684           36 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3685           36 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3686              : 
    3687      3896466 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3688              :         return NULL;
    3689              : 
    3690      3896454 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3691      3896454 :       if (DECL_TEMPLATE_INFO (nt))
    3692       888384 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3693      3896454 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3694      3896454 :       if (DECL_TEMPLATE_INFO (ot))
    3695      3896454 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3696      6592787 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3697      3896493 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3698           15 :         return G_("redefinition of %q#D");
    3699              : 
    3700      6292018 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3701              :         {
    3702      1748890 :           bool olda = GNU_INLINE_P (ot);
    3703      1748890 :           bool newa = GNU_INLINE_P (nt);
    3704              : 
    3705      1748890 :           if (olda != newa)
    3706              :             {
    3707            0 :               if (newa)
    3708              :                 return G_("%q+D redeclared inline with "
    3709              :                           "%<gnu_inline%> attribute");
    3710              :               else
    3711              :                 return G_("%q+D redeclared inline without "
    3712              :                           "%<gnu_inline%> attribute");
    3713              :             }
    3714              :         }
    3715              : 
    3716              :       /* Core issue #226 (C++11):
    3717              : 
    3718              :            If a friend function template declaration specifies a
    3719              :            default template-argument, that declaration shall be a
    3720              :            definition and shall be the only declaration of the
    3721              :            function template in the translation unit.  */
    3722      3896439 :       if ((cxx_dialect != cxx98)
    3723      3880298 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3724      4098425 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3725              :                                        /*is_primary=*/true,
    3726              :                                        /*is_partial=*/false,
    3727              :                                        /*is_friend_decl=*/2))
    3728              :         return G_("redeclaration of friend %q#D "
    3729              :                   "may not have default template arguments");
    3730              : 
    3731      3896436 :       return NULL;
    3732              :     }
    3733       495465 :   else if (VAR_P (newdecl)
    3734       495381 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3735       495381 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3736       495512 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3737           44 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3738           41 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3739              :     {
    3740              :       /* Only variables can be thread-local, and all declarations must
    3741              :          agree on this property.  */
    3742            6 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3743              :         return G_("thread-local declaration of %q#D follows "
    3744              :                   "non-thread-local declaration");
    3745              :       else
    3746            3 :         return G_("non-thread-local declaration of %q#D follows "
    3747              :                   "thread-local declaration");
    3748              :     }
    3749       495459 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3750              :     {
    3751              :       /* The objects have been declared at namespace scope.  If either
    3752              :          is a member of an anonymous union, then this is an invalid
    3753              :          redeclaration.  For example:
    3754              : 
    3755              :            int i;
    3756              :            union { int i; };
    3757              : 
    3758              :            is invalid.  */
    3759       495225 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3760       990519 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3761              :         return G_("redeclaration of %q#D");
    3762              :       /* If at least one declaration is a reference, there is no
    3763              :          conflict.  For example:
    3764              : 
    3765              :            int i = 3;
    3766              :            extern int i;
    3767              : 
    3768              :          is valid.  */
    3769       495291 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3770              :         return NULL;
    3771              : 
    3772              :       /* Static data member declared outside a class definition
    3773              :          if the variable is defined within the class with constexpr
    3774              :          specifier is declaration rather than definition (and
    3775              :          deprecated).  */
    3776         2820 :       if (cxx_dialect >= cxx17
    3777         2747 :           && VAR_P (olddecl)
    3778         2691 :           && DECL_CLASS_SCOPE_P (olddecl)
    3779         2649 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3780         5457 :           && !DECL_INITIAL (newdecl))
    3781              :         {
    3782         2637 :           DECL_EXTERNAL (newdecl) = 1;
    3783              :           /* For now, only warn with explicit -Wdeprecated.  */
    3784         2637 :           if (OPTION_SET_P (warn_deprecated))
    3785              :             {
    3786           40 :               auto_diagnostic_group d;
    3787           40 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3788              :                                 "redundant redeclaration of %<constexpr%> "
    3789              :                                 "static data member %qD", newdecl))
    3790            4 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3791              :                           "previous declaration of %qD", olddecl);
    3792           40 :             }
    3793         2637 :           return NULL;
    3794              :         }
    3795              : 
    3796              :       /* Reject two definitions.  */
    3797              :       return G_("redefinition of %q#D");
    3798              :     }
    3799              :   else
    3800              :     {
    3801              :       /* Objects declared with block scope:  */
    3802              :       /* Reject two definitions, and reject a definition
    3803              :          together with an external reference.  */
    3804          153 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3805              :         return G_("redeclaration of %q#D");
    3806              :       return NULL;
    3807              :     }
    3808              : }
    3809              : 
    3810              : 
    3811              : /* Hash and equality functions for the named_label table.  */
    3812              : 
    3813              : hashval_t
    3814        78971 : named_label_hash::hash (const value_type entry)
    3815              : {
    3816        78971 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3817              : }
    3818              : 
    3819              : bool
    3820        75922 : named_label_hash::equal (const value_type entry, compare_type name)
    3821              : {
    3822        75922 :   return name == entry->name;
    3823              : }
    3824              : 
    3825              : /* Look for a label named ID in the current function.  If one cannot
    3826              :    be found, create one.  Return the named_label_entry, or NULL on
    3827              :    failure.  */
    3828              : 
    3829              : static named_label_entry *
    3830        24248 : lookup_label_1 (tree id, bool making_local_p)
    3831              : {
    3832        24248 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3833              : 
    3834              :   /* You can't use labels at global scope.  */
    3835        24248 :   if (current_function_decl == NULL_TREE)
    3836              :     {
    3837            3 :       error ("label %qE referenced outside of any function", id);
    3838            3 :       return NULL;
    3839              :     }
    3840              : 
    3841        24245 :   if (!named_labels)
    3842         4676 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3843              : 
    3844        24245 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3845        24245 :   named_label_entry **slot
    3846        24245 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3847        24245 :   named_label_entry *old = *slot;
    3848              : 
    3849        24245 :   if (old && old->label_decl)
    3850              :     {
    3851         3461 :       if (!making_local_p)
    3852              :         return old;
    3853              : 
    3854           21 :       if (old->binding_level == current_binding_level)
    3855              :         {
    3856            0 :           auto_diagnostic_group d;
    3857            0 :           error ("local label %qE conflicts with existing label", id);
    3858            0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3859            0 :           return NULL;
    3860            0 :         }
    3861              :     }
    3862              : 
    3863              :   /* We are making a new decl, create or reuse the named_label_entry  */
    3864        20826 :   named_label_entry *ent = NULL;
    3865           33 :   if (old && !old->label_decl)
    3866              :     ent = old;
    3867              :   else
    3868              :     {
    3869        20793 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3870        20793 :       ent->name = id;
    3871        20793 :       ent->outer = old;
    3872        20793 :       *slot = ent;
    3873              :     }
    3874              : 
    3875              :   /* Now create the LABEL_DECL.  */
    3876        20805 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3877              : 
    3878        20805 :   DECL_CONTEXT (decl) = current_function_decl;
    3879        20805 :   SET_DECL_MODE (decl, VOIDmode);
    3880        20805 :   if (making_local_p)
    3881              :     {
    3882          219 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3883          219 :       DECL_CHAIN (decl) = current_binding_level->names;
    3884          219 :       current_binding_level->names = decl;
    3885              :     }
    3886              : 
    3887        20805 :   ent->label_decl = decl;
    3888              : 
    3889        20805 :   return ent;
    3890        24248 : }
    3891              : 
    3892              : /* Wrapper for lookup_label_1.  */
    3893              : 
    3894              : tree
    3895         2955 : lookup_label (tree id)
    3896              : {
    3897         2955 :   named_label_entry *ent = lookup_label_1 (id, false);
    3898         2955 :   return ent ? ent->label_decl : NULL_TREE;
    3899              : }
    3900              : 
    3901              : /* Remember that we've seen &&ID.  */
    3902              : 
    3903              : void
    3904          253 : mark_label_addressed (tree id)
    3905              : {
    3906          253 :   named_label_entry *ent = lookup_label_1 (id, false);
    3907          253 :   ent->addressed = true;
    3908          253 : }
    3909              : 
    3910              : tree
    3911          219 : declare_local_label (tree id)
    3912              : {
    3913          219 :   named_label_entry *ent = lookup_label_1 (id, true);
    3914          219 :   return ent ? ent->label_decl : NULL_TREE;
    3915              : }
    3916              : 
    3917              : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3918              : 
    3919              : static bool
    3920        85099 : decl_jump_unsafe (tree decl)
    3921              : {
    3922              :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3923              :      with automatic storage duration is not in scope to a point where it is
    3924              :      in scope is ill-formed unless the variable has scalar type, class type
    3925              :      with a trivial default constructor and a trivial destructor, a
    3926              :      cv-qualified version of one of these types, or an array of one of the
    3927              :      preceding types and is declared without an initializer (8.5).  */
    3928        85099 :   tree type = TREE_TYPE (decl);
    3929              : 
    3930        85099 :   return (type != error_mark_node
    3931        85081 :           && VAR_P (decl)
    3932        15049 :           && !TREE_STATIC (decl)
    3933       100012 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3934        12992 :               || variably_modified_type_p (type, NULL_TREE)));
    3935              : }
    3936              : 
    3937              : /* Returns true if decl is an automatic variable with vacuous initialization
    3938              :    except when it is [[indeterminate]] or [[gnu::uninitialized]].
    3939              :    Jumps across such initialization need to be instrumented for
    3940              :    !!flag_auto_var_init.  */
    3941              : 
    3942              : static bool
    3943        83169 : decl_instrument_init_bypass_p (tree decl)
    3944              : {
    3945        83169 :   tree type = TREE_TYPE (decl);
    3946              : 
    3947        83169 :   return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    3948         5941 :           && !processing_template_decl
    3949         5695 :           && type != error_mark_node
    3950         5689 :           && VAR_P (decl)
    3951         1070 :           && !TREE_STATIC (decl)
    3952         1049 :           && !DECL_EXTERNAL (decl)
    3953         2070 :           && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3954         1035 :                || variably_modified_type_p (type, NULL_TREE))
    3955         1035 :           && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
    3956         1035 :           && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
    3957        84204 :           && !DECL_HAS_VALUE_EXPR_P (decl));
    3958              : }
    3959              : 
    3960              : /* Build .DEFERRED_INIT call for DECL.  */
    3961              : 
    3962              : static tree
    3963          140 : build_deferred_init_call (tree decl)
    3964              : {
    3965          140 :   tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
    3966          280 :   tree init_type_arg = build_int_cst (integer_type_node,
    3967          140 :                                       (int) flag_auto_var_init);
    3968          140 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    3969          140 :   tree decl_name;
    3970              : 
    3971          140 :   if (DECL_NAME (decl))
    3972          140 :     decl_name = build_string_literal (DECL_NAME (decl));
    3973              :   else
    3974              :     {
    3975            0 :       char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
    3976            0 :       sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
    3977            0 :       decl_name = build_string_literal (decl_name_anonymous);
    3978              :     }
    3979              : 
    3980          140 :   tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
    3981          140 :                                             TREE_TYPE (decl), 3,
    3982              :                                             decl_size_arg, init_type_arg,
    3983              :                                             decl_name);
    3984          140 :   tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
    3985          140 :   return build_stmt (loc, EXPR_STMT, ret);
    3986              : }
    3987              : 
    3988              : /* Emit before ITER (and any labels/case labels before it) code like
    3989              :    if (0)
    3990              :      {
    3991              :        l1:
    3992              :         v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
    3993              :         v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
    3994              :         v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
    3995              :         v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
    3996              :      }
    3997              :    and return l1 label, or if it already exists, assert it has the
    3998              :    .DEFERRED_INIT calls for the right decls in the right order and
    3999              :    amend it, either by adding extra labels in between or further
    4000              :    ,DEFERRED_INIT calls before the first label and extra label before
    4001              :    that.  If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
    4002              :    of adding a label.  DECLS points to an array of NDECLS VAR_DECLs
    4003              :    which should be initialized.  */
    4004              : 
    4005              : static tree
    4006          127 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
    4007              :                                tree *decls, unsigned ndecls)
    4008              : {
    4009          127 :   tree lab = NULL_TREE;
    4010          191 :   for (; !tsi_end_p (iter); tsi_prev (&iter))
    4011              :     {
    4012          185 :       switch (TREE_CODE (tsi_stmt (iter)))
    4013              :         {
    4014           64 :         case LABEL_EXPR:
    4015           64 :         case CASE_LABEL_EXPR:
    4016           64 :         case DEBUG_BEGIN_STMT:
    4017           64 :           continue;
    4018              :         default:
    4019              :           break;
    4020              :         }
    4021              :       break;
    4022              :     }
    4023          127 :   if (!tsi_end_p (iter)
    4024          121 :       && TREE_CODE (tsi_stmt (iter)) == IF_STMT
    4025          204 :       && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
    4026              :     {
    4027              :       /* Found IF_STMT added for this or some adjacent
    4028              :          LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
    4029              :          The decls are ordered so that we can always reuse it.  Sometimes
    4030              :          by no modifications at all and just returning the right label
    4031              :          which was added already before, sometimes by adding a label in
    4032              :          between two previously added .DEFERRED_INIT calls and sometimes
    4033              :          by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
    4034              :          before that) before the statements in IF_STMT body.  */
    4035           71 :       tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
    4036           71 :       iter = tsi_last (then_clause);
    4037           71 :       bool add = false;
    4038          381 :       for (unsigned int i = 0; i < ndecls; ++i)
    4039              :         {
    4040          310 :           tree decl = decls[i];
    4041          310 :           if (!add)
    4042              :             {
    4043              :               /* Skip over labels/case labels after .DEFERRED_INIT for the
    4044              :                  DECL we are looking for.  */
    4045          399 :               while (!tsi_end_p (iter)
    4046          399 :                      && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
    4047          286 :                          || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
    4048           26 :                              && !case_label)))
    4049          119 :                 tsi_prev (&iter);
    4050          280 :               if (tsi_end_p (iter))
    4051              :                 {
    4052              :                   /* Reached the start, we'll need to prepend further
    4053              :                      statements.  */
    4054           20 :                   add = true;
    4055           20 :                   iter = tsi_start (then_clause);
    4056              :                 }
    4057              :               else
    4058              :                 {
    4059              :                   /* Found something, assert it is .DEFERRED_INIT for
    4060              :                      DECL.  */
    4061          260 :                   tree t = tsi_stmt (iter);
    4062          260 :                   gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
    4063          260 :                   t = EXPR_STMT_EXPR (t);
    4064          260 :                   gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
    4065              :                                        && TREE_OPERAND (t, 0) == decl
    4066              :                                        && (TREE_CODE (TREE_OPERAND (t, 1))
    4067              :                                            == CALL_EXPR));
    4068          260 :                   t = TREE_OPERAND (t, 1);
    4069          260 :                   gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
    4070              :                                        && (CALL_EXPR_IFN (t)
    4071              :                                            == IFN_DEFERRED_INIT));
    4072          260 :                   tsi_prev (&iter);
    4073              :                 }
    4074              :             }
    4075          280 :           if (add)
    4076              :             {
    4077              :               /* If reached the start in this or some earlier iteration,
    4078              :                  prepend .DEFERRED_INIT call for DECL.  */
    4079           50 :               tree t = build_deferred_init_call (decl);
    4080           50 :               STMT_IS_FULL_EXPR_P (t) = 1;
    4081           50 :               tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4082              :             }
    4083              :         }
    4084           71 :       if (!add)
    4085              :         {
    4086              :           /* If .DEFERRED_INIT calls for all the decls were already there,
    4087              :              skip over case labels and if we find a LABEL_EXPR, return
    4088              :              its label.  */
    4089           63 :           while (!tsi_end_p (iter)
    4090           63 :                  && !case_label
    4091          117 :                  && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
    4092           12 :             tsi_prev (&iter);
    4093           51 :           if (tsi_end_p (iter))
    4094              :             {
    4095              :               /* Only case labels were found and we are looking for normal
    4096              :                  label, we'll need to add it.  */
    4097            0 :               add = true;
    4098            0 :               iter = tsi_start (then_clause);
    4099              :             }
    4100           51 :           else if (!case_label
    4101           51 :                    && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
    4102              :             /* Return existing label.  */
    4103           21 :             lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
    4104              :           else
    4105              :             {
    4106              :               /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR.  */
    4107           30 :               gcc_checking_assert (case_label
    4108              :                                    || (TREE_CODE (tsi_stmt (iter))
    4109              :                                        == EXPR_STMT));
    4110           30 :               add = true;
    4111           30 :               tsi_next (&iter);
    4112           30 :               gcc_checking_assert (!tsi_end_p (iter));
    4113              :             }
    4114              :         }
    4115           21 :       if (add)
    4116              :         {
    4117           50 :           tree t;
    4118           50 :           if (case_label)
    4119              :             t = case_label;
    4120              :           else
    4121              :             {
    4122           41 :               lab = create_artificial_label (UNKNOWN_LOCATION);
    4123           41 :               t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
    4124              :             }
    4125           50 :           tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
    4126              :         }
    4127              :     }
    4128              :   else
    4129              :     {
    4130              :       /* No IF_STMT created by this function found.  Create it all
    4131              :          from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
    4132              :          followed by .DEFERRED_INIT calls inside of a new if (0).  */
    4133           56 :       tree new_then = push_stmt_list ();
    4134           56 :       if (!case_label)
    4135              :         {
    4136           23 :           lab = create_artificial_label (UNKNOWN_LOCATION);
    4137           23 :           add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
    4138              :         }
    4139              :       else
    4140           33 :         add_stmt (case_label);
    4141          146 :       for (unsigned int i = ndecls; i; --i)
    4142           90 :         add_stmt (build_deferred_init_call (decls[i - 1]));
    4143           56 :       new_then = pop_stmt_list (new_then);
    4144           56 :       tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
    4145              :                           new_then, void_node, NULL_TREE);
    4146           56 :       IF_STMT_VACUOUS_INIT_P (stmt) = 1;
    4147           56 :       if (tsi_end_p (iter))
    4148              :         {
    4149            6 :           iter = tsi_start (iter.container);
    4150            6 :           tsi_link_before (&iter, stmt, TSI_SAME_STMT);
    4151              :         }
    4152              :       else
    4153           50 :         tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
    4154              :     }
    4155          127 :   return lab;
    4156              : }
    4157              : 
    4158              : /* Adjust backward gotos to named label ENT if they jump over vacuous
    4159              :    initializers if !!flag_auto_var_init.  ITER is the location of
    4160              :    LABEL_EXPR for that named label.  */
    4161              : 
    4162              : static void
    4163           19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
    4164              : {
    4165           19 :   auto_vec<tree, 4> decls;
    4166           19 :   unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
    4167           19 :   tree decl;
    4168           88 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
    4169           88 :     if (!decl_jump_unsafe (decl))
    4170              :       {
    4171           88 :         gcc_checking_assert (decl_instrument_init_bypass_p (decl));
    4172           88 :         decls.safe_push (decl);
    4173          176 :         if (decls.length () == max_cnt)
    4174              :           break;
    4175              :       }
    4176           19 :   named_label_bck_direct_goto *dgoto;
    4177           19 :   unsigned last = 0;
    4178           19 :   tree lab = NULL_TREE;
    4179          103 :   FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
    4180              :     {
    4181           46 :       if (dgoto->n_bad_decls != last)
    4182              :         {
    4183           40 :           last = dgoto->n_bad_decls;
    4184           80 :           lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
    4185              :                                                decls.address (), last);
    4186              :         }
    4187           46 :       *dgoto->direct_goto = lab;
    4188              :     }
    4189           19 : }
    4190              : 
    4191              : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    4192              :    to the user.  */
    4193              : 
    4194              : static bool
    4195          286 : identify_goto (tree decl, location_t loc, const location_t *locus,
    4196              :                enum diagnostics::kind diag_kind, bool computed)
    4197              : {
    4198          286 :   if (computed)
    4199           43 :     diag_kind = diagnostics::kind::warning;
    4200          286 :   auto_diagnostic_group d;
    4201          286 :   bool complained
    4202          373 :     = emit_diagnostic (diag_kind, loc, 0,
    4203              :                        decl ? G_("jump to label %qD")
    4204              :                        : G_("jump to case label"), decl);
    4205          286 :   if (complained && locus)
    4206              :     {
    4207          199 :       if (computed)
    4208           43 :         inform (*locus, "  as a possible target of computed goto");
    4209              :       else
    4210          156 :         inform (*locus, "  from here");
    4211              :     }
    4212          572 :   return complained;
    4213          286 : }
    4214              : 
    4215              : /* Check that a single previously seen jump to a newly defined label
    4216              :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    4217              :    the jump context; NAMES are the names in scope in LEVEL at the jump
    4218              :    context; LOCUS is the source position of the jump or 0.  COMPUTED
    4219              :    is a vec of decls if the jump is a computed goto.  DIRECT_GOTO is a
    4220              :    vec of pointers to LABEL_DECLs that might need adjusting if vacuous
    4221              :    initializations are crossed for !!flag_auto_var_init.  CASE_LABEL is
    4222              :    CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
    4223              :    Returns non-zero if all is well, 2 if any vacuous initializers were
    4224              :    crossed.  */
    4225              : 
    4226              : static int
    4227      1592074 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
    4228              :                        bool exited_omp, const location_t *locus,
    4229              :                        vec<tree, va_gc> *computed,
    4230              :                        vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
    4231              :                        tree case_label)
    4232              : {
    4233      1592074 :   auto_diagnostic_group d;
    4234      1592074 :   cp_binding_level *b;
    4235      1592074 :   bool complained = false;
    4236      1592074 :   int identified = 0;
    4237      1592074 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    4238      1592074 :   bool saw_ceif = false, saw_se = false;
    4239      1592074 :   auto_vec<tree> vacuous_decls;
    4240      1592074 :   bool vacuous_inits = false;
    4241              : 
    4242      1592074 :   if (exited_omp)
    4243              :     {
    4244           12 :       complained = identify_goto (decl, input_location, locus,
    4245              :                                   diagnostics::kind::error,
    4246              :                                   computed);
    4247           12 :       if (complained)
    4248           12 :         inform (input_location, "  exits OpenMP structured block");
    4249              :       saw_omp = true;
    4250              :       identified = 2;
    4251              :     }
    4252              : 
    4253      4747005 :   for (b = current_binding_level; b ; b = b->level_chain)
    4254              :     {
    4255      3154931 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    4256              : 
    4257      3234840 :       for (new_decls = b->names; new_decls != old_decls;
    4258       149130 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    4259        69221 :                         : TREE_CHAIN (new_decls)))
    4260              :         {
    4261        79909 :           bool problem = decl_jump_unsafe (new_decls);
    4262        79909 :           if (! problem)
    4263              :             {
    4264        79864 :               if (decl_instrument_init_bypass_p (new_decls))
    4265              :                 {
    4266          323 :                   if (direct_goto || case_label)
    4267          254 :                     vacuous_decls.safe_push (new_decls);
    4268              :                   vacuous_inits = true;
    4269              :                 }
    4270        79864 :               continue;
    4271              :             }
    4272              : 
    4273           45 :           if (!identified)
    4274              :             {
    4275           45 :               complained = identify_goto (decl, input_location, locus,
    4276              :                                           diagnostics::kind::error,
    4277              :                                           computed);
    4278           45 :               identified = 2;
    4279              :             }
    4280           45 :           if (complained)
    4281           45 :             inform (DECL_SOURCE_LOCATION (new_decls),
    4282              :                     "  crosses initialization of %q#D", new_decls);
    4283              :         }
    4284              : 
    4285      3154931 :       if (b == level)
    4286              :         break;
    4287              : 
    4288      1562857 :       const char *inf = NULL;
    4289      1562857 :       location_t loc = input_location;
    4290      1562857 :       switch (b->kind)
    4291              :         {
    4292            3 :         case sk_try:
    4293            3 :           if (!saw_eh)
    4294              :             inf = G_("  enters %<try%> block");
    4295              :           saw_eh = true;
    4296              :           break;
    4297              : 
    4298            9 :         case sk_catch:
    4299            9 :           if (!saw_eh)
    4300              :             inf = G_("  enters %<catch%> block");
    4301              :           saw_eh = true;
    4302              :           break;
    4303              : 
    4304          102 :         case sk_omp:
    4305          102 :           if (!saw_omp)
    4306              :             inf = G_("  enters OpenMP structured block");
    4307              :           saw_omp = true;
    4308              :           break;
    4309              : 
    4310            3 :         case sk_transaction:
    4311            3 :           if (!saw_tm)
    4312              :             inf = G_("  enters synchronized or atomic statement");
    4313              :           saw_tm = true;
    4314              :           break;
    4315              : 
    4316           18 :         case sk_stmt_expr:
    4317           18 :           if (!saw_se)
    4318              :             inf = G_("  enters statement expression");
    4319              :           saw_se = true;
    4320              :           break;
    4321              : 
    4322      1562585 :         case sk_block:
    4323      1562585 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    4324              :             {
    4325            9 :               inf = G_("  enters %<constexpr if%> statement");
    4326            9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4327              :               saw_cxif = true;
    4328              :             }
    4329      1562576 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    4330              :             {
    4331           18 :               inf = G_("  enters %<consteval if%> statement");
    4332           18 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    4333              :               saw_ceif = true;
    4334              :             }
    4335              :           break;
    4336              : 
    4337              :         default:
    4338              :           break;
    4339              :         }
    4340              : 
    4341              :       if (inf)
    4342              :         {
    4343          141 :           if (identified < 2)
    4344          141 :             complained = identify_goto (decl, input_location, locus,
    4345              :                                         diagnostics::kind::error,
    4346              :                                         computed);
    4347          141 :           identified = 2;
    4348          141 :           if (complained)
    4349          141 :             inform (loc, inf);
    4350              :         }
    4351              :     }
    4352              : 
    4353      1592074 :   if (!vec_safe_is_empty (computed))
    4354              :     {
    4355            9 :       if (!identified)
    4356            6 :         complained = identify_goto (decl, input_location, locus,
    4357              :                                     diagnostics::kind::error,
    4358              :                                     computed);
    4359            9 :       identified = 2;
    4360            9 :       if (complained)
    4361           18 :         for (tree d : computed)
    4362              :           {
    4363            9 :             if (DECL_P (d))
    4364            6 :               inform (DECL_SOURCE_LOCATION (d), "  does not destroy %qD", d);
    4365            3 :             else if (d == get_identifier ("catch"))
    4366            3 :               inform (*locus, "  does not clean up handled exception");
    4367              :           }
    4368              :     }
    4369              : 
    4370      1592163 :   if (!vacuous_decls.is_empty () && !seen_error ())
    4371              :     {
    4372           87 :       tree_stmt_iterator iter = tsi_last (cur_stmt_list);
    4373           87 :       if (case_label)
    4374              :         {
    4375           42 :           gcc_checking_assert (tsi_stmt (iter) == case_label);
    4376           42 :           tsi_delink (&iter);
    4377           42 :           iter = tsi_last (cur_stmt_list);
    4378              :         }
    4379           87 :       tree lab = maybe_add_deferred_init_calls (iter, case_label,
    4380              :                                                 vacuous_decls.address (),
    4381              :                                                 vacuous_decls.length ());
    4382           87 :       if (lab)
    4383              :         {
    4384              :           unsigned int i;
    4385              :           named_label_fwd_direct_goto *dgoto;
    4386          177 :           FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
    4387           45 :             *dgoto->direct_goto = lab;
    4388              :         }
    4389              :     }
    4390              : 
    4391      1592074 :   if (identified)
    4392              :     return 0;
    4393      1591870 :   return vacuous_inits ? 2 : 1;
    4394      1592074 : }
    4395              : 
    4396              : static void
    4397         2109 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    4398              : {
    4399         2109 :   check_previous_goto_1 (decl, use->binding_level,
    4400         2109 :                          use->names_in_scope, use->in_omp_scope,
    4401         2109 :                          &use->o_goto_locus, use->computed_goto,
    4402              :                          use->direct_goto, NULL_TREE);
    4403         2109 :   vec_free (use->direct_goto);
    4404         2109 : }
    4405              : 
    4406              : static int
    4407      1589965 : check_switch_goto (cp_binding_level *level, tree case_label)
    4408              : {
    4409      1589965 :   return check_previous_goto_1 (NULL_TREE, level, level->names,
    4410      1589965 :                                 false, NULL, nullptr, nullptr, case_label);
    4411              : }
    4412              : 
    4413              : /* Check that a new jump to a label ENT is OK.  DECLP is a pointer
    4414              :    to a LABEL_DECL for direct gotos and NULL for computed gotos.  */
    4415              : 
    4416              : void
    4417         2833 : check_goto_1 (named_label_entry *ent, tree *declp)
    4418              : {
    4419         2833 :   auto_diagnostic_group d;
    4420         2833 :   tree decl = ent->label_decl;
    4421         2833 :   bool computed = declp == NULL;
    4422              : 
    4423              :   /* If the label hasn't been defined yet, defer checking.  */
    4424         2833 :   if (! DECL_INITIAL (decl))
    4425              :     {
    4426              :       /* Don't bother creating another use if the last goto had the
    4427              :          same data, and will therefore create the same set of errors.  */
    4428         2178 :       if (ent->uses
    4429          658 :           && ent->uses->binding_level == current_binding_level
    4430           60 :           && ent->uses->names_in_scope == current_binding_level->names)
    4431              :         {
    4432           60 :           if (declp
    4433           54 :               && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4434           11 :               && !processing_template_decl)
    4435            9 :             vec_safe_push (ent->uses->direct_goto,
    4436            9 :                            named_label_fwd_direct_goto { declp });
    4437           60 :           return;
    4438              :         }
    4439              : 
    4440         2118 :       named_label_use_entry *new_use
    4441         2118 :         = ggc_alloc<named_label_use_entry> ();
    4442         2118 :       new_use->binding_level = current_binding_level;
    4443         2118 :       new_use->names_in_scope = current_binding_level->names;
    4444         2118 :       new_use->o_goto_locus = input_location;
    4445         2118 :       new_use->in_omp_scope = false;
    4446         2118 :       new_use->computed_goto = computed ? make_tree_vector () : nullptr;
    4447         2118 :       new_use->direct_goto = nullptr;
    4448         2118 :       if (declp
    4449         2027 :           && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
    4450          358 :           && !processing_template_decl)
    4451          301 :         vec_safe_push (new_use->direct_goto,
    4452          301 :                        named_label_fwd_direct_goto { declp });
    4453              : 
    4454         2118 :       new_use->next = ent->uses;
    4455         2118 :       ent->uses = new_use;
    4456         2118 :       return;
    4457              :     }
    4458              : 
    4459          655 :   bool saw_catch = false, complained = false;
    4460          655 :   int identified = 0;
    4461          655 :   tree bad;
    4462          655 :   unsigned ix;
    4463          655 :   unsigned n_bad_decls = 0;
    4464              : 
    4465          655 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    4466          640 :       || ent->in_constexpr_if || ent->in_consteval_if
    4467          634 :       || ent->in_omp_scope || ent->in_stmt_expr
    4468          616 :       || ent->has_bad_decls)
    4469              :     {
    4470           45 :       enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
    4471           45 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    4472           30 :           || ent->in_consteval_if || ent->in_transaction_scope
    4473           24 :           || ent->in_omp_scope || ent->in_stmt_expr)
    4474           39 :         diag_kind = diagnostics::kind::error;
    4475           45 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4476              :                                   &input_location, diag_kind, computed);
    4477           45 :       identified = 1 + (diag_kind == diagnostics::kind::error);
    4478              :     }
    4479              : 
    4480          845 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    4481              :     {
    4482          190 :       bool problem = decl_jump_unsafe (bad);
    4483          190 :       if (!problem)
    4484              :         {
    4485          184 :           gcc_checking_assert (decl_instrument_init_bypass_p (bad));
    4486          184 :           n_bad_decls++;
    4487          184 :           continue;
    4488              :         }
    4489              : 
    4490            6 :       if (DECL_ARTIFICIAL (bad))
    4491              :         {
    4492              :           /* Can't skip init of __exception_info.  */
    4493            0 :           if (identified == 1)
    4494              :             {
    4495            0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4496              :                                           &input_location,
    4497              :                                           diagnostics::kind::error,
    4498              :                                           computed);
    4499            0 :               identified = 2;
    4500              :             }
    4501            0 :           if (complained)
    4502            0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    4503              :           saw_catch = true;
    4504              :         }
    4505            6 :       else if (complained)
    4506            6 :         inform (DECL_SOURCE_LOCATION (bad),
    4507              :                 "  skips initialization of %q#D", bad);
    4508              :     }
    4509              : 
    4510          655 :   if (complained)
    4511              :     {
    4512           45 :       if (ent->in_try_scope)
    4513            9 :         inform (input_location, "  enters %<try%> block");
    4514           36 :       else if (ent->in_catch_scope && !saw_catch)
    4515            3 :         inform (input_location, "  enters %<catch%> block");
    4516           33 :       else if (ent->in_transaction_scope)
    4517            3 :         inform (input_location, "  enters synchronized or atomic statement");
    4518           30 :       else if (ent->in_constexpr_if)
    4519            3 :         inform (input_location, "  enters %<constexpr if%> statement");
    4520           27 :       else if (ent->in_consteval_if)
    4521            3 :         inform (input_location, "  enters %<consteval if%> statement");
    4522           24 :       else if (ent->in_stmt_expr)
    4523           15 :         inform (input_location, "  enters statement expression");
    4524              :     }
    4525              : 
    4526          655 :   if (ent->in_omp_scope)
    4527              :     {
    4528            3 :       if (complained)
    4529            3 :         inform (input_location, "  enters OpenMP structured block");
    4530              :     }
    4531          652 :   else if (flag_openmp)
    4532           69 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4533              :       {
    4534           42 :         if (b == ent->binding_level)
    4535              :           break;
    4536           36 :         if (b->kind == sk_omp)
    4537              :           {
    4538           21 :             if (identified < 2)
    4539              :               {
    4540           42 :                 complained = identify_goto (decl,
    4541           21 :                                             DECL_SOURCE_LOCATION (decl),
    4542              :                                             &input_location,
    4543              :                                             diagnostics::kind::error,
    4544              :                                             computed);
    4545           21 :                 identified = 2;
    4546              :               }
    4547           21 :             if (complained)
    4548           21 :               inform (input_location, "  exits OpenMP structured block");
    4549              :             break;
    4550              :           }
    4551              :       }
    4552              : 
    4553              :   /* Warn if a computed goto might involve a local variable going out of scope
    4554              :      without being cleaned up.  */
    4555          655 :   if (computed)
    4556              :     {
    4557           71 :       auto level = ent->binding_level;
    4558           71 :       auto names = ent->names_in_scope;
    4559           71 :       for (auto b = current_binding_level; ; b = b->level_chain)
    4560              :         {
    4561          111 :           if (b->kind == sk_catch)
    4562              :             {
    4563            6 :               if (!identified)
    4564              :                 {
    4565            6 :                   complained
    4566            6 :                     = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4567              :                                      &input_location, diagnostics::kind::error,
    4568              :                                      computed);
    4569            6 :                   identified = 2;
    4570              :                 }
    4571            6 :               if (complained)
    4572            6 :                 inform (input_location,
    4573              :                         "  does not clean up handled exception");
    4574              :             }
    4575          111 :           tree end = b == level ? names : NULL_TREE;
    4576          127 :           for (tree d = b->names; d != end; d = DECL_CHAIN (d))
    4577              :             {
    4578           16 :               if (automatic_var_with_nontrivial_dtor_p (d))
    4579              :                 {
    4580           10 :                   if (!identified)
    4581              :                     {
    4582           10 :                       complained
    4583           10 :                         = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    4584              :                                          &input_location, diagnostics::kind::error,
    4585              :                                          computed);
    4586           10 :                       identified = 2;
    4587              :                     }
    4588           10 :                   if (complained)
    4589           10 :                     inform (DECL_SOURCE_LOCATION (d),
    4590              :                             "  does not destroy %qD", d);
    4591              :                 }
    4592              :             }
    4593          111 :           if (b == level)
    4594              :             break;
    4595           40 :         }
    4596              :     }
    4597              : 
    4598          655 :   if (n_bad_decls && declp)
    4599           46 :     vec_safe_push (ent->direct_goto,
    4600           46 :                    named_label_bck_direct_goto { declp, n_bad_decls });
    4601         2833 : }
    4602              : 
    4603              : /* Check that a new jump to a label *DECLP is OK.  Called by
    4604              :    finish_goto_stmt.  */
    4605              : 
    4606              : void
    4607         2793 : check_goto (tree *declp)
    4608              : {
    4609         2793 :   if (!named_labels)
    4610              :     return;
    4611         2778 :   tree decl = *declp;
    4612         2778 :   if (TREE_CODE (decl) != LABEL_DECL)
    4613              :     {
    4614              :       /* We don't know where a computed goto is jumping,
    4615              :          so check all addressable labels.  */
    4616          312 :       for (auto iter = named_labels->begin ();
    4617          425 :            iter != named_labels->end ();
    4618          199 :            ++iter)
    4619              :         {
    4620          199 :           auto ent = *iter;
    4621          199 :           if (ent->addressed)
    4622          168 :             check_goto_1 (ent, NULL);
    4623              :         }
    4624              :     }
    4625              :   else
    4626              :     {
    4627         2665 :       hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    4628         2665 :       named_label_entry **slot
    4629         2665 :         = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    4630         2665 :       named_label_entry *ent = *slot;
    4631         2665 :       check_goto_1 (ent, declp);
    4632              :     }
    4633              : }
    4634              : 
    4635              : /* Check that a return is ok wrt OpenMP structured blocks.
    4636              :    Called by finish_return_stmt.  Returns true if all is well.  */
    4637              : 
    4638              : bool
    4639       279354 : check_omp_return (void)
    4640              : {
    4641      1108094 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    4642       828740 :     if (b->kind == sk_omp)
    4643              :       {
    4644           15 :         error ("invalid exit from OpenMP structured block");
    4645           15 :         return false;
    4646              :       }
    4647       828725 :     else if (b->kind == sk_function_parms)
    4648              :       break;
    4649              :   return true;
    4650              : }
    4651              : 
    4652              : /* Define a label, specifying the location in the source file.
    4653              :    Return the LABEL_DECL node for the label.  */
    4654              : 
    4655              : tree
    4656        20802 : define_label (location_t location, tree name)
    4657              : {
    4658        20802 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    4659              : 
    4660              :   /* After labels, make any new cleanups in the function go into their
    4661              :      own new (temporary) binding contour.  */
    4662        20802 :   for (cp_binding_level *p = current_binding_level;
    4663        31499 :        p->kind != sk_function_parms;
    4664        10697 :        p = p->level_chain)
    4665        10697 :     p->more_cleanups_ok = 0;
    4666              : 
    4667        20802 :   named_label_entry *ent = lookup_label_1 (name, false);
    4668        20802 :   tree decl = ent->label_decl;
    4669              : 
    4670        20802 :   if (DECL_INITIAL (decl) != NULL_TREE)
    4671              :     {
    4672            6 :       error ("duplicate label %qD", decl);
    4673            6 :       return error_mark_node;
    4674              :     }
    4675              :   else
    4676              :     {
    4677              :       /* Mark label as having been defined.  */
    4678        20796 :       DECL_INITIAL (decl) = error_mark_node;
    4679              :       /* Say where in the source.  */
    4680        20796 :       DECL_SOURCE_LOCATION (decl) = location;
    4681              : 
    4682        20796 :       ent->binding_level = current_binding_level;
    4683        20796 :       ent->names_in_scope = current_binding_level->names;
    4684              : 
    4685        22905 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    4686         2109 :         check_previous_goto (decl, use);
    4687        20796 :       ent->uses = NULL;
    4688              :     }
    4689              : 
    4690        20796 :   return decl;
    4691        20802 : }
    4692              : 
    4693              : struct cp_switch
    4694              : {
    4695              :   cp_binding_level *level;
    4696              :   struct cp_switch *next;
    4697              :   /* The SWITCH_STMT being built.  */
    4698              :   tree switch_stmt;
    4699              :   /* A splay-tree mapping the low element of a case range to the high
    4700              :      element, or NULL_TREE if there is no high element.  Used to
    4701              :      determine whether or not a new case label duplicates an old case
    4702              :      label.  We need a tree, rather than simply a hash table, because
    4703              :      of the GNU case range extension.  */
    4704              :   splay_tree cases;
    4705              :   /* Remember whether a default: case label has been seen.  */
    4706              :   bool has_default_p;
    4707              :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    4708              :   bool break_stmt_seen_p;
    4709              :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    4710              :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    4711              :   bool in_loop_body_p;
    4712              : };
    4713              : 
    4714              : /* A stack of the currently active switch statements.  The innermost
    4715              :    switch statement is on the top of the stack.  There is no need to
    4716              :    mark the stack for garbage collection because it is only active
    4717              :    during the processing of the body of a function, and we never
    4718              :    collect at that point.  */
    4719              : 
    4720              : static struct cp_switch *switch_stack;
    4721              : 
    4722              : /* Called right after a switch-statement condition is parsed.
    4723              :    SWITCH_STMT is the switch statement being parsed.  */
    4724              : 
    4725              : void
    4726       683915 : push_switch (tree switch_stmt)
    4727              : {
    4728       683915 :   struct cp_switch *p = XNEW (struct cp_switch);
    4729       683915 :   p->level = current_binding_level;
    4730       683915 :   p->next = switch_stack;
    4731       683915 :   p->switch_stmt = switch_stmt;
    4732       683915 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    4733       683915 :   p->has_default_p = false;
    4734       683915 :   p->break_stmt_seen_p = false;
    4735       683915 :   p->in_loop_body_p = false;
    4736       683915 :   switch_stack = p;
    4737       683915 : }
    4738              : 
    4739              : void
    4740       683915 : pop_switch (void)
    4741              : {
    4742       683915 :   struct cp_switch *cs = switch_stack;
    4743              : 
    4744              :   /* Emit warnings as needed.  */
    4745       683915 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    4746       683915 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    4747       683915 :   const bool bool_cond_p
    4748       683915 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    4749       683915 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    4750       683915 :   if (!processing_template_decl)
    4751       275263 :     c_do_switch_warnings (cs->cases, switch_location,
    4752       275263 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    4753              :                           bool_cond_p);
    4754              : 
    4755              :   /* For the benefit of block_may_fallthru remember if the switch body
    4756              :      case labels cover all possible values and if there are break; stmts.  */
    4757       683915 :   if (cs->has_default_p
    4758       683915 :       || (!processing_template_decl
    4759        39508 :           && c_switch_covers_all_cases_p (cs->cases,
    4760        39508 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    4761       504258 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    4762       683915 :   if (!cs->break_stmt_seen_p)
    4763       354174 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    4764              :   /* Now that we're done with the switch warnings, set the switch type
    4765              :      to the type of the condition if the index type was of scoped enum type.
    4766              :      (Such types don't participate in the integer promotions.)  We do this
    4767              :      because of bit-fields whose declared type is a scoped enum type:
    4768              :      gimplification will use the lowered index type, but convert the
    4769              :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    4770              :      and verify_gimple_switch doesn't accept that.  */
    4771       683915 :   if (is_bitfield_expr_with_lowered_type (cond))
    4772        21842 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    4773       683915 :   gcc_assert (!cs->in_loop_body_p);
    4774       683915 :   splay_tree_delete (cs->cases);
    4775       683915 :   switch_stack = switch_stack->next;
    4776       683915 :   free (cs);
    4777       683915 : }
    4778              : 
    4779              : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    4780              :    a SWITCH_STMT and not inside of a loop body inside of it, note
    4781              :    in switch_stack we've seen a BREAK_STMT.  */
    4782              : 
    4783              : void
    4784      4616762 : note_break_stmt (void)
    4785              : {
    4786      4616762 :   if (switch_stack && !switch_stack->in_loop_body_p)
    4787      2583795 :     switch_stack->break_stmt_seen_p = true;
    4788      4616762 : }
    4789              : 
    4790              : /* Note the start of processing of an iteration statement's body.
    4791              :    The note_break_stmt function will do nothing while processing it.
    4792              :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    4793              : 
    4794              : bool
    4795     17562410 : note_iteration_stmt_body_start (void)
    4796              : {
    4797     17562410 :   if (!switch_stack)
    4798              :     return false;
    4799       183971 :   bool ret = switch_stack->in_loop_body_p;
    4800       183971 :   switch_stack->in_loop_body_p = true;
    4801       183971 :   return ret;
    4802              : }
    4803              : 
    4804              : /* Note the end of processing of an iteration statement's body.  */
    4805              : 
    4806              : void
    4807     17562410 : note_iteration_stmt_body_end (bool prev)
    4808              : {
    4809     17562410 :   if (switch_stack)
    4810       183971 :     switch_stack->in_loop_body_p = prev;
    4811     17562410 : }
    4812              : 
    4813              : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4814              :    condition.  Note that if TYPE and VALUE are already integral we don't
    4815              :    really do the conversion because the language-independent
    4816              :    warning/optimization code will work better that way.  */
    4817              : 
    4818              : static tree
    4819      3179598 : case_conversion (tree type, tree value)
    4820              : {
    4821      3179598 :   if (value == NULL_TREE)
    4822              :     return value;
    4823              : 
    4824      1354212 :   value = mark_rvalue_use (value);
    4825              : 
    4826      1354212 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4827      1065702 :     type = type_promotes_to (type);
    4828              : 
    4829      1354212 :   tree ovalue = value;
    4830              :   /* The constant-expression VALUE shall be a converted constant expression
    4831              :      of the adjusted type of the switch condition, which doesn't allow
    4832              :      narrowing conversions.  */
    4833      1354212 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4834              : 
    4835      1354212 :   if (cxx_dialect >= cxx11
    4836      1354212 :       && (SCOPED_ENUM_P (type)
    4837      1062581 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4838              :     /* Use the converted value.  */;
    4839              :   else
    4840              :     /* The already integral case.  */
    4841              :     value = ovalue;
    4842              : 
    4843      1354212 :   return cxx_constant_value (value);
    4844              : }
    4845              : 
    4846              : /* Note that we've seen a definition of a case label, and complain if this
    4847              :    is a bad place for one.  */
    4848              : 
    4849              : tree
    4850      5460984 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4851              : {
    4852      5460984 :   tree cond, r;
    4853      5460984 :   cp_binding_level *p;
    4854      5460984 :   tree type;
    4855              : 
    4856      5460984 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4857       504222 :     switch_stack->has_default_p = true;
    4858              : 
    4859      5460984 :   if (processing_template_decl)
    4860              :     {
    4861      3871062 :       tree label;
    4862              : 
    4863              :       /* For templates, just add the case label; we'll do semantic
    4864              :          analysis at instantiation-time.  But diagnose case labels
    4865              :          in expansion statements with switch outside of it here.  */
    4866      3871062 :       if (in_expansion_stmt)
    4867           39 :         for (cp_binding_level *b = current_binding_level;
    4868           78 :              b != switch_stack->level; b = b->level_chain)
    4869           63 :           if (b->kind == sk_template_for && b->this_entity)
    4870              :             {
    4871           24 :               auto_diagnostic_group d;
    4872           24 :               error ("jump to case label");
    4873           24 :               inform (EXPR_LOCATION (b->this_entity),
    4874              :                       "  enters %<template for%> statement");
    4875           24 :               return error_mark_node;
    4876           24 :             }
    4877      3871038 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4878      3871038 :       return add_stmt (build_case_label (low_value, high_value, label));
    4879              :     }
    4880              : 
    4881              :   /* Find the condition on which this switch statement depends.  */
    4882      1589922 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4883      1589922 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4884            0 :     cond = TREE_VALUE (cond);
    4885              : 
    4886      1589922 :   int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
    4887      1589922 :   if (!chk_switch_goto)
    4888           87 :     return error_mark_node;
    4889              : 
    4890      1589835 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4891      1589835 :   if (type == error_mark_node)
    4892              :     return error_mark_node;
    4893              : 
    4894      1589799 :   low_value = case_conversion (type, low_value);
    4895      1589799 :   high_value = case_conversion (type, high_value);
    4896              : 
    4897      1589799 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4898              : 
    4899      1589799 :   if (r != error_mark_node && chk_switch_goto == 2)
    4900           43 :     check_switch_goto (switch_stack->level, r);
    4901              : 
    4902              :   /* After labels, make any new cleanups in the function go into their
    4903              :      own new (temporary) binding contour.  */
    4904      1589799 :   for (p = current_binding_level;
    4905      6705048 :        p->kind != sk_function_parms;
    4906      5115249 :        p = p->level_chain)
    4907      5115249 :     p->more_cleanups_ok = 0;
    4908              : 
    4909              :   return r;
    4910              : }
    4911              : 
    4912              : struct typename_info {
    4913              :   tree scope;
    4914              :   tree name;
    4915              :   tree template_id;
    4916              :   tag_types tag_type;
    4917              : };
    4918              : 
    4919              : struct typename_hasher : ggc_ptr_hash<tree_node>
    4920              : {
    4921              :   typedef typename_info *compare_type;
    4922              : 
    4923              :   /* Hash a TYPENAME_TYPE.  */
    4924              : 
    4925              :   static hashval_t
    4926    437028115 :   hash (tree context, tree fullname)
    4927              :   {
    4928    437028115 :     hashval_t hash = 0;
    4929    437028115 :     hash = iterative_hash_object (context, hash);
    4930    437028115 :     hash = iterative_hash_object (fullname, hash);
    4931    437028115 :     return hash;
    4932              :   }
    4933              : 
    4934              :   static hashval_t
    4935     61804567 :   hash (const typename_info *ti)
    4936              :   {
    4937     61804567 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4938              :   }
    4939              : 
    4940              :   static hashval_t
    4941    375223548 :   hash (tree t)
    4942              :   {
    4943    375223548 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4944              :   }
    4945              : 
    4946              :   /* Compare two TYPENAME_TYPEs.  */
    4947              : 
    4948              :   static bool
    4949    443543651 :   equal (tree t1, const typename_info *t2)
    4950              :   {
    4951    443543651 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4952    143330444 :             && TYPE_CONTEXT (t1) == t2->scope
    4953     31694848 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4954    475226628 :             && get_typename_tag (t1) == t2->tag_type);
    4955              :   }
    4956              : };
    4957              : 
    4958              : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4959              :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4960              : 
    4961              :    Returns the new TYPENAME_TYPE.  */
    4962              : 
    4963              : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4964              : 
    4965              : tree
    4966     61804567 : build_typename_type (tree context, tree name, tree fullname,
    4967              :                      enum tag_types tag_type)
    4968              : {
    4969     61804567 :   typename_info ti;
    4970              : 
    4971     61804567 :   if (typename_htab == NULL)
    4972        19545 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4973              : 
    4974     61804567 :   ti.scope = FROB_CONTEXT (context);
    4975     61804567 :   ti.name = name;
    4976     61804567 :   ti.template_id = fullname;
    4977     61804567 :   ti.tag_type = tag_type;
    4978     61804567 :   hashval_t hash = typename_hasher::hash (&ti);
    4979              : 
    4980              :   /* See if we already have this type.  */
    4981     61804567 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4982     61804567 :   tree t = *e;
    4983     61804567 :   if (*e)
    4984              :     t = *e;
    4985              :   else
    4986              :     {
    4987              :       /* Build the TYPENAME_TYPE.  */
    4988     31176394 :       t = cxx_make_type (TYPENAME_TYPE);
    4989     31176394 :       TYPE_CONTEXT (t) = ti.scope;
    4990     31176394 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4991     31176394 :       set_typename_tag (t, ti.tag_type);
    4992              : 
    4993              :       /* Build the corresponding TYPE_DECL.  */
    4994     31176394 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4995     31176394 :       TYPE_NAME (t) = d;
    4996     31176394 :       TYPE_STUB_DECL (t) = d;
    4997     31176394 :       DECL_CONTEXT (d) = ti.scope;
    4998     31176394 :       DECL_ARTIFICIAL (d) = 1;
    4999              : 
    5000              :       /* Store it in the hash table.  */
    5001     31176394 :       *e = t;
    5002              : 
    5003              :       /* TYPENAME_TYPEs must always be compared structurally, because
    5004              :          they may or may not resolve down to another type depending on
    5005              :          the currently open classes. */
    5006     31176394 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    5007              :     }
    5008              : 
    5009     61804567 :   return t;
    5010              : }
    5011              : 
    5012              : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    5013              :    provided to name the type.  Returns an appropriate type, unless an
    5014              :    error occurs, in which case error_mark_node is returned.  If we
    5015              :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    5016              :    return that, rather than the _TYPE it corresponds to, in other
    5017              :    cases we look through the type decl.  If TF_ERROR is set, complain
    5018              :    about errors, otherwise be quiet.  */
    5019              : 
    5020              : tree
    5021    255163324 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    5022              :                     tsubst_flags_t complain)
    5023              : {
    5024    255163324 :   tree fullname;
    5025    255163324 :   tree t;
    5026    255163324 :   bool want_template;
    5027              : 
    5028    255163324 :   if (name == error_mark_node
    5029    255163318 :       || context == NULL_TREE
    5030    255163318 :       || context == error_mark_node)
    5031              :     return error_mark_node;
    5032              : 
    5033    255163302 :   if (TYPE_P (name))
    5034              :     {
    5035            0 :       if (!(TYPE_LANG_SPECIFIC (name)
    5036            0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    5037            0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    5038            0 :         name = TYPE_IDENTIFIER (name);
    5039              :       else
    5040              :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    5041            0 :         name = build_nt (TEMPLATE_ID_EXPR,
    5042            0 :                          CLASSTYPE_TI_TEMPLATE (name),
    5043            0 :                          CLASSTYPE_TI_ARGS (name));
    5044              :     }
    5045    255163302 :   else if (TREE_CODE (name) == TYPE_DECL)
    5046            0 :     name = DECL_NAME (name);
    5047              : 
    5048    255163302 :   fullname = name;
    5049              : 
    5050    255163302 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    5051              :     {
    5052      5046414 :       name = TREE_OPERAND (name, 0);
    5053      5046414 :       if (DECL_TYPE_TEMPLATE_P (name))
    5054            0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    5055      5046414 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    5056              :         {
    5057            0 :           if (complain & tf_error)
    5058            0 :             error ("%qD is not a type", name);
    5059            0 :           return error_mark_node;
    5060              :         }
    5061              :     }
    5062    255163302 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    5063              :     {
    5064            0 :       if (complain & tf_error)
    5065            0 :         error ("%qD used without template arguments", name);
    5066            0 :       return error_mark_node;
    5067              :     }
    5068    255163302 :   else if (is_overloaded_fn (name))
    5069              :     {
    5070            3 :       if (complain & tf_error)
    5071            3 :         error ("%qD is a function, not a type", name);
    5072            3 :       return error_mark_node;
    5073              :     }
    5074    255163299 :   gcc_assert (identifier_p (name));
    5075    255163299 :   gcc_assert (TYPE_P (context));
    5076              : 
    5077    255163299 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    5078              :     /* This can happen for C++17 variadic using (c++/88986).  */;
    5079    242399531 :   else if (!MAYBE_CLASS_TYPE_P (context))
    5080              :     {
    5081            6 :       if (complain & tf_error)
    5082            6 :         error ("%q#T is not a class", context);
    5083            6 :       return error_mark_node;
    5084              :     }
    5085              : 
    5086              :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    5087              :      dependent base class of CONTEXT.  But look inside it anyway
    5088              :      if CONTEXT is a currently open scope, in case it refers to a
    5089              :      member of the current instantiation or a non-dependent base;
    5090              :      lookup will stop when we hit a dependent base.  */
    5091    255163293 :   if (!dependent_scope_p (context))
    5092              :     {
    5093              :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    5094              :          (as per [temp.res.general]/3), unless
    5095              :            - the tag corresponds to a class-key or 'enum' so
    5096              :              [basic.lookup.elab] applies, or
    5097              :            - the tag corresponds to scope_type or tf_qualifying_scope is
    5098              :              set so [basic.lookup.qual]/1 applies, or
    5099              :            - we're inside a base-specifier so [class.derived.general]/2 applies;
    5100              :              the tag will already be class_type in that case.
    5101              :          TODO: If we'd set/track the scope_type tag thoroughly on all
    5102              :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    5103              :          tf_qualifying_scope flag.  */
    5104    396027002 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    5105    198013501 :         || (complain & tf_qualifying_scope);
    5106    198013501 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    5107              :     }
    5108              :   else
    5109              :     t = NULL_TREE;
    5110              : 
    5111    273006458 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
    5112     57150717 :     return build_typename_type (context, name, fullname, tag_type);
    5113              : 
    5114    198012576 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    5115              : 
    5116    198012576 :   if (!t)
    5117              :     {
    5118     17842240 :       if (complain & tf_error)
    5119              :         {
    5120          234 :           if (!COMPLETE_TYPE_P (context))
    5121           18 :             cxx_incomplete_type_error (NULL_TREE, context);
    5122              :           else
    5123          431 :             error (want_template ? G_("no class template named %q#T in %q#T")
    5124              :                    : G_("no type named %q#T in %q#T"), name, context);
    5125              :         }
    5126     17842240 :       return error_mark_node;
    5127              :     }
    5128              : 
    5129              :   /* Pull out the template from an injected-class-name (or multiple).  */
    5130    180170336 :   if (want_template)
    5131      3201905 :     t = maybe_get_template_decl_from_type_decl (t);
    5132              : 
    5133    180170336 :   if (TREE_CODE (t) == TREE_LIST)
    5134              :     {
    5135            3 :       if (complain & tf_error)
    5136              :         {
    5137            3 :           auto_diagnostic_group d;
    5138            3 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    5139            3 :           print_candidates (input_location, t);
    5140            3 :         }
    5141            3 :       return error_mark_node;
    5142              :     }
    5143              : 
    5144    180170333 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    5145              :     {
    5146            6 :       if (complain & tf_error)
    5147            6 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    5148              :                context, name, t);
    5149            6 :       return error_mark_node;
    5150              :     }
    5151    180170327 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    5152              :     {
    5153         1469 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    5154         2941 :           && DECL_TYPE_TEMPLATE_P (t))
    5155              :         /* The caller permits this typename-specifier to name a template
    5156              :            (because it appears in a CTAD-enabled context).  */;
    5157              :       else
    5158              :         {
    5159           23 :           if (complain & tf_error)
    5160           17 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    5161              :                    context, name, t);
    5162           23 :           return error_mark_node;
    5163              :         }
    5164              :     }
    5165              : 
    5166    180170304 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    5167              :                                             context, complain))
    5168           42 :     return error_mark_node;
    5169              : 
    5170    180170262 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    5171         1458 :     return make_template_placeholder (t);
    5172              : 
    5173    180168804 :   if (want_template)
    5174              :     {
    5175      3201899 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    5176              :                                  NULL_TREE, context,
    5177              :                                  complain | tf_user);
    5178      3201899 :       if (t == error_mark_node)
    5179              :         return error_mark_node;
    5180      3201894 :       t = TYPE_NAME (t);
    5181              :     }
    5182              : 
    5183    180168799 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    5184      2244611 :     t = TREE_TYPE (t);
    5185              : 
    5186    180168799 :   maybe_record_typedef_use (t);
    5187              : 
    5188    180168799 :   return t;
    5189              : }
    5190              : 
    5191              : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    5192              :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    5193              :    in which case error_mark_node is returned.
    5194              : 
    5195              :    If PARM_LIST is non-NULL, also make sure that the template parameter
    5196              :    list of TEMPLATE_DECL matches.
    5197              : 
    5198              :    If COMPLAIN zero, don't complain about any errors that occur.  */
    5199              : 
    5200              : tree
    5201       179213 : make_unbound_class_template (tree context, tree name, tree parm_list,
    5202              :                              tsubst_flags_t complain)
    5203              : {
    5204       179213 :   if (TYPE_P (name))
    5205            0 :     name = TYPE_IDENTIFIER (name);
    5206       179213 :   else if (DECL_P (name))
    5207            0 :     name = DECL_NAME (name);
    5208       179213 :   gcc_assert (identifier_p (name));
    5209              : 
    5210       179213 :   if (!dependent_type_p (context)
    5211       179213 :       || currently_open_class (context))
    5212              :     {
    5213        88388 :       tree tmpl = NULL_TREE;
    5214              : 
    5215        88388 :       if (MAYBE_CLASS_TYPE_P (context))
    5216        88382 :         tmpl = lookup_field (context, name, 0, false);
    5217              : 
    5218        88382 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    5219            3 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    5220              : 
    5221        88376 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    5222              :         {
    5223           12 :           if (complain & tf_error)
    5224            9 :             error ("no class template named %q#T in %q#T", name, context);
    5225           12 :           return error_mark_node;
    5226              :         }
    5227              : 
    5228        88376 :       if (parm_list
    5229        88376 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    5230              :         {
    5231            0 :           if (complain & tf_error)
    5232              :             {
    5233            0 :               auto_diagnostic_group d;
    5234            0 :               error ("template parameters do not match template %qD", tmpl);
    5235            0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    5236              :                       "%qD declared here", tmpl);
    5237            0 :             }
    5238            0 :           return error_mark_node;
    5239              :         }
    5240              : 
    5241        88376 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    5242              :                                           complain))
    5243            0 :         return error_mark_node;
    5244              : 
    5245              :       return tmpl;
    5246              :     }
    5247              : 
    5248        90825 :   return make_unbound_class_template_raw (context, name, parm_list);
    5249              : }
    5250              : 
    5251              : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    5252              : 
    5253              : tree
    5254        90877 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    5255              : {
    5256              :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    5257        90877 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    5258        90877 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    5259        90877 :   TREE_TYPE (t) = NULL_TREE;
    5260        90877 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    5261              : 
    5262              :   /* Build the corresponding TEMPLATE_DECL.  */
    5263        90877 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    5264        90877 :   TYPE_NAME (t) = d;
    5265        90877 :   TYPE_STUB_DECL (t) = d;
    5266        90877 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    5267        90877 :   DECL_ARTIFICIAL (d) = 1;
    5268        90877 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    5269              : 
    5270        90877 :   return t;
    5271              : }
    5272              : 
    5273              : 
    5274              : 
    5275              : /* Push the declarations of builtin types into the global namespace.
    5276              :    RID_INDEX is the index of the builtin type in the array
    5277              :    RID_POINTERS.  NAME is the name used when looking up the builtin
    5278              :    type.  TYPE is the _TYPE node for the builtin type.
    5279              : 
    5280              :    The calls to set_global_binding below should be
    5281              :    eliminated.  Built-in types should not be looked up name; their
    5282              :    names are keywords that the parser can recognize.  However, there
    5283              :    is code in c-common.cc that uses identifier_global_value to look up
    5284              :    built-in types by name.  */
    5285              : 
    5286              : void
    5287      4134046 : record_builtin_type (enum rid rid_index,
    5288              :                      const char* name,
    5289              :                      tree type)
    5290              : {
    5291      4134046 :   tree decl = NULL_TREE;
    5292              : 
    5293      4134046 :   if (name)
    5294              :     {
    5295      2439503 :       tree tname = get_identifier (name);
    5296      2439503 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    5297      2439503 :       DECL_ARTIFICIAL (tdecl) = 1;
    5298      2439503 :       set_global_binding (tdecl);
    5299      2439503 :       decl = tdecl;
    5300              :     }
    5301              : 
    5302      4134046 :   if ((int) rid_index < (int) RID_MAX)
    5303      2537947 :     if (tree rname = ridpointers[(int) rid_index])
    5304      1939873 :       if (!decl || DECL_NAME (decl) != rname)
    5305              :         {
    5306      1395506 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    5307      1395506 :           DECL_ARTIFICIAL (rdecl) = 1;
    5308      1395506 :           set_global_binding (rdecl);
    5309      1395506 :           if (!decl)
    5310              :             decl = rdecl;
    5311              :         }
    5312              : 
    5313      3835009 :   if (decl)
    5314              :     {
    5315      3535972 :       if (!TYPE_NAME (type))
    5316      2937898 :         TYPE_NAME (type) = decl;
    5317      3535972 :       debug_hooks->type_decl (decl, 0);
    5318              :     }
    5319      4134046 : }
    5320              : 
    5321              : /* Push a type into the namespace so that the back ends ignore it.  */
    5322              : 
    5323              : static void
    5324       299037 : record_unknown_type (tree type, const char* name)
    5325              : {
    5326       299037 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    5327              :                                     TYPE_DECL, get_identifier (name), type));
    5328              :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    5329       299037 :   DECL_IGNORED_P (decl) = 1;
    5330       299037 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    5331       299037 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    5332       299037 :   SET_TYPE_ALIGN (type, 1);
    5333       299037 :   TYPE_USER_ALIGN (type) = 0;
    5334       299037 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    5335       299037 : }
    5336              : 
    5337              : /* Create all the predefined identifiers.  */
    5338              : 
    5339              : static void
    5340        99679 : initialize_predefined_identifiers (void)
    5341              : {
    5342        99679 :   struct predefined_identifier
    5343              :   {
    5344              :     const char *name; /* Name.  */
    5345              :     tree *node;  /* Node to store it in.  */
    5346              :     cp_identifier_kind kind;  /* Kind of identifier.  */
    5347              :   };
    5348              : 
    5349              :   /* A table of identifiers to create at startup.  */
    5350        99679 :   static const predefined_identifier predefined_identifiers[] = {
    5351              :     {"C++", &lang_name_cplusplus, cik_normal},
    5352              :     {"C", &lang_name_c, cik_normal},
    5353              :     /* Some of these names have a trailing space so that it is
    5354              :        impossible for them to conflict with names written by users.  */
    5355              :     {"__ct ", &ctor_identifier, cik_ctor},
    5356              :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    5357              :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    5358              :     {"__dt ", &dtor_identifier, cik_dtor},
    5359              :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    5360              :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    5361              :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    5362              :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    5363              :     {"__in_chrg", &in_charge_identifier, cik_normal},
    5364              :     {"__as_base ", &as_base_identifier, cik_normal},
    5365              :     {"this", &this_identifier, cik_normal},
    5366              :     {"__delta", &delta_identifier, cik_normal},
    5367              :     {"__pfn", &pfn_identifier, cik_normal},
    5368              :     {"_vptr", &vptr_identifier, cik_normal},
    5369              :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    5370              :     {"::", &global_identifier, cik_normal},
    5371              :       /* The demangler expects anonymous namespaces to be called
    5372              :          something starting with '_GLOBAL__N_'.  It no longer needs
    5373              :          to be unique to the TU.  */
    5374              :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    5375              :     {"auto", &auto_identifier, cik_normal},
    5376              :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    5377              :     {"initializer_list", &init_list_identifier, cik_normal},
    5378              :     {"__for_range ", &for_range__identifier, cik_normal},
    5379              :     {"__for_begin ", &for_begin__identifier, cik_normal},
    5380              :     {"__for_end ", &for_end__identifier, cik_normal},
    5381              :     {"__for_range", &for_range_identifier, cik_normal},
    5382              :     {"__for_begin", &for_begin_identifier, cik_normal},
    5383              :     {"__for_end", &for_end_identifier, cik_normal},
    5384              :     {"abi_tag", &abi_tag_identifier, cik_normal},
    5385              :     {"aligned", &aligned_identifier, cik_normal},
    5386              :     {"begin", &begin_identifier, cik_normal},
    5387              :     {"end", &end_identifier, cik_normal},
    5388              :     {"get", &get__identifier, cik_normal},
    5389              :     {"gnu", &gnu_identifier, cik_normal},
    5390              :     {"tuple_element", &tuple_element_identifier, cik_normal},
    5391              :     {"tuple_size", &tuple_size_identifier, cik_normal},
    5392              :     {"type", &type_identifier, cik_normal},
    5393              :     {"value", &value_identifier, cik_normal},
    5394              :     {"_FUN", &fun_identifier, cik_normal},
    5395              :     {"__closure", &closure_identifier, cik_normal},
    5396              :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    5397              :     {"heap ", &heap_identifier, cik_normal},
    5398              :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    5399              :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    5400              :     {"heap []", &heap_vec_identifier, cik_normal},
    5401              :     {"omp", &omp_identifier, cik_normal},
    5402              :     {"internal ", &internal_identifier, cik_normal},
    5403              :     {"annotation ", &annotation_identifier, cik_normal},
    5404              :     {NULL, NULL, cik_normal}
    5405              :   };
    5406              : 
    5407      4884271 :   for (const predefined_identifier *pid = predefined_identifiers;
    5408      4884271 :        pid->name; ++pid)
    5409              :     {
    5410      4784592 :       *pid->node = get_identifier (pid->name);
    5411              :       /* Some of these identifiers already have a special kind.  */
    5412      4784592 :       if (pid->kind != cik_normal)
    5413       797432 :         set_identifier_kind (*pid->node, pid->kind);
    5414              :     }
    5415        99679 : }
    5416              : 
    5417              : /* Build a specific variant of operator new.  */
    5418              : 
    5419              : static void
    5420       178177 : cxx_build_operator_new (tree newtype)
    5421              : {
    5422       178177 :   tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    5423       178177 :   DECL_IS_MALLOC (opnew) = 1;
    5424       178177 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5425       178177 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5426       178177 :   opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    5427       178177 :   DECL_IS_MALLOC (opnew) = 1;
    5428       178177 :   DECL_SET_IS_OPERATOR_NEW (opnew, true);
    5429       178177 :   DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    5430       178177 : }
    5431              : 
    5432              : /* Build a specific variant of operator delete.  */
    5433              : 
    5434              : static void
    5435       336462 : cxx_build_operator_delete (tree deltype)
    5436              : {
    5437       336462 :   tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    5438       336462 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5439       336462 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5440       336462 :   opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    5441       336462 :   DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    5442       336462 :   DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    5443       336462 : }
    5444              : 
    5445              : /* Declare all variants of operator new and delete.  */
    5446              : 
    5447              : static void
    5448        99679 : cxx_init_operator_new_delete_decls (void)
    5449              : {
    5450        99679 :   tree newattrs, extvisattr;
    5451        99679 :   tree newtype, deltype;
    5452        99679 :   tree ptr_ftype_sizetype;
    5453        99679 :   tree new_eh_spec;
    5454        99679 :   tree void_ftype_ptr = build_function_type_list (void_type_node,
    5455              :                                                   ptr_type_node, NULL_TREE);
    5456        99679 :   void_ftype_ptr
    5457        99679 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    5458              : 
    5459        99679 :   ptr_ftype_sizetype
    5460        99679 :     = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    5461        99679 :   if (cxx_dialect == cxx98)
    5462              :     {
    5463        14185 :       tree bad_alloc_id;
    5464        14185 :       tree bad_alloc_type_node;
    5465        14185 :       tree bad_alloc_decl;
    5466              : 
    5467        14185 :       push_nested_namespace (std_node);
    5468        14185 :       bad_alloc_id = get_identifier ("bad_alloc");
    5469        14185 :       bad_alloc_type_node = make_class_type (RECORD_TYPE);
    5470        14185 :       TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    5471        14185 :       bad_alloc_decl
    5472        14185 :         = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    5473        14185 :       DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    5474        14185 :       pop_nested_namespace (std_node);
    5475              : 
    5476        14185 :       new_eh_spec
    5477        14185 :         = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    5478              :     }
    5479              :   else
    5480        85494 :     new_eh_spec = noexcept_false_spec;
    5481              : 
    5482        99679 :   extvisattr = build_tree_list (get_identifier ("externally_visible"),
    5483              :                                 NULL_TREE);
    5484        99679 :   newattrs = tree_cons (get_identifier ("alloc_size"),
    5485              :                         build_tree_list (NULL_TREE, integer_one_node),
    5486              :                         extvisattr);
    5487        99679 :   newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    5488        99679 :   newtype = build_exception_variant (newtype, new_eh_spec);
    5489        99679 :   deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    5490        99679 :   deltype = build_exception_variant (deltype, empty_except_spec);
    5491        99679 :   cxx_build_operator_new (newtype);
    5492        99679 :   cxx_build_operator_delete (deltype);
    5493        99679 :   if (flag_sized_deallocation)
    5494              :     {
    5495              :       /* Also push the sized deallocation variants:
    5496              :            void operator delete(void*, std::size_t) throw();
    5497              :            void operator delete[](void*, std::size_t) throw();  */
    5498        79792 :       tree void_ftype_ptr_size
    5499        79792 :         = build_function_type_list (void_type_node, ptr_type_node,
    5500              :                                     size_type_node, NULL_TREE);
    5501        79792 :       deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    5502              :                                                  extvisattr);
    5503        79792 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5504        79792 :       cxx_build_operator_delete (deltype);
    5505              :     }
    5506              : 
    5507        99679 :   if (aligned_new_threshold)
    5508              :     {
    5509        78498 :       push_nested_namespace (std_node);
    5510        78498 :       tree align_id = get_identifier ("align_val_t");
    5511        78498 :       align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    5512              :                                     NULL_TREE, /*scoped*/true, NULL);
    5513        78498 :       pop_nested_namespace (std_node);
    5514              : 
    5515              :       /* operator new (size_t, align_val_t); */
    5516        78498 :       newtype = build_function_type_list (ptr_type_node, size_type_node,
    5517              :                                           align_type_node, NULL_TREE);
    5518        78498 :       newtype = cp_build_type_attribute_variant (newtype, newattrs);
    5519        78498 :       newtype = build_exception_variant (newtype, new_eh_spec);
    5520        78498 :       cxx_build_operator_new (newtype);
    5521              : 
    5522              :       /* operator delete (void *, align_val_t); */
    5523        78498 :       deltype = build_function_type_list (void_type_node, ptr_type_node,
    5524              :                                           align_type_node, NULL_TREE);
    5525        78498 :       deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5526        78498 :       deltype = build_exception_variant (deltype, empty_except_spec);
    5527        78498 :       cxx_build_operator_delete (deltype);
    5528              : 
    5529        78498 :       if (flag_sized_deallocation)
    5530              :         {
    5531              :           /* operator delete (void *, size_t, align_val_t); */
    5532        78493 :           deltype = build_function_type_list (void_type_node, ptr_type_node,
    5533              :                                               size_type_node, align_type_node,
    5534              :                                               NULL_TREE);
    5535        78493 :           deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    5536        78493 :           deltype = build_exception_variant (deltype, empty_except_spec);
    5537        78493 :           cxx_build_operator_delete (deltype);
    5538              :         }
    5539              :     }
    5540        99679 : }
    5541              : 
    5542              : /* Create the predefined scalar types of C,
    5543              :    and some nodes representing standard constants (0, 1, (void *)0).
    5544              :    Initialize the global binding level.
    5545              :    Make definitions for built-in primitive functions.  */
    5546              : 
    5547              : void
    5548        99679 : cxx_init_decl_processing (void)
    5549              : {
    5550        99679 :   tree void_ftype;
    5551              : 
    5552              :   /* Create all the identifiers we need.  */
    5553        99679 :   initialize_predefined_identifiers ();
    5554              : 
    5555              :   /* Create the global variables.  */
    5556        99679 :   push_to_top_level ();
    5557              : 
    5558        99679 :   current_function_decl = NULL_TREE;
    5559        99679 :   current_binding_level = NULL;
    5560              :   /* Enter the global namespace.  */
    5561        99679 :   gcc_assert (global_namespace == NULL_TREE);
    5562        99679 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    5563              :                                       void_type_node);
    5564        99679 :   TREE_PUBLIC (global_namespace) = true;
    5565        99679 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    5566        99679 :   DECL_CONTEXT (global_namespace)
    5567        99679 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    5568              :   /* Remember whether we want the empty class passing ABI change warning
    5569              :      in this TU.  */
    5570        99679 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    5571       124289 :     = warn_abi && abi_version_crosses (12);
    5572        99679 :   debug_hooks->register_main_translation_unit
    5573        99679 :     (DECL_CONTEXT (global_namespace));
    5574        99679 :   begin_scope (sk_namespace, global_namespace);
    5575        99679 :   current_namespace = global_namespace;
    5576              : 
    5577        99679 :   if (flag_visibility_ms_compat)
    5578            6 :     default_visibility = VISIBILITY_HIDDEN;
    5579              : 
    5580              :   /* Initially, C.  */
    5581        99679 :   current_lang_name = lang_name_c;
    5582              : 
    5583              :   /* Create the `std' namespace.  */
    5584        99679 :   push_namespace (get_identifier ("std"));
    5585        99679 :   std_node = current_namespace;
    5586        99679 :   pop_namespace ();
    5587              : 
    5588        99679 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    5589              : 
    5590        99679 :   c_common_nodes_and_builtins ();
    5591              : 
    5592              :   /* Call the target stack_protect_guard hook if the stack protection
    5593              :      guard is declared as a global symbol.  */
    5594        99679 :   if (targetm.stack_protect_guard_symbol_p ())
    5595           24 :     pushdecl (targetm.stack_protect_guard ());
    5596              : 
    5597        99679 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    5598        99679 :   tree decl
    5599        99679 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    5600              :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    5601              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5602        99679 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5603              : 
    5604              :   /* The concrete return type of __builtin_source_location is
    5605              :      const std::source_location::__impl*, but we can't form the type
    5606              :      at this point.  So we initially declare it with an auto return
    5607              :      type which we then "deduce" from require_deduced_type upon first use.  */
    5608        99679 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    5609        99679 :   decl = add_builtin_function ("__builtin_source_location",
    5610              :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    5611              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5612        99679 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5613              : 
    5614        99679 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    5615              :                                                         NULL_TREE);
    5616        99679 :   decl
    5617        99679 :     = add_builtin_function ("__builtin_is_corresponding_member",
    5618              :                             bool_vaftype,
    5619              :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    5620              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5621        99679 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5622              : 
    5623        99679 :   decl
    5624        99679 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    5625              :                             bool_vaftype,
    5626              :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    5627              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5628        99679 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5629              : 
    5630        99679 :   if (cxx_dialect >= cxx26)
    5631              :     {
    5632        24817 :       tree void_ptrintftype
    5633        24817 :         = build_function_type_list (void_type_node, ptr_type_node,
    5634              :                                     integer_type_node, NULL_TREE);
    5635        24817 :       decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
    5636              :                                    void_ptrintftype,
    5637              :                                    CP_BUILT_IN_EH_PTR_ADJUST_REF,
    5638              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5639        24817 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5640              : 
    5641              :       /* Similar case to __builtin_source_location above.  The concrete
    5642              :          return type is std::exception_ptr, but we can't form the type
    5643              :          at this point, so it is deduced later.  */
    5644        24817 :       decl = add_builtin_function ("__builtin_current_exception",
    5645              :                                    auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
    5646              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5647        24817 :       set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5648              : 
    5649        24817 :       tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
    5650        24817 :       decl = add_builtin_function ("__builtin_uncaught_exceptions",
    5651              :                                    int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
    5652              :                                    BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5653        24817 :       set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
    5654              :     }
    5655              : 
    5656        99679 :   decl
    5657        99679 :     = add_builtin_function ("__builtin_is_string_literal",
    5658              :                             bool_vaftype,
    5659              :                             CP_BUILT_IN_IS_STRING_LITERAL,
    5660              :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5661        99679 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    5662              : 
    5663        99679 :   tree void_vaintftype = build_varargs_function_type_list (void_type_node,
    5664              :                                                            integer_type_node,
    5665              :                                                            NULL_TREE);
    5666        99679 :   decl = add_builtin_function ("__builtin_constexpr_diag",
    5667              :                                void_vaintftype,
    5668              :                                CP_BUILT_IN_CONSTEXPR_DIAG,
    5669              :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    5670        99679 :   set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
    5671              : 
    5672        99679 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    5673              : 
    5674              :   /* Guess at the initial static decls size.  */
    5675        99679 :   vec_alloc (static_decls, 500);
    5676              : 
    5677              :   /* ... and keyed classes.  */
    5678        99679 :   vec_alloc (keyed_classes, 100);
    5679              : 
    5680        99679 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    5681        99679 :   truthvalue_type_node = boolean_type_node;
    5682        99679 :   truthvalue_false_node = boolean_false_node;
    5683        99679 :   truthvalue_true_node = boolean_true_node;
    5684              : 
    5685        99679 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    5686        99679 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    5687        99679 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    5688        99679 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    5689              :                                             NULL_TREE);
    5690              : 
    5691              : #if 0
    5692              :   record_builtin_type (RID_MAX, NULL, string_type_node);
    5693              : #endif
    5694              : 
    5695        99679 :   delta_type_node = ptrdiff_type_node;
    5696        99679 :   vtable_index_type = ptrdiff_type_node;
    5697              : 
    5698        99679 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    5699        99679 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    5700              : 
    5701              :   /* Create the conversion operator marker.  This operator's DECL_NAME
    5702              :      is in the identifier table, so we can use identifier equality to
    5703              :      find it.  */
    5704        99679 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    5705              :                                     void_ftype);
    5706              : 
    5707              :   /* C++ extensions */
    5708              : 
    5709        99679 :   unknown_type_node = make_node (LANG_TYPE);
    5710        99679 :   record_unknown_type (unknown_type_node, "unknown type");
    5711              : 
    5712              :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    5713        99679 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    5714              : 
    5715              :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    5716              :      result.  */
    5717        99679 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    5718        99679 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    5719              : 
    5720        99679 :   init_list_type_node = make_node (LANG_TYPE);
    5721        99679 :   record_unknown_type (init_list_type_node, "init list");
    5722              : 
    5723              :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    5724        99679 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    5725              : 
    5726        99679 :   {
    5727              :     /* Make sure we get a unique function type, so we can give
    5728              :        its pointer type a name.  (This wins for gdb.) */
    5729        99679 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    5730        99679 :     TREE_TYPE (vfunc_type) = integer_type_node;
    5731        99679 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    5732        99679 :     layout_type (vfunc_type);
    5733              : 
    5734        99679 :     vtable_entry_type = build_pointer_type (vfunc_type);
    5735              :   }
    5736        99679 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    5737              : 
    5738        99679 :   vtbl_type_node
    5739        99679 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    5740        99679 :   layout_type (vtbl_type_node);
    5741        99679 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    5742        99679 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    5743        99679 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    5744        99679 :   layout_type (vtbl_ptr_type_node);
    5745        99679 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    5746              : 
    5747        99679 :   push_namespace (get_identifier ("__cxxabiv1"));
    5748        99679 :   abi_node = current_namespace;
    5749        99679 :   pop_namespace ();
    5750              : 
    5751        99679 :   any_targ_node = make_node (LANG_TYPE);
    5752        99679 :   record_unknown_type (any_targ_node, "any type");
    5753              : 
    5754              :   /* Now, C++.  */
    5755        99679 :   current_lang_name = lang_name_cplusplus;
    5756              : 
    5757        99679 :   if (aligned_new_threshold > 1
    5758        99679 :       && !pow2p_hwi (aligned_new_threshold))
    5759              :     {
    5760            0 :       error ("%<-faligned-new=%d%> is not a power of two",
    5761              :              aligned_new_threshold);
    5762            0 :       aligned_new_threshold = 1;
    5763              :     }
    5764        99679 :   if (aligned_new_threshold == -1)
    5765       120846 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    5766        99679 :   if (aligned_new_threshold == 1)
    5767        78495 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    5768              : 
    5769              :   /* Ensure attribs.cc is initialized.  */
    5770        99679 :   init_attributes ();
    5771        99679 :   cxx_init_operator_new_delete_decls ();
    5772              : 
    5773              :   /* C++-specific nullptr initialization.  */
    5774        99679 :   if (abi_version_at_least (9))
    5775        99508 :     SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    5776        99679 :   record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    5777              : 
    5778        99679 :   if (! supports_one_only ())
    5779            0 :     flag_weak = 0;
    5780              : 
    5781        99679 :   abort_fndecl
    5782        99679 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    5783              :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    5784        99679 :   if (flag_weak)
    5785              :     /* If no definition is available, resolve references to NULL.  */
    5786        99649 :     declare_weak (abort_fndecl);
    5787              : 
    5788              :   /* Perform other language dependent initializations.  */
    5789        99679 :   init_class_processing ();
    5790        99679 :   init_rtti_processing ();
    5791        99679 :   init_template_processing ();
    5792              : 
    5793        99679 :   if (flag_exceptions)
    5794        98422 :     init_exception_processing ();
    5795              : 
    5796        99679 :   if (flag_contracts)
    5797        24863 :     init_contracts ();
    5798              : 
    5799        99679 :   if (modules_p ())
    5800         4929 :     init_modules (parse_in);
    5801              : 
    5802        99679 :   if (flag_reflection)
    5803         1235 :     init_reflection ();
    5804              : 
    5805        99679 :   make_fname_decl = cp_make_fname_decl;
    5806        99679 :   start_fname_decls ();
    5807              : 
    5808              :   /* Show we use EH for cleanups.  */
    5809        99679 :   if (flag_exceptions)
    5810        98422 :     using_eh_for_cleanups ();
    5811              : 
    5812              :   /* Check that the hardware interference sizes are at least
    5813              :      alignof(max_align_t), as required by the standard.  */
    5814        99679 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    5815        99679 :   if (OPTION_SET_P (param_destruct_interfere_size))
    5816              :     {
    5817            0 :       if (param_destruct_interfere_size < max_align)
    5818            0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    5819              :                "%d", param_destruct_interfere_size, max_align);
    5820            0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    5821            0 :         warning (OPT_Winterference_size,
    5822              :                  "%<--param destructive-interference-size=%d%> "
    5823              :                  "is less than %<--param l1-cache-line-size=%d%>",
    5824              :                  param_destruct_interfere_size, param_l1_cache_line_size);
    5825              :     }
    5826        99679 :   else if (param_destruct_interfere_size)
    5827              :     /* Assume the internal value is OK.  */;
    5828            0 :   else if (param_l1_cache_line_size >= max_align)
    5829            0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    5830              :   /* else leave it unset.  */
    5831              : 
    5832        99679 :   if (OPTION_SET_P (param_construct_interfere_size))
    5833              :     {
    5834            0 :       if (param_construct_interfere_size < max_align)
    5835            0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    5836              :                "%d", param_construct_interfere_size, max_align);
    5837            0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    5838            0 :                && param_l1_cache_line_size >= max_align)
    5839            0 :         warning (OPT_Winterference_size,
    5840              :                  "%<--param constructive-interference-size=%d%> "
    5841              :                  "is greater than %<--param l1-cache-line-size=%d%>",
    5842              :                  param_construct_interfere_size, param_l1_cache_line_size);
    5843              :     }
    5844        99679 :   else if (param_construct_interfere_size)
    5845              :     /* Assume the internal value is OK.  */;
    5846            0 :   else if (param_l1_cache_line_size >= max_align)
    5847            0 :     param_construct_interfere_size = param_l1_cache_line_size;
    5848        99679 : }
    5849              : 
    5850              : /* Enter an abi node in global-module context.  returns a cookie to
    5851              :    give to pop_abi_namespace.  */
    5852              : 
    5853              : unsigned
    5854        56975 : push_abi_namespace (tree node)
    5855              : {
    5856        56975 :   push_nested_namespace (node);
    5857        56975 :   push_visibility ("default", 2);
    5858        56975 :   unsigned flags = module_kind;
    5859        56975 :   module_kind = 0;
    5860        56975 :   return flags;
    5861              : }
    5862              : 
    5863              : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5864              :    you.  */
    5865              : 
    5866              : void
    5867        56975 : pop_abi_namespace (unsigned flags, tree node)
    5868              : {
    5869        56975 :   module_kind = flags;
    5870        56975 :   pop_visibility (2);
    5871        56975 :   pop_nested_namespace (node);
    5872        56975 : }
    5873              : 
    5874              : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5875              :    the decl, LOC is the location to give the decl, NAME is the
    5876              :    initialization string and TYPE_DEP indicates whether NAME depended
    5877              :    on the type of the function. We make use of that to detect
    5878              :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5879              :    at the point of first use, so we mustn't push the decl now.  */
    5880              : 
    5881              : static tree
    5882       225768 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5883              : {
    5884       225768 :   tree domain = NULL_TREE;
    5885       225768 :   tree init = NULL_TREE;
    5886              : 
    5887       225768 :   if (!(type_dep && current_function_decl && in_template_context))
    5888              :     {
    5889        56562 :       const char *name = NULL;
    5890        56562 :       bool release_name = false;
    5891              : 
    5892        56562 :       if (current_function_decl == NULL_TREE)
    5893              :         name = "top level";
    5894        56548 :       else if (type_dep == 0)
    5895              :         {
    5896              :           /* __FUNCTION__ */
    5897          594 :           name = fname_as_string (type_dep);
    5898          594 :           release_name = true;
    5899              :         }
    5900              :       else
    5901              :         {
    5902              :           /* __PRETTY_FUNCTION__ */
    5903        55954 :           gcc_checking_assert (type_dep == 1);
    5904        55954 :           name = cxx_printable_name (current_function_decl, 2);
    5905              :         }
    5906              : 
    5907        56548 :       if (!release_name)
    5908              :         {
    5909        55968 :           cpp_string cstr = { 0, 0 }, strname;
    5910        55968 :           strname.text
    5911        55968 :             = const_cast <unsigned char *> ((const unsigned char *) name);
    5912        55968 :           strname.len = strlen (name) + 1;
    5913        55968 :           if (cpp_translate_string (parse_in, &strname, &cstr, CPP_STRING,
    5914              :                                     false))
    5915              :             {
    5916        55968 :               name = (const char *) cstr.text;
    5917        55968 :               release_name = true;
    5918              :             }
    5919              :         }
    5920              : 
    5921        56562 :       size_t length = strlen (name);
    5922        56562 :       domain = build_index_type (size_int (length));
    5923        56562 :       init = build_string (length + 1, name);
    5924        56562 :       if (release_name)
    5925        56562 :         free (const_cast<char *> (name));
    5926              :     }
    5927              : 
    5928       225768 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5929       225768 :   type = build_cplus_array_type (type, domain);
    5930              : 
    5931       225768 :   if (init)
    5932        56562 :     TREE_TYPE (init) = type;
    5933              :   else
    5934       169206 :     init = error_mark_node;
    5935              : 
    5936       225768 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5937              : 
    5938       225768 :   TREE_READONLY (decl) = 1;
    5939       225768 :   DECL_ARTIFICIAL (decl) = 1;
    5940       225768 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5941       225768 :   TREE_STATIC (decl) = 1;
    5942              : 
    5943       225768 :   TREE_USED (decl) = 1;
    5944              : 
    5945       225768 :   SET_DECL_VALUE_EXPR (decl, init);
    5946       225768 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5947              :   /* For decl_constant_var_p.  */
    5948       225768 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5949              : 
    5950       225768 :   if (current_function_decl)
    5951              :     {
    5952       225754 :       DECL_CONTEXT (decl) = current_function_decl;
    5953       225754 :       decl = pushdecl_outermost_localscope (decl);
    5954       225754 :       if (decl != error_mark_node)
    5955       225751 :         add_decl_expr (decl);
    5956              :       else
    5957            3 :         gcc_assert (seen_error ());
    5958              :     }
    5959              :   else
    5960              :     {
    5961           14 :       DECL_THIS_STATIC (decl) = true;
    5962           14 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5963              :     }
    5964              : 
    5965       225768 :   return decl;
    5966              : }
    5967              : 
    5968              : /* Install DECL as a builtin function at current global scope.  Return
    5969              :    the new decl (if we found an existing version).  Also installs it
    5970              :    into ::std, if it's not '_*'.  */
    5971              : 
    5972              : tree
    5973    231309671 : cxx_builtin_function (tree decl)
    5974              : {
    5975    231309671 :   retrofit_lang_decl (decl);
    5976              : 
    5977    231309671 :   DECL_ARTIFICIAL (decl) = 1;
    5978    231309671 :   SET_DECL_LANGUAGE (decl, lang_c);
    5979              :   /* Runtime library routines are, by definition, available in an
    5980              :      external shared object.  */
    5981    231309671 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5982    231309671 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5983              : 
    5984    231309671 :   tree id = DECL_NAME (decl);
    5985    231309671 :   const char *name = IDENTIFIER_POINTER (id);
    5986    231309671 :   bool hiding = false;
    5987    231309671 :   if (name[0] != '_' || name[1] != '_')
    5988              :     /* In the user's namespace, it must be declared before use.  */
    5989              :     hiding = true;
    5990    194117179 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5991    194117179 :            && !startswith (name + 2, "builtin_")
    5992    217287880 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5993              :                            "_chk", strlen ("_chk") + 1))
    5994              :     /* Treat __*_chk fortification functions as anticipated as well,
    5995              :        unless they are __builtin_*_chk.  */
    5996              :     hiding = true;
    5997              : 
    5998              :   /* All builtins that don't begin with an '_' should additionally
    5999              :      go in the 'std' namespace.  */
    6000    231309671 :   if (name[0] != '_')
    6001              :     {
    6002     37056882 :       tree std_decl = copy_decl (decl);
    6003              : 
    6004     37056882 :       push_nested_namespace (std_node);
    6005     37056882 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    6006     37056882 :       pushdecl (std_decl, hiding);
    6007     37056882 :       pop_nested_namespace (std_node);
    6008              :     }
    6009              : 
    6010    231309671 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6011    231309671 :   decl = pushdecl (decl, hiding);
    6012              : 
    6013    231309671 :   return decl;
    6014              : }
    6015              : 
    6016              : /* Like cxx_builtin_function, but guarantee the function is added to the global
    6017              :    scope.  This is to allow function specific options to add new machine
    6018              :    dependent builtins when the target ISA changes via attribute((target(...)))
    6019              :    which saves space on program startup if the program does not use non-generic
    6020              :    ISAs.  */
    6021              : 
    6022              : tree
    6023       764537 : cxx_builtin_function_ext_scope (tree decl)
    6024              : {
    6025       764537 :   push_nested_namespace (global_namespace);
    6026       764537 :   decl = cxx_builtin_function (decl);
    6027       764537 :   pop_nested_namespace (global_namespace);
    6028              : 
    6029       764537 :   return decl;
    6030              : }
    6031              : 
    6032              : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    6033              : 
    6034              : tree
    6035            0 : cxx_simulate_builtin_function_decl (tree decl)
    6036              : {
    6037            0 :   retrofit_lang_decl (decl);
    6038              : 
    6039            0 :   DECL_ARTIFICIAL (decl) = 1;
    6040            0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    6041            0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    6042            0 :   return pushdecl (decl);
    6043              : }
    6044              : 
    6045              : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    6046              :    function.  Not called directly.  */
    6047              : 
    6048              : static tree
    6049      1605641 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    6050              :                   int ecf_flags)
    6051              : {
    6052      1605641 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    6053      1605641 :   DECL_EXTERNAL (fn) = 1;
    6054      1605641 :   TREE_PUBLIC (fn) = 1;
    6055      1605641 :   DECL_ARTIFICIAL (fn) = 1;
    6056      1605641 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    6057      1605641 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    6058      1605641 :   SET_DECL_LANGUAGE (fn, lang_c);
    6059              :   /* Runtime library routines are, by definition, available in an
    6060              :      external shared object.  */
    6061      1605641 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    6062      1605641 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    6063      1605641 :   set_call_expr_flags (fn, ecf_flags);
    6064      1605641 :   return fn;
    6065              : }
    6066              : 
    6067              : /* Returns the _DECL for a library function with C++ linkage.  */
    6068              : 
    6069              : static tree
    6070      1127940 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    6071              :                      int ecf_flags)
    6072              : {
    6073      1127940 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    6074      1127940 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    6075      1127940 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    6076      1127940 :   return fn;
    6077              : }
    6078              : 
    6079              : /* Like build_library_fn, but takes a C string instead of an
    6080              :    IDENTIFIER_NODE.  */
    6081              : 
    6082              : tree
    6083       104352 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6084              : {
    6085       104352 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    6086              : }
    6087              : 
    6088              : /* Like build_cp_library_fn, but takes a C string instead of an
    6089              :    IDENTIFIER_NODE.  */
    6090              : 
    6091              : tree
    6092        98662 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    6093              : {
    6094        98662 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    6095        98662 :                               ecf_flags);
    6096              : }
    6097              : 
    6098              : /* Like build_library_fn, but also pushes the function so that we will
    6099              :    be able to find it via get_global_binding.  Also, the function
    6100              :    may throw exceptions listed in RAISES.  */
    6101              : 
    6102              : tree
    6103       373349 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    6104              : {
    6105       373349 :   if (raises)
    6106        41585 :     type = build_exception_variant (type, raises);
    6107              : 
    6108       373349 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    6109       373349 :   return pushdecl_top_level (fn);
    6110              : }
    6111              : 
    6112              : /* Like build_cp_library_fn, but also pushes the function so that it
    6113              :    will be found by normal lookup.  */
    6114              : 
    6115              : static tree
    6116      1029278 : push_cp_library_fn (enum tree_code operator_code, tree type,
    6117              :                     int ecf_flags)
    6118              : {
    6119      1029278 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    6120              :                                  operator_code, type, ecf_flags);
    6121      1029278 :   pushdecl (fn);
    6122      1029278 :   if (flag_tm)
    6123         3100 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    6124      1029278 :   return fn;
    6125              : }
    6126              : 
    6127              : /* Like push_library_fn, but also note that this function throws
    6128              :    and does not return.  Used for __throw_foo and the like.  */
    6129              : 
    6130              : tree
    6131       109037 : push_throw_library_fn (tree name, tree type)
    6132              : {
    6133       109037 :   tree fn = push_library_fn (name, type, NULL_TREE,
    6134              :                              ECF_NORETURN | ECF_XTHROW | ECF_COLD);
    6135       109037 :   return fn;
    6136              : }
    6137              : 
    6138              : /* When we call finish_struct for an anonymous union, we create
    6139              :    default copy constructors and such.  But, an anonymous union
    6140              :    shouldn't have such things; this function undoes the damage to the
    6141              :    anonymous union type T.
    6142              : 
    6143              :    (The reason that we create the synthesized methods is that we don't
    6144              :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    6145              :    The first is an anonymous union; the second is just an ordinary
    6146              :    union type.)  */
    6147              : 
    6148              : void
    6149       171536 : fixup_anonymous_aggr (tree t)
    6150              : {
    6151              :   /* Wipe out memory of synthesized methods.  */
    6152       171536 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    6153       171536 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    6154       171536 :   TYPE_HAS_COPY_CTOR (t) = 0;
    6155       171536 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    6156       171536 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    6157       171536 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    6158              : 
    6159              :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    6160              :      invalid members.  */
    6161      1003743 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    6162              :     {
    6163       832207 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    6164            0 :         *prev_p = DECL_CHAIN (probe);
    6165              :       else
    6166       832207 :         prev_p = &DECL_CHAIN (probe);
    6167              : 
    6168       832207 :       if (DECL_ARTIFICIAL (probe)
    6169       832207 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    6170        74834 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    6171       281820 :         continue;
    6172              : 
    6173       550387 :       if (TREE_CODE (probe) != FIELD_DECL
    6174       550333 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    6175              :         {
    6176              :           /* We already complained about static data members in
    6177              :              finish_static_data_member_decl.  */
    6178           66 :           if (!VAR_P (probe))
    6179              :             {
    6180           51 :               auto_diagnostic_group d;
    6181           51 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    6182           51 :                              TREE_CODE (t) == UNION_TYPE
    6183              :                              ? "%q#D invalid; an anonymous union may "
    6184              :                              "only have public non-static data members"
    6185              :                              : "%q#D invalid; an anonymous struct may "
    6186              :                              "only have public non-static data members", probe))
    6187              :                 {
    6188           51 :                   static bool hint;
    6189           51 :                   if (flag_permissive && !hint)
    6190              :                     {
    6191            6 :                       hint = true;
    6192            6 :                       inform (DECL_SOURCE_LOCATION (probe),
    6193              :                               "this flexibility is deprecated and will be "
    6194              :                               "removed");
    6195              :                     }
    6196              :                 }
    6197           51 :             }
    6198              :         }
    6199              :       }
    6200              : 
    6201              :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    6202       171536 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    6203       171536 :   unsigned store = 0;
    6204       510954 :   for (tree elt : vec)
    6205       339418 :     if (!is_overloaded_fn (elt))
    6206       339397 :       (*vec)[store++] = elt;
    6207       171536 :   vec_safe_truncate (vec, store);
    6208              : 
    6209              :   /* Wipe RTTI info.  */
    6210       171536 :   SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
    6211              : 
    6212              :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    6213              :      assignment operators (because they cannot have these methods themselves).
    6214              :      For anonymous unions this is already checked because they are not allowed
    6215              :      in any union, otherwise we have to check it.  */
    6216       171536 :   if (TREE_CODE (t) != UNION_TYPE)
    6217              :     {
    6218        36709 :       tree field, type;
    6219              : 
    6220        36709 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    6221              :         {
    6222            9 :           error_at (location_of (t), "anonymous struct with base classes");
    6223              :           /* Avoid ICE after error on anon-struct9.C.  */
    6224            9 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    6225              :         }
    6226              : 
    6227       147672 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    6228       110963 :         if (TREE_CODE (field) == FIELD_DECL)
    6229              :           {
    6230        74153 :             type = TREE_TYPE (field);
    6231        74153 :             if (CLASS_TYPE_P (type))
    6232              :               {
    6233           61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    6234            6 :                   error ("member %q+#D with constructor not allowed "
    6235              :                          "in anonymous aggregate", field);
    6236           61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    6237            0 :                   error ("member %q+#D with destructor not allowed "
    6238              :                          "in anonymous aggregate", field);
    6239           61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    6240            0 :                   error ("member %q+#D with copy assignment operator "
    6241              :                          "not allowed in anonymous aggregate", field);
    6242              :               }
    6243              :           }
    6244              :     }
    6245       171536 : }
    6246              : 
    6247              : /* Warn for an attribute located at LOCATION that appertains to the
    6248              :    class type CLASS_TYPE that has not been properly placed after its
    6249              :    class-key, in it class-specifier.  */
    6250              : 
    6251              : void
    6252          111 : warn_misplaced_attr_for_class_type (location_t location,
    6253              :                                     tree class_type)
    6254              : {
    6255          111 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    6256              : 
    6257          111 :   auto_diagnostic_group d;
    6258          111 :   if (warning_at (location, OPT_Wattributes,
    6259              :                   "attribute ignored in declaration "
    6260              :                   "of %q#T", class_type))
    6261          111 :     inform (location,
    6262              :             "attribute for %q#T must follow the %qs keyword",
    6263              :             class_type, class_key_or_enum_as_string (class_type));
    6264          111 : }
    6265              : 
    6266              : /* Returns the cv-qualifiers that apply to the type specified
    6267              :    by the DECLSPECS.  */
    6268              : 
    6269              : static int
    6270   1029186442 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    6271              : {
    6272   1029186442 :   int type_quals = TYPE_UNQUALIFIED;
    6273              : 
    6274   1029186442 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6275    106562262 :     type_quals |= TYPE_QUAL_CONST;
    6276   1029186442 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6277      1722588 :     type_quals |= TYPE_QUAL_VOLATILE;
    6278   1029186442 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6279           34 :     type_quals |= TYPE_QUAL_RESTRICT;
    6280              : 
    6281   1029186442 :   return type_quals;
    6282              : }
    6283              : 
    6284              : /* Make sure that a declaration with no declarator is well-formed, i.e.
    6285              :    just declares a tagged type or anonymous union.
    6286              : 
    6287              :    Returns the type declared; or NULL_TREE if none.  */
    6288              : 
    6289              : tree
    6290     37069384 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    6291              :                 bool explicit_type_instantiation_p)
    6292              : {
    6293     37069384 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    6294     37069384 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    6295              :   /* If a class, struct, or enum type is declared by the DECLSPECS
    6296              :      (i.e, if a class-specifier, enum-specifier, or non-typename
    6297              :      elaborated-type-specifier appears in the DECLSPECS),
    6298              :      DECLARED_TYPE is set to the corresponding type.  */
    6299     37069384 :   tree declared_type = NULL_TREE;
    6300     37069384 :   bool error_p = false;
    6301              : 
    6302     37069384 :   if (declspecs->multiple_types_p)
    6303           26 :     error_at (smallest_type_location (declspecs),
    6304              :               "multiple types in one declaration");
    6305     37069358 :   else if (declspecs->redefined_builtin_type)
    6306              :     {
    6307           21 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    6308           21 :       if (!in_system_header_at (loc))
    6309            9 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    6310              :                    declspecs->redefined_builtin_type);
    6311           21 :       return NULL_TREE;
    6312              :     }
    6313              : 
    6314     37069363 :   if (declspecs->type
    6315     37069348 :       && TYPE_P (declspecs->type)
    6316     73786623 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    6317     36716471 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    6318      1859119 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    6319              :     declared_type = declspecs->type;
    6320       352937 :   else if (declspecs->type == error_mark_node)
    6321         1502 :     error_p = true;
    6322              : 
    6323     37069363 :   if (type_uses_auto (declared_type))
    6324              :     {
    6325            8 :       error_at (declspecs->locations[ds_type_spec],
    6326              :                 "%<auto%> can only be specified for variables "
    6327              :                 "or function declarations");
    6328            8 :       return error_mark_node;
    6329              :     }
    6330              : 
    6331     37069355 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    6332              :     declared_type = NULL_TREE;
    6333              : 
    6334     37069355 :   if (!declared_type && !saw_friend && !error_p)
    6335           91 :     permerror (input_location, "declaration does not declare anything");
    6336              :   /* Check for an anonymous union.  */
    6337     36716391 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    6338    106957018 :            && TYPE_UNNAMED_P (declared_type))
    6339              :     {
    6340              :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    6341              :          can be omitted only when declaring a class (clause 9) or
    6342              :          enumeration (7.2), that is, when the decl-specifier-seq contains
    6343              :          either a class-specifier, an elaborated-type-specifier with
    6344              :          a class-key (9.1), or an enum-specifier.  In these cases and
    6345              :          whenever a class-specifier or enum-specifier is present in the
    6346              :          decl-specifier-seq, the identifiers in these specifiers are among
    6347              :          the names being declared by the declaration (as class-name,
    6348              :          enum-names, or enumerators, depending on the syntax).  In such
    6349              :          cases, and except for the declaration of an unnamed bit-field (9.6),
    6350              :          the decl-specifier-seq shall introduce one or more names into the
    6351              :          program, or shall redeclare a name introduced by a previous
    6352              :          declaration.  [Example:
    6353              :              enum { };                  // ill-formed
    6354              :              typedef class { };         // ill-formed
    6355              :          --end example]  */
    6356       171542 :       if (saw_typedef)
    6357              :         {
    6358            6 :           error_at (declspecs->locations[ds_typedef],
    6359              :                     "missing type-name in typedef-declaration");
    6360            6 :           return NULL_TREE;
    6361              :         }
    6362       171536 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    6363       171536 :       SET_ANON_AGGR_TYPE_P (declared_type);
    6364              : 
    6365       171536 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    6366        36709 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    6367        36709 :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    6368              :     }
    6369              : 
    6370              :   else
    6371              :     {
    6372     36897722 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    6373            9 :         error_at (declspecs->locations[ds_inline],
    6374              :                   "%<inline%> can only be specified for functions");
    6375     36897713 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    6376            3 :         error_at (declspecs->locations[ds_virtual],
    6377              :                   "%<virtual%> can only be specified for functions");
    6378     36897710 :       else if (saw_friend
    6379     36897710 :                && (!current_class_type
    6380      2049179 :                    || current_scope () != current_class_type))
    6381            0 :         error_at (declspecs->locations[ds_friend],
    6382              :                   "%<friend%> can only be specified inside a class");
    6383     36897710 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    6384            3 :         error_at (declspecs->locations[ds_explicit],
    6385              :                   "%<explicit%> can only be specified for constructors");
    6386     36897707 :       else if (declspecs->storage_class)
    6387            3 :         error_at (declspecs->locations[ds_storage_class],
    6388              :                   "a storage class can only be specified for objects "
    6389              :                   "and functions");
    6390     36897704 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    6391            9 :         error_at (declspecs->locations[ds_const],
    6392              :                   "%<const%> can only be specified for objects and "
    6393              :                   "functions");
    6394     36897695 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    6395            3 :         error_at (declspecs->locations[ds_volatile],
    6396              :                   "%<volatile%> can only be specified for objects and "
    6397              :                   "functions");
    6398     36897692 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    6399            3 :         error_at (declspecs->locations[ds_restrict],
    6400              :                   "%<__restrict%> can only be specified for objects and "
    6401              :                   "functions");
    6402     36897689 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    6403            3 :         error_at (declspecs->locations[ds_thread],
    6404              :                   "%<__thread%> can only be specified for objects "
    6405              :                   "and functions");
    6406     36897686 :       else if (saw_typedef)
    6407           24 :         warning_at (declspecs->locations[ds_typedef], 0,
    6408              :                     "%<typedef%> was ignored in this declaration");
    6409     36897662 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    6410            9 :         error_at (declspecs->locations[ds_constexpr],
    6411              :                   "%qs cannot be used for type declarations", "constexpr");
    6412     36897653 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    6413            3 :         error_at (declspecs->locations[ds_constinit],
    6414              :                   "%qs cannot be used for type declarations", "constinit");
    6415     36897650 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    6416            3 :         error_at (declspecs->locations[ds_consteval],
    6417              :                   "%qs cannot be used for type declarations", "consteval");
    6418              :     }
    6419              : 
    6420     37069349 :   if (declspecs->attributes && warn_attributes && declared_type)
    6421              :     {
    6422           30 :       location_t loc;
    6423           24 :       if (!CLASS_TYPE_P (declared_type)
    6424           54 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    6425              :         /* For a non-template class, use the name location.  */
    6426           21 :         loc = location_of (declared_type);
    6427              :       else
    6428              :         /* For a template class (an explicit instantiation), use the
    6429              :            current location.  */
    6430            9 :         loc = input_location;
    6431              : 
    6432           30 :       if (explicit_type_instantiation_p)
    6433              :         /* [dcl.attr.grammar]/4:
    6434              : 
    6435              :                No attribute-specifier-seq shall appertain to an explicit
    6436              :                instantiation.  */
    6437              :         {
    6438            6 :           auto_diagnostic_group d;
    6439            6 :           if (warning_at (loc, OPT_Wattributes,
    6440              :                           "attribute ignored in explicit instantiation %q#T",
    6441              :                           declared_type))
    6442            6 :             inform (loc,
    6443              :                     "no attribute can be applied to "
    6444              :                     "an explicit instantiation");
    6445            6 :         }
    6446              :       else
    6447           24 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    6448              :     }
    6449              : 
    6450     37069349 :   if (declspecs->std_attributes
    6451           87 :       && declared_type
    6452     37069433 :       && any_nonignored_attribute_p (declspecs->std_attributes))
    6453              :     {
    6454           84 :       auto_diagnostic_group d;
    6455           84 :       if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
    6456              :                       "attribute ignored"))
    6457           84 :         inform (declspecs->locations[ds_std_attribute],
    6458              :                 "an attribute that appertains to a type-specifier is ignored");
    6459           84 :     }
    6460              : 
    6461              :   return declared_type;
    6462              : }
    6463              : 
    6464              : /* Called when a declaration is seen that contains no names to declare.
    6465              :    If its type is a reference to a structure, union or enum inherited
    6466              :    from a containing scope, shadow that tag name for the current scope
    6467              :    with a forward reference.
    6468              :    If its type defines a new named structure or union
    6469              :    or defines an enum, it is valid but we need not do anything here.
    6470              :    Otherwise, it is an error.
    6471              : 
    6472              :    C++: may have to grok the declspecs to learn about static,
    6473              :    complain for anonymous unions.
    6474              : 
    6475              :    Returns the TYPE declared -- or NULL_TREE if none.  */
    6476              : 
    6477              : tree
    6478     32498160 : shadow_tag (cp_decl_specifier_seq *declspecs)
    6479              : {
    6480     32498160 :   tree t = check_tag_decl (declspecs,
    6481              :                            /*explicit_type_instantiation_p=*/false);
    6482              : 
    6483     32498160 :   if (!t)
    6484              :     return NULL_TREE;
    6485              : 
    6486     32496645 :   t = maybe_process_partial_specialization (t);
    6487     32496645 :   if (t == error_mark_node)
    6488              :     return NULL_TREE;
    6489              : 
    6490              :   /* This is where the variables in an anonymous union are
    6491              :      declared.  An anonymous union declaration looks like:
    6492              :      union { ... } ;
    6493              :      because there is no declarator after the union, the parser
    6494              :      sends that declaration here.  */
    6495     32494805 :   if (ANON_AGGR_TYPE_P (t))
    6496              :     {
    6497          384 :       fixup_anonymous_aggr (t);
    6498              : 
    6499          384 :       if (TYPE_FIELDS (t))
    6500              :         {
    6501          384 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    6502              :                                       declspecs, NORMAL, 0, NULL);
    6503          384 :           finish_anon_union (decl);
    6504              :         }
    6505              :     }
    6506              : 
    6507              :   return t;
    6508              : }
    6509              : 
    6510              : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    6511              : 
    6512              : tree
    6513    402324052 : groktypename (cp_decl_specifier_seq *type_specifiers,
    6514              :               const cp_declarator *declarator,
    6515              :               bool is_template_arg)
    6516              : {
    6517    402324052 :   tree attrs;
    6518    402324052 :   tree type;
    6519     66598121 :   enum decl_context context
    6520    402324052 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    6521    402324052 :   attrs = type_specifiers->attributes;
    6522    402324052 :   type_specifiers->attributes = NULL_TREE;
    6523    402324052 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    6524    402324052 :   if (attrs && type != error_mark_node)
    6525              :     {
    6526          675 :       if (CLASS_TYPE_P (type))
    6527            6 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    6528              :                  "outside of definition", type);
    6529          669 :       else if (MAYBE_CLASS_TYPE_P (type))
    6530              :         /* A template type parameter or other dependent type.  */
    6531            9 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    6532              :                  "type %qT without an associated declaration", type);
    6533              :       else
    6534          660 :         cplus_decl_attributes (&type, attrs, 0);
    6535              :     }
    6536    402324052 :   return type;
    6537              : }
    6538              : 
    6539              : /* Process a DECLARATOR for a function-scope or namespace-scope
    6540              :    variable or function declaration.
    6541              :    (Function definitions go through start_function; class member
    6542              :    declarations appearing in the body of the class go through
    6543              :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    6544              :    If an error occurs, the error_mark_node is returned instead.
    6545              : 
    6546              :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    6547              :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    6548              :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    6549              :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    6550              :    implicitly initialized via a default constructor.  It can also be
    6551              :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    6552              :    mark the new decl as DECL_DECOMPOSITION_P.
    6553              : 
    6554              :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    6555              :    declaration.
    6556              : 
    6557              :    The scope represented by the context of the returned DECL is pushed
    6558              :    (if it is not the global namespace) and is assigned to
    6559              :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    6560              :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    6561              : 
    6562              : tree
    6563    126517878 : start_decl (const cp_declarator *declarator,
    6564              :             cp_decl_specifier_seq *declspecs,
    6565              :             int initialized,
    6566              :             tree attributes,
    6567              :             tree prefix_attributes,
    6568              :             tree *pushed_scope_p)
    6569              : {
    6570    126517878 :   tree decl;
    6571    126517878 :   tree context;
    6572    126517878 :   bool was_public;
    6573    126517878 :   int flags;
    6574    126517878 :   bool alias;
    6575    126517878 :   tree initial;
    6576              : 
    6577    126517878 :   *pushed_scope_p = NULL_TREE;
    6578              : 
    6579    126517878 :   if (prefix_attributes != error_mark_node)
    6580    126517876 :     attributes = attr_chainon (attributes, prefix_attributes);
    6581              : 
    6582    126517878 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    6583              :                          &attributes);
    6584              : 
    6585    126517878 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    6586    126517878 :       || decl == error_mark_node
    6587    126515723 :       || prefix_attributes == error_mark_node)
    6588         2157 :     return error_mark_node;
    6589              : 
    6590    126515721 :   context = CP_DECL_CONTEXT (decl);
    6591    126515721 :   if (context != global_namespace)
    6592     22125212 :     *pushed_scope_p = push_scope (context);
    6593              : 
    6594    126515721 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    6595              :     {
    6596           27 :       error_at (DECL_SOURCE_LOCATION (decl),
    6597              :                 "typedef %qD is initialized (use %qs instead)",
    6598              :                 decl, "decltype");
    6599           27 :       return error_mark_node;
    6600              :     }
    6601              : 
    6602    126515694 :   if (flag_contracts
    6603     10741902 :       && TREE_CODE (decl) == FUNCTION_DECL
    6604      3078174 :       && !processing_template_decl
    6605      2494003 :       && DECL_RESULT (decl)
    6606    129005131 :       && is_auto (TREE_TYPE (DECL_RESULT (decl))))
    6607           42 :     for (tree ca = get_fn_contract_specifiers (decl); ca; ca = TREE_CHAIN (ca))
    6608            9 :       if (POSTCONDITION_P (CONTRACT_STATEMENT (ca))
    6609            9 :           && POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
    6610              :         {
    6611            3 :           error_at (DECL_SOURCE_LOCATION (decl),
    6612              :                     "postconditions with deduced result name types must only"
    6613              :                     " appear on function definitions");
    6614            3 :           return error_mark_node;
    6615              :         }
    6616              :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    6617              :      with attribute validation.  */
    6618    126515691 :   initial = DECL_INITIAL (decl);
    6619              : 
    6620    126515691 :   if (initialized)
    6621              :     {
    6622     61029613 :       if (! toplevel_bindings_p ()
    6623     61029613 :           && DECL_EXTERNAL (decl))
    6624            3 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    6625              :                  decl);
    6626     61029613 :       DECL_EXTERNAL (decl) = 0;
    6627     61029613 :       if (toplevel_bindings_p ())
    6628      7300077 :         TREE_STATIC (decl) = 1;
    6629              :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    6630              :          even though we might not yet have the initializer expression.  */
    6631     61029613 :       if (!DECL_INITIAL (decl))
    6632     60464090 :         DECL_INITIAL (decl) = error_mark_node;
    6633              :     }
    6634    126515691 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    6635              : 
    6636    126515691 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    6637         3988 :     record_key_method_defined (decl);
    6638              : 
    6639              :   /* If this is a typedef that names the class for linkage purposes
    6640              :      (7.1.3p8), apply any attributes directly to the type.  */
    6641    126515691 :   if (TREE_CODE (decl) == TYPE_DECL
    6642    126515691 :       && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
    6643              :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    6644              :   else
    6645              :     flags = 0;
    6646              : 
    6647              :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    6648    126515691 :   cplus_decl_attributes (&decl, attributes, flags);
    6649              : 
    6650              :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    6651              :      assist with attribute validation.  */
    6652    126515691 :   DECL_INITIAL (decl) = initial;
    6653              : 
    6654              :   /* Dllimported symbols cannot be defined.  Static data members (which
    6655              :      can be initialized in-class and dllimported) go through grokfield,
    6656              :      not here, so we don't need to exclude those decls when checking for
    6657              :      a definition.  */
    6658    126515691 :   if (initialized && DECL_DLLIMPORT_P (decl))
    6659              :     {
    6660            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    6661              :                 "definition of %q#D is marked %<dllimport%>", decl);
    6662            0 :       DECL_DLLIMPORT_P (decl) = 0;
    6663              :     }
    6664              : 
    6665              :   /* If #pragma weak was used, mark the decl weak now.  */
    6666    126515691 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    6667     46316316 :     maybe_apply_pragma_weak (decl);
    6668              : 
    6669    126515691 :   if (TREE_CODE (decl) == FUNCTION_DECL
    6670     37534284 :       && DECL_DECLARED_INLINE_P (decl)
    6671      3311026 :       && DECL_UNINLINABLE (decl)
    6672    126515691 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    6673              :     {
    6674            0 :       auto_urlify_attributes sentinel;
    6675            0 :       warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6676              :                   "inline function %qD given attribute %qs", decl, "noinline");
    6677            0 :     }
    6678              : 
    6679    126515691 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    6680              :     {
    6681       839883 :       bool this_tmpl = (current_template_depth
    6682       839883 :                         > template_class_depth (context));
    6683       839883 :       if (VAR_P (decl))
    6684              :         {
    6685       491475 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    6686       491475 :           if (field == NULL_TREE
    6687       491475 :               || !(VAR_P (field) || variable_template_p (field)))
    6688            6 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    6689       491469 :           else if (variable_template_p (field)
    6690       491469 :                    && (DECL_LANG_SPECIFIC (decl)
    6691          147 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    6692              :             /* OK, specialization was already checked.  */;
    6693       491400 :           else if (variable_template_p (field) && !this_tmpl)
    6694              :             {
    6695            3 :               auto_diagnostic_group d;
    6696            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    6697              :                         "non-member-template declaration of %qD", decl);
    6698            3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    6699              :                       "member template declaration here");
    6700            3 :               return error_mark_node;
    6701            3 :             }
    6702              :           else
    6703              :             {
    6704       491397 :               if (variable_template_p (field))
    6705           75 :                 field = DECL_TEMPLATE_RESULT (field);
    6706              : 
    6707       491397 :               if (DECL_CONTEXT (field) != context)
    6708              :                 {
    6709            3 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    6710            3 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    6711              :                                "to be defined as %<%T::%D%>",
    6712            3 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    6713            3 :                                context, DECL_NAME (decl));
    6714            3 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    6715              :                 }
    6716              : 
    6717       491397 :               if (modules_p () && !module_may_redeclare (field))
    6718           30 :                 return error_mark_node;
    6719              : 
    6720              :               /* Static data member are tricky; an in-class initialization
    6721              :                  still doesn't provide a definition, so the in-class
    6722              :                  declaration will have DECL_EXTERNAL set, but will have an
    6723              :                  initialization.  Thus, duplicate_decls won't warn
    6724              :                  about this situation, and so we check here.  */
    6725       491367 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    6726            9 :                 error ("duplicate initialization of %qD", decl);
    6727       491367 :               field = duplicate_decls (decl, field);
    6728       491367 :               if (field == error_mark_node)
    6729              :                 return error_mark_node;
    6730       491311 :               else if (field)
    6731       491311 :                 decl = field;
    6732              :             }
    6733              :         }
    6734              :       else
    6735              :         {
    6736       348420 :           tree field = check_classfn (context, decl,
    6737              :                                       this_tmpl
    6738           12 :                                       ? current_template_parms
    6739              :                                       : NULL_TREE);
    6740       348333 :           if (field && field != error_mark_node
    6741       696741 :               && duplicate_decls (decl, field))
    6742       348333 :             decl = field;
    6743              :         }
    6744              : 
    6745              :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    6746       839794 :       DECL_IN_AGGR_P (decl) = 0;
    6747              :       /* Do not mark DECL as an explicit specialization if it was not
    6748              :          already marked as an instantiation; a declaration should
    6749              :          never be marked as a specialization unless we know what
    6750              :          template is being specialized.  */
    6751       839794 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    6752              :         {
    6753       346452 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    6754       346452 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    6755       326461 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    6756       326461 :                                   && DECL_NONGNU_INLINE_P (decl));
    6757              :           else
    6758        19991 :             DECL_COMDAT (decl) = false;
    6759              : 
    6760              :           /* [temp.expl.spec] An explicit specialization of a static data
    6761              :              member of a template is a definition if the declaration
    6762              :              includes an initializer; otherwise, it is a declaration.
    6763              : 
    6764              :              We check for processing_specialization so this only applies
    6765              :              to the new specialization syntax.  */
    6766       346452 :           if (!initialized && processing_specialization)
    6767       346250 :             DECL_EXTERNAL (decl) = 1;
    6768              :         }
    6769              : 
    6770      1186092 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    6771              :           /* Aliases are definitions. */
    6772       839830 :           && !alias)
    6773              :         {
    6774            9 :           permerror (declarator->id_loc,
    6775              :                        "declaration of %q#D outside of class is not definition",
    6776              :                        decl);
    6777              :         }
    6778              :     }
    6779              : 
    6780              :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    6781    126515602 :   if (initialized == SD_DECOMPOSITION)
    6782       460622 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    6783              : 
    6784    126515602 :   was_public = TREE_PUBLIC (decl);
    6785              : 
    6786    215497079 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    6787    127081152 :       && current_function_decl)
    6788              :     {
    6789              :       /* A function-scope decl of some namespace-scope decl.  */
    6790        60642 :       DECL_LOCAL_DECL_P (decl) = true;
    6791        60642 :       if (named_module_attach_p ())
    6792            3 :         error_at (declarator->id_loc,
    6793              :                   "block-scope extern declaration %q#D must not be"
    6794              :                   " attached to a named module", decl);
    6795              :     }
    6796              : 
    6797              :   /* Enter this declaration into the symbol table.  Don't push the plain
    6798              :      VAR_DECL for a variable template.  */
    6799    126515602 :   if (!template_parm_scope_p ()
    6800    126515602 :       || !VAR_P (decl))
    6801    122430235 :     decl = maybe_push_decl (decl);
    6802              : 
    6803    126515602 :   if (processing_template_decl)
    6804     80192285 :     decl = push_template_decl (decl);
    6805              : 
    6806    126515602 :   if (decl == error_mark_node)
    6807              :     return error_mark_node;
    6808              : 
    6809    126515162 :   if (VAR_P (decl)
    6810     67212716 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    6811        68675 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    6812              :       /* But not templated variables.  */
    6813    126544852 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    6814              :     {
    6815              :       /* This is a const variable with implicit 'static'.  Set
    6816              :          DECL_THIS_STATIC so we can tell it from variables that are
    6817              :          !TREE_PUBLIC because of the anonymous namespace.  */
    6818        29690 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    6819        29690 :       DECL_THIS_STATIC (decl) = 1;
    6820              :     }
    6821              : 
    6822     71377948 :   if (current_function_decl && VAR_P (decl)
    6823     59117059 :       && maybe_constexpr_fn (current_function_decl)
    6824    141716061 :       && cxx_dialect < cxx23)
    6825              :     {
    6826     12553383 :       bool ok = false;
    6827     12553383 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    6828              :         {
    6829            9 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6830           18 :             error_at (DECL_SOURCE_LOCATION (decl),
    6831              :                       "%qD defined %<thread_local%> in %qs function only "
    6832              :                       "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6833            9 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6834              :                       ? "consteval" : "constexpr");
    6835              :         }
    6836     12553374 :       else if (TREE_STATIC (decl))
    6837              :         {
    6838           50 :           if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
    6839           72 :             error_at (DECL_SOURCE_LOCATION (decl),
    6840              :                       "%qD defined %<static%> in %qs function only available "
    6841              :                       "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
    6842           36 :                       DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    6843              :                       ? "consteval" : "constexpr");
    6844              :         }
    6845              :       else
    6846              :         ok = true;
    6847           45 :       if (!ok)
    6848           59 :         cp_function_chain->invalid_constexpr = true;
    6849              :     }
    6850              : 
    6851    126515162 :   if (!processing_template_decl && VAR_P (decl))
    6852      8440283 :     start_decl_1 (decl, initialized);
    6853              : 
    6854    126515159 :   return decl;
    6855              : }
    6856              : 
    6857              : /* Process the declaration of a variable DECL.  INITIALIZED is true
    6858              :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    6859              :    variable is initialized via an implicitly-called constructor.)
    6860              :    This function must be called for ordinary variables (including, for
    6861              :    example, implicit instantiations of templates), but must not be
    6862              :    called for template declarations.  */
    6863              : 
    6864              : void
    6865      8448951 : start_decl_1 (tree decl, bool initialized)
    6866              : {
    6867      8448951 :   gcc_checking_assert (!processing_template_decl);
    6868              : 
    6869      8448951 :   if (error_operand_p (decl))
    6870              :     return;
    6871              : 
    6872      8448936 :   gcc_checking_assert (VAR_P (decl));
    6873              : 
    6874      8448936 :   tree type = TREE_TYPE (decl);
    6875      8448936 :   bool complete_p = COMPLETE_TYPE_P (type);
    6876      8448936 :   bool aggregate_definition_p
    6877      8448936 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    6878              : 
    6879              :   /* If an explicit initializer is present, or if this is a definition
    6880              :      of an aggregate, then we need a complete type at this point.
    6881              :      (Scalars are always complete types, so there is nothing to
    6882              :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    6883              :      are issued below.  */
    6884      4387942 :   if ((initialized || aggregate_definition_p)
    6885      7435839 :       && !complete_p
    6886      5970424 :       && COMPLETE_TYPE_P (complete_type (type)))
    6887              :     {
    6888       328050 :       complete_p = true;
    6889              :       /* We will not yet have set TREE_READONLY on DECL if the type
    6890              :          was "const", but incomplete, before this point.  But, now, we
    6891              :          have a complete type, so we can try again.  */
    6892       328050 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    6893              :     }
    6894              : 
    6895      8448933 :   if (initialized)
    6896              :     /* Is it valid for this decl to have an initializer at all?  */
    6897              :     {
    6898              :       /* Don't allow initializations for incomplete types except for
    6899              :          arrays which might be completed by the initialization.  */
    6900      6696445 :       if (complete_p)
    6901              :         ;                       /* A complete type is ok.  */
    6902      1254191 :       else if (type_uses_auto (type))
    6903              :         ;                       /* An auto type is ok.  */
    6904       119885 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    6905              :         {
    6906           27 :           auto_diagnostic_group d;
    6907           27 :           error ("variable %q#D has initializer but incomplete type", decl);
    6908           48 :           maybe_suggest_missing_header (input_location,
    6909           27 :                                         TYPE_IDENTIFIER (type),
    6910           27 :                                         CP_TYPE_CONTEXT (type));
    6911           27 :           type = TREE_TYPE (decl) = error_mark_node;
    6912           27 :         }
    6913       119858 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6914              :         {
    6915            0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6916            0 :             error ("elements of array %q#D have incomplete type", decl);
    6917              :           /* else we already gave an error in start_decl.  */
    6918              :         }
    6919              :     }
    6920      1752488 :   else if (aggregate_definition_p && !complete_p)
    6921              :     {
    6922          238 :       if (type_uses_auto (type))
    6923           71 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6924              :       else
    6925              :         {
    6926          167 :           auto_diagnostic_group d;
    6927          167 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6928              :                  decl);
    6929          289 :           maybe_suggest_missing_header (input_location,
    6930          167 :                                         TYPE_IDENTIFIER (type),
    6931          167 :                                         CP_TYPE_CONTEXT (type));
    6932              :           /* Change the type so that assemble_variable will give
    6933              :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6934          167 :           type = TREE_TYPE (decl) = error_mark_node;
    6935          167 :         }
    6936              :     }
    6937              : 
    6938              :   /* Create a new scope to hold this declaration if necessary.
    6939              :      Whether or not a new scope is necessary cannot be determined
    6940              :      until after the type has been completed; if the type is a
    6941              :      specialization of a class template it is not until after
    6942              :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6943              :      will be set correctly.  */
    6944      8448933 :   maybe_push_cleanup_level (type);
    6945              : }
    6946              : 
    6947              : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6948              :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6949              : 
    6950              : tree
    6951          309 : do_aggregate_paren_init (tree init, tree type)
    6952              : {
    6953          309 :   tree val = TREE_VALUE (init);
    6954              : 
    6955          309 :   if (TREE_CHAIN (init) == NULL_TREE)
    6956              :     {
    6957              :       /* If the list has a single element and it's a string literal,
    6958              :          then it's the initializer for the array as a whole.  */
    6959          193 :       if (TREE_CODE (type) == ARRAY_TYPE
    6960          193 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6961          239 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6962              :              == STRING_CST)
    6963              :         return val;
    6964              :       /* Handle non-standard extensions like compound literals.  This also
    6965              :          prevents triggering aggregate parenthesized-initialization in
    6966              :          compiler-generated code for =default.  */
    6967          154 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6968          154 :                                                           TREE_TYPE (val)))
    6969              :         return val;
    6970              :     }
    6971              : 
    6972          208 :   init = build_constructor_from_list (init_list_type_node, init);
    6973          208 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6974          208 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6975          208 :   return init;
    6976              : }
    6977              : 
    6978              : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6979              :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6980              :    but will be set to a new CLEANUP_STMT if a temporary is created
    6981              :    that must be destroyed subsequently.
    6982              : 
    6983              :    Returns an initializer expression to use to initialize DECL, or
    6984              :    NULL if the initialization can be performed statically.
    6985              : 
    6986              :    Quotes on semantics can be found in ARM 8.4.3.  */
    6987              : 
    6988              : static tree
    6989       358887 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6990              : {
    6991       358887 :   if (init == NULL_TREE)
    6992              :     {
    6993           15 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6994            3 :            || DECL_IN_AGGR_P (decl) == 0)
    6995           18 :           && ! DECL_THIS_EXTERN (decl))
    6996           15 :         error_at (DECL_SOURCE_LOCATION (decl),
    6997              :                   "%qD declared as reference but not initialized", decl);
    6998           15 :       return NULL_TREE;
    6999              :     }
    7000              : 
    7001       358872 :   tree ttype = TREE_TYPE (type);
    7002       358872 :   if (TREE_CODE (init) == TREE_LIST)
    7003              :     {
    7004              :       /* This handles (C++20 only) code like
    7005              : 
    7006              :            const A& r(1, 2, 3);
    7007              : 
    7008              :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    7009         1167 :       if (TREE_TYPE (init) == NULL_TREE
    7010         1167 :           && CP_AGGREGATE_TYPE_P (ttype)
    7011           69 :           && !DECL_DECOMPOSITION_P (decl)
    7012         1233 :           && (cxx_dialect >= cxx20))
    7013              :         {
    7014              :           /* We don't know yet if we should treat const A& r(1) as
    7015              :              const A& r{1}.  */
    7016           60 :           if (list_length (init) == 1)
    7017              :             {
    7018           39 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    7019           39 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    7020              :                                                       tf_warning_or_error);
    7021              :             }
    7022              :           /* If the list had more than one element, the code is ill-formed
    7023              :              pre-C++20, so we can build a constructor right away.  */
    7024              :           else
    7025           21 :             init = do_aggregate_paren_init (init, ttype);
    7026              :         }
    7027              :       else
    7028         1107 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    7029              :                                                 tf_warning_or_error);
    7030              :     }
    7031              : 
    7032       358872 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    7033       358872 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    7034              :     /* Note: default conversion is only called in very special cases.  */
    7035           12 :     init = decay_conversion (init, tf_warning_or_error);
    7036              : 
    7037              :   /* check_initializer handles this for non-reference variables, but for
    7038              :      references we need to do it here or the initializer will get the
    7039              :      incomplete array type and confuse later calls to
    7040              :      cp_complete_array_type.  */
    7041       358872 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    7042        22648 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    7043       358955 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    7044           50 :           || TREE_CODE (init) == STRING_CST))
    7045              :     {
    7046           33 :       cp_complete_array_type (&ttype, init, false);
    7047           33 :       if (ttype != TREE_TYPE (type))
    7048           33 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    7049              :     }
    7050              : 
    7051              :   /* Convert INIT to the reference type TYPE.  This may involve the
    7052              :      creation of a temporary, whose lifetime must be the same as that
    7053              :      of the reference.  If so, a DECL_EXPR for the temporary will be
    7054              :      added just after the DECL_EXPR for DECL.  That's why we don't set
    7055              :      DECL_INITIAL for local references (instead assigning to them
    7056              :      explicitly); we need to allow the temporary to be initialized
    7057              :      first.  */
    7058       358872 :   return initialize_reference (type, init, flags,
    7059       358872 :                                tf_warning_or_error);
    7060              : }
    7061              : 
    7062              : /* Designated initializers in arrays are not supported in GNU C++.
    7063              :    The parser cannot detect this error since it does not know whether
    7064              :    a given brace-enclosed initializer is for a class type or for an
    7065              :    array.  This function checks that CE does not use a designated
    7066              :    initializer.  If it does, an error is issued.  Returns true if CE
    7067              :    is valid, i.e., does not have a designated initializer.  */
    7068              : 
    7069              : bool
    7070    149171647 : check_array_designated_initializer (constructor_elt *ce,
    7071              :                                     unsigned HOST_WIDE_INT index)
    7072              : {
    7073              :   /* Designated initializers for array elements are not supported.  */
    7074    149171647 :   if (ce->index)
    7075              :     {
    7076              :       /* The parser only allows identifiers as designated
    7077              :          initializers.  */
    7078    100683972 :       if (ce->index == error_mark_node)
    7079              :         {
    7080            0 :           error ("name used in a GNU-style designated "
    7081              :                  "initializer for an array");
    7082            0 :           return false;
    7083              :         }
    7084    100683972 :       else if (identifier_p (ce->index))
    7085              :         {
    7086           19 :           error ("name %qD used in a GNU-style designated "
    7087              :                  "initializer for an array", ce->index);
    7088           19 :           ce->index = error_mark_node;
    7089           19 :           return false;
    7090              :         }
    7091              : 
    7092    100683953 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    7093              :                                                   ce->index, true);
    7094    100683953 :       if (ce_index
    7095    100683950 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    7096    201367900 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    7097              :               == INTEGER_CST))
    7098              :         {
    7099              :           /* A C99 designator is OK if it matches the current index.  */
    7100    100683947 :           if (wi::to_wide (ce_index) == index)
    7101              :             {
    7102    100683941 :               ce->index = ce_index;
    7103    100683941 :               return true;
    7104              :             }
    7105              :           else
    7106            6 :             sorry ("non-trivial designated initializers not supported");
    7107              :         }
    7108              :       else
    7109            6 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    7110              :                   "C99 designator %qE is not an integral constant-expression",
    7111              :                   ce->index);
    7112              : 
    7113           12 :       return false;
    7114              :     }
    7115              : 
    7116              :   return true;
    7117              : }
    7118              : 
    7119              : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    7120              :    array until we finish parsing the initializer.  If that's the
    7121              :    situation we're in, update DECL accordingly.  */
    7122              : 
    7123              : static void
    7124     72559066 : maybe_deduce_size_from_array_init (tree decl, tree init)
    7125              : {
    7126     72559066 :   tree type = TREE_TYPE (decl);
    7127              : 
    7128     72559066 :   if (TREE_CODE (type) == ARRAY_TYPE
    7129       928122 :       && TYPE_DOMAIN (type) == NULL_TREE
    7130     73158671 :       && TREE_CODE (decl) != TYPE_DECL)
    7131              :     {
    7132              :       /* do_default is really a C-ism to deal with tentative definitions.
    7133              :          But let's leave it here to ease the eventual merge.  */
    7134       599605 :       int do_default = !DECL_EXTERNAL (decl);
    7135       599605 :       tree initializer = init ? init : DECL_INITIAL (decl);
    7136       599605 :       int failure = 0;
    7137              : 
    7138              :       /* Check that there are no designated initializers in INIT, as
    7139              :          those are not supported in GNU C++, and as the middle-end
    7140              :          will crash if presented with a non-numeric designated
    7141              :          initializer.  */
    7142       599605 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    7143              :         {
    7144       142528 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    7145       142528 :           constructor_elt *ce;
    7146       142528 :           HOST_WIDE_INT i, j = 0;
    7147     46792971 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    7148              :             {
    7149     46651208 :               if (instantiation_dependent_expression_p (ce->index))
    7150     72559066 :                 return;
    7151     46651202 :               if (!check_array_designated_initializer (ce, j))
    7152            1 :                 failure = 1;
    7153              :               /* If an un-designated initializer is type-dependent, we can't
    7154              :                  check brace elision yet.  */
    7155     46651202 :               if (ce->index == NULL_TREE
    7156     46651202 :                   && type_dependent_expression_p (ce->value))
    7157              :                 return;
    7158     46650443 :               if (TREE_CODE (ce->value) == RAW_DATA_CST)
    7159          204 :                 j += RAW_DATA_LENGTH (ce->value);
    7160              :               else
    7161     46650239 :                 ++j;
    7162              :             }
    7163              :         }
    7164              : 
    7165       141763 :       if (failure)
    7166            1 :         TREE_TYPE (decl) = error_mark_node;
    7167              :       else
    7168              :         {
    7169       598839 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    7170              :                                             do_default);
    7171       598839 :           if (failure == 1)
    7172              :             {
    7173           33 :               error_at (cp_expr_loc_or_loc (initializer,
    7174           30 :                                          DECL_SOURCE_LOCATION (decl)),
    7175              :                         "initializer fails to determine size of %qD", decl);
    7176              :             }
    7177       598809 :           else if (failure == 2)
    7178              :             {
    7179           30 :               if (do_default)
    7180              :                 {
    7181            6 :                   error_at (DECL_SOURCE_LOCATION (decl),
    7182              :                             "array size missing in %qD", decl);
    7183              :                 }
    7184              :               /* If a `static' var's size isn't known, make it extern as
    7185              :                  well as static, so it does not get allocated.  If it's not
    7186              :                  `static', then don't mark it extern; finish_incomplete_decl
    7187              :                  will give it a default size and it will get allocated.  */
    7188           24 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    7189            0 :                 DECL_EXTERNAL (decl) = 1;
    7190              :             }
    7191       598779 :           else if (failure == 3)
    7192              :             {
    7193            6 :               error_at (DECL_SOURCE_LOCATION (decl),
    7194              :                         "zero-size array %qD", decl);
    7195              :             }
    7196              :         }
    7197              : 
    7198       598840 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    7199              : 
    7200       598840 :       relayout_decl (decl);
    7201              : 
    7202              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    7203       598840 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    7204              :         {
    7205          208 :           tree tmpl = template_for_substitution (decl);
    7206          208 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    7207           50 :             TREE_TYPE (tmpl) = TREE_TYPE (decl);
    7208              :         }
    7209              :     }
    7210              : }
    7211              : 
    7212              : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    7213              :    any appropriate error messages regarding the layout.  */
    7214              : 
    7215              : static void
    7216     62047533 : layout_var_decl (tree decl)
    7217              : {
    7218     62047533 :   tree type;
    7219              : 
    7220     62047533 :   type = TREE_TYPE (decl);
    7221     62047533 :   if (type == error_mark_node)
    7222              :     return;
    7223              : 
    7224              :   /* If we haven't already laid out this declaration, do so now.
    7225              :      Note that we must not call complete type for an external object
    7226              :      because it's type might involve templates that we are not
    7227              :      supposed to instantiate yet.  (And it's perfectly valid to say
    7228              :      `extern X x' for some incomplete type `X'.)  */
    7229     62047486 :   if (!DECL_EXTERNAL (decl))
    7230     51925248 :     complete_type (type);
    7231     62047486 :   if (!DECL_SIZE (decl)
    7232       605563 :       && TREE_TYPE (decl) != error_mark_node
    7233     62653049 :       && complete_or_array_type_p (type))
    7234       457042 :     layout_decl (decl, 0);
    7235              : 
    7236     62047486 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    7237              :     {
    7238              :       /* An automatic variable with an incomplete type: that is an error.
    7239              :          Don't talk about array types here, since we took care of that
    7240              :          message in grokdeclarator.  */
    7241           17 :       error_at (DECL_SOURCE_LOCATION (decl),
    7242              :                 "storage size of %qD isn%'t known", decl);
    7243           17 :       TREE_TYPE (decl) = error_mark_node;
    7244              :     }
    7245              : #if 0
    7246              :   /* Keep this code around in case we later want to control debug info
    7247              :      based on whether a type is "used".  (jason 1999-11-11) */
    7248              : 
    7249              :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    7250              :     /* Let debugger know it should output info for this type.  */
    7251              :     note_debug_info_needed (ttype);
    7252              : 
    7253              :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    7254              :     note_debug_info_needed (DECL_CONTEXT (decl));
    7255              : #endif
    7256              : 
    7257    113972734 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    7258     38202928 :       && DECL_SIZE (decl) != NULL_TREE
    7259     99973334 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    7260              :     {
    7261            6 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7262            6 :           && !DECL_LOCAL_DECL_P (decl))
    7263            0 :         constant_expression_warning (DECL_SIZE (decl));
    7264              :       else
    7265              :         {
    7266            6 :           error_at (DECL_SOURCE_LOCATION (decl),
    7267              :                     "storage size of %qD isn%'t constant", decl);
    7268            6 :           TREE_TYPE (decl) = error_mark_node;
    7269            6 :           type = error_mark_node;
    7270              :         }
    7271              :     }
    7272              : 
    7273              :   /* If the final element initializes a flexible array field, adjust
    7274              :      the size of the DECL with the initializer based on whether the
    7275              :      DECL is a union or a structure.  */
    7276     62047486 :   if (type != error_mark_node
    7277     62047480 :       && DECL_INITIAL (decl)
    7278     36647644 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    7279      5050140 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    7280      3399749 :       && DECL_SIZE (decl) != NULL_TREE
    7281      3399749 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    7282      3399749 :       && COMPLETE_TYPE_P (type)
    7283      3399749 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    7284     65447235 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    7285              :     {
    7286      3399749 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    7287      3399749 :       if (elt.index)
    7288              :         {
    7289      1253031 :           tree itype = TREE_TYPE (elt.index);
    7290      1253031 :           tree vtype = TREE_TYPE (elt.value);
    7291      1253031 :           if (TREE_CODE (itype) == ARRAY_TYPE
    7292        80229 :               && TYPE_DOMAIN (itype) == NULL
    7293          275 :               && TREE_CODE (vtype) == ARRAY_TYPE
    7294      1253306 :               && COMPLETE_TYPE_P (vtype))
    7295              :             {
    7296              :               /* For a structure, add the size of the initializer to the DECL's
    7297              :                  size.  */
    7298          275 :               if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
    7299              :                 {
    7300          260 :                   DECL_SIZE (decl)
    7301          260 :                     = size_binop (PLUS_EXPR, DECL_SIZE (decl),
    7302              :                                   TYPE_SIZE (vtype));
    7303          260 :                   DECL_SIZE_UNIT (decl)
    7304          520 :                     = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    7305              :                                   TYPE_SIZE_UNIT (vtype));
    7306              :                 }
    7307              :               /* For a union, the DECL's size is the maximum of the current size
    7308              :                  and the size of the initializer.  */
    7309              :               else
    7310              :                 {
    7311           15 :                   DECL_SIZE (decl)
    7312           15 :                     = size_binop (MAX_EXPR, DECL_SIZE (decl),
    7313              :                                   TYPE_SIZE (vtype));
    7314           15 :                   DECL_SIZE_UNIT (decl)
    7315           30 :                     = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
    7316              :                                   TYPE_SIZE_UNIT (vtype));
    7317              :                 }
    7318              :             }
    7319              :         }
    7320              :     }
    7321              : }
    7322              : 
    7323              : /* If a local static variable is declared in an inline function, or if
    7324              :    we have a weak definition, we must endeavor to create only one
    7325              :    instance of the variable at link-time.  */
    7326              : 
    7327              : void
    7328     76139067 : maybe_commonize_var (tree decl)
    7329              : {
    7330              :   /* Don't mess with __FUNCTION__ and similar.  But do handle structured
    7331              :      bindings.  */
    7332     76139067 :   if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
    7333              :     return;
    7334              : 
    7335              :   /* Static data in a function with comdat linkage also has comdat
    7336              :      linkage.  */
    7337     71003805 :   if ((TREE_STATIC (decl)
    7338     46882551 :        && DECL_FUNCTION_SCOPE_P (decl)
    7339       135468 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    7340    164949741 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    7341              :     {
    7342     41031352 :       if (flag_weak)
    7343              :         {
    7344              :           /* With weak symbols, we simply make the variable COMDAT;
    7345              :              that will cause copies in multiple translations units to
    7346              :              be merged.  */
    7347     41031325 :           comdat_linkage (decl);
    7348              :         }
    7349              :       else
    7350              :         {
    7351           27 :           if (DECL_INITIAL (decl) == NULL_TREE
    7352           27 :               || DECL_INITIAL (decl) == error_mark_node)
    7353              :             {
    7354              :               /* Without weak symbols, we can use COMMON to merge
    7355              :                  uninitialized variables.  */
    7356           24 :               TREE_PUBLIC (decl) = 1;
    7357           24 :               DECL_COMMON (decl) = 1;
    7358              :             }
    7359              :           else
    7360              :             {
    7361              :               /* While for initialized variables, we must use internal
    7362              :                  linkage -- which means that multiple copies will not
    7363              :                  be merged.  */
    7364            3 :               TREE_PUBLIC (decl) = 0;
    7365            3 :               DECL_COMMON (decl) = 0;
    7366            3 :               DECL_INTERFACE_KNOWN (decl) = 1;
    7367            3 :               const char *msg;
    7368            3 :               if (DECL_INLINE_VAR_P (decl))
    7369              :                 msg = G_("sorry: semantics of inline variable "
    7370              :                          "%q#D are wrong (you%'ll wind up with "
    7371              :                          "multiple copies)");
    7372              :               else
    7373              :                 msg = G_("sorry: semantics of inline function "
    7374              :                          "static data %q#D are wrong (you%'ll wind "
    7375              :                          "up with multiple copies)");
    7376            3 :               auto_diagnostic_group d;
    7377            3 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    7378              :                               msg, decl))
    7379            3 :                 inform (DECL_SOURCE_LOCATION (decl),
    7380              :                         "you can work around this by removing the initializer");
    7381            3 :             }
    7382              :         }
    7383              :     }
    7384              : }
    7385              : 
    7386              : /* Issue an error message if DECL is an uninitialized const variable.
    7387              :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    7388              :    context from potential_constant_expression.  Returns true if all is well,
    7389              :    false otherwise.  */
    7390              : 
    7391              : bool
    7392      8790984 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    7393              :                                    tsubst_flags_t complain)
    7394              : {
    7395      8790984 :   tree type = strip_array_types (TREE_TYPE (decl));
    7396              : 
    7397              :   /* ``Unless explicitly declared extern, a const object does not have
    7398              :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    7399              :      7.1.6 */
    7400      8790984 :   if (VAR_P (decl)
    7401      8790984 :       && !TYPE_REF_P (type)
    7402      8747520 :       && (CP_TYPE_CONST_P (type)
    7403              :           /* C++20 permits trivial default initialization in constexpr
    7404              :              context (P1331R2).  */
    7405      6791503 :           || (cxx_dialect < cxx20
    7406       137021 :               && (constexpr_context_p
    7407       123643 :                   || var_in_constexpr_fn (decl))))
    7408     10762475 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    7409              :     {
    7410       633743 :       tree field = default_init_uninitialized_part (type);
    7411       633743 :       if (!field)
    7412              :         return true;
    7413              : 
    7414         3914 :       auto_diagnostic_group d;
    7415         3914 :       bool show_notes = true;
    7416              : 
    7417         3914 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    7418              :         {
    7419          188 :           if (CP_TYPE_CONST_P (type))
    7420              :             {
    7421           90 :               if (complain & tf_error)
    7422           84 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    7423              :                                         "uninitialized %<const %D%>", decl);
    7424              :             }
    7425              :           else
    7426              :             {
    7427           98 :               if (!is_instantiation_of_constexpr (current_function_decl)
    7428           98 :                   && (complain & tf_error))
    7429           21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    7430              :                           "uninitialized variable %qD in %<constexpr%> "
    7431              :                           "function", decl);
    7432              :               else
    7433              :                 show_notes = false;
    7434           98 :               cp_function_chain->invalid_constexpr = true;
    7435              :             }
    7436              :         }
    7437         3726 :       else if (complain & tf_error)
    7438            2 :         error_at (DECL_SOURCE_LOCATION (decl),
    7439              :                   "uninitialized variable %qD in %<constexpr%> context",
    7440              :                   decl);
    7441              : 
    7442         3914 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    7443              :         {
    7444           62 :           tree defaulted_ctor;
    7445              : 
    7446           62 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    7447              :                   "%q#T has no user-provided default constructor", type);
    7448           62 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    7449           62 :           if (defaulted_ctor)
    7450           33 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    7451              :                     "constructor is not user-provided because it is "
    7452              :                     "explicitly defaulted in the class body");
    7453           62 :           inform (DECL_SOURCE_LOCATION (field),
    7454              :                   "and the implicitly-defined constructor does not "
    7455              :                   "initialize %q#D", field);
    7456              :         }
    7457              : 
    7458         3914 :       return false;
    7459         3914 :     }
    7460              : 
    7461              :   return true;
    7462              : }
    7463              : 
    7464              : /* Structure holding the current initializer being processed by reshape_init.
    7465              :    CUR is a pointer to the current element being processed, END is a pointer
    7466              :    after the last element present in the initializer and RAW_IDX is index into
    7467              :    RAW_DATA_CST if that is CUR elt.  */
    7468              : struct reshape_iter
    7469              : {
    7470              :   constructor_elt *cur;
    7471              :   constructor_elt *end;
    7472              :   unsigned raw_idx;
    7473              : };
    7474              : 
    7475              : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    7476              : 
    7477              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7478              :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    7479              :    initialized as if for an aggregate class.  If there are no more such fields,
    7480              :    the return value will be NULL.  */
    7481              : 
    7482              : tree
    7483     13789996 : next_aggregate_field (tree field)
    7484              : {
    7485     13789996 :   while (field
    7486     55548825 :          && (TREE_CODE (field) != FIELD_DECL
    7487      8595403 :              || DECL_UNNAMED_BIT_FIELD (field)
    7488      8595242 :              || (DECL_ARTIFICIAL (field)
    7489              :                  /* In C++17, aggregates can have bases.  */
    7490       179380 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    7491     41758829 :     field = DECL_CHAIN (field);
    7492              : 
    7493     13789996 :   return field;
    7494              : }
    7495              : 
    7496              : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    7497              :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    7498              :    to a subobject.  If there are no more such fields, the return value will be
    7499              :    NULL.  */
    7500              : 
    7501              : tree
    7502     64268107 : next_subobject_field (tree field)
    7503              : {
    7504     64268107 :   while (field
    7505    829670604 :          && (TREE_CODE (field) != FIELD_DECL
    7506     28491629 :              || DECL_UNNAMED_BIT_FIELD (field)
    7507     28491490 :              || (DECL_ARTIFICIAL (field)
    7508      8040684 :                  && !DECL_FIELD_IS_BASE (field)
    7509      1735911 :                  && !DECL_VIRTUAL_P (field))))
    7510    765402497 :     field = DECL_CHAIN (field);
    7511              : 
    7512     64268107 :   return field;
    7513              : }
    7514              : 
    7515              : /* Return true for [dcl.init.list] direct-list-initialization from
    7516              :    single element of enumeration with a fixed underlying type.  */
    7517              : 
    7518              : bool
    7519    178879635 : is_direct_enum_init (tree type, tree init)
    7520              : {
    7521    178879635 :   if (cxx_dialect >= cxx17
    7522    176841470 :       && TREE_CODE (type) == ENUMERAL_TYPE
    7523      7262211 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    7524      4946101 :       && TREE_CODE (init) == CONSTRUCTOR
    7525       419667 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    7526       205981 :       && CONSTRUCTOR_NELTS (init) == 1
    7527          216 :       && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
    7528              :       /* DR 2374: The single element needs to be implicitly
    7529              :          convertible to the underlying type of the enum.  */
    7530          216 :       && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
    7531    178879849 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    7532          214 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    7533          214 :                           CONSTRUCTOR_ELT (init, 0)->value,
    7534              :                           LOOKUP_IMPLICIT, tf_none))
    7535              :     return true;
    7536              :   return false;
    7537              : }
    7538              : 
    7539              : /* Helper function for reshape_init*.  Split first element of
    7540              :    RAW_DATA_CST or return NULL for other elements.  Set *INC_CUR
    7541              :    to true if the whole d->cur has been consumed.  */
    7542              : 
    7543              : static tree
    7544     59501637 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
    7545              : {
    7546     59501637 :   *inc_cur = true;
    7547     59501637 :   if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
    7548              :     return NULL_TREE;
    7549        30720 :   tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
    7550        30720 :   if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
    7551        30588 :     *inc_cur = false;
    7552              :   else
    7553          132 :     d->raw_idx = 0;
    7554              :   return ret;
    7555              : }
    7556              : 
    7557              : /* Wrapper around that which for RAW_DATA_CST in INIT
    7558              :    (as well as in D->cur->value) peels off the first element
    7559              :    of the raw data and returns it, otherwise increments
    7560              :    D->cur and returns INIT.  */
    7561              : 
    7562              : static tree
    7563     59501620 : consume_init (tree init, reshape_iter *d)
    7564              : {
    7565     59501620 :   bool inc_cur;
    7566     59501620 :   if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    7567        30720 :     init = raw_init;
    7568     59501620 :   if (inc_cur)
    7569     59471032 :     d->cur++;
    7570     59501620 :   return init;
    7571              : }
    7572              : 
    7573              : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    7574              :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    7575              :    INTEGER_CST representing the size of the array minus one (the maximum index),
    7576              :    or NULL_TREE if the array was declared without specifying the size. D is
    7577              :    the iterator within the constructor.  */
    7578              : 
    7579              : static tree
    7580       448051 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    7581              :                       tree first_initializer_p, bool vector_p,
    7582              :                       tsubst_flags_t complain)
    7583              : {
    7584       448051 :   tree new_init;
    7585       448051 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    7586       448051 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    7587       448051 :   unsigned HOST_WIDE_INT index;
    7588              : 
    7589              :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    7590              :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    7591              :      to build a new one.  But don't reuse if not complaining; if this is
    7592              :      tentative, we might also reshape to another type (95319).  */
    7593       448051 :   bool reuse = (first_initializer_p
    7594       392968 :                 && (complain & tf_error)
    7595       391714 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    7596       777919 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    7597       122876 :   if (reuse)
    7598              :     new_init = first_initializer_p;
    7599              :   else
    7600       122876 :     new_init = build_constructor (init_list_type_node, NULL);
    7601              : 
    7602       448051 :   if (sized_array_p)
    7603              :     {
    7604       264661 :       poly_uint64 midx;
    7605              :       /* Minus 1 is used for zero sized arrays.  */
    7606       264661 :       if (integer_all_onesp (max_index))
    7607           24 :         return new_init;
    7608              : 
    7609       264637 :       if (tree_fits_poly_uint64_p (max_index))
    7610       264637 :         midx = tree_to_poly_uint64 (max_index);
    7611              :       /* sizetype is sign extended, not zero extended.  */
    7612              :       else
    7613            0 :         midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
    7614              : 
    7615              :       /* For VLA vectors, we restrict the number of elements in the constructor
    7616              :          to lower bound of the VLA elements.  */
    7617       264637 :       max_index_cst = constant_lower_bound (midx);
    7618              :     }
    7619              : 
    7620       448027 :   constructor_elt *first_cur = d->cur;
    7621              :   /* Loop until there are no more initializers.  */
    7622     54511877 :   for (index = 0;
    7623     54511877 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    7624              :        ++index)
    7625              :     {
    7626     54064030 :       tree elt_init;
    7627     54064030 :       constructor_elt *old_cur = d->cur;
    7628     54064030 :       unsigned int old_raw_idx = d->raw_idx;
    7629     54064030 :       bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
    7630              : 
    7631     54064030 :       if (d->cur->index)
    7632      5597512 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7633     54064030 :       check_array_designated_initializer (d->cur, index);
    7634     54064030 :       if (TREE_CODE (d->cur->value) == RAW_DATA_CST
    7635        32740 :           && (TREE_CODE (elt_type) == INTEGER_TYPE
    7636        10233 :               || is_byte_access_type (elt_type))
    7637        22507 :           && TYPE_PRECISION (elt_type) == CHAR_BIT
    7638         1846 :           && (!sized_array_p || index < max_index_cst)
    7639     54065864 :           && !vector_p)
    7640              :         {
    7641          514 :           elt_init = d->cur->value;
    7642          514 :           unsigned int off = d->raw_idx;
    7643          514 :           unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
    7644          514 :           if (!sized_array_p || len <= max_index_cst - index + 1)
    7645              :             {
    7646          505 :               d->cur++;
    7647          505 :               d->raw_idx = 0;
    7648              :             }
    7649              :           else
    7650              :             {
    7651            9 :               len = max_index_cst - index + 1;
    7652            9 :               d->raw_idx += len;
    7653              :             }
    7654          514 :           if (!reuse || off || d->cur == old_cur)
    7655              :             {
    7656           27 :               elt_init = copy_node (elt_init);
    7657           27 :               RAW_DATA_LENGTH (elt_init) = len;
    7658           27 :               RAW_DATA_POINTER (elt_init) += off;
    7659              :             }
    7660          514 :           TREE_TYPE (elt_init) = elt_type;
    7661              :         }
    7662              :       else
    7663     54063516 :         elt_init = reshape_init_r (elt_type, d,
    7664              :                                    /*first_initializer_p=*/NULL_TREE,
    7665              :                                    complain);
    7666     54064030 :       if (elt_init == error_mark_node)
    7667              :         return error_mark_node;
    7668     54063853 :       tree idx = size_int (index);
    7669     54063853 :       if (reuse && old_raw_data_cst && d->cur == old_cur)
    7670              :         {
    7671              :           /* We need to stop reusing as some RAW_DATA_CST in the original
    7672              :              ctor had to be split.  */
    7673           72 :           new_init = build_constructor (init_list_type_node, NULL);
    7674           72 :           if (index)
    7675              :             {
    7676           72 :               vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
    7677           72 :               memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
    7678           72 :                       (d->cur - first_cur)
    7679              :                       * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
    7680           72 :               if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
    7681              :                 {
    7682              :                   unsigned int j;
    7683              :                   tree nidx, nval;
    7684            4 :                   FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
    7685              :                                             j, nidx, nval)
    7686            4 :                     if (nidx)
    7687              :                       {
    7688            4 :                         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
    7689            4 :                         (void) nval;
    7690            4 :                         break;
    7691              :                       }
    7692              :                 }
    7693              :             }
    7694              :           reuse = false;
    7695              :         }
    7696     54063781 :       if (reuse)
    7697              :         {
    7698     52816576 :           old_cur->index = idx;
    7699     52816576 :           old_cur->value = elt_init;
    7700              :         }
    7701              :       else
    7702      1247277 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    7703              :                                 idx, elt_init);
    7704     54063853 :       if (!TREE_CONSTANT (elt_init))
    7705       186695 :         TREE_CONSTANT (new_init) = false;
    7706              : 
    7707              :       /* This can happen with an invalid initializer (c++/54501).  */
    7708     54063853 :       if (d->cur == old_cur
    7709        32082 :           && !sized_array_p
    7710        14085 :           && d->raw_idx == old_raw_idx)
    7711              :         break;
    7712              : 
    7713     54063850 :       if (TREE_CODE (elt_init) == RAW_DATA_CST)
    7714          514 :         index += RAW_DATA_LENGTH (elt_init) - 1;
    7715              :     }
    7716              : 
    7717              :   return new_init;
    7718              : }
    7719              : 
    7720              : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    7721              :    Parameters are the same of reshape_init_r.  */
    7722              : 
    7723              : static tree
    7724       400052 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    7725              :                     tsubst_flags_t complain)
    7726              : {
    7727       400052 :   tree max_index = NULL_TREE;
    7728              : 
    7729       400052 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    7730              : 
    7731       400052 :   if (TYPE_DOMAIN (type))
    7732       216710 :     max_index = array_type_nelts_minus_one (type);
    7733              : 
    7734       400052 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7735       400052 :                                first_initializer_p, false, complain);
    7736              : }
    7737              : 
    7738              : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    7739              :    Parameters are the same of reshape_init_r.  */
    7740              : 
    7741              : static tree
    7742        47999 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    7743              : {
    7744        47999 :   tree max_index = NULL_TREE;
    7745              : 
    7746        47999 :   gcc_assert (VECTOR_TYPE_P (type));
    7747              : 
    7748        47999 :   if (COMPOUND_LITERAL_P (d->cur->value))
    7749              :     {
    7750            0 :       tree value = d->cur->value;
    7751            0 :       if (!same_type_p (TREE_TYPE (value), type))
    7752              :         {
    7753            0 :           if (complain & tf_error)
    7754            0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    7755            0 :                    TREE_TYPE (d->cur->value), type);
    7756            0 :           value = error_mark_node;
    7757              :         }
    7758            0 :       ++d->cur;
    7759            0 :       return value;
    7760              :     }
    7761              : 
    7762              :   /* For a vector, we initialize it as an array of the appropriate size.  */
    7763        47999 :   if (VECTOR_TYPE_P (type))
    7764        47999 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    7765              : 
    7766        47999 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    7767        47999 :                                NULL_TREE, true, complain);
    7768              : }
    7769              : 
    7770              : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    7771              :    INIT, in isolation from any designator or other initializers.  */
    7772              : 
    7773              : static tree
    7774       534540 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    7775              : {
    7776              :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    7777              :      calling reshape_init, but this way can just live on the stack.  */
    7778       534540 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    7779       534540 :   reshape_iter iter = { &elt, &elt + 1, 0 };
    7780       534540 :   return reshape_init_r (type, &iter,
    7781              :                          /*first_initializer_p=*/NULL_TREE,
    7782       534540 :                          complain);
    7783              : }
    7784              : 
    7785              : /* Subroutine of reshape_init_r, processes the initializers for classes
    7786              :    or union. Parameters are the same of reshape_init_r.  */
    7787              : 
    7788              : static tree
    7789      3338350 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    7790              :                     tsubst_flags_t complain)
    7791              : {
    7792      3338350 :   tree field;
    7793      3338350 :   tree new_init;
    7794              : 
    7795      3338350 :   gcc_assert (CLASS_TYPE_P (type));
    7796              : 
    7797              :   /* The initializer for a class is always a CONSTRUCTOR.  */
    7798      3338350 :   new_init = build_constructor (init_list_type_node, NULL);
    7799              : 
    7800      3338350 :   int binfo_idx = -1;
    7801      3338350 :   tree binfo = TYPE_BINFO (type);
    7802      3338350 :   tree base_binfo = NULL_TREE;
    7803      3338350 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    7804              :     {
    7805              :       /* We get here from maybe_aggr_guide for C++20 class template argument
    7806              :          deduction.  In this case we need to look through the binfo because a
    7807              :          template doesn't have base fields.  */
    7808         1436 :       binfo_idx = 0;
    7809         1436 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    7810              :     }
    7811           86 :   if (base_binfo)
    7812              :     field = base_binfo;
    7813              :   else
    7814      3338264 :     field = next_aggregate_field (TYPE_FIELDS (type));
    7815              : 
    7816      3338350 :   if (!field)
    7817              :     {
    7818              :       /* [dcl.init.aggr]
    7819              : 
    7820              :         An initializer for an aggregate member that is an
    7821              :         empty class shall have the form of an empty
    7822              :         initializer-list {}.  */
    7823          322 :       if (!first_initializer_p)
    7824              :         {
    7825          268 :           if (complain & tf_error)
    7826           13 :             error ("initializer for %qT must be brace-enclosed", type);
    7827          268 :           return error_mark_node;
    7828              :         }
    7829              :       return new_init;
    7830              :     }
    7831              : 
    7832              :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    7833              :   tree last_was_pack_expansion = NULL_TREE;
    7834              : 
    7835              :   /* Loop through the initializable fields, gathering initializers.  */
    7836      9959293 :   while (d->cur != d->end)
    7837              :     {
    7838      6725430 :       tree field_init;
    7839      6725430 :       constructor_elt *old_cur = d->cur;
    7840      6725430 :       unsigned old_raw_idx = d->raw_idx;
    7841      6725430 :       bool direct_desig = false;
    7842              : 
    7843              :       /* Handle C++20 designated initializers.  */
    7844      6725430 :       if (d->cur->index)
    7845              :         {
    7846       534710 :           if (d->cur->index == error_mark_node)
    7847              :             return error_mark_node;
    7848              : 
    7849       534704 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    7850              :             {
    7851              :               /* We already reshaped this; we should have returned early from
    7852              :                  reshape_init.  */
    7853            0 :               gcc_checking_assert (false);
    7854              :               if (field != d->cur->index)
    7855              :                 {
    7856              :                   if (tree id = DECL_NAME (d->cur->index))
    7857              :                     gcc_checking_assert (d->cur->index
    7858              :                                          == get_class_binding (type, id));
    7859              :                   field = d->cur->index;
    7860              :                 }
    7861              :             }
    7862       534704 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7863              :             {
    7864       534698 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    7865       534698 :               field = get_class_binding (type, d->cur->index);
    7866       534698 :               direct_desig = true;
    7867              :             }
    7868              :           else
    7869              :             {
    7870            6 :               if (complain & tf_error)
    7871            6 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    7872              :                        " for class %qT", d->cur->index, type);
    7873            6 :               return error_mark_node;
    7874              :             }
    7875              : 
    7876       534698 :           if (!field && ANON_AGGR_TYPE_P (type))
    7877              :             /* Apparently the designator isn't for a member of this anonymous
    7878              :                struct, so head back to the enclosing class.  */
    7879              :             break;
    7880              : 
    7881       534695 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    7882              :             {
    7883           18 :               if (complain & tf_error)
    7884              :                 {
    7885            6 :                   if (field && TREE_CODE (field) == TREE_LIST)
    7886              :                     {
    7887            3 :                       auto_diagnostic_group g;
    7888            3 :                       error ("request for member %qD is ambiguous",
    7889            3 :                              d->cur->index);
    7890            3 :                       print_candidates (input_location, field);
    7891            3 :                     }
    7892              :                   else
    7893            3 :                     error ("%qT has no non-static data member named %qD", type,
    7894            3 :                            d->cur->index);
    7895              :                 }
    7896           18 :               return error_mark_node;
    7897              :             }
    7898              : 
    7899              :           /* If the element is an anonymous union object and the initializer
    7900              :              list is a designated-initializer-list, the anonymous union object
    7901              :              is initialized by the designated-initializer-list { D }, where D
    7902              :              is the designated-initializer-clause naming a member of the
    7903              :              anonymous union object.  */
    7904       534677 :           tree ictx = DECL_CONTEXT (field);
    7905       534677 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    7906              :             {
    7907              :               /* Find the anon aggr that is a direct member of TYPE.  */
    7908          151 :               while (ANON_AGGR_TYPE_P (ictx))
    7909              :                 {
    7910          148 :                   tree cctx = TYPE_CONTEXT (ictx);
    7911          148 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    7912          134 :                     goto found;
    7913              :                   ictx = cctx;
    7914              :                 }
    7915              : 
    7916              :               /* Not found, e.g. FIELD is a member of a base class.  */
    7917            3 :               if (complain & tf_error)
    7918            3 :                 error ("%qD is not a direct member of %qT", field, type);
    7919            3 :               return error_mark_node;
    7920              : 
    7921          134 :             found:
    7922              :               /* Now find the TYPE member with that anon aggr type.  */
    7923          134 :               tree aafield = TYPE_FIELDS (type);
    7924         1139 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    7925         1139 :                 if (TREE_TYPE (aafield) == ictx)
    7926              :                   break;
    7927            0 :               gcc_assert (aafield);
    7928              :               field = aafield;
    7929              :               direct_desig = false;
    7930              :             }
    7931              :         }
    7932              : 
    7933              :       /* If we processed all the member of the class, we are done.  */
    7934      6725260 :       if (!field)
    7935              :         break;
    7936              : 
    7937     13449864 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    7938      6724942 :                                  ? field : NULL_TREE);
    7939      6724942 :       if (last_was_pack_expansion)
    7940              :         /* Each non-trailing aggregate element that is a pack expansion is
    7941              :            assumed to correspond to no elements of the initializer list.  */
    7942           20 :         goto continue_;
    7943              : 
    7944      6724922 :       if (direct_desig)
    7945              :         {
    7946              :           /* The designated field F is initialized from this one element.
    7947              : 
    7948              :              Note that we don't want to do this if we found the designator
    7949              :              inside an anon aggr above; we use the normal code to implement:
    7950              : 
    7951              :              "If the element is an anonymous union member and the initializer
    7952              :              list is a brace-enclosed designated- initializer-list, the element
    7953              :              is initialized by the designated-initializer-list { D }, where D
    7954              :              is the designated- initializer-clause naming a member of the
    7955              :              anonymous union member."  */
    7956       534540 :           gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
    7957       534540 :           field_init = reshape_single_init (TREE_TYPE (field),
    7958              :                                             d->cur->value, complain);
    7959       534540 :           d->cur++;
    7960              :         }
    7961              :       else
    7962      6190382 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    7963              :                                      /*first_initializer_p=*/NULL_TREE,
    7964              :                                      complain);
    7965              : 
    7966      6724922 :       if (field_init == error_mark_node)
    7967              :         return error_mark_node;
    7968              : 
    7969      6724635 :       if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
    7970              :         {
    7971              :           /* This can happen with an invalid initializer for a flexible
    7972              :              array member (c++/54441).  */
    7973            0 :           if (complain & tf_error)
    7974            0 :             error ("invalid initializer for %q#D", field);
    7975            0 :           return error_mark_node;
    7976              :         }
    7977              : 
    7978      6724635 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    7979              : 
    7980              :       /* [dcl.init.aggr]
    7981              : 
    7982              :         When a union  is  initialized with a brace-enclosed
    7983              :         initializer, the braces shall only contain an
    7984              :         initializer for the first member of the union.  */
    7985      6724635 :       if (TREE_CODE (type) == UNION_TYPE)
    7986              :         break;
    7987              : 
    7988      6621245 :     continue_:
    7989      6621265 :       if (base_binfo)
    7990              :         {
    7991          101 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    7992              :             field = base_binfo;
    7993              :           else
    7994           38 :             field = next_aggregate_field (TYPE_FIELDS (type));
    7995              :         }
    7996              :       else
    7997      6621164 :         field = next_aggregate_field (DECL_CHAIN (field));
    7998              :     }
    7999              : 
    8000              :   /* A trailing aggregate element that is a pack expansion is assumed to
    8001              :      correspond to all remaining elements of the initializer list (if any).  */
    8002      3337708 :   if (last_was_pack_expansion)
    8003              :     {
    8004           17 :       tree init = d->cur->value;
    8005           17 :       bool inc_cur;
    8006           17 :       if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
    8007            0 :         init = raw_init;
    8008           17 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    8009              :                               last_was_pack_expansion, init);
    8010           49 :       while (d->cur != d->end)
    8011           32 :         d->cur++;
    8012              :     }
    8013              : 
    8014              :   return new_init;
    8015              : }
    8016              : 
    8017              : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    8018              :    designators are not valid; either complain or return true to indicate
    8019              :    that reshape_init_r should return error_mark_node.  */
    8020              : 
    8021              : static bool
    8022       240557 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    8023              : {
    8024       240557 :   if (d->cur->index)
    8025              :     {
    8026           30 :       if (complain & tf_error)
    8027           45 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    8028              :                   "C99 designator %qE outside aggregate initializer",
    8029              :                   d->cur->index);
    8030              :       else
    8031              :         return true;
    8032              :     }
    8033              :   return false;
    8034              : }
    8035              : 
    8036              : /* Subroutine of reshape_init, which processes a single initializer (part of
    8037              :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    8038              :    iterator within the CONSTRUCTOR which points to the initializer to process.
    8039              :    If this is the first initializer of the outermost CONSTRUCTOR node,
    8040              :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    8041              : 
    8042              : static tree
    8043     64807352 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    8044              :                 tsubst_flags_t complain)
    8045              : {
    8046     64807352 :   tree init = d->cur->value;
    8047              : 
    8048     64807352 :   if (error_operand_p (init))
    8049          134 :     return error_mark_node;
    8050              : 
    8051      4018783 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    8052     65047596 :       && has_designator_problem (d, complain))
    8053            0 :     return error_mark_node;
    8054              : 
    8055     64807218 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    8056              : 
    8057     64807218 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    8058              :     {
    8059              :       /* A complex type can be initialized from one or two initializers,
    8060              :          but braces are not elided.  */
    8061          678 :       init = consume_init (init, d);
    8062          678 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    8063              :         {
    8064            9 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    8065              :             {
    8066            0 :               if (complain & tf_error)
    8067            0 :                 error ("too many initializers for %qT", type);
    8068              :               else
    8069            0 :                 return error_mark_node;
    8070              :             }
    8071              :         }
    8072          669 :       else if (first_initializer_p && d->cur != d->end)
    8073              :         {
    8074           36 :           if (error_operand_p (d->cur->value)
    8075           36 :               || has_designator_problem (d, complain))
    8076            0 :             return error_mark_node;
    8077           36 :           vec<constructor_elt, va_gc> *v = 0;
    8078           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8079           36 :           init = consume_init (d->cur->value, d);
    8080           36 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    8081           36 :           init = build_constructor (init_list_type_node, v);
    8082              :         }
    8083          678 :       return init;
    8084              :     }
    8085              : 
    8086              :   /* A non-aggregate type is always initialized with a single
    8087              :      initializer.  */
    8088    129556277 :   if (!CP_AGGREGATE_TYPE_P (type)
    8089              :       /* As is an array with dependent bound, which we can see
    8090              :          during C++20 aggregate CTAD.  */
    8091     70060068 :       || (cxx_dialect >= cxx20
    8092      5204748 :           && TREE_CODE (type) == ARRAY_TYPE
    8093       481850 :           && uses_template_parms (TYPE_DOMAIN (type))))
    8094              :     {
    8095              :       /* It is invalid to initialize a non-aggregate type with a
    8096              :          brace-enclosed initializer before C++0x.
    8097              :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    8098              :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    8099              :          a CONSTRUCTOR (with a record type).  */
    8100     59496220 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    8101              :           /* Don't complain about a capture-init.  */
    8102       292600 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    8103     59778519 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    8104              :         {
    8105       282260 :           if (SCALAR_TYPE_P (type))
    8106              :             {
    8107          478 :               if (cxx_dialect < cxx11)
    8108              :                 {
    8109           16 :                   if (complain & tf_error)
    8110           16 :                     error ("braces around scalar initializer for type %qT",
    8111              :                            type);
    8112           16 :                   init = error_mark_node;
    8113              :                 }
    8114          462 :               else if (first_initializer_p
    8115          462 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    8116          296 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    8117              :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    8118              :                 {
    8119           13 :                   if (complain & tf_error)
    8120           13 :                     error ("too many braces around scalar initializer "
    8121              :                            "for type %qT", type);
    8122           13 :                   init = error_mark_node;
    8123              :                 }
    8124              :             }
    8125              :           else
    8126       281782 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8127              :         }
    8128     59496220 :       return consume_init (init, d);
    8129              :     }
    8130              : 
    8131              :   /* "If T is a class type and the initializer list has a single element of
    8132              :      type cv U, where U is T or a class derived from T, the object is
    8133              :      initialized from that element."  Even if T is an aggregate.  */
    8134      5286429 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    8135      4779008 :       && first_initializer_p
    8136              :       /* But not if it's a designated init.  */
    8137      3370892 :       && !d->cur->index
    8138      3102960 :       && d->end - d->cur == 1
    8139       581339 :       && TREE_CODE (init) != RAW_DATA_CST
    8140      5891659 :       && reference_related_p (type, TREE_TYPE (init)))
    8141              :     {
    8142          426 :       d->cur++;
    8143          426 :       return init;
    8144              :     }
    8145              : 
    8146              :   /* [dcl.init.aggr]
    8147              : 
    8148              :      All implicit type conversions (clause _conv_) are considered when
    8149              :      initializing the aggregate member with an initializer from an
    8150              :      initializer-list.  If the initializer can initialize a member,
    8151              :      the member is initialized.  Otherwise, if the member is itself a
    8152              :      non-empty subaggregate, brace elision is assumed and the
    8153              :      initializer is considered for the initialization of the first
    8154              :      member of the subaggregate.  */
    8155      2129483 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    8156              :       /* But don't try this for the first initializer, since that would be
    8157              :          looking through the outermost braces; A a2 = { a1 }; is not a
    8158              :          valid aggregate initialization.  */
    8159      3180477 :       && !first_initializer_p
    8160      5323897 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    8161         9353 :           || can_convert_arg (type, TREE_TYPE (init),
    8162         9353 :                               TREE_CODE (init) == RAW_DATA_CST
    8163      5311500 :                               ? build_int_cst (integer_type_node,
    8164         1606 :                                                *(const unsigned char *)
    8165         1606 :                                                RAW_DATA_POINTER (init))
    8166              :                               : init,
    8167              :                               LOOKUP_NORMAL, complain)))
    8168         4686 :     return consume_init (init, d);
    8169              : 
    8170              :   /* [dcl.init.string]
    8171              : 
    8172              :       A char array (whether plain char, signed char, or unsigned char)
    8173              :       can be initialized by a string-literal (optionally enclosed in
    8174              :       braces); a wchar_t array can be initialized by a wide
    8175              :       string-literal (optionally enclosed in braces).  */
    8176      5305208 :   if (TREE_CODE (type) == ARRAY_TYPE
    8177      5305208 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    8178              :     {
    8179       106694 :       tree str_init = init;
    8180       106694 :       tree stripped_str_init = stripped_init;
    8181       106694 :       reshape_iter stripd = {};
    8182              : 
    8183              :       /* Strip one level of braces if and only if they enclose a single
    8184              :          element (as allowed by [dcl.init.string]).  */
    8185       106694 :       if (!first_initializer_p
    8186         2718 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    8187       108276 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    8188              :         {
    8189          392 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    8190          392 :           str_init = stripd.cur->value;
    8191          392 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    8192              :         }
    8193              : 
    8194              :       /* If it's a string literal, then it's the initializer for the array
    8195              :          as a whole. Otherwise, continue with normal initialization for
    8196              :          array types (one value per array element).  */
    8197       106694 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    8198              :         {
    8199           72 :           if ((first_initializer_p && has_designator_problem (d, complain))
    8200         1062 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    8201          990 :             return error_mark_node;
    8202          990 :           d->cur++;
    8203          990 :           return str_init;
    8204              :         }
    8205              :     }
    8206              : 
    8207              :   /* The following cases are about aggregates. If we are not within a full
    8208              :      initializer already, and there is not a CONSTRUCTOR, it means that there
    8209              :      is a missing set of braces (that is, we are processing the case for
    8210              :      which reshape_init exists).  */
    8211      5304218 :   bool braces_elided_p = false;
    8212      5304218 :   if (!first_initializer_p)
    8213              :     {
    8214      1526311 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    8215              :         {
    8216      1517849 :           tree init_type = TREE_TYPE (init);
    8217      1517849 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    8218              :             /* There is no need to call reshape_init for pointer-to-member
    8219              :                function initializers, as they are always constructed correctly
    8220              :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    8221              :                which is missing outermost braces.  We should warn below, and
    8222              :                one of the routines below will wrap it in additional { }.  */;
    8223              :           /* For a nested compound literal, proceed to specialized routines,
    8224              :              to handle initialization of arrays and similar.  */
    8225      1517840 :           else if (COMPOUND_LITERAL_P (stripped_init))
    8226            8 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8227              :           /* If we have an unresolved designator, we need to find the member it
    8228              :              designates within TYPE, so proceed to the routines below.  For
    8229              :              FIELD_DECL or INTEGER_CST designators, we're already initializing
    8230              :              the designated element.  */
    8231      1517832 :           else if (d->cur->index
    8232           30 :                    && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    8233              :             /* Brace elision with designators is only permitted for anonymous
    8234              :                aggregates.  */
    8235           15 :             gcc_checking_assert (ANON_AGGR_TYPE_P (type));
    8236              :           /* A CONSTRUCTOR of the target's type is a previously
    8237              :              digested initializer.  */
    8238      1517817 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    8239              :             {
    8240            0 :               ++d->cur;
    8241            0 :               return init;
    8242              :             }
    8243              :           else
    8244              :             {
    8245              :               /* Something that hasn't been reshaped yet.  */
    8246      1517817 :               ++d->cur;
    8247      1517817 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    8248      1517817 :               return reshape_init (type, init, complain);
    8249              :             }
    8250              :         }
    8251              : 
    8252         8494 :       if (complain & tf_warning)
    8253         7336 :         warning (OPT_Wmissing_braces,
    8254              :                  "missing braces around initializer for %qT",
    8255              :                  type);
    8256              :       braces_elided_p = true;
    8257              :     }
    8258              : 
    8259              :   /* Dispatch to specialized routines.  */
    8260      3786401 :   tree new_init;
    8261      3786401 :   if (CLASS_TYPE_P (type))
    8262      3338350 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    8263       448051 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    8264       400052 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    8265        47999 :   else if (VECTOR_TYPE_P (type))
    8266        47999 :     new_init = reshape_init_vector (type, d, complain);
    8267              :   else
    8268            0 :     gcc_unreachable ();
    8269              : 
    8270      3786401 :   if (braces_elided_p
    8271         8494 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    8272         8220 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    8273              : 
    8274              :   return new_init;
    8275              : }
    8276              : 
    8277              : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    8278              :    brace-enclosed aggregate initializer.
    8279              : 
    8280              :    INIT is the CONSTRUCTOR containing the list of initializers describing
    8281              :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    8282              :    It may not presently match the shape of the TYPE; for example:
    8283              : 
    8284              :      struct S { int a; int b; };
    8285              :      struct S a[] = { 1, 2, 3, 4 };
    8286              : 
    8287              :    Here INIT will hold a vector of four elements, rather than a
    8288              :    vector of two elements, each itself a vector of two elements.  This
    8289              :    routine transforms INIT from the former form into the latter.  The
    8290              :    revised CONSTRUCTOR node is returned.  */
    8291              : 
    8292              : tree
    8293     11584471 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    8294              : {
    8295     11584471 :   vec<constructor_elt, va_gc> *v;
    8296     11584471 :   reshape_iter d;
    8297     11584471 :   tree new_init;
    8298              : 
    8299     11584471 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    8300              : 
    8301     11584471 :   v = CONSTRUCTOR_ELTS (init);
    8302              : 
    8303              :   /* An empty constructor does not need reshaping, and it is always a valid
    8304              :      initializer.  */
    8305     11585258 :   if (vec_safe_is_empty (v))
    8306              :     return init;
    8307              : 
    8308      4019909 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    8309              :     /* Already reshaped.  */
    8310              :     return init;
    8311              : 
    8312              :   /* Brace elision is not performed for a CONSTRUCTOR representing
    8313              :      parenthesized aggregate initialization.  */
    8314      4019763 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    8315              :     {
    8316          675 :       tree elt = (*v)[0].value;
    8317              :       /* If we're initializing a char array from a string-literal that is
    8318              :          enclosed in braces, unwrap it here.  */
    8319          675 :       if (TREE_CODE (type) == ARRAY_TYPE
    8320          277 :           && vec_safe_length (v) == 1
    8321          149 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    8322          714 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    8323              :         return elt;
    8324          641 :       return init;
    8325              :     }
    8326              : 
    8327              :   /* Handle [dcl.init.list] direct-list-initialization from
    8328              :      single element of enumeration with a fixed underlying type.  */
    8329      4019088 :   if (is_direct_enum_init (type, init))
    8330              :     {
    8331          174 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    8332          174 :       type = cv_unqualified (type);
    8333          174 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    8334              :         {
    8335          159 :           warning_sentinel w (warn_useless_cast);
    8336          159 :           warning_sentinel w2 (warn_ignored_qualifiers);
    8337          159 :           return cp_build_c_cast (input_location, type, elt,
    8338              :                                   tf_warning_or_error);
    8339          159 :         }
    8340              :       else
    8341           15 :         return error_mark_node;
    8342              :     }
    8343              : 
    8344              :   /* Recurse on this CONSTRUCTOR.  */
    8345      4018914 :   d.cur = &(*v)[0];
    8346      4018914 :   d.end = d.cur + v->length ();
    8347      4018914 :   d.raw_idx = 0;
    8348              : 
    8349      4018914 :   new_init = reshape_init_r (type, &d, init, complain);
    8350      4018914 :   if (new_init == error_mark_node)
    8351              :     return error_mark_node;
    8352              : 
    8353              :   /* Make sure all the element of the constructor were used. Otherwise,
    8354              :      issue an error about exceeding initializers.  */
    8355      4018286 :   if (d.cur != d.end)
    8356              :     {
    8357          207 :       if (complain & tf_error)
    8358           64 :         error ("too many initializers for %qT", type);
    8359          207 :       return error_mark_node;
    8360              :     }
    8361              : 
    8362      4018079 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    8363      4018079 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8364       545578 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    8365      4018079 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    8366      4018079 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    8367        71341 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    8368              :                          || seen_error ());
    8369              : 
    8370              :   return new_init;
    8371              : }
    8372              : 
    8373              : /* Verify array initializer.  Returns true if errors have been reported.  */
    8374              : 
    8375              : bool
    8376       968161 : check_array_initializer (tree decl, tree type, tree init)
    8377              : {
    8378       968161 :   tree element_type = TREE_TYPE (type);
    8379              : 
    8380              :   /* Structured binding when initialized with an array type needs
    8381              :      to have complete type.  */
    8382       968161 :   if (decl
    8383       951547 :       && DECL_DECOMPOSITION_P (decl)
    8384         3355 :       && DECL_DECOMP_IS_BASE (decl)
    8385       971516 :       && !COMPLETE_TYPE_P (type))
    8386              :     {
    8387            0 :       error_at (DECL_SOURCE_LOCATION (decl),
    8388              :                 "structured binding has incomplete type %qT", type);
    8389            0 :       TREE_TYPE (decl) = error_mark_node;
    8390            0 :       return true;
    8391              :     }
    8392              : 
    8393              :   /* The array type itself need not be complete, because the
    8394              :      initializer may tell us how many elements are in the array.
    8395              :      But, the elements of the array must be complete.  */
    8396       968161 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    8397              :     {
    8398           15 :       if (decl)
    8399            9 :         error_at (DECL_SOURCE_LOCATION (decl),
    8400              :                   "elements of array %q#D have incomplete type", decl);
    8401              :       else
    8402            6 :         error ("elements of array %q#T have incomplete type", type);
    8403           15 :       return true;
    8404              :     }
    8405              : 
    8406       968146 :   location_t loc = (decl ? location_of (decl) : input_location);
    8407       968146 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    8408              :     return true;
    8409              : 
    8410              :   /* A compound literal can't have variable size.  */
    8411       968146 :   if (init && !decl
    8412       968146 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    8413        16605 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    8414              :     {
    8415            3 :       error ("variable-sized compound literal");
    8416            3 :       return true;
    8417              :     }
    8418              :   return false;
    8419              : }
    8420              : 
    8421              : /* Subroutine of check_initializer; args are passed down from that function.
    8422              :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    8423              : 
    8424              : static tree
    8425      2977243 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    8426              : {
    8427      2977243 :   gcc_assert (stmts_are_full_exprs_p ());
    8428      2977243 :   if (init)
    8429      2433130 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    8430      2977243 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    8431              : }
    8432              : 
    8433              : /* Verify INIT (the initializer for DECL), and record the
    8434              :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    8435              :    grok_reference_init.
    8436              : 
    8437              :    If the return value is non-NULL, it is an expression that must be
    8438              :    evaluated dynamically to initialize DECL.  */
    8439              : 
    8440              : static tree
    8441     55389440 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    8442              : {
    8443     55389440 :   tree type;
    8444     55389440 :   tree init_code = NULL;
    8445     55389440 :   tree core_type;
    8446              : 
    8447              :   /* Things that are going to be initialized need to have complete
    8448              :      type.  */
    8449     55389440 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    8450              : 
    8451     55389440 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    8452              :     {
    8453              :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    8454              :          it doesn't have storage to be initialized.  */
    8455          108 :       gcc_assert (init == NULL_TREE);
    8456              :       return NULL_TREE;
    8457              :     }
    8458              : 
    8459     55389332 :   if (type == error_mark_node)
    8460              :     /* We will have already complained.  */
    8461              :     return NULL_TREE;
    8462              : 
    8463     55389332 :   if (TREE_CODE (type) == ARRAY_TYPE)
    8464              :     {
    8465       951547 :       if (check_array_initializer (decl, type, init))
    8466              :         return NULL_TREE;
    8467              :     }
    8468     54437785 :   else if (!COMPLETE_TYPE_P (type))
    8469              :     {
    8470           37 :       error_at (DECL_SOURCE_LOCATION (decl),
    8471              :                 "%q#D has incomplete type", decl);
    8472           37 :       TREE_TYPE (decl) = error_mark_node;
    8473           37 :       return NULL_TREE;
    8474              :     }
    8475              :   else
    8476              :     /* There is no way to make a variable-sized class type in GNU C++.  */
    8477     54437748 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    8478              : 
    8479     55389286 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    8480              :     {
    8481      2786932 :       int init_len = CONSTRUCTOR_NELTS (init);
    8482      2786932 :       if (SCALAR_TYPE_P (type))
    8483              :         {
    8484        64850 :           if (init_len == 0)
    8485              :             {
    8486        33061 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    8487        33061 :               init = build_zero_init (type, NULL_TREE, false);
    8488              :             }
    8489        31789 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    8490              :             {
    8491           12 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8492              :                         "scalar object %qD requires one element in "
    8493              :                         "initializer", decl);
    8494            6 :               TREE_TYPE (decl) = error_mark_node;
    8495            6 :               return NULL_TREE;
    8496              :             }
    8497              :         }
    8498              :     }
    8499              : 
    8500     55389280 :   if (TREE_CODE (decl) == CONST_DECL)
    8501              :     {
    8502            0 :       gcc_assert (!TYPE_REF_P (type));
    8503              : 
    8504            0 :       DECL_INITIAL (decl) = init;
    8505              : 
    8506            0 :       gcc_assert (init != NULL_TREE);
    8507              :       init = NULL_TREE;
    8508              :     }
    8509     55389280 :   else if (!init && DECL_REALLY_EXTERN (decl))
    8510              :     ;
    8511     55389280 :   else if (flag_openmp
    8512       189507 :            && VAR_P (decl)
    8513       189507 :            && DECL_LANG_SPECIFIC (decl)
    8514       110718 :            && DECL_OMP_DECLARE_MAPPER_P (decl)
    8515     55389280 :            && TREE_CODE (init) == OMP_DECLARE_MAPPER)
    8516              :     return NULL_TREE;
    8517      4121312 :   else if (init || type_build_ctor_call (type)
    8518     58966476 :            || TYPE_REF_P (type))
    8519              :     {
    8520     51812099 :       if (TYPE_REF_P (type))
    8521              :         {
    8522       358887 :           init = grok_reference_init (decl, type, init, flags);
    8523       358887 :           flags |= LOOKUP_ALREADY_DIGESTED;
    8524              :         }
    8525     51453212 :       else if (!init)
    8526       544116 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8527              :                                            tf_warning_or_error);
    8528              :       /* Do not reshape constructors of vectors (they don't need to be
    8529              :          reshaped.  */
    8530     50909096 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    8531              :         {
    8532      2753507 :           if (is_std_init_list (type))
    8533              :             {
    8534          346 :               init = perform_implicit_conversion (type, init,
    8535              :                                                   tf_warning_or_error);
    8536          346 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8537              :             }
    8538      2753161 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    8539              :             {
    8540              :               /* Don't reshape if the class has constructors.  */
    8541       432886 :               if (cxx_dialect == cxx98)
    8542            6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    8543              :                           "in C++98 %qD must be initialized by "
    8544              :                           "constructor, not by %<{...}%>",
    8545              :                           decl);
    8546              :             }
    8547      2320275 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    8548              :             {
    8549            0 :               error ("opaque vector types cannot be initialized");
    8550            0 :               init = error_mark_node;
    8551              :             }
    8552              :           else
    8553              :             {
    8554      2320275 :               init = reshape_init (type, init, tf_warning_or_error);
    8555      2320275 :               flags |= LOOKUP_NO_NARROWING;
    8556              :             }
    8557              :         }
    8558              :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    8559              :          is initialized as follows..."  So handle things like
    8560              : 
    8561              :           int a[](1, 2, 3);
    8562              : 
    8563              :          which is permitted in C++20 by P0960.  */
    8564     48155589 :       else if (TREE_CODE (init) == TREE_LIST
    8565       719540 :                && TREE_TYPE (init) == NULL_TREE
    8566       719540 :                && TREE_CODE (type) == ARRAY_TYPE
    8567          182 :                && !DECL_DECOMPOSITION_P (decl)
    8568     48155741 :                && (cxx_dialect >= cxx20))
    8569          142 :         init = do_aggregate_paren_init (init, type);
    8570     48155447 :       else if (TREE_CODE (init) == TREE_LIST
    8571       719398 :                && TREE_TYPE (init) != unknown_type_node
    8572     48874845 :                && !MAYBE_CLASS_TYPE_P (type))
    8573              :         {
    8574       126743 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8575              : 
    8576              :           /* We get here with code like `int a (2);' */
    8577       126743 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    8578              :                                                   tf_warning_or_error);
    8579              :         }
    8580              : 
    8581              :       /* If DECL has an array type without a specific bound, deduce the
    8582              :          array size from the initializer.  */
    8583     51812099 :       maybe_deduce_size_from_array_init (decl, init);
    8584     51812099 :       type = TREE_TYPE (decl);
    8585     51812099 :       if (type == error_mark_node)
    8586              :         return NULL_TREE;
    8587              : 
    8588    100388655 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    8589      5055588 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    8590      7569428 :            && !(init
    8591      4511129 :                 && BRACE_ENCLOSED_INITIALIZER_P (init)
    8592      5028372 :                 && CP_AGGREGATE_TYPE_P (type)))
    8593    100650248 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    8594              :         {
    8595      2977243 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    8596              : 
    8597              :           /* A constructor call is a non-trivial initializer even if
    8598              :              it isn't explicitly written.  */
    8599      2977243 :           if (TREE_SIDE_EFFECTS (init_code))
    8600      2955079 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    8601              : 
    8602              :           /* If this is a constexpr initializer, expand_default_init will
    8603              :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    8604              :              case, pull the initializer back out and pass it down into
    8605              :              store_init_value.  */
    8606      7918185 :           while (true)
    8607              :             {
    8608      7918185 :               if (TREE_CODE (init_code) == EXPR_STMT
    8609      4967342 :                   || TREE_CODE (init_code) == STMT_EXPR
    8610      4931103 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    8611      4904795 :                 init_code = TREE_OPERAND (init_code, 0);
    8612      3013390 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    8613        36147 :                 init_code = BIND_EXPR_BODY (init_code);
    8614              :               else
    8615              :                 break;
    8616              :             }
    8617      2977243 :           if (TREE_CODE (init_code) == INIT_EXPR)
    8618              :             {
    8619              :               /* In C++20, the call to build_aggr_init could have created
    8620              :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    8621              :                  A(1, 2).  */
    8622      1939396 :               init = TREE_OPERAND (init_code, 1);
    8623      1939396 :               init_code = NULL_TREE;
    8624              :               /* Don't call digest_init; it's unnecessary and will complain
    8625              :                  about aggregate initialization of non-aggregate classes.  */
    8626      1939396 :               flags |= LOOKUP_ALREADY_DIGESTED;
    8627              :             }
    8628      1037847 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    8629      2057345 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    8630              :             {
    8631              :               /* Declared constexpr or constinit, but no suitable initializer;
    8632              :                  massage init appropriately so we can pass it into
    8633              :                  store_init_value for the error.  */
    8634        18367 :               tree new_init = NULL_TREE;
    8635        18367 :               if (!processing_template_decl
    8636          268 :                   && TREE_CODE (init_code) == CALL_EXPR)
    8637          232 :                 new_init = build_cplus_new (type, init_code, tf_none);
    8638        18135 :               else if (CLASS_TYPE_P (type)
    8639        36270 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    8640        18030 :                 new_init = build_functional_cast (input_location, type,
    8641              :                                                   init, tf_none);
    8642        18262 :               if (new_init)
    8643              :                 {
    8644        18262 :                   init = new_init;
    8645        18262 :                   if (TREE_CODE (init) == TARGET_EXPR
    8646          258 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    8647          258 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    8648              :                 }
    8649              :               init_code = NULL_TREE;
    8650              :             }
    8651              :           else
    8652              :             init = NULL_TREE;
    8653              :         }
    8654              : 
    8655     50792615 :       if (init && TREE_CODE (init) != TREE_VEC)
    8656              :         {
    8657     50792600 :           init_code = store_init_value (decl, init, cleanups, flags);
    8658              : 
    8659     50789903 :           if (DECL_INITIAL (decl)
    8660     36810993 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    8661     53729663 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    8662              :             {
    8663      1289214 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    8664      1289214 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    8665      1289214 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    8666           36 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    8667              :             }
    8668              : 
    8669      2512143 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    8670        65210 :               && DECL_INITIAL (decl)
    8671        64474 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    8672     50850126 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    8673            6 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    8674            3 :                                          DECL_SOURCE_LOCATION (decl)),
    8675            3 :                         0, "array %qD initialized by parenthesized "
    8676              :                         "string literal %qE",
    8677            3 :                         decl, DECL_INITIAL (decl));
    8678              :           init = NULL_TREE;
    8679              :         }
    8680              :     }
    8681      3577181 :   else if (!init && REFLECTION_TYPE_P (type))
    8682              :     {
    8683              :       /* [dcl.init.general]: To default-initialize an object of type
    8684              :          std::meta::info means that the object is zero-initialized.  */
    8685          154 :       DECL_INITIAL (decl)
    8686          154 :         = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
    8687          154 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    8688          154 :       TREE_CONSTANT (decl) = true;
    8689          154 :       init = NULL_TREE;
    8690              :     }
    8691              :   else
    8692              :     {
    8693      7154054 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    8694      4362920 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    8695       785878 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    8696           21 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    8697              :                                                   /*complain=*/true);
    8698              : 
    8699      3577027 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    8700              :                                          tf_warning_or_error);
    8701              :     }
    8702              : 
    8703          154 :   if (init && init != error_mark_node)
    8704            0 :     init_code = cp_build_init_expr (decl, init);
    8705              : 
    8706     15137731 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    8707     55441238 :       && init_code != error_mark_node)
    8708              :     init_code = NULL_TREE;
    8709              : 
    8710     55334190 :   if (init_code)
    8711              :     {
    8712              :       /* We might have set these in cp_finish_decl.  */
    8713     15085342 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    8714     15085342 :       TREE_CONSTANT (decl) = false;
    8715              :     }
    8716              : 
    8717     15085342 :   if (init_code
    8718     15085342 :       && DECL_IN_AGGR_P (decl)
    8719            6 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8720              :     {
    8721            0 :       static int explained = 0;
    8722              : 
    8723            0 :       auto_diagnostic_group d;
    8724            0 :       if (cxx_dialect < cxx11)
    8725            0 :         error ("initializer invalid for static member with constructor");
    8726            0 :       else if (cxx_dialect < cxx17)
    8727            0 :         error ("non-constant in-class initialization invalid for static "
    8728              :                "member %qD", decl);
    8729              :       else
    8730            0 :         error ("non-constant in-class initialization invalid for non-inline "
    8731              :                "static member %qD", decl);
    8732            0 :       if (!explained)
    8733              :         {
    8734            0 :           inform (input_location,
    8735              :                   "(an out of class initialization is required)");
    8736            0 :           explained = 1;
    8737              :         }
    8738            0 :       return NULL_TREE;
    8739            0 :     }
    8740              : 
    8741              :   return init_code;
    8742              : }
    8743              : 
    8744              : /* If DECL is not a local variable, give it RTL.  */
    8745              : 
    8746              : static void
    8747    118765138 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    8748              : {
    8749    118765138 :   int toplev = toplevel_bindings_p ();
    8750    118765138 :   int defer_p;
    8751              : 
    8752              :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    8753    118765138 :   if (asmspec)
    8754              :     {
    8755              :       /* The `register' keyword, when used together with an
    8756              :          asm-specification, indicates that the variable should be
    8757              :          placed in a particular register.  */
    8758       988637 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    8759              :         {
    8760           87 :           if (TREE_ADDRESSABLE (decl))
    8761            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    8762              :                       "address of explicit register variable %qD requested",
    8763              :                       decl);
    8764              :           else
    8765              :             {
    8766           84 :               set_user_assembler_name (decl, asmspec);
    8767           84 :               DECL_HARD_REGISTER (decl) = 1;
    8768              :             }
    8769              :         }
    8770              :       else
    8771              :         {
    8772       988550 :           if (TREE_CODE (decl) == FUNCTION_DECL
    8773       988550 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    8774        79014 :             set_builtin_user_assembler_name (decl, asmspec);
    8775       988550 :           set_user_assembler_name (decl, asmspec);
    8776       988550 :           if (DECL_LOCAL_DECL_P (decl))
    8777            6 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    8778              :               /* We have to propagate the name to the ns-alias.
    8779              :                  This is horrible, as we're affecting a
    8780              :                  possibly-shared decl.  Again, a one-true-decl
    8781              :                  model breaks down.  */
    8782            6 :               if (ns_decl != error_mark_node)
    8783            6 :                 set_user_assembler_name (ns_decl, asmspec);
    8784              :         }
    8785              :     }
    8786              : 
    8787              :   /* Handle non-variables up front.  */
    8788    118765138 :   if (!VAR_P (decl))
    8789              :     {
    8790     56864499 :       rest_of_decl_compilation (decl, toplev, at_eof);
    8791     56864499 :       return;
    8792              :     }
    8793              : 
    8794              :   /* If we see a class member here, it should be a static data
    8795              :      member.  */
    8796     61900639 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    8797              :     {
    8798      5403097 :       gcc_assert (TREE_STATIC (decl));
    8799              :       /* An in-class declaration of a static data member should be
    8800              :          external; it is only a declaration, and not a definition.  */
    8801      5403097 :       if (init == NULL_TREE)
    8802      5403072 :         gcc_assert (DECL_EXTERNAL (decl)
    8803              :                     || !TREE_PUBLIC (decl));
    8804              :     }
    8805              : 
    8806              :   /* We don't create any RTL for local variables.  */
    8807     61900639 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8808              :     return;
    8809              : 
    8810              :   /* Don't output reflection variables.  */
    8811     38056191 :   if (consteval_only_p (decl))
    8812              :     {
    8813              :       /* Disable assemble_variable.  */
    8814         1772 :       DECL_EXTERNAL (decl) = true;
    8815              :       /* Undo make_decl_one_only.  */
    8816         1772 :       if (DECL_COMDAT_GROUP (decl))
    8817              :         {
    8818          308 :           symtab_node *node = symtab_node::get (decl);
    8819          308 :           node->set_comdat_group (NULL);
    8820          308 :           node->dissolve_same_comdat_group_list ();
    8821              :         }
    8822         1772 :       return;
    8823              :     }
    8824              : 
    8825              :   /* We defer emission of local statics until the corresponding
    8826              :      DECL_EXPR is expanded.  But with constexpr its function might never
    8827              :      be expanded, so go ahead and tell cgraph about the variable now.  */
    8828     76108838 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    8829       135688 :               && !var_in_maybe_constexpr_fn (decl))
    8830     75976489 :              || DECL_VIRTUAL_P (decl));
    8831              : 
    8832              :   /* Defer template instantiations.  */
    8833     38054419 :   if (DECL_LANG_SPECIFIC (decl)
    8834     38054419 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    8835              :     defer_p = 1;
    8836              : 
    8837              :   /* If we're not deferring, go ahead and assemble the variable.  */
    8838     19659683 :   if (!defer_p)
    8839     17340962 :     rest_of_decl_compilation (decl, toplev, at_eof);
    8840              : }
    8841              : 
    8842              : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    8843              : 
    8844              : static tree
    8845     10492230 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    8846              : {
    8847              :   /* Stop at types or full-expression boundaries.  */
    8848     10492230 :   if (TYPE_P (*stmt_p)
    8849     10492003 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    8850              :     {
    8851          487 :       *walk_subtrees = 0;
    8852          487 :       return NULL_TREE;
    8853              :     }
    8854              : 
    8855     10491743 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    8856              :     {
    8857       221064 :       tree guard = (tree)data;
    8858       221064 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    8859              : 
    8860       110292 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    8861       327997 :           && !expr_noexcept_p (tcleanup, tf_none))
    8862              :         {
    8863          145 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    8864              :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    8865              :              cleanup.  */
    8866          145 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    8867          145 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    8868              :         }
    8869              :     }
    8870              : 
    8871              :   return NULL_TREE;
    8872              : }
    8873              : 
    8874              : /* We're initializing a local variable which has a cleanup GUARD.  If there
    8875              :    are any temporaries used in the initializer INIT of this variable, we
    8876              :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    8877              :    variable will be cleaned up properly if one of them throws.
    8878              : 
    8879              :    Unfortunately, there's no way to express this properly in terms of
    8880              :    nesting, as the regions for the temporaries overlap the region for the
    8881              :    variable itself; if there are two temporaries, the variable needs to be
    8882              :    the first thing destroyed if either of the temporary destructors throws.
    8883              :    However, we only want to run the variable's cleanup if it actually got
    8884              :    constructed.  So we need to guard the temporary cleanups with the
    8885              :    variable's cleanup if they are run on the normal path, but not if they
    8886              :    are run on the exceptional path.  We implement this by telling
    8887              :    honor_protect_cleanup_actions to strip the variable cleanup from the
    8888              :    exceptional path.
    8889              : 
    8890              :    Another approach could be to make the variable cleanup region enclose
    8891              :    initialization, but depend on a flag to indicate that the variable is
    8892              :    initialized; that's effectively what we do for arrays.  But the current
    8893              :    approach works fine for non-arrays, and has no code overhead in the usual
    8894              :    case where the temporary destructors are noexcept.  */
    8895              : 
    8896              : static void
    8897       953418 : wrap_temporary_cleanups (tree init, tree guard)
    8898              : {
    8899       953418 :   if (TREE_CODE (guard) == BIND_EXPR)
    8900              :     {
    8901              :       /* An array cleanup region already encloses any temporary cleanups,
    8902              :          don't wrap it around them again.  */
    8903          407 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    8904              :       return;
    8905              :     }
    8906       953011 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    8907              : }
    8908              : 
    8909              : /* Generate code to initialize DECL (a local variable).  */
    8910              : 
    8911              : static void
    8912     23844430 : initialize_local_var (tree decl, tree init, bool decomp)
    8913              : {
    8914     23844430 :   tree type = TREE_TYPE (decl);
    8915     23844430 :   tree cleanup;
    8916     23844430 :   int already_used;
    8917              : 
    8918     23844430 :   gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
    8919     23844430 :   gcc_assert (!TREE_STATIC (decl));
    8920              : 
    8921     23844430 :   if (DECL_SIZE (decl) == NULL_TREE)
    8922              :     {
    8923              :       /* If we used it already as memory, it must stay in memory.  */
    8924            0 :       DECL_INITIAL (decl) = NULL_TREE;
    8925            0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    8926            0 :       return;
    8927              :     }
    8928              : 
    8929     23844430 :   if (type == error_mark_node)
    8930              :     return;
    8931              : 
    8932              :   /* Compute and store the initial value.  */
    8933     23844430 :   already_used = TREE_USED (decl) || TREE_USED (type);
    8934     23844430 :   if (TREE_USED (type))
    8935           32 :     DECL_READ_P (decl) = 1;
    8936              : 
    8937              :   /* Generate a cleanup, if necessary.  */
    8938     23844430 :   cleanup = (decomp ? NULL_TREE
    8939     23811707 :              : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
    8940              : 
    8941              :   /* Perform the initialization.  */
    8942     23844430 :   if (init)
    8943              :     {
    8944     15071315 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    8945     15071315 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    8946     13802043 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    8947     21399391 :           && TREE_OPERAND (init, 0) == decl)
    8948              :         {
    8949              :           /* Stick simple initializers in DECL_INITIAL so that
    8950              :              -Wno-init-self works (c++/34772).  */
    8951      7597348 :           DECL_INITIAL (decl) = rinit;
    8952              : 
    8953      7597348 :           if (warn_init_self && TYPE_REF_P (type))
    8954              :             {
    8955         2469 :               STRIP_NOPS (rinit);
    8956         2469 :               if (rinit == decl)
    8957            3 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    8958            3 :                             OPT_Winit_self,
    8959              :                             "reference %qD is initialized with itself", decl);
    8960              :             }
    8961              :         }
    8962              :       else
    8963              :         {
    8964      7473967 :           int saved_stmts_are_full_exprs_p;
    8965              : 
    8966              :           /* If we're only initializing a single object, guard the
    8967              :              destructors of any temporaries used in its initializer with
    8968              :              its destructor.  */
    8969      7473967 :           if (cleanup)
    8970       950629 :             wrap_temporary_cleanups (init, cleanup);
    8971              : 
    8972      7473967 :           gcc_assert (building_stmt_list_p ());
    8973      7473967 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    8974              :           /* Avoid CLEANUP_POINT_EXPR for the structured binding
    8975              :              bases, those will have CLEANUP_POINT_EXPR at the end of
    8976              :              code emitted by cp_finish_decomp.  */
    8977      7473967 :           if (decomp)
    8978        32265 :             current_stmt_tree ()->stmts_are_full_exprs_p = 0;
    8979              :           else
    8980      7441702 :             current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    8981      7473967 :           finish_expr_stmt (init);
    8982      7473967 :           current_stmt_tree ()->stmts_are_full_exprs_p
    8983      7473967 :             = saved_stmts_are_full_exprs_p;
    8984              :         }
    8985              :     }
    8986              : 
    8987              :   /* Set this to 0 so we can tell whether an aggregate which was
    8988              :      initialized was ever used.  Don't do this if it has a
    8989              :      destructor, so we don't complain about the 'resource
    8990              :      allocation is initialization' idiom.  Now set
    8991              :      attribute((unused)) on types so decls of that type will be
    8992              :      marked used. (see TREE_USED, above.)  */
    8993     23844430 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    8994      2050091 :       && ! already_used
    8995        23747 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    8996     23865858 :       && DECL_NAME (decl))
    8997        21380 :     TREE_USED (decl) = 0;
    8998     23823050 :   else if (already_used)
    8999     20896904 :     TREE_USED (decl) = 1;
    9000              : 
    9001     23844430 :   if (cleanup)
    9002       963752 :     finish_decl_cleanup (decl, cleanup);
    9003              : }
    9004              : 
    9005              : /* DECL is a VAR_DECL for a compiler-generated variable with static
    9006              :    storage duration (like a virtual table) whose initializer is a
    9007              :    compile-time constant.  Initialize the variable and provide it to the
    9008              :    back end.  */
    9009              : 
    9010              : void
    9011      2146718 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    9012              : {
    9013      2146718 :   tree init;
    9014      2146718 :   gcc_assert (DECL_ARTIFICIAL (decl));
    9015      2146718 :   init = build_constructor (TREE_TYPE (decl), v);
    9016      2146718 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    9017      2146718 :   DECL_INITIAL (decl) = init;
    9018      2146718 :   DECL_INITIALIZED_P (decl) = 1;
    9019              :   /* Mark the decl as constexpr so that we can access its content
    9020              :      at compile time.  */
    9021      2146718 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    9022      2146718 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    9023      2146718 :   determine_visibility (decl);
    9024      2146718 :   layout_var_decl (decl);
    9025      2146718 :   maybe_commonize_var (decl);
    9026      2146718 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    9027      2146718 : }
    9028              : 
    9029              : /* INIT is the initializer for a variable, as represented by the
    9030              :    parser.  Returns true iff INIT is value-dependent.  */
    9031              : 
    9032              : static bool
    9033      9562701 : value_dependent_init_p (tree init)
    9034              : {
    9035      9562701 :   if (TREE_CODE (init) == TREE_LIST)
    9036              :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    9037        20123 :     return any_value_dependent_elements_p (init);
    9038      9542578 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    9039              :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    9040              :     {
    9041        70743 :       if (dependent_type_p (TREE_TYPE (init)))
    9042              :         return true;
    9043              : 
    9044        70737 :       vec<constructor_elt, va_gc> *elts;
    9045        70737 :       size_t nelts;
    9046        70737 :       size_t i;
    9047              : 
    9048        70737 :       elts = CONSTRUCTOR_ELTS (init);
    9049        70737 :       nelts = vec_safe_length (elts);
    9050       625147 :       for (i = 0; i < nelts; ++i)
    9051       582623 :         if (value_dependent_init_p ((*elts)[i].value))
    9052              :           return true;
    9053              :     }
    9054              :   else
    9055              :     /* It must be a simple expression, e.g., int i = 3;  */
    9056      9471835 :     return value_dependent_expression_p (init);
    9057              : 
    9058              :   return false;
    9059              : }
    9060              : 
    9061              : /* A helper function to be called via walk_tree.  If any label exists
    9062              :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    9063              : 
    9064              : static tree
    9065          337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    9066              : {
    9067          337 :   if (TYPE_P (*tp))
    9068            0 :     *walk_subtrees = 0;
    9069          337 :   if (TREE_CODE (*tp) == LABEL_DECL)
    9070            6 :     cfun->has_forced_label_in_static = 1;
    9071          337 :   return NULL_TREE;
    9072              : }
    9073              : 
    9074              : /* Return true if DECL has either a trivial destructor, or for C++20
    9075              :    is constexpr and has a constexpr destructor.  */
    9076              : 
    9077              : static bool
    9078     60212122 : decl_maybe_constant_destruction (tree decl, tree type)
    9079              : {
    9080     60212122 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    9081     60212122 :           || (cxx_dialect >= cxx20
    9082      4000750 :               && VAR_P (decl)
    9083      4000413 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    9084          482 :               && type_has_constexpr_destructor (strip_array_types (type))));
    9085              : }
    9086              : 
    9087              : static tree declare_simd_adjust_this (tree *, int *, void *);
    9088              : 
    9089              : /* Helper function of omp_declare_variant_finalize.  Finalize one
    9090              :    "omp declare variant base" attribute.  Return true if it should be
    9091              :    removed.  */
    9092              : 
    9093              : static bool
    9094         1755 : omp_declare_variant_finalize_one (tree decl, tree attr)
    9095              : {
    9096         1755 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9097              :     {
    9098          164 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9099              :                  DECL_ARGUMENTS (decl), NULL);
    9100          164 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    9101              :                  DECL_ARGUMENTS (decl), NULL);
    9102              :     }
    9103              : 
    9104         1755 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    9105         1755 :   tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
    9106              :                                         OMP_TRAIT_CONSTRUCT_SIMD);
    9107         1755 :   if (simd)
    9108              :     {
    9109           51 :       TREE_VALUE (simd)
    9110           51 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    9111           51 :                                                  OMP_TS_PROPERTIES (simd));
    9112              :       /* FIXME, adjusting simd args unimplemented.  */
    9113           51 :       return true;
    9114              :     }
    9115              : 
    9116         1704 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    9117         1704 :   location_t varid_loc
    9118         1704 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    9119         1704 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    9120         1704 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    9121         1704 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    9122              : 
    9123         1704 :   location_t save_loc = input_location;
    9124         1704 :   input_location = varid_loc;
    9125              : 
    9126         1704 :   releasing_vec args;
    9127         1704 :   tree parm = DECL_ARGUMENTS (decl);
    9128         1704 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    9129          164 :     parm = DECL_CHAIN (parm);
    9130         3026 :   for (; parm; parm = DECL_CHAIN (parm))
    9131         1322 :     vec_safe_push (args, forward_parm (parm));
    9132              : 
    9133         1704 :   unsigned nappend_args = 0;
    9134         1704 :   tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9135         1704 :   if (append_args_list)
    9136              :     {
    9137          354 :       append_args_list = TREE_VALUE (append_args_list);
    9138          354 :       append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
    9139          591 :                           ? TREE_VALUE (TREE_CHAIN (append_args_list))
    9140              :                           : NULL_TREE);
    9141          741 :       for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9142          387 :         nappend_args++;
    9143          354 :       if (nappend_args)
    9144              :         {
    9145          237 :           tree type;
    9146          237 :           if ((type = lookup_qualified_name (global_namespace,
    9147              :                                              "omp_interop_t",
    9148              :                                              LOOK_want::NORMAL,
    9149              :                                              /*complain*/false)) == NULL_TREE
    9150          237 :               || !c_omp_interop_t_p (TREE_TYPE (type)))
    9151              :             {
    9152           24 :               location_t loc = input_location;
    9153           24 :               variant = tree_strip_any_location_wrapper (variant);
    9154           24 :               if (!identifier_p (variant))
    9155              :                 {
    9156           21 :                   if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
    9157           21 :                     variant = OVL_FIRST (variant);
    9158           21 :                   loc = EXPR_LOC_OR_LOC (variant,
    9159              :                                          DECL_SOURCE_LOCATION (variant));
    9160              :                 }
    9161           24 :               auto_diagnostic_group d;
    9162           24 :               error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
    9163           24 :                         args->length () + 1, variant);
    9164           24 :               inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9165              :                       "%<append_args%> specified here");
    9166           24 :               return true;
    9167           24 :             }
    9168          564 :           for (unsigned i = 0; i < nappend_args; i++)
    9169          351 :             vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
    9170              :         }
    9171              :     }
    9172              : 
    9173         1680 :   bool koenig_p = false;
    9174         1680 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    9175              :     {
    9176         1610 :       if (identifier_p (variant)
    9177              :           /* In C++20, we may need to perform ADL for a template
    9178              :              name.  */
    9179         1586 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    9180           18 :               && identifier_p (TREE_OPERAND (variant, 0))))
    9181              :         {
    9182           24 :           if (!args->is_empty ())
    9183              :             {
    9184           24 :               koenig_p = true;
    9185           24 :               if (!any_type_dependent_arguments_p (args))
    9186           21 :                 variant = perform_koenig_lookup (variant, args,
    9187              :                                                  tf_warning_or_error);
    9188              :             }
    9189              :           else
    9190            0 :             variant = unqualified_fn_lookup_error (variant);
    9191              :         }
    9192         1586 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    9193              :         {
    9194          830 :           tree fn = get_first_fn (variant);
    9195          830 :           fn = STRIP_TEMPLATE (fn);
    9196          830 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    9197          830 :                  || DECL_FUNCTION_MEMBER_P (fn)
    9198          717 :                  || DECL_LOCAL_DECL_P (fn)))
    9199              :             {
    9200          717 :               koenig_p = true;
    9201          717 :               if (!any_type_dependent_arguments_p (args))
    9202          666 :                 variant = perform_koenig_lookup (variant, args,
    9203              :                                                  tf_warning_or_error);
    9204              :             }
    9205              :         }
    9206              :     }
    9207              : 
    9208         1680 :   if (idk == CP_ID_KIND_QUALIFIED)
    9209            6 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    9210              :                                 koenig_p, tf_warning_or_error);
    9211         1674 :   else if (idk == CP_ID_KIND_NONE
    9212           64 :            && TREE_CODE (variant) == FUNCTION_DECL
    9213           64 :            && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
    9214         1722 :            && CLASS_TYPE_P (DECL_CONTEXT (decl)))
    9215              :     {
    9216           48 :       tree saved_ccp = current_class_ptr;
    9217           48 :       tree saved_ccr = current_class_ref;
    9218           48 :       current_class_ptr = NULL_TREE;
    9219           48 :       current_class_ref = NULL_TREE;
    9220           48 :       inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
    9221           48 :       variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9222              :                                   koenig_p, tf_warning_or_error);
    9223           48 :       current_class_ptr = saved_ccp;
    9224           48 :       current_class_ref = saved_ccr;
    9225              :     }
    9226              :   else
    9227         1626 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    9228              :                                 koenig_p, tf_warning_or_error);
    9229         1680 :   if (variant == error_mark_node && !processing_template_decl)
    9230              :     return true;
    9231              : 
    9232         1614 :   if (TREE_CODE (variant) == TARGET_EXPR)
    9233            9 :     variant = TARGET_EXPR_INITIAL (variant);
    9234              : 
    9235         3219 :   variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
    9236         1614 :   input_location = save_loc;
    9237              : 
    9238         1614 :   if (variant == decl)
    9239              :     {
    9240            0 :       error_at (varid_loc, "variant %qD is the same as base function",
    9241              :                 variant);
    9242            0 :       return true;
    9243              :     }
    9244              : 
    9245         1614 :   if (variant)
    9246              :     {
    9247         1530 :       bool fail;
    9248         1530 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    9249         1530 :       if (!nappend_args)
    9250         1371 :         fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9251              :                            COMPARE_STRICT);
    9252              :       else
    9253              :         {
    9254          159 :           unsigned nbase_args = 0;
    9255          159 :           for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
    9256          756 :                t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
    9257          240 :             nbase_args++;
    9258          159 :           tree vargs, varg;
    9259          159 :           vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
    9260          399 :           for (unsigned i = 0; i < nbase_args && varg;
    9261          240 :                i++, varg = TREE_CHAIN (varg))
    9262          240 :             vargs = varg;
    9263          417 :           for (unsigned i = 0; i < nappend_args && varg; i++)
    9264          258 :             varg = TREE_CHAIN (varg);
    9265          159 :           tree saved_vargs;
    9266          159 :           int saved_no_named_args_stdarg = 0;
    9267          159 :           if (nbase_args)
    9268              :             {
    9269          111 :               saved_vargs = TREE_CHAIN (vargs);
    9270          111 :               TREE_CHAIN (vargs) = varg;
    9271              :             }
    9272              :           else
    9273              :             {
    9274           48 :               saved_vargs = vargs;
    9275           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
    9276           48 :               saved_no_named_args_stdarg
    9277           48 :                 = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
    9278           48 :               if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
    9279           48 :                   && varg == NULL_TREE)
    9280            2 :                 TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
    9281              :             }
    9282              :           /* Skip assert check that TYPE_CANONICAL is the same.  */
    9283          159 :           fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
    9284              :                              COMPARE_STRUCTURAL);
    9285          159 :           if (nbase_args)
    9286          111 :             TREE_CHAIN (vargs) = saved_vargs;
    9287              :           else
    9288              :             {
    9289           48 :               TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
    9290           48 :               TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
    9291           96 :                 = saved_no_named_args_stdarg;
    9292              :             }
    9293          159 :           varg = saved_vargs;
    9294          159 :           if (!fail && !processing_template_decl)
    9295          402 :             for (unsigned i = 0; i < nappend_args;
    9296          246 :                  i++, varg = TREE_CHAIN (varg))
    9297          507 :               if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
    9298              :                 {
    9299            9 :                   auto_diagnostic_group d;
    9300            9 :                   error_at (DECL_SOURCE_LOCATION (variant),
    9301              :                             "argument %d of %qD must be of %<omp_interop_t%>",
    9302            9 :                             nbase_args + i + 1, variant);
    9303            9 :                   inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
    9304              :                           "%<append_args%> specified here");
    9305            9 :                   break;
    9306            9 :                 }
    9307              :         }
    9308         1530 :       if (fail)
    9309              :         {
    9310           69 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    9311              :                                "types", variant, decl);
    9312           69 :           return true;
    9313              :         }
    9314         1461 :       if (fndecl_built_in_p (variant)
    9315         1461 :           && (startswith (varname, "__builtin_")
    9316            0 :               || startswith (varname, "__sync_")
    9317            0 :               || startswith (varname, "__atomic_")))
    9318              :         {
    9319            6 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    9320            6 :           return true;
    9321              :         }
    9322              :       else
    9323              :         {
    9324         1455 :           tree construct
    9325         1455 :             = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
    9326         1455 :           omp_mark_declare_variant (match_loc, variant, construct);
    9327         1455 :           if (!omp_context_selector_matches (ctx, NULL_TREE, false))
    9328              :             return true;
    9329         1039 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    9330              : 
    9331              :           // Prepend adjust_args list to variant attributes
    9332         1039 :           tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
    9333         1039 :           if (adjust_args_list != NULL_TREE)
    9334              :             {
    9335          507 :               if (DECL_NONSTATIC_MEMBER_P (variant)
    9336          285 :                   && TREE_VALUE (adjust_args_list))
    9337              :                 {
    9338              :                   /* Shift arg position for the added 'this' pointer.  */
    9339              :                   /* Handle need_device_ptr  */
    9340           21 :                   for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
    9341           51 :                        t; t = TREE_CHAIN (t))
    9342           30 :                     TREE_VALUE (t)
    9343           30 :                       = build_int_cst (TREE_TYPE (t),
    9344           30 :                                        tree_to_uhwi (TREE_VALUE (t)) + 1);
    9345              :                 }
    9346          264 :               if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
    9347              :                 {
    9348              :                   /* Shift likewise the number of args after which the
    9349              :                      interop object should be added.  */
    9350            6 :                   tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
    9351            6 :                   TREE_PURPOSE (nargs)
    9352            6 :                     = build_int_cst (TREE_TYPE (nargs),
    9353            6 :                                      tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
    9354              :                 }
    9355          528 :               for (tree t = append_args_list; t; t = TREE_CHAIN (t))
    9356          264 :                 TREE_VALUE (t)
    9357          264 :                   = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
    9358          528 :               DECL_ATTRIBUTES (variant) = tree_cons (
    9359              :                 get_identifier ("omp declare variant variant args"),
    9360          528 :                 TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
    9361              :             }
    9362              :         }
    9363              :     }
    9364           84 :   else if (!processing_template_decl)
    9365              :     {
    9366            0 :       error_at (varid_loc, "could not find variant declaration");
    9367            0 :       return true;
    9368              :     }
    9369              : 
    9370              :   return false;
    9371         1704 : }
    9372              : 
    9373              : /* Helper function, finish up "omp declare variant base" attribute
    9374              :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    9375              :    attribute.  */
    9376              : 
    9377              : void
    9378         1548 : omp_declare_variant_finalize (tree decl, tree attr)
    9379              : {
    9380         1548 :   size_t attr_len = strlen ("omp declare variant base");
    9381         1548 :   tree *list = &DECL_ATTRIBUTES (decl);
    9382         1548 :   bool remove_all = false;
    9383         1548 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    9384         1548 :   if (TREE_CHAIN (TREE_VALUE (attr))
    9385         1548 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    9386         3096 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    9387         1548 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    9388         3096 :   if (DECL_CONSTRUCTOR_P (decl))
    9389              :     {
    9390           27 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    9391           27 :       remove_all = true;
    9392              :     }
    9393         1521 :   else if (DECL_DESTRUCTOR_P (decl))
    9394              :     {
    9395            9 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    9396            9 :       remove_all = true;
    9397              :     }
    9398         1512 :   else if (DECL_DEFAULTED_FN (decl))
    9399              :     {
    9400            2 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    9401            2 :       remove_all = true;
    9402              :     }
    9403         1510 :   else if (DECL_DELETED_FN (decl))
    9404              :     {
    9405            2 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    9406            2 :       remove_all = true;
    9407              :     }
    9408         1508 :   else if (DECL_VIRTUAL_P (decl))
    9409              :     {
    9410            0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    9411            0 :       remove_all = true;
    9412              :     }
    9413              :   /* This loop is like private_lookup_attribute, except that it works
    9414              :      with tree * rather than tree, as we might want to remove the
    9415              :      attributes that are diagnosed as erroneous.  */
    9416         3355 :   while (*list)
    9417              :     {
    9418         1807 :       tree attr = get_attribute_name (*list);
    9419         1807 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    9420         4737 :       if (cmp_attribs ("omp declare variant base", attr_len,
    9421         1807 :                        IDENTIFIER_POINTER (attr), ident_len))
    9422              :         {
    9423         1795 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    9424              :             {
    9425          672 :               *list = TREE_CHAIN (*list);
    9426          672 :               continue;
    9427              :             }
    9428              :         }
    9429         1135 :       list = &TREE_CHAIN (*list);
    9430              :     }
    9431         1548 : }
    9432              : 
    9433              : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
    9434              : 
    9435              : /* Finish processing of a declaration;
    9436              :    install its line number and initial value.
    9437              :    If the length of an array type is not known before,
    9438              :    it must be determined now, from the initial value, or it is an error.
    9439              : 
    9440              :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    9441              :    true, then INIT is an integral constant expression.
    9442              : 
    9443              :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    9444              :    if the (init) syntax was used.
    9445              : 
    9446              :    DECOMP is first identifier's DECL and identifier count in a structured
    9447              :    bindings, nullptr if not a structured binding.  */
    9448              : 
    9449              : void
    9450    320979280 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    9451              :                 tree asmspec_tree, int flags, cp_decomp *decomp)
    9452              : {
    9453    320979280 :   vec<tree, va_gc> *cleanups = NULL;
    9454    320979280 :   const char *asmspec = NULL;
    9455    320979280 :   int was_readonly = 0;
    9456    320979280 :   bool var_definition_p = false;
    9457    320979280 :   tree auto_node;
    9458    320979280 :   auto_vec<tree> extra_cleanups;
    9459    320979280 :   tree aggregates1 = NULL_TREE;
    9460    320979280 :   struct decomp_cleanup {
    9461              :     tree decl;
    9462              :     cp_decomp *&decomp;
    9463    320976583 :     ~decomp_cleanup ()
    9464              :     {
    9465    320976583 :       if (decomp && DECL_DECOMPOSITION_P (decl))
    9466       222690 :         cp_finish_decomp (decl, decomp);
    9467    320976583 :     }
    9468    320979280 :   } decomp_cl = { decl, decomp };
    9469              : 
    9470    320979280 :   if (decl == error_mark_node)
    9471              :     return;
    9472    320979240 :   else if (! decl)
    9473              :     {
    9474            0 :       if (init)
    9475            0 :         error ("assignment (not initialization) in declaration");
    9476            0 :       return;
    9477              :     }
    9478              : 
    9479    320979240 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    9480              :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    9481    320979240 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    9482              : 
    9483    320979240 :   tree type = TREE_TYPE (decl);
    9484    320979240 :   if (type == error_mark_node)
    9485              :     return;
    9486              : 
    9487    320978549 :   if (VAR_P (decl) && is_copy_initialization (init))
    9488     95226826 :     flags |= LOOKUP_ONLYCONVERTING;
    9489              : 
    9490              :   /* Warn about register storage specifiers except when in GNU global
    9491              :      or local register variable extension.  */
    9492    320978549 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    9493              :     {
    9494         1931 :       if (cxx_dialect >= cxx17)
    9495         1282 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9496              :                  "ISO C++17 does not allow %<register%> storage "
    9497              :                  "class specifier");
    9498              :       else
    9499          649 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    9500              :                     "%<register%> storage class specifier used");
    9501              :     }
    9502              : 
    9503              :   /* If a name was specified, get the string.  */
    9504    320978549 :   if (at_namespace_scope_p ())
    9505     69235436 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    9506    320978549 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    9507       988646 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    9508              : 
    9509    320978549 :   bool in_class_decl
    9510    320978549 :     = (current_class_type
    9511    202160422 :        && CP_DECL_CONTEXT (decl) == current_class_type
    9512    134348897 :        && TYPE_BEING_DEFINED (current_class_type)
    9513    453295548 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    9514              : 
    9515    127321282 :   if (in_class_decl
    9516    127321282 :       && (DECL_INITIAL (decl) || init))
    9517     93422515 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    9518              : 
    9519    320978549 :   if (VAR_P (decl)
    9520    320978549 :       && (auto_node = type_uses_auto (type)))
    9521              :     {
    9522     13258210 :       tree d_init;
    9523     13258210 :       if (init == NULL_TREE)
    9524              :         {
    9525         2347 :           if (DECL_LANG_SPECIFIC (decl)
    9526         2262 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    9527         4606 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    9528              :             {
    9529              :               /* init is null because we're deferring instantiating the
    9530              :                  initializer until we need it.  Well, we need it now.  */
    9531         2253 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    9532         2253 :               return;
    9533              :             }
    9534              : 
    9535           94 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9536              :             /* Class deduction with no initializer is OK.  */;
    9537              :           else
    9538              :             {
    9539              :               /* Ordinary auto deduction without an initializer, a situation
    9540              :                  which grokdeclarator already detects and rejects for the most
    9541              :                  part.  But we can still get here if we're instantiating a
    9542              :                  variable template before we've fully parsed (and attached) its
    9543              :                  initializer, e.g. template<class> auto x = x<int>;  */
    9544            3 :               error_at (DECL_SOURCE_LOCATION (decl),
    9545              :                         "declaration of %q#D has no initializer", decl);
    9546            3 :               TREE_TYPE (decl) = error_mark_node;
    9547            3 :               return;
    9548              :             }
    9549              :         }
    9550     13255954 :       d_init = init;
    9551     13255954 :       if (d_init)
    9552              :         {
    9553     13255863 :           if (TREE_CODE (d_init) == TREE_LIST
    9554     13307990 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    9555        27814 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    9556              :                                                       tf_warning_or_error);
    9557     13255863 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    9558              :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    9559              :              on deprecated-14.C.  */
    9560     13255863 :           mark_single_function (d_init, tf_none);
    9561              :         }
    9562     13255954 :       enum auto_deduction_context adc = adc_variable_type;
    9563     13255954 :       if (DECL_DECOMPOSITION_P (decl))
    9564              :         adc = adc_decomp_type;
    9565     13255954 :       tree outer_targs = NULL_TREE;
    9566     13255954 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    9567          305 :           && DECL_LANG_SPECIFIC (decl)
    9568          126 :           && DECL_TEMPLATE_INFO (decl)
    9569     13256011 :           && !DECL_FUNCTION_SCOPE_P (decl))
    9570              :         /* The outer template arguments might be needed for satisfaction.
    9571              :            (For function scope variables, do_auto_deduction will obtain the
    9572              :            outer template arguments from current_function_decl.)  */
    9573           57 :         outer_targs = DECL_TI_ARGS (decl);
    9574     13255954 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    9575              :                                                    tf_warning_or_error, adc,
    9576              :                                                    outer_targs, flags);
    9577     13255954 :       if (type == error_mark_node)
    9578              :         return;
    9579     13254828 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    9580              :         {
    9581            3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    9582              :                  "did you forget the %<()%>?", decl);
    9583            3 :           TREE_TYPE (decl) = error_mark_node;
    9584            3 :           return;
    9585              :         }
    9586              :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    9587     13254825 :       if (!processing_template_decl
    9588      3012641 :           && !type_uses_auto (type)
    9589     16267459 :           && !COMPLETE_TYPE_P (complete_type (type)))
    9590              :         {
    9591           18 :           auto_diagnostic_group d;
    9592           18 :           error_at (location_of (decl),
    9593              :                     "deduced type %qT for %qD is incomplete", type, decl);
    9594           18 :           cxx_incomplete_type_inform (type);
    9595           18 :           TREE_TYPE (decl) = error_mark_node;
    9596           18 :           return;
    9597           18 :         }
    9598              : 
    9599              :       /* Now that we have a type, try these again.  */
    9600     13254807 :       layout_decl (decl, 0);
    9601     13254807 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    9602              : 
    9603              :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    9604     13254807 :       if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    9605              :         {
    9606        34440 :           tree tmpl = template_for_substitution (decl);
    9607        34440 :           if (DECL_TEMPLATE_RESULT (tmpl) == decl)
    9608        31125 :             TREE_TYPE (tmpl) = type;
    9609              :         }
    9610              :     }
    9611              : 
    9612    320975146 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    9613              :     {
    9614           65 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    9615           65 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    9616              :         {
    9617            6 :           init = NULL_TREE;
    9618            6 :           DECL_EXTERNAL (decl) = 1;
    9619              :         }
    9620              :     }
    9621              : 
    9622    320975146 :   if (VAR_P (decl)
    9623    120696886 :       && DECL_CLASS_SCOPE_P (decl)
    9624     19676317 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    9625              :                               TCTX_STATIC_STORAGE, type)
    9626    340651463 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    9627     18355989 :     check_static_variable_definition (decl, type);
    9628              : 
    9629    320975146 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    9630              :     {
    9631     35912045 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    9632     35912045 :                                    ? TCTX_THREAD_STORAGE
    9633              :                                    : TCTX_STATIC_STORAGE);
    9634     35912045 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    9635              :     }
    9636              : 
    9637    320975146 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    9638              :     {
    9639       565532 :       tree clone;
    9640       565532 :       if (init == ridpointers[(int)RID_DELETE]
    9641       565532 :           || (TREE_CODE (init) == STRING_CST
    9642           36 :               && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
    9643              :         {
    9644              :           /* FIXME check this is 1st decl.  */
    9645       543582 :           if (UNLIKELY (DECL_MAIN_P (decl)))
    9646              :             {
    9647              :               /* [basic.start.main]/3: A program that defines main as deleted
    9648              :                  is ill-formed.  */
    9649            6 :               error ("%<::main%> cannot be deleted");
    9650            6 :               DECL_INITIAL (decl) = error_mark_node;
    9651              :             }
    9652              :           else
    9653              :             {
    9654       543576 :               DECL_DELETED_FN (decl) = 1;
    9655       543576 :               DECL_DECLARED_INLINE_P (decl) = 1;
    9656       543576 :               DECL_INITIAL (decl)
    9657       543576 :                 = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
    9658       543594 :               FOR_EACH_CLONE (clone, decl)
    9659              :                 {
    9660           18 :                   DECL_DELETED_FN (clone) = 1;
    9661           18 :                   DECL_DECLARED_INLINE_P (clone) = 1;
    9662           18 :                   DECL_INITIAL (clone) = DECL_INITIAL (decl);
    9663              :                 }
    9664              :             }
    9665       543582 :           init = NULL_TREE;
    9666              :         }
    9667        21950 :       else if (init == ridpointers[(int)RID_DEFAULT])
    9668              :         {
    9669        21938 :           if (defaultable_fn_check (decl))
    9670        21914 :             DECL_DEFAULTED_FN (decl) = 1;
    9671              :           else
    9672           24 :             DECL_INITIAL (decl) = NULL_TREE;
    9673              :         }
    9674              :     }
    9675              : 
    9676    320975146 :   if (init && VAR_P (decl))
    9677              :     {
    9678    104743047 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    9679              :       /* If DECL is a reference, then we want to know whether init is a
    9680              :          reference constant; init_const_expr_p as passed tells us whether
    9681              :          it's an rvalue constant.  */
    9682    104743047 :       if (TYPE_REF_P (type))
    9683      2266702 :         init_const_expr_p = potential_constant_expression (init);
    9684    104743047 :       if (init_const_expr_p)
    9685              :         {
    9686              :           /* Set these flags now for templates.  We'll update the flags in
    9687              :              store_init_value for instantiations.  */
    9688     92222861 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    9689     92222861 :           if (decl_maybe_constant_var_p (decl)
    9690              :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    9691     92222861 :               && !TYPE_REF_P (type))
    9692     40428473 :             TREE_CONSTANT (decl) = true;
    9693              :         }
    9694              :       /* This is handled mostly by gimplify.cc, but we have to deal with
    9695              :          not warning about int x = x; as it is a GCC extension to turn off
    9696              :          this warning but only if warn_init_self is zero.  */
    9697    104743047 :       if (!DECL_EXTERNAL (decl)
    9698    103154685 :           && !TREE_STATIC (decl)
    9699     69957309 :           && decl == tree_strip_any_location_wrapper (init)
    9700    104746867 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    9701         3796 :         suppress_warning (decl, OPT_Winit_self);
    9702              :     }
    9703    216232099 :   else if (VAR_P (decl)
    9704     15953839 :            && COMPLETE_TYPE_P (type)
    9705     12464228 :            && !TYPE_REF_P (type)
    9706     12463688 :            && !dependent_type_p (type)
    9707    228378200 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    9708              :     /* We have no initializer but there's nothing to initialize anyway.
    9709              :        Treat DECL as constant due to c++/109876.  */
    9710       573663 :     TREE_CONSTANT (decl) = true;
    9711              : 
    9712    320975146 :   if (flag_openmp
    9713       846550 :       && TREE_CODE (decl) == FUNCTION_DECL
    9714              :       /* #pragma omp declare variant on methods handled in finish_struct
    9715              :          instead.  */
    9716    321339958 :       && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
    9717       139543 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    9718       225732 :     if (tree attr = lookup_attribute ("omp declare variant base",
    9719       225732 :                                       DECL_ATTRIBUTES (decl)))
    9720          970 :       omp_declare_variant_finalize (decl, attr);
    9721              : 
    9722    320975146 :   if (processing_template_decl)
    9723              :     {
    9724    184523145 :       bool type_dependent_p;
    9725              : 
    9726              :       /* Add this declaration to the statement-tree.  */
    9727    184523145 :       if (at_function_scope_p ())
    9728     66593405 :         add_decl_expr (decl);
    9729              : 
    9730    184523145 :       type_dependent_p = dependent_type_p (type);
    9731              : 
    9732    184523145 :       if (check_for_bare_parameter_packs (init))
    9733              :         {
    9734            3 :           init = NULL_TREE;
    9735            3 :           DECL_INITIAL (decl) = NULL_TREE;
    9736              :         }
    9737              : 
    9738              :       /* Generally, initializers in templates are expanded when the
    9739              :          template is instantiated.  But, if DECL is a variable constant
    9740              :          then it can be used in future constant expressions, so its value
    9741              :          must be available. */
    9742              : 
    9743    184523145 :       bool dep_init = false;
    9744              : 
    9745    184523145 :       if (!VAR_P (decl) || type_dependent_p)
    9746              :         /* We can't do anything if the decl has dependent type.  */;
    9747     23058615 :       else if (init
    9748     21398374 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    9749     17444246 :                && !TYPE_REF_P (type)
    9750     17412225 :                && decl_maybe_constant_var_p (decl)
    9751     32038693 :                && !(dep_init = value_dependent_init_p (init)))
    9752              :         {
    9753              :           /* This variable seems to be a non-dependent constant, so process
    9754              :              its initializer.  If check_initializer returns non-null the
    9755              :              initialization wasn't constant after all.  */
    9756      2311648 :           tree init_code;
    9757      2311648 :           cleanups = make_tree_vector ();
    9758      2311648 :           init_code = check_initializer (decl, init, flags, &cleanups);
    9759      2311648 :           if (init_code == NULL_TREE)
    9760      2311648 :             init = NULL_TREE;
    9761      2311648 :           release_tree_vector (cleanups);
    9762              :         }
    9763              :       else
    9764              :         {
    9765     20746967 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    9766              :           /* Try to deduce array size.  */
    9767     20746967 :           maybe_deduce_size_from_array_init (decl, init);
    9768              :           /* And complain about multiple initializers.  */
    9769     19086726 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    9770     20848720 :               && !MAYBE_CLASS_TYPE_P (type))
    9771            7 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    9772              :                                                     tf_warning_or_error);
    9773              :         }
    9774              : 
    9775    184523145 :       if (init)
    9776     55149220 :         DECL_INITIAL (decl) = init;
    9777              : 
    9778    184523145 :       if (dep_init)
    9779              :         {
    9780      6668430 :           retrofit_lang_decl (decl);
    9781      6668430 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    9782              :         }
    9783              : 
    9784    184523145 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    9785              :         {
    9786            9 :           if (TREE_ADDRESSABLE (decl))
    9787            3 :             error_at (DECL_SOURCE_LOCATION (decl),
    9788              :                       "address of explicit register variable %qD requested",
    9789              :                       decl);
    9790              :           else
    9791              :             {
    9792            6 :               set_user_assembler_name (decl, asmspec);
    9793            6 :               DECL_HARD_REGISTER (decl) = 1;
    9794              :             }
    9795              :         }
    9796    184523145 :       return;
    9797              :     }
    9798              : 
    9799              :   /* Just store non-static data member initializers for later.  */
    9800    136452001 :   if (init && TREE_CODE (decl) == FIELD_DECL)
    9801       587917 :     DECL_INITIAL (decl) = init;
    9802              : 
    9803              :   /* Take care of TYPE_DECLs up front.  */
    9804    136452001 :   if (TREE_CODE (decl) == TYPE_DECL)
    9805              :     {
    9806     10640965 :       if (type != error_mark_node
    9807     10640965 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
    9808              :         {
    9809      5079945 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
    9810            0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
    9811      5079945 :           set_identifier_type_value (DECL_NAME (decl), decl);
    9812              :         }
    9813              : 
    9814              :       /* If we have installed this as the canonical typedef for this
    9815              :          type, and that type has not been defined yet, delay emitting
    9816              :          the debug information for it, as we will emit it later.  */
    9817     10640965 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
    9818     10640965 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    9819       582503 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    9820              : 
    9821     10640965 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
    9822              :                                 at_eof);
    9823     10640965 :       return;
    9824              :     }
    9825              : 
    9826              :   /* A reference will be modified here, as it is initialized.  */
    9827    125811036 :   if (! DECL_EXTERNAL (decl)
    9828     61273099 :       && TREE_READONLY (decl)
    9829    162362154 :       && TYPE_REF_P (type))
    9830              :     {
    9831       236593 :       was_readonly = 1;
    9832       236593 :       TREE_READONLY (decl) = 0;
    9833              :     }
    9834              : 
    9835              :   /* This needs to happen before extend_ref_init_temps.  */
    9836    125811036 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9837              :     {
    9838    116621141 :       if (VAR_P (decl))
    9839     59756642 :         maybe_commonize_var (decl);
    9840    116621141 :       determine_visibility (decl);
    9841              :     }
    9842              : 
    9843    125811036 :   if (VAR_P (decl))
    9844              :     {
    9845     59756642 :       duration_kind dk = decl_storage_duration (decl);
    9846              :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
    9847              :          only to a declaration of a variable with static or thread storage
    9848              :          duration."  */
    9849     59756642 :       if (DECL_DECLARED_CONSTINIT_P (decl)
    9850     59756642 :           && !(dk == dk_thread || dk == dk_static))
    9851              :         {
    9852           24 :           error_at (DECL_SOURCE_LOCATION (decl),
    9853              :                     "%<constinit%> can only be applied to a variable with "
    9854              :                     "static or thread storage duration");
    9855           24 :           return;
    9856              :         }
    9857              : 
    9858     59756618 :       if (decomp)
    9859              :         {
    9860        55340 :           if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
    9861           40 :             pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
    9862              :                      "%<constinit%> can be applied to structured binding "
    9863              :                      "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
    9864        55340 :           cp_maybe_mangle_decomp (decl, decomp);
    9865        55340 :           if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
    9866              :             {
    9867          619 :               if (CP_DECL_THREAD_LOCAL_P (decl))
    9868           37 :                 aggregates1 = tls_aggregates;
    9869              :               else
    9870          582 :                 aggregates1 = static_aggregates;
    9871              :             }
    9872              :         }
    9873              : 
    9874              :       /* Detect stuff like 'info r = ^^int;' outside a manifestly
    9875              :          constant-evaluated context.  */
    9876     59756618 :       check_out_of_consteval_use (decl);
    9877              : 
    9878              :       /* If this is a local variable that will need a mangled name,
    9879              :          register it now.  We must do this before processing the
    9880              :          initializer for the variable, since the initialization might
    9881              :          require a guard variable, and since the mangled name of the
    9882              :          guard variable will depend on the mangled name of this
    9883              :          variable.  */
    9884     59756618 :       if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl))
    9885              :         {
    9886              :           /* The variable holding an anonymous union will have had its
    9887              :              discriminator set in finish_anon_union, after which it's
    9888              :              NAME will have been cleared.  */
    9889       135914 :           if (DECL_NAME (decl))
    9890       135602 :             determine_local_discriminator (decl);
    9891              :           /* Normally has_forced_label_in_static is set during GIMPLE
    9892              :              lowering, but [cd]tors are never actually compiled directly.
    9893              :              We need to set this early so we can deal with the label
    9894              :              address extension.  */
    9895       135914 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
    9896       135873 :                || DECL_DESTRUCTOR_P (current_function_decl))
    9897       135930 :               && init)
    9898              :             {
    9899           29 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
    9900           29 :               add_local_decl (cfun, decl);
    9901              :             }
    9902       135914 :           if (!consteval_only_p (decl))
    9903              :             /* And make sure it's in the symbol table for
    9904              :                c_parse_final_cleanups to find.  */
    9905       135688 :             varpool_node::get_create (decl);
    9906              :         }
    9907              : 
    9908     59756618 :       if (flag_openmp
    9909       194082 :           && VAR_P (decl)
    9910       194082 :           && DECL_LANG_SPECIFIC (decl)
    9911       115595 :           && DECL_OMP_DECLARE_MAPPER_P (decl)
    9912     59756631 :           && init)
    9913              :         {
    9914           12 :           gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
    9915           12 :           DECL_INITIAL (decl) = init;
    9916              :         }
    9917              :       /* Convert the initializer to the type of DECL, if we have not
    9918              :          already initialized DECL.  */
    9919     59756606 :       else if (!DECL_INITIALIZED_P (decl)
    9920              :                /* If !DECL_EXTERNAL then DECL is being defined.  In the
    9921              :                   case of a static data member initialized inside the
    9922              :                   class-specifier, there can be an initializer even if DECL
    9923              :                   is *not* defined.  */
    9924     59756606 :                && (!DECL_EXTERNAL (decl) || init))
    9925              :         {
    9926     53077792 :           cleanups = make_tree_vector ();
    9927     53077792 :           init = check_initializer (decl, init, flags, &cleanups);
    9928              : 
    9929              :           /* Handle:
    9930              : 
    9931              :              [dcl.init]
    9932              : 
    9933              :              The memory occupied by any object of static storage
    9934              :              duration is zero-initialized at program startup before
    9935              :              any other initialization takes place.
    9936              : 
    9937              :              We cannot create an appropriate initializer until after
    9938              :              the type of DECL is finalized.  If DECL_INITIAL is set,
    9939              :              then the DECL is statically initialized, and any
    9940              :              necessary zero-initialization has already been performed.  */
    9941     53075095 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
    9942       502282 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
    9943              :                                                    /*nelts=*/NULL_TREE,
    9944              :                                                    /*static_storage_p=*/true);
    9945              :           /* Remember that the initialization for this variable has
    9946              :              taken place.  */
    9947     53075095 :           DECL_INITIALIZED_P (decl) = 1;
    9948              :           /* This declaration is the definition of this variable,
    9949              :              unless we are initializing a static data member within
    9950              :              the class specifier.  */
    9951     53075095 :           if (!DECL_EXTERNAL (decl))
    9952     59753921 :             var_definition_p = true;
    9953              :         }
    9954              :       /* If the variable has an array type, lay out the type, even if
    9955              :          there is no initializer.  It is valid to index through the
    9956              :          array, and we must get TYPE_ALIGN set correctly on the array
    9957              :          type.  */
    9958      6678814 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    9959       210013 :         layout_type (type);
    9960              : 
    9961     59753921 :       if (TREE_STATIC (decl)
    9962     35361815 :           && !at_function_scope_p ()
    9963     94979822 :           && current_function_decl == NULL)
    9964              :         /* So decl is a global variable or a static member of a
    9965              :            non local class. Record the types it uses
    9966              :            so that we can decide later to emit debug info for them.  */
    9967     35225889 :         record_types_used_by_current_var_decl (decl);
    9968              :     }
    9969              : 
    9970              :   /* Add this declaration to the statement-tree.  This needs to happen
    9971              :      after the call to check_initializer so that the DECL_EXPR for a
    9972              :      reference temp is added before the DECL_EXPR for the reference itself.  */
    9973    125808315 :   if (DECL_FUNCTION_SCOPE_P (decl))
    9974              :     {
    9975              :       /* If we're building a variable sized type, and we might be
    9976              :          reachable other than via the top of the current binding
    9977              :          level, then create a new BIND_EXPR so that we deallocate
    9978              :          the object at the right time.  */
    9979     23980362 :       if (VAR_P (decl)
    9980     23980362 :           && DECL_SIZE (decl)
    9981     23920792 :           && !TREE_CONSTANT (DECL_SIZE (decl))
    9982     23981392 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    9983              :         {
    9984            3 :           tree bind;
    9985            3 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    9986            3 :           TREE_SIDE_EFFECTS (bind) = 1;
    9987            3 :           add_stmt (bind);
    9988            3 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
    9989              :         }
    9990     23980362 :       add_decl_expr (decl);
    9991              :     }
    9992              : 
    9993    125808315 :   tree decomp_init = NULL_TREE;
    9994              :   /* Let the middle end know about variables and functions -- but not
    9995              :      static data members in uninstantiated class templates.  */
    9996    125808315 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    9997              :     {
    9998    116618420 :       if (VAR_P (decl))
    9999              :         {
   10000     59753921 :           layout_var_decl (decl);
   10001     59753921 :           if (!flag_weak)
   10002              :             /* Check again now that we have an initializer.  */
   10003           57 :             maybe_commonize_var (decl);
   10004              :           /* A class-scope constexpr variable with an out-of-class declaration.
   10005              :              C++17 makes them implicitly inline, but still force it out.  */
   10006     80793279 :           if (DECL_INLINE_VAR_P (decl)
   10007     27945506 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
   10008     12791229 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
   10009     45079200 :               && !in_class_decl)
   10010          108 :             mark_needed (decl);
   10011              :         }
   10012              : 
   10013    116618420 :       if (var_definition_p
   10014              :           /* With -fmerge-all-constants, gimplify_init_constructor
   10015              :              might add TREE_STATIC to aggregate variables.  */
   10016     51923990 :           && (TREE_STATIC (decl)
   10017     23844573 :               || (flag_merge_constants >= 2
   10018           38 :                   && AGGREGATE_TYPE_P (type))))
   10019              :         {
   10020              :           /* If a TREE_READONLY variable needs initialization
   10021              :              at runtime, it is no longer readonly and we need to
   10022              :              avoid MEM_READONLY_P being set on RTL created for it.  */
   10023     28079420 :           if (init)
   10024              :             {
   10025        14019 :               if (TREE_READONLY (decl))
   10026          336 :                 TREE_READONLY (decl) = 0;
   10027              :               was_readonly = 0;
   10028              :             }
   10029     28065401 :           else if (was_readonly)
   10030         2299 :             TREE_READONLY (decl) = 1;
   10031              : 
   10032              :           /* Likewise if it needs destruction.  */
   10033     28079420 :           if (!decl_maybe_constant_destruction (decl, type))
   10034         3386 :             TREE_READONLY (decl) = 0;
   10035              :         }
   10036     88539000 :       else if (VAR_P (decl)
   10037     31674501 :                && CP_DECL_THREAD_LOCAL_P (decl)
   10038        18603 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
   10039        18603 :                && (was_readonly || TREE_READONLY (decl))
   10040     88539015 :                && var_needs_tls_wrapper (decl))
   10041              :         {
   10042              :           /* TLS variables need dynamic initialization by the TLS wrapper
   10043              :              function, we don't want to hoist accesses to it before the
   10044              :              wrapper.  */
   10045            6 :           was_readonly = 0;
   10046            6 :           TREE_READONLY (decl) = 0;
   10047              :         }
   10048              : 
   10049    116618420 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
   10050              : 
   10051              :       /* Check for abstractness of the type.  */
   10052    116618420 :       if (var_definition_p)
   10053     51923990 :         abstract_virtuals_error (decl, type);
   10054              : 
   10055    116618420 :       if (decomp && !cp_finish_decomp (decl, decomp, true))
   10056        22367 :         decomp = NULL;
   10057              : 
   10058    116618420 :       if (TREE_TYPE (decl) == error_mark_node)
   10059              :         /* No initialization required.  */
   10060              :         ;
   10061    116618350 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
   10062              :         {
   10063     56864499 :           if (init)
   10064              :             {
   10065          584 :               if (init == ridpointers[(int)RID_DEFAULT])
   10066              :                 {
   10067              :                   /* An out-of-class default definition is defined at
   10068              :                      the point where it is explicitly defaulted.  */
   10069          572 :                   if (DECL_DELETED_FN (decl))
   10070            6 :                     maybe_explain_implicit_delete (decl);
   10071          566 :                   else if (DECL_INITIAL (decl) == error_mark_node)
   10072          542 :                     synthesize_method (decl);
   10073              :                 }
   10074              :               else
   10075           24 :                 error_at (cp_expr_loc_or_loc (init,
   10076           12 :                                               DECL_SOURCE_LOCATION (decl)),
   10077              :                           "function %q#D is initialized like a variable",
   10078              :                           decl);
   10079              :             }
   10080              :           /* else no initialization required.  */
   10081              :         }
   10082     59753851 :       else if (DECL_EXTERNAL (decl)
   10083     59753851 :                && ! (DECL_LANG_SPECIFIC (decl)
   10084      7529664 :                      && DECL_NOT_REALLY_EXTERN (decl)))
   10085              :         {
   10086              :           /* check_initializer will have done any constant initialization.  */
   10087              :         }
   10088              :       /* A variable definition.  */
   10089     53784221 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
   10090              :         {
   10091              :           /* Initialize the local variable.  */
   10092     23844430 :           if (!decomp)
   10093     23811707 :             initialize_local_var (decl, init, false);
   10094              :           else
   10095              :             {
   10096        32723 :               tree cleanup = NULL_TREE;
   10097        32723 :               if (DECL_SIZE (decl))
   10098        32723 :                 cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   10099              :               /* If cp_finish_decomp needs to emit any code, we need to emit that
   10100              :                  code after code emitted by initialize_local_var in a single
   10101              :                  CLEANUP_POINT_EXPR, so that temporaries are destructed only
   10102              :                  after the cp_finish_decomp emitted code.
   10103              :                  If there are any cleanups, either extend_ref_init_temps
   10104              :                  created ones or e.g. array destruction, push those first
   10105              :                  with the cleanups guarded on a bool temporary, initially
   10106              :                  set to false and set to true after initialize_local_var
   10107              :                  emitted code.  */
   10108        32723 :               tree guard = NULL_TREE;
   10109        32723 :               if (cleanups || cleanup)
   10110              :                 {
   10111        32723 :                   guard = get_internal_target_expr (boolean_false_node);
   10112        32723 :                   add_stmt (guard);
   10113        32723 :                   guard = TARGET_EXPR_SLOT (guard);
   10114              :                 }
   10115        32723 :               tree sl = push_stmt_list ();
   10116        32723 :               initialize_local_var (decl, init, true);
   10117        32723 :               if (guard)
   10118              :                 {
   10119        32723 :                   add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
   10120              :                                     guard, boolean_true_node));
   10121        32741 :                   for (tree &t : *cleanups)
   10122           18 :                     t = build3 (COND_EXPR, void_type_node,
   10123              :                                 guard, t, void_node);
   10124        32723 :                   if (cleanup)
   10125           25 :                     cleanup = build3 (COND_EXPR, void_type_node,
   10126              :                                       guard, cleanup, void_node);
   10127              :                 }
   10128        32723 :               unsigned before = stmt_list_stack->length ();
   10129        32723 :               cp_finish_decomp (decl, decomp);
   10130        32723 :               decomp = NULL;
   10131        32723 :               unsigned n_extra_cleanups = stmt_list_stack->length () - before;
   10132        32723 :               sl = pop_stmt_list (sl);
   10133        32723 :               if (n_extra_cleanups)
   10134              :                 {
   10135              :                   /* If cp_finish_decomp needs any cleanups, such as for
   10136              :                      extend_ref_init_temps created vars, pop_stmt_list
   10137              :                      popped that all, so push those extra cleanups around
   10138              :                      the whole sequence with a guard variable.  */
   10139           15 :                   gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
   10140           15 :                   guard = get_internal_target_expr (integer_zero_node);
   10141           15 :                   add_stmt (guard);
   10142           15 :                   guard = TARGET_EXPR_SLOT (guard);
   10143           63 :                   for (unsigned i = 0; i < n_extra_cleanups; ++i)
   10144              :                     {
   10145           48 :                       tree_stmt_iterator tsi = tsi_last (sl);
   10146           48 :                       gcc_assert (!tsi_end_p (tsi));
   10147           48 :                       tree last = tsi_stmt (tsi);
   10148           48 :                       gcc_assert (TREE_CODE (last) == CLEANUP_STMT
   10149              :                                   && !CLEANUP_EH_ONLY (last));
   10150           48 :                       tree cst = build_int_cst (integer_type_node, i + 1);
   10151           96 :                       tree cl = build3 (COND_EXPR, void_type_node,
   10152              :                                         build2 (GE_EXPR, boolean_type_node,
   10153              :                                                 guard, cst),
   10154           48 :                                         CLEANUP_EXPR (last), void_node);
   10155           48 :                       extra_cleanups.safe_push (cl);
   10156           48 :                       tsi_link_before (&tsi, build2 (MODIFY_EXPR,
   10157              :                                                      integer_type_node,
   10158              :                                                      guard, cst),
   10159              :                                        TSI_SAME_STMT);
   10160           48 :                       tree sl2 = CLEANUP_BODY (last);
   10161           48 :                       gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
   10162           48 :                       tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
   10163           48 :                       tsi_delink (&tsi);
   10164              :                     }
   10165              :                 }
   10166        32723 :               decomp_init = maybe_cleanup_point_expr_void (sl);
   10167        32723 :               if (cleanup)
   10168           25 :                 finish_decl_cleanup (decl, cleanup);
   10169              :             }
   10170              :         }
   10171              : 
   10172              :       /* If a variable is defined, and then a subsequent
   10173              :          definition with external linkage is encountered, we will
   10174              :          get here twice for the same variable.  We want to avoid
   10175              :          calling expand_static_init more than once.  For variables
   10176              :          that are not static data members, we can call
   10177              :          expand_static_init only when we actually process the
   10178              :          initializer.  It is not legal to redeclare a static data
   10179              :          member, so this issue does not arise in that case.  */
   10180     29939791 :       else if (var_definition_p && TREE_STATIC (decl))
   10181              :         {
   10182     28077701 :           if (decomp && DECL_FUNCTION_SCOPE_P (decl))
   10183              :             {
   10184          104 :               tree sl = push_stmt_list ();
   10185          104 :               auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
   10186          104 :               current_stmt_tree ()->stmts_are_full_exprs_p = 0;
   10187          104 :               expand_static_init (decl, init);
   10188          104 :               current_stmt_tree ()->stmts_are_full_exprs_p
   10189          104 :                 = saved_stmts_are_full_exprs_p;
   10190          104 :               cp_finish_decomp (decl, decomp);
   10191          104 :               decomp = NULL;
   10192          104 :               sl = pop_stmt_list (sl);
   10193          104 :               sl = maybe_cleanup_point_expr_void (sl);
   10194          104 :               add_stmt (sl);
   10195              :             }
   10196              :           else
   10197     28077597 :             expand_static_init (decl, init);
   10198              :         }
   10199              :     }
   10200              : 
   10201              :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
   10202              :      reference, insert it in the statement-tree now.  */
   10203    125808315 :   if (cleanups)
   10204              :     {
   10205     53077884 :       for (tree t : *cleanups)
   10206              :         {
   10207         2789 :           push_cleanup (NULL_TREE, t, false);
   10208              :           /* As in initialize_local_var.  */
   10209         2789 :           wrap_temporary_cleanups (init, t);
   10210              :         }
   10211     53075095 :       release_tree_vector (cleanups);
   10212              :     }
   10213              : 
   10214    125808393 :   for (tree t : &extra_cleanups)
   10215           48 :     push_cleanup (NULL_TREE, t, false);
   10216              : 
   10217    125808315 :   if (decomp_init)
   10218        32723 :     add_stmt (decomp_init);
   10219              : 
   10220    125808315 :   if (decomp
   10221          146 :       && var_definition_p
   10222          146 :       && TREE_STATIC (decl)
   10223    125808461 :       && !DECL_FUNCTION_SCOPE_P (decl))
   10224              :     {
   10225          146 :       tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
   10226          146 :                            ? tls_aggregates : static_aggregates);
   10227          146 :       tree aggregates2 = aggregates3;
   10228          146 :       if (aggregates2 != aggregates1)
   10229              :         {
   10230           66 :           cp_finish_decomp (decl, decomp);
   10231           66 :           decomp = NULL;
   10232           66 :           if (aggregates3 != aggregates2)
   10233              :             {
   10234              :               /* If there are dynamic initializers for the structured
   10235              :                  binding base or associated extended ref temps and also
   10236              :                  dynamic initializers for the structured binding non-base
   10237              :                  vars, mark them.  */
   10238          267 :               for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
   10239          204 :                 STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
   10240          150 :               for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
   10241           87 :                 STATIC_INIT_DECOMP_BASE_P (t) = 1;
   10242              :             }
   10243              :         }
   10244              :     }
   10245              : 
   10246    125808315 :   if (was_readonly)
   10247       236023 :     TREE_READONLY (decl) = 1;
   10248              : 
   10249    125808315 :   if (flag_openmp
   10250       438614 :       && VAR_P (decl)
   10251    126002397 :       && lookup_attribute ("omp declare target implicit",
   10252       194082 :                            DECL_ATTRIBUTES (decl)))
   10253              :     {
   10254           52 :       DECL_ATTRIBUTES (decl)
   10255           52 :         = remove_attribute ("omp declare target implicit",
   10256           52 :                             DECL_ATTRIBUTES (decl));
   10257           52 :       complete_type (TREE_TYPE (decl));
   10258           52 :       if (!omp_mappable_type (TREE_TYPE (decl)))
   10259              :         {
   10260           30 :           auto_diagnostic_group d;
   10261           30 :           error ("%q+D in declare target directive does not have mappable"
   10262              :                  " type", decl);
   10263           30 :           if (TREE_TYPE (decl) != error_mark_node
   10264           30 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
   10265           30 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
   10266           30 :         }
   10267           22 :       else if (!lookup_attribute ("omp declare target",
   10268           22 :                                   DECL_ATTRIBUTES (decl))
   10269           44 :                && !lookup_attribute ("omp declare target link",
   10270           22 :                                      DECL_ATTRIBUTES (decl)))
   10271              :         {
   10272           22 :           DECL_ATTRIBUTES (decl)
   10273           22 :             = tree_cons (get_identifier ("omp declare target"),
   10274           22 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
   10275           22 :           symtab_node *node = symtab_node::get (decl);
   10276           22 :           if (node != NULL)
   10277              :             {
   10278           19 :               node->offloadable = 1;
   10279           19 :               if (ENABLE_OFFLOADING)
   10280              :                 {
   10281              :                   g->have_offload = true;
   10282              :                   if (is_a <varpool_node *> (node))
   10283              :                     vec_safe_push (offload_vars, decl);
   10284              :                 }
   10285              :             }
   10286              :         }
   10287              :     }
   10288              : 
   10289              :   /* This is the last point we can lower alignment so give the target the
   10290              :      chance to do so.  */
   10291    125808315 :   if (VAR_P (decl)
   10292     59753921 :       && !is_global_var (decl)
   10293    149652888 :       && !DECL_HARD_REGISTER (decl))
   10294     23844520 :     targetm.lower_local_decl_alignment (decl);
   10295              : 
   10296    125808315 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
   10297    320976583 : }
   10298              : 
   10299              : /* For class TYPE return itself or some its bases that contain
   10300              :    any direct non-static data members.  Return error_mark_node if an
   10301              :    error has been diagnosed.  */
   10302              : 
   10303              : static tree
   10304        27846 : find_decomp_class_base (location_t loc, tree type, tree ret,
   10305              :                         tsubst_flags_t complain)
   10306              : {
   10307        55692 :   if (LAMBDA_TYPE_P (type))
   10308              :     {
   10309           12 :       if (complain & tf_error)
   10310              :         {
   10311           12 :           auto_diagnostic_group d;
   10312           12 :           error_at (loc, "cannot decompose lambda closure type %qT", type);
   10313           12 :           inform (location_of (type), "lambda declared here");
   10314           12 :         }
   10315           12 :       return error_mark_node;
   10316              :     }
   10317              : 
   10318        27834 :   bool member_seen = false;
   10319       344772 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
   10320       577584 :     if (TREE_CODE (field) != FIELD_DECL
   10321        56506 :         || DECL_ARTIFICIAL (field)
   10322       373383 :         || DECL_UNNAMED_BIT_FIELD (field))
   10323       260607 :       continue;
   10324        56370 :     else if (ret)
   10325              :       return type;
   10326        56344 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
   10327              :       {
   10328            8 :         if ((complain & tf_error) == 0)
   10329            0 :           return error_mark_node;
   10330            8 :         auto_diagnostic_group d;
   10331            8 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
   10332            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10333              :                          "anonymous struct member", type);
   10334              :         else
   10335            4 :           error_at (loc, "cannot decompose class type %qT because it has an "
   10336              :                          "anonymous union member", type);
   10337            8 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
   10338            8 :         return error_mark_node;
   10339            8 :       }
   10340        56336 :     else if (!accessible_p (type, field, true))
   10341              :       {
   10342            5 :         if ((complain & tf_error) == 0)
   10343            0 :           return error_mark_node;
   10344            5 :         auto_diagnostic_group d;
   10345            5 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
   10346              :                   field, type);
   10347            5 :         inform (DECL_SOURCE_LOCATION (field),
   10348            5 :                 TREE_PRIVATE (field)
   10349              :                 ? G_("declared private here")
   10350              :                 : G_("declared protected here"));
   10351            5 :         return error_mark_node;
   10352            5 :       }
   10353              :     else
   10354              :       member_seen = true;
   10355              : 
   10356        27795 :   tree base_binfo, binfo;
   10357        27795 :   tree orig_ret = ret;
   10358        27795 :   int i;
   10359        27795 :   if (member_seen)
   10360        27693 :     ret = type;
   10361        27859 :   for (binfo = TYPE_BINFO (type), i = 0;
   10362        27859 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   10363              :     {
   10364           84 :       auto_diagnostic_group d;
   10365           84 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
   10366              :                                        complain);
   10367           84 :       if (t == error_mark_node)
   10368              :         {
   10369            3 :           if (complain & tf_error)
   10370            3 :             inform (location_of (type), "in base class of %qT", type);
   10371            3 :           return error_mark_node;
   10372              :         }
   10373           81 :       if (t != NULL_TREE && t != ret)
   10374              :         {
   10375           54 :           if (ret == type)
   10376              :             {
   10377           10 :               if (complain & tf_error)
   10378           10 :                 error_at (loc, "cannot decompose class type %qT: both it and "
   10379              :                                "its base class %qT have non-static data "
   10380              :                                "members", type, t);
   10381           10 :               return error_mark_node;
   10382              :             }
   10383           44 :           else if (orig_ret != NULL_TREE)
   10384              :             return t;
   10385           44 :           else if (ret != NULL_TREE)
   10386              :             {
   10387            7 :               if (complain & tf_error)
   10388            7 :                 error_at (loc, "cannot decompose class type %qT: its base "
   10389              :                                "classes %qT and %qT have non-static data "
   10390              :                                "members", type, ret, t);
   10391            7 :               return error_mark_node;
   10392              :             }
   10393              :           else
   10394              :             ret = t;
   10395              :         }
   10396           84 :     }
   10397              :   return ret;
   10398              : }
   10399              : 
   10400              : /* Return std::tuple_size<TYPE>::value.  */
   10401              : 
   10402              : static tree
   10403       103247 : get_tuple_size (tree type)
   10404              : {
   10405       103247 :   tree args = make_tree_vec (1);
   10406       103247 :   TREE_VEC_ELT (args, 0) = type;
   10407       103247 :   tree inst = lookup_template_class (tuple_size_identifier, args,
   10408              :                                      /*in_decl*/NULL_TREE,
   10409              :                                      /*context*/std_node,
   10410              :                                      tf_none);
   10411       103247 :   inst = complete_type (inst);
   10412       103247 :   if (inst == error_mark_node
   10413       101763 :       || !COMPLETE_TYPE_P (inst)
   10414       178690 :       || !CLASS_TYPE_P (inst))
   10415              :     return NULL_TREE;
   10416        75443 :   tree val = lookup_qualified_name (inst, value_identifier,
   10417              :                                     LOOK_want::NORMAL, /*complain*/false);
   10418        75443 :   if (val == error_mark_node)
   10419              :     return NULL_TREE;
   10420        75437 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
   10421        75437 :     val = maybe_constant_value (val, NULL_TREE, mce_true);
   10422        75437 :   if (TREE_CODE (val) == INTEGER_CST)
   10423              :     return val;
   10424              :   else
   10425            6 :     return error_mark_node;
   10426              : }
   10427              : 
   10428              : /* Return std::tuple_element<I,TYPE>::type.  */
   10429              : 
   10430              : static tree
   10431        85574 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
   10432              : {
   10433        85574 :   tree args = make_tree_vec (2);
   10434        85574 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
   10435        85574 :   TREE_VEC_ELT (args, 1) = type;
   10436        85574 :   tree inst = lookup_template_class (tuple_element_identifier, args,
   10437              :                                      /*in_decl*/NULL_TREE,
   10438              :                                      /*context*/std_node,
   10439              :                                      tf_warning_or_error);
   10440        85574 :   return make_typename_type (inst, type_identifier,
   10441        85574 :                              none_type, tf_warning_or_error);
   10442              : }
   10443              : 
   10444              : /* Return e.get<i>() or get<i>(e).  */
   10445              : 
   10446              : static tree
   10447        85583 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
   10448              : {
   10449        85583 :   tree targs = make_tree_vec (1);
   10450        85583 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
   10451              : 
   10452        85583 :   tree etype = TREE_TYPE (decl);
   10453        85583 :   tree e = convert_from_reference (decl);
   10454              : 
   10455              :   /* [The id-expression] e is an lvalue if the type of the entity e is an
   10456              :      lvalue reference and an xvalue otherwise.  */
   10457        85583 :   if (!TYPE_REF_P (etype)
   10458        85583 :       || TYPE_REF_IS_RVALUE (etype))
   10459        84279 :     e = move (e);
   10460              : 
   10461        85583 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
   10462              :                                     LOOK_want::NORMAL, /*complain*/false);
   10463        85583 :   bool use_member_get = false;
   10464              : 
   10465              :   /* To use a member get, member lookup must find at least one
   10466              :      declaration that is a function template
   10467              :      whose first template parameter is a non-type parameter.  */
   10468       254269 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
   10469              :     {
   10470        85583 :       tree fn = *iter;
   10471        85583 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
   10472              :         {
   10473         2483 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
   10474         2483 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
   10475         2483 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
   10476              :             {
   10477              :               use_member_get = true;
   10478              :               break;
   10479              :             }
   10480              :         }
   10481              :     }
   10482              : 
   10483        85583 :   if (use_member_get)
   10484              :     {
   10485         2480 :       fns = lookup_template_function (fns, targs);
   10486         2480 :       return build_new_method_call (e, fns, /*args*/NULL,
   10487              :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
   10488         2480 :                                     /*fn_p*/NULL, tf_warning_or_error);
   10489              :     }
   10490              :   else
   10491              :     {
   10492        83103 :       releasing_vec args (make_tree_vector_single (e));
   10493        83103 :       fns = lookup_template_function (get__identifier, targs);
   10494        83103 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
   10495        83103 :       return finish_call_expr (fns, &args, /*novirt*/false,
   10496              :                                /*koenig*/true, tf_warning_or_error);
   10497        83103 :     }
   10498              : }
   10499              : 
   10500              : /* It's impossible to recover the decltype of a tuple decomposition variable
   10501              :    based on the actual type of the variable, so store it in a hash table.  */
   10502              : 
   10503              : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
   10504              : 
   10505              : tree
   10506          630 : lookup_decomp_type (tree v)
   10507              : {
   10508          630 :   if (decomp_type_table)
   10509          503 :     if (tree *slot = decomp_type_table->get (v))
   10510          439 :       return *slot;
   10511              :   return NULL_TREE;
   10512              : }
   10513              : 
   10514              : /* Mangle a decomposition declaration if needed.  Arguments like
   10515              :    in cp_finish_decomp.  */
   10516              : 
   10517              : static void
   10518        55340 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
   10519              : {
   10520        55340 :   if (!processing_template_decl
   10521        55340 :       && !error_operand_p (decl)
   10522       110680 :       && TREE_STATIC (decl))
   10523              :     {
   10524          884 :       auto_vec<tree, 16> v;
   10525          884 :       v.safe_grow (decomp->count, true);
   10526          884 :       tree d = decomp->decl;
   10527         2931 :       for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
   10528         2047 :         v[decomp->count - i - 1] = d;
   10529          884 :       if (DECL_FUNCTION_SCOPE_P (decl))
   10530              :         {
   10531              :           size_t sz = 3;
   10532          925 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10533          660 :             sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
   10534          265 :           char *name = XALLOCAVEC (char, sz);
   10535          265 :           name[0] = 'D';
   10536          265 :           name[1] = 'C';
   10537          265 :           char *p = name + 2;
   10538          925 :           for (unsigned int i = 0; i < decomp->count; ++i)
   10539              :             {
   10540          660 :               size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
   10541          660 :               *p++ = ' ';
   10542          660 :               memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
   10543          660 :               p += len;
   10544              :             }
   10545          265 :           *p = '\0';
   10546          265 :           determine_local_discriminator (decl, get_identifier (name));
   10547              :         }
   10548          884 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
   10549          884 :       maybe_apply_pragma_weak (decl);
   10550          884 :     }
   10551        55340 : }
   10552              : 
   10553              : /* Append #i to DECL_NAME (decl) or for name independent decls
   10554              :    clear DECL_NAME (decl).  */
   10555              : 
   10556              : static void
   10557        14884 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
   10558              : {
   10559        14884 :   if (name_independent_decl_p (decl))
   10560              :     /* Only "_" names are treated as name independent, "_#0" etc. is not and
   10561              :        because we pushdecl the individual decl elements of structured binding
   10562              :        pack, we could get redeclaration errors if there are 2 or more name
   10563              :        independent structured binding packs in the same scope.  */
   10564          312 :     DECL_NAME (decl) = NULL_TREE;
   10565              :   else
   10566              :     {
   10567        14572 :       tree name = DECL_NAME (decl);
   10568        14572 :       size_t len = IDENTIFIER_LENGTH (name) + 22;
   10569        14572 :       char *n = XALLOCAVEC (char, len);
   10570        14572 :       snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
   10571        14572 :                 IDENTIFIER_POINTER (name), i);
   10572        14572 :       DECL_NAME (decl) = get_identifier (n);
   10573              :     }
   10574        14884 : }
   10575              : 
   10576              : /* Return structured binding size of TYPE or -1 if erroneous.  */
   10577              : 
   10578              : HOST_WIDE_INT
   10579          540 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
   10580              : {
   10581          540 :   if (TYPE_REF_P (type))
   10582              :     {
   10583            0 :       type = complete_type (TREE_TYPE (type));
   10584            0 :       if (type == error_mark_node)
   10585              :         return -1;
   10586            0 :       if (!COMPLETE_TYPE_P (type))
   10587              :         {
   10588            0 :           if (complain & tf_error)
   10589            0 :             error_at (loc, "structured binding refers to incomplete type %qT",
   10590              :                       type);
   10591            0 :           return -1;
   10592              :         }
   10593              :     }
   10594              : 
   10595          540 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10596          540 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10597              :     {
   10598          311 :       if (TYPE_DOMAIN (type) == NULL_TREE)
   10599              :         {
   10600            9 :           if (complain & tf_error)
   10601            6 :             error_at (loc, "cannot decompose array of unknown bound %qT",
   10602              :                       type);
   10603            9 :           return -1;
   10604              :         }
   10605          302 :       tree nelts = array_type_nelts_top (type);
   10606          302 :       if (nelts == error_mark_node)
   10607              :         return -1;
   10608          302 :       if (!tree_fits_shwi_p (nelts))
   10609              :         {
   10610            3 :           if (complain & tf_error)
   10611            3 :             error_at (loc, "cannot decompose variable length array %qT", type);
   10612            3 :           return -1;
   10613              :         }
   10614          299 :       return tree_to_shwi (nelts);
   10615              :     }
   10616              :   /* 2 GNU extensions.  */
   10617          229 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10618              :     return 2;
   10619          223 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10620              :     {
   10621           12 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10622              :         {
   10623              :           if (complain & tf_error)
   10624              :             error_at (loc, "cannot decompose variable length vector %qT", type);
   10625              :           return -1;
   10626              :         }
   10627           12 :       return eltscnt;
   10628              :     }
   10629          211 :   else if (tree tsize = get_tuple_size (type))
   10630              :     {
   10631           37 :       if (tsize == error_mark_node
   10632           31 :           || !tree_fits_shwi_p (tsize)
   10633           68 :           || tree_int_cst_sgn (tsize) < 0)
   10634              :         {
   10635            9 :           if (complain & tf_error)
   10636            9 :             error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10637              :                            "constant expression", type);
   10638            9 :           return -1;
   10639              :         }
   10640           28 :       return tree_to_shwi (tsize);
   10641              :     }
   10642          174 :   else if (TREE_CODE (type) == UNION_TYPE)
   10643              :     {
   10644            3 :       if (complain & tf_error)
   10645            3 :         error_at (loc, "cannot decompose union type %qT", type);
   10646            3 :       return -1;
   10647              :     }
   10648          171 :   else if (!CLASS_TYPE_P (type))
   10649              :     {
   10650           21 :       if (complain & tf_error)
   10651           18 :         error_at (loc, "cannot decompose non-array non-class type %qT", type);
   10652           21 :       return -1;
   10653              :     }
   10654          150 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   10655              :     return -1;
   10656          150 :   else if (!COMPLETE_TYPE_P (type))
   10657              :     {
   10658            3 :       if (complain & tf_error)
   10659            3 :         error_at (loc, "structured binding refers to incomplete class type "
   10660              :                   "%qT", type);
   10661            3 :       return -1;
   10662              :     }
   10663              :   else
   10664              :     {
   10665          147 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
   10666          147 :       if (btype == error_mark_node)
   10667              :         return -1;
   10668          126 :       else if (btype == NULL_TREE)
   10669              :         return 0;
   10670          105 :       if (btype != type)
   10671              :         {
   10672            6 :           tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
   10673            6 :           if (binfo == NULL_TREE || binfo == error_mark_node)
   10674              :             return -1;
   10675              :         }
   10676         1123 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   10677         1703 :         if (TREE_CODE (field) != FIELD_DECL
   10678          357 :             || DECL_ARTIFICIAL (field)
   10679         1381 :             || DECL_UNNAMED_BIT_FIELD (field))
   10680          679 :           continue;
   10681              :         else
   10682          345 :           eltscnt++;
   10683           99 :       return eltscnt;
   10684              :     }
   10685              : }
   10686              : 
   10687              : /* Finish a decomposition declaration.  DECL is the underlying declaration
   10688              :    "e", FIRST is the head of a chain of decls for the individual identifiers
   10689              :    chained through DECL_CHAIN in reverse order and COUNT is the number of
   10690              :    those decls.  If TEST_P is true, return true if any code would need to be
   10691              :    actually emitted but don't emit it.  Return false otherwise.  */
   10692              : 
   10693              : bool
   10694       311766 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
   10695              : {
   10696       311766 :   tree first = decomp->decl;
   10697       311766 :   unsigned count = decomp->count;
   10698       311766 :   if (error_operand_p (decl))
   10699              :     {
   10700           63 :      error_out:
   10701          616 :       while (count--)
   10702              :         {
   10703          420 :           TREE_TYPE (first) = error_mark_node;
   10704          420 :           if (DECL_HAS_VALUE_EXPR_P (first))
   10705              :             {
   10706            9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
   10707            9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
   10708              :             }
   10709          420 :           first = DECL_CHAIN (first);
   10710              :         }
   10711          196 :       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
   10712           51 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
   10713          196 :       return false;
   10714              :     }
   10715              : 
   10716       311703 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   10717       311703 :   if (type_dependent_expression_p (decl)
   10718              :       /* This happens for range for when not in templates.
   10719              :          Still add the DECL_VALUE_EXPRs for later processing.  */
   10720       311703 :       || (!processing_template_decl
   10721        88591 :           && type_uses_auto (TREE_TYPE (decl))))
   10722              :     {
   10723       613572 :       for (unsigned int i = 0; i < count; i++)
   10724              :         {
   10725       408977 :           if (!DECL_HAS_VALUE_EXPR_P (first))
   10726              :             {
   10727       408977 :               tree v = build_nt (ARRAY_REF, decl,
   10728       408977 :                                  size_int (count - i - 1),
   10729              :                                  NULL_TREE, NULL_TREE);
   10730       408977 :               SET_DECL_VALUE_EXPR (first, v);
   10731       408977 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
   10732              :             }
   10733       408977 :           if (processing_template_decl)
   10734       408347 :             fit_decomposition_lang_decl (first, decl);
   10735       408977 :           first = DECL_CHAIN (first);
   10736              :         }
   10737              :       return false;
   10738              :     }
   10739              : 
   10740       107108 :   auto_vec<tree, 16> v;
   10741       107108 :   v.safe_grow (count, true);
   10742       107108 :   tree d = first;
   10743       107108 :   int pack = -1;
   10744       320021 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
   10745              :     {
   10746       212913 :       v[count - i - 1] = d;
   10747       212913 :       fit_decomposition_lang_decl (d, decl);
   10748       212913 :       if (DECL_PACK_P (d))
   10749         3894 :         pack = count - i - 1;
   10750              :     }
   10751              : 
   10752       107108 :   tree type = TREE_TYPE (decl);
   10753       107108 :   tree dexp = decl;
   10754              : 
   10755       107108 :   if (TYPE_REF_P (type))
   10756              :     {
   10757         1930 :       dexp = convert_from_reference (dexp);
   10758         1930 :       type = complete_type (TREE_TYPE (type));
   10759         1930 :       if (type == error_mark_node)
   10760          133 :         goto error_out;
   10761         1930 :       if (!COMPLETE_TYPE_P (type))
   10762              :         {
   10763            3 :           error_at (loc, "structured binding refers to incomplete type %qT",
   10764              :                     type);
   10765            3 :           goto error_out;
   10766              :         }
   10767              :     }
   10768              : 
   10769       107105 :   tree eltype = NULL_TREE;
   10770       107105 :   unsigned HOST_WIDE_INT eltscnt = 0;
   10771              :   /* Structured binding packs when initializer is non-dependent should
   10772              :      have their DECL_VALUE_EXPR set to a TREE_VEC.  First two elements
   10773              :      of that TREE_VEC are the base and index, what is normally represented
   10774              :      as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
   10775              :      of the pack first element.  The remaining elements of the TREE_VEC
   10776              :      are VAR_DECLs for the pack elements.  */
   10777       107105 :   tree packv = NULL_TREE;
   10778              : 
   10779       107105 :   if (TREE_CODE (type) == ARRAY_TYPE)
   10780              :     {
   10781         3931 :       tree nelts;
   10782         3931 :       nelts = array_type_nelts_top (type);
   10783         3931 :       if (nelts == error_mark_node)
   10784            0 :         goto error_out;
   10785         3931 :       if (DECL_DECOMP_BASE (decl))
   10786              :         {
   10787            9 :           error_at (loc, "array initializer for structured binding "
   10788              :                     "declaration in condition");
   10789            9 :           goto error_out;
   10790              :         }
   10791         3922 :       if (!tree_fits_uhwi_p (nelts))
   10792              :         {
   10793            3 :           error_at (loc, "cannot decompose variable length array %qT", type);
   10794            3 :           goto error_out;
   10795              :         }
   10796         3919 :       eltscnt = tree_to_uhwi (nelts);
   10797         3919 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10798              :         {
   10799           11 :        cnt_mismatch:
   10800           38 :           auto_diagnostic_group d;
   10801           38 :           if (count > eltscnt)
   10802           27 :             error_n (loc, count,
   10803              :                      "%u name provided for structured binding",
   10804              :                      "%u names provided for structured binding", count);
   10805              :           else
   10806           11 :             error_n (loc, count,
   10807              :                      "only %u name provided for structured binding",
   10808              :                      "only %u names provided for structured binding", count);
   10809           38 :           inform_n (loc, eltscnt,
   10810              :                     "while %qT decomposes into %wu element",
   10811              :                     "while %qT decomposes into %wu elements",
   10812              :                     type, eltscnt);
   10813           38 :           goto error_out;
   10814              :         }
   10815         3908 :       eltype = TREE_TYPE (type);
   10816         9312 :       for (unsigned int i = 0; i < count; i++)
   10817              :         {
   10818         5404 :           if ((unsigned) pack == i)
   10819              :             {
   10820         2967 :               packv = make_tree_vec (eltscnt - count + 3);
   10821        15781 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10822              :                 {
   10823        12814 :                   tree t;
   10824        12814 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10825        12814 :                   set_sb_pack_name (t, j);
   10826        12814 :                   maybe_push_decl (t);
   10827        12814 :                   TREE_TYPE (t) = eltype;
   10828        12814 :                   layout_decl (t, 0);
   10829        12814 :                   if (!processing_template_decl)
   10830              :                     {
   10831        12716 :                       tree a = unshare_expr (dexp);
   10832        12716 :                       a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
   10833              :                                   NULL_TREE, NULL_TREE);
   10834        12716 :                       SET_DECL_VALUE_EXPR (t, a);
   10835        12716 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10836              :                     }
   10837              :                 }
   10838         5404 :               continue;
   10839         2967 :             }
   10840         2437 :           TREE_TYPE (v[i]) = eltype;
   10841         2437 :           layout_decl (v[i], 0);
   10842         2437 :           if (processing_template_decl)
   10843          140 :             continue;
   10844         2297 :           tree t = unshare_expr (dexp);
   10845         2297 :           unsigned HOST_WIDE_INT j = i;
   10846         2297 :           if (pack != -1 && (unsigned) pack < i)
   10847           64 :             j = i + eltscnt - count;
   10848         2297 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   10849         2297 :           SET_DECL_VALUE_EXPR (v[i], t);
   10850         2297 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10851              :         }
   10852              :     }
   10853              :   /* 2 GNU extensions.  */
   10854       103174 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
   10855              :     {
   10856           78 :       eltscnt = 2;
   10857           78 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10858            3 :         goto cnt_mismatch;
   10859           75 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10860          213 :       for (unsigned int i = 0; i < count; i++)
   10861              :         {
   10862          138 :           if ((unsigned) pack == i)
   10863              :             {
   10864           60 :               packv = make_tree_vec (eltscnt - count + 3);
   10865          132 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10866              :                 {
   10867           72 :                   tree t;
   10868           72 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10869           72 :                   set_sb_pack_name (t, j);
   10870           72 :                   maybe_push_decl (t);
   10871           72 :                   TREE_TYPE (t) = eltype;
   10872           72 :                   layout_decl (t, 0);
   10873           72 :                   if (!processing_template_decl)
   10874              :                     {
   10875           72 :                       tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
   10876              :                                        unshare_expr (dexp));
   10877           48 :                       SET_DECL_VALUE_EXPR (t, a);
   10878           48 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10879              :                     }
   10880              :                 }
   10881           60 :               continue;
   10882           60 :             }
   10883           78 :           TREE_TYPE (v[i]) = eltype;
   10884           78 :           layout_decl (v[i], 0);
   10885           78 :           if (processing_template_decl)
   10886           16 :             continue;
   10887           62 :           tree t = unshare_expr (dexp);
   10888           62 :           unsigned HOST_WIDE_INT j = i;
   10889           62 :           if (pack != -1 && (unsigned) pack < i)
   10890           16 :             j = i + eltscnt - count;
   10891           93 :           t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
   10892           62 :           SET_DECL_VALUE_EXPR (v[i], t);
   10893           62 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10894              :         }
   10895              :     }
   10896       103096 :   else if (TREE_CODE (type) == VECTOR_TYPE)
   10897              :     {
   10898           60 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
   10899              :         {
   10900              :           error_at (loc, "cannot decompose variable length vector %qT", type);
   10901              :           goto error_out;
   10902              :         }
   10903           60 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10904            3 :         goto cnt_mismatch;
   10905           57 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
   10906          249 :       for (unsigned int i = 0; i < count; i++)
   10907              :         {
   10908          192 :           if ((unsigned) pack == i)
   10909              :             {
   10910           48 :               packv = make_tree_vec (eltscnt - count + 3);
   10911          708 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   10912              :                 {
   10913          660 :                   tree t;
   10914          660 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   10915          660 :                   set_sb_pack_name (t, j);
   10916          660 :                   maybe_push_decl (t);
   10917          660 :                   TREE_TYPE (t) = eltype;
   10918          660 :                   layout_decl (t, 0);
   10919          660 :                   if (!processing_template_decl)
   10920              :                     {
   10921          440 :                       tree a = unshare_expr (dexp);
   10922          440 :                       location_t loc = DECL_SOURCE_LOCATION (t);
   10923          440 :                       tree s = size_int (j + pack);
   10924          440 :                       convert_vector_to_array_for_subscript (loc, &a, s);
   10925          440 :                       a = build4 (ARRAY_REF, eltype, a, s,
   10926              :                                   NULL_TREE, NULL_TREE);
   10927          440 :                       SET_DECL_VALUE_EXPR (t, a);
   10928          440 :                       DECL_HAS_VALUE_EXPR_P (t) = 1;
   10929              :                     }
   10930              :                 }
   10931           84 :               continue;
   10932           48 :             }
   10933          144 :           TREE_TYPE (v[i]) = eltype;
   10934          144 :           layout_decl (v[i], 0);
   10935          144 :           if (processing_template_decl)
   10936           36 :             continue;
   10937          108 :           tree t = unshare_expr (dexp);
   10938          108 :           unsigned HOST_WIDE_INT j = i;
   10939          108 :           if (pack != -1 && (unsigned) pack < i)
   10940           24 :             j = i + eltscnt - count;
   10941          108 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
   10942          108 :                                                  &t, size_int (j));
   10943          108 :           t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
   10944          108 :           SET_DECL_VALUE_EXPR (v[i], t);
   10945          108 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   10946              :         }
   10947              :     }
   10948       103036 :   else if (tree tsize = get_tuple_size (type))
   10949              :     {
   10950        75400 :       if (tsize == error_mark_node)
   10951              :         {
   10952            0 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
   10953              :                          "constant expression", type);
   10954            0 :           goto error_out;
   10955              :         }
   10956        75400 :       if (!tree_fits_uhwi_p (tsize))
   10957              :         {
   10958           12 :           auto_diagnostic_group d;
   10959           12 :           error_n (loc, count,
   10960              :                    "%u name provided for structured binding",
   10961              :                    "%u names provided for structured binding", count);
   10962           12 :           inform (loc, "while %qT decomposes into %E elements",
   10963              :                   type, tsize);
   10964           12 :           goto error_out;
   10965           12 :         }
   10966        75388 :       eltscnt = tree_to_uhwi (tsize);
   10967        75388 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   10968            6 :         goto cnt_mismatch;
   10969        75382 :       if (test_p && eltscnt)
   10970       106975 :         return true;
   10971        42409 :       if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
   10972              :         {
   10973              :           /* For structured bindings used in conditions we need to evaluate
   10974              :              the conversion of decl (aka e in the standard) to bool or
   10975              :              integral/enumeral type (the latter for switch conditions)
   10976              :              before the get methods.  */
   10977           86 :           tree cond = convert_from_reference (decl);
   10978           86 :           if (integer_onep (DECL_DECOMP_BASE (decl)))
   10979              :             /* switch condition.  */
   10980           18 :             cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   10981              :                                                cond, true);
   10982              :           else
   10983              :             /* if/while/for condition.  */
   10984           68 :             cond = contextual_conv_bool (cond, tf_warning_or_error);
   10985           86 :           if (cond && !error_operand_p (cond))
   10986              :             {
   10987              :               /* Wrap that value into a TARGET_EXPR, emit it right
   10988              :                  away and save for later uses in the cp_parse_condition
   10989              :                  or its instantiation.  */
   10990           86 :               cond = get_internal_target_expr (cond);
   10991           86 :               add_stmt (cond);
   10992           86 :               DECL_DECOMP_BASE (decl) = cond;
   10993              :             }
   10994              :         }
   10995        42409 :       int save_read = DECL_READ_P (decl);
   10996       127458 :       for (unsigned i = 0; i < count; ++i)
   10997              :         {
   10998        85070 :           location_t sloc = input_location;
   10999        85070 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
   11000              : 
   11001        85070 :           if ((unsigned) pack == i)
   11002              :             {
   11003          321 :               packv = make_tree_vec (eltscnt - count + 3);
   11004         1155 :               for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
   11005              :                 {
   11006          834 :                   tree t;
   11007          834 :                   TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
   11008          834 :                   set_sb_pack_name (t, j);
   11009          834 :                   input_location = dloc;
   11010          834 :                   tree init = get_tuple_decomp_init (decl, j + pack);
   11011          834 :                   tree eltype = (init == error_mark_node ? error_mark_node
   11012          834 :                                  : get_tuple_element_type (type, j + pack));
   11013          834 :                   input_location = sloc;
   11014              : 
   11015          834 :                   if (VOID_TYPE_P (eltype))
   11016              :                     {
   11017            0 :                       error ("%<std::tuple_element<%wu, %T>::type%> is "
   11018              :                              "%<void%>", j + pack, type);
   11019            0 :                       eltype = error_mark_node;
   11020              :                     }
   11021          834 :                   if (init == error_mark_node || eltype == error_mark_node)
   11022              :                     {
   11023            0 :                       inform (dloc, "in initialization of structured binding "
   11024            0 :                               "pack %qD", v[pack]);
   11025            0 :                       goto error_out;
   11026              :                     }
   11027          834 :                   maybe_push_decl (t);
   11028              :                   /* Save the decltype away before reference collapse.  */
   11029          834 :                   hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
   11030          834 :                   if (glvalue_p (init))
   11031          777 :                     eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11032          834 :                   TREE_TYPE (t) = eltype;
   11033          834 :                   layout_decl (t, 0);
   11034          834 :                   DECL_HAS_VALUE_EXPR_P (t) = 0;
   11035          834 :                   if (!processing_template_decl)
   11036              :                     {
   11037          604 :                       copy_linkage (t, decl);
   11038          604 :                       tree name = DECL_NAME (t);
   11039          604 :                       if (TREE_STATIC (decl))
   11040           44 :                         DECL_NAME (t) = DECL_NAME (v[pack]);
   11041          604 :                       cp_finish_decl (t, init, /*constexpr*/false,
   11042              :                                       /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11043          604 :                       if (TREE_STATIC (decl))
   11044              :                         {
   11045           44 :                           DECL_ASSEMBLER_NAME (t);
   11046           44 :                           DECL_NAME (t) = name;
   11047              :                         }
   11048              :                     }
   11049              :                 }
   11050          321 :               continue;
   11051          321 :             }
   11052              : 
   11053        84749 :           unsigned HOST_WIDE_INT j = i;
   11054        84749 :           if (pack != -1 && (unsigned) pack < i)
   11055          235 :             j = i + eltscnt - count;
   11056        84749 :           input_location = dloc;
   11057        84749 :           tree init = get_tuple_decomp_init (decl, j);
   11058        84749 :           tree eltype = (init == error_mark_node ? error_mark_node
   11059        84740 :                          : get_tuple_element_type (type, j));
   11060        84749 :           input_location = sloc;
   11061              : 
   11062        84749 :           if (VOID_TYPE_P (eltype))
   11063              :             {
   11064            3 :               error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
   11065              :                      j, type);
   11066            3 :               eltype = error_mark_node;
   11067              :             }
   11068        84749 :           if (init == error_mark_node || eltype == error_mark_node)
   11069              :             {
   11070           21 :               inform (dloc, "in initialization of structured binding "
   11071           21 :                       "variable %qD", v[i]);
   11072           21 :               goto error_out;
   11073              :             }
   11074              :           /* Save the decltype away before reference collapse.  */
   11075        84728 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
   11076        84728 :           if (glvalue_p (init))
   11077        84384 :             eltype = cp_build_reference_type (eltype, !lvalue_p (init));
   11078        84728 :           TREE_TYPE (v[i]) = eltype;
   11079        84728 :           layout_decl (v[i], 0);
   11080        84728 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
   11081              :             {
   11082              :               /* In this case the names are variables, not just proxies.  */
   11083          220 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
   11084          220 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
   11085              :             }
   11086        84728 :           if (!processing_template_decl)
   11087              :             {
   11088        65878 :               copy_linkage (v[i], decl);
   11089        65878 :               cp_finish_decl (v[i], init, /*constexpr*/false,
   11090              :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
   11091              :             }
   11092              :         }
   11093              :       /* Ignore reads from the underlying decl performed during initialization
   11094              :          of the individual variables.  If those will be read, we'll mark
   11095              :          the underlying decl as read at that point.  */
   11096        42388 :       DECL_READ_P (decl) = save_read;
   11097              :     }
   11098        27636 :   else if (TREE_CODE (type) == UNION_TYPE)
   11099              :     {
   11100            3 :       error_at (loc, "cannot decompose union type %qT", type);
   11101            3 :       goto error_out;
   11102              :     }
   11103        27633 :   else if (!CLASS_TYPE_P (type))
   11104              :     {
   11105           16 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
   11106           16 :       goto error_out;
   11107              :     }
   11108        27617 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
   11109            0 :     goto error_out;
   11110        27617 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
   11111            2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
   11112              :              type);
   11113              :   else
   11114              :     {
   11115        27615 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE,
   11116              :                                            tf_warning_or_error);
   11117        27615 :       if (btype == error_mark_node)
   11118           21 :         goto error_out;
   11119        27594 :       else if (btype == NULL_TREE)
   11120              :         {
   11121           23 :           if (pack == 0 && count == 1)
   11122              :             {
   11123           16 :               eltscnt = 0;
   11124           16 :               packv = make_tree_vec (2);
   11125           16 :               goto done;
   11126              :             }
   11127            7 :           error_at (loc, "cannot decompose class type %qT without non-static "
   11128              :                          "data members", type);
   11129            7 :           goto error_out;
   11130              :         }
   11131       341980 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11132       572870 :         if (TREE_CODE (field) != FIELD_DECL
   11133        55964 :             || DECL_ARTIFICIAL (field)
   11134       370369 :             || DECL_UNNAMED_BIT_FIELD (field))
   11135       258461 :           continue;
   11136              :         else
   11137        55948 :           eltscnt++;
   11138        27571 :       if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
   11139           15 :         goto cnt_mismatch;
   11140        27556 :       tree t = dexp;
   11141        27556 :       if (type != btype)
   11142              :         {
   11143           18 :           t = convert_to_base (t, btype, /*check_access*/true,
   11144              :                                /*nonnull*/false, tf_warning_or_error);
   11145           18 :           type = btype;
   11146              :         }
   11147        27556 :       unsigned HOST_WIDE_INT j = 0;
   11148        27556 :       unsigned int i = 0;
   11149       341769 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
   11150       572515 :         if (TREE_CODE (field) != FIELD_DECL
   11151        55927 :             || DECL_ARTIFICIAL (field)
   11152       370136 :             || DECL_UNNAMED_BIT_FIELD (field))
   11153       258302 :           continue;
   11154              :         else
   11155              :           {
   11156        55911 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
   11157              :                                                      NULL_TREE);
   11158        55911 :             if (REFERENCE_REF_P (tt))
   11159           30 :               tt = TREE_OPERAND (tt, 0);
   11160        55911 :             if (pack != -1 && j >= (unsigned) pack)
   11161              :               {
   11162          685 :                 if (j == (unsigned) pack)
   11163              :                   {
   11164          227 :                     packv = make_tree_vec (eltscnt - count + 3);
   11165          227 :                     i++;
   11166              :                   }
   11167          685 :                 if (j < (unsigned) pack + eltscnt - (count - 1))
   11168              :                   {
   11169          504 :                     tree t;
   11170          504 :                     TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
   11171          504 :                     set_sb_pack_name (t, j + 1 - i);
   11172          504 :                     maybe_push_decl (t);
   11173          504 :                     TREE_TYPE (t) = TREE_TYPE (tt);
   11174          504 :                     layout_decl (t, 0);
   11175          504 :                     if (!processing_template_decl)
   11176              :                       {
   11177          383 :                         SET_DECL_VALUE_EXPR (t, tt);
   11178          383 :                         DECL_HAS_VALUE_EXPR_P (t) = 1;
   11179              :                       }
   11180              :                     else
   11181          121 :                       DECL_HAS_VALUE_EXPR_P (t) = 0;
   11182          504 :                     j++;
   11183          504 :                     continue;
   11184          504 :                   }
   11185              :               }
   11186        55407 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
   11187        55407 :             layout_decl (v[i], 0);
   11188        55407 :             if (!processing_template_decl)
   11189              :               {
   11190        37015 :                 SET_DECL_VALUE_EXPR (v[i], tt);
   11191        37015 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11192              :               }
   11193        55407 :             i++;
   11194        55407 :             j++;
   11195              :           }
   11196        27556 :       if (pack != -1 && j == (unsigned) pack)
   11197              :         {
   11198           20 :           gcc_checking_assert (eltscnt == count - 1);
   11199           20 :           packv = make_tree_vec (2);
   11200              :         }
   11201              :     }
   11202        74002 :  done:
   11203        74002 :   if (packv)
   11204              :     {
   11205         3659 :       gcc_checking_assert (pack != -1);
   11206         3659 :       TREE_VEC_ELT (packv, 0) = decl;
   11207         3659 :       TREE_VEC_ELT (packv, 1) = size_int (pack);
   11208         3659 :       SET_DECL_VALUE_EXPR (v[pack], packv);
   11209         3659 :       DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
   11210         3659 :       DECL_IGNORED_P (v[pack]) = 1;
   11211         3659 :       if (!processing_template_decl)
   11212        17580 :         for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
   11213        14191 :           pushdecl (TREE_VEC_ELT (packv, 2 + i));
   11214              :     }
   11215        74002 :   if (processing_template_decl)
   11216              :     {
   11217        56467 :       for (unsigned int i = 0; i < count; i++)
   11218        37706 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
   11219              :           {
   11220        37289 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
   11221              :                                NULL_TREE, NULL_TREE);
   11222        37289 :             SET_DECL_VALUE_EXPR (v[i], a);
   11223        37289 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
   11224              :           }
   11225              :     }
   11226        55241 :   else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
   11227              :     {
   11228          480 :       tree attr = NULL_TREE, *pa = &attr;
   11229         1550 :       for (unsigned int i = 0; i < count; i++)
   11230         1070 :         if ((unsigned) pack != i
   11231         1070 :             && DECL_HAS_VALUE_EXPR_P (v[i])
   11232         1796 :             && !DECL_IGNORED_P (v[i]))
   11233              :           {
   11234          726 :             (*debug_hooks->early_global_decl) (v[i]);
   11235          726 :             *pa = build_tree_list (NULL_TREE, v[i]);
   11236          726 :             pa = &TREE_CHAIN (*pa);
   11237              :           }
   11238          480 :       if (attr)
   11239          364 :         DECL_ATTRIBUTES (decl)
   11240          728 :           = tree_cons (get_identifier ("structured bindings"),
   11241          364 :                        attr, DECL_ATTRIBUTES (decl));
   11242              :     }
   11243              :   return false;
   11244              : }
   11245              : 
   11246              : /* Returns a declaration for a VAR_DECL as if:
   11247              : 
   11248              :      extern "C" TYPE NAME;
   11249              : 
   11250              :    had been seen.  Used to create compiler-generated global
   11251              :    variables.  */
   11252              : 
   11253              : static tree
   11254         2156 : declare_global_var (tree name, tree type)
   11255              : {
   11256         2156 :   auto cookie = push_abi_namespace (global_namespace);
   11257         2156 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
   11258         2156 :   TREE_PUBLIC (decl) = 1;
   11259         2156 :   DECL_EXTERNAL (decl) = 1;
   11260         2156 :   DECL_ARTIFICIAL (decl) = 1;
   11261         2156 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   11262              :   /* If the user has explicitly declared this variable (perhaps
   11263              :      because the code we are compiling is part of a low-level runtime
   11264              :      library), then it is possible that our declaration will be merged
   11265              :      with theirs by pushdecl.  */
   11266         2156 :   decl = pushdecl (decl);
   11267         2156 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
   11268         2156 :   pop_abi_namespace (cookie, global_namespace);
   11269              : 
   11270         2156 :   return decl;
   11271              : }
   11272              : 
   11273              : /* Returns the type for the argument to "atexit" corresponding to the function
   11274              :    to be called when the program exits.  */
   11275              : 
   11276              : static tree
   11277           24 : get_atexit_fn_ptr_type ()
   11278              : {
   11279           24 :   if (!atexit_fn_ptr_type_node)
   11280              :     {
   11281           12 :       tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
   11282           12 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
   11283              :     }
   11284              : 
   11285           24 :   return atexit_fn_ptr_type_node;
   11286              : }
   11287              : 
   11288              : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
   11289              :    or "__cxa_throw" corresponding to the destructor to be called when the
   11290              :    program exits.  */
   11291              : 
   11292              : tree
   11293        18823 : get_cxa_atexit_fn_ptr_type ()
   11294              : {
   11295        18823 :   if (!cleanup_type)
   11296              :     {
   11297        14292 :       tree fntype = build_function_type_list (void_type_node,
   11298              :                                               ptr_type_node, NULL_TREE);
   11299        14292 :       fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
   11300        14292 :       cleanup_type = build_pointer_type (fntype);
   11301              :     }
   11302              : 
   11303        18823 :   return cleanup_type;
   11304              : }
   11305              : 
   11306              : /* Returns a pointer to the `atexit' function.  Note that if
   11307              :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
   11308              :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
   11309              : 
   11310              : static tree
   11311         3317 : get_atexit_node (void)
   11312              : {
   11313         3317 :   tree atexit_fndecl;
   11314         3317 :   tree fn_type;
   11315         3317 :   tree fn_ptr_type;
   11316         3317 :   const char *name;
   11317         3317 :   bool use_aeabi_atexit;
   11318         3317 :   tree ctx = global_namespace;
   11319              : 
   11320         3317 :   if (atexit_node)
   11321              :     return atexit_node;
   11322              : 
   11323         2119 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
   11324              :     {
   11325              :       /* The declaration for `__cxa_atexit' is:
   11326              : 
   11327              :            int __cxa_atexit (void (*)(void *), void *, void *)
   11328              : 
   11329              :          We build up the argument types and then the function type
   11330              :          itself.  */
   11331         2107 :       tree argtype0, argtype1, argtype2;
   11332              : 
   11333         2107 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
   11334              :       /* First, build the pointer-to-function type for the first
   11335              :          argument.  */
   11336         2107 :       fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
   11337              :       /* Then, build the rest of the argument types.  */
   11338         2107 :       argtype2 = ptr_type_node;
   11339         2107 :       if (use_aeabi_atexit)
   11340              :         {
   11341              :           argtype1 = fn_ptr_type;
   11342              :           argtype0 = ptr_type_node;
   11343              :         }
   11344              :       else
   11345              :         {
   11346         2107 :           argtype1 = ptr_type_node;
   11347         2107 :           argtype0 = fn_ptr_type;
   11348              :         }
   11349              :       /* And the final __cxa_atexit type.  */
   11350         2107 :       fn_type = build_function_type_list (integer_type_node,
   11351              :                                           argtype0, argtype1, argtype2,
   11352              :                                           NULL_TREE);
   11353              :       /* ... which needs noexcept.  */
   11354         2107 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11355         2107 :       if (use_aeabi_atexit)
   11356              :         {
   11357            0 :           name = "__aeabi_atexit";
   11358            0 :           push_to_top_level ();
   11359            0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
   11360            0 :           ctx = current_namespace;
   11361            0 :           while (n--)
   11362            0 :             pop_namespace ();
   11363            0 :           pop_from_top_level ();
   11364              :         }
   11365              :       else
   11366              :         {
   11367         2107 :           name = "__cxa_atexit";
   11368         2107 :           ctx = abi_node;
   11369              :         }
   11370              :     }
   11371              :   else
   11372              :     {
   11373              :       /* The declaration for `atexit' is:
   11374              : 
   11375              :            int atexit (void (*)());
   11376              : 
   11377              :          We build up the argument types and then the function type
   11378              :          itself.  */
   11379           12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
   11380              :       /* Build the final atexit type.  */
   11381           12 :       fn_type = build_function_type_list (integer_type_node,
   11382              :                                           fn_ptr_type, NULL_TREE);
   11383              :       /* ... which needs noexcept.  */
   11384           12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
   11385           12 :       name = "atexit";
   11386              :     }
   11387              : 
   11388              :   /* Now, build the function declaration.  */
   11389         2119 :   push_lang_context (lang_name_c);
   11390         2119 :   auto cookie = push_abi_namespace (ctx);
   11391         2119 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
   11392         2119 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11393              :   /* Install as hidden builtin so we're (a) more relaxed about
   11394              :     exception spec matching and (b) will not give a confusing location
   11395              :     in diagnostic and (c) won't magically appear in user-visible name
   11396              :     lookups.  */
   11397         2119 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11398         2119 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11399         2119 :   pop_abi_namespace (cookie, ctx);
   11400         2119 :   mark_used (atexit_fndecl);
   11401         2119 :   pop_lang_context ();
   11402         2119 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11403              : 
   11404         2119 :   return atexit_node;
   11405              : }
   11406              : 
   11407              : /* Like get_atexit_node, but for thread-local cleanups.  */
   11408              : 
   11409              : static tree
   11410           98 : get_thread_atexit_node (void)
   11411              : {
   11412           98 :   if (thread_atexit_node)
   11413              :     return thread_atexit_node;
   11414              : 
   11415              :   /* The declaration for `__cxa_thread_atexit' is:
   11416              : 
   11417              :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
   11418           59 :   tree fn_type = build_function_type_list (integer_type_node,
   11419              :                                            get_cxa_atexit_fn_ptr_type (),
   11420              :                                            ptr_type_node, ptr_type_node,
   11421              :                                            NULL_TREE);
   11422              : 
   11423              :   /* Now, build the function declaration, as with __cxa_atexit.  */
   11424           59 :   unsigned flags = push_abi_namespace ();
   11425           59 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
   11426              :                                              ECF_LEAF | ECF_NOTHROW);
   11427           59 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
   11428           59 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
   11429           59 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
   11430           59 :   pop_abi_namespace (flags);
   11431           59 :   mark_used (atexit_fndecl);
   11432           59 :   thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
   11433              : 
   11434           59 :   return thread_atexit_node;
   11435              : }
   11436              : 
   11437              : /* Returns the __dso_handle VAR_DECL.  */
   11438              : 
   11439              : static tree
   11440         3403 : get_dso_handle_node (void)
   11441              : {
   11442         3403 :   if (dso_handle_node)
   11443              :     return dso_handle_node;
   11444              : 
   11445              :   /* Declare the variable.  */
   11446         2156 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
   11447              :                                         ptr_type_node);
   11448              : 
   11449              : #ifdef HAVE_GAS_HIDDEN
   11450         2156 :   if (dso_handle_node != error_mark_node)
   11451              :     {
   11452         2153 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
   11453         2153 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
   11454              :     }
   11455              : #endif
   11456              : 
   11457         2156 :   return dso_handle_node;
   11458              : }
   11459              : 
   11460              : /* Begin a new function with internal linkage whose job will be simply
   11461              :    to destroy some particular DECL.  OB_PARM is true if object pointer
   11462              :    is passed to the cleanup function, otherwise no argument is passed.  */
   11463              : 
   11464              : static tree
   11465          372 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
   11466              : {
   11467          372 :   push_to_top_level ();
   11468              : 
   11469              :   /* No need to mangle this.  */
   11470          372 :   push_lang_context (lang_name_c);
   11471              : 
   11472              :   /* Build the name of the function.  */
   11473          372 :   gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
   11474          372 :   const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   11475          372 :   dname = targetm.strip_name_encoding (dname);
   11476          741 :   char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
   11477              : 
   11478          372 :   tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
   11479              :                                    : get_atexit_fn_ptr_type ());
   11480              :   /* Build the function declaration.  */
   11481          372 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
   11482          372 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
   11483              :   /* It's a function with internal linkage, generated by the
   11484              :      compiler.  */
   11485          372 :   TREE_PUBLIC (fndecl) = 0;
   11486          372 :   DECL_ARTIFICIAL (fndecl) = 1;
   11487              :   /* Make the function `inline' so that it is only emitted if it is
   11488              :      actually needed.  It is unlikely that it will be inlined, since
   11489              :      it is only called via a function pointer, but we avoid unnecessary
   11490              :      emissions this way.  */
   11491          372 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
   11492          372 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
   11493          372 :   if (ob_parm)
   11494              :     {
   11495              :       /* Build the parameter.  */
   11496          360 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
   11497          360 :       TREE_USED (parmdecl) = 1;
   11498          360 :       DECL_READ_P (parmdecl) = 1;
   11499          360 :       DECL_ARGUMENTS (fndecl) = parmdecl;
   11500              :     }
   11501              : 
   11502          372 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
   11503          372 :   if (omp_target)
   11504              :     {
   11505            3 :       DECL_ATTRIBUTES (fndecl)
   11506            3 :         = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
   11507            3 :                      DECL_ATTRIBUTES (fndecl));
   11508            3 :       DECL_ATTRIBUTES (fndecl)
   11509            6 :         = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
   11510            3 :                      DECL_ATTRIBUTES (fndecl));
   11511              :     }
   11512          372 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
   11513              : 
   11514          372 :   pop_lang_context ();
   11515              : 
   11516          372 :   return current_function_decl;
   11517              : }
   11518              : 
   11519              : /* Finish the cleanup function begun by start_cleanup_fn.  */
   11520              : 
   11521              : static void
   11522          372 : end_cleanup_fn (void)
   11523              : {
   11524          372 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
   11525              : 
   11526          372 :   pop_from_top_level ();
   11527          372 : }
   11528              : 
   11529              : /* Generate code to handle the destruction of DECL, an object with
   11530              :    static storage duration.  */
   11531              : 
   11532              : tree
   11533        14991 : register_dtor_fn (tree decl, bool omp_target)
   11534              : {
   11535        14991 :   tree cleanup;
   11536        14991 :   tree addr;
   11537        14991 :   tree compound_stmt;
   11538        14991 :   tree fcall;
   11539        14991 :   tree type;
   11540        14991 :   bool ob_parm, dso_parm, use_dtor;
   11541        14991 :   tree arg0, arg1, arg2;
   11542        14991 :   tree atex_node;
   11543              : 
   11544        14991 :   type = TREE_TYPE (decl);
   11545        14991 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   11546        11576 :     return void_node;
   11547              : 
   11548         3415 :   if (decl_maybe_constant_destruction (decl, type)
   11549         3415 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   11550              :     {
   11551            0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11552            0 :       return void_node;
   11553              :     }
   11554              : 
   11555              :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
   11556              :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
   11557              :      destructor to "__cxa_atexit"; we don't have to build a temporary
   11558              :      function to do the cleanup.  */
   11559         6830 :   dso_parm = (flag_use_cxa_atexit
   11560         3415 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
   11561         3415 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
   11562         3403 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
   11563         3415 :   if (use_dtor)
   11564              :     {
   11565         3043 :       cleanup = get_class_binding (type, complete_dtor_identifier);
   11566              : 
   11567              :       /* Make sure it is accessible.  */
   11568         3043 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
   11569              :                                      tf_warning_or_error);
   11570              :     }
   11571              :   else
   11572              :     {
   11573              :       /* Call build_cleanup before we enter the anonymous function so
   11574              :          that any access checks will be done relative to the current
   11575              :          scope, rather than the scope of the anonymous function.  */
   11576          372 :       build_cleanup (decl);
   11577              : 
   11578              :       /* Now start the function.  */
   11579          372 :       cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
   11580              : 
   11581              :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
   11582              :          to the original function, rather than the anonymous one.  That
   11583              :          will make the back end think that nested functions are in use,
   11584              :          which causes confusion.  */
   11585          372 :       push_deferring_access_checks (dk_no_check);
   11586          372 :       fcall = build_cleanup (decl);
   11587          372 :       pop_deferring_access_checks ();
   11588              : 
   11589              :       /* Create the body of the anonymous function.  */
   11590          372 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
   11591          372 :       finish_expr_stmt (fcall);
   11592          372 :       finish_compound_stmt (compound_stmt);
   11593          372 :       end_cleanup_fn ();
   11594              :     }
   11595              : 
   11596              :   /* Call atexit with the cleanup function.  */
   11597         3415 :   mark_used (cleanup);
   11598         3415 :   cleanup = build_address (cleanup);
   11599              : 
   11600         3415 :   if (CP_DECL_THREAD_LOCAL_P (decl))
   11601           98 :     atex_node = get_thread_atexit_node ();
   11602              :   else
   11603         3317 :     atex_node = get_atexit_node ();
   11604              : 
   11605         3415 :   if (use_dtor)
   11606              :     {
   11607              :       /* We must convert CLEANUP to the type that "__cxa_atexit"
   11608              :          expects.  */
   11609         3043 :       cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
   11610              :       /* "__cxa_atexit" will pass the address of DECL to the
   11611              :          cleanup function.  */
   11612         3043 :       mark_used (decl);
   11613         3043 :       addr = build_address (decl);
   11614              :       /* The declared type of the parameter to "__cxa_atexit" is
   11615              :          "void *".  For plain "T*", we could just let the
   11616              :          machinery in cp_build_function_call convert it -- but if the
   11617              :          type is "cv-qualified T *", then we need to convert it
   11618              :          before passing it in, to avoid spurious errors.  */
   11619         3043 :       addr = build_nop (ptr_type_node, addr);
   11620              :     }
   11621              :   else
   11622              :     /* Since the cleanup functions we build ignore the address
   11623              :        they're given, there's no reason to pass the actual address
   11624              :        in, and, in general, it's cheaper to pass NULL than any
   11625              :        other value.  */
   11626          372 :     addr = null_pointer_node;
   11627              : 
   11628         3415 :   if (dso_parm)
   11629         3403 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
   11630              :                                tf_warning_or_error);
   11631           12 :   else if (ob_parm)
   11632              :     /* Just pass NULL to the dso handle parm if we don't actually
   11633              :        have a DSO handle on this target.  */
   11634            0 :     arg2 = null_pointer_node;
   11635              :   else
   11636              :     arg2 = NULL_TREE;
   11637              : 
   11638         3403 :   if (ob_parm)
   11639              :     {
   11640         3403 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
   11641         3403 :           && targetm.cxx.use_aeabi_atexit ())
   11642              :         {
   11643              :           arg1 = cleanup;
   11644              :           arg0 = addr;
   11645              :         }
   11646              :       else
   11647              :         {
   11648              :           arg1 = addr;
   11649              :           arg0 = cleanup;
   11650              :         }
   11651              :     }
   11652              :   else
   11653              :     {
   11654              :       arg0 = cleanup;
   11655              :       arg1 = NULL_TREE;
   11656              :     }
   11657         3415 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
   11658         3415 :                                       arg0, arg1, arg2, NULL_TREE);
   11659              : }
   11660              : 
   11661              : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
   11662              :    is its initializer.  Generate code to handle the construction
   11663              :    and destruction of DECL.  */
   11664              : 
   11665              : static void
   11666     28077701 : expand_static_init (tree decl, tree init)
   11667              : {
   11668     28077701 :   gcc_assert (VAR_P (decl));
   11669     28077701 :   gcc_assert (TREE_STATIC (decl));
   11670              : 
   11671              :   /* Some variables require no dynamic initialization.  */
   11672     28077701 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
   11673              :     {
   11674              :       /* Make sure the destructor is callable.  */
   11675     28074318 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
   11676     28074318 :       if (!init)
   11677              :         return;
   11678              :     }
   11679              : 
   11680        15860 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
   11681        14934 :       && !DECL_FUNCTION_SCOPE_P (decl))
   11682              :     {
   11683           15 :       auto_diagnostic_group d;
   11684           15 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
   11685           15 :       if (init)
   11686           12 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11687              :                   "needs dynamic initialization", decl);
   11688              :       else
   11689            3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
   11690              :                   "has a non-trivial destructor", decl);
   11691           15 :       static bool informed;
   11692           15 :       if (!informed)
   11693              :         {
   11694            6 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
   11695              :                   "initialization and destruction");
   11696            6 :           informed = true;
   11697              :         }
   11698           15 :       return;
   11699           15 :     }
   11700              : 
   11701        14890 :   if (DECL_FUNCTION_SCOPE_P (decl))
   11702              :     {
   11703              :       /* Emit code to perform this initialization but once.  */
   11704         3789 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
   11705         3789 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
   11706         3789 :       tree guard, guard_addr;
   11707         3789 :       tree flag, begin;
   11708              :       /* We don't need thread-safety code for thread-local vars.  */
   11709         3789 :       bool thread_guard = (flag_threadsafe_statics
   11710         3789 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
   11711              : 
   11712              :       /* Emit code to perform this initialization but once.  This code
   11713              :          looks like:
   11714              : 
   11715              :            static <type> guard;
   11716              :            if (!__atomic_load (guard.first_byte)) {
   11717              :              if (__cxa_guard_acquire (&guard)) {
   11718              :                bool flag = false;
   11719              :                try {
   11720              :                  // Do initialization.
   11721              :                  flag = true; __cxa_guard_release (&guard);
   11722              :                  // Register variable for destruction at end of program.
   11723              :                } catch {
   11724              :                  if (!flag) __cxa_guard_abort (&guard);
   11725              :                }
   11726              :              }
   11727              :            }
   11728              : 
   11729              :          Note that the `flag' variable is only set to 1 *after* the
   11730              :          initialization is complete.  This ensures that an exception,
   11731              :          thrown during the construction, will cause the variable to
   11732              :          reinitialized when we pass through this code again, as per:
   11733              : 
   11734              :            [stmt.dcl]
   11735              : 
   11736              :            If the initialization exits by throwing an exception, the
   11737              :            initialization is not complete, so it will be tried again
   11738              :            the next time control enters the declaration.
   11739              : 
   11740              :          This process should be thread-safe, too; multiple threads
   11741              :          should not be able to initialize the variable more than
   11742              :          once.  */
   11743              : 
   11744              :       /* Create the guard variable.  */
   11745         3789 :       guard = get_guard (decl);
   11746              : 
   11747              :       /* Begin the conditional initialization.  */
   11748         3789 :       if_stmt = begin_if_stmt ();
   11749              : 
   11750         3789 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
   11751         3789 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11752              : 
   11753         3789 :       if (thread_guard)
   11754              :         {
   11755         3641 :           tree vfntype = NULL_TREE;
   11756         3641 :           tree acquire_name, release_name, abort_name;
   11757         3641 :           tree acquire_fn, release_fn, abort_fn;
   11758         3641 :           guard_addr = build_address (guard);
   11759              : 
   11760         3641 :           acquire_name = get_identifier ("__cxa_guard_acquire");
   11761         3641 :           release_name = get_identifier ("__cxa_guard_release");
   11762         3641 :           abort_name = get_identifier ("__cxa_guard_abort");
   11763         3641 :           acquire_fn = get_global_binding (acquire_name);
   11764         3641 :           release_fn = get_global_binding (release_name);
   11765         3641 :           abort_fn = get_global_binding (abort_name);
   11766         3641 :           if (!acquire_fn)
   11767         2037 :             acquire_fn = push_library_fn
   11768         2037 :               (acquire_name, build_function_type_list (integer_type_node,
   11769         2037 :                                                        TREE_TYPE (guard_addr),
   11770              :                                                        NULL_TREE),
   11771              :                NULL_TREE, ECF_NOTHROW);
   11772         3641 :           if (!release_fn || !abort_fn)
   11773         2040 :             vfntype = build_function_type_list (void_type_node,
   11774         2040 :                                                 TREE_TYPE (guard_addr),
   11775              :                                                 NULL_TREE);
   11776         2040 :           if (!release_fn)
   11777         2040 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
   11778              :                                           ECF_NOTHROW);
   11779         3641 :           if (!abort_fn)
   11780         2040 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
   11781              :                                         ECF_NOTHROW | ECF_LEAF);
   11782              : 
   11783         3641 :           inner_if_stmt = begin_if_stmt ();
   11784         3641 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
   11785              :                                inner_if_stmt);
   11786              : 
   11787         3641 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
   11788         3641 :           begin = get_internal_target_expr (boolean_false_node);
   11789         3641 :           flag = TARGET_EXPR_SLOT (begin);
   11790              : 
   11791         3641 :           TARGET_EXPR_CLEANUP (begin)
   11792         3641 :             = build3 (COND_EXPR, void_type_node, flag,
   11793              :                       void_node,
   11794              :                       build_call_n (abort_fn, 1, guard_addr));
   11795         3641 :           CLEANUP_EH_ONLY (begin) = 1;
   11796              : 
   11797              :           /* Do the initialization itself.  */
   11798         3641 :           init = add_stmt_to_compound (begin, init);
   11799         3641 :           init = add_stmt_to_compound (init,
   11800              :                                        build2 (MODIFY_EXPR, void_type_node,
   11801              :                                                flag, boolean_true_node));
   11802              : 
   11803              :           /* Use atexit to register a function for destroying this static
   11804              :              variable.  Do this before calling __cxa_guard_release.  */
   11805         3641 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   11806              : 
   11807         3641 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
   11808              :                                                            guard_addr));
   11809              :         }
   11810              :       else
   11811              :         {
   11812          148 :           init = add_stmt_to_compound (init, set_guard (guard));
   11813              : 
   11814              :           /* Use atexit to register a function for destroying this static
   11815              :              variable.  */
   11816          148 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
   11817              :         }
   11818              : 
   11819         3789 :       finish_expr_stmt (init);
   11820              : 
   11821         3789 :       if (thread_guard)
   11822              :         {
   11823         3641 :           finish_compound_stmt (inner_then_clause);
   11824         3641 :           finish_then_clause (inner_if_stmt);
   11825         3641 :           finish_if_stmt (inner_if_stmt);
   11826              :         }
   11827              : 
   11828         3789 :       finish_compound_stmt (then_clause);
   11829         3789 :       finish_then_clause (if_stmt);
   11830         3789 :       finish_if_stmt (if_stmt);
   11831              :     }
   11832        11101 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
   11833          795 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
   11834              :   else
   11835        10306 :     static_aggregates = tree_cons (init, decl, static_aggregates);
   11836              : }
   11837              : 
   11838              : 
   11839              : /* Make TYPE a complete type based on INITIAL_VALUE.
   11840              :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
   11841              :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
   11842              :    3 if the initializer list is empty (in pedantic mode). */
   11843              : 
   11844              : int
   11845       600624 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
   11846              : {
   11847       600624 :   int failure;
   11848       600624 :   tree type, elt_type;
   11849              : 
   11850              :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   11851       600594 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
   11852       143490 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
   11853       600956 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
   11854              :     return 1;
   11855              : 
   11856       600621 :   if (initial_value)
   11857              :     {
   11858              :       /* An array of character type can be initialized from a
   11859              :          brace-enclosed string constant so call reshape_init to
   11860              :          remove the optional braces from a braced string literal.  */
   11861       600591 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
   11862       600591 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
   11863        49571 :         initial_value = reshape_init (*ptype, initial_value,
   11864              :                                       tf_warning_or_error);
   11865              : 
   11866              :       /* If any of the elements are parameter packs, we can't actually
   11867              :          complete this type now because the array size is dependent.  */
   11868       600591 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
   11869     47086793 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
   11870     46656739 :           if (PACK_EXPANSION_P (e.value))
   11871              :             return 0;
   11872              :     }
   11873              : 
   11874       600621 :   failure = complete_array_type (ptype, initial_value, do_default);
   11875              : 
   11876              :   /* We can create the array before the element type is complete, which
   11877              :      means that we didn't have these two bits set in the original type
   11878              :      either.  In completing the type, we are expected to propagate these
   11879              :      bits.  See also complete_type which does the same thing for arrays
   11880              :      of fixed size.  */
   11881       600621 :   type = *ptype;
   11882      1201239 :   if (type != error_mark_node && TYPE_DOMAIN (type))
   11883              :     {
   11884       600594 :       elt_type = TREE_TYPE (type);
   11885       600594 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
   11886      1201188 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
   11887       600594 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
   11888              :     }
   11889              : 
   11890              :   return failure;
   11891              : }
   11892              : 
   11893              : /* As above, but either give an error or reject zero-size arrays, depending
   11894              :    on COMPLAIN.  */
   11895              : 
   11896              : int
   11897         1245 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
   11898              :                                  bool do_default, tsubst_flags_t complain)
   11899              : {
   11900         1245 :   int failure;
   11901         1245 :   bool sfinae = !(complain & tf_error);
   11902              :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   11903         1245 :   if (sfinae)
   11904            3 :     ++pedantic;
   11905         1245 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   11906         1245 :   if (sfinae)
   11907            3 :     --pedantic;
   11908         1245 :   if (failure)
   11909              :     {
   11910            3 :       if (sfinae)
   11911              :         /* Not an error.  */;
   11912            0 :       else if (failure == 1)
   11913            0 :         error ("initializer fails to determine size of %qT", *ptype);
   11914            0 :       else if (failure == 2)
   11915              :         {
   11916            0 :           if (do_default)
   11917            0 :             error ("array size missing in %qT", *ptype);
   11918              :         }
   11919            0 :       else if (failure == 3)
   11920            0 :         error ("zero-size array %qT", *ptype);
   11921            3 :       *ptype = error_mark_node;
   11922              :     }
   11923         1245 :   return failure;
   11924              : }
   11925              : 
   11926              : /* Return zero if something is declared to be a member of type
   11927              :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   11928              :    message to print in that case.  Otherwise, quietly return 1.  */
   11929              : 
   11930              : static int
   11931     26131503 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   11932              : {
   11933     26131503 :   if (ctype && ctype != cur_type)
   11934              :     {
   11935            0 :       if (flags == DTOR_FLAG)
   11936            0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   11937              :       else
   11938            0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   11939            0 :       return 0;
   11940              :     }
   11941              :   return 1;
   11942              : }
   11943              : 
   11944              : /* Subroutine of `grokdeclarator'.  */
   11945              : 
   11946              : /* Generate errors possibly applicable for a given set of specifiers.
   11947              :    This is for ARM $7.1.2.  */
   11948              : 
   11949              : static void
   11950    438240758 : bad_specifiers (tree object,
   11951              :                 enum bad_spec_place type,
   11952              :                 int virtualp,
   11953              :                 int quals,
   11954              :                 int inlinep,
   11955              :                 int friendp,
   11956              :                 int raises,
   11957              :                 const location_t* locations)
   11958              : {
   11959    438240758 :   switch (type)
   11960              :     {
   11961     67686100 :       case BSP_VAR:
   11962     67686100 :         if (virtualp)
   11963            0 :           error_at (locations[ds_virtual],
   11964              :                     "%qD declared as a %<virtual%> variable", object);
   11965     67686100 :         if (quals)
   11966            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   11967              :                  "%qD invalid in variable declaration", object);
   11968              :         break;
   11969    291067482 :       case BSP_PARM:
   11970    291067482 :         if (virtualp)
   11971            0 :           error_at (locations[ds_virtual],
   11972              :                     "%qD declared as a %<virtual%> parameter", object);
   11973    291067482 :         if (inlinep)
   11974            6 :           error_at (locations[ds_inline],
   11975              :                     "%qD declared as an %<inline%> parameter", object);
   11976    291067482 :         if (quals)
   11977            3 :           error ("%<const%> and %<volatile%> function specifiers on "
   11978              :                  "%qD invalid in parameter declaration", object);
   11979              :         break;
   11980     46801412 :       case BSP_TYPE:
   11981     46801412 :         if (virtualp)
   11982            0 :           error_at (locations[ds_virtual],
   11983              :                     "%qD declared as a %<virtual%> type", object);
   11984     46801412 :         if (inlinep)
   11985            6 :           error_at (locations[ds_inline],
   11986              :                     "%qD declared as an %<inline%> type", object);
   11987     46801412 :         if (quals)
   11988            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   11989              :                  "%qD invalid in type declaration", object);
   11990              :         break;
   11991     32685764 :       case BSP_FIELD:
   11992     32685764 :         if (virtualp)
   11993            6 :           error_at (locations[ds_virtual],
   11994              :                     "%qD declared as a %<virtual%> field", object);
   11995     32685764 :         if (inlinep)
   11996            6 :           error_at (locations[ds_inline],
   11997              :                     "%qD declared as an %<inline%> field", object);
   11998     32685764 :         if (quals)
   11999            0 :           error ("%<const%> and %<volatile%> function specifiers on "
   12000              :                  "%qD invalid in field declaration", object);
   12001              :         break;
   12002            0 :       default:
   12003            0 :         gcc_unreachable();
   12004              :     }
   12005    438240758 :   if (friendp)
   12006            0 :     error ("%q+D declared as a friend", object);
   12007    438240758 :   if (raises
   12008          127 :       && !flag_noexcept_type
   12009    438240783 :       && (TREE_CODE (object) == TYPE_DECL
   12010           19 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   12011            5 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   12012            4 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   12013            6 :     error ("%q+D declared with an exception specification", object);
   12014    438240758 : }
   12015              : 
   12016              : /* DECL is a member function or static data member and is presently
   12017              :    being defined.  Check that the definition is taking place in a
   12018              :    valid namespace.  */
   12019              : 
   12020              : static void
   12021     96279669 : check_class_member_definition_namespace (tree decl)
   12022              : {
   12023              :   /* These checks only apply to member functions and static data
   12024              :      members.  */
   12025     96279669 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   12026              :   /* We check for problems with specializations in pt.cc in
   12027              :      check_specialization_namespace, where we can issue better
   12028              :      diagnostics.  */
   12029     96279669 :   if (processing_specialization)
   12030              :     return;
   12031              :   /* We check this in check_explicit_instantiation_namespace.  */
   12032     96141088 :   if (processing_explicit_instantiation)
   12033              :     return;
   12034              :   /* [class.mfct]
   12035              : 
   12036              :      A member function definition that appears outside of the
   12037              :      class definition shall appear in a namespace scope enclosing
   12038              :      the class definition.
   12039              : 
   12040              :      [class.static.data]
   12041              : 
   12042              :      The definition for a static data member shall appear in a
   12043              :      namespace scope enclosing the member's class definition.  */
   12044     96141008 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   12045           18 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   12046           18 :                decl, DECL_CONTEXT (decl));
   12047              : }
   12048              : 
   12049              : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   12050              :    METHOD_TYPE for a non-static member function; QUALS are the
   12051              :    cv-qualifiers that apply to the function.  */
   12052              : 
   12053              : tree
   12054    233653841 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   12055              : {
   12056    233653841 :   tree this_type;
   12057    233653841 :   tree qual_type;
   12058    233653841 :   tree parm;
   12059    233653841 :   cp_cv_quals this_quals;
   12060              : 
   12061    233653841 :   if (CLASS_TYPE_P (type))
   12062              :     {
   12063    102299048 :       this_type
   12064    102299048 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   12065    102299048 :       this_type = build_pointer_type (this_type);
   12066              :     }
   12067              :   else
   12068    131354793 :     this_type = type_of_this_parm (type);
   12069              :   /* The `this' parameter is implicitly `const'; it cannot be
   12070              :      assigned to.  */
   12071    233653841 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   12072    233653841 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   12073    233653841 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   12074    233653841 :   cp_apply_type_quals_to_decl (this_quals, parm);
   12075    233653841 :   return parm;
   12076              : }
   12077              : 
   12078              : /* DECL is a static member function.  Complain if it was declared
   12079              :    with function-cv-quals.  */
   12080              : 
   12081              : static void
   12082     10476657 : check_static_quals (tree decl, cp_cv_quals quals)
   12083              : {
   12084            0 :   if (quals != TYPE_UNQUALIFIED)
   12085            6 :     error ("static member function %q#D declared with type qualifiers",
   12086              :            decl);
   12087            0 : }
   12088              : 
   12089              : /* Helper function.  Replace the temporary this parameter injected
   12090              :    during cp_finish_omp_declare_simd with the real this parameter.  */
   12091              : 
   12092              : static tree
   12093         2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   12094              : {
   12095         2692 :   tree this_parm = (tree) data;
   12096         2692 :   if (TREE_CODE (*tp) == PARM_DECL
   12097          450 :       && DECL_NAME (*tp) == this_identifier
   12098         2965 :       && *tp != this_parm)
   12099          273 :     *tp = this_parm;
   12100         2419 :   else if (TYPE_P (*tp))
   12101           33 :     *walk_subtrees = 0;
   12102         2692 :   return NULL_TREE;
   12103              : }
   12104              : 
   12105              : /* CTYPE is class type, or null if non-class.
   12106              :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   12107              :    or METHOD_TYPE.
   12108              :    DECLARATOR is the function's name.
   12109              :    PARMS is a chain of PARM_DECLs for the function.
   12110              :    VIRTUALP is truthvalue of whether the function is virtual or not.
   12111              :    FLAGS are to be passed through to `grokclassfn'.
   12112              :    QUALS are qualifiers indicating whether the function is `const'
   12113              :    or `volatile'.
   12114              :    RAISES is a list of exceptions that this function can raise.
   12115              :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   12116              :    not look, and -1 if we should not call `grokclassfn' at all.
   12117              : 
   12118              :    SFK is the kind of special function (if any) for the new function.
   12119              : 
   12120              :    Returns `NULL_TREE' if something goes wrong, after issuing
   12121              :    applicable error messages.  */
   12122              : 
   12123              : static tree
   12124    186127802 : grokfndecl (tree ctype,
   12125              :             tree type,
   12126              :             tree declarator,
   12127              :             tree parms,
   12128              :             tree orig_declarator,
   12129              :             const cp_decl_specifier_seq *declspecs,
   12130              :             tree decl_reqs,
   12131              :             int virtualp,
   12132              :             enum overload_flags flags,
   12133              :             cp_cv_quals quals,
   12134              :             cp_ref_qualifier rqual,
   12135              :             tree raises,
   12136              :             int check,
   12137              :             int friendp,
   12138              :             int publicp,
   12139              :             int inlinep,
   12140              :             int initialized,
   12141              :             bool xobj_func_p,
   12142              :             special_function_kind sfk,
   12143              :             bool funcdef_flag,
   12144              :             bool late_return_type_p,
   12145              :             int template_count,
   12146              :             tree in_namespace,
   12147              :             tree* attrlist,
   12148              :             tree contract_specifiers,
   12149              :             location_t location)
   12150              : {
   12151    186127802 :   tree decl;
   12152    186127802 :   tree t;
   12153              : 
   12154    186127802 :   if (location == UNKNOWN_LOCATION)
   12155            0 :     location = input_location;
   12156              : 
   12157              :   /* Was the concept specifier present?  */
   12158    186127802 :   bool concept_p = inlinep & 4;
   12159              : 
   12160    186127802 :   if (concept_p)
   12161              :     {
   12162           15 :       error_at (location, "function concepts are no longer supported");
   12163           15 :       return NULL_TREE;
   12164              :     }
   12165              : 
   12166    186127787 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   12167              : 
   12168    186127787 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   12169              : 
   12170              :   /* Set the constraints on the declaration. */
   12171    186127787 :   if (flag_concepts)
   12172              :     {
   12173    181903830 :       tree tmpl_reqs = NULL_TREE;
   12174    181903830 :       tree ctx = friendp ? current_class_type : ctype;
   12175    181903830 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   12176    181903830 :       bool memtmpl = (!block_local
   12177    181903830 :                       && (current_template_depth
   12178    181847686 :                           > template_class_depth (ctx)));
   12179     50136598 :       if (memtmpl)
   12180              :         {
   12181     50136598 :           if (!current_template_parms)
   12182              :             /* If there are no template parameters, something must have
   12183              :                gone wrong.  */
   12184            0 :             gcc_assert (seen_error ());
   12185              :           else
   12186     50136598 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   12187              :         }
   12188    181903830 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   12189              :       /* C++20 CA378: Remove non-templated constrained functions.  */
   12190              :       /* [temp.friend]/9 A non-template friend declaration with a
   12191              :          requires-clause shall be a definition. A friend function template with
   12192              :          a constraint that depends on a template parameter from an enclosing
   12193              :          template shall be a definition. */
   12194    181903830 :       if (ci
   12195      9580424 :           && (block_local
   12196      9580421 :               || !processing_template_decl
   12197      9580360 :               || (friendp && !memtmpl && !funcdef_flag)))
   12198              :         {
   12199           73 :           if (!friendp || !processing_template_decl)
   12200           64 :             error_at (location, "constraints on a non-templated function");
   12201              :           else
   12202            9 :             error_at (location, "constrained non-template friend declaration"
   12203              :                       " must be a definition");
   12204              :           ci = NULL_TREE;
   12205              :         }
   12206    181903830 :       set_constraints (decl, ci);
   12207      1189542 :       if (ci && friendp && memtmpl && !funcdef_flag
   12208    181940028 :           && uses_outer_template_parms_in_constraints (decl, ctx))
   12209            6 :         error_at (location, "friend function template with constraints that "
   12210              :                   "depend on outer template parameters must be a definition");
   12211              :     }
   12212              : 
   12213    186127787 :   if (TREE_CODE (type) == METHOD_TYPE)
   12214              :     {
   12215    100417386 :       tree parm = build_this_parm (decl, type, quals);
   12216    100417386 :       DECL_CHAIN (parm) = parms;
   12217    100417386 :       parms = parm;
   12218              : 
   12219              :       /* Allocate space to hold the vptr bit if needed.  */
   12220    100417386 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   12221              :     }
   12222              : 
   12223    186127787 :   DECL_ARGUMENTS (decl) = parms;
   12224    562184089 :   for (t = parms; t; t = DECL_CHAIN (t))
   12225              :     {
   12226    376056302 :       DECL_CONTEXT (t) = decl;
   12227    376056302 :       if (flag_reflection
   12228      7181648 :           && initialized == SD_INITIALIZED
   12229    377485696 :           && DECL_ATTRIBUTES (t))
   12230         3402 :         for (tree a = DECL_ATTRIBUTES (t);
   12231         3406 :              (a = lookup_annotation (a));
   12232            4 :              a = TREE_CHAIN (a))
   12233              :           {
   12234            4 :             gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
   12235              :             /* Mark TREE_PURPOSE of the value that it is an annotation
   12236              :                on an argument of a function definition (rather than
   12237              :                annotation from function declaration).  For function parameter
   12238              :                reflection all annotations are listed, while for variable_of
   12239              :                only those marked here.  Annotation is marked as coming from
   12240              :                function definition's argument if it has TREE_PURPOSE
   12241              :                void_node or INTEGER_CST with signed type.  */
   12242            4 :             tree val = TREE_VALUE (a);
   12243            4 :             gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
   12244            4 :             TREE_PURPOSE (val) = void_node;
   12245              :           }
   12246              :     }
   12247              : 
   12248              :   /* Propagate volatile out from type to decl.  */
   12249    186127787 :   if (TYPE_VOLATILE (type))
   12250            0 :     TREE_THIS_VOLATILE (decl) = 1;
   12251              : 
   12252              :   /* Setup decl according to sfk.  */
   12253    186127787 :   switch (sfk)
   12254              :     {
   12255     23862703 :     case sfk_constructor:
   12256     23862703 :     case sfk_copy_constructor:
   12257     23862703 :     case sfk_move_constructor:
   12258     23862703 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   12259     23862703 :       DECL_NAME (decl) = ctor_identifier;
   12260     23862703 :       break;
   12261      3212006 :     case sfk_destructor:
   12262      3212006 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   12263      3212006 :       DECL_NAME (decl) = dtor_identifier;
   12264      3212006 :       break;
   12265      1186898 :     case sfk_deduction_guide:
   12266              :       /* Give deduction guides a definition even though they don't really
   12267              :          have one: the restriction that you can't repeat a deduction guide
   12268              :          makes them more like a definition anyway.  */
   12269      1186898 :       DECL_INITIAL (decl) = void_node;
   12270              :       /* But to ensure that external-linkage deduction guides in header units
   12271              :          don't fall afoul of [module.import] p6, mark them as inline.  */
   12272      1186898 :       DECL_DECLARED_INLINE_P (decl) = true;
   12273      1186898 :       break;
   12274              :     default:
   12275              :       break;
   12276              :     }
   12277              : 
   12278    186127787 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   12279              :     {
   12280        93284 :       if (funcdef_flag)
   12281            3 :         error_at (location,
   12282              :                   "defining explicit specialization %qD in friend declaration",
   12283              :                   orig_declarator);
   12284              :       else
   12285              :         {
   12286        93281 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   12287        93281 :           tree args = TREE_OPERAND (orig_declarator, 1);
   12288              : 
   12289        93281 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   12290              :             {
   12291              :               /* Something like `template <class T> friend void f<T>()'.  */
   12292            6 :               error_at (location,
   12293              :                         "invalid use of template-id %qD in declaration "
   12294              :                         "of primary template",
   12295              :                         orig_declarator);
   12296            6 :               return NULL_TREE;
   12297              :             }
   12298              : 
   12299              :           /* A friend declaration of the form friend void f<>().  Record
   12300              :              the information in the TEMPLATE_ID_EXPR.  */
   12301        93275 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   12302              : 
   12303        93275 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   12304        93275 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   12305              : 
   12306              :           /* Remember the befriending class like push_template_decl does for
   12307              :              template friends.  */
   12308        93275 :           gcc_checking_assert (!DECL_CHAIN (decl));
   12309        93275 :           DECL_CHAIN (decl) = current_scope ();
   12310              : 
   12311       301421 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   12312       208151 :             if (TREE_PURPOSE (t)
   12313       208151 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   12314              :             {
   12315            5 :               error_at (defparse_location (TREE_PURPOSE (t)),
   12316              :                         "default arguments are not allowed in declaration "
   12317              :                         "of friend template specialization %qD",
   12318              :                         decl);
   12319            5 :               return NULL_TREE;
   12320              :             }
   12321              : 
   12322        93270 :           if (inlinep & 1)
   12323              :             {
   12324            5 :               error_at (declspecs->locations[ds_inline],
   12325              :                         "%<inline%> is not allowed in declaration of friend "
   12326              :                         "template specialization %qD",
   12327              :                         decl);
   12328            5 :               return NULL_TREE;
   12329              :             }
   12330              :         }
   12331              :     }
   12332              : 
   12333              :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   12334              :      expression, that declaration shall be a definition..."  */
   12335    186127771 :   if (friendp && !funcdef_flag)
   12336              :     {
   12337      1807412 :       bool has_errored = false;
   12338      1807412 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   12339      5078328 :            t && t != void_list_node; t = TREE_CHAIN (t))
   12340      3270916 :         if (TREE_PURPOSE (t))
   12341              :           {
   12342           51 :             enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
   12343              :             /* For templates, mark the default argument as erroneous and give a
   12344              :                hard error.  */
   12345           51 :             if (processing_template_decl)
   12346              :               {
   12347           33 :                 diag_kind = diagnostics::kind::error;
   12348           33 :                 TREE_PURPOSE (t) = error_mark_node;
   12349              :               }
   12350           51 :             if (!has_errored)
   12351              :               {
   12352           48 :                 has_errored = true;
   12353           48 :                 emit_diagnostic (diag_kind,
   12354           48 :                                  DECL_SOURCE_LOCATION (decl),
   12355           48 :                                  /*diagnostics::option_id=*/0,
   12356              :                                  "friend declaration of %qD specifies default "
   12357              :                                  "arguments and isn%'t a definition", decl);
   12358              :               }
   12359              :           }
   12360              :     }
   12361              : 
   12362              :   /* If this decl has namespace scope, set that up.  */
   12363    186127771 :   if (in_namespace)
   12364       239938 :     set_decl_namespace (decl, in_namespace, friendp);
   12365    185887833 :   else if (ctype)
   12366    110804781 :     DECL_CONTEXT (decl) = ctype;
   12367              :   else
   12368     75083052 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   12369              : 
   12370              :   /* `main' and builtins have implicit 'C' linkage.  */
   12371    186127771 :   if (ctype == NULL_TREE
   12372     75322990 :       && DECL_FILE_SCOPE_P (decl)
   12373     31172309 :       && current_lang_name == lang_name_cplusplus
   12374    189084185 :       && (MAIN_NAME_P (declarator)
   12375      2922688 :           || (IDENTIFIER_LENGTH (declarator) > 10
   12376      2098669 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   12377      1631108 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   12378       338933 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   12379              :                              "builtin_"))
   12380      2922670 :           || (targetcm.cxx_implicit_extern_c
   12381            0 :               && (targetcm.cxx_implicit_extern_c
   12382            0 :                   (IDENTIFIER_POINTER (declarator))))))
   12383        33744 :     SET_DECL_LANGUAGE (decl, lang_c);
   12384              : 
   12385    186127771 :   DECL_STATIC_FUNCTION_P (decl)
   12386    186127771 :     = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
   12387    186127771 :   DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
   12388              : 
   12389    186127771 :   if (initialized == SD_DELETED)
   12390      4142599 :     DECL_DELETED_FN (decl) = 1;
   12391              : 
   12392    186127771 :   if (ctype && funcdef_flag)
   12393     95788105 :     check_class_member_definition_namespace (decl);
   12394              : 
   12395    186127771 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12396              :     {
   12397        33732 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   12398            9 :         error_at (location, "cannot declare %<::main%> to be a template");
   12399        33732 :       if (inlinep & 1)
   12400            3 :         error_at (declspecs->locations[ds_inline],
   12401              :                   "cannot declare %<::main%> to be inline");
   12402        33732 :       if (inlinep & 2)
   12403            6 :         error_at (declspecs->locations[ds_constexpr],
   12404              :                   "cannot declare %<::main%> to be %qs", "constexpr");
   12405        33732 :       if (inlinep & 8)
   12406            3 :         error_at (declspecs->locations[ds_consteval],
   12407              :                   "cannot declare %<::main%> to be %qs", "consteval");
   12408        33732 :       if (!publicp)
   12409            0 :         error_at (location, "cannot declare %<::main%> to be static");
   12410        33732 :       if (current_lang_name != lang_name_cplusplus)
   12411           12 :         pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
   12412              :                  " linkage specification other than %<extern \"C++\"%>");
   12413        33732 :       if (module_attach_p ())
   12414              :         {
   12415            3 :           auto_diagnostic_group adg;
   12416            3 :           error_at (location, "cannot attach %<::main%> to a named module");
   12417            3 :           inform (location, "use %<extern \"C++\"%> to attach it to the "
   12418              :                   "global module instead");
   12419            3 :         }
   12420              :       inlinep = 0;
   12421              :       publicp = 1;
   12422              :     }
   12423              : 
   12424              :   /* Members of anonymous types and local classes have no linkage; make
   12425              :      them internal.  If a typedef is made later, this will be changed.  */
   12426    186127771 :   if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
   12427              :     publicp = 0;
   12428    186114015 :   else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
   12429              :     /* But members of local classes in a module CMI should have their
   12430              :        definitions exported, in case they are (directly or indirectly)
   12431              :        used by an importer.  We don't just use module_has_cmi_p here
   12432              :        because for entities in the GMF we don't yet know whether this
   12433              :        module will have a CMI, so we'll conservatively assume it might.  */
   12434      2181779 :     publicp = module_maybe_has_cmi_p ();
   12435              : 
   12436    186114015 :   if (publicp && cxx_dialect == cxx98)
   12437              :     {
   12438              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12439              :          or enumeration declared in a local scope) shall not be used to
   12440              :          declare an entity with linkage.
   12441              : 
   12442              :          DR 757 relaxes this restriction for C++0x.  */
   12443      1039395 :       no_linkage_error (decl);
   12444              :     }
   12445              : 
   12446    186127771 :   TREE_PUBLIC (decl) = publicp;
   12447    186127771 :   if (! publicp)
   12448              :     {
   12449      2296791 :       DECL_INTERFACE_KNOWN (decl) = 1;
   12450      2296791 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   12451              :     }
   12452              : 
   12453              :   /* If the declaration was declared inline, mark it as such.  */
   12454    186127771 :   if (inlinep)
   12455              :     {
   12456     71165411 :       DECL_DECLARED_INLINE_P (decl) = 1;
   12457     71165411 :       if (publicp)
   12458     70919213 :         DECL_COMDAT (decl) = 1;
   12459              :     }
   12460     71165411 :   if (inlinep & 2)
   12461     52296891 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12462    133830880 :   else if (inlinep & 8)
   12463              :     {
   12464      1081581 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   12465      1081581 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   12466              :     }
   12467              : 
   12468    186127771 :   DECL_EXTERNAL (decl) = 1;
   12469    186127771 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   12470              :     {
   12471     85710385 :       if (quals || rqual)
   12472          393 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   12473              :                                               TYPE_UNQUALIFIED,
   12474              :                                               REF_QUAL_NONE);
   12475     85710385 :       auto_diagnostic_group d;
   12476     85710385 :       if (quals)
   12477          621 :         error (!ctype
   12478              :                ? G_("non-member function %qD cannot have cv-qualifier")
   12479              :                : !xobj_func_p
   12480          297 :                  ? G_("static member function %qD cannot have cv-qualifier")
   12481              :                  : G_("explicit object member function "
   12482              :                       "%qD cannot have cv-qualifier"),
   12483              :                decl);
   12484     85710385 :       if (rqual)
   12485          531 :         error (!ctype
   12486              :                ? G_("non-member function %qD cannot have ref-qualifier")
   12487              :                : !xobj_func_p
   12488          264 :                  ? G_("static member function %qD cannot have ref-qualifier")
   12489              :                  : G_("explicit object member function "
   12490              :                       "%qD cannot have ref-qualifier"),
   12491              :                  decl);
   12492              : 
   12493     85710385 :       if (xobj_func_p && (quals || rqual))
   12494          363 :         inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
   12495              :                 "explicit object parameter declared here");
   12496     85710385 :       quals = TYPE_UNQUALIFIED;
   12497     85710385 :       rqual = REF_QUAL_NONE;
   12498              : 
   12499     85710385 :     }
   12500              : 
   12501    186127771 :   if (deduction_guide_p (decl))
   12502              :     {
   12503      1186898 :       tree type = TREE_TYPE (DECL_NAME (decl));
   12504      1186898 :       if (in_namespace == NULL_TREE
   12505      1186898 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   12506              :         {
   12507            3 :           auto_diagnostic_group d;
   12508            3 :           error_at (location, "deduction guide %qD must be declared in the "
   12509              :                               "same scope as %qT", decl, type);
   12510            3 :           inform (location_of (type), "  declared here");
   12511            3 :           return NULL_TREE;
   12512            3 :         }
   12513      2373790 :       if (DECL_CLASS_SCOPE_P (decl)
   12514      1186936 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   12515              :         {
   12516            3 :           auto_diagnostic_group d;
   12517            3 :           error_at (location, "deduction guide %qD must have the same access "
   12518              :                               "as %qT", decl, type);
   12519            3 :           inform (location_of (type), "  declared here");
   12520            3 :         }
   12521      1186895 :       if (funcdef_flag)
   12522            3 :         error_at (location,
   12523              :                   "deduction guide %qD must not have a function body", decl);
   12524              :     }
   12525    345005397 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   12526    196646492 :            && !grok_op_properties (decl, /*complain=*/true))
   12527              :     return NULL_TREE;
   12528    184940726 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   12529              :     {
   12530       303386 :       bool long_long_unsigned_p;
   12531       303386 :       bool long_double_p;
   12532       303386 :       const char *suffix = NULL;
   12533              :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   12534       303386 :       if (DECL_LANGUAGE (decl) == lang_c)
   12535              :         {
   12536            6 :           auto_diagnostic_group d;
   12537            6 :           error_at (location, "literal operator with C linkage");
   12538            6 :           maybe_show_extern_c_location ();
   12539            6 :           return NULL_TREE;
   12540            6 :         }
   12541              : 
   12542       303380 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   12543              :         {
   12544       303374 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   12545              :                                             &long_double_p))
   12546              :             {
   12547           42 :               error_at (location, "%qD has invalid argument list", decl);
   12548           42 :               return NULL_TREE;
   12549              :             }
   12550              : 
   12551       303332 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   12552       303332 :           if (long_long_unsigned_p)
   12553              :             {
   12554        45294 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   12555           68 :                 warning_at (location, 0, "integer suffix %qs"
   12556              :                             " shadowed by implementation", suffix);
   12557              :             }
   12558       258038 :           else if (long_double_p)
   12559              :             {
   12560        82997 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   12561           80 :                 warning_at (location, 0, "floating-point suffix %qs"
   12562              :                             " shadowed by implementation", suffix);
   12563              :             }
   12564              :           /* 17.6.3.3.5  */
   12565       303332 :           if (suffix[0] != '_'
   12566       302728 :               && !current_function_decl && !(friendp && !funcdef_flag))
   12567       302722 :             warning_at (location, OPT_Wliteral_suffix,
   12568              :                         "literal operator suffixes not preceded by %<_%>"
   12569              :                         " are reserved for future standardization");
   12570              :         }
   12571              :       else
   12572              :         {
   12573            6 :           error_at (location, "%qD must be a non-member function", decl);
   12574            6 :           return NULL_TREE;
   12575              :         }
   12576              :     }
   12577              : 
   12578    184940675 :   if (funcdef_flag)
   12579              :     /* Make the init_value nonzero so pushdecl knows this is not
   12580              :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   12581    131120758 :     DECL_INITIAL (decl) = error_mark_node;
   12582              : 
   12583    186127567 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   12584     70640802 :     TREE_NOTHROW (decl) = 1;
   12585              : 
   12586    186127567 :   if (flag_openmp || flag_openmp_simd)
   12587              :     {
   12588              :       /* Adjust "omp declare simd" attributes.  */
   12589       475901 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   12590       475901 :       if (ods)
   12591              :         {
   12592              :           tree attr;
   12593         2033 :           for (attr = ods; attr;
   12594         1078 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   12595              :             {
   12596         1078 :               if (TREE_CODE (type) == METHOD_TYPE)
   12597          204 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   12598              :                            DECL_ARGUMENTS (decl), NULL);
   12599         1078 :               if (TREE_VALUE (attr) != NULL_TREE)
   12600              :                 {
   12601          872 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   12602          872 :                   cl = c_omp_declare_simd_clauses_to_numbers
   12603          872 :                                                 (DECL_ARGUMENTS (decl), cl);
   12604          872 :                   if (cl)
   12605          872 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   12606              :                   else
   12607            0 :                     TREE_VALUE (attr) = NULL_TREE;
   12608              :                 }
   12609              :             }
   12610              :         }
   12611              :     }
   12612              : 
   12613              :   /* Caller will do the rest of this.  */
   12614    186127567 :   if (check < 0)
   12615              :     {
   12616      6351572 :       if (decl && decl != error_mark_node && contract_specifiers)
   12617           24 :         set_fn_contract_specifiers (decl, contract_specifiers);
   12618      6351572 :       return decl;
   12619              :     }
   12620              : 
   12621    179775995 :   if (ctype != NULL_TREE)
   12622    110804474 :     grokclassfn (ctype, decl, flags);
   12623              : 
   12624              :   /* 12.4/3  */
   12625    179775995 :   if (cxx_dialect >= cxx11
   12626    357488878 :       && DECL_DESTRUCTOR_P (decl)
   12627      3193274 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   12628    179937806 :       && !processing_template_decl)
   12629        82828 :     deduce_noexcept_on_destructor (decl);
   12630              : 
   12631    179775995 :   set_originating_module (decl);
   12632              : 
   12633    179775995 :   decl = check_explicit_specialization (orig_declarator, decl,
   12634              :                                         template_count,
   12635    179775995 :                                         2 * funcdef_flag +
   12636    179775995 :                                         4 * (friendp != 0),
   12637              :                                         *attrlist);
   12638    179775995 :   if (decl == error_mark_node)
   12639              :     return NULL_TREE;
   12640              : 
   12641    179775721 :   if (DECL_STATIC_FUNCTION_P (decl))
   12642     10304900 :     check_static_quals (decl, quals);
   12643              : 
   12644    179775721 :   if (attrlist)
   12645              :     {
   12646    179775721 :       cplus_decl_attributes (&decl, *attrlist, 0);
   12647    179775721 :       *attrlist = NULL_TREE;
   12648              :     }
   12649              : 
   12650              :   /* Update now we have a decl and maybe know the return type.  */
   12651    179775721 :   if (contract_specifiers)
   12652              :     {
   12653          852 :       tree t = decl;
   12654          852 :       if (TREE_CODE (decl) == TEMPLATE_DECL)
   12655            3 :         t = DECL_TEMPLATE_RESULT (decl);
   12656          852 :       set_fn_contract_specifiers (t, contract_specifiers);
   12657          852 :       rebuild_postconditions (t);
   12658              :     }
   12659              : 
   12660              :   /* Check main's type after attributes have been applied.  */
   12661    179775721 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   12662              :     {
   12663        33720 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   12664              :                         integer_type_node))
   12665              :         {
   12666           20 :           tree dtype = TREE_TYPE (decl);
   12667           20 :           tree oldtypeargs = TYPE_ARG_TYPES (dtype);
   12668           20 :           tree newtype;
   12669           20 :           error_at (declspecs->locations[ds_type_spec],
   12670              :                     "%<::main%> must return %<int%>");
   12671           60 :           newtype = build_function_type (integer_type_node, oldtypeargs,
   12672           20 :                                          TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
   12673           20 :           TREE_TYPE (decl) = newtype;
   12674              :         }
   12675        33720 :       if (warn_main)
   12676        33698 :         check_main_parameter_types (decl);
   12677              :     }
   12678              : 
   12679    179775721 :   if (ctype != NULL_TREE && check)
   12680              :     {
   12681      8834386 :       tree old_decl = check_classfn (ctype, decl,
   12682      8834386 :                                      (current_template_depth
   12683      8834386 :                                       > template_class_depth (ctype))
   12684      2139716 :                                      ? current_template_parms
   12685              :                                      : NULL_TREE);
   12686              : 
   12687      8834386 :       if (old_decl == error_mark_node)
   12688              :         return NULL_TREE;
   12689              : 
   12690      8834278 :       if (old_decl)
   12691              :         {
   12692      8449034 :           tree ok;
   12693      8449034 :           tree pushed_scope;
   12694              : 
   12695      8449034 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   12696              :             /* Because grokfndecl is always supposed to return a
   12697              :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   12698              :                here.  We depend on our callers to figure out that its
   12699              :                really a template that's being returned.  */
   12700      2139704 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   12701              : 
   12702      8449034 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   12703      8449034 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   12704              :             {
   12705              :               /* Remove the `this' parm added by grokclassfn.  */
   12706       171757 :               revert_static_member_fn (decl);
   12707       171757 :               check_static_quals (decl, quals);
   12708              :             }
   12709      8449034 :           if (DECL_ARTIFICIAL (old_decl))
   12710              :             {
   12711            9 :               error ("definition of implicitly-declared %qD", old_decl);
   12712            9 :               return NULL_TREE;
   12713              :             }
   12714      8449025 :           else if (DECL_DEFAULTED_FN (old_decl))
   12715              :             {
   12716            3 :               auto_diagnostic_group d;
   12717            3 :               error ("definition of explicitly-defaulted %q+D", decl);
   12718            3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   12719              :                       "%q#D explicitly defaulted here", old_decl);
   12720            3 :               return NULL_TREE;
   12721            3 :             }
   12722              : 
   12723      8449022 :           if (modules_p () && !module_may_redeclare (old_decl))
   12724              :             return NULL_TREE;
   12725              : 
   12726              :           /* Since we've smashed OLD_DECL to its
   12727              :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   12728      8448962 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   12729         1005 :             decl = DECL_TEMPLATE_RESULT (decl);
   12730              : 
   12731              :           /* Attempt to merge the declarations.  This can fail, in
   12732              :              the case of some invalid specialization declarations.  */
   12733      8448962 :           pushed_scope = push_scope (ctype);
   12734      8448962 :           ok = duplicate_decls (decl, old_decl);
   12735      8448962 :           if (pushed_scope)
   12736      8448962 :             pop_scope (pushed_scope);
   12737      8448962 :           if (!ok)
   12738              :             {
   12739            0 :               error ("no %q#D member function declared in class %qT",
   12740              :                      decl, ctype);
   12741            0 :               return NULL_TREE;
   12742              :             }
   12743      8448962 :           if (ok == error_mark_node)
   12744              :             return NULL_TREE;
   12745              :           return old_decl;
   12746              :         }
   12747              :     }
   12748              : 
   12749    342653158 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   12750              :     return NULL_TREE;
   12751              : 
   12752              :   /* Don't call check_consteval_only_fn for defaulted functions.  Those are
   12753              :      immediate-escalating functions but at this point DECL_DEFAULTED_P has
   12754              :      not been set.  */
   12755    171326576 :   if (initialized != SD_DEFAULTED)
   12756    164806922 :     check_consteval_only_fn (decl);
   12757              : 
   12758    171326576 :   if (ctype == NULL_TREE || check)
   12759     69356560 :     return decl;
   12760              : 
   12761    101970016 :   if (virtualp)
   12762      4061157 :     DECL_VIRTUAL_P (decl) = 1;
   12763              : 
   12764    101970016 :   return decl;
   12765              : }
   12766              : 
   12767              : /* decl is a FUNCTION_DECL.
   12768              :    specifiers are the parsed virt-specifiers.
   12769              : 
   12770              :    Set flags to reflect the virt-specifiers.
   12771              : 
   12772              :    Returns decl.  */
   12773              : 
   12774              : static tree
   12775    108321685 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   12776              : {
   12777    108321685 :   if (decl == NULL_TREE)
   12778              :     return decl;
   12779    108321588 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   12780       321567 :     DECL_OVERRIDE_P (decl) = 1;
   12781    108321588 :   if (specifiers & VIRT_SPEC_FINAL)
   12782         9602 :     DECL_FINAL_P (decl) = 1;
   12783              :   return decl;
   12784              : }
   12785              : 
   12786              : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   12787              :    the linkage that DECL will receive in the object file.  */
   12788              : 
   12789              : static void
   12790     13451329 : set_linkage_for_static_data_member (tree decl)
   12791              : {
   12792              :   /* A static data member always has static storage duration and
   12793              :      external linkage.  Note that static data members are forbidden in
   12794              :      local classes -- the only situation in which a class has
   12795              :      non-external linkage.  */
   12796     13451329 :   TREE_PUBLIC (decl) = 1;
   12797     13451329 :   TREE_STATIC (decl) = 1;
   12798              :   /* For non-template classes, static data members are always put
   12799              :      out in exactly those files where they are defined, just as
   12800              :      with ordinary namespace-scope variables.  */
   12801     13451329 :   if (!processing_template_decl)
   12802     10279354 :     DECL_INTERFACE_KNOWN (decl) = 1;
   12803     13451329 : }
   12804              : 
   12805              : /* Create a VAR_DECL named NAME with the indicated TYPE.
   12806              : 
   12807              :    If SCOPE is non-NULL, it is the class type or namespace containing
   12808              :    the variable.  If SCOPE is NULL, the variable should is created in
   12809              :    the innermost enclosing scope.  */
   12810              : 
   12811              : static tree
   12812     67686192 : grokvardecl (tree type,
   12813              :              tree name,
   12814              :              tree orig_declarator,
   12815              :              const cp_decl_specifier_seq *declspecs,
   12816              :              int initialized,
   12817              :              int type_quals,
   12818              :              int inlinep,
   12819              :              bool conceptp,
   12820              :              int template_count,
   12821              :              tree scope,
   12822              :              location_t location)
   12823              : {
   12824     67686192 :   tree decl;
   12825     67686192 :   tree explicit_scope;
   12826              : 
   12827     67686192 :   gcc_assert (!name || identifier_p (name));
   12828              : 
   12829     67686192 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   12830     67686192 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   12831              : 
   12832              :   /* Compute the scope in which to place the variable, but remember
   12833              :      whether or not that scope was explicitly specified by the user.   */
   12834     67686192 :   explicit_scope = scope;
   12835     67686192 :   if (!scope)
   12836              :     {
   12837              :       /* An explicit "extern" specifier indicates a namespace-scope
   12838              :          variable.  */
   12839     67179382 :       if (declspecs->storage_class == sc_extern)
   12840       545846 :         scope = current_decl_namespace ();
   12841     66633536 :       else if (!at_function_scope_p ())
   12842      7044901 :         scope = current_scope ();
   12843              :     }
   12844              : 
   12845     67179382 :   if (scope
   12846      8097557 :       && (/* If the variable is a namespace-scope variable declared in a
   12847              :              template, we need DECL_LANG_SPECIFIC.  */
   12848      8097557 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   12849              :           /* Similarly for namespace-scope variables with language linkage
   12850              :              other than C++.  */
   12851      7605993 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   12852      4374536 :               && current_lang_name != lang_name_cplusplus)
   12853              :           /* Similarly for static data members.  */
   12854      4637248 :           || TYPE_P (scope)
   12855              :           /* Similarly for explicit specializations.  */
   12856      4145684 :           || (orig_declarator
   12857      4144845 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   12858      4806100 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   12859              :   else
   12860     62880092 :     decl = build_decl (location, VAR_DECL, name, type);
   12861              : 
   12862     67686192 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   12863        15246 :     set_decl_namespace (decl, explicit_scope, 0);
   12864              :   else
   12865     67670946 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   12866              : 
   12867     67686192 :   if (declspecs->storage_class == sc_extern)
   12868              :     {
   12869       545846 :       DECL_THIS_EXTERN (decl) = 1;
   12870       545846 :       DECL_EXTERNAL (decl) = !initialized;
   12871              :     }
   12872              : 
   12873     67686192 :   if (DECL_CLASS_SCOPE_P (decl))
   12874              :     {
   12875       491564 :       set_linkage_for_static_data_member (decl);
   12876              :       /* This function is only called with out-of-class definitions.  */
   12877       491564 :       DECL_EXTERNAL (decl) = 0;
   12878       491564 :       check_class_member_definition_namespace (decl);
   12879              :     }
   12880              :   /* At top level, either `static' or no s.c. makes a definition
   12881              :      (perhaps tentative), and absence of `static' makes it public.  */
   12882     67194628 :   else if (toplevel_bindings_p ())
   12883              :     {
   12884     15209656 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   12885      7604828 :                             && (DECL_THIS_EXTERN (decl)
   12886      7020997 :                                 || ! constp
   12887      7020997 :                                 || volatilep
   12888      6942878 :                                 || inlinep
   12889       535544 :                                 || in_template_context
   12890        29955 :                                 || processing_specialization
   12891        29886 :                                 || module_attach_p ()));
   12892      7604828 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   12893              :     }
   12894              :   /* Not at top level, only `static' makes a static definition.  */
   12895              :   else
   12896              :     {
   12897     59589800 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   12898     59589800 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   12899              :     }
   12900              : 
   12901     67686192 :   set_originating_module (decl);
   12902              : 
   12903     67686192 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   12904              :     {
   12905        19405 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   12906              :         {
   12907        19397 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   12908              :           // NB: Set a tentative TLS model to avoid tls_model attribute
   12909              :           // warnings due to lack of thread storage duration.  It will
   12910              :           // be updated by cplus_decl_attributes later.
   12911        19397 :           if (!processing_template_decl)
   12912        19272 :             set_decl_tls_model (decl, TLS_MODEL_REAL);
   12913              :         }
   12914        19405 :       if (declspecs->gnu_thread_keyword_p)
   12915        18398 :         SET_DECL_GNU_TLS_P (decl);
   12916              :     }
   12917              : 
   12918              :   /* If the type of the decl has no linkage, make sure that we'll
   12919              :      notice that in mark_used.  */
   12920     67686192 :   if (cxx_dialect > cxx98
   12921     67414718 :       && decl_linkage (decl) != lk_none
   12922     66733372 :       && DECL_LANG_SPECIFIC (decl) == NULL
   12923     61847167 :       && !DECL_EXTERN_C_P (decl)
   12924    129533359 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   12925         4318 :     retrofit_lang_decl (decl);
   12926              : 
   12927     67686192 :   if (TREE_PUBLIC (decl))
   12928              :     {
   12929              :       /* [basic.link]: A name with no linkage (notably, the name of a class
   12930              :          or enumeration declared in a local scope) shall not be used to
   12931              :          declare an entity with linkage.
   12932              : 
   12933              :          DR 757 relaxes this restriction for C++0x.  */
   12934      8028529 :       if (cxx_dialect < cxx11)
   12935        21363 :         no_linkage_error (decl);
   12936              :     }
   12937              :   else
   12938     59657663 :     DECL_INTERFACE_KNOWN (decl) = 1;
   12939              : 
   12940     67686192 :   if (DECL_NAME (decl)
   12941     67686192 :       && MAIN_NAME_P (DECL_NAME (decl)))
   12942              :     {
   12943           12 :       if (scope == global_namespace)
   12944            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   12945              :                   "cannot declare %<::main%> to be a global variable");
   12946            6 :       else if (DECL_EXTERN_C_P (decl))
   12947            3 :         error_at (DECL_SOURCE_LOCATION (decl),
   12948              :                   "an entity named %<main%> cannot be declared with "
   12949              :                   "C language linkage");
   12950              :     }
   12951              : 
   12952              :   /* Check if a variable is being declared as a concept.  */
   12953     67686192 :   if (conceptp)
   12954              :     {
   12955           30 :       if (!processing_template_decl)
   12956           13 :         error_at (declspecs->locations[ds_concept],
   12957              :                   "a non-template variable cannot be %<concept%>");
   12958           17 :       else if (!at_namespace_scope_p ())
   12959            2 :         error_at (declspecs->locations[ds_concept],
   12960              :                   "concept must be defined at namespace scope");
   12961              :       else
   12962           15 :         error_at (declspecs->locations[ds_concept],
   12963              :                   "variable concepts are no longer supported");
   12964           30 :       return NULL_TREE;
   12965              :     }
   12966     67686162 :   else if (flag_concepts
   12967     67686162 :            && current_template_depth > template_class_depth (scope))
   12968              :     {
   12969     58238346 :       tree ci = current_template_constraints ();
   12970     58238346 :       set_constraints (decl, ci);
   12971              :     }
   12972              : 
   12973              :   // Handle explicit specializations and instantiations of variable templates.
   12974     67686162 :   if (orig_declarator)
   12975     66997165 :     decl = check_explicit_specialization (orig_declarator, decl,
   12976              :                                           template_count, 0);
   12977              : 
   12978     67686162 :   return decl != error_mark_node ? decl : NULL_TREE;
   12979              : }
   12980              : 
   12981              : /* Create and return a canonical pointer to member function type, for
   12982              :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   12983              : 
   12984              : tree
   12985      3121324 : build_ptrmemfunc_type (tree type)
   12986              : {
   12987      3121324 :   tree field, fields;
   12988      3121324 :   tree t;
   12989              : 
   12990      3121324 :   if (type == error_mark_node)
   12991              :     return type;
   12992              : 
   12993              :   /* Make sure that we always have the unqualified pointer-to-member
   12994              :      type first.  */
   12995      3121324 :   if (cp_cv_quals quals = cp_type_quals (type))
   12996              :     {
   12997            0 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   12998            0 :       return cp_build_qualified_type (unqual, quals);
   12999              :     }
   13000              : 
   13001              :   /* If a canonical type already exists for this type, use it.  We use
   13002              :      this method instead of type_hash_canon, because it only does a
   13003              :      simple equality check on the list of field members.  */
   13004              : 
   13005      3121324 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   13006      3121324 :   if (t)
   13007              :     return t;
   13008              : 
   13009      1033910 :   t = make_node (RECORD_TYPE);
   13010              : 
   13011              :   /* Let the front end know this is a pointer to member function.  */
   13012      1033910 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   13013              : 
   13014      1033910 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   13015      1033910 :   DECL_NONADDRESSABLE_P (field) = 1;
   13016      1033910 :   fields = field;
   13017              : 
   13018      1033910 :   field = build_decl (input_location, FIELD_DECL, delta_identifier,
   13019              :                       delta_type_node);
   13020      1033910 :   DECL_NONADDRESSABLE_P (field) = 1;
   13021      1033910 :   DECL_CHAIN (field) = fields;
   13022      1033910 :   fields = field;
   13023              : 
   13024      1033910 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   13025              : 
   13026              :   /* Zap out the name so that the back end will give us the debugging
   13027              :      information for this anonymous RECORD_TYPE.  */
   13028      1033910 :   TYPE_NAME (t) = NULL_TREE;
   13029              : 
   13030              :   /* Cache this pointer-to-member type so that we can find it again
   13031              :      later.  */
   13032      1033910 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   13033              : 
   13034      1033910 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   13035       500752 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   13036       533158 :   else if (TYPE_CANONICAL (type) != type)
   13037       347962 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   13038              : 
   13039              :   return t;
   13040              : }
   13041              : 
   13042              : /* Create and return a pointer to data member type.  */
   13043              : 
   13044              : tree
   13045       321565 : build_ptrmem_type (tree class_type, tree member_type)
   13046              : {
   13047       321565 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   13048              :     {
   13049        58323 :       cp_cv_quals quals = type_memfn_quals (member_type);
   13050        58323 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   13051        58323 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   13052        58323 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   13053              :     }
   13054              :   else
   13055              :     {
   13056       263242 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   13057       263242 :       return build_offset_type (class_type, member_type);
   13058              :     }
   13059              : }
   13060              : 
   13061              : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   13062              :    Check to see that the definition is valid.  Issue appropriate error
   13063              :    messages.  */
   13064              : 
   13065              : static void
   13066     18355989 : check_static_variable_definition (tree decl, tree type)
   13067              : {
   13068              :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   13069     18355989 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   13070              :     ;
   13071              :   /* Can't check yet if we don't know the type.  */
   13072     17000953 :   else if (dependent_type_p (type))
   13073              :     ;
   13074              :   /* If DECL is declared constexpr, we'll do the appropriate checks
   13075              :      in check_initializer.  Similarly for inline static data members.  */
   13076     16475032 :   else if (DECL_P (decl)
   13077     16475032 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   13078      2628149 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   13079              :     ;
   13080      2627654 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13081              :     {
   13082           58 :       if (!COMPLETE_TYPE_P (type))
   13083           11 :         error_at (DECL_SOURCE_LOCATION (decl),
   13084              :                   "in-class initialization of static data member %q#D of "
   13085              :                   "incomplete type", decl);
   13086           47 :       else if (literal_type_p (type))
   13087           41 :         permerror (DECL_SOURCE_LOCATION (decl),
   13088              :                    "%<constexpr%> needed for in-class initialization of "
   13089              :                    "static data member %q#D of non-integral type", decl);
   13090              :       else
   13091            6 :         error_at (DECL_SOURCE_LOCATION (decl),
   13092              :                   "in-class initialization of static data member %q#D of "
   13093              :                   "non-literal type", decl);
   13094              :     }
   13095              :   /* Motion 10 at San Diego: If a static const integral data member is
   13096              :      initialized with an integral constant expression, the initializer
   13097              :      may appear either in the declaration (within the class), or in
   13098              :      the definition, but not both.  If it appears in the class, the
   13099              :      member is a member constant.  The file-scope definition is always
   13100              :      required.  */
   13101      2627596 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   13102           11 :     error_at (DECL_SOURCE_LOCATION (decl),
   13103              :               "invalid in-class initialization of static data member "
   13104              :               "of non-integral type %qT",
   13105              :               type);
   13106      2627585 :   else if (!CP_TYPE_CONST_P (type))
   13107            5 :     error_at (DECL_SOURCE_LOCATION (decl),
   13108              :               "ISO C++ forbids in-class initialization of non-const "
   13109              :               "static member %qD",
   13110              :               decl);
   13111      2627580 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   13112            5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   13113              :              "ISO C++ forbids initialization of member constant "
   13114              :              "%qD of non-integral type %qT", decl, type);
   13115     18355989 : }
   13116              : 
   13117              : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   13118              :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   13119              :    expressions out into temporary variables so that walk_tree doesn't
   13120              :    step into them (c++/15764).  */
   13121              : 
   13122              : static tree
   13123         3422 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   13124              : {
   13125         3422 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   13126         3422 :   tree expr = *expr_p;
   13127         3422 :   if (TREE_CODE (expr) == SAVE_EXPR)
   13128              :     {
   13129         1492 :       tree op = TREE_OPERAND (expr, 0);
   13130         1492 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   13131         1492 :       if (TREE_SIDE_EFFECTS (op))
   13132           56 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   13133         1492 :       *walk_subtrees = 0;
   13134              :     }
   13135         1930 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   13136         1755 :     *walk_subtrees = 0;
   13137         3422 :   return NULL;
   13138              : }
   13139              : 
   13140              : /* Entry point for the above.  */
   13141              : 
   13142              : static void
   13143         1551 : stabilize_vla_size (tree size)
   13144              : {
   13145         1551 :   hash_set<tree> pset;
   13146              :   /* Break out any function calls into temporary variables.  */
   13147         1551 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   13148         1551 : }
   13149              : 
   13150              : /* Reduce a SIZEOF_EXPR to its value.  */
   13151              : 
   13152              : tree
   13153     11653128 : fold_sizeof_expr (tree t)
   13154              : {
   13155     11653128 :   tree r;
   13156     11653128 :   if (SIZEOF_EXPR_TYPE_P (t))
   13157     11104153 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13158     11104153 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   13159              :                                     SIZEOF_EXPR, false, false);
   13160       548975 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   13161            0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   13162            0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13163              :                                     false, false);
   13164              :   else
   13165       548975 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   13166       548975 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   13167              :                                     false, false);
   13168     11653128 :   if (r == error_mark_node)
   13169           67 :     r = size_one_node;
   13170     11653128 :   r = cp_fold_convert (size_type_node, r);
   13171     11653128 :   return r;
   13172              : }
   13173              : 
   13174              : /* Given the SIZE (i.e., number of elements) in an array, compute
   13175              :    an appropriate index type for the array.  If non-NULL, NAME is
   13176              :    the name of the entity being declared.  */
   13177              : 
   13178              : static tree
   13179      3351881 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   13180              :                               tsubst_flags_t complain)
   13181              : {
   13182      3351881 :   if (error_operand_p (size))
   13183           32 :     return error_mark_node;
   13184              : 
   13185              :   /* The type of the index being computed.  */
   13186      3351849 :   tree itype;
   13187              : 
   13188              :   /* The original numeric size as seen in the source code before
   13189              :      conversion to size_t.  */
   13190      3351849 :   tree origsize = size;
   13191              : 
   13192      3351849 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   13193              : 
   13194      3351849 :   if (!type_dependent_expression_p (size))
   13195              :     {
   13196      3305787 :       origsize = size = mark_rvalue_use (size);
   13197              : 
   13198        35489 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   13199      3305947 :           && TREE_SIDE_EFFECTS (size))
   13200              :         /* In C++98, we mark a non-constant array bound with a magic
   13201              :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   13202              :       else
   13203              :         {
   13204      3305786 :           size = build_converted_constant_expr (size_type_node, size, complain);
   13205              :           /* Pedantically a constant expression is required here and so
   13206              :              __builtin_is_constant_evaluated () should fold to true if it
   13207              :              is successfully folded into a constant.  */
   13208      3305786 :           size = fold_non_dependent_expr (size, complain,
   13209              :                                           /*manifestly_const_eval=*/true);
   13210              : 
   13211      3305786 :           if (!TREE_CONSTANT (size))
   13212       130942 :             size = origsize;
   13213              :         }
   13214              : 
   13215      3305787 :       if (error_operand_p (size))
   13216            3 :         return error_mark_node;
   13217              : 
   13218              :       /* The array bound must be an integer type.  */
   13219      3305784 :       tree type = TREE_TYPE (size);
   13220      3305784 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   13221              :         {
   13222           21 :           if (!(complain & tf_error))
   13223            0 :             return error_mark_node;
   13224           21 :           if (name)
   13225           18 :             error_at (loc, "size of array %qD has non-integral type %qT",
   13226              :                       name, type);
   13227              :           else
   13228            3 :             error_at (loc, "size of array has non-integral type %qT", type);
   13229           21 :           size = integer_one_node;
   13230              :         }
   13231              :     }
   13232              : 
   13233              :   /* A type is dependent if it is...an array type constructed from any
   13234              :      dependent type or whose size is specified by a constant expression
   13235              :      that is value-dependent.  */
   13236              :   /* We can only call value_dependent_expression_p on integral constant
   13237              :      expressions.  */
   13238      3351846 :   if (processing_template_decl
   13239      1527843 :       && potential_constant_expression (size)
   13240      4879664 :       && value_dependent_expression_p (size))
   13241              :     {
   13242              :       /* Just build the index type and mark that it requires
   13243              :          structural equality checks.  */
   13244       843348 :     in_template:
   13245       843348 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   13246              :                                            size, size_one_node));
   13247       843348 :       TYPE_DEPENDENT_P (itype) = 1;
   13248       843348 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   13249       843348 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   13250       843348 :       return itype;
   13251              :     }
   13252              : 
   13253      2522901 :   if (TREE_CODE (size) != INTEGER_CST)
   13254              :     {
   13255        16454 :       tree folded = cp_fully_fold (size);
   13256        16454 :       if (TREE_CODE (folded) == INTEGER_CST)
   13257              :         {
   13258          231 :           if (name)
   13259          157 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   13260              :                      "integral constant-expression", name);
   13261              :           else
   13262           74 :             pedwarn (loc, OPT_Wpedantic,
   13263              :                      "size of array is not an integral constant-expression");
   13264              :         }
   13265        16454 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   13266              :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   13267              :            folding a conversion from a pointer to integral type.  In that
   13268              :            case issue an error below and don't treat this as a VLA.  */;
   13269              :       else
   13270              :         /* Use the folded result for VLAs, too; it will have resolved
   13271              :            SIZEOF_EXPR.  */
   13272              :         size = folded;
   13273              :     }
   13274              : 
   13275              :   /* Normally, the array-bound will be a constant.  */
   13276      2522901 :   if (TREE_CODE (size) == INTEGER_CST)
   13277              :     {
   13278              :       /* The size to use in diagnostics that reflects the constant
   13279              :          size used in the source, rather than SIZE massaged above.  */
   13280      2506678 :       tree diagsize = size;
   13281              : 
   13282              :       /* If the original size before conversion to size_t was signed
   13283              :          and negative, convert it to ssizetype to restore the sign.  */
   13284      2506678 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   13285              :           && TREE_CODE (size) == INTEGER_CST
   13286      2506678 :           && tree_int_cst_sign_bit (size))
   13287              :         {
   13288          250 :           diagsize = fold_convert (ssizetype, size);
   13289              : 
   13290              :           /* Clear the overflow bit that may have been set as a result
   13291              :              of the conversion from the sizetype of the new size to
   13292              :              ssizetype.  */
   13293          250 :           TREE_OVERFLOW (diagsize) = false;
   13294              :         }
   13295              : 
   13296              :       /* Verify that the array has a positive number of elements
   13297              :          and issue the appropriate diagnostic if it doesn't.  */
   13298      2506678 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   13299              :         {
   13300          481 :           if (!(complain & tf_error))
   13301           15 :             return error_mark_node;
   13302          466 :           size = integer_one_node;
   13303              :         }
   13304              :       /* As an extension we allow zero-sized arrays.  */
   13305      2506197 :       else if (integer_zerop (size))
   13306              :         {
   13307         3182 :           if (!(complain & tf_error))
   13308              :             /* We must fail if performing argument deduction (as
   13309              :                indicated by the state of complain), so that
   13310              :                another substitution can be found.  */
   13311            8 :             return error_mark_node;
   13312         3174 :           else if (name)
   13313         2890 :             pedwarn (loc, OPT_Wpedantic,
   13314              :                      "ISO C++ forbids zero-size array %qD", name);
   13315              :           else
   13316          284 :             pedwarn (loc, OPT_Wpedantic,
   13317              :                      "ISO C++ forbids zero-size array");
   13318              :         }
   13319              :     }
   13320        16223 :   else if (TREE_CONSTANT (size)
   13321              :            /* We don't allow VLAs at non-function scopes, or during
   13322              :               tentative template substitution.  */
   13323        16208 :            || !at_function_scope_p ()
   13324        32183 :            || !(complain & tf_error))
   13325              :     {
   13326          269 :       if (!(complain & tf_error))
   13327          218 :         return error_mark_node;
   13328              :       /* `(int) &fn' is not a valid array bound.  */
   13329           51 :       if (name)
   13330           37 :         error_at (loc,
   13331              :                   "size of array %qD is not an integral constant-expression",
   13332              :                   name);
   13333              :       else
   13334           14 :         error_at (loc, "size of array is not an integral constant-expression");
   13335           51 :       size = integer_one_node;
   13336              :     }
   13337        15954 :   else if (pedantic && warn_vla != 0)
   13338              :     {
   13339           30 :       if (name)
   13340           15 :         pedwarn (name_loc, OPT_Wvla,
   13341              :                  "ISO C++ forbids variable length array %qD", name);
   13342              :       else
   13343           15 :         pedwarn (input_location, OPT_Wvla,
   13344              :                  "ISO C++ forbids variable length array");
   13345              :     }
   13346        15924 :   else if (warn_vla > 0)
   13347              :     {
   13348            3 :       if (name)
   13349            3 :         warning_at (name_loc, OPT_Wvla,
   13350              :                     "variable length array %qD is used", name);
   13351              :       else
   13352            0 :         warning (OPT_Wvla,
   13353              :                  "variable length array is used");
   13354              :     }
   13355              : 
   13356      2522660 :   if (processing_template_decl && !TREE_CONSTANT (size))
   13357        14403 :     goto in_template;
   13358              :   else
   13359              :     {
   13360      2508257 :       if (!TREE_CONSTANT (size))
   13361              :         {
   13362              :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   13363              :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   13364              :              that happens when building TYPE_SIZE.  */
   13365         1551 :           size = variable_size (size);
   13366         1551 :           stabilize_vla_size (size);
   13367              :         }
   13368              : 
   13369              :       /* Compute the index of the largest element in the array.  It is
   13370              :          one less than the number of elements in the array.  We save
   13371              :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   13372              :          cp_build_binary_op will be appropriately folded.  */
   13373      2508257 :       {
   13374      2508257 :         processing_template_decl_sentinel s;
   13375      2508257 :         itype = cp_build_binary_op (input_location,
   13376              :                                     MINUS_EXPR,
   13377              :                                     cp_convert (ssizetype, size, complain),
   13378              :                                     cp_convert (ssizetype, integer_one_node,
   13379              :                                                 complain),
   13380              :                                     complain);
   13381      2508257 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   13382      2508257 :       }
   13383              : 
   13384      2508257 :       if (!TREE_CONSTANT (itype))
   13385              :         {
   13386         1551 :           if (sanitize_flags_p (SANITIZE_VLA)
   13387         1551 :               && current_function_decl != NULL_TREE)
   13388              :             {
   13389              :               /* We have to add 1 -- in the ubsan routine we generate
   13390              :                  LE_EXPR rather than LT_EXPR.  */
   13391           78 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   13392              :                                     build_one_cst (TREE_TYPE (itype)));
   13393           78 :               t = ubsan_instrument_vla (input_location, t);
   13394           78 :               finish_expr_stmt (t);
   13395              :             }
   13396              :         }
   13397              :       /* Make sure that there was no overflow when creating to a signed
   13398              :          index type.  (For example, on a 32-bit machine, an array with
   13399              :          size 2^32 - 1 is too big.)  */
   13400      2506706 :       else if (TREE_CODE (itype) == INTEGER_CST
   13401      2506706 :                && TREE_OVERFLOW (itype))
   13402              :         {
   13403            0 :           if (!(complain & tf_error))
   13404            0 :             return error_mark_node;
   13405            0 :           error ("overflow in array dimension");
   13406            0 :           TREE_OVERFLOW (itype) = 0;
   13407              :         }
   13408              :     }
   13409              : 
   13410              :   /* Create and return the appropriate index type.  */
   13411      2508257 :   itype = build_index_type (itype);
   13412              : 
   13413              :   /* If the index type were dependent, we would have returned early, so
   13414              :      remember that it isn't.  */
   13415      2508257 :   TYPE_DEPENDENT_P (itype) = 0;
   13416      2508257 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   13417      2508257 :   return itype;
   13418              : }
   13419              : 
   13420              : tree
   13421       577525 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   13422              : {
   13423       577525 :   return compute_array_index_type_loc (input_location, name, size, complain);
   13424              : }
   13425              : 
   13426              : /* Returns the scope (if any) in which the entity declared by
   13427              :    DECLARATOR will be located.  If the entity was declared with an
   13428              :    unqualified name, NULL_TREE is returned.  */
   13429              : 
   13430              : tree
   13431    743331211 : get_scope_of_declarator (const cp_declarator *declarator)
   13432              : {
   13433    861464922 :   while (declarator && declarator->kind != cdk_id)
   13434    118133711 :     declarator = declarator->declarator;
   13435              : 
   13436              :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   13437              :      declaration occurs is the first operand.  */
   13438    743331211 :   if (declarator
   13439    742117691 :       && declarator->u.id.qualifying_scope)
   13440              :     return declarator->u.id.qualifying_scope;
   13441              : 
   13442              :   /* Otherwise, the declarator is not a qualified name; the entity will
   13443              :      be declared in the current scope.  */
   13444              :   return NULL_TREE;
   13445              : }
   13446              : 
   13447              : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   13448              :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   13449              :    with this type.  */
   13450              : 
   13451              : static tree
   13452      3567732 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   13453              : {
   13454      3567732 :   tree itype = NULL_TREE;
   13455              : 
   13456              :   /* If things have already gone awry, bail now.  */
   13457      3567732 :   if (type == error_mark_node || size == error_mark_node)
   13458              :     return error_mark_node;
   13459              : 
   13460              :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   13461              :      for a deduced class type.  */
   13462      3567669 :   if (template_placeholder_p (type))
   13463              :     {
   13464            6 :       if (name)
   13465            0 :         error_at (loc, "%qD declared as array of template placeholder "
   13466              :                   "type %qT", name, type);
   13467              :       else
   13468            6 :         error ("creating array of template placeholder type %qT", type);
   13469            6 :       return error_mark_node;
   13470              :     }
   13471              : 
   13472              :   /* If there are some types which cannot be array elements,
   13473              :      issue an error-message and return.  */
   13474      3567663 :   switch (TREE_CODE (type))
   13475              :     {
   13476            3 :     case VOID_TYPE:
   13477            3 :       if (name)
   13478            0 :         error_at (loc, "declaration of %qD as array of void", name);
   13479              :       else
   13480            3 :         error ("creating array of void");
   13481            3 :       return error_mark_node;
   13482              : 
   13483            6 :     case FUNCTION_TYPE:
   13484            6 :       if (name)
   13485            6 :         error_at (loc, "declaration of %qD as array of functions", name);
   13486              :       else
   13487            0 :         error ("creating array of functions");
   13488            6 :       return error_mark_node;
   13489              : 
   13490           21 :     case REFERENCE_TYPE:
   13491           21 :       if (name)
   13492           15 :         error_at (loc, "declaration of %qD as array of references", name);
   13493              :       else
   13494            6 :         error ("creating array of references");
   13495           21 :       return error_mark_node;
   13496              : 
   13497            0 :     case METHOD_TYPE:
   13498            0 :       if (name)
   13499            0 :         error_at (loc, "declaration of %qD as array of function members",
   13500              :                   name);
   13501              :       else
   13502            0 :         error ("creating array of function members");
   13503            0 :       return error_mark_node;
   13504              : 
   13505      3567633 :     default:
   13506      3567633 :       break;
   13507              :     }
   13508              : 
   13509      3567633 :   if (!verify_type_context (name ? loc : input_location,
   13510              :                             TCTX_ARRAY_ELEMENT, type))
   13511            0 :     return error_mark_node;
   13512              : 
   13513              :   /* [dcl.array]
   13514              : 
   13515              :      The constant expressions that specify the bounds of the arrays
   13516              :      can be omitted only for the first member of the sequence.  */
   13517      3567633 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   13518              :     {
   13519           30 :       if (name)
   13520           24 :         error_at (loc, "declaration of %qD as multidimensional array must "
   13521              :                   "have bounds for all dimensions except the first",
   13522              :                   name);
   13523              :       else
   13524            6 :         error ("multidimensional array must have bounds for all "
   13525              :                "dimensions except the first");
   13526              : 
   13527           30 :       return error_mark_node;
   13528              :     }
   13529              : 
   13530              :   /* Figure out the index type for the array.  */
   13531      3567603 :   if (size)
   13532              :     {
   13533      2774356 :       itype = compute_array_index_type_loc (loc, name, size,
   13534              :                                             tf_warning_or_error);
   13535      2774356 :       if (type_uses_auto (type)
   13536      2774356 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   13537              :         {
   13538            9 :           sorry_at (loc, "variable-length array of %<auto%>");
   13539            9 :           return error_mark_node;
   13540              :         }
   13541              :     }
   13542              : 
   13543      3567594 :   return build_cplus_array_type (type, itype);
   13544              : }
   13545              : 
   13546              : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   13547              : 
   13548              : static location_t
   13549   1030909253 : min_location (location_t loca, location_t locb)
   13550              : {
   13551   1030909253 :   if (loca == UNKNOWN_LOCATION
   13552   1030909253 :       || (locb != UNKNOWN_LOCATION
   13553    108037733 :           && linemap_location_before_p (line_table, locb, loca)))
   13554    924057989 :     return locb;
   13555              :   return loca;
   13556              : }
   13557              : 
   13558              : /* Returns the smallest location != UNKNOWN_LOCATION among the
   13559              :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   13560              :    and LOCATIONS[ds_restrict].  */
   13561              : 
   13562              : static location_t
   13563   1029186544 : smallest_type_quals_location (int type_quals, const location_t* locations)
   13564              : {
   13565   1029186544 :   location_t loc = UNKNOWN_LOCATION;
   13566              : 
   13567   1029186544 :   if (type_quals & TYPE_QUAL_CONST)
   13568    106562295 :     loc = locations[ds_const];
   13569              : 
   13570   1029186544 :   if (type_quals & TYPE_QUAL_VOLATILE)
   13571      1722618 :     loc = min_location (loc, locations[ds_volatile]);
   13572              : 
   13573   1029186544 :   if (type_quals & TYPE_QUAL_RESTRICT)
   13574           43 :     loc = min_location (loc, locations[ds_restrict]);
   13575              : 
   13576   1029186544 :   return loc;
   13577              : }
   13578              : 
   13579              : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   13580              : 
   13581              : static location_t
   13582   1029186523 : smallest_type_location (int type_quals, const location_t* locations)
   13583              : {
   13584   1029186523 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   13585   1029186523 :   return min_location (loc, locations[ds_type_spec]);
   13586              : }
   13587              : 
   13588              : static location_t
   13589           26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   13590              : {
   13591           26 :   int type_quals = get_type_quals (declspecs);
   13592           26 :   return smallest_type_location (type_quals, declspecs->locations);
   13593              : }
   13594              : 
   13595              : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
   13596              :    strip out the pointer/reference declarator(s).  */
   13597              : 
   13598              : static bool
   13599     29269622 : maybe_strip_indirect_ref (const cp_declarator** declarator)
   13600              : {
   13601     29269622 :   bool indirect_ref_p = false;
   13602     58539391 :   while (declarator && *declarator
   13603     29269769 :          && ((*declarator)->kind == cdk_pointer
   13604     29269769 :              || (*declarator)->kind == cdk_reference))
   13605              :     {
   13606          147 :       indirect_ref_p = true;
   13607          147 :       *declarator = (*declarator)->declarator;
   13608              :     }
   13609     29269622 :   return indirect_ref_p;
   13610              : }
   13611              : 
   13612              : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
   13613              :    and DECLARATOR.  SFK indicates the kind of special function (if any) that
   13614              :    this function is.  OPTYPE is the type given in a conversion operator
   13615              :    declaration, or the class type for a constructor/destructor.
   13616              :    Returns the actual return type of the function; that may be different
   13617              :    than TYPE if an error occurs, or for certain special functions.  */
   13618              : 
   13619              : static tree
   13620     29269622 : check_special_function_return_type (special_function_kind sfk,
   13621              :                                     tree type,
   13622              :                                     tree optype,
   13623              :                                     int type_quals,
   13624              :                                     const cp_declarator** declarator,
   13625              :                                     const location_t* locations)
   13626              : {
   13627     29269622 :   gcc_assert (declarator);
   13628     29269622 :   location_t rettype_loc = (type
   13629     29269622 :                             ? smallest_type_location (type_quals, locations)
   13630     29269541 :                             : (*declarator)->id_loc);
   13631     29269622 :   switch (sfk)
   13632              :     {
   13633     23862745 :     case sfk_constructor:
   13634     23862745 :       if (maybe_strip_indirect_ref (declarator) || type)
   13635           81 :         error_at (rettype_loc,
   13636              :                   "return type specification for constructor invalid");
   13637     23862664 :       else if (type_quals != TYPE_UNQUALIFIED)
   13638           15 :         error_at (smallest_type_quals_location (type_quals, locations),
   13639              :                   "qualifiers are not allowed on constructor declaration");
   13640              : 
   13641     23862745 :       if (targetm.cxx.cdtor_returns_this ())
   13642            0 :         type = build_pointer_type (optype);
   13643              :       else
   13644     23862745 :         type = void_type_node;
   13645              :       break;
   13646              : 
   13647      3212057 :     case sfk_destructor:
   13648      3212057 :       if (maybe_strip_indirect_ref (declarator) || type)
   13649           45 :         error_at (rettype_loc,
   13650              :                   "return type specification for destructor invalid");
   13651      3212012 :       else if (type_quals != TYPE_UNQUALIFIED)
   13652            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13653              :                   "qualifiers are not allowed on destructor declaration");
   13654              : 
   13655              :       /* We can't use the proper return type here because we run into
   13656              :          problems with ambiguous bases and covariant returns.  */
   13657      3212057 :       if (targetm.cxx.cdtor_returns_this ())
   13658            0 :         type = build_pointer_type (void_type_node);
   13659              :       else
   13660      3212057 :         type = void_type_node;
   13661              :       break;
   13662              : 
   13663      1007916 :     case sfk_conversion:
   13664      1007916 :       if (maybe_strip_indirect_ref (declarator) || type)
   13665           42 :         error_at (rettype_loc,
   13666              :                   "return type specified for %<operator %T%>", optype);
   13667      1007874 :       else if (type_quals != TYPE_UNQUALIFIED)
   13668            3 :         error_at (smallest_type_quals_location (type_quals, locations),
   13669              :                   "qualifiers are not allowed on declaration of "
   13670              :                   "%<operator %T%>", optype);
   13671              : 
   13672              :       type = optype;
   13673              :       break;
   13674              : 
   13675      1186904 :     case sfk_deduction_guide:
   13676      1186904 :       if (maybe_strip_indirect_ref (declarator) || type)
   13677            0 :         error_at (rettype_loc,
   13678              :                   "return type specified for deduction guide");
   13679      1186904 :       else if (type_quals != TYPE_UNQUALIFIED)
   13680            0 :         error_at (smallest_type_quals_location (type_quals, locations),
   13681              :                   "qualifiers are not allowed on declaration of "
   13682              :                   "deduction guide");
   13683      1186904 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   13684              :         {
   13685            3 :           error ("template template parameter %qT in declaration of "
   13686              :                  "deduction guide", optype);
   13687            3 :           type = error_mark_node;
   13688              :         }
   13689              :       else
   13690      1186901 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   13691     32046408 :       for (int i = 0; i < ds_last; ++i)
   13692     30859504 :         if (i != ds_explicit && locations[i])
   13693            3 :           error_at (locations[i],
   13694              :                     "%<decl-specifier%> in declaration of deduction guide");
   13695              :       break;
   13696              : 
   13697            0 :     default:
   13698            0 :       gcc_unreachable ();
   13699              :     }
   13700              : 
   13701     29269622 :   return type;
   13702              : }
   13703              : 
   13704              : /* A variable or data member (whose unqualified name is IDENTIFIER)
   13705              :    has been declared with the indicated TYPE.  If the TYPE is not
   13706              :    acceptable, issue an error message and return a type to use for
   13707              :    error-recovery purposes.  */
   13708              : 
   13709              : tree
   13710    322627654 : check_var_type (tree identifier, tree type, location_t loc)
   13711              : {
   13712    322627654 :   if (VOID_TYPE_P (type))
   13713              :     {
   13714           92 :       if (!identifier)
   13715            0 :         error_at (loc, "unnamed variable or field declared void");
   13716           92 :       else if (identifier_p (identifier))
   13717              :         {
   13718           92 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   13719           92 :           error_at (loc, "variable or field %qE declared void",
   13720              :                     identifier);
   13721              :         }
   13722              :       else
   13723            0 :         error_at (loc, "variable or field declared void");
   13724           92 :       type = error_mark_node;
   13725              :     }
   13726              : 
   13727    322627654 :   return type;
   13728              : }
   13729              : 
   13730              : /* Handle declaring DECL as an inline variable.  */
   13731              : 
   13732              : static void
   13733      6587257 : mark_inline_variable (tree decl, location_t loc)
   13734              : {
   13735      6587257 :   bool inlinep = true;
   13736      6587257 :   if (! toplevel_bindings_p ())
   13737              :     {
   13738           24 :       error_at (loc, "%<inline%> specifier invalid for variable "
   13739              :                 "%qD declared at block scope", decl);
   13740           24 :       inlinep = false;
   13741              :     }
   13742      6587233 :   else if (cxx_dialect < cxx17)
   13743          652 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   13744              :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   13745          676 :   if (inlinep)
   13746              :     {
   13747      6587233 :       retrofit_lang_decl (decl);
   13748      6587233 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   13749              :     }
   13750      6587257 : }
   13751              : 
   13752              : 
   13753              : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn.  TYPE is the unnamed class
   13754              :    with a typedef name for linkage purposes with freshly updated TYPE_NAME,
   13755              :    ORIG is the anonymous TYPE_NAME before that change.  */
   13756              : 
   13757              : static bool
   13758           42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
   13759              : {
   13760           42 :   gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
   13761           42 :   tree name = DECL_NAME (TYPE_NAME (type));
   13762           42 :   richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
   13763           42 :   return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
   13764              :                   "anonymous non-C-compatible type given name for linkage "
   13765           42 :                   "purposes by %<typedef%> declaration");
   13766           42 : }
   13767              : 
   13768              : /* Diagnose -Wnon-c-typedef-for-linkage violations on T.  TYPE and ORIG
   13769              :    like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
   13770              :    to TYPE but during recursion can be set to nested classes.  */
   13771              : 
   13772              : static bool
   13773       511281 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
   13774              : {
   13775       511281 :   if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
   13776              :     {
   13777            6 :       auto_diagnostic_group d;
   13778            6 :       if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13779            9 :         inform (type == t ? DECL_SOURCE_LOCATION (orig)
   13780            3 :                 : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
   13781              :                 "type is not C-compatible because it has a base class");
   13782            6 :       return true;
   13783            6 :     }
   13784      2401714 :   for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
   13785      1890500 :     switch (TREE_CODE (field))
   13786              :       {
   13787            9 :       case VAR_DECL:
   13788              :         /* static data members have been diagnosed already.  */
   13789            9 :         continue;
   13790      1257409 :       case FIELD_DECL:
   13791      1257409 :         if (DECL_INITIAL (field))
   13792              :           {
   13793            4 :             auto_diagnostic_group d;
   13794            4 :             if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13795            4 :               inform (DECL_SOURCE_LOCATION (field),
   13796              :                       "type is not C-compatible because %qD has default "
   13797              :                       "member initializer", field);
   13798            4 :             return true;
   13799            4 :           }
   13800      1257405 :         continue;
   13801            9 :       case CONST_DECL:
   13802            9 :         continue;
   13803       632992 :       case TYPE_DECL:
   13804       632992 :         if (DECL_SELF_REFERENCE_P (field))
   13805       511249 :           continue;
   13806       121743 :         if (DECL_IMPLICIT_TYPEDEF_P (field))
   13807              :           {
   13808       121733 :             if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
   13809            3 :               continue;
   13810       121730 :             if (CLASS_TYPE_P (TREE_TYPE (field)))
   13811              :               {
   13812       121730 :                 tree tf = TREE_TYPE (field);
   13813       121730 :                 if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
   13814              :                                                                     tf))
   13815              :                   return true;
   13816       121705 :                 continue;
   13817       121705 :               }
   13818              :           }
   13819              :         /* FALLTHRU */
   13820           32 :       case FUNCTION_DECL:
   13821           32 :       case TEMPLATE_DECL:
   13822           32 :         {
   13823           32 :           auto_diagnostic_group d;
   13824           32 :           if (diagnose_non_c_class_typedef_for_linkage (type, orig))
   13825           32 :             inform (DECL_SOURCE_LOCATION (field),
   13826              :                     "type is not C-compatible because it contains %qD "
   13827              :                     "declaration", field);
   13828           32 :           return true;
   13829           32 :         }
   13830              :       default:
   13831              :         break;
   13832      1257423 :       }
   13833              :   return false;
   13834              : }
   13835              : 
   13836              : /* Assign a typedef-given name to a class or enumeration type declared
   13837              :    as anonymous at first.  This was split out of grokdeclarator
   13838              :    because it is also used in libcc1.  */
   13839              : 
   13840              : void
   13841       391358 : name_unnamed_type (tree type, tree decl)
   13842              : {
   13843      1174074 :   gcc_assert (TYPE_UNNAMED_P (type)
   13844              :               || enum_with_enumerator_for_linkage_p (type));
   13845              : 
   13846       391358 :   tree orig = TYPE_NAME (type);
   13847       391358 :   if (flag_reflection)
   13848              :     {
   13849              :       /* For -freflection for typedef struct { ... } S; ^^S needs to be
   13850              :          a reflection of a type alias.  So, TREE_TYPE (DECL) can't be
   13851              :          TYPE.  Instead of what we do below, override DECL_NAME (orig).  */
   13852        14902 :       DECL_NAME (orig) = DECL_NAME (decl);
   13853        14902 :       TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
   13854              :     }
   13855              :   else
   13856              :     /* Replace the anonymous decl with the real decl.  Be careful not to
   13857              :        rename other typedefs (such as the self-reference) of type.  */
   13858      1127642 :     for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   13859       751186 :       if (TYPE_NAME (t) == orig)
   13860       376456 :         TYPE_NAME (t) = decl;
   13861       391358 :   TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
   13862              : 
   13863              :   /* If this is a typedef within a template class, the nested
   13864              :      type is a (non-primary) template.  The name for the
   13865              :      template needs updating as well.  */
   13866       391358 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   13867           68 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   13868              : 
   13869              :   /* Adjust linkage now that we aren't unnamed anymore.  */
   13870       391358 :   reset_type_linkage (type);
   13871              : 
   13872       391358 :   if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
   13873       389551 :     maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
   13874              : 
   13875              :   /* FIXME remangle member functions; member functions of a
   13876              :      type with external linkage have external linkage.  */
   13877              : 
   13878              :   /* Check that our job is done, and that it would fail if we
   13879              :      attempted to do it again.  */
   13880       782716 :   gcc_assert (!TYPE_UNNAMED_P (type)
   13881              :               && !enum_with_enumerator_for_linkage_p (type));
   13882       391358 : }
   13883              : 
   13884              : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   13885              :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   13886              :    there was a problem, false otherwise.  */
   13887              : 
   13888              : static bool
   13889    626565862 : check_decltype_auto (location_t loc, tree type)
   13890              : {
   13891    626565862 :   if (tree a = type_uses_auto (type))
   13892              :     {
   13893     17225090 :       if (AUTO_IS_DECLTYPE (a))
   13894              :         {
   13895       602156 :           if (a != type)
   13896              :             {
   13897           33 :               error_at (loc, "%qT as type rather than plain "
   13898              :                         "%<decltype(auto)%>", type);
   13899           33 :               return true;
   13900              :             }
   13901       602123 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   13902              :             {
   13903           37 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   13904           37 :               return true;
   13905              :             }
   13906              :         }
   13907              :     }
   13908              :   return false;
   13909              : }
   13910              : 
   13911              : /* Issue an error about two mutually incompatible declspecs
   13912              :    with the given names and locations
   13913              :    e.g. "error: `signed' and `unsigned' specified together" */
   13914              : 
   13915              : static void
   13916           66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
   13917              :                                        const char *name_b, location_t loc_b)
   13918              : {
   13919           66 :   gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
   13920           66 :   richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
   13921              :                      nullptr, highlight_colors::rhs);
   13922           66 :   pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
   13923           66 :   pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
   13924           66 :   error_at (&richloc, "%e and %e specified together",
   13925              :             &e_name_a, &e_name_b);
   13926           66 : }
   13927              : 
   13928              : /* Given declspecs and a declarator (abstract or otherwise), determine
   13929              :    the name and type of the object declared and construct a DECL node
   13930              :    for it.
   13931              : 
   13932              :    DECLSPECS points to the representation of declaration-specifier
   13933              :    sequence that precedes declarator.
   13934              : 
   13935              :    DECL_CONTEXT says which syntactic context this declaration is in:
   13936              :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   13937              :      FUNCDEF for a function definition.  Like NORMAL but a few different
   13938              :       error messages in each case.  Return value may be zero meaning
   13939              :       this definition is too screwy to try to parse.
   13940              :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   13941              :       handle member functions (which have FIELD context).
   13942              :       Return value may be zero meaning this definition is too screwy to
   13943              :       try to parse.
   13944              :      PARM for a parameter declaration (either within a function prototype
   13945              :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   13946              :      TPARM for a template parameter declaration.
   13947              :      CATCHPARM for a parameter declaration before a catch clause.
   13948              :      TYPENAME if for a typename (in a cast or sizeof).
   13949              :       Don't make a DECL node; just return the ..._TYPE node.
   13950              :      FIELD for a struct or union field; make a FIELD_DECL.
   13951              :      BITFIELD for a field with specified width.
   13952              : 
   13953              :    INITIALIZED is as for start_decl.
   13954              : 
   13955              :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   13956              :    if there are none; *ATTRLIST may be modified if attributes from inside
   13957              :    the declarator should be applied to the declaration.
   13958              : 
   13959              :    When this function is called, scoping variables (such as
   13960              :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   13961              :    declaration occurs, not the scope in which the new declaration will
   13962              :    be placed.  For example, on:
   13963              : 
   13964              :      void S::f() { ... }
   13965              : 
   13966              :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   13967              :    should not be `S'.
   13968              : 
   13969              :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   13970              :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   13971              :    error occurs. */
   13972              : 
   13973              : tree
   13974   1029186416 : grokdeclarator (const cp_declarator *declarator,
   13975              :                 cp_decl_specifier_seq *declspecs,
   13976              :                 enum decl_context decl_context,
   13977              :                 int initialized,
   13978              :                 tree* attrlist)
   13979              : {
   13980   1029186416 :   tree type = NULL_TREE;
   13981   1029186416 :   int longlong = 0;
   13982   1029186416 :   int explicit_intN = 0;
   13983   1029186416 :   int int_n_alt = 0;
   13984   1029186416 :   int virtualp, explicitp, friendp, inlinep, staticp;
   13985   1029186416 :   int explicit_int = 0;
   13986   1029186416 :   int explicit_char = 0;
   13987   1029186416 :   int defaulted_int = 0;
   13988              : 
   13989   1029186416 :   tree typedef_decl = NULL_TREE;
   13990   1029186416 :   const char *name = NULL;
   13991   1029186416 :   tree typedef_type = NULL_TREE;
   13992              :   /* True if this declarator is a function definition.  */
   13993   1029186416 :   bool funcdef_flag = false;
   13994   1029186416 :   cp_declarator_kind innermost_code = cdk_error;
   13995   1029186416 :   int bitfield = 0;
   13996              : #if 0
   13997              :   /* See the code below that used this.  */
   13998              :   tree decl_attr = NULL_TREE;
   13999              : #endif
   14000              : 
   14001              :   /* Keep track of what sort of function is being processed
   14002              :      so that we can warn about default return values, or explicit
   14003              :      return values which do not match prescribed defaults.  */
   14004   1029186416 :   special_function_kind sfk = sfk_none;
   14005              : 
   14006   1029186416 :   tree dname = NULL_TREE;
   14007   1029186416 :   tree ctor_return_type = NULL_TREE;
   14008   1029186416 :   enum overload_flags flags = NO_SPECIAL;
   14009              :   /* cv-qualifiers that apply to the declarator, for a declaration of
   14010              :      a member function.  */
   14011   1029186416 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   14012              :   /* virt-specifiers that apply to the declarator, for a declaration of
   14013              :      a member function.  */
   14014   1029186416 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   14015              :   /* ref-qualifier that applies to the declarator, for a declaration of
   14016              :      a member function.  */
   14017   1029186416 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   14018              :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   14019   1029186416 :   int type_quals = get_type_quals (declspecs);
   14020   1029186416 :   tree raises = NULL_TREE;
   14021   1029186416 :   int template_count = 0;
   14022   1029186416 :   tree returned_attrs = NULL_TREE;
   14023   1029186416 :   tree contract_specifiers = NULL_TREE;
   14024   1029186416 :   tree parms = NULL_TREE;
   14025   1029186416 :   const cp_declarator *id_declarator;
   14026              :   /* The unqualified name of the declarator; either an
   14027              :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   14028   1029186416 :   tree unqualified_id;
   14029              :   /* The class type, if any, in which this entity is located,
   14030              :      or NULL_TREE if none.  Note that this value may be different from
   14031              :      the current class type; for example if an attempt is made to declare
   14032              :      "A::f" inside "B", this value will be "A".  */
   14033   1029186416 :   tree ctype = current_class_type;
   14034              :   /* The NAMESPACE_DECL for the namespace in which this entity is
   14035              :      located.  If an unqualified name is used to declare the entity,
   14036              :      this value will be NULL_TREE, even if the entity is located at
   14037              :      namespace scope.  */
   14038   1029186416 :   tree in_namespace = NULL_TREE;
   14039   1029186416 :   cp_storage_class storage_class;
   14040   1029186416 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   14041   1029186416 :   bool type_was_error_mark_node = false;
   14042   1029186416 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   14043   1029186416 :   bool template_type_arg = false;
   14044   1029186416 :   bool template_parm_flag = false;
   14045   1029186416 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   14046   1029186416 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   14047   1029186416 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   14048   1029186416 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   14049   1029186416 :   bool late_return_type_p = false;
   14050   1029186416 :   bool array_parameter_p = false;
   14051   1029186416 :   tree reqs = NULL_TREE;
   14052              : 
   14053   1029186416 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   14054   1029186416 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   14055   1029186416 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   14056   1029186416 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   14057   1029186416 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   14058   1029186416 :   explicit_intN = declspecs->explicit_intN_p;
   14059   1029186416 :   int_n_alt = declspecs->int_n_alt;
   14060   1029186416 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   14061              : 
   14062              :   // Was concept_p specified? Note that ds_concept
   14063              :   // implies ds_constexpr!
   14064   1029186416 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   14065   1029186416 :   if (concept_p)
   14066          117 :     constexpr_p = true;
   14067              : 
   14068   1029186416 :   if (decl_context == FUNCDEF)
   14069              :     funcdef_flag = true, decl_context = NORMAL;
   14070              :   else if (decl_context == MEMFUNCDEF)
   14071              :     funcdef_flag = true, decl_context = FIELD;
   14072              :   else if (decl_context == BITFIELD)
   14073              :     bitfield = 1, decl_context = FIELD;
   14074              :   else if (decl_context == TEMPLATE_TYPE_ARG)
   14075              :     template_type_arg = true, decl_context = TYPENAME;
   14076              :   else if (decl_context == TPARM)
   14077     10867491 :     template_parm_flag = true, decl_context = PARM;
   14078              : 
   14079   1029186416 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   14080     10874554 :     funcdef_flag = true;
   14081              : 
   14082   1029186416 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   14083              :                                               (type_quals,
   14084   1029186416 :                                                declspecs->locations));
   14085   1029186416 :   location_t id_loc;
   14086   1029186416 :   location_t init_loc;
   14087   1029186416 :   if (declarator)
   14088              :     {
   14089    620839239 :       id_loc = loc_or_input_loc (declarator->id_loc);
   14090    620839239 :       init_loc = loc_or_input_loc (declarator->init_loc);
   14091              :     }
   14092              :   else
   14093    408347177 :     init_loc = id_loc = input_location;
   14094              : 
   14095              :   /* Look inside a declarator for the name being declared
   14096              :      and get it as a string, for an error message.  */
   14097   1029186416 :   for (id_declarator = declarator;
   14098   1413392651 :        id_declarator;
   14099    384206235 :        id_declarator = id_declarator->declarator)
   14100              :     {
   14101    963714315 :       if (id_declarator->kind != cdk_id)
   14102    384206260 :         innermost_code = id_declarator->kind;
   14103              : 
   14104    963714315 :       switch (id_declarator->kind)
   14105              :         {
   14106    188464010 :         case cdk_function:
   14107    188464010 :           if (id_declarator->declarator
   14108    188093711 :               && id_declarator->declarator->kind == cdk_id)
   14109              :             {
   14110    186266781 :               sfk = id_declarator->declarator->u.id.sfk;
   14111    186266781 :               if (sfk == sfk_destructor)
   14112      3212060 :                 flags = DTOR_FLAG;
   14113              :             }
   14114              :           break;
   14115              : 
   14116    579508055 :         case cdk_id:
   14117    579508055 :           {
   14118    579508055 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   14119    579508055 :             tree decl = id_declarator->u.id.unqualified_name;
   14120    579508055 :             if (!decl)
   14121              :               break;
   14122    579508055 :             if (qualifying_scope)
   14123              :               {
   14124      9581691 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   14125      9581691 :                                                     id_declarator->id_loc))
   14126            6 :                   return error_mark_node;
   14127      9581685 :                 if (at_function_scope_p ())
   14128              :                   {
   14129              :                     /* [dcl.meaning]
   14130              : 
   14131              :                        A declarator-id shall not be qualified except
   14132              :                        for ...
   14133              : 
   14134              :                        None of the cases are permitted in block
   14135              :                        scope.  */
   14136            0 :                     if (qualifying_scope == global_namespace)
   14137            0 :                       error ("invalid use of qualified-name %<::%D%>",
   14138              :                              decl);
   14139            0 :                     else if (TYPE_P (qualifying_scope))
   14140            0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   14141              :                              qualifying_scope, decl);
   14142              :                     else
   14143            0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   14144              :                              qualifying_scope, decl);
   14145            0 :                     return error_mark_node;
   14146              :                   }
   14147      9581685 :                 else if (TYPE_P (qualifying_scope))
   14148              :                   {
   14149      9326459 :                     ctype = qualifying_scope;
   14150      9326459 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   14151              :                       {
   14152            6 :                         error_at (id_declarator->id_loc,
   14153              :                                   "%q#T is not a class or namespace", ctype);
   14154            6 :                         ctype = NULL_TREE;
   14155              :                       }
   14156      9326453 :                     else if (innermost_code != cdk_function
   14157       491615 :                              && current_class_type
   14158      9326468 :                              && !uniquely_derived_from_p (ctype,
   14159              :                                                           current_class_type))
   14160              :                       {
   14161            9 :                         error_at (id_declarator->id_loc,
   14162              :                                   "invalid use of qualified-name %<%T::%D%>",
   14163              :                                   qualifying_scope, decl);
   14164            9 :                         return error_mark_node;
   14165              :                       }
   14166              :                   }
   14167       255226 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   14168    579508040 :                   in_namespace = qualifying_scope;
   14169              :               }
   14170    579508040 :             switch (TREE_CODE (decl))
   14171              :               {
   14172      3212075 :               case BIT_NOT_EXPR:
   14173      3212075 :                 {
   14174      3212075 :                   if (innermost_code != cdk_function)
   14175              :                     {
   14176            6 :                       error_at (EXPR_LOCATION (decl),
   14177              :                                 "declaration of %qE as non-function", decl);
   14178            6 :                       return error_mark_node;
   14179              :                     }
   14180      3212069 :                   else if (!qualifying_scope
   14181      3212069 :                            && !(current_class_type && at_class_scope_p ()))
   14182              :                     {
   14183            9 :                       error_at (EXPR_LOCATION (decl),
   14184              :                                 "declaration of %qE as non-member", decl);
   14185            9 :                       return error_mark_node;
   14186              :                     }
   14187              : 
   14188      3212060 :                   tree type = TREE_OPERAND (decl, 0);
   14189      3212060 :                   if (TYPE_P (type))
   14190      3212057 :                     type = constructor_name (type);
   14191      3212060 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   14192      3212060 :                   dname = decl;
   14193              :                 }
   14194      3212060 :                 break;
   14195              : 
   14196      2754225 :               case TEMPLATE_ID_EXPR:
   14197      2754225 :                 {
   14198      2754225 :                   tree fns = TREE_OPERAND (decl, 0);
   14199              : 
   14200      2754225 :                   dname = fns;
   14201      3685145 :                   if (!identifier_p (dname))
   14202      2754201 :                     dname = OVL_NAME (dname);
   14203              :                 }
   14204              :                 /* Fall through.  */
   14205              : 
   14206    576295965 :               case IDENTIFIER_NODE:
   14207    576295965 :                 if (identifier_p (decl))
   14208    573541740 :                   dname = decl;
   14209              : 
   14210    576295965 :                 if (IDENTIFIER_KEYWORD_P (dname))
   14211              :                   {
   14212            0 :                     error ("declarator-id missing; using reserved word %qD",
   14213              :                            dname);
   14214            0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14215              :                   }
   14216    576295965 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   14217    575288046 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14218              :                 else
   14219              :                   {
   14220      1007919 :                     gcc_assert (flags == NO_SPECIAL);
   14221      1007919 :                     flags = TYPENAME_FLAG;
   14222      1007919 :                     sfk = sfk_conversion;
   14223      1007919 :                     tree glob = get_global_binding (dname);
   14224      1007919 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   14225            0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   14226              :                     else
   14227              :                       name = "<invalid operator>";
   14228              :                   }
   14229              :                 break;
   14230              : 
   14231            0 :               default:
   14232            0 :                 gcc_unreachable ();
   14233              :               }
   14234              :             break;
   14235              :           }
   14236              : 
   14237              :         case cdk_array:
   14238              :         case cdk_pointer:
   14239              :         case cdk_reference:
   14240              :         case cdk_ptrmem:
   14241              :           break;
   14242              : 
   14243              :         case cdk_decomp:
   14244    963714260 :           name = "structured binding";
   14245              :           break;
   14246              : 
   14247           25 :         case cdk_error:
   14248           25 :           return error_mark_node;
   14249              : 
   14250            0 :         default:
   14251            0 :           gcc_unreachable ();
   14252              :         }
   14253    963714260 :       if (id_declarator->kind == cdk_id)
   14254              :         break;
   14255              :     }
   14256              : 
   14257              :   /* [dcl.fct.edf]
   14258              : 
   14259              :      The declarator in a function-definition shall have the form
   14260              :      D1 ( parameter-declaration-clause) ...  */
   14261   1029186361 :   if (funcdef_flag && innermost_code != cdk_function)
   14262              :     {
   14263            3 :       error_at (id_loc, "function definition does not declare parameters");
   14264            3 :       return error_mark_node;
   14265              :     }
   14266              : 
   14267   1029186358 :   if (flags == TYPENAME_FLAG
   14268   1029186358 :       && innermost_code != cdk_function
   14269            3 :       && ! (ctype && !declspecs->any_specifiers_p))
   14270              :     {
   14271            3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   14272            3 :       return error_mark_node;
   14273              :     }
   14274              : 
   14275   1029186355 :   if (dname && identifier_p (dname))
   14276              :     {
   14277    576295959 :       if (UDLIT_OPER_P (dname)
   14278    576295959 :           && innermost_code != cdk_function)
   14279              :         {
   14280            6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   14281            6 :           return error_mark_node;
   14282              :         }
   14283              : 
   14284    576295953 :       if (IDENTIFIER_ANY_OP_P (dname))
   14285              :         {
   14286     36582028 :           if (typedef_p)
   14287              :             {
   14288            3 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   14289            3 :               return error_mark_node;
   14290              :             }
   14291     36582025 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14292              :             {
   14293           15 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   14294           15 :               return error_mark_node;
   14295              :             }
   14296              :         }
   14297              :     }
   14298              : 
   14299              :   /* Anything declared one level down from the top level
   14300              :      must be one of the parameters of a function
   14301              :      (because the body is at least two levels down).  */
   14302              : 
   14303              :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   14304              :      by not allowing C++ class definitions to specify their parameters
   14305              :      with xdecls (must be spec.d in the parmlist).
   14306              : 
   14307              :      Since we now wait to push a class scope until we are sure that
   14308              :      we are in a legitimate method context, we must set oldcname
   14309              :      explicitly (since current_class_name is not yet alive).
   14310              : 
   14311              :      We also want to avoid calling this a PARM if it is in a namespace.  */
   14312              : 
   14313   1029186331 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   14314              :     {
   14315     71378441 :       cp_binding_level *b = current_binding_level;
   14316     71378441 :       current_binding_level = b->level_chain;
   14317     71378441 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   14318              :         decl_context = PARM;
   14319     71378441 :       current_binding_level = b;
   14320              :     }
   14321              : 
   14322   1029186331 :   if (name == NULL)
   14323    449448312 :     name = decl_context == PARM ? "parameter" : "type name";
   14324              : 
   14325   1029186331 :   if (consteval_p && constexpr_p)
   14326              :     {
   14327            6 :       error_at (declspecs->locations[ds_consteval],
   14328              :                 "both %qs and %qs specified", "constexpr", "consteval");
   14329            6 :       return error_mark_node;
   14330              :     }
   14331              : 
   14332   1029186325 :   if (concept_p && typedef_p)
   14333              :     {
   14334            9 :       error_at (declspecs->locations[ds_concept],
   14335              :                 "%qs cannot appear in a typedef declaration", "concept");
   14336            9 :       return error_mark_node;
   14337              :     }
   14338              : 
   14339   1029186316 :   if (constexpr_p && typedef_p)
   14340              :     {
   14341            3 :       error_at (declspecs->locations[ds_constexpr],
   14342              :                 "%qs cannot appear in a typedef declaration", "constexpr");
   14343            3 :       return error_mark_node;
   14344              :     }
   14345              : 
   14346   1029186313 :   if (consteval_p && typedef_p)
   14347              :     {
   14348            3 :       error_at (declspecs->locations[ds_consteval],
   14349              :                 "%qs cannot appear in a typedef declaration", "consteval");
   14350            3 :       return error_mark_node;
   14351              :     }
   14352              : 
   14353   1029186310 :   if (constinit_p && typedef_p)
   14354              :     {
   14355            3 :       error_at (declspecs->locations[ds_constinit],
   14356              :                 "%qs cannot appear in a typedef declaration", "constinit");
   14357            3 :       return error_mark_node;
   14358              :     }
   14359              : 
   14360              :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   14361              :      keywords shall appear in a decl-specifier-seq."  */
   14362   1029186307 :   if (constinit_p && constexpr_p)
   14363              :     {
   14364            6 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   14365            6 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   14366            6 :       error_at (&richloc,
   14367              :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   14368              :                 "specifiers");
   14369            6 :       return error_mark_node;
   14370            6 :     }
   14371              : 
   14372              :   /* If there were multiple types specified in the decl-specifier-seq,
   14373              :      issue an error message.  */
   14374   1029186301 :   if (declspecs->multiple_types_p)
   14375              :     {
   14376         1501 :       error_at (typespec_loc,
   14377              :                 "two or more data types in declaration of %qs", name);
   14378         1501 :       return error_mark_node;
   14379              :     }
   14380              : 
   14381   1029184800 :   if (declspecs->conflicting_specifiers_p)
   14382           31 :     return error_mark_node;
   14383              : 
   14384              :   /* Extract the basic type from the decl-specifier-seq.  */
   14385   1029184769 :   type = declspecs->type;
   14386   1029184769 :   if (type == error_mark_node)
   14387              :     {
   14388         1225 :       type = NULL_TREE;
   14389         1225 :       type_was_error_mark_node = true;
   14390              :     }
   14391              : 
   14392              :   /* Ignore erroneous attributes.  */
   14393   1029184769 :   if (attrlist && *attrlist == error_mark_node)
   14394           12 :     *attrlist = NULL_TREE;
   14395              : 
   14396              :   /* An object declared as __attribute__((unavailable)) suppresses
   14397              :      any reports of being declared with unavailable or deprecated
   14398              :      items.  An object declared as __attribute__((deprecated))
   14399              :      suppresses warnings of uses of other deprecated items.  */
   14400   1029184769 :   auto ds = make_temp_override (deprecated_state);
   14401   1029184769 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   14402          171 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   14403   1029184598 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   14404       911809 :     deprecated_state = DEPRECATED_SUPPRESS;
   14405              : 
   14406   1029184769 :   cp_handle_deprecated_or_unavailable (type);
   14407   1029184769 :   if (type && TREE_CODE (type) == TYPE_DECL)
   14408              :     {
   14409    716301332 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   14410    716301332 :       typedef_decl = type;
   14411    716301332 :       type = TREE_TYPE (typedef_decl);
   14412    716301332 :       if (DECL_ARTIFICIAL (typedef_decl))
   14413    521105707 :         cp_handle_deprecated_or_unavailable (type);
   14414              :     }
   14415              :   /* No type at all: default to `int', and set DEFAULTED_INT
   14416              :      because it was not a user-defined typedef.  */
   14417   1029184769 :   if (type == NULL_TREE)
   14418              :     {
   14419     38329975 :       if (signed_p || unsigned_p || long_p || short_p)
   14420              :         {
   14421              :           /* These imply 'int'.  */
   14422      9058728 :           type = integer_type_node;
   14423      9058728 :           defaulted_int = 1;
   14424              :         }
   14425              :       /* If we just have "complex", it is equivalent to "complex double".  */
   14426     29271247 :       else if (!longlong && !explicit_intN
   14427     29271247 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14428              :         {
   14429           81 :           type = double_type_node;
   14430           81 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   14431              :                    "ISO C++ does not support plain %<complex%> meaning "
   14432              :                    "%<double complex%>");
   14433              :         }
   14434              :     }
   14435              :   /* Gather flags.  */
   14436   1029184769 :   explicit_int = declspecs->explicit_int_p;
   14437   1029184769 :   explicit_char = declspecs->explicit_char_p;
   14438              : 
   14439              : #if 0
   14440              :   /* See the code below that used this.  */
   14441              :   if (typedef_decl)
   14442              :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   14443              : #endif
   14444   1029184769 :   typedef_type = type;
   14445              : 
   14446   1029184769 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   14447      2194820 :     ctor_return_type = TREE_TYPE (dname);
   14448              :   else
   14449              :     ctor_return_type = ctype;
   14450              : 
   14451   1029184769 :   if (sfk != sfk_none)
   14452              :     {
   14453     29269622 :       type = check_special_function_return_type (sfk, type,
   14454              :                                                  ctor_return_type,
   14455              :                                                  type_quals,
   14456              :                                                  &declarator,
   14457              :                                                  declspecs->locations);
   14458     29269622 :       type_quals = TYPE_UNQUALIFIED;
   14459              :     }
   14460    999915147 :   else if (type == NULL_TREE)
   14461              :     {
   14462         1625 :       int is_main;
   14463              : 
   14464         1625 :       explicit_int = -1;
   14465              : 
   14466              :       /* We handle `main' specially here, because 'main () { }' is so
   14467              :          common.  With no options, it is allowed.  With -Wreturn-type,
   14468              :          it is a warning.  It is only an error with -pedantic-errors.  */
   14469         3250 :       is_main = (funcdef_flag
   14470         3484 :                  && dname && identifier_p (dname)
   14471          234 :                  && MAIN_NAME_P (dname)
   14472           68 :                  && ctype == NULL_TREE
   14473           68 :                  && in_namespace == NULL_TREE
   14474         1693 :                  && current_namespace == global_namespace);
   14475              : 
   14476         1625 :       if (type_was_error_mark_node)
   14477              :         /* We've already issued an error, don't complain more.  */;
   14478          400 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   14479              :         /* Allow it, sigh.  */;
   14480          338 :       else if (! is_main)
   14481          276 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   14482              :                    name);
   14483           62 :       else if (pedantic)
   14484            4 :         pedwarn (id_loc, OPT_Wpedantic,
   14485              :                  "ISO C++ forbids declaration of %qs with no type", name);
   14486              :       else
   14487           58 :         warning_at (id_loc, OPT_Wreturn_type,
   14488              :                     "ISO C++ forbids declaration of %qs with no type", name);
   14489              : 
   14490         1625 :       if (type_was_error_mark_node && template_parm_flag)
   14491              :         /* FIXME we should be able to propagate the error_mark_node as is
   14492              :            for other contexts too.  */
   14493          150 :         type = error_mark_node;
   14494              :       else
   14495         1475 :         type = integer_type_node;
   14496              :     }
   14497              : 
   14498   1029184769 :   ctype = NULL_TREE;
   14499              : 
   14500   1029184769 :   if (explicit_intN)
   14501              :     {
   14502      1100271 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   14503              :         {
   14504            0 :           error_at (declspecs->locations[ds_type_spec],
   14505              :                     "%<__int%d%> is not supported by this target",
   14506            0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   14507            0 :           explicit_intN = false;
   14508              :         }
   14509              :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   14510              :          of "__intN".  */
   14511      1100271 :       else if (!int_n_alt && pedantic)
   14512         9618 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   14513              :                  "ISO C++ does not support %<__int%d%> for %qs",
   14514         9618 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   14515              :     }
   14516              : 
   14517              :   /* Now process the modifiers that were specified
   14518              :      and check for invalid combinations.  */
   14519              : 
   14520              :   /* Long double is a special combination.  */
   14521   1029184769 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   14522              :     {
   14523      8774041 :       long_p = false;
   14524      8774041 :       type = cp_build_qualified_type (long_double_type_node,
   14525              :                                       cp_type_quals (type));
   14526              :     }
   14527              : 
   14528              :   /* Check all other uses of type modifiers.  */
   14529              : 
   14530   1029184769 :   if (unsigned_p || signed_p || long_p || short_p)
   14531              :     {
   14532     20938764 :       location_t loc;
   14533     20938764 :       const char *key;
   14534     20938764 :       if (unsigned_p)
   14535              :         {
   14536     14240177 :           key = "unsigned";
   14537     14240177 :           loc = declspecs->locations[ds_unsigned];
   14538              :         }
   14539      6698587 :       else if (signed_p)
   14540              :         {
   14541      1022840 :           key = "signed";
   14542      1022840 :           loc = declspecs->locations[ds_signed];
   14543              :         }
   14544      5675747 :       else if (longlong)
   14545              :         {
   14546      2212235 :           key = "long long";
   14547      2212235 :           loc = declspecs->locations[ds_long_long];
   14548              :         }
   14549      3463512 :       else if (long_p)
   14550              :         {
   14551      2910878 :           key = "long";
   14552      2910878 :           loc = declspecs->locations[ds_long];
   14553              :         }
   14554              :       else /* if (short_p) */
   14555              :         {
   14556       552634 :           key = "short";
   14557       552634 :           loc = declspecs->locations[ds_short];
   14558              :         }
   14559              : 
   14560     20938764 :       int ok = 0;
   14561              : 
   14562     20938764 :       if (signed_p && unsigned_p)
   14563           54 :         complain_about_incompatible_declspecs
   14564           54 :           ("signed", declspecs->locations[ds_signed],
   14565              :            "unsigned", declspecs->locations[ds_unsigned]);
   14566     20938710 :       else if (long_p && short_p)
   14567           12 :         complain_about_incompatible_declspecs
   14568           12 :           ("long", declspecs->locations[ds_long],
   14569              :            "short", declspecs->locations[ds_short]);
   14570     20938698 :       else if (TREE_CODE (type) != INTEGER_TYPE
   14571     20938685 :                || type == char8_type_node
   14572     20938661 :                || type == char16_type_node
   14573     20938637 :                || type == char32_type_node
   14574     20938613 :                || ((long_p || short_p)
   14575     10999721 :                    && (explicit_char || explicit_intN)))
   14576          418 :         error_at (loc, "%qs specified with %qT", key, type);
   14577     20938280 :       else if (!explicit_int && !defaulted_int
   14578     20938280 :                && !explicit_char && !explicit_intN)
   14579              :         {
   14580           30 :           if (typedef_decl)
   14581              :             {
   14582           27 :               pedwarn (loc, OPT_Wpedantic,
   14583              :                        "%qs specified with typedef-name %qD",
   14584              :                        key, typedef_decl);
   14585           27 :               ok = !flag_pedantic_errors;
   14586              :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   14587              :                  and is not built as a typedef.  */
   14588           27 :               if (is_typedef_decl (typedef_decl))
   14589           18 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   14590              :             }
   14591            3 :           else if (declspecs->decltype_p)
   14592            0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   14593              :           else
   14594            3 :             error_at (loc, "%qs specified with %<typeof%>", key);
   14595              :         }
   14596              :       else
   14597              :         ok = 1;
   14598              : 
   14599              :       /* Discard the type modifiers if they are invalid.  */
   14600          514 :       if (! ok)
   14601              :         {
   14602              :           unsigned_p = false;
   14603              :           signed_p = false;
   14604              :           long_p = false;
   14605              :           short_p = false;
   14606              :           longlong = 0;
   14607              :         }
   14608              :     }
   14609              : 
   14610              :   /* Decide whether an integer type is signed or not.
   14611              :      Optionally treat bitfields as signed by default.  */
   14612   1029184279 :   if (unsigned_p
   14613              :       /* [class.bit]
   14614              : 
   14615              :          It is implementation-defined whether a plain (neither
   14616              :          explicitly signed or unsigned) char, short, int, or long
   14617              :          bit-field is signed or unsigned.
   14618              : 
   14619              :          Naturally, we extend this to long long as well.  Note that
   14620              :          this does not include wchar_t.  */
   14621   1029184769 :       || (bitfield && !flag_signed_bitfields
   14622           18 :           && !signed_p
   14623              :           /* A typedef for plain `int' without `signed' can be
   14624              :              controlled just like plain `int', but a typedef for
   14625              :              `signed int' cannot be so controlled.  */
   14626           18 :           && !(typedef_decl
   14627           18 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   14628           13 :           && TREE_CODE (type) == INTEGER_TYPE
   14629           10 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   14630              :     {
   14631     14239962 :       if (explicit_intN)
   14632       519967 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   14633     13719995 :       else if (longlong)
   14634      1407065 :         type = long_long_unsigned_type_node;
   14635     12312930 :       else if (long_p)
   14636      2311019 :         type = long_unsigned_type_node;
   14637     10001911 :       else if (short_p)
   14638      1398001 :         type = short_unsigned_type_node;
   14639      8603910 :       else if (type == char_type_node)
   14640      1873596 :         type = unsigned_char_type_node;
   14641      6730314 :       else if (typedef_decl)
   14642           25 :         type = c_common_unsigned_type (type);
   14643              :       else
   14644      6730289 :         type = unsigned_type_node;
   14645              :     }
   14646   1014944807 :   else if (signed_p && type == char_type_node)
   14647       671188 :     type = signed_char_type_node;
   14648   1014273619 :   else if (explicit_intN)
   14649       580304 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   14650   1013693315 :   else if (longlong)
   14651      2275148 :     type = long_long_integer_type_node;
   14652   1011418167 :   else if (long_p)
   14653      2978032 :     type = long_integer_type_node;
   14654   1008440135 :   else if (short_p)
   14655       630123 :     type = short_integer_type_node;
   14656   1007810012 :   else if (signed_p && typedef_decl)
   14657            9 :     type = c_common_signed_type (type);
   14658              : 
   14659   1029184769 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   14660              :     {
   14661      1179472 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   14662            3 :         error_at (declspecs->locations[ds_complex],
   14663              :                   "complex invalid for %qs", name);
   14664              :       /* If a modifier is specified, the resulting complex is the complex
   14665              :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   14666      1179469 :       else if (type == integer_type_node)
   14667          171 :         type = complex_integer_type_node;
   14668      1179298 :       else if (type == float_type_node)
   14669       335417 :         type = complex_float_type_node;
   14670       843881 :       else if (type == double_type_node)
   14671       335955 :         type = complex_double_type_node;
   14672       507926 :       else if (type == long_double_type_node)
   14673       335458 :         type = complex_long_double_type_node;
   14674              :       else
   14675       172468 :         type = build_complex_type (type);
   14676              :     }
   14677              : 
   14678              :   /* If we're using the injected-class-name to form a compound type or a
   14679              :      declaration, replace it with the underlying class so we don't get
   14680              :      redundant typedefs in the debug output.  But if we are returning the
   14681              :      type unchanged, leave it alone so that it's available to
   14682              :      maybe_get_template_decl_from_type_decl.  */
   14683    202116707 :   if (CLASS_TYPE_P (type)
   14684    202055001 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   14685     34412347 :       && type == TREE_TYPE (TYPE_NAME (type))
   14686   1063597116 :       && (declarator || type_quals))
   14687     32894319 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   14688              : 
   14689   1029184769 :   type_quals |= cp_type_quals (type);
   14690   2058369538 :   type = cp_build_qualified_type
   14691   2058369538 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   14692    833989144 :                           || declspecs->decltype_p)
   14693              :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   14694              :   /* We might have ignored or rejected some of the qualifiers.  */
   14695   1029184769 :   type_quals = cp_type_quals (type);
   14696              : 
   14697   1014012153 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   14698     22178354 :       && innermost_code != cdk_function
   14699              :       /* Placeholder in parm gets a better error below.  */
   14700     13866038 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   14701   1043019777 :       && id_declarator && declarator != id_declarator)
   14702      1146877 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   14703              :       {
   14704           16 :         auto_diagnostic_group g;
   14705           16 :         gcc_rich_location richloc (typespec_loc);
   14706           16 :         richloc.add_fixit_insert_after ("<>");
   14707           16 :         error_at (&richloc, "missing template argument list after %qE; "
   14708              :                   "for deduction, template placeholder must be followed "
   14709              :                   "by a simple declarator-id", tmpl);
   14710           16 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   14711           16 :         type = error_mark_node;
   14712           16 :       }
   14713              : 
   14714   1029184769 :   staticp = 0;
   14715   1029184769 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   14716   1029184769 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   14717   1029184769 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   14718              : 
   14719   1029184769 :   storage_class = declspecs->storage_class;
   14720   1029184769 :   if (storage_class == sc_static)
   14721     23578285 :     staticp = 1 + (decl_context == FIELD);
   14722   1005606484 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   14723              :     /* Treat class-scope deduction guides as static member functions
   14724              :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   14725     23257121 :     staticp = 2;
   14726              : 
   14727   1029184769 :   if (virtualp)
   14728              :     {
   14729      4061288 :       if (staticp == 2)
   14730              :         {
   14731           21 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14732           21 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   14733           21 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   14734              :                     "and %<static%>", dname);
   14735           21 :           storage_class = sc_none;
   14736           21 :           staticp = 0;
   14737           21 :         }
   14738      4061288 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   14739              :         {
   14740            6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   14741            6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   14742            6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   14743              :                    "declared both %<virtual%> and %<constexpr%> only in "
   14744              :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   14745            6 :         }
   14746              :     }
   14747   1029184769 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   14748              : 
   14749              :   /* Issue errors about use of storage classes for parameters.  */
   14750   1029184769 :   if (decl_context == PARM)
   14751              :     {
   14752    291067634 :       if (typedef_p)
   14753              :         {
   14754           24 :           error_at (declspecs->locations[ds_typedef],
   14755              :                     "typedef declaration invalid in parameter declaration");
   14756           24 :           return error_mark_node;
   14757              :         }
   14758    291067610 :       else if (template_parm_flag && storage_class != sc_none)
   14759              :         {
   14760           16 :           error_at (min_location (declspecs->locations[ds_thread],
   14761              :                                   declspecs->locations[ds_storage_class]),
   14762              :                     "storage class specified for template parameter %qs",
   14763              :                     name);
   14764           16 :           return error_mark_node;
   14765              :         }
   14766    291067594 :       else if (storage_class == sc_static
   14767    291067594 :                || storage_class == sc_extern
   14768    291067591 :                || thread_p)
   14769              :         {
   14770            9 :           error_at (min_location (declspecs->locations[ds_thread],
   14771              :                                   declspecs->locations[ds_storage_class]),
   14772              :                     "storage class specified for parameter %qs", name);
   14773            9 :           return error_mark_node;
   14774              :         }
   14775              : 
   14776              :       /* Function parameters cannot be concept. */
   14777    291067585 :       if (concept_p)
   14778              :         {
   14779            9 :           error_at (declspecs->locations[ds_concept],
   14780              :                     "a parameter cannot be declared %qs", "concept");
   14781            9 :           concept_p = 0;
   14782            9 :           constexpr_p = 0;
   14783              :         }
   14784              :       /* Function parameters cannot be constexpr.  If we saw one, moan
   14785              :          and pretend it wasn't there.  */
   14786    291067576 :       else if (constexpr_p)
   14787              :         {
   14788            9 :           error_at (declspecs->locations[ds_constexpr],
   14789              :                     "a parameter cannot be declared %qs", "constexpr");
   14790            9 :           constexpr_p = 0;
   14791              :         }
   14792    291067585 :       if (constinit_p)
   14793              :         {
   14794            6 :           error_at (declspecs->locations[ds_constinit],
   14795              :                     "a parameter cannot be declared %qs", "constinit");
   14796            6 :           constinit_p = 0;
   14797              :         }
   14798    291067585 :       if (consteval_p)
   14799              :         {
   14800            3 :           error_at (declspecs->locations[ds_consteval],
   14801              :                     "a parameter cannot be declared %qs", "consteval");
   14802            3 :           consteval_p = 0;
   14803              :         }
   14804              :     }
   14805              : 
   14806              :   /* Give error if `virtual' is used outside of class declaration.  */
   14807   1029184720 :   if (virtualp
   14808      4061288 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   14809              :     {
   14810           68 :       error_at (declspecs->locations[ds_virtual],
   14811              :                 "%<virtual%> outside class declaration");
   14812           68 :       virtualp = 0;
   14813              :     }
   14814              : 
   14815   1029184720 :   if (innermost_code == cdk_decomp)
   14816              :     {
   14817       220226 :       location_t loc = (declarator->kind == cdk_reference
   14818       230024 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   14819       230024 :       if (inlinep)
   14820           29 :         error_at (declspecs->locations[ds_inline],
   14821              :                   "structured binding declaration cannot be %qs", "inline");
   14822       230024 :       if (typedef_p)
   14823           29 :         error_at (declspecs->locations[ds_typedef],
   14824              :                   "structured binding declaration cannot be %qs", "typedef");
   14825       230024 :       if (constexpr_p && !concept_p && cxx_dialect < cxx26)
   14826           99 :         pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
   14827              :                  "structured binding declaration can be %qs only with "
   14828              :                  "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
   14829       230024 :       if (consteval_p)
   14830           13 :         error_at (declspecs->locations[ds_consteval], "structured "
   14831              :                   "binding declaration cannot be %qs", "consteval");
   14832       230024 :       if (thread_p && cxx_dialect < cxx20)
   14833           75 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   14834              :                  "structured binding declaration can be %qs only in "
   14835              :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   14836           75 :                  declspecs->gnu_thread_keyword_p
   14837              :                  ? "__thread" : "thread_local");
   14838       230024 :       if (concept_p)
   14839              :         {
   14840            0 :           error_at (declspecs->locations[ds_concept],
   14841              :                     "structured binding declaration cannot be %qs", "concept");
   14842            0 :           constexpr_p = 0;
   14843              :         }
   14844              :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   14845       230024 :       if (type_quals & TYPE_QUAL_VOLATILE)
   14846           26 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   14847              :                     "%<volatile%>-qualified structured binding is deprecated");
   14848       230024 :       switch (storage_class)
   14849              :         {
   14850              :         case sc_none:
   14851              :           break;
   14852           28 :         case sc_register:
   14853           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   14854              :                     "register");
   14855           28 :           break;
   14856          247 :         case sc_static:
   14857          247 :           if (cxx_dialect < cxx20)
   14858          185 :             pedwarn (loc, OPT_Wc__20_extensions,
   14859              :                      "structured binding declaration can be %qs only in "
   14860              :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   14861              :           break;
   14862           29 :         case sc_extern:
   14863           29 :           error_at (loc, "structured binding declaration cannot be %qs",
   14864              :                     "extern");
   14865           29 :           break;
   14866           28 :         case sc_mutable:
   14867           28 :           error_at (loc, "structured binding declaration cannot be %qs",
   14868              :                     "mutable");
   14869           28 :           break;
   14870            0 :         case sc_auto:
   14871            0 :           error_at (loc, "structured binding declaration cannot be "
   14872              :                     "C++98 %<auto%>");
   14873            0 :           break;
   14874            0 :         default:
   14875            0 :           gcc_unreachable ();
   14876              :         }
   14877       230024 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   14878       230024 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   14879              :         {
   14880            3 :           if (type != error_mark_node)
   14881              :             {
   14882            3 :               auto_diagnostic_group d;
   14883            3 :               error_at (loc, "structured binding declaration cannot have "
   14884              :                         "type %qT", type);
   14885            3 :               inform (loc,
   14886              :                       "type must be cv-qualified %<auto%> or reference to "
   14887              :                       "cv-qualified %<auto%>");
   14888            3 :             }
   14889            3 :           type = build_qualified_type (make_auto (), type_quals);
   14890            3 :           declspecs->type = type;
   14891              :         }
   14892       230021 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   14893           51 :         pedwarn (loc, OPT_Wpedantic,
   14894              :                  "structured binding declaration cannot have constrained "
   14895              :                  "%<auto%> type %qT", type);
   14896       230024 :       inlinep = 0;
   14897       230024 :       typedef_p = 0;
   14898       230024 :       consteval_p = 0;
   14899       230024 :       concept_p = 0;
   14900       230024 :       if (storage_class != sc_static)
   14901              :         {
   14902       229777 :           storage_class = sc_none;
   14903       229777 :           declspecs->storage_class = sc_none;
   14904              :         }
   14905              :     }
   14906              : 
   14907              :   /* Static anonymous unions are dealt with here.  */
   14908   1029184720 :   if (staticp && decl_context == TYPENAME
   14909            0 :       && declspecs->type
   14910   1029184720 :       && ANON_AGGR_TYPE_P (declspecs->type))
   14911              :     decl_context = FIELD;
   14912              : 
   14913              :   /* Warn about storage classes that are invalid for certain
   14914              :      kinds of declarations (parameters, typenames, etc.).  */
   14915   1029184720 :   if (thread_p
   14916        19851 :       && ((storage_class
   14917        19851 :            && storage_class != sc_extern
   14918          528 :            && storage_class != sc_static)
   14919        19840 :           || typedef_p))
   14920              :     {
   14921           17 :       location_t loc
   14922           17 :         = min_location (declspecs->locations[ds_thread],
   14923              :                         declspecs->locations[ds_storage_class]);
   14924           17 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   14925           17 :       thread_p = false;
   14926              :     }
   14927   1029184720 :   if (decl_context != NORMAL
   14928    862395892 :       && ((storage_class != sc_none
   14929    862395892 :            && storage_class != sc_mutable)
   14930    839138785 :           || thread_p))
   14931              :     {
   14932     23257110 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   14933           36 :           && (storage_class == sc_register
   14934           36 :               || storage_class == sc_auto))
   14935              :         ;
   14936     23257074 :       else if (typedef_p)
   14937              :         ;
   14938     23257074 :       else if (decl_context == FIELD
   14939              :                /* C++ allows static class elements.  */
   14940     23257074 :                && storage_class == sc_static)
   14941              :         /* C++ also allows inlines and signed and unsigned elements,
   14942              :            but in those cases we don't come in here.  */
   14943              :         ;
   14944              :       else
   14945              :         {
   14946           15 :           location_t loc
   14947           15 :             = min_location (declspecs->locations[ds_thread],
   14948              :                             declspecs->locations[ds_storage_class]);
   14949           15 :           if (decl_context == FIELD)
   14950           15 :             error_at (loc, "storage class specified for %qs", name);
   14951            0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   14952            0 :             error_at (loc, "storage class specified for parameter %qs", name);
   14953              :           else
   14954            0 :             error_at (loc, "storage class specified for typename");
   14955           15 :           if (storage_class == sc_register
   14956           15 :               || storage_class == sc_auto
   14957           15 :               || storage_class == sc_extern
   14958            3 :               || thread_p)
   14959           15 :             storage_class = sc_none;
   14960              :         }
   14961              :     }
   14962   1005927610 :   else if (storage_class == sc_extern && funcdef_flag
   14963   1005927610 :            && ! toplevel_bindings_p ())
   14964            0 :     error ("nested function %qs declared %<extern%>", name);
   14965   1005927610 :   else if (toplevel_bindings_p ())
   14966              :     {
   14967    468301300 :       if (storage_class == sc_auto)
   14968            2 :         error_at (declspecs->locations[ds_storage_class],
   14969              :                   "top-level declaration of %qs specifies %<auto%>", name);
   14970              :     }
   14971    537626310 :   else if (thread_p
   14972    537626310 :            && storage_class != sc_extern
   14973          243 :            && storage_class != sc_static)
   14974              :     {
   14975          210 :       if (declspecs->gnu_thread_keyword_p)
   14976           49 :         pedwarn (declspecs->locations[ds_thread],
   14977           49 :                  0, "function-scope %qs implicitly auto and "
   14978              :                  "declared %<__thread%>", name);
   14979              : 
   14980              :       /* When thread_local is applied to a variable of block scope the
   14981              :          storage-class-specifier static is implied if it does not appear
   14982              :          explicitly.  */
   14983          210 :       storage_class = declspecs->storage_class = sc_static;
   14984          210 :       staticp = 1;
   14985              :     }
   14986              : 
   14987   1029184720 :   if (storage_class && friendp)
   14988              :     {
   14989           12 :       error_at (min_location (declspecs->locations[ds_thread],
   14990              :                               declspecs->locations[ds_storage_class]),
   14991              :                 "storage class specifiers invalid in friend function "
   14992              :                 "declarations");
   14993           12 :       storage_class = sc_none;
   14994           12 :       staticp = 0;
   14995              :     }
   14996              : 
   14997   1029184720 :   if (!id_declarator)
   14998              :     unqualified_id = NULL_TREE;
   14999              :   else
   15000              :     {
   15001    579506464 :       unqualified_id = id_declarator->u.id.unqualified_name;
   15002    579506464 :       switch (TREE_CODE (unqualified_id))
   15003              :         {
   15004      3212060 :         case BIT_NOT_EXPR:
   15005      3212060 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   15006      3212060 :           if (TYPE_P (unqualified_id))
   15007      3212057 :             unqualified_id = constructor_name (unqualified_id);
   15008              :           break;
   15009              : 
   15010              :         case IDENTIFIER_NODE:
   15011              :         case TEMPLATE_ID_EXPR:
   15012              :           break;
   15013              : 
   15014            0 :         default:
   15015            0 :           gcc_unreachable ();
   15016              :         }
   15017              :     }
   15018              : 
   15019   1029184720 :   if (declspecs->std_attributes)
   15020              :     {
   15021          741 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   15022          741 :       auto_diagnostic_group d;
   15023          741 :       if (any_nonignored_attribute_p (declspecs->std_attributes)
   15024          741 :           && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   15025          738 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   15026              :                 "is ignored");
   15027          741 :     }
   15028              : 
   15029              :   /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn.  */
   15030              :   bool is_xobj_member_function = false;
   15031              :   /* Determine the type of the entity declared by recurring on the
   15032              :      declarator.  */
   15033   1413158917 :   for (; declarator; declarator = declarator->declarator)
   15034              :     {
   15035    963710711 :       const cp_declarator *inner_declarator;
   15036    963710711 :       tree attrs;
   15037              : 
   15038    963710711 :       if (type == error_mark_node)
   15039          607 :         return error_mark_node;
   15040              : 
   15041    963710383 :       attrs = declarator->attributes;
   15042    963710383 :       if (attrs)
   15043              :         {
   15044        13299 :           int attr_flags;
   15045              : 
   15046        13299 :           attr_flags = 0;
   15047        13299 :           if (declarator->kind == cdk_id)
   15048        12590 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   15049        13299 :           if (declarator->kind == cdk_function)
   15050          692 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   15051        13299 :           if (declarator->kind == cdk_array)
   15052            2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   15053        13299 :           tree late_attrs = NULL_TREE;
   15054        13299 :           if (decl_context != PARM && decl_context != TYPENAME)
   15055              :             /* Assume that any attributes that get applied late to
   15056              :                templates will DTRT when applied to the declaration
   15057              :                as a whole.  */
   15058        13287 :             late_attrs = splice_template_attributes (&attrs, type);
   15059        13299 :           returned_attrs = decl_attributes (&type,
   15060              :                                             attr_chainon (returned_attrs,
   15061              :                                                           attrs),
   15062              :                                             attr_flags);
   15063        13299 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   15064              :         }
   15065              : 
   15066    963710383 :       inner_declarator = declarator->declarator;
   15067              : 
   15068              :       /* We don't want to warn in parameter context because we don't
   15069              :          yet know if the parse will succeed, and this might turn out
   15070              :          to be a constructor call.  */
   15071    963710383 :       if (decl_context != PARM
   15072    963710383 :           && decl_context != TYPENAME
   15073    559617590 :           && !typedef_p
   15074    511721132 :           && declarator->parenthesized != UNKNOWN_LOCATION
   15075              :           /* If the type is class-like and the inner name used a
   15076              :              global namespace qualifier, we need the parens.
   15077              :              Unfortunately all we can tell is whether a qualified name
   15078              :              was used or not.  */
   15079    963710564 :           && !(inner_declarator
   15080          126 :                && inner_declarator->kind == cdk_id
   15081          108 :                && inner_declarator->u.id.qualifying_scope
   15082           18 :                && (MAYBE_CLASS_TYPE_P (type)
   15083           12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   15084              :         {
   15085          169 :           auto_diagnostic_group d;
   15086          169 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   15087              :                           "unnecessary parentheses in declaration of %qs",
   15088              :                           name))
   15089              :             {
   15090           42 :               gcc_rich_location iloc (declarator->parenthesized);
   15091           42 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   15092           42 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   15093           42 :               inform (&iloc, "remove parentheses");
   15094           42 :             }
   15095          169 :         }
   15096    963710383 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   15097              :         break;
   15098              : 
   15099    383974476 :       switch (declarator->kind)
   15100              :         {
   15101      3567732 :         case cdk_array:
   15102      7135464 :           type = create_array_type_for_decl (dname, type,
   15103      3567732 :                                              declarator->u.array.bounds,
   15104      3567732 :                                              declarator->id_loc);
   15105      3567732 :           if (!valid_array_size_p (dname
   15106              :                                    ? declarator->id_loc : input_location,
   15107              :                                    type, dname))
   15108          267 :             type = error_mark_node;
   15109              : 
   15110      3567732 :           if (declarator->std_attributes)
   15111              :             /* [dcl.array]/1:
   15112              : 
   15113              :                The optional attribute-specifier-seq appertains to the
   15114              :                array type.  */
   15115          197 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15116              :           break;
   15117              : 
   15118    188463974 :         case cdk_function:
   15119    188463974 :           {
   15120    188463974 :             tree arg_types;
   15121    188463974 :             int funcdecl_p;
   15122              : 
   15123              :             /* Declaring a function type.  */
   15124              : 
   15125              :             /* Pick up type qualifiers which should be applied to `this'.  */
   15126    188463974 :             memfn_quals = declarator->u.function.qualifiers;
   15127              :             /* Pick up virt-specifiers.  */
   15128    188463974 :             virt_specifiers = declarator->u.function.virt_specifiers;
   15129              :             /* And ref-qualifier, too */
   15130    188463974 :             rqual = declarator->u.function.ref_qualifier;
   15131              :             /* And tx-qualifier.  */
   15132    188463974 :             tree tx_qual = declarator->u.function.tx_qualifier;
   15133              :             /* Pick up the exception specifications.  */
   15134    188463974 :             raises = declarator->u.function.exception_specification;
   15135              :             /* If the exception-specification is ill-formed, let's pretend
   15136              :                there wasn't one.  */
   15137    188463974 :             if (raises == error_mark_node)
   15138            9 :               raises = NULL_TREE;
   15139              : 
   15140    376927948 :             auto find_xobj_parm = [](tree parm_list)
   15141              :               {
   15142              :                 /* There is no need to iterate over the list,
   15143              :                    only the first parm can be a valid xobj parm.  */
   15144    376702166 :                 if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
   15145              :                   return NULL_TREE;
   15146              :                 /* If we make it here, we are looking at an xobj parm.
   15147              : 
   15148              :                    Non-null 'purpose' usually means the parm has a default
   15149              :                    argument, we don't want to violate this assumption.  */
   15150        83644 :                 TREE_PURPOSE (parm_list) = NULL_TREE;
   15151        83644 :                 return TREE_VALUE (parm_list);
   15152              :               };
   15153              : 
   15154    188463974 :             tree xobj_parm
   15155    188463974 :               = find_xobj_parm (declarator->u.function.parameters);
   15156    188463974 :             is_xobj_member_function = xobj_parm;
   15157              : 
   15158    188463974 :             if (xobj_parm && cxx_dialect < cxx23)
   15159        41806 :               pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
   15160              :                        "explicit object member function only available "
   15161              :                        "with %<-std=c++23%> or %<-std=gnu++23%>");
   15162              : 
   15163    188463974 :             if (xobj_parm && decl_context == TYPENAME)
   15164              :               {
   15165              :                 /* We inform in every case, just differently depending on what
   15166              :                    case it is.  */
   15167            9 :                 auto_diagnostic_group d;
   15168            9 :                 bool ptr_type = true;
   15169              :                 /* If declarator->kind is cdk_function and we are at the end of
   15170              :                    the declarator chain, we are looking at a function type.  */
   15171            9 :                 if (!declarator->declarator)
   15172              :                   {
   15173            3 :                     error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15174              :                               "a function type cannot "
   15175              :                               "have an explicit object parameter");
   15176            3 :                     ptr_type = false;
   15177              :                   }
   15178            6 :                 else if (declarator->declarator->kind == cdk_pointer)
   15179            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15180              :                             "a pointer to function type cannot "
   15181              :                             "have an explicit object parameter");
   15182            3 :                 else if (declarator->declarator->kind == cdk_ptrmem)
   15183            3 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15184              :                             "a pointer to member function type "
   15185              :                             "cannot have an explicit object parameter");
   15186              :                 else
   15187            0 :                   gcc_unreachable ();
   15188              : 
   15189              :                 /* The locations being used here are probably not correct.  */
   15190            6 :                 if (ptr_type)
   15191            6 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15192              :                           "the type of a pointer to explicit object member "
   15193              :                           "function is a regular pointer to function type");
   15194              :                 else
   15195            3 :                   inform (DECL_SOURCE_LOCATION (xobj_parm),
   15196              :                           "the type of an explicit object "
   15197              :                           "member function is a regular function type");
   15198              :                 /* Ideally we should synthesize the correct syntax
   15199              :                    for the user, perhaps this could be added later.  */
   15200            9 :               }
   15201              :             /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
   15202              :                the first parm node will never erroneously be detected here.  */
   15203    188463974 :             {
   15204    188463974 :               auto_diagnostic_group d;
   15205    188463974 :               bool bad_xobj_parm_encountered = false;
   15206    188463974 :               for (tree parm = declarator->u.function.parameters;
   15207    467735861 :                    parm && parm != void_list_node;
   15208    279271887 :                    parm = TREE_CHAIN (parm))
   15209              :                 {
   15210    279271887 :                   if (TREE_PURPOSE (parm) != this_identifier)
   15211    279271878 :                     continue;
   15212            9 :                   bad_xobj_parm_encountered = true;
   15213            9 :                   TREE_PURPOSE (parm) = NULL_TREE;
   15214            9 :                   gcc_rich_location bad_xobj_parm
   15215            9 :                     (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
   15216            9 :                   error_at (&bad_xobj_parm,
   15217              :                             "only the first parameter of a member function "
   15218              :                             "can be declared as an explicit object parameter");
   15219            9 :                 }
   15220    188463974 :               if (bad_xobj_parm_encountered && xobj_parm)
   15221            0 :                 inform (DECL_SOURCE_LOCATION (xobj_parm),
   15222              :                         "valid explicit object parameter declared here");
   15223    188463974 :             }
   15224              : 
   15225    188463974 :             if (reqs)
   15226            3 :               error_at (location_of (reqs), "requires-clause on return type");
   15227    188463974 :             reqs = declarator->u.function.requires_clause;
   15228              : 
   15229              :             /* Say it's a definition only for the CALL_EXPR
   15230              :                closest to the identifier.  */
   15231    188463974 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   15232              : 
   15233              :             /* Handle a late-specified return type.  */
   15234    188463974 :             tree late_return_type = declarator->u.function.late_return_type;
   15235    188463974 :             if (tree auto_node = type_uses_auto (type))
   15236              :               {
   15237      8324063 :                 if (!late_return_type)
   15238              :                   {
   15239      4782594 :                     if (!funcdecl_p)
   15240              :                       /* auto (*fp)() = f; is OK.  */;
   15241      4782560 :                     else if (current_class_type
   15242      8775651 :                              && LAMBDA_TYPE_P (current_class_type))
   15243              :                       /* OK for C++11 lambdas.  */;
   15244      3137703 :                     else if (cxx_dialect < cxx14)
   15245              :                       {
   15246            7 :                         auto_diagnostic_group d;
   15247            7 :                         error_at (typespec_loc, "%qs function uses "
   15248              :                                   "%<auto%> type specifier without "
   15249              :                                   "trailing return type", name);
   15250            7 :                         inform (typespec_loc,
   15251              :                                 "deduced return type only available "
   15252              :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   15253            7 :                       }
   15254      3137696 :                     else if (virtualp)
   15255              :                       {
   15256            6 :                         error_at (typespec_loc, "virtual function "
   15257              :                                   "cannot have deduced return type");
   15258            6 :                         virtualp = false;
   15259              :                       }
   15260              :                   }
   15261      3541469 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   15262              :                   {
   15263           15 :                     error_at (typespec_loc, "%qs function with trailing "
   15264              :                               "return type has %qT as its type rather "
   15265              :                               "than plain %<auto%>", name, type);
   15266          276 :                     return error_mark_node;
   15267              :                   }
   15268      3541454 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   15269              :                   {
   15270            9 :                     if (funcdecl_p)
   15271            3 :                       error_at (typespec_loc,
   15272              :                                 "%qs function with trailing return type "
   15273              :                                 "has %<decltype(auto)%> as its type "
   15274              :                                 "rather than plain %<auto%>", name);
   15275              :                     else
   15276            6 :                       error_at (typespec_loc,
   15277              :                                 "invalid use of %<decltype(auto)%>");
   15278            9 :                     return error_mark_node;
   15279              :                   }
   15280      3541445 :                 else if (is_constrained_auto (type))
   15281              :                   {
   15282            6 :                     if (funcdecl_p)
   15283            3 :                       error_at (typespec_loc,
   15284              :                                 "%qs function with trailing return type "
   15285              :                                 "has constrained %<auto%> type specifier "
   15286              :                                 "rather than plain %<auto%>",
   15287              :                                 name);
   15288              :                     else
   15289            3 :                       error_at (typespec_loc,
   15290              :                                 "invalid use of constrained %<auto%> type");
   15291            6 :                     return error_mark_node;
   15292              :                   }
   15293      8324033 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   15294      8324033 :                 if (!tmpl)
   15295      7137125 :                   if (tree late_auto = type_uses_auto (late_return_type))
   15296        36124 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   15297      7137125 :                 if (tmpl)
   15298              :                   {
   15299      1186914 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   15300              :                       {
   15301           13 :                         auto_diagnostic_group g;
   15302           13 :                         error_at (typespec_loc, "deduced class "
   15303              :                                   "type %qD in function return type",
   15304           13 :                                   DECL_NAME (tmpl));
   15305           13 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15306              :                                 "%qD declared here", tmpl);
   15307           13 :                         return error_mark_node;
   15308           13 :                       }
   15309      1186901 :                     else if (!late_return_type)
   15310              :                       {
   15311            3 :                         auto_diagnostic_group d;
   15312            3 :                         error_at (declarator->id_loc, "deduction guide "
   15313              :                                   "for %qT must have trailing return "
   15314            3 :                                   "type", TREE_TYPE (tmpl));
   15315            3 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   15316              :                                 "%qD declared here", tmpl);
   15317            3 :                         return error_mark_node;
   15318            3 :                       }
   15319      1186898 :                     else if (CLASS_TYPE_P (late_return_type)
   15320      1186898 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   15321      2373796 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   15322              :                                   == tmpl))
   15323              :                       /* OK */;
   15324              :                     else
   15325            0 :                       error ("trailing return type %qT of deduction guide "
   15326              :                               "is not a specialization of %qT",
   15327            0 :                               late_return_type, TREE_TYPE (tmpl));
   15328              :                   }
   15329              :               }
   15330    180139911 :             else if (late_return_type
   15331    180139911 :                      && sfk != sfk_conversion)
   15332              :               {
   15333           37 :                 if (late_return_type == error_mark_node)
   15334              :                   return error_mark_node;
   15335           37 :                 if (cxx_dialect < cxx11)
   15336              :                   /* Not using maybe_warn_cpp0x because this should
   15337              :                      always be an error.  */
   15338            1 :                   error_at (typespec_loc,
   15339              :                             "trailing return type only available "
   15340              :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   15341              :                 else
   15342           36 :                   error_at (typespec_loc, "%qs function with trailing "
   15343              :                             "return type not declared with %<auto%> "
   15344              :                             "type specifier", name);
   15345           37 :                 return error_mark_node;
   15346              :               }
   15347    188463891 :             if (late_return_type && sfk == sfk_conversion)
   15348              :               {
   15349           14 :                 error ("a conversion function cannot have a trailing return type");
   15350           14 :                 return error_mark_node;
   15351              :               }
   15352    188463877 :             type = splice_late_return_type (type, late_return_type);
   15353    188463877 :             if (type == error_mark_node)
   15354              :               return error_mark_node;
   15355              : 
   15356    188463799 :             if (late_return_type)
   15357              :               {
   15358      3541347 :                 late_return_type_p = true;
   15359      3541347 :                 type_quals = cp_type_quals (type);
   15360              :               }
   15361              : 
   15362    188463799 :             if (type_quals != TYPE_UNQUALIFIED)
   15363              :               {
   15364              :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   15365              :                    warning for
   15366              :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   15367              :                     because there the qualifier matters.  */
   15368        11757 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   15369          232 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   15370              :                               "qualifiers ignored on function return type");
   15371              :                 /* [dcl.fct] "A volatile-qualified return type is
   15372              :                    deprecated."  */
   15373        11757 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   15374          599 :                   warning_at (typespec_loc, OPT_Wvolatile,
   15375              :                               "%<volatile%>-qualified return type is "
   15376              :                               "deprecated");
   15377              : 
   15378              :                 /* We now know that the TYPE_QUALS don't apply to the
   15379              :                    decl, but to its return type.  */
   15380              :                 type_quals = TYPE_UNQUALIFIED;
   15381              :               }
   15382              : 
   15383              :             /* Error about some types functions can't return.  */
   15384              : 
   15385    188463799 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   15386              :               {
   15387           30 :                 error_at (typespec_loc, "%qs declared as function returning "
   15388              :                           "a function", name);
   15389           30 :                 return error_mark_node;
   15390              :               }
   15391    188463769 :             if (TREE_CODE (type) == ARRAY_TYPE)
   15392              :               {
   15393            6 :                 error_at (typespec_loc, "%qs declared as function returning "
   15394              :                           "an array", name);
   15395            6 :                 return error_mark_node;
   15396              :               }
   15397    188463763 :             if (constinit_p && funcdecl_p)
   15398              :               {
   15399           15 :                 error_at (declspecs->locations[ds_constinit],
   15400              :                           "%<constinit%> on function return type is not "
   15401              :                           "allowed");
   15402           15 :                 return error_mark_node;
   15403              :               }
   15404              : 
   15405    188463748 :             if (check_decltype_auto (typespec_loc, type))
   15406           50 :               return error_mark_node;
   15407              : 
   15408    188463698 :             if (ctype == NULL_TREE
   15409    188463698 :                 && decl_context == FIELD
   15410              :                 && funcdecl_p
   15411    108633868 :                 && friendp == 0)
   15412    101970299 :               ctype = current_class_type;
   15413              : 
   15414    188463698 :             if (ctype && (sfk == sfk_constructor
   15415    101970299 :                           || sfk == sfk_destructor))
   15416              :               {
   15417              :                 /* We are within a class's scope. If our declarator name
   15418              :                    is the same as the class name, and we are defining
   15419              :                    a function, then it is a constructor/destructor, and
   15420              :                    therefore returns a void type.  */
   15421              : 
   15422              :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   15423              :                    const or volatile.  A destructor may not be static.
   15424              :                    A destructor may not be declared with ref-qualifier.
   15425              : 
   15426              :                    ISO C++ 12.1.  A constructor may not be declared
   15427              :                    const or volatile.  A constructor may not be
   15428              :                    virtual.  A constructor may not be static.
   15429              :                    A constructor may not be declared with ref-qualifier. */
   15430     26131503 :                 if (staticp == 2)
   15431            9 :                   error_at (declspecs->locations[ds_storage_class],
   15432              :                             (flags == DTOR_FLAG)
   15433              :                             ? G_("destructor cannot be static member "
   15434              :                                  "function")
   15435              :                             : G_("constructor cannot be static member "
   15436              :                                  "function"));
   15437     26131503 :                 if (memfn_quals)
   15438              :                   {
   15439            9 :                     error ((flags == DTOR_FLAG)
   15440              :                            ? G_("destructors may not be cv-qualified")
   15441              :                            : G_("constructors may not be cv-qualified"));
   15442            9 :                     memfn_quals = TYPE_UNQUALIFIED;
   15443              :                   }
   15444              : 
   15445     26131503 :                 if (rqual)
   15446              :                   {
   15447            6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   15448            6 :                     error ((flags == DTOR_FLAG)
   15449              :                            ? G_("destructors may not be ref-qualified")
   15450              :                            : G_("constructors may not be ref-qualified"));
   15451            6 :                     rqual = REF_QUAL_NONE;
   15452              :                   }
   15453              : 
   15454     26131503 :                 if (decl_context == FIELD
   15455     26131503 :                     && !member_function_or_else (ctype,
   15456              :                                                  current_class_type,
   15457              :                                                  flags))
   15458            0 :                   return error_mark_node;
   15459              : 
   15460     26131503 :                 if (flags != DTOR_FLAG)
   15461              :                   {
   15462              :                     /* It's a constructor.  */
   15463     23082639 :                     if (explicitp == 1)
   15464      5377692 :                       explicitp = 2;
   15465     23082639 :                     if (virtualp)
   15466              :                       {
   15467            3 :                         permerror (declspecs->locations[ds_virtual],
   15468              :                                    "constructors cannot be declared %<virtual%>");
   15469            3 :                         virtualp = 0;
   15470              :                       }
   15471     23082639 :                     if (decl_context == FIELD
   15472     23082639 :                         && sfk != sfk_constructor)
   15473            0 :                       return error_mark_node;
   15474              :                   }
   15475     26131503 :                 if (decl_context == FIELD)
   15476     26131503 :                   staticp = 0;
   15477              :               }
   15478    162332195 :             else if (friendp)
   15479              :               {
   15480      6351663 :                 if (virtualp)
   15481              :                   {
   15482              :                     /* Cannot be both friend and virtual.  */
   15483           12 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   15484           12 :                     richloc.add_range (declspecs->locations[ds_friend]);
   15485           12 :                     error_at (&richloc, "virtual functions cannot be friends");
   15486           12 :                     friendp = 0;
   15487           12 :                   }
   15488      6351663 :                 if (decl_context == NORMAL)
   15489            0 :                   error_at (declarator->id_loc,
   15490              :                             "friend declaration not in class definition");
   15491      6351663 :                 if (current_function_decl && funcdef_flag)
   15492              :                   {
   15493            9 :                     error_at (declarator->id_loc,
   15494              :                               "cannot define friend function %qs in a local "
   15495              :                               "class definition", name);
   15496            9 :                     friendp = 0;
   15497              :                   }
   15498              :                 /* [class.friend]/6: A function can be defined in a friend
   15499              :                    declaration if the function name is unqualified.  */
   15500      6351663 :                 if (funcdef_flag && in_namespace)
   15501              :                   {
   15502            6 :                     if (in_namespace == global_namespace)
   15503            3 :                       error_at (declarator->id_loc,
   15504              :                                 "friend function definition %qs cannot have "
   15505              :                                 "a name qualified with %<::%>", name);
   15506              :                     else
   15507            3 :                       error_at (declarator->id_loc,
   15508              :                                 "friend function definition %qs cannot have "
   15509              :                                 "a name qualified with %<%D::%>", name,
   15510              :                                 in_namespace);
   15511              :                   }
   15512              :               }
   15513    155980532 :             else if (ctype && sfk == sfk_conversion)
   15514              :               {
   15515      1007493 :                 if (explicitp == 1)
   15516              :                   {
   15517       470621 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   15518       470621 :                     explicitp = 2;
   15519              :                   }
   15520              :               }
   15521    154973039 :             else if (sfk == sfk_deduction_guide)
   15522              :               {
   15523      1186898 :                 if (explicitp == 1)
   15524    188463698 :                   explicitp = 2;
   15525              :               }
   15526              : 
   15527    188463698 :             if (xobj_parm)
   15528              :               {
   15529        83644 :                 if (!ctype
   15530        83644 :                     && decl_context == NORMAL
   15531           71 :                     && (in_namespace
   15532           71 :                         || !declarator->declarator->u.id.qualifying_scope))
   15533            6 :                   error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15534              :                             "a non-member function cannot have "
   15535              :                             "an explicit object parameter");
   15536              :                 else
   15537              :                   {
   15538        83638 :                     if (virtualp)
   15539              :                       {
   15540           24 :                         auto_diagnostic_group d;
   15541           24 :                         error_at (declspecs->locations[ds_virtual],
   15542              :                                   "an explicit object member function cannot "
   15543              :                                   "be %<virtual%>");
   15544           24 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15545              :                                 "explicit object parameter declared here");
   15546           24 :                         virtualp = false;
   15547           24 :                       }
   15548        83638 :                     if (staticp >= 2)
   15549              :                       {
   15550            3 :                         auto_diagnostic_group d;
   15551            3 :                         error_at (declspecs->locations[ds_storage_class],
   15552              :                                   "an explicit object member function cannot "
   15553              :                                   "be %<static%>");
   15554            3 :                         inform (DECL_SOURCE_LOCATION (xobj_parm),
   15555              :                                 "explicit object parameter declared here");
   15556            3 :                       }
   15557        83638 :                     if (unqualified_id
   15558    188547327 :                         && identifier_p (unqualified_id)
   15559       167267 :                         && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   15560           12 :                       error_at (DECL_SOURCE_LOCATION (xobj_parm),
   15561              :                                 "%qD cannot be an explicit object member "
   15562              :                                 "function", unqualified_id);
   15563              :                   }
   15564              :               }
   15565    188463698 :             tree pushed_scope = NULL_TREE;
   15566    188463698 :             if (funcdecl_p
   15567    188463698 :                 && decl_context != FIELD
   15568     77944554 :                 && inner_declarator->u.id.qualifying_scope
   15569    197299520 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   15570      8834491 :               pushed_scope
   15571      8834491 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   15572              : 
   15573    188463698 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   15574              : 
   15575    188463698 :             if (pushed_scope)
   15576      8834491 :               pop_scope (pushed_scope);
   15577              : 
   15578    188463698 :             if (inner_declarator
   15579    188093416 :                 && inner_declarator->kind == cdk_id
   15580    186266516 :                 && inner_declarator->u.id.sfk == sfk_destructor
   15581      3212051 :                 && arg_types != void_list_node)
   15582              :               {
   15583           21 :                 error_at (declarator->id_loc,
   15584              :                           "destructors may not have parameters");
   15585           21 :                 arg_types = void_list_node;
   15586           21 :                 parms = NULL_TREE;
   15587           21 :                 is_xobj_member_function = false;
   15588              :               }
   15589              : 
   15590    188463698 :             type = cp_build_function_type (type, arg_types);
   15591              : 
   15592    188463698 :             tree attrs = declarator->std_attributes;
   15593    188463698 :             if (tx_qual)
   15594              :               {
   15595          242 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   15596              :                 /* transaction_safe applies to the type, but
   15597              :                    transaction_safe_dynamic applies to the function.  */
   15598          242 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   15599          213 :                   attrs = attr_chainon (attrs, att);
   15600              :                 else
   15601           29 :                   returned_attrs = attr_chainon (returned_attrs, att);
   15602              :               }
   15603              : 
   15604              :             /* Actually apply the contract attributes to the declaration.  */
   15605    188463698 :             if (flag_contracts)
   15606     16753387 :               contract_specifiers
   15607     16753387 :                 = attr_chainon (contract_specifiers,
   15608     16753387 :                                 declarator->u.function.contract_specifiers);
   15609              : 
   15610    188463698 :             if (attrs)
   15611              :               /* [dcl.fct]/2:
   15612              : 
   15613              :                  The optional attribute-specifier-seq appertains to
   15614              :                  the function type.  */
   15615          501 :               cplus_decl_attributes (&type, attrs, 0);
   15616              : 
   15617    188463698 :             if (raises)
   15618     75197094 :               type = build_exception_variant (type, raises);
   15619              :           }
   15620    188463698 :           break;
   15621              : 
   15622    191942770 :         case cdk_pointer:
   15623    191942770 :         case cdk_reference:
   15624    191942770 :         case cdk_ptrmem:
   15625              :           /* Filter out pointers-to-references and references-to-references.
   15626              :              We can get these if a TYPE_DECL is used.  */
   15627              : 
   15628    191942770 :           if (TYPE_REF_P (type))
   15629              :             {
   15630          240 :               if (declarator->kind != cdk_reference)
   15631              :                 {
   15632            3 :                   error ("cannot declare pointer to %q#T", type);
   15633            3 :                   type = TREE_TYPE (type);
   15634              :                 }
   15635              : 
   15636              :               /* In C++0x, we allow reference to reference declarations
   15637              :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   15638              :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   15639              :                  check for direct reference to reference declarations, which
   15640              :                  are still forbidden, occurs below. Reasoning behind the change
   15641              :                  can be found in DR106, DR540, and the rvalue reference
   15642              :                  proposals. */
   15643          237 :               else if (cxx_dialect == cxx98)
   15644              :                 {
   15645            0 :                   error ("cannot declare reference to %q#T", type);
   15646            0 :                   type = TREE_TYPE (type);
   15647              :                 }
   15648              :             }
   15649    191942530 :           else if (VOID_TYPE_P (type))
   15650              :             {
   15651      5138441 :               if (declarator->kind == cdk_reference)
   15652            4 :                 error ("cannot declare reference to %q#T", type);
   15653      5138437 :               else if (declarator->kind == cdk_ptrmem)
   15654            3 :                 error ("cannot declare pointer to %q#T member", type);
   15655              :             }
   15656              : 
   15657              :           /* We now know that the TYPE_QUALS don't apply to the decl,
   15658              :              but to the target of the pointer.  */
   15659    191942770 :           type_quals = TYPE_UNQUALIFIED;
   15660              : 
   15661              :           /* This code used to handle METHOD_TYPE, but I don't think it's
   15662              :              possible to get it here anymore.  */
   15663    191942770 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   15664    191942770 :           if (declarator->kind == cdk_ptrmem
   15665      1103988 :               && TREE_CODE (type) == FUNCTION_TYPE)
   15666              :             {
   15667       893198 :               memfn_quals |= type_memfn_quals (type);
   15668      1786396 :               type = build_memfn_type (type,
   15669       893198 :                                        declarator->u.pointer.class_type,
   15670              :                                        memfn_quals,
   15671              :                                        rqual);
   15672       893198 :               if (type == error_mark_node)
   15673              :                 return error_mark_node;
   15674              : 
   15675              :               rqual = REF_QUAL_NONE;
   15676              :               memfn_quals = TYPE_UNQUALIFIED;
   15677              :             }
   15678              : 
   15679    191942767 :           if (TREE_CODE (type) == FUNCTION_TYPE
   15680    191942767 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   15681      1006330 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   15682           15 :             error (declarator->kind == cdk_reference
   15683              :                    ? G_("cannot declare reference to qualified function type %qT")
   15684              :                    : G_("cannot declare pointer to qualified function type %qT"),
   15685              :                    type);
   15686              : 
   15687              :           /* When the pointed-to type involves components of variable size,
   15688              :              care must be taken to ensure that the size evaluation code is
   15689              :              emitted early enough to dominate all the possible later uses
   15690              :              and late enough for the variables on which it depends to have
   15691              :              been assigned.
   15692              : 
   15693              :              This is expected to happen automatically when the pointed-to
   15694              :              type has a name/declaration of it's own, but special attention
   15695              :              is required if the type is anonymous.
   15696              : 
   15697              :              We handle the NORMAL and FIELD contexts here by inserting a
   15698              :              dummy statement that just evaluates the size at a safe point
   15699              :              and ensures it is not deferred until e.g. within a deeper
   15700              :              conditional context (c++/43555).
   15701              : 
   15702              :              We expect nothing to be needed here for PARM or TYPENAME.
   15703              :              Evaluating the size at this point for TYPENAME would
   15704              :              actually be incorrect, as we might be in the middle of an
   15705              :              expression with side effects on the pointed-to type size
   15706              :              "arguments" prior to the pointer declaration point and the
   15707              :              size evaluation could end up prior to the side effects.  */
   15708              : 
   15709    191942767 :           if (!TYPE_NAME (type)
   15710      5434072 :               && (decl_context == NORMAL || decl_context == FIELD)
   15711       608278 :               && at_function_scope_p ()
   15712    191982393 :               && variably_modified_type_p (type, NULL_TREE))
   15713              :             {
   15714          119 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   15715              :                                              NULL_TREE, type);
   15716          119 :               add_decl_expr (TYPE_NAME (type));
   15717              :             }
   15718              : 
   15719    191942767 :           if (declarator->kind == cdk_reference)
   15720              :             {
   15721              :               /* In C++0x, the type we are creating a reference to might be
   15722              :                  a typedef which is itself a reference type. In that case,
   15723              :                  we follow the reference collapsing rules in
   15724              :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   15725              : 
   15726              :                  "If a typedef TD names a type that is a reference to a type
   15727              :                  T, an attempt to create the type 'lvalue reference to cv TD'
   15728              :                  creates the type 'lvalue reference to T,' while an attempt
   15729              :                  to create the type "rvalue reference to cv TD' creates the
   15730              :                  type TD."
   15731              :               */
   15732    128384202 :               if (VOID_TYPE_P (type))
   15733              :                 /* We already gave an error.  */;
   15734    128384198 :               else if (TYPE_REF_P (type))
   15735              :                 {
   15736          237 :                   if (declarator->u.reference.rvalue_ref)
   15737              :                     /* Leave type alone.  */;
   15738              :                   else
   15739          116 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   15740              :                 }
   15741              :               else
   15742    128383961 :                 type = cp_build_reference_type
   15743    128383961 :                   (type, declarator->u.reference.rvalue_ref);
   15744              : 
   15745              :               /* In C++0x, we need this check for direct reference to
   15746              :                  reference declarations, which are forbidden by
   15747              :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   15748              :                  are only allowed indirectly through typedefs and template
   15749              :                  type arguments. Example:
   15750              : 
   15751              :                    void foo(int & &);      // invalid ref-to-ref decl
   15752              : 
   15753              :                    typedef int & int_ref;
   15754              :                    void foo(int_ref &);    // valid ref-to-ref decl
   15755              :               */
   15756    128384202 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   15757            2 :                 error ("cannot declare reference to %q#T, which is not "
   15758              :                        "a typedef or a template type argument", type);
   15759              :             }
   15760     63558565 :           else if (TREE_CODE (type) == METHOD_TYPE)
   15761       893195 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   15762     62665370 :           else if (declarator->kind == cdk_ptrmem)
   15763              :             {
   15764       210790 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   15765              :                           != NAMESPACE_DECL);
   15766       210790 :               if (declarator->u.pointer.class_type == error_mark_node)
   15767              :                 /* We will already have complained.  */
   15768            3 :                 type = error_mark_node;
   15769              :               else
   15770       210787 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   15771              :                                           type);
   15772              :             }
   15773              :           else
   15774     62454580 :             type = build_pointer_type (type);
   15775              : 
   15776              :           /* Process a list of type modifier keywords (such as
   15777              :              const or volatile) that were given inside the `*' or `&'.  */
   15778              : 
   15779    191942767 :           if (declarator->u.pointer.qualifiers)
   15780              :             {
   15781      8449482 :               type
   15782      8449482 :                 = cp_build_qualified_type (type,
   15783              :                                            declarator->u.pointer.qualifiers);
   15784      8449482 :               type_quals = cp_type_quals (type);
   15785              :             }
   15786              : 
   15787              :           /* Apply C++11 attributes to the pointer, and not to the
   15788              :              type pointed to.  This is unlike what is done for GNU
   15789              :              attributes above.  It is to comply with [dcl.ptr]/1:
   15790              : 
   15791              :                  [the optional attribute-specifier-seq (7.6.1) appertains
   15792              :                   to the pointer and not to the object pointed to].  */
   15793    191942767 :           if (declarator->std_attributes)
   15794          177 :             cplus_decl_attributes (&type, declarator->std_attributes, 0);
   15795              : 
   15796              :           ctype = NULL_TREE;
   15797              :           break;
   15798              : 
   15799              :         case cdk_error:
   15800              :           break;
   15801              : 
   15802            0 :         default:
   15803            0 :           gcc_unreachable ();
   15804              :         }
   15805              :     }
   15806              : 
   15807   1029184113 :   id_loc = declarator ? declarator->id_loc : input_location;
   15808              : 
   15809   1029184113 :   if (innermost_code != cdk_function
   15810              :     /* Don't check this if it can be the artificial decltype(auto)
   15811              :        we created when building a constraint in a compound-requirement:
   15812              :        that the type-constraint is plain is going to be checked in
   15813              :        cp_parser_compound_requirement.  */
   15814   1029184113 :       && decl_context != TYPENAME
   15815   1029184113 :       && check_decltype_auto (id_loc, type))
   15816           20 :     return error_mark_node;
   15817              : 
   15818              :   /* A `constexpr' specifier used in an object declaration declares
   15819              :      the object as `const'.  */
   15820   1029184093 :   if (constexpr_p && innermost_code != cdk_function)
   15821              :     {
   15822              :       /* DR1688 says that a `constexpr' specifier in combination with
   15823              :          `volatile' is valid.  */
   15824              : 
   15825     19521324 :       if (!TYPE_REF_P (type))
   15826              :         {
   15827     19510514 :           type_quals |= TYPE_QUAL_CONST;
   15828     19510514 :           type = cp_build_qualified_type (type, type_quals);
   15829              :         }
   15830              :     }
   15831              : 
   15832    579505866 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   15833      2754223 :       && !FUNC_OR_METHOD_TYPE_P (type)
   15834   1031007372 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   15835              :     {
   15836            0 :       error ("template-id %qD used as a declarator",
   15837              :              unqualified_id);
   15838            0 :       unqualified_id = dname;
   15839              :     }
   15840              : 
   15841              :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   15842              :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   15843              :      we know that the function is static.  We take advantage of this
   15844              :      opportunity to do other processing that pertains to entities
   15845              :      explicitly declared to be class members.  Note that if DECLARATOR
   15846              :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   15847              :      would not have exited the loop above.  */
   15848   1029184093 :   if (declarator
   15849    579735890 :       && declarator->kind == cdk_id
   15850    579505866 :       && declarator->u.id.qualifying_scope
   15851   1038765769 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   15852              :     {
   15853      9326444 :       ctype = declarator->u.id.qualifying_scope;
   15854      9326444 :       ctype = TYPE_MAIN_VARIANT (ctype);
   15855      9326444 :       template_count = num_template_headers_for_class (ctype);
   15856              : 
   15857      9326444 :       if (ctype == current_class_type)
   15858              :         {
   15859           54 :           if (friendp)
   15860              :             {
   15861           15 :               permerror (declspecs->locations[ds_friend],
   15862              :                          "member functions are implicitly "
   15863              :                          "friends of their class");
   15864           15 :               friendp = 0;
   15865              :             }
   15866              :           else
   15867           39 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   15868              :                        ctype, name);
   15869              :         }
   15870      9326390 :       else if (/* If the qualifying type is already complete, then we
   15871              :                   can skip the following checks.  */
   15872      9326390 :                !COMPLETE_TYPE_P (ctype)
   15873          154 :                && (/* If the function is being defined, then
   15874              :                       qualifying type must certainly be complete.  */
   15875              :                    funcdef_flag
   15876              :                    /* A friend declaration of "T::f" is OK, even if
   15877              :                       "T" is a template parameter.  But, if this
   15878              :                       function is not a friend, the qualifying type
   15879              :                       must be a class.  */
   15880          117 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   15881              :                    /* For a declaration, the type need not be
   15882              :                       complete, if either it is dependent (since there
   15883              :                       is no meaningful definition of complete in that
   15884              :                       case) or the qualifying class is currently being
   15885              :                       defined.  */
   15886          129 :                    || !(dependent_type_p (ctype)
   15887           24 :                         || currently_open_class (ctype)))
   15888              :                /* Check that the qualifying type is complete.  */
   15889      9326454 :                && !complete_type_or_else (ctype, NULL_TREE))
   15890           64 :         return error_mark_node;
   15891      9326326 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   15892              :         {
   15893      8834741 :           if (current_class_type
   15894          277 :               && (!friendp || funcdef_flag || initialized))
   15895              :             {
   15896           57 :               error_at (id_loc, funcdef_flag || initialized
   15897              :                         ? G_("cannot define member function %<%T::%s%> "
   15898              :                              "within %qT")
   15899              :                         : G_("cannot declare member function %<%T::%s%> "
   15900              :                              "within %qT"),
   15901              :                         ctype, name, current_class_type);
   15902           48 :               return error_mark_node;
   15903              :             }
   15904              :         }
   15905       491585 :       else if (typedef_p && current_class_type)
   15906              :         {
   15907            0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   15908              :                     ctype, name, current_class_type);
   15909            0 :           return error_mark_node;
   15910              :         }
   15911              :     }
   15912              : 
   15913   1029183981 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   15914     57718659 :     ctype = current_class_type;
   15915              : 
   15916              :   /* Now TYPE has the actual type.  */
   15917              : 
   15918   1029183981 :   if (returned_attrs)
   15919              :     {
   15920         2941 :       if (attrlist)
   15921         2941 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   15922              :       else
   15923              :         attrlist = &returned_attrs;
   15924              :     }
   15925              : 
   15926   1029183981 :   if (declarator
   15927    579735778 :       && declarator->kind == cdk_id
   15928    579505754 :       && declarator->std_attributes
   15929       567691 :       && attrlist != NULL)
   15930              :     {
   15931              :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   15932              :          a declarator-id appertains to the entity that is declared.  */
   15933       567688 :       if (declarator->std_attributes != error_mark_node)
   15934              :         {
   15935       567670 :           if (flag_reflection
   15936              :               && declarator->std_attributes != error_mark_node
   15937        26888 :               && lookup_annotation (declarator->std_attributes)
   15938           40 :               && *attrlist != error_mark_node
   15939       567710 :               && lookup_annotation (*attrlist))
   15940              :             /* If there are annotations in both lists, ensure
   15941              :                declarator->std_attributes go after *attrlist.  See
   15942              :                PR124399.  */
   15943           14 :             *attrlist = chainon (copy_list (*attrlist),
   15944           14 :                                  declarator->std_attributes);
   15945              :           else
   15946       567656 :             *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   15947              :         }
   15948              :       else
   15949              :         /* We should have already diagnosed the issue (c++/78344).  */
   15950           18 :         gcc_assert (seen_error ());
   15951              :     }
   15952              : 
   15953              :   /* Handle parameter packs. */
   15954   1029183981 :   if (parameter_pack_p)
   15955              :     {
   15956      3024027 :       if (decl_context == PARM)
   15957              :         /* Turn the type into a pack expansion.*/
   15958      3024027 :         type = make_pack_expansion (type);
   15959              :       else
   15960            0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   15961              :     }
   15962              : 
   15963   1029183981 :   if ((decl_context == FIELD || decl_context == PARM)
   15964    457108061 :       && !processing_template_decl
   15965   1175612394 :       && variably_modified_type_p (type, NULL_TREE))
   15966              :     {
   15967           12 :       if (decl_context == FIELD)
   15968            6 :         error_at (id_loc,
   15969              :                   "data member may not have variably modified type %qT", type);
   15970              :       else
   15971            6 :         error_at (id_loc,
   15972              :                   "parameter may not have variably modified type %qT", type);
   15973           12 :       type = error_mark_node;
   15974              :     }
   15975              : 
   15976   1029183981 :   if (explicitp == 1 || (explicitp && friendp))
   15977              :     {
   15978              :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   15979              :          in the declaration of a constructor or conversion function within
   15980              :          a class definition.  */
   15981           74 :       if (!current_class_type)
   15982           59 :         error_at (declspecs->locations[ds_explicit],
   15983              :                   "%<explicit%> outside class declaration");
   15984           15 :       else if (friendp)
   15985           12 :         error_at (declspecs->locations[ds_explicit],
   15986              :                   "%<explicit%> in friend declaration");
   15987              :       else
   15988            3 :         error_at (declspecs->locations[ds_explicit],
   15989              :                   "only declarations of constructors and conversion operators "
   15990              :                   "can be %<explicit%>");
   15991              :       explicitp = 0;
   15992              :     }
   15993              : 
   15994   1029183981 :   if (storage_class == sc_mutable)
   15995              :     {
   15996       134794 :       location_t sloc = declspecs->locations[ds_storage_class];
   15997       134794 :       if (decl_context != FIELD || friendp)
   15998              :         {
   15999           30 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   16000              :                     name);
   16001           30 :           storage_class = sc_none;
   16002              :         }
   16003       134764 :       else if (decl_context == TYPENAME || typedef_p)
   16004              :         {
   16005            0 :           error_at (sloc,
   16006              :                     "non-object member %qs cannot be declared %<mutable%>",
   16007              :                     name);
   16008            0 :           storage_class = sc_none;
   16009              :         }
   16010       134764 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   16011              :         {
   16012            3 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   16013              :                     name);
   16014            3 :           storage_class = sc_none;
   16015              :         }
   16016       134761 :       else if (staticp)
   16017              :         {
   16018            0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   16019              :                     name);
   16020            0 :           storage_class = sc_none;
   16021              :         }
   16022       134761 :       else if (type_quals & TYPE_QUAL_CONST)
   16023              :         {
   16024            9 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   16025              :                     name);
   16026            9 :           storage_class = sc_none;
   16027              :         }
   16028       134752 :       else if (TYPE_REF_P (type))
   16029              :         {
   16030            6 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   16031              :                      name);
   16032            6 :           storage_class = sc_none;
   16033              :         }
   16034              :     }
   16035              : 
   16036              :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   16037   1029183981 :   if (typedef_p && decl_context != TYPENAME)
   16038              :     {
   16039     46801418 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   16040     46801418 :       tree decl;
   16041              : 
   16042     46801418 :       if (funcdef_flag)
   16043              :         {
   16044            6 :           if (decl_context == NORMAL)
   16045            3 :             error_at (id_loc,
   16046              :                       "typedef may not be a function definition");
   16047              :           else
   16048            3 :             error_at (id_loc,
   16049              :                       "typedef may not be a member function definition");
   16050            6 :           return error_mark_node;
   16051              :         }
   16052              : 
   16053              :       /* This declaration:
   16054              : 
   16055              :            typedef void f(int) const;
   16056              : 
   16057              :          declares a function type which is not a member of any
   16058              :          particular class, but which is cv-qualified; for
   16059              :          example "f S::*" declares a pointer to a const-qualified
   16060              :          member function of S.  We record the cv-qualification in the
   16061              :          function type.  */
   16062     46801412 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   16063              :         {
   16064           62 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   16065              : 
   16066              :           /* We have now dealt with these qualifiers.  */
   16067           62 :           memfn_quals = TYPE_UNQUALIFIED;
   16068           62 :           rqual = REF_QUAL_NONE;
   16069              :         }
   16070              : 
   16071     46801412 :       if (type_uses_auto (type))
   16072              :         {
   16073           62 :           if (alias_p)
   16074           20 :             error_at (declspecs->locations[ds_type_spec],
   16075              :                       "%<auto%> not allowed in alias declaration");
   16076              :           else
   16077           42 :             error_at (declspecs->locations[ds_type_spec],
   16078              :                       "typedef declared %<auto%>");
   16079           62 :           type = error_mark_node;
   16080              :         }
   16081              : 
   16082     46801412 :       if (reqs)
   16083            3 :         error_at (location_of (reqs), "requires-clause on typedef");
   16084              : 
   16085     46801412 :       if (id_declarator && declarator->u.id.qualifying_scope)
   16086              :         {
   16087           21 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   16088           21 :           type = error_mark_node;
   16089              :         }
   16090              : 
   16091     46801412 :       if (decl_context == FIELD)
   16092     25033034 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   16093              :       else
   16094     21768378 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   16095              : 
   16096     46801412 :       if (decl_context != FIELD)
   16097              :         {
   16098     21768378 :           if (!current_function_decl)
   16099      9566927 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   16100     12201451 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   16101              :             /* The TYPE_DECL is "abstract" because there will be
   16102              :                clones of this constructor/destructor, and there will
   16103              :                be copies of this TYPE_DECL generated in those
   16104              :                clones.  The decloning optimization (for space) may
   16105              :                revert this subsequently if it determines that
   16106              :                the clones should share a common implementation.  */
   16107       154890 :             DECL_ABSTRACT_P (decl) = true;
   16108              : 
   16109     21768378 :           set_originating_module (decl);
   16110              :         }
   16111     25033034 :       else if (current_class_type
   16112     25033034 :                && constructor_name_p (unqualified_id, current_class_type))
   16113            3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   16114              :                    "as enclosing class",
   16115              :                    unqualified_id);
   16116              : 
   16117              :       /* If the user declares "typedef struct {...} foo" then the
   16118              :          struct will have an anonymous name.  Fill that name in now.
   16119              :          Nothing can refer to it, so nothing needs know about the name
   16120              :          change.  */
   16121     46801412 :       if (type != error_mark_node
   16122     46801329 :           && unqualified_id
   16123     46801326 :           && TYPE_NAME (type)
   16124     43507132 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   16125     86889651 :           && (TYPE_UNNAMED_P (type)
   16126              :               /* An enum may have previously used an enumerator for linkage
   16127              :                  purposes, but we want the typedef name to take priority.  */
   16128     43116107 :               || enum_with_enumerator_for_linkage_p (type))
   16129       391452 :           && declspecs->type_definition_p
   16130       391379 :           && attributes_naming_typedef_ok (*attrlist)
   16131     47192788 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   16132       391358 :         name_unnamed_type (type, decl);
   16133              : 
   16134     46801412 :       if (signed_p
   16135     46801412 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   16136       372982 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   16137              : 
   16138     46801412 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   16139              :                       memfn_quals != TYPE_UNQUALIFIED,
   16140              :                       inlinep, friendp, raises != NULL_TREE,
   16141              :                       declspecs->locations);
   16142              : 
   16143     46801412 :       if (alias_p)
   16144              :         /* Acknowledge that this was written:
   16145              :              `using analias = atype;'.  */
   16146     21080569 :         TYPE_DECL_ALIAS_P (decl) = 1;
   16147              : 
   16148              :       /* We use a flag so that dependent_opaque_alias_p doesn't have to
   16149              :          recompute the answer every single time.  */
   16150     46801412 :       TYPE_DECL_OPAQUE_ALIAS_P (decl) = any_lambdas_p (type);
   16151              : 
   16152     46801412 :       return decl;
   16153              :     }
   16154              : 
   16155              :   /* Detect the case of an array type of unspecified size
   16156              :      which came, as such, direct from a typedef name.
   16157              :      We must copy the type, so that the array's domain can be
   16158              :      individually set by the object's initializer.  */
   16159              : 
   16160    982382563 :   if (type && typedef_type
   16161    953111597 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   16162    982967544 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   16163           83 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16164              : 
   16165              :   /* Detect where we're using a typedef of function type to declare a
   16166              :      function. PARMS will not be set, so we must create it now.  */
   16167              : 
   16168    982382563 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   16169              :     {
   16170        15680 :       tree decls = NULL_TREE;
   16171        15680 :       tree args;
   16172              : 
   16173        15680 :       for (args = TYPE_ARG_TYPES (type);
   16174        33825 :            args && args != void_list_node;
   16175        18145 :            args = TREE_CHAIN (args))
   16176              :         {
   16177        18145 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   16178        18145 :                                           TREE_VALUE (args));
   16179              : 
   16180        18145 :           DECL_CHAIN (decl) = decls;
   16181        18145 :           decls = decl;
   16182              :         }
   16183              : 
   16184        15680 :       parms = nreverse (decls);
   16185              : 
   16186        15680 :       if (decl_context != TYPENAME)
   16187              :         {
   16188              :           /* The qualifiers on the function type become the qualifiers on
   16189              :              the non-static member function. */
   16190        14909 :           memfn_quals |= type_memfn_quals (type);
   16191        14909 :           rqual = type_memfn_rqual (type);
   16192        14909 :           type_quals = TYPE_UNQUALIFIED;
   16193        14909 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   16194              :         }
   16195              :     }
   16196              : 
   16197              :   /* If this is a type name (such as, in a cast or sizeof),
   16198              :      compute the type and return it now.  */
   16199              : 
   16200    982381792 :   if (decl_context == TYPENAME)
   16201              :     {
   16202              :       /* Note that here we don't care about type_quals.  */
   16203              : 
   16204              :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   16205    404815141 :       if (friendp)
   16206              :         {
   16207            0 :           if (inlinep)
   16208              :             {
   16209            0 :               error ("%<inline%> specified for friend class declaration");
   16210            0 :               inlinep = 0;
   16211              :             }
   16212              : 
   16213            0 :           if (!current_aggr)
   16214              :             {
   16215              :               /* Don't allow friend declaration without a class-key.  */
   16216            0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   16217            0 :                 permerror (input_location, "template parameters cannot be friends");
   16218            0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   16219            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16220              :                            "i.e. %<friend class %T::%D%>",
   16221            0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   16222              :               else
   16223            0 :                 permerror (input_location, "friend declaration requires class-key, "
   16224              :                            "i.e. %<friend %#T%>",
   16225              :                            type);
   16226              :             }
   16227              : 
   16228              :           /* Only try to do this stuff if we didn't already give up.  */
   16229            0 :           if (type != integer_type_node)
   16230              :             {
   16231              :               /* A friendly class?  */
   16232            0 :               if (current_class_type)
   16233            0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   16234              :                                    /*complain=*/true);
   16235              :               else
   16236            0 :                 error ("trying to make class %qT a friend of global scope",
   16237              :                        type);
   16238              : 
   16239            0 :               type = void_type_node;
   16240              :             }
   16241              :         }
   16242    404815141 :       else if (memfn_quals || rqual)
   16243              :         {
   16244        10805 :           if (ctype == NULL_TREE
   16245        10805 :               && TREE_CODE (type) == METHOD_TYPE)
   16246            0 :             ctype = TYPE_METHOD_BASETYPE (type);
   16247              : 
   16248        10805 :           if (ctype)
   16249            0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   16250              :           /* Core issue #547: need to allow this in template type args.
   16251              :              Allow it in general in C++11 for alias-declarations.  */
   16252        10805 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   16253        10803 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   16254        10801 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   16255              :           else
   16256            4 :             error ("invalid qualifiers on non-member function type");
   16257              :         }
   16258              : 
   16259    404815141 :       if (reqs)
   16260            3 :         error_at (location_of (reqs), "requires-clause on type-id");
   16261              : 
   16262    404815141 :       return type;
   16263              :     }
   16264    577567422 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   16265       819533 :            && decl_context != CATCHPARM
   16266       360935 :            && TREE_CODE (type) != UNION_TYPE
   16267       360560 :            && ! bitfield
   16268       360560 :            && innermost_code != cdk_decomp)
   16269              :     {
   16270            9 :       error ("abstract declarator %qT used as declaration", type);
   16271            9 :       return error_mark_node;
   16272              :     }
   16273              : 
   16274    577567413 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   16275              :     {
   16276              :       /* Only functions may be declared using an operator-function-id.  */
   16277    391340106 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   16278              :         {
   16279            8 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   16280            8 :           return error_mark_node;
   16281              :         }
   16282              : 
   16283    391340098 :       if (reqs)
   16284           15 :         error_at (location_of (reqs),
   16285              :                   "requires-clause on declaration of non-function type %qT",
   16286              :                   type);
   16287              :     }
   16288              : 
   16289              :   /* We don't check parameter types here because we can emit a better
   16290              :      error message later.  */
   16291    577567405 :   if (decl_context != PARM)
   16292              :     {
   16293    286499923 :       type = check_var_type (unqualified_id, type, id_loc);
   16294    286499923 :       if (type == error_mark_node)
   16295              :         return error_mark_node;
   16296              :     }
   16297              : 
   16298              :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   16299              :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   16300              : 
   16301    577567321 :   if (decl_context == PARM || decl_context == CATCHPARM)
   16302              :     {
   16303    291539873 :       if (ctype || in_namespace)
   16304            0 :         error ("cannot use %<::%> in parameter declaration");
   16305              : 
   16306    291539873 :       tree auto_node = type_uses_auto (type);
   16307    291539873 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   16308              :         {
   16309          126 :           bool err_p = true;
   16310          126 :           if (cxx_dialect >= cxx14)
   16311              :             {
   16312          224 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   16313            3 :                 error_at (typespec_loc,
   16314              :                           "cannot declare a parameter with %<decltype(auto)%>");
   16315          115 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16316              :                 {
   16317            7 :                   auto_diagnostic_group g;
   16318            7 :                   gcc_rich_location richloc (typespec_loc);
   16319            7 :                   richloc.add_fixit_insert_after ("<>");
   16320            7 :                   error_at (&richloc,
   16321              :                             "missing template argument list after %qE; template "
   16322              :                             "placeholder not permitted in parameter", c);
   16323            7 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   16324            6 :                     inform (typespec_loc, "or use %<auto%> for an "
   16325              :                             "abbreviated function template");
   16326            7 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   16327            7 :                 }
   16328          108 :               else if (decl_context == CATCHPARM || template_parm_flag)
   16329           14 :                 error_at (typespec_loc,
   16330              :                           "%<auto%> parameter not permitted in this context");
   16331              :               else
   16332              :                 /* Do not issue an error while tentatively parsing a function
   16333              :                    parameter: for T t(auto(a), 42);, when we just saw the 1st
   16334              :                    parameter, we don't know yet that this construct won't be
   16335              :                    a function declaration.  Defer the checking to
   16336              :                    cp_parser_parameter_declaration_clause.  */
   16337              :                 err_p = false;
   16338              :             }
   16339              :           else
   16340            8 :             error_at (typespec_loc, "parameter declared %<auto%>");
   16341           32 :           if (err_p)
   16342           32 :             type = error_mark_node;
   16343              :         }
   16344              : 
   16345              :       /* A parameter declared as an array of T is really a pointer to T.
   16346              :          One declared as a function is really a pointer to a function.
   16347              :          One declared as a member is really a pointer to member.  */
   16348              : 
   16349    291539873 :       if (TREE_CODE (type) == ARRAY_TYPE)
   16350              :         {
   16351              :           /* Transfer const-ness of array into that of type pointed to.  */
   16352       758275 :           type = build_pointer_type (TREE_TYPE (type));
   16353       758275 :           type_quals = TYPE_UNQUALIFIED;
   16354       758275 :           array_parameter_p = true;
   16355              :         }
   16356    290781598 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   16357        99445 :         type = build_pointer_type (type);
   16358              :     }
   16359              : 
   16360    143982160 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   16361              :       /* Don't convert xobj member functions to METHOD_TYPE.  */
   16362    110804826 :       && !is_xobj_member_function
   16363    677991213 :       && !(unqualified_id
   16364    200840923 :            && identifier_p (unqualified_id)
   16365    100423492 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   16366              :     {
   16367    100417431 :       cp_cv_quals real_quals = memfn_quals;
   16368    100417431 :       if (cxx_dialect < cxx14 && constexpr_p
   16369       657989 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   16370         3698 :         real_quals |= TYPE_QUAL_CONST;
   16371    100417431 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   16372              :     }
   16373              : 
   16374    577567321 :   {
   16375    577567321 :     tree decl = NULL_TREE;
   16376              : 
   16377    577567321 :     if (decl_context == PARM)
   16378              :       {
   16379    291067482 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   16380    291067482 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   16381              : 
   16382    291067482 :         bad_specifiers (decl, BSP_PARM, virtualp,
   16383              :                         memfn_quals != TYPE_UNQUALIFIED,
   16384              :                         inlinep, friendp, raises != NULL_TREE,
   16385              :                         declspecs->locations);
   16386              :       }
   16387    286499839 :     else if (decl_context == FIELD)
   16388              :       {
   16389    141007530 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   16390     19726005 :           if (tree auto_node = type_uses_auto (type))
   16391              :             {
   16392           24 :               location_t tloc = declspecs->locations[ds_type_spec];
   16393           24 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   16394            6 :                 error_at (tloc, "invalid use of template-name %qE without an "
   16395              :                           "argument list",
   16396            6 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   16397              :               else
   16398           18 :                 error_at (tloc, "non-static data member declared with "
   16399              :                           "placeholder %qT", auto_node);
   16400           24 :               type = error_mark_node;
   16401              :             }
   16402              : 
   16403              :         /* The C99 flexible array extension.  */
   16404    117750454 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   16405    142095522 :             && TYPE_DOMAIN (type) == NULL_TREE)
   16406              :           {
   16407         1401 :             if (ctype
   16408         1401 :                 && (TREE_CODE (ctype) == UNION_TYPE
   16409         1401 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   16410           84 :               pedwarn (id_loc, OPT_Wpedantic,
   16411              :                        "flexible array member in union is a GCC extension");
   16412              : 
   16413              :             else
   16414              :               {
   16415              :                 /* Array is a flexible member.  */
   16416         1317 :                 if (name)
   16417         1317 :                   pedwarn (id_loc, OPT_Wpedantic,
   16418              :                            "ISO C++ forbids flexible array member %qs", name);
   16419              :                 else
   16420              :                   pedwarn (input_location, OPT_Wpedantic,
   16421              :                            "ISO C++ forbids flexible array members");
   16422              : 
   16423              :                 /* Flexible array member has a null domain.  */
   16424         1317 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   16425              :               }
   16426              :           }
   16427              : 
   16428    141007530 :         if (type == error_mark_node)
   16429              :           {
   16430              :             /* Happens when declaring arrays of sizes which
   16431              :                are error_mark_node, for example.  */
   16432           24 :             decl = NULL_TREE;
   16433              :           }
   16434    141007506 :         else if (in_namespace && !friendp)
   16435              :           {
   16436              :             /* Something like struct S { int N::j; };  */
   16437            6 :             error_at (id_loc, "invalid use of %<::%>");
   16438            6 :             return error_mark_node;
   16439              :           }
   16440    141007500 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   16441              :           {
   16442    108321739 :             int publicp = 0;
   16443    108321739 :             tree function_context;
   16444              : 
   16445    108321739 :             if (friendp == 0)
   16446              :               {
   16447              :                 /* This should never happen in pure C++ (the check
   16448              :                    could be an assert).  It could happen in
   16449              :                    Objective-C++ if someone writes invalid code that
   16450              :                    uses a function declaration for an instance
   16451              :                    variable or property (instance variables and
   16452              :                    properties are parsed as FIELD_DECLs, but they are
   16453              :                    part of an Objective-C class, not a C++ class).
   16454              :                    That code is invalid and is caught by this
   16455              :                    check.  */
   16456    101970133 :                 if (!ctype)
   16457              :                   {
   16458            0 :                     error ("declaration of function %qD in invalid context",
   16459              :                            unqualified_id);
   16460            0 :                     return error_mark_node;
   16461              :                   }
   16462              : 
   16463              :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   16464              :                    ARM 9.5 */
   16465    101970133 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   16466              :                   {
   16467            3 :                     error_at (declspecs->locations[ds_virtual],
   16468              :                               "function %qD declared %<virtual%> inside a union",
   16469              :                               unqualified_id);
   16470            3 :                     return error_mark_node;
   16471              :                   }
   16472              : 
   16473      4061166 :                 if (virtualp
   16474    112382902 :                     && identifier_p (unqualified_id)
   16475      4061166 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16476              :                   {
   16477            9 :                     error_at (declspecs->locations[ds_virtual],
   16478              :                               "%qD cannot be declared %<virtual%>, since it "
   16479              :                               "is always static", unqualified_id);
   16480            9 :                     virtualp = 0;
   16481              :                   }
   16482              :               }
   16483              : 
   16484              :             /* Check that the name used for a destructor makes sense.  */
   16485    108321736 :             if (sfk == sfk_destructor)
   16486              :               {
   16487      3048900 :                 tree uqname = id_declarator->u.id.unqualified_name;
   16488              : 
   16489      3048900 :                 if (!ctype)
   16490              :                   {
   16491           12 :                     gcc_assert (friendp);
   16492           12 :                     error_at (id_loc, "expected qualified name in friend "
   16493              :                               "declaration for destructor %qD", uqname);
   16494           12 :                     return error_mark_node;
   16495              :                   }
   16496              : 
   16497      3048888 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   16498              :                   {
   16499            9 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   16500              :                               uqname, ctype);
   16501            9 :                     return error_mark_node;
   16502              :                   }
   16503      3048879 :                 if (concept_p)
   16504              :                   {
   16505            9 :                     error_at (declspecs->locations[ds_concept],
   16506              :                               "a destructor cannot be %qs", "concept");
   16507            9 :                     return error_mark_node;
   16508              :                   }
   16509      3048870 :                 if (constexpr_p && cxx_dialect < cxx20)
   16510              :                   {
   16511            6 :                     error_at (declspecs->locations[ds_constexpr],
   16512              :                               "%<constexpr%> destructors only available"
   16513              :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   16514            6 :                     return error_mark_node;
   16515              :                   }
   16516      3048864 :                 if (consteval_p)
   16517              :                   {
   16518            3 :                     error_at (declspecs->locations[ds_consteval],
   16519              :                               "a destructor cannot be %qs", "consteval");
   16520            3 :                     return error_mark_node;
   16521              :                   }
   16522              :               }
   16523    105272836 :             else if (sfk == sfk_constructor && friendp && !ctype)
   16524              :               {
   16525            0 :                 error ("expected qualified name in friend declaration "
   16526              :                        "for constructor %qD",
   16527            0 :                        id_declarator->u.id.unqualified_name);
   16528            0 :                 return error_mark_node;
   16529              :               }
   16530    108321697 :             if (sfk == sfk_constructor)
   16531     23082663 :               if (concept_p)
   16532              :                 {
   16533            9 :                   error_at (declspecs->locations[ds_concept],
   16534              :                             "a constructor cannot be %<concept%>");
   16535            9 :                   return error_mark_node;
   16536              :                 }
   16537     85239034 :             if (concept_p)
   16538              :               {
   16539            9 :                 error_at (declspecs->locations[ds_concept],
   16540              :                           "a concept cannot be a member function");
   16541            9 :                 concept_p = false;
   16542              :               }
   16543    108321679 :             else if (consteval_p
   16544    109076064 :                      && identifier_p (unqualified_id)
   16545    109076055 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16546              :               {
   16547            9 :                 error_at (declspecs->locations[ds_consteval],
   16548              :                           "%qD cannot be %qs", unqualified_id, "consteval");
   16549            9 :                 consteval_p = false;
   16550              :               }
   16551              : 
   16552    108321688 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16553              :               {
   16554        93305 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   16555        93305 :                 if (variable_template_p (tmpl))
   16556              :                   {
   16557            3 :                     auto_diagnostic_group d;
   16558            3 :                     error_at (id_loc, "specialization of variable template "
   16559              :                               "%qD declared as function", tmpl);
   16560            3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   16561              :                             "variable template declared here");
   16562            3 :                     return error_mark_node;
   16563            3 :                   }
   16564              :               }
   16565              : 
   16566              :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   16567    108321685 :             function_context
   16568              :               = (ctype != NULL_TREE
   16569    108321685 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   16570    216643370 :             publicp = ((! friendp || ! staticp)
   16571    108321685 :                        && function_context == NULL_TREE);
   16572              : 
   16573    108321685 :             decl = grokfndecl (ctype, type,
   16574    108321685 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   16575              :                                ? unqualified_id : dname,
   16576              :                                parms,
   16577              :                                unqualified_id,
   16578              :                                declspecs,
   16579              :                                reqs,
   16580              :                                virtualp, flags, memfn_quals, rqual, raises,
   16581              :                                friendp ? -1 : 0, friendp, publicp,
   16582    108321685 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   16583    108321685 :                                        | (8 * consteval_p),
   16584              :                                initialized,
   16585              :                                is_xobj_member_function, sfk,
   16586              :                                funcdef_flag, late_return_type_p,
   16587              :                                template_count, in_namespace,
   16588              :                                attrlist, contract_specifiers, id_loc);
   16589    108321685 :             decl = set_virt_specifiers (decl, virt_specifiers);
   16590    108321685 :             if (decl == NULL_TREE)
   16591           97 :               return error_mark_node;
   16592              : #if 0
   16593              :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   16594              :             /* The decl and setting of decl_attr is also turned off.  */
   16595              :             decl = build_decl_attribute_variant (decl, decl_attr);
   16596              : #endif
   16597              : 
   16598              :             /* [class.conv.ctor]
   16599              : 
   16600              :                A constructor declared without the function-specifier
   16601              :                explicit that can be called with a single parameter
   16602              :                specifies a conversion from the type of its first
   16603              :                parameter to the type of its class.  Such a constructor
   16604              :                is called a converting constructor.  */
   16605    108321588 :             if (explicitp == 2)
   16606      5848313 :               DECL_NONCONVERTING_P (decl) = 1;
   16607              : 
   16608    108321588 :             if (declspecs->explicit_specifier)
   16609       413099 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   16610              :           }
   16611     32685761 :         else if (!staticp
   16612     32685761 :                  && ((current_class_type
   16613     19725996 :                       && same_type_p (TYPE_MAIN_VARIANT (type),
   16614              :                                       current_class_type))
   16615     19725900 :                      || (!dependent_type_p (type)
   16616     11974753 :                          && !COMPLETE_TYPE_P (complete_type (type))
   16617         1449 :                          && (!complete_or_array_type_p (type)
   16618         1374 :                              || initialized == SD_UNINITIALIZED))))
   16619              :           {
   16620         1512 :             if (TREE_CODE (type) != ARRAY_TYPE
   16621         1512 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   16622              :               {
   16623          171 :                 if (unqualified_id)
   16624              :                   {
   16625          126 :                     auto_diagnostic_group d;
   16626          126 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   16627              :                               unqualified_id, type);
   16628          126 :                     cxx_incomplete_type_inform (strip_array_types (type));
   16629          126 :                   }
   16630              :                 else
   16631           45 :                   error ("name %qT has incomplete type", type);
   16632              : 
   16633          171 :                 type = error_mark_node;
   16634          171 :                 decl = NULL_TREE;
   16635              :               }
   16636              :           }
   16637     52408721 :         else if (!verify_type_context (input_location,
   16638              :                                        staticp
   16639              :                                        ? TCTX_STATIC_STORAGE
   16640              :                                        : TCTX_FIELD, type))
   16641              :           {
   16642            0 :             type = error_mark_node;
   16643            0 :             decl = NULL_TREE;
   16644              :           }
   16645              :         else
   16646              :           {
   16647     32684243 :             if (friendp)
   16648              :               {
   16649           12 :                 if (unqualified_id)
   16650            9 :                   error_at (id_loc,
   16651              :                             "%qE is neither function nor member function; "
   16652              :                             "cannot be declared friend", unqualified_id);
   16653              :                 else
   16654            3 :                   error ("unnamed field is neither function nor member "
   16655              :                          "function; cannot be declared friend");
   16656           12 :                 return error_mark_node;
   16657              :               }
   16658     32684231 :             decl = NULL_TREE;
   16659              :           }
   16660              : 
   16661    141007355 :         if (friendp)
   16662              :           {
   16663      6351575 :             if (flag_reflection && !funcdef_flag && decl)
   16664              :               {
   16665        13546 :                 if (attrlist && lookup_annotation (*attrlist))
   16666              :                   {
   16667              :                     /* Remove the annotations to avoid spurious warning
   16668              :                        below.  */
   16669            8 :                     *attrlist = remove_attribute ("internal ", "annotation ",
   16670              :                                                   *attrlist);
   16671            8 :                     error_at (id_loc, "annotation applied to non-defining "
   16672              :                                       "friend declaration %qD", decl);
   16673              :                   }
   16674        13546 :                 for (tree arg = DECL_ARGUMENTS (decl);
   16675        30610 :                      arg; arg = DECL_CHAIN (arg))
   16676        17064 :                   if (lookup_annotation (DECL_ATTRIBUTES (arg)))
   16677            8 :                     error_at (DECL_SOURCE_LOCATION (arg),
   16678              :                               "annotation applied to parameter %qD of "
   16679              :                               "non-defining friend declaration", arg);
   16680              :               }
   16681              :             /* Packages tend to use GNU attributes on friends, so we only
   16682              :                warn for standard attributes.  */
   16683      6351575 :             if (attrlist
   16684      6351575 :                 && !funcdef_flag
   16685      6351575 :                 && cxx11_attribute_p (*attrlist))
   16686              :               {
   16687           27 :                 *attrlist = NULL_TREE;
   16688           27 :                 auto_diagnostic_group d;
   16689           27 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   16690           27 :                   inform (id_loc, "an attribute that appertains to a friend "
   16691              :                           "declaration that is not a definition is ignored");
   16692           27 :               }
   16693              :             /* Friends are treated specially.  */
   16694      6351575 :             if (ctype == current_class_type)
   16695              :               ;  /* We already issued a permerror.  */
   16696      6351575 :             else if (decl && DECL_NAME (decl))
   16697              :               {
   16698      6351572 :                 set_originating_module (decl, true);
   16699              : 
   16700      6351572 :                 if (initialized)
   16701              :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   16702              :                      in-class defaulted functions, but that breaks grokfndecl.
   16703              :                      So set it here.  */
   16704       210209 :                   funcdef_flag = true;
   16705              : 
   16706      6351572 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   16707      6351572 :                 *attrlist = NULL_TREE;
   16708              : 
   16709      6351572 :                 tree scope = ctype ? ctype : in_namespace;
   16710      6351572 :                 decl = do_friend (scope, unqualified_id, decl,
   16711              :                                   flags, funcdef_flag);
   16712      6351572 :                 return decl;
   16713              :               }
   16714              :             else
   16715            3 :               return error_mark_node;
   16716              :           }
   16717              : 
   16718              :         /* Structure field.  It may not be a function, except for C++.  */
   16719              : 
   16720    134655780 :         if (decl == NULL_TREE)
   16721              :           {
   16722     32685764 :             if (staticp)
   16723              :               {
   16724              :                 /* C++ allows static class members.  All other work
   16725              :                    for this is done by grokfield.  */
   16726     12959765 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   16727              :                                             dname, type);
   16728     12959765 :                 if (unqualified_id
   16729     12959762 :                     && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16730              :                   {
   16731        42230 :                     decl = check_explicit_specialization (unqualified_id, decl,
   16732              :                                                           template_count,
   16733              :                                                           concept_p * 8);
   16734        42230 :                     if (decl == error_mark_node)
   16735              :                       return error_mark_node;
   16736              :                   }
   16737     12959765 :                 set_linkage_for_static_data_member (decl);
   16738     12959765 :                 if (concept_p)
   16739           15 :                   error_at (declspecs->locations[ds_concept],
   16740              :                             "static data member %qE declared %qs",
   16741              :                             unqualified_id, "concept");
   16742     12959750 :                 else if (constexpr_p && !initialized)
   16743              :                   {
   16744            9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   16745              :                               "%<constexpr%> static data member %qD must "
   16746              :                               "have an initializer", decl);
   16747            9 :                     constexpr_p = false;
   16748              :                   }
   16749     12959765 :                 if (consteval_p)
   16750            3 :                   error_at (declspecs->locations[ds_consteval],
   16751              :                             "static data member %qE declared %qs",
   16752              :                             unqualified_id, "consteval");
   16753              : 
   16754     12959765 :                 if (inlinep)
   16755        22444 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   16756              : 
   16757     12959765 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   16758     12959765 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   16759              :                   /* Even if there is an in-class initialization, DECL
   16760              :                      is considered undefined until an out-of-class
   16761              :                      definition is provided, unless this is an inline
   16762              :                      variable.  */
   16763      1802337 :                   DECL_EXTERNAL (decl) = 1;
   16764              : 
   16765     12959765 :                 if (thread_p)
   16766              :                   {
   16767          422 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   16768          422 :                     if (!processing_template_decl)
   16769          376 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   16770          422 :                     if (declspecs->gnu_thread_keyword_p)
   16771           34 :                       SET_DECL_GNU_TLS_P (decl);
   16772              :                   }
   16773              : 
   16774              :                 /* Set the constraints on the declaration.  */
   16775     12959765 :                 bool memtmpl = (current_template_depth
   16776     12959765 :                                 > template_class_depth (current_class_type));
   16777     12959765 :                 if (memtmpl)
   16778              :                   {
   16779       374597 :                     tree ci = current_template_constraints ();
   16780       374597 :                     set_constraints (decl, ci);
   16781              :                   }
   16782              :               }
   16783              :             else
   16784              :               {
   16785     19725999 :                 if (concept_p)
   16786              :                   {
   16787           12 :                     error_at (declspecs->locations[ds_concept],
   16788              :                               "non-static data member %qE declared %qs",
   16789              :                               unqualified_id, "concept");
   16790           12 :                     concept_p = false;
   16791           12 :                     constexpr_p = false;
   16792              :                   }
   16793     19725987 :                 else if (constexpr_p)
   16794              :                   {
   16795            9 :                     error_at (declspecs->locations[ds_constexpr],
   16796              :                               "non-static data member %qE declared %qs",
   16797              :                               unqualified_id, "constexpr");
   16798            9 :                     constexpr_p = false;
   16799              :                   }
   16800     19725999 :                 if (constinit_p)
   16801              :                   {
   16802            6 :                     error_at (declspecs->locations[ds_constinit],
   16803              :                               "non-static data member %qE declared %qs",
   16804              :                               unqualified_id, "constinit");
   16805            6 :                     constinit_p = false;
   16806              :                   }
   16807     19725999 :                 if (consteval_p)
   16808              :                   {
   16809            3 :                     error_at (declspecs->locations[ds_consteval],
   16810              :                               "non-static data member %qE declared %qs",
   16811              :                               unqualified_id, "consteval");
   16812            3 :                     consteval_p = false;
   16813              :                   }
   16814     19725999 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   16815     19725999 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   16816     19725999 :                 if (bitfield && !unqualified_id)
   16817       130518 :                   DECL_PADDING_P (decl) = 1;
   16818              : 
   16819     19725999 :                 if (storage_class == sc_mutable)
   16820              :                   {
   16821       134746 :                     DECL_MUTABLE_P (decl) = 1;
   16822       134746 :                     storage_class = sc_none;
   16823              :                   }
   16824              : 
   16825     19725999 :                 if (initialized)
   16826              :                   {
   16827              :                     /* An attempt is being made to initialize a non-static
   16828              :                        member.  This is new in C++11.  */
   16829      2240821 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   16830              : 
   16831              :                     /* If this has been parsed with static storage class, but
   16832              :                        errors forced staticp to be cleared, ensure NSDMI is
   16833              :                        not present.  */
   16834      2240821 :                     if (declspecs->storage_class == sc_static)
   16835            3 :                       DECL_INITIAL (decl) = error_mark_node;
   16836              :                   }
   16837              :               }
   16838              : 
   16839     52411763 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   16840              :                             memfn_quals != TYPE_UNQUALIFIED,
   16841              :                             staticp ? false : inlinep, friendp,
   16842              :                             raises != NULL_TREE,
   16843              :                             declspecs->locations);
   16844              :           }
   16845              :       }
   16846    145492309 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   16847              :       {
   16848     77806117 :         tree original_name;
   16849     77806117 :         int publicp = 0;
   16850              : 
   16851     77806117 :         if (!unqualified_id)
   16852            0 :           return error_mark_node;
   16853              : 
   16854     77806117 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   16855              :           original_name = dname;
   16856              :         else
   16857     76968484 :           original_name = unqualified_id;
   16858              :         // FIXME:gcc_assert (original_name == dname);
   16859              : 
   16860     77806117 :         if (storage_class == sc_auto)
   16861            1 :           error_at (declspecs->locations[ds_storage_class],
   16862              :                     "storage class %<auto%> invalid for function %qs", name);
   16863     77806116 :         else if (storage_class == sc_register)
   16864            7 :           error_at (declspecs->locations[ds_storage_class],
   16865              :                     "storage class %<register%> invalid for function %qs",
   16866              :                     name);
   16867     77806109 :         else if (thread_p)
   16868              :           {
   16869           12 :             if (declspecs->gnu_thread_keyword_p)
   16870           12 :               error_at (declspecs->locations[ds_thread],
   16871              :                         "storage class %<__thread%> invalid for function %qs",
   16872              :                         name);
   16873              :             else
   16874            0 :               error_at (declspecs->locations[ds_thread],
   16875              :                         "storage class %<thread_local%> invalid for "
   16876              :                         "function %qs", name);
   16877              :           }
   16878     77806097 :         else if (constinit_p)
   16879            3 :           error_at (declspecs->locations[ds_constinit],
   16880              :                     "%<constinit%> specifier invalid for function %qs", name);
   16881              : 
   16882     77806117 :         if (virt_specifiers)
   16883            6 :           error ("virt-specifiers in %qs not allowed outside a class "
   16884              :                  "definition", name);
   16885              :         /* Function declaration not at top level.
   16886              :            Storage classes other than `extern' are not allowed
   16887              :            and `extern' makes no difference.  */
   16888     77806117 :         if (! toplevel_bindings_p ()
   16889        59501 :             && (storage_class == sc_static
   16890        59492 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   16891     77806129 :             && pedantic)
   16892              :           {
   16893            9 :             if (storage_class == sc_static)
   16894            6 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
   16895              :                        "%<static%> specifier invalid for function %qs "
   16896              :                        "declared out of global scope", name);
   16897              :             else
   16898            3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
   16899              :                        "%<inline%> specifier invalid for function %qs "
   16900              :                        "declared out of global scope", name);
   16901              :           }
   16902              : 
   16903     77806117 :         if (ctype == NULL_TREE)
   16904              :           {
   16905     68971659 :             if (virtualp)
   16906              :               {
   16907            0 :                 error ("virtual non-class function %qs", name);
   16908            0 :                 virtualp = 0;
   16909              :               }
   16910     68971659 :             else if (sfk == sfk_constructor
   16911     68971659 :                      || sfk == sfk_destructor)
   16912              :               {
   16913            3 :                 error (funcdef_flag
   16914              :                        ? G_("%qs defined in a non-class scope")
   16915              :                        : G_("%qs declared in a non-class scope"), name);
   16916            3 :                 sfk = sfk_none;
   16917              :               }
   16918              :           }
   16919     77806117 :         if (consteval_p
   16920     78132433 :             && identifier_p (unqualified_id)
   16921     78132433 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   16922              :           {
   16923            9 :             error_at (declspecs->locations[ds_consteval],
   16924              :                       "%qD cannot be %qs", unqualified_id, "consteval");
   16925            9 :             consteval_p = false;
   16926              :           }
   16927              : 
   16928              :         /* Record whether the function is public.  */
   16929     77806117 :         publicp = (ctype != NULL_TREE
   16930     77806117 :                    || storage_class != sc_static);
   16931              : 
   16932    155612234 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   16933              :                            declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
   16934              :                            1, friendp,
   16935              :                            publicp,
   16936     77806117 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   16937     77806117 :                                    | (8 * consteval_p),
   16938              :                            initialized,
   16939              :                            is_xobj_member_function, sfk,
   16940              :                            funcdef_flag,
   16941              :                            late_return_type_p,
   16942              :                            template_count, in_namespace, attrlist,
   16943              :                            contract_specifiers, id_loc);
   16944     77806117 :         if (decl == NULL_TREE)
   16945          619 :           return error_mark_node;
   16946              : 
   16947     77805498 :         if (explicitp == 2)
   16948        10491 :           DECL_NONCONVERTING_P (decl) = 1;
   16949     77805498 :         if (staticp == 1)
   16950              :           {
   16951       112007 :             int invalid_static = 0;
   16952              : 
   16953              :             /* Don't allow a static member function in a class, and forbid
   16954              :                declaring main to be static.  */
   16955       112007 :             if (TREE_CODE (type) == METHOD_TYPE)
   16956              :               {
   16957            0 :                 permerror (input_location, "cannot declare member function %qD to have "
   16958              :                            "static linkage", decl);
   16959            0 :                 invalid_static = 1;
   16960              :               }
   16961       112007 :             else if (current_function_decl)
   16962              :               {
   16963              :                 /* 7.1.1: There can be no static function declarations within a
   16964              :                    block.  */
   16965            9 :                 error_at (declspecs->locations[ds_storage_class],
   16966              :                           "cannot declare static function inside another function");
   16967            9 :                 invalid_static = 1;
   16968              :               }
   16969              : 
   16970            9 :             if (invalid_static)
   16971              :               {
   16972     77805498 :                 staticp = 0;
   16973              :                 storage_class = sc_none;
   16974              :               }
   16975              :           }
   16976     77805498 :         if (declspecs->explicit_specifier)
   16977            3 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   16978              :       }
   16979              :     else
   16980              :       {
   16981              :         /* It's a variable.  */
   16982              : 
   16983              :         /* An uninitialized decl with `extern' is a reference.  */
   16984    134880820 :         decl = grokvardecl (type, dname, unqualified_id,
   16985              :                             declspecs,
   16986              :                             initialized,
   16987              :                             type_quals,
   16988              :                             inlinep,
   16989              :                             concept_p,
   16990              :                             template_count,
   16991              :                             ctype ? ctype : in_namespace,
   16992              :                             id_loc);
   16993     67686192 :         if (decl == NULL_TREE)
   16994           92 :           return error_mark_node;
   16995              : 
   16996     67686100 :         bad_specifiers (decl, BSP_VAR, virtualp,
   16997              :                         memfn_quals != TYPE_UNQUALIFIED,
   16998              :                         inlinep, friendp, raises != NULL_TREE,
   16999              :                         declspecs->locations);
   17000              : 
   17001     67686100 :         if (ctype)
   17002              :           {
   17003       491558 :             DECL_CONTEXT (decl) = ctype;
   17004       491558 :             if (staticp == 1)
   17005              :               {
   17006            6 :                 permerror (declspecs->locations[ds_storage_class],
   17007              :                            "%<static%> may not be used when defining "
   17008              :                            "(as opposed to declaring) a static data member");
   17009            6 :                 staticp = 0;
   17010            6 :                 storage_class = sc_none;
   17011              :               }
   17012       491558 :             if (storage_class == sc_register && TREE_STATIC (decl))
   17013              :               {
   17014            0 :                 error ("static member %qD declared %<register%>", decl);
   17015            0 :                 storage_class = sc_none;
   17016              :               }
   17017       491558 :             if (storage_class == sc_extern && pedantic)
   17018              :               {
   17019            0 :                 pedwarn (input_location, OPT_Wpedantic,
   17020              :                          "cannot explicitly declare member %q#D to have "
   17021              :                          "extern linkage", decl);
   17022            0 :                 storage_class = sc_none;
   17023              :               }
   17024              :           }
   17025     67194542 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   17026              :           {
   17027           14 :             error_at (DECL_SOURCE_LOCATION (decl),
   17028              :                       "declaration of %<constexpr%> variable %qD "
   17029              :                       "is not a definition", decl);
   17030           14 :             constexpr_p = false;
   17031              :           }
   17032     67686100 :         if (consteval_p)
   17033              :           {
   17034           13 :             error_at (DECL_SOURCE_LOCATION (decl),
   17035              :                       "a variable cannot be declared %<consteval%>");
   17036           13 :             consteval_p = false;
   17037              :           }
   17038              : 
   17039     67686100 :         if (inlinep)
   17040      6564813 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   17041     67686100 :         if (innermost_code == cdk_decomp)
   17042              :           {
   17043       230024 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   17044       230024 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   17045       230024 :             DECL_ARTIFICIAL (decl) = 1;
   17046       230024 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   17047              :           }
   17048              :       }
   17049              : 
   17050    571214860 :     if (VAR_P (decl) && !initialized)
   17051      7434758 :       if (tree auto_node = type_uses_auto (type))
   17052          104 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   17053              :           {
   17054           21 :             location_t loc = declspecs->locations[ds_type_spec];
   17055           21 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   17056           21 :             TREE_TYPE (decl) = error_mark_node;
   17057              :           }
   17058              : 
   17059    571214860 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   17060              :       {
   17061          277 :         if (toplevel_bindings_p ())
   17062              :           {
   17063              :             /* It's common practice (and completely valid) to have a const
   17064              :                be initialized and declared extern.  */
   17065          253 :             if (!(type_quals & TYPE_QUAL_CONST))
   17066           20 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   17067              :                           "%qs initialized and declared %<extern%>", name);
   17068              :           }
   17069              :         else
   17070              :           {
   17071           24 :             error_at (DECL_SOURCE_LOCATION (decl),
   17072              :                       "%qs has both %<extern%> and initializer", name);
   17073           24 :             return error_mark_node;
   17074              :           }
   17075              :       }
   17076              : 
   17077              :     /* Record `register' declaration for warnings on &
   17078              :        and in case doing stupid register allocation.  */
   17079              : 
   17080    571214836 :     if (storage_class == sc_register)
   17081              :       {
   17082         2069 :         DECL_REGISTER (decl) = 1;
   17083              :         /* Warn about register storage specifiers on PARM_DECLs.  */
   17084         2069 :         if (TREE_CODE (decl) == PARM_DECL)
   17085              :           {
   17086           35 :             if (cxx_dialect >= cxx17)
   17087           24 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17088              :                        "ISO C++17 does not allow %<register%> storage "
   17089              :                        "class specifier");
   17090              :             else
   17091           11 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   17092              :                           "%<register%> storage class specifier used");
   17093              :           }
   17094              :       }
   17095    571212767 :     else if (storage_class == sc_extern)
   17096     30619423 :       DECL_THIS_EXTERN (decl) = 1;
   17097    540593344 :     else if (storage_class == sc_static)
   17098     23578396 :       DECL_THIS_STATIC (decl) = 1;
   17099              : 
   17100    571214836 :     if (VAR_P (decl))
   17101              :       {
   17102              :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   17103     80645841 :         if (constexpr_p)
   17104     19521250 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   17105              :         /* And the constinit flag (which only applies to variables).  */
   17106     61124591 :         else if (constinit_p)
   17107          453 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   17108              :       }
   17109    490568995 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   17110              :       {
   17111              :         /* If we saw a return type, record its location.  */
   17112    179775514 :         location_t loc = declspecs->locations[ds_type_spec];
   17113    179775514 :         if (loc == UNKNOWN_LOCATION)
   17114              :           /* Build DECL_RESULT in start_preparsed_function.  */;
   17115    147201640 :         else if (!DECL_RESULT (decl))
   17116              :           {
   17117    147164257 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   17118    147164257 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   17119    147164257 :             DECL_ARTIFICIAL (resdecl) = 1;
   17120    147164257 :             DECL_IGNORED_P (resdecl) = 1;
   17121    147164257 :             DECL_RESULT (decl) = resdecl;
   17122              :           }
   17123        37383 :         else if (funcdef_flag)
   17124            3 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   17125              :       }
   17126              : 
   17127              :     /* Record constancy and volatility on the DECL itself .  There's
   17128              :        no need to do this when processing a template; we'll do this
   17129              :        for the instantiated declaration based on the type of DECL.  */
   17130    571214836 :     if (!processing_template_decl
   17131              :         /* Don't do it for instantiated variable templates either,
   17132              :            cp_apply_type_quals_to_decl should have been called on it
   17133              :            already and might have been overridden in cp_finish_decl
   17134              :            if initializer needs runtime initialization.  */
   17135    571214836 :         && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
   17136    191495767 :       cp_apply_type_quals_to_decl (type_quals, decl);
   17137              : 
   17138    571214836 :     return decl;
   17139              :   }
   17140   1029184763 : }
   17141              : 
   17142              : /* Subroutine of start_function.  Ensure that each of the parameter
   17143              :    types (as listed in PARMS) is complete, as is required for a
   17144              :    function definition.  */
   17145              : 
   17146              : static void
   17147    159124652 : require_complete_types_for_parms (tree parms)
   17148              : {
   17149    471268608 :   for (; parms; parms = DECL_CHAIN (parms))
   17150              :     {
   17151    312143956 :       if (dependent_type_p (TREE_TYPE (parms)))
   17152    175085234 :         continue;
   17153    137058722 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   17154    137058722 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   17155              :         {
   17156    137058641 :           relayout_decl (parms);
   17157    137058641 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   17158              : 
   17159    137058641 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   17160    137058641 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   17161    137058641 :                                DECL_SOURCE_LOCATION (parms));
   17162              :         }
   17163              :       else
   17164              :         /* grokparms or complete_type_or_else will have already issued
   17165              :            an error.  */
   17166           81 :         TREE_TYPE (parms) = error_mark_node;
   17167              :     }
   17168    159124652 : }
   17169              : 
   17170              : /* Returns nonzero if T is a local variable.  */
   17171              : 
   17172              : int
   17173    167971165 : local_variable_p (const_tree t)
   17174              : {
   17175    167971165 :   if ((VAR_P (t)
   17176     64572676 :        && (DECL_LOCAL_DECL_P (t)
   17177     64572676 :            || !DECL_CONTEXT (t)
   17178     64531059 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   17179    173394553 :       || (TREE_CODE (t) == PARM_DECL))
   17180    149393495 :     return 1;
   17181              : 
   17182              :   return 0;
   17183              : }
   17184              : 
   17185              : /* Like local_variable_p, but suitable for use as a tree-walking
   17186              :    function.  */
   17187              : 
   17188              : static tree
   17189      5445223 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   17190              :                          void * /*data*/)
   17191              : {
   17192      5445223 :   if (unevaluated_p (TREE_CODE (*tp)))
   17193              :     {
   17194              :       /* DR 2082 permits local variables in unevaluated contexts
   17195              :          within a default argument.  */
   17196           64 :       *walk_subtrees = 0;
   17197           64 :       return NULL_TREE;
   17198              :     }
   17199              : 
   17200      5445159 :   if (local_variable_p (*tp)
   17201      5445159 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   17202              :     return *tp;
   17203      5445159 :   else if (TYPE_P (*tp))
   17204           30 :     *walk_subtrees = 0;
   17205              : 
   17206              :   return NULL_TREE;
   17207              : }
   17208              : 
   17209              : /* Check that ARG, which is a default-argument expression for a
   17210              :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   17211              :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   17212              :    DECL, if there is no DECL available.  */
   17213              : 
   17214              : tree
   17215      2690154 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   17216              : {
   17217      2690154 :   tree var;
   17218      2690154 :   tree decl_type;
   17219              : 
   17220      2690154 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   17221              :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   17222              :        with a default argument.  Ignore the argument for now; we'll
   17223              :        deal with it after the class is complete.  */
   17224              :     return arg;
   17225              : 
   17226      1903572 :   if (TYPE_P (decl))
   17227              :     {
   17228              :       decl_type = decl;
   17229              :       decl = NULL_TREE;
   17230              :     }
   17231              :   else
   17232       580657 :     decl_type = TREE_TYPE (decl);
   17233              : 
   17234      1903572 :   if (arg == error_mark_node
   17235      1903429 :       || decl == error_mark_node
   17236      1903420 :       || TREE_TYPE (arg) == error_mark_node
   17237      3806992 :       || decl_type == error_mark_node)
   17238              :     /* Something already went wrong.  There's no need to check
   17239              :        further.  */
   17240              :     return error_mark_node;
   17241              : 
   17242              :   /* [dcl.fct.default]
   17243              : 
   17244              :      A default argument expression is implicitly converted to the
   17245              :      parameter type.  */
   17246      1903420 :   ++cp_unevaluated_operand;
   17247              :   /* Avoid digest_init clobbering the initializer.  */
   17248      1903420 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   17249      1903420 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   17250              :                                      LOOKUP_IMPLICIT);
   17251      1903420 :   --cp_unevaluated_operand;
   17252              : 
   17253              :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   17254              :      the call sites.  */
   17255      1518757 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   17256       384678 :       && null_ptr_cst_p (arg)
   17257              :       /* Don't lose side-effects as in PR90473.  */
   17258      2255827 :       && !TREE_SIDE_EFFECTS (arg))
   17259       352404 :     return nullptr_node;
   17260              : 
   17261              :   /* [dcl.fct.default]
   17262              : 
   17263              :      Local variables shall not be used in default argument
   17264              :      expressions.
   17265              : 
   17266              :      The keyword `this' shall not be used in a default argument of a
   17267              :      member function.  */
   17268      1551016 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   17269      1551016 :   if (var)
   17270              :     {
   17271            0 :       if (complain & tf_warning_or_error)
   17272              :         {
   17273            0 :           if (DECL_NAME (var) == this_identifier)
   17274            0 :             permerror (input_location, "default argument %qE uses %qD",
   17275              :                        arg, var);
   17276              :           else
   17277            0 :             error ("default argument %qE uses local variable %qD", arg, var);
   17278              :         }
   17279            0 :       return error_mark_node;
   17280              :     }
   17281              : 
   17282              :   /* All is well.  */
   17283      1551016 :   return arg;
   17284              : }
   17285              : 
   17286              : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   17287              : 
   17288              : static tree
   17289    278388057 : type_is_deprecated (tree type)
   17290              : {
   17291    410529432 :   enum tree_code code;
   17292    410529432 :   if (TREE_DEPRECATED (type))
   17293              :     return type;
   17294    410490071 :   if (TYPE_NAME (type))
   17295              :     {
   17296    274214530 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   17297              :         return type;
   17298              :       else
   17299              :         {
   17300    274214524 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17301    274214524 :           return NULL_TREE;
   17302              :         }
   17303              :     }
   17304              : 
   17305              :   /* Do warn about using typedefs to a deprecated class.  */
   17306    136275541 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17307            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17308              : 
   17309    136275541 :   code = TREE_CODE (type);
   17310              : 
   17311    136275541 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17312    136275541 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17313              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17314    132025262 :     return type_is_deprecated (TREE_TYPE (type));
   17315              : 
   17316       116113 :   if (TYPE_PTRMEMFUNC_P (type))
   17317       116113 :     return type_is_deprecated
   17318       116113 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17319              : 
   17320              :   return NULL_TREE;
   17321              : }
   17322              : 
   17323              : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   17324              : 
   17325              : static tree
   17326    279583504 : type_is_unavailable (tree type)
   17327              : {
   17328    412439891 :   enum tree_code code;
   17329    412439891 :   if (TREE_UNAVAILABLE (type))
   17330              :     return type;
   17331    412439885 :   if (TYPE_NAME (type))
   17332              :     {
   17333    275449275 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   17334              :         return type;
   17335              :       else
   17336              :         {
   17337    275449269 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   17338    275449269 :           return NULL_TREE;
   17339              :         }
   17340              :     }
   17341              : 
   17342              :   /* Do warn about using typedefs to a deprecated class.  */
   17343    136990610 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   17344            0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   17345              : 
   17346    136990610 :   code = TREE_CODE (type);
   17347              : 
   17348    136990610 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   17349    136990610 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   17350              :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   17351    132630642 :     return type_is_unavailable (TREE_TYPE (type));
   17352              : 
   17353       225745 :   if (TYPE_PTRMEMFUNC_P (type))
   17354       225745 :     return type_is_unavailable
   17355       225745 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   17356              : 
   17357              :   return NULL_TREE;
   17358              : }
   17359              : 
   17360              : /* Decode the list of parameter types for a function type.
   17361              :    Given the list of things declared inside the parens,
   17362              :    return a list of types.
   17363              : 
   17364              :    If this parameter does not end with an ellipsis, we append
   17365              :    void_list_node.
   17366              : 
   17367              :    *PARMS is set to the chain of PARM_DECLs created.  */
   17368              : 
   17369              : tree
   17370    191367025 : grokparms (tree parmlist, tree *parms)
   17371              : {
   17372    191367025 :   tree result = NULL_TREE;
   17373    191367025 :   tree decls = NULL_TREE;
   17374    191367025 :   tree parm;
   17375    191367025 :   int any_error = 0;
   17376              : 
   17377    471566119 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   17378              :     {
   17379    469131917 :       tree type = NULL_TREE;
   17380    469131917 :       tree init = TREE_PURPOSE (parm);
   17381    469131917 :       tree decl = TREE_VALUE (parm);
   17382              : 
   17383    469131917 :       if (parm == void_list_node || parm == explicit_void_list_node)
   17384              :         break;
   17385              : 
   17386    280199110 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   17387              :         {
   17388          198 :           any_error = 1;
   17389          198 :           continue;
   17390              :         }
   17391              : 
   17392    280198912 :       type = TREE_TYPE (decl);
   17393    280198912 :       if (VOID_TYPE_P (type))
   17394              :         {
   17395           82 :           if (same_type_p (type, void_type_node)
   17396           73 :               && !init
   17397           61 :               && !DECL_NAME (decl) && !result
   17398          110 :               && TREE_CHAIN (parm) == void_list_node)
   17399              :             /* DR 577: A parameter list consisting of a single
   17400              :                unnamed parameter of non-dependent type 'void'.  */
   17401              :             break;
   17402           66 :           else if (cv_qualified_p (type))
   17403            9 :             error_at (DECL_SOURCE_LOCATION (decl),
   17404              :                       "invalid use of cv-qualified type %qT in "
   17405              :                       "parameter declaration", type);
   17406              :           else
   17407           57 :             error_at (DECL_SOURCE_LOCATION (decl),
   17408              :                       "invalid use of type %<void%> in parameter "
   17409              :                       "declaration");
   17410              :           /* It's not a good idea to actually create parameters of
   17411              :              type `void'; other parts of the compiler assume that a
   17412              :              void type terminates the parameter list.  */
   17413           66 :           type = error_mark_node;
   17414           66 :           TREE_TYPE (decl) = error_mark_node;
   17415              :         }
   17416              : 
   17417    280198896 :       if (type != error_mark_node)
   17418              :         {
   17419    280198830 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17420              :             {
   17421    279583504 :               tree unavailtype = type_is_unavailable (type);
   17422    279583504 :               if (unavailtype)
   17423           12 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   17424              :             }
   17425    280198830 :           if (deprecated_state != DEPRECATED_SUPPRESS
   17426    280198830 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   17427              :             {
   17428    278388057 :               tree deptype = type_is_deprecated (type);
   17429    278388057 :               if (deptype)
   17430        39367 :                 cp_handle_deprecated_or_unavailable (deptype);
   17431              :             }
   17432              : 
   17433              :           /* [dcl.fct] "A parameter with volatile-qualified type is
   17434              :              deprecated."  */
   17435    280198830 :           if (CP_TYPE_VOLATILE_P (type))
   17436          520 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   17437              :                         "%<volatile%>-qualified parameter is "
   17438              :                         "deprecated");
   17439              : 
   17440              :           /* Top-level qualifiers on the parameters are
   17441              :              ignored for function types.  */
   17442    280198830 :           type = cp_build_qualified_type (type, 0);
   17443    280198830 :           if (TREE_CODE (type) == METHOD_TYPE)
   17444              :             {
   17445            0 :               error ("parameter %qD invalidly declared method type", decl);
   17446            0 :               type = build_pointer_type (type);
   17447            0 :               TREE_TYPE (decl) = type;
   17448              :             }
   17449    280198830 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   17450              :             {
   17451              :               /* Before C++17 DR 393:
   17452              :                  [dcl.fct]/6, parameter types cannot contain pointers
   17453              :                  (references) to arrays of unknown bound.  */
   17454      1642852 :               tree t = TREE_TYPE (type);
   17455      1642852 :               int ptr = TYPE_PTR_P (type);
   17456              : 
   17457      1801140 :               while (1)
   17458              :                 {
   17459      1721996 :                   if (TYPE_PTR_P (t))
   17460              :                     ptr = 1;
   17461      1646001 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   17462              :                     break;
   17463         3159 :                   else if (!TYPE_DOMAIN (t))
   17464              :                     break;
   17465        79144 :                   t = TREE_TYPE (t);
   17466              :                 }
   17467      1642852 :               if (TREE_CODE (t) == ARRAY_TYPE)
   17468           16 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   17469              :                          ptr
   17470              :                          ? G_("parameter %qD includes pointer to array of "
   17471              :                               "unknown bound %qT")
   17472              :                          : G_("parameter %qD includes reference to array of "
   17473              :                               "unknown bound %qT"),
   17474              :                          decl, t);
   17475              :             }
   17476              : 
   17477    280198830 :           if (init && !processing_template_decl)
   17478      1367230 :             init = check_default_argument (decl, init, tf_warning_or_error);
   17479              :         }
   17480              : 
   17481    280198896 :       DECL_CHAIN (decl) = decls;
   17482    280198896 :       decls = decl;
   17483    280198896 :       result = tree_cons (init, type, result);
   17484              :     }
   17485    191367025 :   decls = nreverse (decls);
   17486    191367025 :   result = nreverse (result);
   17487    191367025 :   if (parm)
   17488    188932823 :     result = chainon (result, void_list_node);
   17489    191367025 :   *parms = decls;
   17490    191367025 :   if (any_error)
   17491          183 :     result = NULL_TREE;
   17492              : 
   17493          183 :   if (any_error)
   17494              :     /* We had parm errors, recover by giving the function (...) type.  */
   17495          183 :     result = NULL_TREE;
   17496              : 
   17497    191367025 :   return result;
   17498              : }
   17499              : 
   17500              : 
   17501              : /* D is a constructor or overloaded `operator='.
   17502              : 
   17503              :    Let T be the class in which D is declared. Then, this function
   17504              :    returns:
   17505              : 
   17506              :    -1 if D's is an ill-formed constructor or copy assignment operator
   17507              :       whose first parameter is of type `T'.
   17508              :    0  if D is not a copy constructor or copy assignment
   17509              :       operator.
   17510              :    1  if D is a copy constructor or copy assignment operator whose
   17511              :       first parameter is a reference to non-const qualified T.
   17512              :    2  if D is a copy constructor or copy assignment operator whose
   17513              :       first parameter is a reference to const qualified T.
   17514              : 
   17515              :    This function can be used as a predicate. Positive values indicate
   17516              :    a copy constructor and nonzero values indicate a copy assignment
   17517              :    operator.  */
   17518              : 
   17519              : int
   17520    333467155 : copy_fn_p (const_tree d)
   17521              : {
   17522    333467155 :   tree args;
   17523    333467155 :   tree arg_type;
   17524    333467155 :   int result = 1;
   17525              : 
   17526    333467155 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   17527              : 
   17528    333467155 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17529    333467155 :       || (DECL_TEMPLATE_INFO (d)
   17530    147967367 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17531              :     /* Instantiations of template member functions are never copy
   17532              :        functions.  Note that member functions of templated classes are
   17533              :        represented as template functions internally, and we must
   17534              :        accept those as copy functions.  */
   17535              :     return 0;
   17536              : 
   17537    282126548 :   if (!DECL_CONSTRUCTOR_P (d)
   17538    282126548 :       && DECL_NAME (d) != assign_op_identifier)
   17539              :     return 0;
   17540              : 
   17541    281330820 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17542              :     {
   17543          189 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17544          189 :       if (!TYPE_REF_P (object_param)
   17545          180 :           || TYPE_REF_IS_RVALUE (object_param)
   17546              :           /* Reject unrelated object parameters. */
   17547          162 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17548          351 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17549           36 :         return 0;
   17550          153 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17551              :     }
   17552              :   else
   17553    281330631 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17554    281330784 :   if (!args)
   17555              :     return 0;
   17556              : 
   17557    281323046 :   arg_type = TREE_VALUE (args);
   17558    281323046 :   if (arg_type == error_mark_node)
   17559              :     return 0;
   17560              : 
   17561    281323011 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   17562              :     {
   17563              :       /* Pass by value copy assignment operator.  */
   17564              :       result = -1;
   17565              :     }
   17566    281321728 :   else if (TYPE_REF_P (arg_type)
   17567    178003287 :            && !TYPE_REF_IS_RVALUE (arg_type)
   17568    393698620 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   17569              :     {
   17570     90185976 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   17571     90021490 :         result = 2;
   17572              :     }
   17573              :   else
   17574              :     return 0;
   17575              : 
   17576     90187259 :   args = TREE_CHAIN (args);
   17577              : 
   17578     92978342 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17579              :     /* There are more non-optional args.  */
   17580              :     return 0;
   17581              : 
   17582              :   return result;
   17583              : }
   17584              : 
   17585              : /* D is a constructor or overloaded `operator='.
   17586              : 
   17587              :    Let T be the class in which D is declared. Then, this function
   17588              :    returns true when D is a move constructor or move assignment
   17589              :    operator, false otherwise.  */
   17590              : 
   17591              : bool
   17592    154324928 : move_fn_p (const_tree d)
   17593              : {
   17594    154324928 :   if (cxx_dialect == cxx98)
   17595              :     /* There are no move constructors if we are in C++98 mode.  */
   17596              :     return false;
   17597              : 
   17598    154259846 :   if (TREE_CODE (d) == TEMPLATE_DECL
   17599    154259846 :       || (DECL_TEMPLATE_INFO (d)
   17600     62568662 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   17601              :     /* Instantiations of template member functions are never move
   17602              :        functions.  Note that member functions of templated classes are
   17603              :        represented as template functions internally, and we must
   17604              :        accept those as move functions.  */
   17605              :     return 0;
   17606              : 
   17607    125913521 :   return move_signature_fn_p (d);
   17608              : }
   17609              : 
   17610              : /* D is a constructor or overloaded `operator='.
   17611              : 
   17612              :    Then, this function returns true when D has the same signature as a move
   17613              :    constructor or move assignment operator (because either it is such a
   17614              :    ctor/op= or it is a template specialization with the same signature),
   17615              :    false otherwise.  */
   17616              : 
   17617              : bool
   17618    125913521 : move_signature_fn_p (const_tree d)
   17619              : {
   17620    125913521 :   tree args;
   17621    125913521 :   tree arg_type;
   17622    125913521 :   bool result = false;
   17623              : 
   17624    125913521 :   if (!DECL_CONSTRUCTOR_P (d)
   17625    125913521 :       && DECL_NAME (d) != assign_op_identifier)
   17626              :     return 0;
   17627              : 
   17628    125913295 :   if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
   17629              :     {
   17630          102 :       tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17631          102 :       if (!TYPE_REF_P (object_param)
   17632           96 :           || TYPE_REF_IS_RVALUE (object_param)
   17633              :           /* Reject unrelated object parameters. */
   17634           84 :           || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
   17635          186 :           || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
   17636           24 :         return 0;
   17637           78 :       args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
   17638              :     }
   17639              :   else
   17640    125913193 :     args = FUNCTION_FIRST_USER_PARMTYPE (d);
   17641    125913271 :   if (!args)
   17642              :     return 0;
   17643              : 
   17644    125910329 :   arg_type = TREE_VALUE (args);
   17645    125910329 :   if (arg_type == error_mark_node)
   17646              :     return 0;
   17647              : 
   17648    125910321 :   if (TYPE_REF_P (arg_type)
   17649     64164102 :       && TYPE_REF_IS_RVALUE (arg_type)
   17650    176092548 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   17651              :                       DECL_CONTEXT (d)))
   17652              :     result = true;
   17653              : 
   17654    125910321 :   args = TREE_CHAIN (args);
   17655              : 
   17656    140717203 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   17657              :     /* There are more non-optional args.  */
   17658              :     return false;
   17659              : 
   17660              :   return result;
   17661              : }
   17662              : 
   17663              : /* Remember any special properties of member function DECL.  */
   17664              : 
   17665              : void
   17666    345373918 : grok_special_member_properties (tree decl)
   17667              : {
   17668    345373918 :   tree class_type;
   17669              : 
   17670    345373918 :   if (TREE_CODE (decl) == USING_DECL
   17671    345373918 :       || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   17672              :     return;
   17673              : 
   17674    323795208 :   class_type = DECL_CONTEXT (decl);
   17675    323795208 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   17676              :     {
   17677    146187709 :       int ctor = copy_fn_p (decl);
   17678              : 
   17679    146187709 :       if (!DECL_ARTIFICIAL (decl))
   17680    101545030 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   17681              : 
   17682    146187709 :       if (ctor > 0)
   17683              :         {
   17684              :           /* [class.copy]
   17685              : 
   17686              :              A non-template constructor for class X is a copy
   17687              :              constructor if its first parameter is of type X&, const
   17688              :              X&, volatile X& or const volatile X&, and either there
   17689              :              are no other parameters or else all other parameters have
   17690              :              default arguments.  */
   17691     29790532 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   17692     29790532 :           if (ctor > 1)
   17693     29714078 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   17694              :         }
   17695              : 
   17696    146187709 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   17697     31194883 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   17698              : 
   17699    146187709 :       if (is_list_ctor (decl))
   17700      1498084 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   17701              : 
   17702    146187709 :       if (maybe_constexpr_fn (decl)
   17703    146187709 :           && !ctor && !move_fn_p (decl))
   17704     53046639 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   17705              :     }
   17706    177607499 :   else if (DECL_NAME (decl) == assign_op_identifier)
   17707              :     {
   17708              :       /* [class.copy]
   17709              : 
   17710              :          A non-template assignment operator for class X is a copy
   17711              :          assignment operator if its parameter is of type X, X&, const
   17712              :          X&, volatile X& or const volatile X&.  */
   17713              : 
   17714     14843270 :       int assop = copy_fn_p (decl);
   17715              : 
   17716     14843270 :       if (assop)
   17717              :         {
   17718      7549276 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   17719      7549276 :           if (assop != 1)
   17720      7521564 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   17721              :         }
   17722              :     }
   17723    162764229 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   17724      2683531 :     TYPE_HAS_CONVERSION (class_type) = true;
   17725              : 
   17726              :   /* Destructors are handled in check_methods.  */
   17727              : }
   17728              : 
   17729              : /* Check a constructor DECL has the correct form.  Complains
   17730              :    if the class has a constructor of the form X(X).  */
   17731              : 
   17732              : bool
   17733     47020175 : grok_ctor_properties (const_tree ctype, const_tree decl)
   17734              : {
   17735     47020175 :   int ctor_parm = copy_fn_p (decl);
   17736              : 
   17737     47020175 :   if (ctor_parm < 0)
   17738              :     {
   17739              :       /* [class.copy]
   17740              : 
   17741              :          A declaration of a constructor for a class X is ill-formed if
   17742              :          its first parameter is of type (optionally cv-qualified) X
   17743              :          and either there are no other parameters or else all other
   17744              :          parameters have default arguments.
   17745              : 
   17746              :          We *don't* complain about member template instantiations that
   17747              :          have this form, though; they can occur as we try to decide
   17748              :          what constructor to use during overload resolution.  Since
   17749              :          overload resolution will never prefer such a constructor to
   17750              :          the non-template copy constructor (which is either explicitly
   17751              :          or implicitly defined), there's no need to worry about their
   17752              :          existence.  Theoretically, they should never even be
   17753              :          instantiated, but that's hard to forestall.  */
   17754            9 :       error_at (DECL_SOURCE_LOCATION (decl),
   17755              :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   17756              :                 ctype, ctype);
   17757            9 :       return false;
   17758              :     }
   17759              : 
   17760              :   return true;
   17761              : }
   17762              : 
   17763              : /* DECL is a declaration for an overloaded or conversion operator.  If
   17764              :    COMPLAIN is true, errors are issued for invalid declarations.  */
   17765              : 
   17766              : bool
   17767     58436501 : grok_op_properties (tree decl, bool complain)
   17768              : {
   17769     58436501 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   17770     58436501 :   bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
   17771     58436501 :   tree name = DECL_NAME (decl);
   17772     58436501 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   17773              : 
   17774     58436501 :   tree class_type = DECL_CONTEXT (decl);
   17775     58436501 :   if (class_type && !CLASS_TYPE_P (class_type))
   17776              :     class_type = NULL_TREE;
   17777              : 
   17778     58436501 :   tree_code operator_code;
   17779     58436501 :   unsigned op_flags;
   17780     58436501 :   if (IDENTIFIER_CONV_OP_P (name))
   17781              :     {
   17782              :       /* Conversion operators are TYPE_EXPR for the purposes of this
   17783              :          function.  */
   17784              :       operator_code = TYPE_EXPR;
   17785              :       op_flags = OVL_OP_FLAG_UNARY;
   17786              :     }
   17787              :   else
   17788              :     {
   17789     56125374 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   17790              : 
   17791     56125374 :       operator_code = ovl_op->tree_code;
   17792     56125374 :       op_flags = ovl_op->flags;
   17793     56125374 :       gcc_checking_assert (operator_code != ERROR_MARK);
   17794     56125374 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   17795              :     }
   17796              : 
   17797     56125374 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   17798              :     {
   17799              :       /* operator new and operator delete are quite special.  */
   17800       339045 :       if (class_type)
   17801         7627 :         switch (op_flags)
   17802              :           {
   17803         5150 :           case OVL_OP_FLAG_ALLOC:
   17804         5150 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   17805         5150 :             break;
   17806              : 
   17807         2197 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   17808         2197 :             TYPE_GETS_DELETE (class_type) |= 1;
   17809         2197 :             break;
   17810              : 
   17811          135 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   17812          135 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   17813          135 :             break;
   17814              : 
   17815          145 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   17816          145 :             TYPE_GETS_DELETE (class_type) |= 2;
   17817          145 :             break;
   17818              : 
   17819            0 :           default:
   17820            0 :             gcc_unreachable ();
   17821              :           }
   17822              : 
   17823              :       /* [basic.std.dynamic.allocation]/1:
   17824              : 
   17825              :          A program is ill-formed if an allocation function is declared
   17826              :          in a namespace scope other than global scope or declared
   17827              :          static in global scope.
   17828              : 
   17829              :          The same also holds true for deallocation functions.  */
   17830       339045 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   17831              :         {
   17832       331418 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   17833              :             {
   17834            6 :               error_at (loc, "%qD may not be declared within a namespace",
   17835              :                         decl);
   17836            6 :               return false;
   17837              :             }
   17838              : 
   17839       331412 :           if (!TREE_PUBLIC (decl))
   17840              :             {
   17841            6 :               error_at (loc, "%qD may not be declared as static", decl);
   17842            6 :               return false;
   17843              :             }
   17844              :         }
   17845              : 
   17846              :       /* Check for replaceable global new/delete operators with
   17847              :          const std::nothrow_t & last argument, other replaceable global
   17848              :          new/delete operators are marked in cxx_init_decl_processing.  */
   17849       339033 :       if (CP_DECL_CONTEXT (decl) == global_namespace)
   17850              :         {
   17851       331406 :           tree args = argtypes;
   17852       331406 :           if (args
   17853       331394 :               && args != void_list_node
   17854       994176 :               && same_type_p (TREE_VALUE (args),
   17855              :                               (op_flags & OVL_OP_FLAG_DELETE)
   17856              :                               ? ptr_type_node : size_type_node))
   17857              :             {
   17858       331364 :               args = TREE_CHAIN (args);
   17859       331364 :               if (aligned_allocation_fn_p (decl))
   17860       106884 :                 args = TREE_CHAIN (args);
   17861       331364 :               if (args
   17862       331358 :                   && args != void_list_node
   17863       552529 :                   && TREE_CHAIN (args) == void_list_node)
   17864              :                 {
   17865       194400 :                   tree t = TREE_VALUE (args);
   17866       194400 :                   if (TYPE_REF_P (t)
   17867       110303 :                       && !TYPE_REF_IS_RVALUE (t)
   17868       110303 :                       && (t = TREE_TYPE (t))
   17869       110303 :                       && TYPE_QUALS (t) == TYPE_QUAL_CONST
   17870       304243 :                       && is_std_class (t, "nothrow_t"))
   17871       109843 :                     DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
   17872              :                 }
   17873              :             }
   17874              :         }
   17875              : 
   17876       339033 :       if (op_flags & OVL_OP_FLAG_DELETE)
   17877              :         {
   17878       194170 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   17879       194170 :           coerce_delete_type (decl, loc);
   17880              :         }
   17881              :       else
   17882              :         {
   17883       144863 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   17884       144863 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   17885              :         }
   17886              : 
   17887       339033 :       return true;
   17888              :     }
   17889              : 
   17890              :   /* An operator function must either be a non-static member function
   17891              :      or have at least one parameter of a class, a reference to a class,
   17892              :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   17893     58097456 :   if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
   17894              :     {
   17895     14930079 :       if (operator_code == TYPE_EXPR
   17896     14930079 :           || operator_code == COMPONENT_REF
   17897     14930058 :           || operator_code == NOP_EXPR)
   17898              :         {
   17899           33 :           error_at (loc, "%qD must be a non-static member function", decl);
   17900           33 :           return false;
   17901              :         }
   17902              : 
   17903     14930046 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   17904              :         {
   17905       131085 :           if (! DECL_STATIC_FUNCTION_P (decl))
   17906              :             {
   17907           12 :               error_at (loc, "%qD must be a member function", decl);
   17908           12 :               return false;
   17909              :             }
   17910       131073 :           if (cxx_dialect < cxx23
   17911              :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   17912       208272 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   17913              :               /* For instantiations, we have diagnosed this already.  */
   17914       235195 :               && ! DECL_USE_TEMPLATE (decl))
   17915       104116 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   17916              :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   17917              :                      decl);
   17918       131073 :           if (operator_code == ARRAY_REF)
   17919              :             /* static operator[] should have exactly one argument
   17920              :                for C++20 and earlier, so that it isn't multidimensional.  */
   17921              :             op_flags = OVL_OP_FLAG_UNARY;
   17922              :         }
   17923     14798961 :       else if (DECL_STATIC_FUNCTION_P (decl))
   17924              :         {
   17925            9 :           error_at (loc, "%qD must be either a non-static member "
   17926              :                     "function or a non-member function", decl);
   17927            9 :           return false;
   17928              :         }
   17929              :       else
   17930       399583 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   17931              :           {
   17932     15198535 :             if (!arg || arg == void_list_node)
   17933              :               {
   17934           18 :                 if (complain)
   17935           15 :                   error_at (loc, "%qD must have an argument of class or "
   17936              :                             "enumerated type", decl);
   17937           18 :                 return false;
   17938              :               }
   17939              : 
   17940     15198517 :             tree type = non_reference (TREE_VALUE (arg));
   17941     15198517 :             if (type == error_mark_node)
   17942              :               return false;
   17943              : 
   17944              :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   17945              :                because these checks are performed even on template
   17946              :                functions.  */
   17947     15198514 :             if (MAYBE_CLASS_TYPE_P (type)
   17948      1379437 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   17949              :               break;
   17950       399583 :           }
   17951              :     }
   17952              : 
   17953     58094967 :   if (operator_code == CALL_EXPR)
   17954              :     /* There are no further restrictions on the arguments to an overloaded
   17955              :        "operator ()".  */
   17956              :     return true;
   17957              : 
   17958              :   /* C++23 allows an arbitrary number of parameters and default arguments for
   17959              :      operator[], and none of the other checks below apply.  */
   17960     48520376 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   17961              :     return true;
   17962              : 
   17963     48281122 :   if (operator_code == COND_EXPR)
   17964              :     {
   17965              :       /* 13.4.0.3 */
   17966            6 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   17967            6 :       return false;
   17968              :     }
   17969              : 
   17970              :   /* Count the number of arguments and check for ellipsis.  */
   17971              :   int arity = 0;
   17972    137240496 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   17973              :     {
   17974     88959395 :       if (!arg)
   17975              :         {
   17976           15 :           error_at (loc, "%qD must not have variable number of arguments",
   17977              :                     decl);
   17978           15 :           return false;
   17979              :         }
   17980     88959380 :       ++arity;
   17981              :     }
   17982              :   /* FIXME: We need tests for these errors with xobj member functions.  */
   17983              :   /* Verify correct number of arguments.  */
   17984     48281101 :   switch (op_flags)
   17985              :     {
   17986      9901112 :     case OVL_OP_FLAG_AMBIARY:
   17987      9901112 :       if (arity == 1)
   17988              :         {
   17989              :           /* We have a unary instance of an ambi-ary op.  Remap to the
   17990              :              unary one.  */
   17991      4283515 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   17992      4283515 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   17993      4283515 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   17994      4283515 :           operator_code = ovl_op->tree_code;
   17995      4283515 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   17996              :         }
   17997      5617597 :       else if (arity != 2)
   17998              :         {
   17999              :           /* This was an ambiguous operator but is invalid. */
   18000            3 :           error_at (loc,
   18001              :                     methodp
   18002              :                     ? G_("%qD must have either zero or one argument")
   18003              :                     : G_("%qD must have either one or two arguments"), decl);
   18004            3 :           return false;
   18005              :         }
   18006      5617594 :       else if ((operator_code == POSTINCREMENT_EXPR
   18007      5617594 :                 || operator_code == POSTDECREMENT_EXPR)
   18008      2628207 :                && ! processing_template_decl
   18009              :                /* x++ and x--'s second argument must be an int.  */
   18010      7338305 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   18011              :                                  integer_type_node))
   18012              :         {
   18013           15 :           error_at (loc,
   18014              :                     methodp
   18015              :                     ? G_("postfix %qD must have %<int%> as its argument")
   18016              :                     : G_("postfix %qD must have %<int%> as its second argument"),
   18017              :                     decl);
   18018           15 :           return false;
   18019              :         }
   18020              :       break;
   18021              : 
   18022      3319337 :     case OVL_OP_FLAG_UNARY:
   18023      3319337 :       if (arity != 1)
   18024              :         {
   18025            9 :           error_at (loc,
   18026              :                     methodp
   18027              :                     ? G_("%qD must have no arguments")
   18028              :                     : G_("%qD must have exactly one argument"), decl);
   18029            9 :           return false;
   18030              :         }
   18031              :       break;
   18032              : 
   18033     35060652 :     case OVL_OP_FLAG_BINARY:
   18034     35060652 :       if (arity != 2)
   18035              :         {
   18036            3 :           error_at (loc,
   18037              :                     methodp
   18038              :                     ? G_("%qD must have exactly one argument")
   18039              :                     : G_("%qD must have exactly two arguments"), decl);
   18040            3 :           return false;
   18041              :         }
   18042              :       break;
   18043              : 
   18044            0 :     default:
   18045            0 :       gcc_unreachable ();
   18046              :     }
   18047              : 
   18048              :   /* There can be no default arguments.  */
   18049    137240355 :   for (tree arg = argtypes; arg && arg != void_list_node;
   18050     88959284 :        arg = TREE_CHAIN (arg))
   18051     88959299 :     if (TREE_PURPOSE (arg))
   18052              :       {
   18053           15 :         TREE_PURPOSE (arg) = NULL_TREE;
   18054           15 :         error_at (loc, "%qD cannot have default arguments", decl);
   18055           15 :         return false;
   18056              :       }
   18057              : 
   18058              :   /* At this point the declaration is well-formed.  It may not be
   18059              :      sensible though.  */
   18060              : 
   18061              :   /* Check member function warnings only on the in-class declaration.
   18062              :      There's no point warning on an out-of-class definition.  */
   18063     48281056 :   if (class_type && class_type != current_class_type)
   18064              :     return true;
   18065              : 
   18066              :   /* Warn about conversion operators that will never be used.  */
   18067     46444131 :   if (IDENTIFIER_CONV_OP_P (name)
   18068      2310709 :       && ! DECL_TEMPLATE_INFO (decl)
   18069     47451615 :       && warn_class_conversion)
   18070              :     {
   18071      1007451 :       tree t = TREE_TYPE (name);
   18072      1007451 :       int ref = TYPE_REF_P (t);
   18073              : 
   18074      1007451 :       if (ref)
   18075        21053 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   18076              : 
   18077      1007451 :       if (VOID_TYPE_P (t))
   18078            9 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   18079              :                     "will never use a type conversion operator", class_type);
   18080      1007442 :       else if (class_type)
   18081              :         {
   18082      1007442 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   18083           24 :             warning_at (loc, OPT_Wclass_conversion,
   18084              :                         ref
   18085              :                         ? G_("converting %qT to a reference to the same type "
   18086              :                              "will never use a type conversion operator")
   18087              :                         : G_("converting %qT to the same type "
   18088              :                              "will never use a type conversion operator"),
   18089              :                         class_type);
   18090              :           /* Don't force t to be complete here.  */
   18091      1007427 :           else if (MAYBE_CLASS_TYPE_P (t)
   18092       576654 :                    && COMPLETE_TYPE_P (t)
   18093       154336 :                    && DERIVED_FROM_P (t, class_type))
   18094           30 :             warning_at (loc, OPT_Wclass_conversion,
   18095              :                         ref
   18096              :                         ? G_("converting %qT to a reference to a base class "
   18097              :                              "%qT will never use a type conversion operator")
   18098              :                         : G_("converting %qT to a base class %qT "
   18099              :                              "will never use a type conversion operator"),
   18100              :                         class_type, t);
   18101              :         }
   18102              :     }
   18103              : 
   18104     46444131 :   if (!warn_ecpp)
   18105              :     return true;
   18106              : 
   18107              :   /* Effective C++ rules below.  */
   18108              : 
   18109              :   /* More Effective C++ rule 7.  */
   18110           54 :   if (operator_code == TRUTH_ANDIF_EXPR
   18111           54 :       || operator_code == TRUTH_ORIF_EXPR
   18112           54 :       || operator_code == COMPOUND_EXPR)
   18113            0 :     warning_at (loc, OPT_Weffc__,
   18114              :                 "user-defined %qD always evaluates both arguments", decl);
   18115              : 
   18116              :   /* More Effective C++ rule 6.  */
   18117           54 :   if (operator_code == POSTINCREMENT_EXPR
   18118              :       || operator_code == POSTDECREMENT_EXPR
   18119              :       || operator_code == PREINCREMENT_EXPR
   18120           54 :       || operator_code == PREDECREMENT_EXPR)
   18121              :     {
   18122            0 :       tree arg = TREE_VALUE (argtypes);
   18123            0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   18124            0 :       if (methodp || TYPE_REF_P (arg))
   18125            0 :         arg = TREE_TYPE (arg);
   18126            0 :       arg = TYPE_MAIN_VARIANT (arg);
   18127              : 
   18128            0 :       if (operator_code == PREINCREMENT_EXPR
   18129              :           || operator_code == PREDECREMENT_EXPR)
   18130              :         {
   18131            0 :           if (!TYPE_REF_P (ret)
   18132            0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   18133            0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   18134              :                         build_reference_type (arg));
   18135              :         }
   18136              :       else
   18137              :         {
   18138            0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   18139            0 :             warning_at (loc, OPT_Weffc__,
   18140              :                         "postfix %qD should return %qT", decl, arg);
   18141              :         }
   18142              :     }
   18143              : 
   18144              :   /* Effective C++ rule 23.  */
   18145           54 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   18146              :       && (operator_code == PLUS_EXPR
   18147            9 :           || operator_code == MINUS_EXPR
   18148            9 :           || operator_code == TRUNC_DIV_EXPR
   18149              :           || operator_code == MULT_EXPR
   18150              :           || operator_code == TRUNC_MOD_EXPR)
   18151           60 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   18152            3 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   18153              : 
   18154              :   return true;
   18155              : }
   18156              : 
   18157              : /* Return a string giving the keyword associate with CODE.  */
   18158              : 
   18159              : const char *
   18160         3397 : tag_name (enum tag_types code)
   18161              : {
   18162         3397 :   switch (code)
   18163              :     {
   18164              :     case record_type:
   18165              :       return "struct";
   18166          107 :     case class_type:
   18167          107 :       return "class";
   18168            3 :     case union_type:
   18169            3 :       return "union";
   18170            9 :     case enum_type:
   18171            9 :       return "enum";
   18172         3189 :     case typename_type:
   18173         3189 :     case none_type:
   18174         3189 :       return "typename";
   18175           29 :     case scope_type:
   18176           29 :       return nullptr;
   18177              :     }
   18178            0 :   gcc_unreachable ();
   18179              : }
   18180              : 
   18181              : /* Name lookup in an elaborated-type-specifier (after the keyword
   18182              :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   18183              :    elaborated-type-specifier is invalid, issue a diagnostic and return
   18184              :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   18185              :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   18186              : 
   18187              : tree
   18188     11959813 : check_elaborated_type_specifier (enum tag_types tag_code,
   18189              :                                  tree decl,
   18190              :                                  bool allow_template_p)
   18191              : {
   18192     11959813 :   tree type;
   18193              : 
   18194              :   /* In the case of:
   18195              : 
   18196              :        struct S { struct S *p; };
   18197              : 
   18198              :      name lookup will find the TYPE_DECL for the implicit "S::S"
   18199              :      typedef.  Adjust for that here.  */
   18200     11959813 :   if (DECL_SELF_REFERENCE_P (decl))
   18201       410242 :     decl = TYPE_NAME (TREE_TYPE (decl));
   18202              : 
   18203     11959813 :   type = TREE_TYPE (decl);
   18204              : 
   18205              :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   18206              :      is false for this case as well.  */
   18207     11959813 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   18208              :     {
   18209            9 :       error ("using template type parameter %qT after %qs",
   18210              :              type, tag_name (tag_code));
   18211            9 :       return error_mark_node;
   18212              :     }
   18213              :   /* Accept template template parameters.  */
   18214     11959804 :   else if (allow_template_p
   18215      6721881 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   18216      6721869 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   18217              :     ;
   18218              :   /*   [dcl.type.elab]
   18219              : 
   18220              :        If the identifier resolves to a typedef-name or the
   18221              :        simple-template-id resolves to an alias template
   18222              :        specialization, the elaborated-type-specifier is ill-formed.
   18223              : 
   18224              :      In other words, the only legitimate declaration to use in the
   18225              :      elaborated type specifier is the implicit typedef created when
   18226              :      the type is declared.  */
   18227     11959789 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   18228       410371 :            && !DECL_SELF_REFERENCE_P (decl)
   18229     11959918 :            && tag_code != typename_type)
   18230              :     {
   18231           78 :       auto_diagnostic_group d;
   18232           78 :       if (alias_template_specialization_p (type, nt_opaque))
   18233           21 :         error ("using alias template specialization %qT after %qs",
   18234              :                type, tag_name (tag_code));
   18235              :       else
   18236           57 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   18237           78 :       inform (DECL_SOURCE_LOCATION (decl),
   18238              :               "%qD has a previous declaration here", decl);
   18239           78 :       return error_mark_node;
   18240           78 :     }
   18241     11959711 :   else if (TREE_CODE (type) != RECORD_TYPE
   18242     11959711 :            && TREE_CODE (type) != UNION_TYPE
   18243              :            && tag_code != enum_type
   18244        70712 :            && tag_code != typename_type)
   18245              :     {
   18246            6 :       auto_diagnostic_group d;
   18247            6 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   18248            6 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18249            6 :       return error_mark_node;
   18250            6 :     }
   18251     11959705 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   18252     11889038 :            && tag_code == enum_type)
   18253              :     {
   18254            3 :       auto_diagnostic_group d;
   18255            3 :       error ("%qT referred to as enum", type);
   18256            3 :       inform (location_of (type), "%qT has a previous declaration here", type);
   18257            3 :       return error_mark_node;
   18258            3 :     }
   18259     11959702 :   else if (!allow_template_p
   18260      5237863 :            && TREE_CODE (type) == RECORD_TYPE
   18261     17074950 :            && CLASSTYPE_IS_TEMPLATE (type))
   18262              :     {
   18263              :       /* If a class template appears as elaborated type specifier
   18264              :          without a template header such as:
   18265              : 
   18266              :            template <class T> class C {};
   18267              :            void f(class C);             // No template header here
   18268              : 
   18269              :          then the required template argument is missing.  */
   18270           18 :       error ("template argument required for %<%s %T%>",
   18271              :              tag_name (tag_code),
   18272           18 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   18273           18 :       return error_mark_node;
   18274              :     }
   18275              : 
   18276              :   return type;
   18277              : }
   18278              : 
   18279              : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   18280              :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   18281              :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   18282              :    error.  */
   18283              : 
   18284              : static tree
   18285     26010621 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   18286              :                       TAG_how how, bool template_header_p)
   18287              : {
   18288     26010621 :   tree decl;
   18289     26010621 :   if (how == TAG_how::GLOBAL)
   18290              :     {
   18291              :       /* First try ordinary name lookup, ignoring hidden class name
   18292              :          injected via friend declaration.  */
   18293      2101558 :       decl = lookup_name (name, LOOK_want::TYPE);
   18294              :       /* If that fails, the name will be placed in the smallest
   18295              :          non-class, non-function-prototype scope according to 3.3.1/5.
   18296              :          We may already have a hidden name declared as friend in this
   18297              :          scope.  So lookup again but not ignoring hidden names.
   18298              :          If we find one, that name will be made visible rather than
   18299              :          creating a new tag.  */
   18300      2101558 :       if (!decl)
   18301        18391 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   18302              :     }
   18303              :   else
   18304     23909063 :     decl = lookup_elaborated_type (name, how);
   18305              : 
   18306     23927454 :   if (!decl)
   18307              :     /* We found nothing.  */
   18308              :     return NULL_TREE;
   18309              : 
   18310      5870961 :   if (TREE_CODE (decl) == TREE_LIST)
   18311              :     {
   18312            3 :       auto_diagnostic_group d;
   18313            3 :       error ("reference to %qD is ambiguous", name);
   18314            3 :       print_candidates (input_location, decl);
   18315            3 :       return error_mark_node;
   18316            3 :     }
   18317              : 
   18318      2376934 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18319      2376928 :       && !template_header_p
   18320      8247886 :       && how == TAG_how::CURRENT_ONLY)
   18321              :     {
   18322           12 :       auto_diagnostic_group d;
   18323           12 :       error ("class template %qD redeclared as non-template", name);
   18324           12 :       inform (location_of (decl), "previous declaration here");
   18325           12 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   18326           12 :       return error_mark_node;
   18327           12 :     }
   18328              : 
   18329      2376922 :   if (DECL_CLASS_TEMPLATE_P (decl)
   18330              :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   18331              :          so ignore a template template parameter.  */
   18332      5870952 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   18333      2376919 :     decl = DECL_TEMPLATE_RESULT (decl);
   18334              : 
   18335      5870946 :   if (TREE_CODE (decl) != TYPE_DECL)
   18336              :     /* Found not-a-type.  */
   18337              :     return NULL_TREE;
   18338              : 
   18339              :   /* Look for invalid nested type:
   18340              :      class C {
   18341              :      class C {};
   18342              :      };  */
   18343      5870925 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   18344              :     {
   18345            6 :       error ("%qD has the same name as the class in which it is "
   18346              :              "declared", decl);
   18347            6 :       return error_mark_node;
   18348              :     }
   18349              : 
   18350              :   /* Two cases we need to consider when deciding if a class
   18351              :      template is allowed as an elaborated type specifier:
   18352              :      1. It is a self reference to its own class.
   18353              :      2. It comes with a template header.
   18354              : 
   18355              :      For example:
   18356              : 
   18357              :      template <class T> class C {
   18358              :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   18359              :        class D;
   18360              :      };
   18361              :      template <class U> class C; // template_header_p is true
   18362              :      template <class T> class C<T>::D {
   18363              :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   18364              :      };  */
   18365              : 
   18366     17612757 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   18367              :                                             template_header_p
   18368     11331611 :                                             | DECL_SELF_REFERENCE_P (decl));
   18369      2552122 :   if (template_header_p && t && CLASS_TYPE_P (t)
   18370      8423029 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   18371      2552092 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   18372              :     {
   18373           21 :       auto_diagnostic_group d;
   18374           21 :       error ("%qT is not a template", t);
   18375           21 :       inform (location_of (t), "previous declaration here");
   18376           42 :       if (TYPE_CLASS_SCOPE_P (t)
   18377           24 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   18378            3 :         inform (input_location,
   18379              :                 "perhaps you want to explicitly add %<%T::%>",
   18380            3 :                 TYPE_CONTEXT (t));
   18381           21 :       return error_mark_node;
   18382           21 :     }
   18383              : 
   18384              :   return t;
   18385              : }
   18386              : 
   18387              : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   18388              :    Define the tag as a forward-reference if it is not defined.
   18389              : 
   18390              :    If a declaration is given, process it here, and report an error if
   18391              :    multiple declarations are not identical.
   18392              : 
   18393              :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   18394              :    the current frame for the name (since C++ allows new names in any
   18395              :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   18396              :    declaration.  Only look beginning from the current scope outward up
   18397              :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   18398              : 
   18399              :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   18400              :    a set of template parameters.  */
   18401              : 
   18402              : tree
   18403     25883393 : xref_tag (enum tag_types tag_code, tree name,
   18404              :           TAG_how how, bool template_header_p)
   18405              : {
   18406     25883393 :   enum tree_code code;
   18407     25883393 :   tree context = NULL_TREE;
   18408              : 
   18409     25883393 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   18410              : 
   18411     25883393 :   gcc_assert (identifier_p (name));
   18412              : 
   18413     25883393 :   switch (tag_code)
   18414              :     {
   18415              :     case record_type:
   18416              :     case class_type:
   18417              :       code = RECORD_TYPE;
   18418              :       break;
   18419              :     case union_type:
   18420              :       code = UNION_TYPE;
   18421              :       break;
   18422              :     case enum_type:
   18423              :       code = ENUMERAL_TYPE;
   18424              :       break;
   18425            0 :     default:
   18426            0 :       gcc_unreachable ();
   18427              :     }
   18428              : 
   18429              :   /* In case of anonymous name, xref_tag is only called to
   18430              :      make type node and push name.  Name lookup is not required.  */
   18431     25883393 :   tree t = NULL_TREE;
   18432     25883393 :   if (!IDENTIFIER_ANON_P (name))
   18433     23688671 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   18434              : 
   18435     25883393 :   if (t == error_mark_node)
   18436              :     return error_mark_node;
   18437              : 
   18438      2802235 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   18439      1332419 :       && template_class_depth (current_class_type)
   18440     26470897 :       && template_header_p)
   18441              :     {
   18442       343157 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   18443              :         return t;
   18444              : 
   18445              :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   18446              :          a definition of this tag.  Since, in addition, we are
   18447              :          currently processing a (member) template declaration of a
   18448              :          template class, we must be very careful; consider:
   18449              : 
   18450              :            template <class X> struct S1
   18451              : 
   18452              :            template <class U> struct S2
   18453              :            {
   18454              :              template <class V> friend struct S1;
   18455              :            };
   18456              : 
   18457              :          Here, the S2::S1 declaration should not be confused with the
   18458              :          outer declaration.  In particular, the inner version should
   18459              :          have a template parameter of level 2, not level 1.
   18460              : 
   18461              :          On the other hand, when presented with:
   18462              : 
   18463              :            template <class T> struct S1
   18464              :            {
   18465              :              template <class U> struct S2 {};
   18466              :              template <class U> friend struct S2;
   18467              :            };
   18468              : 
   18469              :          the friend must find S1::S2 eventually.  We accomplish this
   18470              :          by making sure that the new type we create to represent this
   18471              :          declaration has the right TYPE_CONTEXT.  */
   18472       343154 :       context = TYPE_CONTEXT (t);
   18473       343154 :       t = NULL_TREE;
   18474              :     }
   18475              : 
   18476     25883279 :   if (! t)
   18477              :     {
   18478              :       /* If no such tag is yet defined, create a forward-reference node
   18479              :          and record it as the "definition".
   18480              :          When a real declaration of this type is found,
   18481              :          the forward-reference will be altered into a real type.  */
   18482     20390550 :       if (code == ENUMERAL_TYPE)
   18483              :         {
   18484           13 :           error ("use of enum %q#D without previous declaration", name);
   18485           13 :           return error_mark_node;
   18486              :         }
   18487              : 
   18488     20390537 :       t = make_class_type (code);
   18489     20390537 :       TYPE_CONTEXT (t) = context;
   18490     20390537 :       if (IDENTIFIER_LAMBDA_P (name))
   18491              :         /* Mark it as a lambda type right now.  Our caller will
   18492              :            correct the value.  */
   18493      1469255 :         SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
   18494     20390537 :       t = pushtag (name, t, how);
   18495              :     }
   18496              :   else
   18497              :     {
   18498      5492729 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   18499              :         {
   18500              :           /* Check that we aren't trying to overload a class with different
   18501              :              constraints.  */
   18502      2208935 :           if (!redeclare_class_template (t, current_template_parms,
   18503              :                                          current_template_constraints ()))
   18504           60 :             return error_mark_node;
   18505              :         }
   18506      3283794 :       else if (!processing_template_decl
   18507      2956043 :                && CLASS_TYPE_P (t)
   18508      6213529 :                && CLASSTYPE_IS_TEMPLATE (t))
   18509              :         {
   18510            0 :           auto_diagnostic_group d;
   18511            0 :           error ("redeclaration of %qT as a non-template", t);
   18512            0 :           inform (location_of (t), "previous declaration %qD", t);
   18513            0 :           return error_mark_node;
   18514            0 :         }
   18515              : 
   18516      5492669 :       if (modules_p ()
   18517      5492669 :           && how == TAG_how::CURRENT_ONLY)
   18518              :         {
   18519        12084 :           tree decl = TYPE_NAME (t);
   18520        12084 :           if (!module_may_redeclare (decl))
   18521           15 :             return error_mark_node;
   18522              : 
   18523        12069 :           tree not_tmpl = STRIP_TEMPLATE (decl);
   18524        12069 :           if (DECL_LANG_SPECIFIC (not_tmpl)
   18525         4529 :               && DECL_MODULE_ATTACH_P (not_tmpl)
   18526           54 :               && !DECL_MODULE_EXPORT_P (not_tmpl)
   18527        12111 :               && module_exporting_p ())
   18528              :             {
   18529            6 :               auto_diagnostic_group d;
   18530            6 :               error ("conflicting exporting for declaration %qD", decl);
   18531            6 :               inform (DECL_SOURCE_LOCATION (decl),
   18532              :                       "previously declared here without exporting");
   18533            6 :             }
   18534              : 
   18535        12069 :           tree maybe_tmpl = decl;
   18536        12069 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   18537         8955 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   18538              : 
   18539              :           /* FIXME: we should do a more precise check for redefinitions
   18540              :              of a conflicting using-declaration here, as these diagnostics
   18541              :              are not ideal.  */
   18542        12069 :           if (DECL_LANG_SPECIFIC (decl)
   18543         4529 :               && DECL_MODULE_IMPORT_P (decl)
   18544        12123 :               && CP_DECL_CONTEXT (decl) == current_namespace)
   18545              :             {
   18546              :               /* Push it into this TU's symbol slot.  */
   18547           51 :               if (maybe_tmpl != decl)
   18548              :                 /* We're in the template parm binding level.
   18549              :                    Pushtag has logic to slide under that, but we're
   18550              :                    not pushing a *new* type.  */
   18551           20 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   18552              : 
   18553           51 :               pushdecl (maybe_tmpl);
   18554           51 :               if (maybe_tmpl != decl)
   18555           20 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   18556              :             }
   18557              : 
   18558        12069 :           set_instantiating_module (maybe_tmpl);
   18559              :         }
   18560              :     }
   18561              : 
   18562              :   return t;
   18563     25883393 : }
   18564              : 
   18565              : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   18566              :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   18567              :    access_* node, and the TREE_VALUE is the type of the base-class.
   18568              :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   18569              : 
   18570              : void
   18571     69256085 : xref_basetypes (tree ref, tree base_list)
   18572              : {
   18573     69256085 :   tree *basep;
   18574     69256085 :   tree binfo, base_binfo;
   18575     69256085 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   18576     69256085 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   18577     69256085 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   18578              :   /* Highest direct base index with annotations.  */
   18579     69256085 :   unsigned max_annotated_base = 0;
   18580     69256085 :   int i;
   18581     69256085 :   tree default_access;
   18582     69256085 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   18583              : 
   18584     69256085 :   if (ref == error_mark_node)
   18585           12 :     return;
   18586              : 
   18587              :   /* The base of a derived class is private by default, all others are
   18588              :      public.  */
   18589     69256085 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   18590     68661940 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   18591     69256085 :                     ? access_private_node : access_public_node);
   18592              : 
   18593              :   /* First, make sure that any templates in base-classes are
   18594              :      instantiated.  This ensures that if we call ourselves recursively
   18595              :      we do not get confused about which classes are marked and which
   18596              :      are not.  */
   18597     69256085 :   basep = &base_list;
   18598    101578739 :   while (*basep)
   18599              :     {
   18600     32322654 :       tree basetype = TREE_VALUE (*basep);
   18601              : 
   18602              :       /* The dependent_type_p call below should really be dependent_scope_p
   18603              :          so that we give a hard error about using an incomplete type as a
   18604              :          base, but we allow it with a pedwarn for backward
   18605              :          compatibility.  */
   18606     32322654 :       if (processing_template_decl
   18607     32322654 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   18608            3 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
   18609              :                                         diagnostics::kind::pedwarn);
   18610     32322654 :       if (!dependent_type_p (basetype)
   18611     32322654 :           && !complete_type_or_else (basetype, NULL))
   18612              :         /* An incomplete type.  Remove it from the list.  */
   18613           15 :         *basep = TREE_CHAIN (*basep);
   18614              :       else
   18615              :         {
   18616     32322639 :           max_bases++;
   18617     32322639 :           if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
   18618           28 :             max_annotated_base = max_bases;
   18619     32322639 :           if (TREE_TYPE (*basep))
   18620        67059 :             max_dvbases++;
   18621     32322639 :           if (CLASS_TYPE_P (basetype))
   18622     31538005 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18623     32322639 :           basep = &TREE_CHAIN (*basep);
   18624              :         }
   18625              :     }
   18626     69256085 :   max_vbases += max_dvbases;
   18627              : 
   18628     69256085 :   TYPE_MARKED_P (ref) = 1;
   18629              : 
   18630              :   /* The binfo slot should be empty, unless this is an (ill-formed)
   18631              :      redefinition.  */
   18632     69256085 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   18633              : 
   18634     69256085 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   18635              : 
   18636     69256085 :   binfo = make_tree_binfo (max_bases);
   18637              : 
   18638     69256085 :   TYPE_BINFO (ref) = binfo;
   18639     69256085 :   BINFO_OFFSET (binfo) = size_zero_node;
   18640     69256085 :   BINFO_TYPE (binfo) = ref;
   18641              : 
   18642              :   /* Apply base-class info set up to the variants of this type.  */
   18643     69256085 :   fixup_type_variants (ref);
   18644              : 
   18645     69256085 :   if (max_bases)
   18646              :     {
   18647     31433160 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
   18648     31433160 :       BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
   18649              :       /* A C++98 POD cannot have base classes.  */
   18650     31433160 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   18651              : 
   18652     31433160 :       if (TREE_CODE (ref) == UNION_TYPE)
   18653              :         {
   18654           12 :           error ("derived union %qT invalid", ref);
   18655           12 :           return;
   18656              :         }
   18657              :     }
   18658              : 
   18659     31433148 :   if (max_bases > 1)
   18660       702539 :     warning (OPT_Wmultiple_inheritance,
   18661              :              "%qT defined with multiple direct bases", ref);
   18662              : 
   18663     69256073 :   if (max_vbases)
   18664              :     {
   18665              :       /* An aggregate can't have virtual base classes.  */
   18666       199493 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   18667              : 
   18668       199493 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   18669              : 
   18670       199493 :       if (max_dvbases)
   18671        65648 :         warning (OPT_Wvirtual_inheritance,
   18672              :                  "%qT defined with direct virtual base", ref);
   18673              :     }
   18674              : 
   18675    101578700 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   18676              :     {
   18677     32322627 :       tree access = TREE_PURPOSE (base_list);
   18678     32322627 :       tree annotations = NULL_TREE;
   18679     32322627 :       if (TREE_CODE (access) == TREE_LIST)
   18680              :         {
   18681           28 :           annotations = TREE_VALUE (access);
   18682           28 :           access = TREE_PURPOSE (access);
   18683           78 :           for (tree *d = &annotations; *d; )
   18684              :             {
   18685           50 :               if (annotation_p (*d))
   18686              :                 {
   18687           50 :                   tree name = get_attribute_name (*d);
   18688           50 :                   tree args = TREE_VALUE (*d);
   18689           50 :                   const attribute_spec *as
   18690           50 :                     = lookup_attribute_spec (TREE_PURPOSE (*d));
   18691           50 :                   bool no_add_attrs = false;
   18692           50 :                   as->handler (&binfo, name, args, 0, &no_add_attrs);
   18693           50 :                   if (no_add_attrs)
   18694              :                     {
   18695            2 :                       *d = TREE_CHAIN (*d);
   18696            2 :                       continue;
   18697              :                     }
   18698              :                 }
   18699           48 :               d = &TREE_CHAIN (*d);
   18700              :             }
   18701              :         }
   18702     32322627 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   18703     32322627 :       tree basetype = TREE_VALUE (base_list);
   18704              : 
   18705     32322627 :       if (access == access_default_node)
   18706      4416320 :         access = default_access;
   18707              : 
   18708              :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   18709              :          aggregate can't have virtual, private, or protected base classes.  */
   18710     32322627 :       if (cxx_dialect < cxx17
   18711     32108530 :           || access != access_public_node
   18712     31188333 :           || via_virtual)
   18713      1198091 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   18714              : 
   18715     32322627 :       if (PACK_EXPANSION_P (basetype))
   18716        28501 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   18717     32322627 :       if (TREE_CODE (basetype) == TYPE_DECL)
   18718            0 :         basetype = TREE_TYPE (basetype);
   18719     32322627 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   18720              :         {
   18721           24 :           error ("base type %qT fails to be a struct or class type",
   18722              :                  basetype);
   18723           24 :           goto dropped_base;
   18724              :         }
   18725              : 
   18726     32322603 :       base_binfo = NULL_TREE;
   18727     32322603 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   18728              :         {
   18729     25479860 :           base_binfo = TYPE_BINFO (basetype);
   18730              :           /* The original basetype could have been a typedef'd type.  */
   18731     25479860 :           basetype = BINFO_TYPE (base_binfo);
   18732              : 
   18733              :           /* Inherit flags from the base.  */
   18734     76439580 :           TYPE_HAS_NEW_OPERATOR (ref)
   18735     25479860 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   18736     76439580 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   18737     25479860 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   18738     25479860 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   18739     25479860 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   18740     76439580 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   18741     25479860 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   18742     76439580 :           CLASSTYPE_REPEATED_BASE_P (ref)
   18743     25479860 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   18744              :         }
   18745              : 
   18746              :       /* We must do this test after we've seen through a typedef
   18747              :          type.  */
   18748     32322603 :       if (TYPE_MARKED_P (basetype))
   18749              :         {
   18750           18 :           if (basetype == ref)
   18751            0 :             error ("recursive type %qT undefined", basetype);
   18752              :           else
   18753           18 :             error ("duplicate base type %qT invalid", basetype);
   18754           18 :           goto dropped_base;
   18755              :         }
   18756              : 
   18757     32322585 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   18758              :         /* Regenerate the pack expansion for the bases. */
   18759        28501 :         basetype = make_pack_expansion (basetype);
   18760              : 
   18761     32322585 :       TYPE_MARKED_P (basetype) = 1;
   18762              : 
   18763     32322585 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   18764              :                                &igo_prev, via_virtual);
   18765     32322585 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   18766     32255541 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   18767              : 
   18768     32322585 :       unsigned len;
   18769     32322585 :       len = BINFO_N_BASE_BINFOS (binfo);
   18770     32322585 :       BINFO_BASE_APPEND (binfo, base_binfo);
   18771     32322585 :       BINFO_BASE_ACCESS (binfo, len) = access;
   18772     32322585 :       if (len < max_annotated_base)
   18773           34 :         BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
   18774     32322585 :       continue;
   18775              : 
   18776           42 :     dropped_base:
   18777              :       /* Update max_vbases to reflect the reality that we are dropping
   18778              :          this base:  if it reaches zero we want to undo the vec_alloc
   18779              :          above to avoid inconsistencies during error-recovery: eg, in
   18780              :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   18781              :          and vtt null (c++/27952).  */
   18782           42 :       if (via_virtual)
   18783           12 :         max_vbases--;
   18784           42 :       if (CLASS_TYPE_P (basetype))
   18785           30 :         max_vbases
   18786           33 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   18787     32322585 :     }
   18788              : 
   18789     69256073 :   unsigned len = BINFO_N_BASE_BINFOS (binfo);
   18790     69256073 :   if (len < max_bases)
   18791              :     {
   18792           42 :       if (len && max_annotated_base)
   18793            0 :         memmove (&BINFO_BASE_ACCESS (binfo, len),
   18794            0 :                  &BINFO_BASE_ACCESS (binfo, max_bases),
   18795            0 :                  MIN (max_annotated_base, len) * sizeof (tree));
   18796           42 :       BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
   18797              :                                                         len));
   18798              :     }
   18799              : 
   18800     69256073 :   if (CLASSTYPE_VBASECLASSES (ref)
   18801     69256073 :       && max_vbases == 0)
   18802           24 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   18803              : 
   18804     69455554 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   18805              :     /* If we didn't get max_vbases vbases, we must have shared at
   18806              :        least one of them, and are therefore diamond shaped.  */
   18807        21691 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   18808              : 
   18809              :   /* Unmark all the types.  */
   18810    101578658 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   18811     32322585 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   18812     69256073 :   TYPE_MARKED_P (ref) = 0;
   18813              : 
   18814              :   /* Now see if we have a repeated base type.  */
   18815     69256073 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   18816              :     {
   18817    174912962 :       for (base_binfo = binfo; base_binfo;
   18818    105657325 :            base_binfo = TREE_CHAIN (base_binfo))
   18819              :         {
   18820    105658049 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   18821              :             {
   18822          724 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   18823          724 :               break;
   18824              :             }
   18825    105657325 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   18826              :         }
   18827    174912962 :       for (base_binfo = binfo; base_binfo;
   18828    105657325 :            base_binfo = TREE_CHAIN (base_binfo))
   18829    105658049 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   18830    105657325 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   18831              :         else
   18832              :           break;
   18833              :     }
   18834              : }
   18835              : 
   18836              : 
   18837              : /* Copies the enum-related properties from type SRC to type DST.
   18838              :    Used with the underlying type of an enum and the enum itself.  */
   18839              : static void
   18840      1968001 : copy_type_enum (tree dst, tree src)
   18841              : {
   18842      1968001 :   tree t;
   18843      3936020 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   18844              :     {
   18845      1968019 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   18846      1968019 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   18847      1968019 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   18848      1968019 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   18849      1968019 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   18850      1968019 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   18851      1968019 :       unsigned valign = TYPE_ALIGN (src);
   18852      1968019 :       if (TYPE_USER_ALIGN (t))
   18853           12 :         valign = MAX (valign, TYPE_ALIGN (t));
   18854              :       else
   18855      1968007 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   18856      1968019 :       SET_TYPE_ALIGN (t, valign);
   18857      1968019 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   18858              :     }
   18859      1968001 : }
   18860              : 
   18861              : /* Begin compiling the definition of an enumeration type.
   18862              :    NAME is its name,
   18863              : 
   18864              :    if ENUMTYPE is not NULL_TREE then the type has already been found.
   18865              : 
   18866              :    UNDERLYING_TYPE is the type that will be used as the storage for
   18867              :    the enumeration type. This should be NULL_TREE if no storage type
   18868              :    was specified.
   18869              : 
   18870              :    ATTRIBUTES are any attributes specified after the enum-key.
   18871              : 
   18872              :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   18873              : 
   18874              :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   18875              : 
   18876              :    Returns the type object, as yet incomplete.
   18877              :    Also records info about it so that build_enumerator
   18878              :    may be used to declare the individual values as they are read.  */
   18879              : 
   18880              : tree
   18881      2322086 : start_enum (tree name, tree enumtype, tree underlying_type,
   18882              :             tree attributes, bool scoped_enum_p, bool *is_new)
   18883              : {
   18884      2322086 :   tree prevtype = NULL_TREE;
   18885      2322086 :   gcc_assert (identifier_p (name));
   18886              : 
   18887      2322086 :   if (is_new)
   18888      1875518 :     *is_new = false;
   18889              :   /* [C++0x dcl.enum]p5:
   18890              : 
   18891              :     If not explicitly specified, the underlying type of a scoped
   18892              :     enumeration type is int.  */
   18893      2322086 :   if (!underlying_type && scoped_enum_p)
   18894       171712 :     underlying_type = integer_type_node;
   18895              : 
   18896      2322086 :   if (underlying_type)
   18897       585847 :     underlying_type = cv_unqualified (underlying_type);
   18898              : 
   18899              :   /* If this is the real definition for a previous forward reference,
   18900              :      fill in the contents in the same object that used to be the
   18901              :      forward reference.  */
   18902      2322086 :   if (!enumtype)
   18903      2321950 :     enumtype = lookup_and_check_tag (enum_type, name,
   18904              :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   18905              :                                      /*template_header_p=*/false);
   18906              : 
   18907              :   /* In case of a template_decl, the only check that should be deferred
   18908              :      to instantiation time is the comparison of underlying types.  */
   18909      2322086 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   18910              :     {
   18911              :       /* Attempt to set the declaring module.  */
   18912        35076 :       if (modules_p ())
   18913              :         {
   18914          213 :           tree decl = TYPE_NAME (enumtype);
   18915          213 :           if (!module_may_redeclare (decl))
   18916            3 :             enumtype = error_mark_node;
   18917              :           else
   18918          210 :             set_instantiating_module (decl);
   18919              :         }
   18920              : 
   18921        35076 :       if (enumtype == error_mark_node)
   18922              :         ;
   18923        35292 :       else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   18924              :         {
   18925            6 :           auto_diagnostic_group d;
   18926            6 :           error_at (input_location, "scoped/unscoped mismatch "
   18927              :                     "in enum %q#T", enumtype);
   18928            6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18929              :                   "previous definition here");
   18930            6 :           enumtype = error_mark_node;
   18931            6 :         }
   18932        35067 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   18933              :         {
   18934            0 :           auto_diagnostic_group d;
   18935            0 :           error_at (input_location, "underlying type mismatch "
   18936              :                     "in enum %q#T", enumtype);
   18937            0 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18938              :                   "previous definition here");
   18939            0 :           enumtype = error_mark_node;
   18940            0 :         }
   18941        35052 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   18942        70119 :                && !same_type_p (underlying_type,
   18943              :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   18944              :         {
   18945           29 :           auto_diagnostic_group d;
   18946           29 :           error_at (input_location, "different underlying type "
   18947              :                     "in enum %q#T", enumtype);
   18948           29 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   18949              :                   "previous definition here");
   18950           29 :           underlying_type = NULL_TREE;
   18951           29 :         }
   18952              :     }
   18953              : 
   18954      2322086 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   18955        35067 :       || processing_template_decl)
   18956              :     {
   18957              :       /* In case of error, make a dummy enum to allow parsing to
   18958              :          continue.  */
   18959      2287120 :       if (enumtype == error_mark_node)
   18960              :         {
   18961            9 :           name = make_anon_name ();
   18962            9 :           enumtype = NULL_TREE;
   18963              :         }
   18964              : 
   18965              :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   18966              :          of an opaque enum, or an opaque enum of an already defined
   18967              :          enumeration (C++11).
   18968              :          In any other case, it'll be NULL_TREE. */
   18969      2287120 :       if (!enumtype)
   18970              :         {
   18971      2287016 :           if (is_new)
   18972      1840451 :             *is_new = true;
   18973              :         }
   18974      2287120 :       prevtype = enumtype;
   18975              : 
   18976              :       /* Do not push the decl more than once.  */
   18977      2287120 :       if (!enumtype
   18978          104 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   18979              :         {
   18980      2287019 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   18981      2287019 :           enumtype = pushtag (name, enumtype);
   18982              : 
   18983      2287019 :           if (enumtype != error_mark_node)
   18984              :             {
   18985              :               /* The enum is considered opaque until the opening '{' of the
   18986              :                  enumerator list.  */
   18987      2287001 :               SET_OPAQUE_ENUM_P (enumtype, true);
   18988      2287001 :               ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   18989              : 
   18990              :               /* std::byte aliases anything.  */
   18991      2287001 :               if (TYPE_CONTEXT (enumtype) == std_node
   18992      2639193 :                   && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   18993        13103 :                 TYPE_ALIAS_SET (enumtype) = 0;
   18994              :             }
   18995              :         }
   18996              :       else
   18997          101 :           enumtype = xref_tag (enum_type, name);
   18998              : 
   18999      2287120 :       if (enumtype == error_mark_node)
   19000              :         return error_mark_node;
   19001              :     }
   19002              : 
   19003      2322068 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   19004              : 
   19005      2322068 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   19006              : 
   19007      2322068 :   if (underlying_type)
   19008              :     {
   19009       585815 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   19010              :         /* We already checked that it matches, don't change it to a different
   19011              :            typedef variant.  */;
   19012       550792 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   19013              :         {
   19014       550721 :           copy_type_enum (enumtype, underlying_type);
   19015       550721 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19016              :         }
   19017           71 :       else if (dependent_type_p (underlying_type))
   19018           58 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   19019              :       else
   19020              :         {
   19021           13 :           error ("underlying type %qT of %qT must be an integral type",
   19022              :                  underlying_type, enumtype);
   19023           13 :           copy_type_enum (enumtype, integer_type_node);
   19024           13 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   19025              :         }
   19026              :     }
   19027              : 
   19028              :   /* If into a template class, the returned enum is always the first
   19029              :      declaration (opaque or not) seen. This way all the references to
   19030              :      this type will be to the same declaration. The following ones are used
   19031              :      only to check for definition errors.  */
   19032      2322068 :   if (prevtype && processing_template_decl)
   19033              :     return prevtype;
   19034              :   else
   19035      2321967 :     return enumtype;
   19036              : }
   19037              : 
   19038              : /* Returns true if TYPE is an enum that uses an enumerator name for
   19039              :    linkage purposes at namespace scope.  The term is defined in [dcl.enum]/12
   19040              :    for all enums, not just those at namespace scope, but for backward ABI
   19041              :    compatibility we want to treat those not at namespace scope the old way
   19042              :    and e.g. mangle the class scope ones based on their position within the
   19043              :    class rather than the first enumerator.  */
   19044              : 
   19045              : bool
   19046    396188413 : enum_with_enumerator_for_linkage_p (tree type)
   19047              : {
   19048    396188413 :   return (cxx_dialect >= cxx20
   19049    391728597 :           && UNSCOPED_ENUM_P (type)
   19050     19430448 :           && TYPE_ANON_P (type)
   19051      2969729 :           && TYPE_VALUES (type)
   19052    398013024 :           && TYPE_NAMESPACE_SCOPE_P (type));
   19053              : }
   19054              : 
   19055              : /* After processing and defining all the values of an enumeration type,
   19056              :    install their decls in the enumeration type.
   19057              :    ENUMTYPE is the type object.  */
   19058              : 
   19059              : void
   19060      2219485 : finish_enum_value_list (tree enumtype)
   19061              : {
   19062      2219485 :   tree values;
   19063      2219485 :   tree underlying_type;
   19064      2219485 :   tree decl;
   19065      2219485 :   tree value;
   19066      2219485 :   tree minnode, maxnode;
   19067      2219485 :   tree t;
   19068              : 
   19069      2219485 :   ENUM_BEING_DEFINED_P (enumtype) = 0;
   19070              : 
   19071      2219485 :   bool fixed_underlying_type_p
   19072      2219485 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   19073              : 
   19074              :   /* We built up the VALUES in reverse order.  */
   19075      2219485 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   19076              : 
   19077              :   /* For an enum defined in a template, just set the type of the values;
   19078              :      all further processing is postponed until the template is
   19079              :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   19080              :      works.  */
   19081      2219485 :   if (processing_template_decl)
   19082              :     {
   19083       438985 :       for (values = TYPE_VALUES (enumtype);
   19084       785414 :            values;
   19085       438985 :            values = TREE_CHAIN (values))
   19086       438985 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   19087              :       return;
   19088              :     }
   19089              : 
   19090              :   /* Determine the minimum and maximum values of the enumerators.  */
   19091      1873056 :   if (TYPE_VALUES (enumtype))
   19092              :     {
   19093              :       minnode = maxnode = NULL_TREE;
   19094              : 
   19095     11222385 :       for (values = TYPE_VALUES (enumtype);
   19096     13059719 :            values;
   19097     11222385 :            values = TREE_CHAIN (values))
   19098              :         {
   19099     11222385 :           decl = TREE_VALUE (values);
   19100              : 
   19101              :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   19102              :              each enumerator has the type of its enumeration.  Prior to the
   19103              :              closing brace, the type of each enumerator is the type of its
   19104              :              initializing value.  */
   19105     11222385 :           TREE_TYPE (decl) = enumtype;
   19106              : 
   19107              :           /* Update the minimum and maximum values, if appropriate.  */
   19108     11222385 :           value = DECL_INITIAL (decl);
   19109     11222385 :           if (!value || TREE_CODE (value) != INTEGER_CST)
   19110            7 :             value = integer_zero_node;
   19111              :           /* Figure out what the minimum and maximum values of the
   19112              :              enumerators are.  */
   19113     11222385 :           if (!minnode)
   19114              :             minnode = maxnode = value;
   19115      9385051 :           else if (tree_int_cst_lt (maxnode, value))
   19116              :             maxnode = value;
   19117      1476371 :           else if (tree_int_cst_lt (value, minnode))
   19118       165687 :             minnode = value;
   19119              :         }
   19120              :     }
   19121              :   else
   19122              :     /* [dcl.enum]
   19123              : 
   19124              :        If the enumerator-list is empty, the underlying type is as if
   19125              :        the enumeration had a single enumerator with value 0.  */
   19126        35722 :     minnode = maxnode = integer_zero_node;
   19127              : 
   19128      1873056 :   if (!fixed_underlying_type_p)
   19129              :     {
   19130              :       /* Compute the number of bits require to represent all values of the
   19131              :          enumeration.  We must do this before the type of MINNODE and
   19132              :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   19133              :          on the TREE_TYPE of the value it is passed.  */
   19134      1417267 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   19135      1417267 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   19136      1417267 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   19137      1417267 :       int precision = MAX (lowprec, highprec);
   19138      1417267 :       unsigned int itk;
   19139      1417267 :       bool use_short_enum;
   19140              : 
   19141              :       /* Determine the underlying type of the enumeration.
   19142              : 
   19143              :          [dcl.enum]
   19144              : 
   19145              :          The underlying type of an enumeration is an integral type that
   19146              :          can represent all the enumerator values defined in the
   19147              :          enumeration.  It is implementation-defined which integral type is
   19148              :          used as the underlying type for an enumeration except that the
   19149              :          underlying type shall not be larger than int unless the value of
   19150              :          an enumerator cannot fit in an int or unsigned int.
   19151              : 
   19152              :          We use "int" or an "unsigned int" as the underlying type, even if
   19153              :          a smaller integral type would work, unless the user has
   19154              :          explicitly requested that we use the smallest possible type.  The
   19155              :          user can request that for all enumerations with a command line
   19156              :          flag, or for just one enumeration with an attribute.  */
   19157              : 
   19158      2834534 :       use_short_enum = flag_short_enums
   19159      1417267 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   19160              : 
   19161              :       /* If the precision of the type was specified with an attribute and it
   19162              :          was too small, give an error.  Otherwise, use it.  */
   19163      1417267 :       if (TYPE_PRECISION (enumtype))
   19164              :         {
   19165           11 :           if (precision > TYPE_PRECISION (enumtype))
   19166            0 :             error ("specified mode too small for enumerated values");
   19167              :           else
   19168              :             {
   19169           11 :               use_short_enum = true;
   19170           11 :               precision = TYPE_PRECISION (enumtype);
   19171              :             }
   19172              :         }
   19173              : 
   19174      2755847 :       for (itk = (use_short_enum ? itk_char : itk_int);
   19175      2755847 :            itk != itk_none;
   19176              :            itk++)
   19177              :         {
   19178      2755844 :           underlying_type = integer_types[itk];
   19179      2755844 :           if (underlying_type != NULL_TREE
   19180      2755826 :               && TYPE_PRECISION (underlying_type) >= precision
   19181      5509601 :               && TYPE_SIGN (underlying_type) == sgn)
   19182              :             break;
   19183              :         }
   19184      1417267 :       if (itk == itk_none)
   19185              :         {
   19186              :           /* DR 377
   19187              : 
   19188              :              IF no integral type can represent all the enumerator values, the
   19189              :              enumeration is ill-formed.  */
   19190            3 :           error ("no integral type can represent all of the enumerator values "
   19191              :                  "for %qT", enumtype);
   19192            3 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   19193            3 :           underlying_type = integer_types[itk_unsigned_long_long];
   19194              :         }
   19195              : 
   19196              :       /* [dcl.enum]
   19197              : 
   19198              :          The value of sizeof() applied to an enumeration type, an object
   19199              :          of an enumeration type, or an enumerator, is the value of sizeof()
   19200              :          applied to the underlying type.  */
   19201      1417267 :       copy_type_enum (enumtype, underlying_type);
   19202              : 
   19203              :       /* Compute the minimum and maximum values for the type.
   19204              : 
   19205              :          [dcl.enum]
   19206              : 
   19207              :          For an enumeration where emin is the smallest enumerator and emax
   19208              :          is the largest, the values of the enumeration are the values of the
   19209              :          underlying type in the range bmin to bmax, where bmin and bmax are,
   19210              :          respectively, the smallest and largest values of the smallest bit-
   19211              :          field that can store emin and emax.  */
   19212              : 
   19213              :       /* The middle-end currently assumes that types with TYPE_PRECISION
   19214              :          narrower than their underlying type are suitably zero or sign
   19215              :          extended to fill their mode.  Similarly, it assumes that the front
   19216              :          end assures that a value of a particular type must be within
   19217              :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   19218              : 
   19219              :          We used to set these fields based on bmin and bmax, but that led
   19220              :          to invalid assumptions like optimizing away bounds checking.  So
   19221              :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   19222              :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   19223              :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   19224      1417267 :       ENUM_UNDERLYING_TYPE (enumtype)
   19225      1417267 :         = build_distinct_type_copy (underlying_type);
   19226      1417267 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   19227      1417267 :       set_min_and_max_values_for_integral_type
   19228      1417267 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   19229              : 
   19230              :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   19231      1417267 :       if (flag_strict_enums)
   19232           38 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   19233              : 
   19234      1417267 :       if (use_short_enum)
   19235              :         {
   19236          122 :           TYPE_PACKED (enumtype) = use_short_enum;
   19237          122 :           fixup_attribute_variants (enumtype);
   19238              :         }
   19239              :     }
   19240              :   else
   19241       455789 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   19242              : 
   19243              :   /* If the enum is exported, mark the consts too.  */
   19244      1873056 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   19245      1491437 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   19246      1873644 :                    && at_namespace_scope_p ());
   19247              : 
   19248              :   /* Convert each of the enumerators to the type of the underlying
   19249              :      type of the enumeration.  */
   19250     13095441 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   19251              :     {
   19252     11222385 :       decl = TREE_VALUE (values);
   19253     11222385 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   19254     11222385 :       if (fixed_underlying_type_p)
   19255              :         /* If the enumeration type has a fixed underlying type, we
   19256              :            already checked all of the enumerator values.  */
   19257      3908539 :         value = DECL_INITIAL (decl);
   19258              :       else
   19259      7313846 :         value = perform_implicit_conversion (underlying_type,
   19260      7313846 :                                              DECL_INITIAL (decl),
   19261              :                                              tf_warning_or_error);
   19262     11222385 :       if (!value)
   19263            3 :         value = integer_zero_node;
   19264              :       /* Do not clobber shared ints.  But do share identical enumerators.  */
   19265     11222385 :       value = fold_convert (enumtype, value);
   19266              : 
   19267     11222385 :       DECL_INITIAL (decl) = value;
   19268     11222385 :       if (export_p)
   19269         3594 :         DECL_MODULE_EXPORT_P (decl) = true;
   19270     11222385 :     }
   19271              : 
   19272              :   /* Fix up all variant types of this enum type.  */
   19273      3746152 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   19274      1873096 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   19275              : 
   19276      1873056 :   if (at_class_scope_p ()
   19277      1000387 :       && COMPLETE_TYPE_P (current_class_type)
   19278      1873120 :       && UNSCOPED_ENUM_P (enumtype))
   19279              :     {
   19280           45 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   19281              :       /* TYPE_FIELDS needs fixup.  */
   19282           45 :       fixup_type_variants (current_class_type);
   19283              :     }
   19284              : 
   19285              :   /* P2115: An unnamed enum uses the name of its first enumerator for
   19286              :      linkage purposes; reset the type linkage if that is the case.  */
   19287      1873056 :   if (enum_with_enumerator_for_linkage_p (enumtype))
   19288       337351 :     reset_type_linkage (enumtype);
   19289              : 
   19290              :   /* Finish debugging output for this type.  */
   19291      1873056 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   19292              : 
   19293              :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   19294              :      so that this change in types doesn't confuse us later on.  */
   19295      1873056 :   clear_cv_and_fold_caches ();
   19296              : }
   19297              : 
   19298              : /* Finishes the enum type. This is called only the first time an
   19299              :    enumeration is seen, be it opaque or odinary.
   19300              :    ENUMTYPE is the type object.  */
   19301              : 
   19302              : void
   19303      2208461 : finish_enum (tree enumtype)
   19304              : {
   19305      2208461 :   if (processing_template_decl)
   19306              :     {
   19307       346457 :       if (at_function_scope_p ())
   19308         9164 :         add_stmt (build_min (TAG_DEFN, enumtype));
   19309       346457 :       return;
   19310              :     }
   19311              : 
   19312              :   /* If this is a forward declaration, there should not be any variants,
   19313              :      though we can get a variant in the middle of an enum-specifier with
   19314              :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   19315      3724008 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   19316              :               && (TYPE_VALUES (enumtype)
   19317              :                   || !TYPE_NEXT_VARIANT (enumtype)));
   19318              : }
   19319              : 
   19320              : /* Build and install a CONST_DECL for an enumeration constant of the
   19321              :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   19322              :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   19323              :    Assignment of sequential values by default is handled here.  */
   19324              : 
   19325              : tree
   19326     11661344 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   19327              :                   location_t loc)
   19328              : {
   19329     11661344 :   tree decl;
   19330     11661344 :   tree context;
   19331     11661344 :   tree type;
   19332              : 
   19333              :   /* scalar_constant_value will pull out this expression, so make sure
   19334              :      it's folded as appropriate.
   19335              : 
   19336              :      Creating a TARGET_EXPR in a template breaks when substituting, and
   19337              :      here we would create it for instance when using a class prvalue with
   19338              :      a user-defined conversion function.  So don't use such a tree.  We
   19339              :      instantiate VALUE here to get errors about bad enumerators even in
   19340              :      a template that does not get instantiated.  */
   19341     11661344 :   if (processing_template_decl)
   19342       438985 :     value = maybe_fold_non_dependent_expr (value);
   19343              : 
   19344              :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   19345              :      result in the enum being assigned the next value in sequence.  */
   19346     11661344 :   if (value == error_mark_node)
   19347              :     value = NULL_TREE;
   19348              : 
   19349              :   /* Remove no-op casts from the value.  */
   19350     11661306 :   if (value)
   19351      8892464 :     STRIP_TYPE_NOPS (value);
   19352              : 
   19353     11661344 :   if (! processing_template_decl)
   19354              :     {
   19355              :       /* Validate and default VALUE.  */
   19356     11222359 :       if (value != NULL_TREE)
   19357              :         {
   19358      5081307 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   19359              :             {
   19360      2599843 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   19361              :                                                            value, true);
   19362      2599843 :               if (tmp_value)
   19363      5081307 :                 value = tmp_value;
   19364              :             }
   19365      2481464 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19366              :                    (TREE_TYPE (value)))
   19367           39 :             value = perform_implicit_conversion_flags
   19368           39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   19369              :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   19370              : 
   19371      5081307 :           if (value == error_mark_node)
   19372              :             value = NULL_TREE;
   19373              : 
   19374      5081286 :           if (value != NULL_TREE)
   19375              :             {
   19376      5081286 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   19377              :                   (TREE_TYPE (value)))
   19378              :                 {
   19379           17 :                   error_at (cp_expr_loc_or_input_loc (value),
   19380              :                             "enumerator value for %qD must have integral or "
   19381              :                             "unscoped enumeration type", name);
   19382           17 :                   value = NULL_TREE;
   19383              :                 }
   19384              :               else
   19385              :                 {
   19386      5081269 :                   value = cxx_constant_value (value);
   19387              : 
   19388      5081269 :                   if (TREE_CODE (value) != INTEGER_CST)
   19389              :                     {
   19390           48 :                       error ("enumerator value for %qD is not an integer "
   19391              :                              "constant", name);
   19392           48 :                       value = NULL_TREE;
   19393              :                     }
   19394              :                 }
   19395              :             }
   19396              :         }
   19397              : 
   19398              :       /* Default based on previous value.  */
   19399           65 :       if (value == NULL_TREE)
   19400              :         {
   19401      6141138 :           if (TYPE_VALUES (enumtype))
   19402              :             {
   19403      5619608 :               tree prev_value;
   19404              : 
   19405              :               /* C++03 7.2/4: If no initializer is specified for the first
   19406              :                  enumerator, the type is an unspecified integral
   19407              :                  type. Otherwise the type is the same as the type of the
   19408              :                  initializing value of the preceding enumerator unless the
   19409              :                  incremented value is not representable in that type, in
   19410              :                  which case the type is an unspecified integral type
   19411              :                  sufficient to contain the incremented value.  */
   19412      5619608 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   19413      5619608 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   19414            2 :                 value = error_mark_node;
   19415              :               else
   19416              :                 {
   19417      5619606 :                   wi::overflow_type overflowed;
   19418      5619606 :                   tree type = TREE_TYPE (prev_value);
   19419      5619606 :                   signop sgn = TYPE_SIGN (type);
   19420      5619606 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   19421      5619606 :                                            &overflowed);
   19422      5619606 :                   if (!overflowed)
   19423              :                     {
   19424      5619606 :                       bool pos = !wi::neg_p (wi, sgn);
   19425      5619606 :                       if (!wi::fits_to_tree_p (wi, type))
   19426              :                         {
   19427              :                           unsigned int itk;
   19428           53 :                           for (itk = itk_int; itk != itk_none; itk++)
   19429              :                             {
   19430           53 :                               type = integer_types[itk];
   19431           53 :                               if (type != NULL_TREE
   19432           53 :                                   && (pos || !TYPE_UNSIGNED (type))
   19433          106 :                                   && wi::fits_to_tree_p (wi, type))
   19434              :                                 break;
   19435              :                             }
   19436           17 :                           if (type && cxx_dialect < cxx11
   19437            6 :                               && itk > itk_unsigned_long)
   19438            3 :                             pedwarn (input_location, OPT_Wlong_long,
   19439              :                                      pos ? G_("\
   19440              : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   19441              : incremented enumerator value is too large for %<long%>"));
   19442              :                         }
   19443      5619606 :                       if (type == NULL_TREE)
   19444            0 :                         overflowed = wi::OVF_UNKNOWN;
   19445              :                       else
   19446      5619606 :                         value = wide_int_to_tree (type, wi);
   19447              :                     }
   19448              : 
   19449      5619606 :                   if (overflowed)
   19450              :                     {
   19451            0 :                       error ("overflow in enumeration values at %qD", name);
   19452            0 :                       value = error_mark_node;
   19453              :                     }
   19454      5619606 :                 }
   19455              :             }
   19456              :           else
   19457       521530 :             value = integer_zero_node;
   19458              :         }
   19459              : 
   19460              :       /* Remove no-op casts from the value.  */
   19461     11222359 :       STRIP_TYPE_NOPS (value);
   19462              : 
   19463              :       /* If the underlying type of the enum is fixed, check whether
   19464              :          the enumerator values fits in the underlying type.  If it
   19465              :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   19466     11222359 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   19467              :           && value
   19468     11222359 :           && TREE_CODE (value) == INTEGER_CST)
   19469              :         {
   19470      3908511 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   19471            9 :             error ("enumerator value %qE is outside the range of underlying "
   19472            9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   19473              : 
   19474              :           /* Convert the value to the appropriate type.  */
   19475      3908511 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   19476              :         }
   19477              :     }
   19478              : 
   19479              :   /* C++ associates enums with global, function, or class declarations.  */
   19480     11661344 :   context = current_scope ();
   19481              : 
   19482              :   /* Build the actual enumeration constant.  Note that the enumeration
   19483              :      constants have the underlying type of the enum (if it is fixed)
   19484              :      or the type of their initializer (if the underlying type of the
   19485              :      enum is not fixed):
   19486              : 
   19487              :       [ C++0x dcl.enum ]
   19488              : 
   19489              :         If the underlying type is fixed, the type of each enumerator
   19490              :         prior to the closing brace is the underlying type; if the
   19491              :         initializing value of an enumerator cannot be represented by
   19492              :         the underlying type, the program is ill-formed. If the
   19493              :         underlying type is not fixed, the type of each enumerator is
   19494              :         the type of its initializing value.
   19495              : 
   19496              :     If the underlying type is not fixed, it will be computed by
   19497              :     finish_enum and we will reset the type of this enumerator.  Of
   19498              :     course, if we're processing a template, there may be no value.  */
   19499     11661344 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   19500              : 
   19501     11661344 :   decl = build_decl (loc, CONST_DECL, name, type);
   19502              : 
   19503     11661344 :   DECL_CONTEXT (decl) = enumtype;
   19504     11661344 :   TREE_CONSTANT (decl) = 1;
   19505     11661344 :   TREE_READONLY (decl) = 1;
   19506     11661344 :   DECL_INITIAL (decl) = value;
   19507              : 
   19508     11661344 :   if (attributes)
   19509       127893 :     cplus_decl_attributes (&decl, attributes, 0);
   19510              : 
   19511     11661344 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   19512              :     {
   19513              :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   19514              :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   19515              :          things like `S::i' later.)  */
   19516              : 
   19517              :       /* The enumerator may be getting declared outside of its enclosing
   19518              :          class, like so:
   19519              : 
   19520              :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   19521              : 
   19522              :          For which case we need to make sure that the access of `S::i'
   19523              :          matches the access of `S::E'.  */
   19524      2027283 :       auto cas = make_temp_override (current_access_specifier);
   19525      2027283 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   19526      2027283 :       finish_member_declaration (decl);
   19527      2027283 :     }
   19528              :   else
   19529      9634061 :     pushdecl (decl);
   19530              : 
   19531              :   /* Add this enumeration constant to the list for this type.  */
   19532     11661344 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   19533              : 
   19534     11661344 :   return decl;
   19535              : }
   19536              : 
   19537              : /* Look for an enumerator with the given NAME within the enumeration
   19538              :    type ENUMTYPE.  This routine is used primarily for qualified name
   19539              :    lookup into an enumerator in C++0x, e.g.,
   19540              : 
   19541              :      enum class Color { Red, Green, Blue };
   19542              : 
   19543              :      Color color = Color::Red;
   19544              : 
   19545              :    Returns the value corresponding to the enumerator, or
   19546              :    NULL_TREE if no such enumerator was found.  */
   19547              : tree
   19548     27209108 : lookup_enumerator (tree enumtype, tree name)
   19549              : {
   19550     27209108 :   tree e;
   19551     27209108 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   19552              : 
   19553     27209108 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   19554     54418119 :   return e? TREE_VALUE (e) : NULL_TREE;
   19555              : }
   19556              : 
   19557              : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   19558              : 
   19559              : tree
   19560            0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   19561              :                         vec<string_int_pair> *values)
   19562              : {
   19563            0 :   location_t saved_loc = input_location;
   19564            0 :   input_location = loc;
   19565              : 
   19566            0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   19567              :                               NULL_TREE, false, NULL);
   19568            0 :   if (!OPAQUE_ENUM_P (enumtype))
   19569              :     {
   19570            0 :       auto_diagnostic_group d;
   19571            0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   19572            0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   19573              :               "previous definition here");
   19574            0 :       return enumtype;
   19575            0 :     }
   19576            0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   19577            0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   19578              : 
   19579            0 :   for (const string_int_pair &value : values)
   19580            0 :     build_enumerator (get_identifier (value.first),
   19581            0 :                       build_int_cst (integer_type_node, value.second),
   19582              :                       enumtype, NULL_TREE, loc);
   19583              : 
   19584            0 :   finish_enum_value_list (enumtype);
   19585            0 :   finish_enum (enumtype);
   19586              : 
   19587            0 :   input_location = saved_loc;
   19588            0 :   return enumtype;
   19589              : }
   19590              : 
   19591              : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   19592              : 
   19593              : tree
   19594            0 : cxx_simulate_record_decl (location_t loc, const char *name,
   19595              :                           array_slice<const tree> fields)
   19596              : {
   19597            0 :   iloc_sentinel ils (loc);
   19598              : 
   19599            0 :   tree ident = get_identifier (name);
   19600            0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   19601            0 :   if (type != error_mark_node
   19602            0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   19603              :     {
   19604            0 :       error ("redefinition of %q#T", type);
   19605            0 :       type = error_mark_node;
   19606              :     }
   19607            0 :   if (type == error_mark_node)
   19608            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19609              : 
   19610            0 :   xref_basetypes (type, NULL_TREE);
   19611            0 :   type = begin_class_definition (type);
   19612            0 :   if (type == error_mark_node)
   19613            0 :     return lhd_simulate_record_decl (loc, name, fields);
   19614              : 
   19615            0 :   for (tree field : fields)
   19616            0 :     finish_member_declaration (field);
   19617              : 
   19618            0 :   type = finish_struct (type, NULL_TREE);
   19619              : 
   19620            0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   19621            0 :   set_underlying_type (decl);
   19622            0 :   lang_hooks.decls.pushdecl (decl);
   19623              : 
   19624            0 :   return type;
   19625            0 : }
   19626              : 
   19627              : /* We're defining DECL.  Make sure that its type is OK.  */
   19628              : 
   19629              : static void
   19630    159124652 : check_function_type (tree decl, tree current_function_parms)
   19631              : {
   19632    159124652 :   tree fntype = TREE_TYPE (decl);
   19633    159124652 :   tree return_type = complete_type (TREE_TYPE (fntype));
   19634              : 
   19635              :   /* In a function definition, arg types must be complete.  */
   19636    159124652 :   require_complete_types_for_parms (current_function_parms);
   19637              : 
   19638    159124652 :   if (dependent_type_p (return_type)
   19639    159124652 :       || type_uses_auto (return_type))
   19640     50222646 :     return;
   19641    108902006 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   19642              :     {
   19643           12 :       tree args = TYPE_ARG_TYPES (fntype);
   19644              : 
   19645           12 :       error ("return type %q#T is incomplete", return_type);
   19646              : 
   19647              :       /* Make it return void instead.  */
   19648           12 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   19649            3 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   19650              :                                              void_type_node,
   19651            3 :                                              TREE_CHAIN (args));
   19652              :       else
   19653           18 :         fntype = build_function_type (void_type_node, args,
   19654            9 :                                       TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
   19655           12 :       fntype = (cp_build_type_attribute_variant
   19656           12 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   19657           12 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   19658           12 :       TREE_TYPE (decl) = fntype;
   19659              :     }
   19660              :   else
   19661              :     {
   19662    108901994 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   19663    108901994 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   19664    108901994 :                            DECL_SOURCE_LOCATION (decl));
   19665              :     }
   19666              : }
   19667              : 
   19668              : /* True iff FN is an implicitly-defined default constructor.  */
   19669              : 
   19670              : static bool
   19671     16637398 : implicit_default_ctor_p (tree fn)
   19672              : {
   19673     16637398 :   return (DECL_CONSTRUCTOR_P (fn)
   19674     16637398 :           && !user_provided_p (fn)
   19675     18500916 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   19676              : }
   19677              : 
   19678              : /* Clobber the contents of *this to let the back end know that the object
   19679              :    storage is dead when we enter the constructor or leave the destructor.  */
   19680              : 
   19681              : static tree
   19682      1447433 : build_clobber_this (clobber_kind kind)
   19683              : {
   19684              :   /* Clobbering an empty base is pointless, and harmful if its one byte
   19685              :      TYPE_SIZE overlays real data.  */
   19686      1447433 :   if (is_empty_class (current_class_type))
   19687            0 :     return void_node;
   19688              : 
   19689              :   /* If we have virtual bases, clobber the whole object, but only if we're in
   19690              :      charge.  If we don't have virtual bases, clobber the as-base type so we
   19691              :      don't mess with tail padding.  */
   19692      1447433 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   19693              : 
   19694      1447433 :   tree ctype = current_class_type;
   19695      1447433 :   if (!vbases)
   19696      1440536 :     ctype = CLASSTYPE_AS_BASE (ctype);
   19697              : 
   19698      1447433 :   tree clobber = build_clobber (ctype, kind);
   19699              : 
   19700      1447433 :   tree thisref = current_class_ref;
   19701      1447433 :   if (ctype != current_class_type)
   19702              :     {
   19703       166779 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   19704       166779 :       thisref = convert_from_reference (thisref);
   19705              :     }
   19706              : 
   19707      1447433 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   19708      1447433 :   if (kind == CLOBBER_OBJECT_BEGIN)
   19709            0 :     TREE_SET_CODE (exprstmt, INIT_EXPR);
   19710      1447433 :   if (vbases)
   19711         6897 :     exprstmt = build_if_in_charge (exprstmt);
   19712              : 
   19713              :   return exprstmt;
   19714              : }
   19715              : 
   19716              : /* Create the FUNCTION_DECL for a function definition.
   19717              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   19718              :    they describe the function's name and the type it returns,
   19719              :    but twisted together in a fashion that parallels the syntax of C.
   19720              : 
   19721              :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   19722              :    DECLARATOR is really the DECL for the function we are about to
   19723              :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   19724              :    indicating that the function is an inline defined in-class.
   19725              : 
   19726              :    This function creates a binding context for the function body
   19727              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   19728              : 
   19729              :    For C++, we must first check whether that datum makes any sense.
   19730              :    For example, "class A local_a(1,2);" means that variable local_a
   19731              :    is an aggregate of type A, which should have a constructor
   19732              :    applied to it with the argument list [1, 2].
   19733              : 
   19734              :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   19735              :    or may be a BLOCK if the function has been defined previously
   19736              :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   19737              :    error_mark_node if the function has never been defined, or
   19738              :    a BLOCK if the function has been defined somewhere.  */
   19739              : 
   19740              : bool
   19741    159124688 : start_preparsed_function (tree decl1, tree attrs, int flags)
   19742              : {
   19743    159124688 :   tree ctype = NULL_TREE;
   19744    159124688 :   bool doing_friend = false;
   19745              : 
   19746              :   /* Sanity check.  */
   19747    159124688 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   19748    159124688 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   19749              : 
   19750    159124688 :   tree fntype = TREE_TYPE (decl1);
   19751    159124688 :   if (DECL_CLASS_SCOPE_P (decl1))
   19752    117355570 :     ctype = DECL_CONTEXT (decl1);
   19753              :   else
   19754              :     {
   19755     83538236 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   19756              : 
   19757     41769117 :       if (ctype)
   19758    159124688 :         doing_friend = true;
   19759              :     }
   19760              : 
   19761              :   /* Adjust for #pragma target/optimize if this is an artificial function that
   19762              :      (probably) didn't go through grokfndecl.  We particularly don't want this
   19763              :      for deferred instantiations, which should match their template.  */
   19764    159124688 :   if (DECL_ARTIFICIAL (decl1))
   19765      3606827 :     decl_attributes (&decl1, NULL_TREE, 0);
   19766              : 
   19767    159124688 :   if (DECL_DECLARED_INLINE_P (decl1)
   19768    159124688 :       && lookup_attribute ("noinline", attrs))
   19769              :     {
   19770            0 :       auto_urlify_attributes sentinel;
   19771            0 :       warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   19772              :                   "inline function %qD given attribute %qs", decl1, "noinline");
   19773            0 :     }
   19774              : 
   19775              :   /* Handle gnu_inline attribute.  */
   19776    159124688 :   if (GNU_INLINE_P (decl1))
   19777              :     {
   19778      1930703 :       DECL_EXTERNAL (decl1) = 1;
   19779      1930703 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   19780      1930703 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   19781      1930703 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   19782              :     }
   19783              : 
   19784    159124688 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   19785              :     /* This is a constructor, we must ensure that any default args
   19786              :        introduced by this definition are propagated to the clones
   19787              :        now. The clones are used directly in overload resolution.  */
   19788     19859398 :     adjust_clone_args (decl1);
   19789              : 
   19790              :   /* Sometimes we don't notice that a function is a static member, and
   19791              :      build a METHOD_TYPE for it.  Fix that up now.  */
   19792    159124688 :   gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
   19793              :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   19794              : 
   19795              :   /* Set up current_class_type, and enter the scope of the class, if
   19796              :      appropriate.  */
   19797    159124688 :   if (ctype)
   19798    121781773 :     push_nested_class (ctype);
   19799              : 
   19800              :   /* Now that we have entered the scope of the class, we must restore
   19801              :      the bindings for any template parameters surrounding DECL1, if it
   19802              :      is an inline member template.  (Order is important; consider the
   19803              :      case where a template parameter has the same name as a field of
   19804              :      the class.)  It is not until after this point that
   19805              :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   19806    159124688 :   if (flags & SF_INCLASS_INLINE)
   19807     81700681 :     maybe_begin_member_template_processing (decl1);
   19808              : 
   19809              :   /* Effective C++ rule 15.  */
   19810    159124688 :   if (warn_ecpp
   19811          123 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   19812           30 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   19813    159124718 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   19814            0 :     warning (OPT_Weffc__,
   19815              :              "%<operator=%> should return a reference to %<*this%>");
   19816              : 
   19817              :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   19818              :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   19819    159124688 :   if (!DECL_INITIAL (decl1))
   19820     34317249 :     DECL_INITIAL (decl1) = error_mark_node;
   19821              : 
   19822              :   /* This function exists in static storage.
   19823              :      (This does not mean `static' in the C sense!)  */
   19824    159124688 :   TREE_STATIC (decl1) = 1;
   19825              : 
   19826              :   /* We must call push_template_decl after current_class_type is set
   19827              :      up.  (If we are processing inline definitions after exiting a
   19828              :      class scope, current_class_type will be NULL_TREE until set above
   19829              :      by push_nested_class.)  */
   19830    159124688 :   if (processing_template_decl)
   19831              :     {
   19832     93469887 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   19833     93469887 :       if (newdecl1 == error_mark_node)
   19834              :         {
   19835           36 :           if (ctype)
   19836            9 :             pop_nested_class ();
   19837           36 :           return false;
   19838              :         }
   19839     93469851 :       decl1 = newdecl1;
   19840              :     }
   19841              : 
   19842              :   /* Make sure the parameter and return types are reasonable.  When
   19843              :      you declare a function, these types can be incomplete, but they
   19844              :      must be complete when you define the function.  */
   19845    159124652 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   19846              : 
   19847              :   /* Build the return declaration for the function.  */
   19848    159124652 :   tree restype = TREE_TYPE (fntype);
   19849              : 
   19850    159124652 :   if (DECL_RESULT (decl1) == NULL_TREE)
   19851              :     {
   19852              :       /* In a template instantiation, copy the return type location.  When
   19853              :          parsing, the location will be set in grokdeclarator.  */
   19854     65345924 :       location_t loc = input_location;
   19855     65345924 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   19856              :         {
   19857     30905888 :           tree tmpl = template_for_substitution (decl1);
   19858     30905888 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   19859     30017968 :             loc = DECL_SOURCE_LOCATION (res);
   19860              :         }
   19861              : 
   19862     65345924 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   19863     65345924 :       DECL_ARTIFICIAL (resdecl) = 1;
   19864     65345924 :       DECL_IGNORED_P (resdecl) = 1;
   19865     65345924 :       DECL_RESULT (decl1) = resdecl;
   19866              : 
   19867     65345924 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   19868              :     }
   19869              : 
   19870              :   /* Record the decl so that the function name is defined.
   19871              :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   19872              :      use the old decl.  */
   19873    159124652 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   19874              :     {
   19875              :       /* A specialization is not used to guide overload resolution.  */
   19876     19746664 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   19877     19727469 :           && !(DECL_USE_TEMPLATE (decl1) &&
   19878        12824 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   19879              :         {
   19880      9452563 :           tree olddecl = pushdecl (decl1);
   19881              : 
   19882      9452563 :           if (olddecl == error_mark_node)
   19883              :             /* If something went wrong when registering the declaration,
   19884              :                use DECL1; we have to have a FUNCTION_DECL to use when
   19885              :                parsing the body of the function.  */
   19886              :             ;
   19887              :           else
   19888              :             {
   19889              :               /* Otherwise, OLDDECL is either a previous declaration
   19890              :                  of the same function or DECL1 itself.  */
   19891              : 
   19892      9452350 :               if (warn_missing_declarations
   19893           21 :                   && olddecl == decl1
   19894           15 :                   && !DECL_MAIN_P (decl1)
   19895           15 :                   && TREE_PUBLIC (decl1)
   19896      9452362 :                   && !DECL_DECLARED_INLINE_P (decl1))
   19897              :                 {
   19898            9 :                   tree context;
   19899              : 
   19900              :                   /* Check whether DECL1 is in an anonymous
   19901              :                      namespace.  */
   19902            9 :                   for (context = DECL_CONTEXT (decl1);
   19903           18 :                        context;
   19904            9 :                        context = DECL_CONTEXT (context))
   19905              :                     {
   19906           12 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   19907           12 :                           && DECL_NAME (context) == NULL_TREE)
   19908              :                         break;
   19909              :                     }
   19910              : 
   19911            9 :                   if (context == NULL)
   19912            6 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   19913            6 :                                 OPT_Wmissing_declarations,
   19914              :                                 "no previous declaration for %qD", decl1);
   19915              :                 }
   19916              : 
   19917      9452350 :               decl1 = olddecl;
   19918              :             }
   19919              :         }
   19920              :       else
   19921              :         {
   19922              :           /* We need to set the DECL_CONTEXT.  */
   19923       809519 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   19924            0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   19925              :         }
   19926     10262082 :       fntype = TREE_TYPE (decl1);
   19927     10262082 :       restype = TREE_TYPE (fntype);
   19928              : 
   19929              :       /* If #pragma weak applies, mark the decl appropriately now.
   19930              :          The pragma only applies to global functions.  Because
   19931              :          determining whether or not the #pragma applies involves
   19932              :          computing the mangled name for the declaration, we cannot
   19933              :          apply the pragma until after we have merged this declaration
   19934              :          with any previous declarations; if the original declaration
   19935              :          has a linkage specification, that specification applies to
   19936              :          the definition as well, and may affect the mangled name.  */
   19937     10262082 :       if (DECL_FILE_SCOPE_P (decl1))
   19938      2496948 :         maybe_apply_pragma_weak (decl1);
   19939              :     }
   19940              : 
   19941              :   /* We are now in the scope of the function being defined.  */
   19942    159124652 :   current_function_decl = decl1;
   19943              : 
   19944              :   /* Save the parm names or decls from this function's declarator
   19945              :      where store_parm_decls will find them.  */
   19946    159124652 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   19947              : 
   19948              :   /* Let the user know we're compiling this function.  */
   19949    159124652 :   announce_function (decl1);
   19950              : 
   19951    159124652 :   gcc_assert (DECL_INITIAL (decl1));
   19952              : 
   19953              :   /* This function may already have been parsed, in which case just
   19954              :      return; our caller will skip over the body without parsing.  */
   19955    159124652 :   if (DECL_INITIAL (decl1) != error_mark_node)
   19956              :     return true;
   19957              : 
   19958              :   /* Initialize RTL machinery.  We cannot do this until
   19959              :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   19960              :      even when processing a template; this is how we get
   19961              :      CFUN set up, and our per-function variables initialized.
   19962              :      FIXME factor out the non-RTL stuff.  */
   19963    159124652 :   cp_binding_level *bl = current_binding_level;
   19964    159124652 :   allocate_struct_function (decl1, processing_template_decl);
   19965              : 
   19966              :   /* Initialize the language data structures.  Whenever we start
   19967              :      a new function, we destroy temporaries in the usual way.  */
   19968    159124652 :   cfun->language = ggc_cleared_alloc<language_function> ();
   19969    159124652 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   19970    159124652 :   current_binding_level = bl;
   19971              : 
   19972              :   /* If we are (erroneously) defining a function that we have already
   19973              :      defined before, wipe out what we knew before.  */
   19974    159124652 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   19975    159124652 :   FNDECL_USED_AUTO (decl1) = false;
   19976    159124652 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   19977              : 
   19978    159124652 :   if (!processing_template_decl && type_uses_auto (restype))
   19979              :     {
   19980       920645 :       FNDECL_USED_AUTO (decl1) = true;
   19981       920645 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   19982              :     }
   19983              : 
   19984              :   /* Start the statement-tree, start the tree now.  */
   19985    159124652 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   19986              : 
   19987    159124652 :   if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
   19988              :     {
   19989              :       /* We know that this was set up by `grokclassfn'.  We do not
   19990              :          wait until `store_parm_decls', since evil parse errors may
   19991              :          never get us to that point.  Here we keep the consistency
   19992              :          between `current_class_type' and `current_class_ptr'.  */
   19993    103270518 :       tree t = DECL_ARGUMENTS (decl1);
   19994              : 
   19995    103270518 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   19996    103270518 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   19997              : 
   19998    103270518 :       cp_function_chain->x_current_class_ref
   19999    103270518 :         = cp_build_fold_indirect_ref (t);
   20000              :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   20001    103270518 :       cp_function_chain->x_current_class_ptr = t;
   20002              : 
   20003              :       /* Constructors and destructors need to know whether they're "in
   20004              :          charge" of initializing virtual base classes.  */
   20005    103270518 :       t = DECL_CHAIN (t);
   20006    103270518 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   20007              :         {
   20008        16514 :           current_in_charge_parm = t;
   20009        16514 :           t = DECL_CHAIN (t);
   20010              :         }
   20011    103270518 :       if (DECL_HAS_VTT_PARM_P (decl1))
   20012              :         {
   20013        33087 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   20014        33087 :           current_vtt_parm = t;
   20015              :         }
   20016              :     }
   20017              : 
   20018    287327965 :   bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
   20019              :                           /* Implicitly-defined methods (like the
   20020              :                              destructor for a class in which no destructor
   20021              :                              is explicitly declared) must not be defined
   20022              :                              until their definition is needed.  So, we
   20023              :                              ignore interface specifications for
   20024              :                              compiler-generated functions.  */
   20025    193801920 :                           && !DECL_ARTIFICIAL (decl1));
   20026    159124652 :   struct c_fileinfo *finfo
   20027    159124652 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   20028              : 
   20029    159124652 :   if (processing_template_decl)
   20030              :     /* Don't mess with interface flags.  */;
   20031     65654801 :   else if (DECL_INTERFACE_KNOWN (decl1))
   20032              :     {
   20033     19231632 :       tree ctx = decl_function_context (decl1);
   20034              : 
   20035     19231632 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   20036     15293034 :         DECL_EXTERNAL (decl1) = 0;
   20037              : 
   20038     19231632 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   20039              :         /* This is a function in a local class in an extern inline
   20040              :            or template function.  */
   20041      2935954 :         comdat_linkage (decl1);
   20042              :     }
   20043              :   /* If this function belongs to an interface, it is public.
   20044              :      If it belongs to someone else's interface, it is also external.
   20045              :      This only affects inlines and template instantiations.  */
   20046     46423169 :   else if (!finfo->interface_unknown && honor_interface)
   20047              :     {
   20048          106 :       if (DECL_DECLARED_INLINE_P (decl1)
   20049          106 :           || DECL_TEMPLOID_INSTANTIATION (decl1))
   20050              :         {
   20051           82 :           DECL_EXTERNAL (decl1)
   20052          164 :             = (finfo->interface_only
   20053           82 :                || (DECL_DECLARED_INLINE_P (decl1)
   20054           36 :                    && ! flag_implement_inlines
   20055            0 :                    && !DECL_VINDEX (decl1)));
   20056              : 
   20057              :           /* For WIN32 we also want to put these in linkonce sections.  */
   20058           82 :           maybe_make_one_only (decl1);
   20059              :         }
   20060              :       else
   20061           24 :         DECL_EXTERNAL (decl1) = 0;
   20062          106 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20063              :       /* If this function is in an interface implemented in this file,
   20064              :          make sure that the back end knows to emit this function
   20065              :          here.  */
   20066          106 :       if (!DECL_EXTERNAL (decl1))
   20067           60 :         mark_needed (decl1);
   20068              :     }
   20069     46423063 :   else if (finfo->interface_unknown && finfo->interface_only
   20070            0 :            && honor_interface)
   20071              :     {
   20072              :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   20073              :          interface, we will have both finfo->interface_unknown and
   20074              :          finfo->interface_only set.  In that case, we don't want to
   20075              :          use the normal heuristics because someone will supply a
   20076              :          #pragma implementation elsewhere, and deducing it here would
   20077              :          produce a conflict.  */
   20078            0 :       comdat_linkage (decl1);
   20079            0 :       DECL_EXTERNAL (decl1) = 0;
   20080            0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   20081            0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   20082              :     }
   20083              :   else
   20084              :     {
   20085              :       /* This is a definition, not a reference.
   20086              :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   20087     46423063 :       if (!GNU_INLINE_P (decl1))
   20088     46423060 :         DECL_EXTERNAL (decl1) = 0;
   20089              : 
   20090     46423063 :       if ((DECL_DECLARED_INLINE_P (decl1)
   20091      1841792 :            || DECL_TEMPLOID_INSTANTIATION (decl1))
   20092     48026752 :           && ! DECL_INTERFACE_KNOWN (decl1))
   20093     46184960 :         DECL_DEFER_OUTPUT (decl1) = 1;
   20094              :       else
   20095       238103 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   20096              :     }
   20097              : 
   20098              :   /* Determine the ELF visibility attribute for the function.  We must not
   20099              :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   20100              :      to merge any attributes appropriately.  We also need to wait until
   20101              :      linkage is set.  */
   20102    159124652 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   20103    143338375 :     determine_visibility (decl1);
   20104              : 
   20105    159124652 :   if (!processing_template_decl)
   20106     65654801 :     maybe_instantiate_noexcept (decl1);
   20107              : 
   20108    159124652 :   begin_scope (sk_function_parms, decl1);
   20109              : 
   20110    159124652 :   ++function_depth;
   20111              : 
   20112    159124652 :   start_fname_decls ();
   20113              : 
   20114    159124652 :   store_parm_decls (current_function_parms);
   20115              : 
   20116    159124652 :   start_function_contracts (decl1);
   20117              : 
   20118    159124652 :   if (!processing_template_decl
   20119     65654801 :       && flag_lifetime_dse > 1
   20120    131300232 :       && DECL_CONSTRUCTOR_P (decl1)
   20121              :       /* Clobbering an empty base is harmful if it overlays real data.  */
   20122     18448949 :       && !is_empty_class (current_class_type)
   20123              :       /* We can't clobber safely for an implicitly-defined default constructor
   20124              :          because part of the initialization might happen before we enter the
   20125              :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   20126     16636764 :       && !implicit_default_ctor_p (decl1)
   20127    174626519 :       && !lookup_attribute ("clobber *this",
   20128     15501867 :                             DECL_ATTRIBUTES (current_class_ptr)))
   20129     15492301 :     DECL_ATTRIBUTES (current_class_ptr)
   20130     30984602 :       = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
   20131     15492301 :                    DECL_ATTRIBUTES (current_class_ptr));
   20132              : 
   20133    159124652 :   if (!processing_template_decl
   20134    131309602 :       && DECL_CONSTRUCTOR_P (decl1)
   20135     18450191 :       && sanitize_flags_p (SANITIZE_VPTR)
   20136         1902 :       && !DECL_CLONED_FUNCTION_P (decl1)
   20137    159125286 :       && !implicit_default_ctor_p (decl1))
   20138          480 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   20139              : 
   20140    159124652 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   20141    159124082 :     start_lambda_scope (decl1);
   20142              : 
   20143              :   return true;
   20144              : }
   20145              : 
   20146              : 
   20147              : /* Like start_preparsed_function, except that instead of a
   20148              :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   20149              : 
   20150              :    Returns true on success.  If the DECLARATOR is not suitable
   20151              :    for a function, we return false, which tells the parser to
   20152              :    skip the entire function.  */
   20153              : 
   20154              : bool
   20155     38343776 : start_function (cp_decl_specifier_seq *declspecs,
   20156              :                 const cp_declarator *declarator,
   20157              :                 tree attrs)
   20158              : {
   20159     38343776 :   tree decl1;
   20160              : 
   20161     38343776 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   20162     38343776 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   20163     38343776 :   if (decl1 == error_mark_node)
   20164              :     return false;
   20165              : 
   20166     38343410 :   if (DECL_MAIN_P (decl1))
   20167              :     /* main must return int.  grokfndecl should have corrected it
   20168              :        (and issued a diagnostic) if the user got it wrong.  */
   20169        33672 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   20170              :                              integer_type_node));
   20171              : 
   20172     38343410 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   20173              : }
   20174              : 
   20175              : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   20176              :    FN.  */
   20177              : 
   20178              : bool
   20179    304492352 : use_eh_spec_block (tree fn)
   20180              : {
   20181    302545234 :   return (flag_exceptions && flag_enforce_eh_specs
   20182    302545234 :           && !processing_template_decl
   20183              :           /* We insert the EH_SPEC_BLOCK only in the original
   20184              :              function; then, it is copied automatically to the
   20185              :              clones.  */
   20186    114485046 :           && !DECL_CLONED_FUNCTION_P (fn)
   20187              :           /* Implicitly-generated constructors and destructors have
   20188              :              exception specifications.  However, those specifications
   20189              :              are the union of the possible exceptions specified by the
   20190              :              constructors/destructors for bases and members, so no
   20191              :              unallowed exception will ever reach this function.  By
   20192              :              not creating the EH_SPEC_BLOCK we save a little memory,
   20193              :              and we avoid spurious warnings about unreachable
   20194              :              code.  */
   20195     98740546 :           && !DECL_DEFAULTED_FN (fn)
   20196    400792174 :           && !type_throw_all_p (TREE_TYPE (fn)));
   20197              : }
   20198              : 
   20199              : /* Helper function to push ARGS into the current lexical scope.  DECL
   20200              :    is the function declaration.  NONPARMS is used to handle enum
   20201              :    constants.  */
   20202              : 
   20203              : void
   20204    154403536 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   20205              : {
   20206              :   /* If we're doing semantic analysis, then we'll call pushdecl
   20207              :      for each of these.  We must do them in reverse order so that
   20208              :      they end in the correct forward order.  */
   20209    154403536 :   args = nreverse (args);
   20210              : 
   20211    154403536 :   tree next;
   20212    473775709 :   for (tree parm = args; parm; parm = next)
   20213              :     {
   20214    319372173 :       next = DECL_CHAIN (parm);
   20215    319372173 :       if (TREE_CODE (parm) == PARM_DECL)
   20216    319372173 :         pushdecl (parm);
   20217            0 :       else if (nonparms)
   20218              :         {
   20219              :           /* If we find an enum constant or a type tag, put it aside for
   20220              :              the moment.  */
   20221            0 :           TREE_CHAIN (parm) = NULL_TREE;
   20222            0 :           *nonparms = chainon (*nonparms, parm);
   20223              :         }
   20224              :     }
   20225              : 
   20226              :   /* Get the decls in their original chain order and record in the
   20227              :      function.  This is all and only the PARM_DECLs that were
   20228              :      pushed into scope by the loop above.  */
   20229    154403536 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   20230    154403536 : }
   20231              : 
   20232              : /* Store the parameter declarations into the current function declaration.
   20233              :    This is called after parsing the parameter declarations, before
   20234              :    digesting the body of the function.
   20235              : 
   20236              :    Also install to binding contour return value identifier, if any.  */
   20237              : 
   20238              : static void
   20239    159124652 : store_parm_decls (tree current_function_parms)
   20240              : {
   20241    159124652 :   tree fndecl = current_function_decl;
   20242              : 
   20243              :   /* This is a chain of any other decls that came in among the parm
   20244              :      declarations.  If a parm is declared with  enum {foo, bar} x;
   20245              :      then CONST_DECLs for foo and bar are put here.  */
   20246    159124652 :   tree nonparms = NULL_TREE;
   20247              : 
   20248    159124652 :   if (current_function_parms)
   20249              :     {
   20250              :       /* This case is when the function was defined with an ANSI prototype.
   20251              :          The parms already have decls, so we need not do anything here
   20252              :          except record them as in effect
   20253              :          and complain if any redundant old-style parm decls were written.  */
   20254              : 
   20255    150985093 :       tree specparms = current_function_parms;
   20256              : 
   20257              :       /* Must clear this because it might contain TYPE_DECLs declared
   20258              :              at class level.  */
   20259    150985093 :       current_binding_level->names = NULL;
   20260              : 
   20261    150985093 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   20262              :     }
   20263              :   else
   20264      8139559 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   20265              : 
   20266              :   /* Now store the final chain of decls for the arguments
   20267              :      as the decl-chain of the current lexical scope.
   20268              :      Put the enumerators in as well, at the front so that
   20269              :      DECL_ARGUMENTS is not modified.  */
   20270    159124652 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   20271              : 
   20272              :   /* Register cleanups for parameters with trivial_abi attribute, the cleanup
   20273              :      of which is the callee's responsibility.  */
   20274    159124652 :   if (!processing_template_decl)
   20275    172648543 :     for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
   20276              :       {
   20277    106993742 :         if (TREE_CODE (parm) == PARM_DECL)
   20278              :           {
   20279    106993742 :             tree parm_type = TREE_TYPE (parm);
   20280    106993742 :             if (has_trivial_abi_attribute (parm_type))
   20281              :               {
   20282           15 :                 tree cleanup
   20283           15 :                   = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
   20284           15 :                 if (cleanup && cleanup != error_mark_node)
   20285           15 :                   finish_decl_cleanup (parm, cleanup);
   20286              :               }
   20287              :           }
   20288              :       }
   20289              : 
   20290    159124652 :   if (use_eh_spec_block (current_function_decl))
   20291     24334991 :     current_eh_spec_block = begin_eh_spec_block ();
   20292    159124652 : }
   20293              : 
   20294              : 
   20295              : /* Mark CDTOR's implicit THIS argument for returning, if required by
   20296              :    the ABI..  Return the decl for THIS, if it is to be returned, and
   20297              :    NULL otherwise.  */
   20298              : 
   20299              : tree
   20300    136220765 : maybe_prepare_return_this (tree cdtor)
   20301              : {
   20302    136220765 :   if (targetm.cxx.cdtor_returns_this ())
   20303            0 :     if (tree val = DECL_ARGUMENTS (cdtor))
   20304              :       {
   20305            0 :         suppress_warning (val, OPT_Wuse_after_free);
   20306            0 :         return val;
   20307              :       }
   20308              : 
   20309              :   return NULL_TREE;
   20310              : }
   20311              : 
   20312              : /* Set the return value of the [cd]tor if the ABI wants that.  */
   20313              : 
   20314              : void
   20315      8036452 : maybe_return_this ()
   20316              : {
   20317      8036452 :   if (tree val = maybe_prepare_return_this (current_function_decl))
   20318              :     {
   20319              :       /* Return the address of the object.  */
   20320            0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   20321            0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   20322            0 :                     DECL_RESULT (current_function_decl), val);
   20323            0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   20324            0 :       add_stmt (exprstmt);
   20325              :     }
   20326      8036452 : }
   20327              : 
   20328              : /* Do all the processing for the beginning of a destructor; set up the
   20329              :    vtable pointers and cleanups for bases and members.  */
   20330              : 
   20331              : static void
   20332      1586206 : begin_destructor_body (void)
   20333              : {
   20334      1586206 :   tree compound_stmt;
   20335              : 
   20336              :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   20337              :      issued an error message.  We still want to try to process the
   20338              :      body of the function, but initialize_vtbl_ptrs will crash if
   20339              :      TYPE_BINFO is NULL.  */
   20340      1586206 :   if (COMPLETE_TYPE_P (current_class_type))
   20341              :     {
   20342      1586206 :       compound_stmt = begin_compound_stmt (0);
   20343              :       /* Make all virtual function table pointers in non-virtual base
   20344              :          classes point to CURRENT_CLASS_TYPE's virtual function
   20345              :          tables.  */
   20346      1586206 :       initialize_vtbl_ptrs (current_class_ptr);
   20347      1586206 :       finish_compound_stmt (compound_stmt);
   20348              : 
   20349      1586206 :       if (flag_lifetime_dse
   20350              :           /* Clobbering an empty base is harmful if it overlays real data.  */
   20351      1586206 :           && !is_empty_class (current_class_type))
   20352              :       {
   20353      1447496 :         if (sanitize_flags_p (SANITIZE_VPTR)
   20354          235 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   20355      1447559 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   20356              :           {
   20357           63 :             tree binfo = TYPE_BINFO (current_class_type);
   20358           63 :             tree ref
   20359           63 :               = cp_build_fold_indirect_ref (current_class_ptr);
   20360              : 
   20361           63 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   20362           63 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   20363           63 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   20364              :                                               NOP_EXPR, vtbl,
   20365              :                                               tf_warning_or_error);
   20366              :             /* If the vptr is shared with some virtual nearly empty base,
   20367              :                don't clear it if not in charge, the dtor of the virtual
   20368              :                nearly empty base will do that later.  */
   20369           63 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   20370              :               {
   20371              :                 tree c = current_class_type;
   20372           66 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   20373              :                   {
   20374           63 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   20375              :                       {
   20376           36 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   20377              :                                                 tf_warning_or_error);
   20378           36 :                         stmt = build_if_in_charge (stmt);
   20379           36 :                         break;
   20380              :                       }
   20381           27 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   20382              :                   }
   20383              :               }
   20384           63 :             finish_decl_cleanup (NULL_TREE, stmt);
   20385              :           }
   20386              :         else
   20387      1447433 :           finish_decl_cleanup (NULL_TREE,
   20388              :                                build_clobber_this (CLOBBER_OBJECT_END));
   20389              :       }
   20390              : 
   20391              :       /* And insert cleanups for our bases and members so that they
   20392              :          will be properly destroyed if we throw.  */
   20393      1586206 :       push_base_cleanups ();
   20394              :     }
   20395      1586206 : }
   20396              : 
   20397              : /* Do the necessary processing for the beginning of a function body, which
   20398              :    in this case includes member-initializers, but not the catch clauses of
   20399              :    a function-try-block.  Currently, this means opening a binding level
   20400              :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   20401              :    and capture proxies (in a lambda operator()).  */
   20402              : 
   20403              : tree
   20404    125309663 : begin_function_body (void)
   20405              : {
   20406    257878415 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   20407              :     return NULL_TREE;
   20408              : 
   20409     24365710 :   if (processing_template_decl)
   20410              :     /* Do nothing now.  */;
   20411              :   else
   20412              :     /* Always keep the BLOCK node associated with the outermost pair of
   20413              :        curly braces of a function.  These are needed for correct
   20414              :        operation of dwarfout.c.  */
   20415      8143735 :     keep_next_level (true);
   20416              : 
   20417     24365710 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   20418     24365710 :   current_binding_level->artificial = 1;
   20419              : 
   20420     24365710 :   if (processing_template_decl)
   20421              :     /* Do nothing now.  */;
   20422     16287470 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   20423      1586206 :     begin_destructor_body ();
   20424              : 
   20425              :   return stmt;
   20426              : }
   20427              : 
   20428              : /* Do the processing for the end of a function body.  Currently, this means
   20429              :    closing out the cleanups for fully-constructed bases and members, and in
   20430              :    the case of the destructor, deleting the object if desired.  Again, this
   20431              :    is only meaningful for [cd]tors, since they are the only functions where
   20432              :    there is a significant distinction between the main body and any
   20433              :    function catch clauses.  Handling, say, main() return semantics here
   20434              :    would be wrong, as flowing off the end of a function catch clause for
   20435              :    main() would also need to return 0.  */
   20436              : 
   20437              : void
   20438    125309639 : finish_function_body (tree compstmt)
   20439              : {
   20440    125309639 :   if (compstmt == NULL_TREE)
   20441              :     return;
   20442              : 
   20443              :   /* Close the block.  */
   20444     24365710 :   finish_compound_stmt (compstmt);
   20445              : 
   20446     24365710 :   if (processing_template_decl)
   20447              :     /* Do nothing now.  */;
   20448      8143735 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   20449      8143735 :            || DECL_DESTRUCTOR_P (current_function_decl))
   20450      7731705 :     maybe_return_this ();
   20451              : }
   20452              : 
   20453              : /* Given a function, returns the BLOCK corresponding to the outermost level
   20454              :    of curly braces, skipping the artificial block created for constructor
   20455              :    initializers.  */
   20456              : 
   20457              : tree
   20458       341102 : outer_curly_brace_block (tree fndecl)
   20459              : {
   20460       341102 :   tree block = DECL_INITIAL (fndecl);
   20461       341102 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20462              :     return block;
   20463         1042 :   block = BLOCK_SUBBLOCKS (block);
   20464         1042 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   20465              :     return block;
   20466            0 :   block = BLOCK_SUBBLOCKS (block);
   20467            0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   20468              :   return block;
   20469              : }
   20470              : 
   20471              : /* If FNDECL is a class's key method, add the class to the list of
   20472              :    keyed classes that should be emitted.  */
   20473              : 
   20474              : static void
   20475    159128604 : record_key_method_defined (tree fndecl)
   20476              : {
   20477    214986666 :   if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
   20478    103354832 :       && DECL_VIRTUAL_P (fndecl)
   20479    161840217 :       && !processing_template_decl)
   20480              :     {
   20481      1403228 :       tree fnclass = DECL_CONTEXT (fndecl);
   20482      1403228 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   20483              :         {
   20484        26158 :           tree classdecl = TYPE_NAME (fnclass);
   20485              :           /* Classes attached to a named module are already handled.  */
   20486        26158 :           if (!DECL_LANG_SPECIFIC (classdecl)
   20487        26481 :               || !DECL_MODULE_ATTACH_P (classdecl))
   20488        26113 :             vec_safe_push (keyed_classes, fnclass);
   20489              :         }
   20490              :     }
   20491    159128604 : }
   20492              : 
   20493              : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   20494              :    of "return *this;" immediately before its location, using FNDECL's
   20495              :    first statement (if any) to give the indentation, if appropriate.  */
   20496              : 
   20497              : static void
   20498           18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   20499              : {
   20500           18 :   location_t indent = UNKNOWN_LOCATION;
   20501           18 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   20502           18 :   if (stmts)
   20503            9 :     indent = EXPR_LOCATION (stmts);
   20504           18 :   richloc->add_fixit_insert_formatted ("return *this;",
   20505              :                                        richloc->get_loc (),
   20506              :                                        indent);
   20507           18 : }
   20508              : 
   20509              : /* Finish up a function declaration and compile that function
   20510              :    all the way to assembler language output.  The free the storage
   20511              :    for the function definition. INLINE_P is TRUE if we just
   20512              :    finished processing the body of an in-class inline function
   20513              :    definition.  (This processing will have taken place after the
   20514              :    class definition is complete.)  */
   20515              : 
   20516              : tree
   20517    159124616 : finish_function (bool inline_p)
   20518              : {
   20519    159124616 :   tree fndecl = current_function_decl;
   20520    159124616 :   tree fntype, ctype = NULL_TREE;
   20521    159124616 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   20522              : 
   20523              :   /* When we get some parse errors, we can end up without a
   20524              :      current_function_decl, so cope.  */
   20525    159124616 :   if (fndecl == NULL_TREE || fndecl == error_mark_node)
   20526            0 :     return error_mark_node;
   20527              : 
   20528    159124616 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20529    159124046 :     finish_lambda_scope ();
   20530              : 
   20531    159124616 :   if (c_dialect_objc ())
   20532            0 :     objc_finish_function ();
   20533              : 
   20534    159124616 :   record_key_method_defined (fndecl);
   20535              : 
   20536    159124616 :   fntype = TREE_TYPE (fndecl);
   20537              : 
   20538              :   /*  TREE_READONLY (fndecl) = 1;
   20539              :       This caused &foo to be of type ptr-to-const-function
   20540              :       which then got a warning when stored in a ptr-to-function variable.  */
   20541              : 
   20542    159124616 :   gcc_assert (building_stmt_list_p ());
   20543              :   /* The current function is being defined, so its DECL_INITIAL should
   20544              :      be set, and unless there's a multiple definition, it should be
   20545              :      error_mark_node.  */
   20546    159124616 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   20547              : 
   20548    159124616 :   cp_coroutine_transform *coroutine = nullptr;
   20549    159124616 :   if (flag_coroutines
   20550    156385395 :       && !processing_template_decl
   20551     63884272 :       && DECL_COROUTINE_P (fndecl)
   20552    159129548 :       && !DECL_RAMP_FN (fndecl))
   20553              :     {
   20554         1700 :       gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
   20555              :                            && !DECL_DEFAULTED_FN (fndecl));
   20556         1700 :       coroutine = new cp_coroutine_transform (fndecl, inline_p);
   20557         1700 :       if (coroutine && coroutine->cp_valid_coroutine ())
   20558         1700 :         coroutine->apply_transforms ();
   20559              : 
   20560              :       /* We should handle coroutine IFNs in middle end lowering.  */
   20561         1700 :       cfun->coroutine_component = true;
   20562              : 
   20563              :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   20564         1700 :       if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
   20565          360 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20566              :                               (TREE_TYPE (fndecl)),
   20567          360 :                               current_eh_spec_block);
   20568              : 
   20569              :      /* If outlining succeeded, then add contracts handling if needed.  */
   20570         1700 :      if (coroutine->cp_valid_coroutine ())
   20571         1616 :         maybe_apply_function_contracts (fndecl);
   20572              :     }
   20573              :   else
   20574              :   /* For a cloned function, we've already got all the code we need;
   20575              :      there's no need to add any extra bits.  */
   20576    159122916 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   20577              :     {
   20578              :       /* Make it so that `main' always returns 0 by default.  */
   20579    143336639 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   20580    143370296 :           && !TREE_THIS_VOLATILE (current_function_decl))
   20581        33657 :         finish_return_stmt (integer_zero_node);
   20582              : 
   20583    143336639 :       if (use_eh_spec_block (current_function_decl))
   20584     24334628 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   20585              :                               (TREE_TYPE (current_function_decl)),
   20586     24334628 :                               current_eh_spec_block);
   20587              : 
   20588    143336639 :       maybe_apply_function_contracts (current_function_decl);
   20589              : 
   20590              :     }
   20591              : 
   20592              :   /* If we're saving up tree structure, tie off the function now.  */
   20593    159124616 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   20594              : 
   20595    159124616 :   finish_fname_decls ();
   20596              : 
   20597              :   /* This must come after expand_function_end because cleanups might
   20598              :      have declarations (from inline functions) that need to go into
   20599              :      this function's blocks.  */
   20600              : 
   20601              :   /* If the current binding level isn't the outermost binding level
   20602              :      for this function, either there is a bug, or we have experienced
   20603              :      syntax errors and the statement tree is malformed.  */
   20604    159124616 :   if (current_binding_level->kind != sk_function_parms)
   20605              :     {
   20606              :       /* Make sure we have already experienced errors.  */
   20607           12 :       gcc_assert (errorcount);
   20608              : 
   20609              :       /* Throw away the broken statement tree and extra binding
   20610              :          levels.  */
   20611           12 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   20612              : 
   20613           27 :       while (current_binding_level->kind != sk_function_parms)
   20614              :         {
   20615           15 :           if (current_binding_level->kind == sk_class)
   20616            0 :             pop_nested_class ();
   20617              :           else
   20618           15 :             poplevel (0, 0, 0);
   20619              :         }
   20620              :     }
   20621    159124616 :   poplevel (1, 0, 1);
   20622              : 
   20623              :   /* Statements should always be full-expressions at the outermost set
   20624              :      of curly braces for a function.  */
   20625    159124616 :   gcc_assert (stmts_are_full_exprs_p ());
   20626              : 
   20627              :   /* If there are no return statements in a function with auto return type,
   20628              :      the return type is void.  But if the declared type is something like
   20629              :      auto*, this is an error.  */
   20630     65654765 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   20631    160045261 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20632              :     {
   20633       123728 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20634       123713 :           && !current_function_returns_value
   20635       247214 :           && !current_function_returns_null)
   20636              :         {
   20637              :           /* We haven't applied return type deduction because we haven't
   20638              :              seen any return statements. Do that now.  */
   20639       123486 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20640       123486 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   20641              :                              void_node, node, tf_warning_or_error,
   20642              :                              adc_return_type);
   20643              : 
   20644       123486 :           apply_deduced_return_type (fndecl, void_type_node);
   20645       123486 :           fntype = TREE_TYPE (fndecl);
   20646              :         }
   20647          242 :       else if (!current_function_returns_value
   20648            6 :                && !current_function_returns_null)
   20649              :         {
   20650            6 :           auto_diagnostic_group d;
   20651           12 :           error ("no return statements in function returning %qT",
   20652            6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   20653            6 :           inform (input_location, "only plain %<auto%> return type can be "
   20654              :                   "deduced to %<void%>");
   20655            6 :         }
   20656              :     }
   20657              : 
   20658    159124616 :   if (FNDECL_USED_AUTO (fndecl)
   20659    159124616 :       && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   20660       920403 :     if (location_t fcloc = failed_completion_location (fndecl))
   20661              :       {
   20662            6 :         auto_diagnostic_group adg;
   20663            6 :         if (warning (OPT_Wsfinae_incomplete_,
   20664              :                      "defining %qD, which previously failed to be deduced "
   20665              :                      "in a SFINAE context", fndecl)
   20666            6 :             && warn_sfinae_incomplete == 1)
   20667            6 :           inform (fcloc, "here.  Use %qs for a diagnostic at that point",
   20668              :                   "-Wsfinae-incomplete=2");
   20669            6 :       }
   20670              : 
   20671              :   /* Remember that we were in class scope.  */
   20672    159124616 :   if (current_class_name)
   20673    121781761 :     ctype = current_class_type;
   20674              : 
   20675    159124616 :   if (DECL_DELETED_FN (fndecl))
   20676              :     {
   20677           93 :       DECL_INITIAL (fndecl) = error_mark_node;
   20678           93 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   20679           93 :       goto cleanup;
   20680              :     }
   20681              : 
   20682    159124523 :   if (flag_openmp)
   20683       324658 :     if (tree attr = lookup_attribute ("omp declare variant base",
   20684       324658 :                                       DECL_ATTRIBUTES (fndecl)))
   20685          267 :       omp_declare_variant_finalize (fndecl, attr);
   20686              : 
   20687              :   /* Complain if there's just no return statement.  */
   20688    159124523 :   if ((warn_return_type
   20689        47136 :        || (cxx_dialect >= cxx14
   20690        39104 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   20691    159095181 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   20692     99865738 :       && !dependent_type_p (TREE_TYPE (fntype))
   20693     50568683 :       && !current_function_returns_value && !current_function_returns_null
   20694              :       /* Don't complain if we abort or throw.  */
   20695        31698 :       && !current_function_returns_abnormally
   20696              :       /* Don't complain if there's an infinite loop.  */
   20697          953 :       && !current_function_infinite_loop
   20698              :       /* Don't complain if we are declared noreturn.  */
   20699          885 :       && !TREE_THIS_VOLATILE (fndecl)
   20700          879 :       && !DECL_NAME (DECL_RESULT (fndecl))
   20701          879 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   20702              :       /* Structor return values (if any) are set by the compiler.  */
   20703         1270 :       && !DECL_CONSTRUCTOR_P (fndecl)
   20704          635 :       && !DECL_DESTRUCTOR_P (fndecl)
   20705    159125158 :       && targetm.warn_func_return (fndecl))
   20706              :     {
   20707          629 :       gcc_rich_location richloc (input_location);
   20708              :       /* Potentially add a "return *this;" fix-it hint for
   20709              :          assignment operators.  */
   20710          629 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   20711              :         {
   20712           39 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   20713           39 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   20714           32 :               && current_class_ref
   20715           26 :               && same_type_ignoring_top_level_qualifiers_p
   20716           26 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   20717           71 :               && global_dc->option_enabled_p (OPT_Wreturn_type))
   20718           18 :             add_return_star_this_fixit (&richloc, fndecl);
   20719              :         }
   20720          629 :       if (cxx_dialect >= cxx14
   20721          629 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   20722            2 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   20723              :                             "returning non-void");
   20724          627 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   20725              :                            "no return statement in function returning "
   20726              :                            "non-void"))
   20727          169 :         suppress_warning (fndecl, OPT_Wreturn_type);
   20728          629 :     }
   20729              : 
   20730              :   /* Lambda closure members are implicitly constexpr if possible.  */
   20731    159124523 :   if (cxx_dialect >= cxx17
   20732    275280148 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   20733      1766747 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   20734      1766747 :       = ((processing_template_decl
   20735       553501 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   20736      3532597 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   20737              : 
   20738              :   /* Invoke the pre-genericize plugin before we start munging things.  */
   20739    159124523 :   if (!processing_template_decl)
   20740     65654672 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   20741              : 
   20742              :   /* Fold away non-ODR usages of constants so that we don't need to
   20743              :      try and stream them in modules if they're internal.  */
   20744    159124523 :   if (!processing_template_decl)
   20745     65654672 :     cp_fold_function_non_odr_use (fndecl);
   20746              : 
   20747              :   /* Save constexpr function body before it gets munged by
   20748              :      the NRV transformation.   */
   20749    159124523 :   maybe_save_constexpr_fundef (fndecl);
   20750              : 
   20751              :   /* Perform delayed folding before NRV transformation.  */
   20752    159124523 :   if (!processing_template_decl
   20753    131309344 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   20754    223754828 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20755     64629865 :     cp_fold_function (fndecl);
   20756              : 
   20757              :   /* Set up the named return value optimization, if we can.  Candidate
   20758              :      variables are selected in check_return_expr.  */
   20759    159124523 :   if (tree r = current_function_return_value)
   20760              :     {
   20761     41737819 :       if (r != error_mark_node)
   20762       218959 :         finalize_nrv (fndecl, r);
   20763     41737819 :       current_function_return_value = NULL_TREE;
   20764              :     }
   20765              : 
   20766              :   /* Must mark the RESULT_DECL as being in this function.  */
   20767    159124523 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   20768              : 
   20769              :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   20770              :      to the FUNCTION_DECL node itself.  */
   20771    159124523 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   20772              : 
   20773              :   /* Store the end of the function, so that we get good line number
   20774              :      info for the epilogue.  */
   20775    159124523 :   cfun->function_end_locus = input_location;
   20776              : 
   20777              :   /* Complain about parameters that are only set, but never otherwise used.  */
   20778    159124523 :   if (warn_unused_but_set_parameter
   20779       996123 :       && !processing_template_decl
   20780       508778 :       && errorcount == unused_but_set_errorcount
   20781    159633298 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   20782              :     {
   20783       397409 :       tree decl;
   20784              : 
   20785       397409 :       for (decl = DECL_ARGUMENTS (fndecl);
   20786      1059149 :            decl;
   20787       661740 :            decl = DECL_CHAIN (decl))
   20788       661740 :         if (TREE_USED (decl)
   20789       549233 :             && TREE_CODE (decl) == PARM_DECL
   20790       549233 :             && !DECL_READ_P (decl)
   20791          225 :             && DECL_NAME (decl)
   20792          225 :             && !DECL_ARTIFICIAL (decl)
   20793          225 :             && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
   20794          225 :             && !DECL_IN_SYSTEM_HEADER (decl)
   20795          225 :             && TREE_TYPE (decl) != error_mark_node
   20796          225 :             && !TYPE_REF_P (TREE_TYPE (decl))
   20797       661965 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   20798            0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   20799          225 :           warning_at (DECL_SOURCE_LOCATION (decl),
   20800          225 :                       OPT_Wunused_but_set_parameter_,
   20801              :                       "parameter %qD set but not used", decl);
   20802       397409 :       unused_but_set_errorcount = errorcount;
   20803              :     }
   20804              : 
   20805              :   /* Complain about locally defined typedefs that are not used in this
   20806              :      function.  */
   20807    159124523 :   maybe_warn_unused_local_typedefs ();
   20808              : 
   20809              :   /* Possibly warn about unused parameters.  */
   20810    159124523 :   if (warn_unused_parameter
   20811       726737 :       && !processing_template_decl
   20812    159475901 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   20813       269862 :     do_warn_unused_parameter (fndecl);
   20814              : 
   20815              :   /* Genericize before inlining.  */
   20816    159124523 :   if (!processing_template_decl
   20817    131309344 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   20818    223750455 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   20819     64625492 :     cp_genericize (fndecl);
   20820              : 
   20821              :   /* If this function can't throw any exceptions, remember that.  */
   20822    159124523 :   if (!processing_template_decl
   20823     65654672 :       && !cp_function_chain->can_throw
   20824     50158409 :       && !flag_non_call_exceptions
   20825     50149660 :       && !decl_replaceable_p (fndecl,
   20826     50149660 :                               opt_for_fn (fndecl, flag_semantic_interposition))
   20827    209036510 :       && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
   20828     49909272 :     TREE_NOTHROW (fndecl) = 1;
   20829              : 
   20830    159124616 :  cleanup:
   20831              : 
   20832              :   /* We're leaving the context of this function, so zap cfun.  It's still in
   20833              :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   20834    159124616 :   set_cfun (NULL);
   20835    159124616 :   current_function_decl = NULL;
   20836              : 
   20837              :   /* If this is an in-class inline definition, we may have to pop the
   20838              :      bindings for the template parameters that we added in
   20839              :      maybe_begin_member_template_processing when start_function was
   20840              :      called.  */
   20841    159124616 :   if (inline_p)
   20842     81701113 :     maybe_end_member_template_processing ();
   20843              : 
   20844              :   /* Leave the scope of the class.  */
   20845    159124616 :   if (ctype)
   20846    121781761 :     pop_nested_class ();
   20847              : 
   20848    159124616 :   --function_depth;
   20849              : 
   20850              :   /* Clean up.  */
   20851    159124616 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   20852              : 
   20853              :   /* Build outlined functions for coroutines and contracts.  */
   20854              : 
   20855    159124616 :   if (coroutine)
   20856              :     {
   20857              :       /* Emit the resumer and destroyer functions now, providing that we have
   20858              :          not encountered some fatal error.  */
   20859         1700 :       if (coroutine->cp_valid_coroutine ())
   20860              :         {
   20861         1616 :           coroutine->finish_transforms ();
   20862         1616 :           resumer = coroutine->get_resumer ();
   20863         1616 :           destroyer = coroutine->get_destroyer ();
   20864         1616 :           expand_or_defer_fn (resumer);
   20865         1616 :           expand_or_defer_fn (destroyer);
   20866              :         }
   20867         1700 :       delete coroutine;
   20868              :     }
   20869              : 
   20870              :   /* If we have used outlined contracts checking functions, build and emit
   20871              :      them here.  */
   20872    159124616 :   finish_function_outlined_contracts (fndecl);
   20873              : 
   20874    159124616 :   return fndecl;
   20875              : }
   20876              : 
   20877              : /* Create the FUNCTION_DECL for a function definition.
   20878              :    DECLSPECS and DECLARATOR are the parts of the declaration;
   20879              :    they describe the return type and the name of the function,
   20880              :    but twisted together in a fashion that parallels the syntax of C.
   20881              : 
   20882              :    This function creates a binding context for the function body
   20883              :    as well as setting up the FUNCTION_DECL in current_function_decl.
   20884              : 
   20885              :    Returns a FUNCTION_DECL on success.
   20886              : 
   20887              :    If the DECLARATOR is not suitable for a function (it defines a datum
   20888              :    instead), we return 0, which tells yyparse to report a parse error.
   20889              : 
   20890              :    May return void_type_node indicating that this method is actually
   20891              :    a friend.  See grokfield for more details.
   20892              : 
   20893              :    Came here with a `.pushlevel' .
   20894              : 
   20895              :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   20896              :    CHANGES TO CODE IN `grokfield'.  */
   20897              : 
   20898              : tree
   20899     81902695 : grokmethod (cp_decl_specifier_seq *declspecs,
   20900              :             const cp_declarator *declarator, tree attrlist)
   20901              : {
   20902     81902695 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   20903     81902695 :                                 &attrlist);
   20904              : 
   20905     81902695 :   if (fndecl == error_mark_node)
   20906              :     return error_mark_node;
   20907              : 
   20908     81902590 :   if (attrlist)
   20909            0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   20910              : 
   20911              :   /* Pass friends other than inline friend functions back.  */
   20912     81902590 :   if (fndecl == void_type_node)
   20913              :     return fndecl;
   20914              : 
   20915     81902590 :   if (DECL_IN_AGGR_P (fndecl))
   20916              :     {
   20917            0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   20918            0 :         error ("%qD is already defined in class %qT", fndecl,
   20919            0 :                DECL_CONTEXT (fndecl));
   20920            0 :       return error_mark_node;
   20921              :     }
   20922              : 
   20923     81902590 :   check_template_shadow (fndecl);
   20924              : 
   20925              :   /* p1779 ABI-Isolation makes inline not a default for in-class
   20926              :      definitions attached to a named module.  If the user explicitly
   20927              :      made it inline, grokdeclarator will already have done the right
   20928              :      things.  */
   20929     81902590 :   if ((!named_module_attach_p ()
   20930         1074 :        || flag_module_implicit_inline
   20931              :       /* Lambda's operator function remains inline.  */
   20932         2112 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   20933              :       /* If the user explicitly asked for this to be inline, we don't
   20934              :          need to do more, but more importantly we want to warn if we
   20935              :          can't inline it.  */
   20936     81902127 :       && !DECL_DECLARED_INLINE_P (fndecl))
   20937              :     {
   20938     46444438 :       if (TREE_PUBLIC (fndecl))
   20939     44446452 :         DECL_COMDAT (fndecl) = 1;
   20940     46444438 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   20941              :       /* It's ok if we can't inline this.  */
   20942     46444438 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   20943              :     }
   20944              : 
   20945              :   /* We process method specializations in finish_struct_1.  */
   20946     81902590 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   20947              :     {
   20948              :       /* Avoid calling decl_spec_seq... until we have to.  */
   20949     65681988 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   20950     65681988 :       fndecl = push_template_decl (fndecl, friendp);
   20951     65681988 :       if (fndecl == error_mark_node)
   20952              :         return fndecl;
   20953              :     }
   20954              : 
   20955     81902582 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   20956              :     {
   20957            0 :       fndecl = copy_node (fndecl);
   20958            0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   20959              :     }
   20960              : 
   20961     81902582 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   20962              : 
   20963     81902582 :   DECL_IN_AGGR_P (fndecl) = 1;
   20964     81902582 :   return fndecl;
   20965              : }
   20966              : 
   20967              : 
   20968              : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   20969              :    we can lay it out later, when and if its type becomes complete.
   20970              : 
   20971              :    Also handle constexpr variables where the initializer involves
   20972              :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   20973              : 
   20974              : void
   20975    101500553 : maybe_register_incomplete_var (tree var)
   20976              : {
   20977    101500553 :   gcc_assert (VAR_P (var));
   20978              : 
   20979              :   /* Keep track of variables with incomplete types.  */
   20980     44487807 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   20981    145986545 :       && DECL_EXTERNAL (var))
   20982              :     {
   20983      6430376 :       tree inner_type = TREE_TYPE (var);
   20984              : 
   20985      6581127 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   20986       150751 :         inner_type = TREE_TYPE (inner_type);
   20987      6430376 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   20988              : 
   20989      6578517 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   20990              :           /* RTTI TD entries are created while defining the type_info.  */
   20991      6430376 :           || (TYPE_LANG_SPECIFIC (inner_type)
   20992      2284936 :               && TYPE_BEING_DEFINED (inner_type)))
   20993              :         {
   20994       148141 :           incomplete_var iv = {var, inner_type};
   20995       148141 :           vec_safe_push (incomplete_vars, iv);
   20996              :         }
   20997     12266150 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   20998      3428500 :                && DECL_CLASS_SCOPE_P (var)
   20999      1064424 :                && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
   21000      1064424 :                && decl_constant_var_p (var)
   21001      6965008 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   21002              :         {
   21003              :           /* When the outermost open class is complete we can resolve any
   21004              :              pointers-to-members.  */
   21005           29 :           tree context = outermost_open_class ();
   21006           29 :           incomplete_var iv = {var, context};
   21007           29 :           vec_safe_push (incomplete_vars, iv);
   21008              :         }
   21009              :     }
   21010    101500553 : }
   21011              : 
   21012              : /* Called when a class type (given by TYPE) is defined.  If there are
   21013              :    any existing VAR_DECLs whose type has been completed by this
   21014              :    declaration, update them now.  */
   21015              : 
   21016              : void
   21017     69120734 : complete_vars (tree type)
   21018              : {
   21019     69120734 :   unsigned ix;
   21020     69120734 :   incomplete_var *iv;
   21021              : 
   21022     69781700 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   21023              :     {
   21024       660966 :       if (same_type_p (type, iv->incomplete_type))
   21025              :         {
   21026       146941 :           tree var = iv->decl;
   21027       146941 :           tree type = TREE_TYPE (var);
   21028              : 
   21029       146941 :           if (type != error_mark_node
   21030       146941 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   21031       146938 :                   == iv->incomplete_type))
   21032              :             {
   21033              :               /* Complete the type of the variable.  */
   21034       146909 :               complete_type (type);
   21035       146909 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   21036       146909 :               if (COMPLETE_TYPE_P (type))
   21037       146894 :                 layout_var_decl (var);
   21038              :             }
   21039              : 
   21040              :           /* Remove this entry from the list.  */
   21041       146941 :           incomplete_vars->unordered_remove (ix);
   21042              :         }
   21043              :       else
   21044       514025 :         ix++;
   21045              :     }
   21046     69120734 : }
   21047              : 
   21048              : /* If DECL is of a type which needs a cleanup, build and return an
   21049              :    expression to perform that cleanup here.  Return NULL_TREE if no
   21050              :    cleanup need be done.  DECL can also be a _REF when called from
   21051              :    split_nonconstant_init_1.  */
   21052              : 
   21053              : tree
   21054     86140150 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   21055              : {
   21056     86140150 :   tree type;
   21057     86140150 :   tree attr;
   21058     86140150 :   tree cleanup;
   21059              : 
   21060              :   /* Assume no cleanup is required.  */
   21061     86140150 :   cleanup = NULL_TREE;
   21062              : 
   21063     86140150 :   if (!decl || error_operand_p (decl))
   21064              :     return cleanup;
   21065              : 
   21066              :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   21067              :      before the destructor since the destructor is what actually
   21068              :      terminates the lifetime of the object.  */
   21069     86140150 :   if (DECL_P (decl))
   21070     85861493 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   21071              :   else
   21072              :     attr = NULL_TREE;
   21073     85861493 :   if (attr)
   21074              :     {
   21075          159 :       tree id;
   21076          159 :       tree fn;
   21077          159 :       tree arg;
   21078              : 
   21079              :       /* Get the name specified by the user for the cleanup function.  */
   21080          159 :       id = TREE_VALUE (TREE_VALUE (attr));
   21081              :       /* Look up the name to find the cleanup function to call.  It is
   21082              :          important to use lookup_name here because that is what is
   21083              :          used in c-common.cc:handle_cleanup_attribute when performing
   21084              :          initial checks on the attribute.  Note that those checks
   21085              :          include ensuring that the function found is not an overloaded
   21086              :          function, or an object with an overloaded call operator,
   21087              :          etc.; we can rely on the fact that the function found is an
   21088              :          ordinary FUNCTION_DECL.  */
   21089          159 :       fn = lookup_name (id);
   21090          159 :       arg = build_address (decl);
   21091          159 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   21092            0 :         return error_mark_node;
   21093          159 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   21094          159 :       if (cleanup == error_mark_node)
   21095              :         return error_mark_node;
   21096              :     }
   21097              :   /* Handle ordinary C++ destructors.  */
   21098     86140138 :   type = TREE_TYPE (decl);
   21099     86140138 :   if (type_build_dtor_call (type))
   21100              :     {
   21101      6645888 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   21102      6645888 :       tree addr;
   21103      6645888 :       tree call;
   21104              : 
   21105      6645888 :       if (TREE_CODE (type) == ARRAY_TYPE)
   21106              :         addr = decl;
   21107              :       else
   21108      6641198 :         addr = build_address (decl);
   21109              : 
   21110      6645888 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   21111              :                            sfk_complete_destructor, flags, 0, complain);
   21112      6645888 :       if (call == error_mark_node)
   21113              :         cleanup = error_mark_node;
   21114      6645825 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   21115              :         /* Discard the call.  */;
   21116      4051586 :       else if (decl_maybe_constant_destruction (decl, type)
   21117      4051784 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   21118          198 :         cxx_constant_dtor (call, decl);
   21119      4051388 :       else if (cleanup)
   21120            3 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   21121              :       else
   21122              :         cleanup = call;
   21123              :     }
   21124              : 
   21125              :   /* build_delete sets the location of the destructor call to the
   21126              :      current location, even though the destructor is going to be
   21127              :      called later, at the end of the current scope.  This can lead to
   21128              :      a "jumpy" behavior for users of debuggers when they step around
   21129              :      the end of the block.  So let's unset the location of the
   21130              :      destructor call instead.  */
   21131     86140138 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   21132     86140138 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   21133            0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   21134              : 
   21135            0 :   if (cleanup
   21136      4051595 :       && DECL_P (decl)
   21137      4051139 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   21138              :       /* Treat objects with destructors as used; the destructor may do
   21139              :          something substantive.  */
   21140      4051133 :       && !mark_used (decl, complain) && !(complain & tf_error))
   21141            0 :     return error_mark_node;
   21142              : 
   21143      4051595 :   if (cleanup && cfun && !processing_template_decl
   21144     89717676 :       && !expr_noexcept_p (cleanup, tf_none))
   21145         5186 :     cp_function_chain->throwing_cleanup = true;
   21146              : 
   21147              :   return cleanup;
   21148              : }
   21149              : 
   21150              : 
   21151              : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   21152              :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   21153              :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   21154              : 
   21155              : tree
   21156      5761123 : static_fn_type (tree memfntype)
   21157              : {
   21158      5761123 :   tree fntype;
   21159      5761123 :   tree args;
   21160              : 
   21161      5761123 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   21162        20100 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   21163      5761123 :   if (INDIRECT_TYPE_P (memfntype)
   21164      5053646 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   21165      5595425 :     memfntype = TREE_TYPE (memfntype);
   21166      5761123 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   21167              :     return memfntype;
   21168       556370 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   21169       556370 :   args = TYPE_ARG_TYPES (memfntype);
   21170       556370 :   fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   21171       556370 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   21172       556370 :   fntype = (cp_build_type_attribute_variant
   21173       556370 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   21174       556370 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   21175       556370 :   return fntype;
   21176              : }
   21177              : 
   21178              : /* DECL was originally constructed as a non-static member function,
   21179              :    but turned out to be static.  Update it accordingly.  */
   21180              : 
   21181              : void
   21182       172846 : revert_static_member_fn (tree decl)
   21183              : {
   21184       172846 :   tree stype = static_fn_type (decl);
   21185       172846 :   cp_cv_quals quals = type_memfn_quals (stype);
   21186       172846 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   21187              : 
   21188       172846 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   21189            9 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   21190              : 
   21191       172846 :   TREE_TYPE (decl) = stype;
   21192              : 
   21193       172846 :   if (DECL_ARGUMENTS (decl))
   21194       172846 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   21195       172846 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   21196       172846 : }
   21197              : 
   21198              : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   21199              :    one of the language-independent trees.  */
   21200              : 
   21201              : enum cp_tree_node_structure_enum
   21202  36791867830 : cp_tree_node_structure (union lang_tree_node * t)
   21203              : {
   21204  36791867830 :   switch (TREE_CODE (&t->generic))
   21205              :     {
   21206              :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   21207    151643922 :     case BASELINK:              return TS_CP_BASELINK;
   21208     76573985 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   21209     11000329 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   21210      5807444 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   21211   1993313763 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   21212      2974995 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   21213       266953 :     case BINDING_VECTOR:        return TS_CP_BINDING_VECTOR;
   21214    686927120 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   21215          698 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   21216     15175867 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   21217    647311982 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   21218   1504846296 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   21219    657876310 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   21220     14822240 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   21221            6 :     case TU_LOCAL_ENTITY:       return TS_CP_TU_LOCAL_ENTITY;
   21222      3480399 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   21223  31019845521 :     default:                    return TS_CP_GENERIC;
   21224              :     }
   21225              : }
   21226              : 
   21227              : bool
   21228         8920 : cp_missing_noreturn_ok_p (tree decl)
   21229              : {
   21230              :   /* A missing noreturn is ok for the `main' function.  */
   21231         8920 :   return DECL_MAIN_P (decl);
   21232              : }
   21233              : 
   21234              : /* Return the decl used to identify the COMDAT group into which DECL should
   21235              :    be placed.  */
   21236              : 
   21237              : tree
   21238    121465788 : cxx_comdat_group (tree decl)
   21239              : {
   21240              :   /* Virtual tables, construction virtual tables, and virtual table
   21241              :      tables all go in a single COMDAT group, named after the primary
   21242              :      virtual table.  */
   21243    121465788 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   21244       513948 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   21245              :   /* For all other DECLs, the COMDAT group is the mangled name of the
   21246              :      declaration itself.  */
   21247              :   else
   21248              :     {
   21249    120951840 :       while (DECL_THUNK_P (decl))
   21250              :         {
   21251              :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   21252              :              into the same section as the target function.  In that case
   21253              :              we must return target's name.  */
   21254            0 :           tree target = THUNK_TARGET (decl);
   21255            0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   21256            0 :               && DECL_SECTION_NAME (target) != NULL
   21257            0 :               && DECL_ONE_ONLY (target))
   21258              :             decl = target;
   21259              :           else
   21260              :             break;
   21261              :         }
   21262              :       /* If a ctor/dtor has already set the comdat group by
   21263              :          maybe_clone_body, don't override it.  */
   21264    120951840 :       if (SUPPORTS_ONE_ONLY
   21265    120951840 :           && TREE_CODE (decl) == FUNCTION_DECL
   21266    120951840 :           && DECL_CLONED_FUNCTION_P (decl))
   21267     17728798 :         if (tree comdat = DECL_COMDAT_GROUP (decl))
   21268              :           return comdat;
   21269              :     }
   21270              : 
   21271              :   return decl;
   21272              : }
   21273              : 
   21274              : /* Returns the return type for FN as written by the user, which may include
   21275              :    a placeholder for a deduced return type.  */
   21276              : 
   21277              : tree
   21278    486037508 : fndecl_declared_return_type (tree fn)
   21279              : {
   21280    486037508 :   fn = STRIP_TEMPLATE (fn);
   21281    486037508 :   if (FNDECL_USED_AUTO (fn))
   21282       117832 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   21283              : 
   21284    485919676 :   return TREE_TYPE (TREE_TYPE (fn));
   21285              : }
   21286              : 
   21287              : /* Returns true iff DECL is a variable or function declared with an auto type
   21288              :    that has not yet been deduced to a real type.  */
   21289              : 
   21290              : bool
   21291    945148857 : undeduced_auto_decl (tree decl)
   21292              : {
   21293    945148857 :   if (cxx_dialect < cxx11)
   21294              :     return false;
   21295    942793303 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   21296    423032980 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   21297     91632247 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   21298   1274410722 :           && type_uses_auto (TREE_TYPE (decl)));
   21299              : }
   21300              : 
   21301              : /* Complain if DECL has an undeduced return type.  */
   21302              : 
   21303              : bool
   21304    308263519 : require_deduced_type (tree decl, tsubst_flags_t complain)
   21305              : {
   21306    308263519 :   if (undeduced_auto_decl (decl))
   21307              :     {
   21308        14368 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21309        14368 :           && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
   21310              :                                 BUILT_IN_FRONTEND))
   21311              :         {
   21312              :           /* Set the return type of __builtin_source_location.  */
   21313         9883 :           tree type = get_source_location_impl_type ();
   21314         9883 :           if (type == error_mark_node)
   21315              :             {
   21316           33 :               inform (input_location, "using %qs", "__builtin_source_location");
   21317           33 :               return false;
   21318              :             }
   21319         9850 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   21320         9850 :           type = build_pointer_type (type);
   21321         9850 :           apply_deduced_return_type (decl, type);
   21322         9850 :           return true;
   21323              :         }
   21324              : 
   21325         4485 :       if (TREE_CODE (decl) == FUNCTION_DECL
   21326         4485 :           && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
   21327              :                                 BUILT_IN_FRONTEND))
   21328              :         {
   21329              :           /* Set the return type of __builtin_current_exception.  */
   21330         1747 :           tree name = get_identifier ("exception_ptr");
   21331         1747 :           tree eptr = lookup_qualified_name (std_node, name);
   21332         1747 :           tree fld;
   21333         1747 :           if (TREE_CODE (eptr) != TYPE_DECL
   21334         1747 :               || !CLASS_TYPE_P (TREE_TYPE (eptr))
   21335         1747 :               || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
   21336         1747 :               || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
   21337         1747 :               || DECL_ARTIFICIAL (fld)
   21338         1747 :               || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
   21339         1747 :               || next_aggregate_field (DECL_CHAIN (fld))
   21340         3494 :               || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
   21341         1747 :                                       TYPE_SIZE (TREE_TYPE (fld))))
   21342              :             {
   21343            0 :               error ("%qs used without %qs declaration",
   21344              :                      "__builtin_current_exception", "std::exception_ptr");
   21345            0 :               return false;
   21346              :             }
   21347              : 
   21348         1747 :           apply_deduced_return_type (decl, TREE_TYPE (eptr));
   21349         1747 :           return true;
   21350              :         }
   21351              : 
   21352         2738 :       if (warning_suppressed_p (decl) && seen_error ())
   21353              :         /* We probably already complained about deduction failure.  */;
   21354         2565 :       else if (complain & tf_error)
   21355           74 :         error ("use of %qD before deduction of %<auto%>", decl);
   21356         2738 :       note_failed_type_completion (decl, complain);
   21357         2738 :       return false;
   21358              :     }
   21359              :   return true;
   21360              : }
   21361              : 
   21362              : /* Create a representation of the explicit-specifier with
   21363              :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   21364              : 
   21365              : tree
   21366      8031125 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   21367              : {
   21368      8031125 :   if (check_for_bare_parameter_packs (expr))
   21369            3 :     return error_mark_node;
   21370              : 
   21371      8031122 :   if (instantiation_dependent_expression_p (expr))
   21372              :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   21373              :     return expr;
   21374              : 
   21375      6482741 :   expr = build_converted_constant_bool_expr (expr, complain);
   21376      6482741 :   expr = instantiate_non_dependent_expr (expr, complain);
   21377      6482741 :   expr = cxx_constant_value (expr, complain);
   21378      6482741 :   return expr;
   21379              : }
   21380              : 
   21381              : #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.