LCOV - code coverage report
Current view: top level - gcc/cp - decl.cc (source / functions) Hit Total Coverage
Test: gcc.info Lines: 7765 8259 94.0 %
Date: 2023-07-19 08:18:47 Functions: 214 220 97.3 %

          Line data    Source code
       1             : /* Process declarations and variables for -*- C++ -*- compiler.
       2             :    Copyright (C) 1988-2023 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             : #define INCLUDE_MEMORY
      31             : #include "system.h"
      32             : #include "coretypes.h"
      33             : #include "target.h"
      34             : #include "c-family/c-target.h"
      35             : #include "cp-tree.h"
      36             : #include "timevar.h"
      37             : #include "stringpool.h"
      38             : #include "cgraph.h"
      39             : #include "stor-layout.h"
      40             : #include "varasm.h"
      41             : #include "attribs.h"
      42             : #include "flags.h"
      43             : #include "tree-iterator.h"
      44             : #include "decl.h"
      45             : #include "intl.h"
      46             : #include "toplev.h"
      47             : #include "c-family/c-objc.h"
      48             : #include "c-family/c-pragma.h"
      49             : #include "c-family/c-ubsan.h"
      50             : #include "cp/cp-name-hint.h"
      51             : #include "debug.h"
      52             : #include "plugin.h"
      53             : #include "builtins.h"
      54             : #include "gimplify.h"
      55             : #include "asan.h"
      56             : #include "gcc-rich-location.h"
      57             : #include "langhooks.h"
      58             : #include "context.h"  /* For 'g'.  */
      59             : #include "omp-general.h"
      60             : #include "omp-offload.h"  /* For offload_vars.  */
      61             : #include "opts.h"
      62             : #include "langhooks-def.h"  /* For lhd_simulate_record_decl  */
      63             : 
      64             : /* Possible cases of bad specifiers type used by bad_specifiers. */
      65             : enum bad_spec_place {
      66             :   BSP_VAR,    /* variable */
      67             :   BSP_PARM,   /* parameter */
      68             :   BSP_TYPE,   /* type */
      69             :   BSP_FIELD   /* field */
      70             : };
      71             : 
      72             : static const char *redeclaration_error_message (tree, tree);
      73             : 
      74             : static bool decl_jump_unsafe (tree);
      75             : static void require_complete_types_for_parms (tree);
      76             : static tree grok_reference_init (tree, tree, tree, int);
      77             : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
      78             :                          int, int, int, bool, int, tree, location_t);
      79             : static void check_static_variable_definition (tree, tree);
      80             : static void record_unknown_type (tree, const char *);
      81             : static int member_function_or_else (tree, tree, enum overload_flags);
      82             : static tree local_variable_p_walkfn (tree *, int *, void *);
      83             : static const char *tag_name (enum tag_types);
      84             : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
      85             : static void maybe_deduce_size_from_array_init (tree, tree);
      86             : static void layout_var_decl (tree);
      87             : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
      88             : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
      89             : static void copy_type_enum (tree , tree);
      90             : static void check_function_type (tree, tree);
      91             : static void begin_destructor_body (void);
      92             : static void record_key_method_defined (tree);
      93             : static tree create_array_type_for_decl (tree, tree, tree, location_t);
      94             : static tree get_atexit_node (void);
      95             : static tree get_dso_handle_node (void);
      96             : static tree start_cleanup_fn (void);
      97             : static void end_cleanup_fn (void);
      98             : static tree cp_make_fname_decl (location_t, tree, int);
      99             : static void initialize_predefined_identifiers (void);
     100             : static tree check_special_function_return_type
     101             :        (special_function_kind, tree, tree, int, const location_t*);
     102             : static tree push_cp_library_fn (enum tree_code, tree, int);
     103             : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
     104             : static void store_parm_decls (tree);
     105             : static void initialize_local_var (tree, tree);
     106             : static void expand_static_init (tree, tree);
     107             : static location_t smallest_type_location (const cp_decl_specifier_seq*);
     108             : 
     109             : /* The following symbols are subsumed in the cp_global_trees array, and
     110             :    listed here individually for documentation purposes.
     111             : 
     112             :    C++ extensions
     113             :         tree wchar_decl_node;
     114             : 
     115             :         tree vtable_entry_type;
     116             :         tree delta_type_node;
     117             :         tree __t_desc_type_node;
     118             : 
     119             :         tree class_type_node;
     120             :         tree unknown_type_node;
     121             : 
     122             :    Array type `vtable_entry_type[]'
     123             : 
     124             :         tree vtbl_type_node;
     125             :         tree vtbl_ptr_type_node;
     126             : 
     127             :    Namespaces,
     128             : 
     129             :         tree std_node;
     130             :         tree abi_node;
     131             : 
     132             :    A FUNCTION_DECL which can call `abort'.  Not necessarily the
     133             :    one that the user will declare, but sufficient to be called
     134             :    by routines that want to abort the program.
     135             : 
     136             :         tree abort_fndecl;
     137             : 
     138             :    Used by RTTI
     139             :         tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
     140             :         tree tinfo_var_id;  */
     141             : 
     142             : tree cp_global_trees[CPTI_MAX];
     143             : 
     144             : /* A list of objects which have constructors or destructors
     145             :    which reside in namespace scope.  The decl is stored in
     146             :    the TREE_VALUE slot and the initializer is stored
     147             :    in the TREE_PURPOSE slot.  */
     148             : tree static_aggregates;
     149             : 
     150             : /* Like static_aggregates, but for thread_local variables.  */
     151             : tree tls_aggregates;
     152             : 
     153             : /* A hash-map mapping from variable decls to the dynamic initializer for
     154             :    the decl.  This is currently only used by OpenMP.  */
     155             : decl_tree_map *dynamic_initializers;
     156             : 
     157             : /* -- end of C++ */
     158             : 
     159             : /* A node for the integer constant 2.  */
     160             : 
     161             : tree integer_two_node;
     162             : 
     163             : /* vector of static decls.  */
     164             : vec<tree, va_gc> *static_decls;
     165             : 
     166             : /* vector of keyed classes.  */
     167             : vec<tree, va_gc> *keyed_classes;
     168             : 
     169             : /* Used only for jumps to as-yet undefined labels, since jumps to
     170             :    defined labels can have their validity checked immediately.  */
     171             : 
     172             : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
     173             :   struct named_label_use_entry *next;
     174             :   /* The binding level to which this entry is *currently* attached.
     175             :      This is initially the binding level in which the goto appeared,
     176             :      but is modified as scopes are closed.  */
     177             :   cp_binding_level *binding_level;
     178             :   /* The head of the names list that was current when the goto appeared,
     179             :      or the inner scope popped.  These are the decls that will *not* be
     180             :      skipped when jumping to the label.  */
     181             :   tree names_in_scope;
     182             :   /* The location of the goto, for error reporting.  */
     183             :   location_t o_goto_locus;
     184             :   /* True if an OpenMP structured block scope has been closed since
     185             :      the goto appeared.  This means that the branch from the label will
     186             :      illegally exit an OpenMP scope.  */
     187             :   bool in_omp_scope;
     188             : };
     189             : 
     190             : /* A list of all LABEL_DECLs in the function that have names.  Here so
     191             :    we can clear out their names' definitions at the end of the
     192             :    function, and so we can check the validity of jumps to these labels.  */
     193             : 
     194             : struct GTY((for_user)) named_label_entry {
     195             : 
     196             :   tree name;  /* Name of decl. */
     197             : 
     198             :   tree label_decl; /* LABEL_DECL, unless deleted local label. */
     199             : 
     200             :   named_label_entry *outer; /* Outer shadowed chain.  */
     201             : 
     202             :   /* The binding level to which the label is *currently* attached.
     203             :      This is initially set to the binding level in which the label
     204             :      is defined, but is modified as scopes are closed.  */
     205             :   cp_binding_level *binding_level;
     206             : 
     207             :   /* The head of the names list that was current when the label was
     208             :      defined, or the inner scope popped.  These are the decls that will
     209             :      be skipped when jumping to the label.  */
     210             :   tree names_in_scope;
     211             : 
     212             :   /* A vector of all decls from all binding levels that would be
     213             :      crossed by a backward branch to the label.  */
     214             :   vec<tree, va_gc> *bad_decls;
     215             : 
     216             :   /* A list of uses of the label, before the label is defined.  */
     217             :   named_label_use_entry *uses;
     218             : 
     219             :   /* The following bits are set after the label is defined, and are
     220             :      updated as scopes are popped.  They indicate that a jump to the
     221             :      label will illegally enter a scope of the given flavor.  */
     222             :   bool in_try_scope;
     223             :   bool in_catch_scope;
     224             :   bool in_omp_scope;
     225             :   bool in_transaction_scope;
     226             :   bool in_constexpr_if;
     227             :   bool in_consteval_if;
     228             :   bool in_stmt_expr;
     229             : };
     230             : 
     231             : #define named_labels cp_function_chain->x_named_labels
     232             : 
     233             : /* The number of function bodies which we are currently processing.
     234             :    (Zero if we are at namespace scope, one inside the body of a
     235             :    function, two inside the body of a function in a local class, etc.)  */
     236             : int function_depth;
     237             : 
     238             : /* Whether the exception-specifier is part of a function type (i.e. C++17).  */
     239             : bool flag_noexcept_type;
     240             : 
     241             : /* States indicating how grokdeclarator() should handle declspecs marked
     242             :    with __attribute__((deprecated)).  An object declared as
     243             :    __attribute__((deprecated)) suppresses warnings of uses of other
     244             :    deprecated items.  */
     245             : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
     246             : 
     247             : 
     248             : /* A list of VAR_DECLs whose type was incomplete at the time the
     249             :    variable was declared.  */
     250             : 
     251             : struct GTY(()) incomplete_var {
     252             :   tree decl;
     253             :   tree incomplete_type;
     254             : };
     255             : 
     256             : 
     257             : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
     258             : 
     259             : /* Returns the kind of template specialization we are currently
     260             :    processing, given that it's declaration contained N_CLASS_SCOPES
     261             :    explicit scope qualifications.  */
     262             : 
     263             : tmpl_spec_kind
     264   148297440 : current_tmpl_spec_kind (int n_class_scopes)
     265             : {
     266   148297440 :   int n_template_parm_scopes = 0;
     267   148297440 :   int seen_specialization_p = 0;
     268   148297440 :   int innermost_specialization_p = 0;
     269   148297440 :   cp_binding_level *b;
     270             : 
     271             :   /* Scan through the template parameter scopes.  */
     272   148297440 :   for (b = current_binding_level;
     273   186890383 :        b->kind == sk_template_parms;
     274    38592943 :        b = b->level_chain)
     275             :     {
     276             :       /* If we see a specialization scope inside a parameter scope,
     277             :          then something is wrong.  That corresponds to a declaration
     278             :          like:
     279             : 
     280             :             template <class T> template <> ...
     281             : 
     282             :          which is always invalid since [temp.expl.spec] forbids the
     283             :          specialization of a class member template if the enclosing
     284             :          class templates are not explicitly specialized as well.  */
     285    38592943 :       if (b->explicit_spec_p)
     286             :         {
     287      556590 :           if (n_template_parm_scopes == 0)
     288             :             innermost_specialization_p = 1;
     289             :           else
     290         858 :             seen_specialization_p = 1;
     291             :         }
     292    38036353 :       else if (seen_specialization_p == 1)
     293             :         return tsk_invalid_member_spec;
     294             : 
     295    38592943 :       ++n_template_parm_scopes;
     296             :     }
     297             : 
     298             :   /* Handle explicit instantiations.  */
     299   148297440 :   if (processing_explicit_instantiation)
     300             :     {
     301     1430135 :       if (n_template_parm_scopes != 0)
     302             :         /* We've seen a template parameter list during an explicit
     303             :            instantiation.  For example:
     304             : 
     305             :              template <class T> template void f(int);
     306             : 
     307             :            This is erroneous.  */
     308             :         return tsk_invalid_expl_inst;
     309             :       else
     310     1430135 :         return tsk_expl_inst;
     311             :     }
     312             : 
     313   146867305 :   if (n_template_parm_scopes < n_class_scopes)
     314             :     /* We've not seen enough template headers to match all the
     315             :        specialized classes present.  For example:
     316             : 
     317             :          template <class T> void R<T>::S<T>::f(int);
     318             : 
     319             :        This is invalid; there needs to be one set of template
     320             :        parameters for each class.  */
     321             :     return tsk_insufficient_parms;
     322   146867305 :   else if (n_template_parm_scopes == n_class_scopes)
     323             :     /* We're processing a non-template declaration (even though it may
     324             :        be a member of a template class.)  For example:
     325             : 
     326             :          template <class T> void S<T>::f(int);
     327             : 
     328             :        The `class T' matches the `S<T>', leaving no template headers
     329             :        corresponding to the `f'.  */
     330             :     return tsk_none;
     331    32716806 :   else if (n_template_parm_scopes > n_class_scopes + 1)
     332             :     /* We've got too many template headers.  For example:
     333             : 
     334             :          template <> template <class T> void f (T);
     335             : 
     336             :        There need to be more enclosing classes.  */
     337             :     return tsk_excessive_parms;
     338             :   else
     339             :     /* This must be a template.  It's of the form:
     340             : 
     341             :          template <class T> template <class U> void S<T>::f(U);
     342             : 
     343             :        This is a specialization if the innermost level was a
     344             :        specialization; otherwise it's just a definition of the
     345             :        template.  */
     346    65233223 :     return innermost_specialization_p ? tsk_expl_spec : tsk_template;
     347             : }
     348             : 
     349             : /* Exit the current scope.  */
     350             : 
     351             : void
     352    59061497 : finish_scope (void)
     353             : {
     354    59061497 :   poplevel (0, 0, 0);
     355    59061497 : }
     356             : 
     357             : /* When a label goes out of scope, check to see if that label was used
     358             :    in a valid manner, and issue any appropriate warnings or errors.  */
     359             : 
     360             : static void
     361       15379 : check_label_used (tree label)
     362             : {
     363       15379 :   if (!processing_template_decl)
     364             :     {
     365       15080 :       if (DECL_INITIAL (label) == NULL_TREE)
     366             :         {
     367           8 :           location_t location;
     368             : 
     369           8 :           error ("label %q+D used but not defined", label);
     370           8 :           location = input_location;
     371             :             /* FIXME want (LOCATION_FILE (input_location), (line)0) */
     372             :           /* Avoid crashing later.  */
     373           8 :           define_label (location, DECL_NAME (label));
     374             :         }
     375             :       else 
     376       15072 :         warn_for_unused_label (label);
     377             :     }
     378       15379 : }
     379             : 
     380             : /* Helper function to sort named label entries in a vector by DECL_UID.  */
     381             : 
     382             : static int
     383      200565 : sort_labels (const void *a, const void *b)
     384             : {
     385      200565 :   tree label1 = *(tree const *) a;
     386      200565 :   tree label2 = *(tree const *) b;
     387             : 
     388             :   /* DECL_UIDs can never be equal.  */
     389      200565 :   return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
     390             : }
     391             : 
     392             : /* At the end of a function, all labels declared within the function
     393             :    go out of scope.  BLOCK is the top-level block for the
     394             :    function.  */
     395             : 
     396             : static void
     397    90437219 : pop_labels (tree block)
     398             : {
     399    90437219 :   if (!named_labels)
     400    90434861 :     return;
     401             : 
     402             :   /* We need to add the labels to the block chain, so debug
     403             :      information is emitted.  But, we want the order to be stable so
     404             :      need to sort them first.  Otherwise the debug output could be
     405             :      randomly ordered.  I guess it's mostly stable, unless the hash
     406             :      table implementation changes.  */
     407        2358 :   auto_vec<tree, 32> labels (named_labels->elements ());
     408        2358 :   hash_table<named_label_hash>::iterator end (named_labels->end ());
     409       17709 :   for (hash_table<named_label_hash>::iterator iter
     410       20067 :          (named_labels->begin ()); iter != end; ++iter)
     411             :     {
     412       15351 :       named_label_entry *ent = *iter;
     413             : 
     414       15351 :       gcc_checking_assert (!ent->outer);
     415       15351 :       if (ent->label_decl)
     416       15275 :         labels.quick_push (ent->label_decl);
     417       15351 :       ggc_free (ent);
     418             :     }
     419        2358 :   named_labels = NULL;
     420        2358 :   labels.qsort (sort_labels);
     421             : 
     422       17633 :   while (labels.length ())
     423             :     {
     424       15275 :       tree label = labels.pop ();
     425             : 
     426       15275 :       DECL_CHAIN (label) = BLOCK_VARS (block);
     427       15275 :       BLOCK_VARS (block) = label;
     428             : 
     429       15275 :       check_label_used (label);
     430             :     }
     431        2358 : }
     432             : 
     433             : /* At the end of a block with local labels, restore the outer definition.  */
     434             : 
     435             : static void
     436         104 : pop_local_label (tree id, tree label)
     437             : {
     438         104 :   check_label_used (label);
     439         104 :   named_label_entry **slot = named_labels->find_slot_with_hash
     440         104 :     (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
     441         104 :   named_label_entry *ent = *slot;
     442             : 
     443         104 :   if (ent->outer)
     444             :     ent = ent->outer;
     445             :   else
     446             :     {
     447          92 :       ent = ggc_cleared_alloc<named_label_entry> ();
     448          92 :       ent->name = id;
     449             :     }
     450         104 :   *slot = ent;
     451         104 : }
     452             : 
     453             : /* The following two routines are used to interface to Objective-C++.
     454             :    The binding level is purposely treated as an opaque type.  */
     455             : 
     456             : void *
     457           0 : objc_get_current_scope (void)
     458             : {
     459           0 :   return current_binding_level;
     460             : }
     461             : 
     462             : /* The following routine is used by the NeXT-style SJLJ exceptions;
     463             :    variables get marked 'volatile' so as to not be clobbered by
     464             :    _setjmp()/_longjmp() calls.  All variables in the current scope,
     465             :    as well as parent scopes up to (but not including) ENCLOSING_BLK
     466             :    shall be thusly marked.  */
     467             : 
     468             : void
     469           0 : objc_mark_locals_volatile (void *enclosing_blk)
     470             : {
     471           0 :   cp_binding_level *scope;
     472             : 
     473           0 :   for (scope = current_binding_level;
     474           0 :        scope && scope != enclosing_blk;
     475           0 :        scope = scope->level_chain)
     476             :     {
     477           0 :       tree decl;
     478             : 
     479           0 :       for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
     480           0 :         objc_volatilize_decl (decl);
     481             : 
     482             :       /* Do not climb up past the current function.  */
     483           0 :       if (scope->kind == sk_function_parms)
     484             :         break;
     485             :     }
     486           0 : }
     487             : 
     488             : /* True if B is the level for the condition of a constexpr if.  */
     489             : 
     490             : static bool
     491      712955 : level_for_constexpr_if (cp_binding_level *b)
     492             : {
     493      698379 :   return (b->kind == sk_cond && b->this_entity
     494         219 :           && TREE_CODE (b->this_entity) == IF_STMT
     495      713174 :           && IF_STMT_CONSTEXPR_P (b->this_entity));
     496             : }
     497             : 
     498             : /* True if B is the level for the condition of a consteval if.  */
     499             : 
     500             : static bool
     501      712933 : level_for_consteval_if (cp_binding_level *b)
     502             : {
     503      698357 :   return (b->kind == sk_cond && b->this_entity
     504         195 :           && TREE_CODE (b->this_entity) == IF_STMT
     505      713128 :           && IF_STMT_CONSTEVAL_P (b->this_entity));
     506             : }
     507             : 
     508             : /* Update data for defined and undefined labels when leaving a scope.  */
     509             : 
     510             : int
     511      128824 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
     512             : {
     513      128824 :   named_label_entry *ent = *slot;
     514      128824 :   cp_binding_level *obl = bl->level_chain;
     515             : 
     516      128824 :   if (ent->binding_level == bl)
     517             :     {
     518       17876 :       tree decl;
     519             : 
     520             :       /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
     521             :          TREE_LISTs representing OVERLOADs, so be careful.  */
     522       20837 :       for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
     523        3090 :                                                      ? DECL_CHAIN (decl)
     524         129 :                                                      : TREE_CHAIN (decl)))
     525        2961 :         if (decl_jump_unsafe (decl))
     526        1113 :           vec_safe_push (ent->bad_decls, decl);
     527             : 
     528       17876 :       ent->binding_level = obl;
     529       17876 :       ent->names_in_scope = obl->names;
     530       17876 :       switch (bl->kind)
     531             :         {
     532          45 :         case sk_try:
     533          45 :           ent->in_try_scope = true;
     534          45 :           break;
     535          26 :         case sk_catch:
     536          26 :           ent->in_catch_scope = true;
     537          26 :           break;
     538         140 :         case sk_omp:
     539         140 :           ent->in_omp_scope = true;
     540         140 :           break;
     541           4 :         case sk_transaction:
     542           4 :           ent->in_transaction_scope = true;
     543           4 :           break;
     544          38 :         case sk_stmt_expr:
     545          38 :           ent->in_stmt_expr = true;
     546          38 :           break;
     547       14790 :         case sk_block:
     548       14790 :           if (level_for_constexpr_if (bl->level_chain))
     549          15 :             ent->in_constexpr_if = true;
     550       14775 :           else if (level_for_consteval_if (bl->level_chain))
     551          10 :             ent->in_consteval_if = true;
     552             :           break;
     553             :         default:
     554             :           break;
     555             :         }
     556             :     }
     557      110948 :   else if (ent->uses)
     558             :     {
     559             :       struct named_label_use_entry *use;
     560             : 
     561       27236 :       for (use = ent->uses; use ; use = use->next)
     562       17613 :         if (use->binding_level == bl)
     563             :           {
     564        2086 :             use->binding_level = obl;
     565        2086 :             use->names_in_scope = obl->names;
     566        2086 :             if (bl->kind == sk_omp)
     567          16 :               use->in_omp_scope = true;
     568             :           }
     569             :     }
     570             : 
     571      128824 :   return 1;
     572             : }
     573             : 
     574             : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
     575             :    when errors were reported, except for -Werror-unused-but-set-*.  */
     576             : static int unused_but_set_errorcount;
     577             : 
     578             : /* Exit a binding level.
     579             :    Pop the level off, and restore the state of the identifier-decl mappings
     580             :    that were in effect when this level was entered.
     581             : 
     582             :    If KEEP == 1, this level had explicit declarations, so
     583             :    and create a "block" (a BLOCK node) for the level
     584             :    to record its declarations and subblocks for symbol table output.
     585             : 
     586             :    If FUNCTIONBODY is nonzero, this level is the body of a function,
     587             :    so create a block as if KEEP were set and also clear out all
     588             :    label names.
     589             : 
     590             :    If REVERSE is nonzero, reverse the order of decls before putting
     591             :    them into the BLOCK.  */
     592             : 
     593             : tree
     594   357039553 : poplevel (int keep, int reverse, int functionbody)
     595             : {
     596   357039553 :   tree link;
     597             :   /* The chain of decls was accumulated in reverse order.
     598             :      Put it into forward order, just for cleanliness.  */
     599   357039553 :   tree decls;
     600   357039553 :   tree subblocks;
     601   357039553 :   tree block;
     602   357039553 :   tree decl;
     603   357039553 :   scope_kind kind;
     604             : 
     605   357039553 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     606   357039642 :  restart:
     607             : 
     608   357039642 :   block = NULL_TREE;
     609             : 
     610   357039642 :   gcc_assert (current_binding_level->kind != sk_class
     611             :               && current_binding_level->kind != sk_namespace);
     612             : 
     613   357039642 :   if (current_binding_level->kind == sk_cleanup)
     614             :     functionbody = 0;
     615   357039642 :   subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
     616             : 
     617   357039642 :   gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
     618             : 
     619             :   /* We used to use KEEP == 2 to indicate that the new block should go
     620             :      at the beginning of the list of blocks at this binding level,
     621             :      rather than the end.  This hack is no longer used.  */
     622   357039642 :   gcc_assert (keep == 0 || keep == 1);
     623             : 
     624   357039642 :   if (current_binding_level->keep)
     625     4400317 :     keep = 1;
     626             : 
     627             :   /* Any uses of undefined labels, and any defined labels, now operate
     628             :      under constraints of next binding contour.  */
     629   357039642 :   if (cfun && !functionbody && named_labels)
     630       37259 :     named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
     631       37259 :                    (current_binding_level);
     632             : 
     633             :   /* Get the decls in the order they were written.
     634             :      Usually current_binding_level->names is in reverse order.
     635             :      But parameter decls were previously put in forward order.  */
     636             : 
     637   357039642 :   decls = current_binding_level->names;
     638   357039642 :   if (reverse)
     639             :     {
     640   184847963 :       decls = nreverse (decls);
     641   184847963 :       current_binding_level->names = decls;
     642             :     }
     643             : 
     644             :   /* If there were any declarations or structure tags in that level,
     645             :      or if this level is a function body,
     646             :      create a BLOCK to record them for the life of this function.  */
     647   357039642 :   block = NULL_TREE;
     648             :   /* Avoid function body block if possible.  */
     649   378617090 :   if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
     650             :     keep = 0;
     651   335462485 :   else if (keep == 1 || functionbody)
     652   111117776 :     block = make_node (BLOCK);
     653   111117776 :   if (block != NULL_TREE)
     654             :     {
     655   111117776 :       BLOCK_VARS (block) = decls;
     656   111117776 :       BLOCK_SUBBLOCKS (block) = subblocks;
     657             :     }
     658             : 
     659             :   /* In each subblock, record that this is its superior.  */
     660   357039642 :   if (keep >= 0)
     661   399298019 :     for (link = subblocks; link; link = BLOCK_CHAIN (link))
     662    42258377 :       BLOCK_SUPERCONTEXT (link) = block;
     663             : 
     664             :   /* Before we remove the declarations first check for unused variables.  */
     665   357039642 :   if ((warn_unused_variable || warn_unused_but_set_variable)
     666     5203762 :       && current_binding_level->kind != sk_template_parms
     667     4419050 :       && !processing_template_decl)
     668     5334703 :     for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
     669             :       {
     670             :         /* There are cases where D itself is a TREE_LIST.  See in
     671             :            push_local_binding where the list of decls returned by
     672             :            getdecls is built.  */
     673     2758943 :         decl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
     674             : 
     675     2758943 :         tree type = TREE_TYPE (decl);
     676     2758943 :         if (VAR_P (decl)
     677      310999 :             && (! TREE_USED (decl) || !DECL_READ_P (decl))
     678        2307 :             && ! DECL_IN_SYSTEM_HEADER (decl)
     679             :             /* For structured bindings, consider only real variables, not
     680             :                subobjects.  */
     681         729 :             && (DECL_DECOMPOSITION_P (decl) ? !DECL_DECOMP_BASE (decl)
     682         653 :                 : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
     683         443 :             && type != error_mark_node
     684     2760077 :             && (!CLASS_TYPE_P (type)
     685          45 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
     686           4 :                 || lookup_attribute ("warn_unused",
     687           4 :                                      TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
     688             :           {
     689         405 :             if (! TREE_USED (decl))
     690             :               {
     691         218 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     692           2 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     693             :                               OPT_Wunused_variable,
     694             :                               "unused structured binding declaration");
     695             :                 else
     696         216 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     697             :                               OPT_Wunused_variable, "unused variable %qD", decl);
     698         218 :                 suppress_warning (decl, OPT_Wunused_variable);
     699             :               }
     700         187 :             else if (DECL_CONTEXT (decl) == current_function_decl
     701             :                      // For -Wunused-but-set-variable leave references alone.
     702         159 :                      && !TYPE_REF_P (TREE_TYPE (decl))
     703         346 :                      && errorcount == unused_but_set_errorcount)
     704             :               {
     705         147 :                 if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
     706           8 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     707             :                               OPT_Wunused_but_set_variable, "structured "
     708             :                               "binding declaration set but not used");
     709             :                 else
     710         139 :                   warning_at (DECL_SOURCE_LOCATION (decl),
     711             :                               OPT_Wunused_but_set_variable,
     712             :                               "variable %qD set but not used", decl);
     713         147 :                 unused_but_set_errorcount = errorcount;
     714             :               }
     715             :           }
     716             :       }
     717             : 
     718             :   /* Remove declarations for all the DECLs in this level.  */
     719   744109260 :   for (link = decls; link; link = TREE_CHAIN (link))
     720             :     {
     721   387069618 :       tree name;
     722   387069618 :       if (TREE_CODE (link) == TREE_LIST)
     723             :         {
     724      340945 :           decl = TREE_VALUE (link);
     725      340945 :           name = TREE_PURPOSE (link);
     726      340945 :           gcc_checking_assert (name);
     727             :         }
     728             :       else
     729             :         {
     730   386728673 :           decl = link;
     731   386728673 :           name = DECL_NAME (decl);
     732             :         }
     733             : 
     734             :       /* Remove the binding.  */
     735   387069618 :       if (TREE_CODE (decl) == LABEL_DECL)
     736         104 :         pop_local_label (name, decl);
     737             :       else
     738   387069514 :         pop_local_binding (name, decl);
     739             :     }
     740             : 
     741             :   /* Restore the IDENTIFIER_TYPE_VALUEs.  */
     742   357039642 :   for (link = current_binding_level->type_shadowed;
     743   493861806 :        link; link = TREE_CHAIN (link))
     744   136822164 :     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
     745             : 
     746             :   /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
     747             :      list if a `using' declaration put them there.  The debugging
     748             :      back ends won't understand OVERLOAD, so we remove them here.
     749             :      Because the BLOCK_VARS are (temporarily) shared with
     750             :      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
     751             :      popped all the bindings.  Also remove undeduced 'auto' decls,
     752             :      which LTO doesn't understand, and can't have been used by anything.  */
     753   357039642 :   if (block)
     754             :     {
     755   111117776 :       tree* d;
     756             : 
     757   295311077 :       for (d = &BLOCK_VARS (block); *d; )
     758             :         {
     759   184193301 :           if (TREE_CODE (*d) == TREE_LIST
     760   184193301 :               || (!processing_template_decl
     761    56698338 :                   && undeduced_auto_decl (*d)))
     762      340954 :             *d = TREE_CHAIN (*d);
     763             :           else
     764   183852347 :             d = &DECL_CHAIN (*d);
     765             :         }
     766             :     }
     767             : 
     768             :   /* If the level being exited is the top level of a function,
     769             :      check over all the labels.  */
     770   357039642 :   if (functionbody)
     771             :     {
     772    90437219 :       if (block)
     773             :         {
     774             :           /* Since this is the top level block of a function, the vars are
     775             :              the function's parameters.  Don't leave them in the BLOCK
     776             :              because they are found in the FUNCTION_DECL instead.  */
     777    68860062 :           BLOCK_VARS (block) = 0;
     778    68860062 :           pop_labels (block);
     779             :         }
     780             :       else
     781    21577157 :         pop_labels (subblocks);
     782             :     }
     783             : 
     784   357039642 :   kind = current_binding_level->kind;
     785   357039642 :   if (kind == sk_cleanup)
     786             :     {
     787          89 :       tree stmt;
     788             : 
     789             :       /* If this is a temporary binding created for a cleanup, then we'll
     790             :          have pushed a statement list level.  Pop that, create a new
     791             :          BIND_EXPR for the block, and insert it into the stream.  */
     792          89 :       stmt = pop_stmt_list (current_binding_level->statement_list);
     793          89 :       stmt = c_build_bind_expr (input_location, block, stmt);
     794          89 :       add_stmt (stmt);
     795             :     }
     796             : 
     797   357039642 :   leave_scope ();
     798   357039642 :   if (functionbody)
     799             :     {
     800             :       /* The current function is being defined, so its DECL_INITIAL
     801             :          should be error_mark_node.  */
     802    90437219 :       gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
     803   112014376 :       DECL_INITIAL (current_function_decl) = block ? block : subblocks;
     804    90437219 :       if (subblocks)
     805             :         {
     806    43747602 :           if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
     807             :             {
     808     4905985 :               if (BLOCK_SUBBLOCKS (subblocks))
     809      600969 :                 BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
     810             :             }
     811             :           else
     812    16671463 :             BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
     813             :         }
     814             :     }
     815   266602423 :   else if (block)
     816    42257714 :     current_binding_level->blocks
     817    84515428 :       = block_chainon (current_binding_level->blocks, block);
     818             : 
     819             :   /* If we did not make a block for the level just exited,
     820             :      any blocks made for inner levels
     821             :      (since they cannot be recorded as subblocks in that level)
     822             :      must be carried forward so they will later become subblocks
     823             :      of something else.  */
     824   224344709 :   else if (subblocks)
     825           4 :     current_binding_level->blocks
     826           8 :       = block_chainon (current_binding_level->blocks, subblocks);
     827             : 
     828             :   /* Each and every BLOCK node created here in `poplevel' is important
     829             :      (e.g. for proper debugging information) so if we created one
     830             :      earlier, mark it as "used".  */
     831   357039642 :   if (block)
     832   111117776 :     TREE_USED (block) = 1;
     833             : 
     834             :   /* All temporary bindings created for cleanups are popped silently.  */
     835   357039642 :   if (kind == sk_cleanup)
     836          89 :     goto restart;
     837             : 
     838   714079106 :   return block;
     839   357039553 : }
     840             : 
     841             : /* Call wrapup_globals_declarations for the globals in NAMESPACE.  */
     842             : /* Diagnose odr-used extern inline variables without definitions
     843             :    in the current TU.  */
     844             : 
     845             : int
     846      125105 : wrapup_namespace_globals ()
     847             : {
     848      125105 :   if (vec<tree, va_gc> *statics = static_decls)
     849             :     {
     850     9421281 :       for (tree decl : *statics)
     851             :         {
     852     9317646 :           if (warn_unused_function
     853      887282 :               && TREE_CODE (decl) == FUNCTION_DECL
     854      652311 :               && DECL_INITIAL (decl) == 0
     855        2062 :               && DECL_EXTERNAL (decl)
     856        2062 :               && !TREE_PUBLIC (decl)
     857          22 :               && !DECL_ARTIFICIAL (decl)
     858          22 :               && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
     859     9317654 :               && !warning_suppressed_p (decl, OPT_Wunused_function))
     860           8 :             warning_at (DECL_SOURCE_LOCATION (decl),
     861             :                         OPT_Wunused_function,
     862             :                         "%qF declared %<static%> but never defined", decl);
     863             : 
     864     9317646 :           if (VAR_P (decl)
     865     2755455 :               && DECL_EXTERNAL (decl)
     866     1472295 :               && DECL_INLINE_VAR_P (decl)
     867     9317661 :               && DECL_ODR_USED (decl))
     868           3 :             error_at (DECL_SOURCE_LOCATION (decl),
     869             :                       "odr-used inline variable %qD is not defined", decl);
     870             :         }
     871             : 
     872             :       /* Clear out the list, so we don't rescan next time.  */
     873      103635 :       static_decls = NULL;
     874             : 
     875             :       /* Write out any globals that need to be output.  */
     876      103635 :       return wrapup_global_declarations (statics->address (),
     877      103635 :                                          statics->length ());
     878             :     }
     879             :   return 0;
     880             : }
     881             : 
     882             : /* In C++, you don't have to write `struct S' to refer to `S'; you
     883             :    can just use `S'.  We accomplish this by creating a TYPE_DECL as
     884             :    if the user had written `typedef struct S S'.  Create and return
     885             :    the TYPE_DECL for TYPE.  */
     886             : 
     887             : tree
     888   100636421 : create_implicit_typedef (tree name, tree type)
     889             : {
     890   100636421 :   tree decl;
     891             : 
     892   100636421 :   decl = build_decl (input_location, TYPE_DECL, name, type);
     893   100636421 :   DECL_ARTIFICIAL (decl) = 1;
     894             :   /* There are other implicit type declarations, like the one *within*
     895             :      a class that allows you to write `S::S'.  We must distinguish
     896             :      amongst these.  */
     897   100636421 :   SET_DECL_IMPLICIT_TYPEDEF_P (decl);
     898   100636421 :   TYPE_NAME (type) = decl;
     899   100636421 :   TYPE_STUB_DECL (type) = decl;
     900             : 
     901   100636421 :   return decl;
     902             : }
     903             : 
     904             : /* Function-scope local entities that need discriminators.  Each entry
     905             :    is a {decl,name} pair.  VAR_DECLs for anon unions get their name
     906             :    smashed, so we cannot rely on DECL_NAME.  */
     907             : 
     908             : static GTY((deletable)) vec<tree, va_gc> *local_entities;
     909             : 
     910             : /* Determine the mangling discriminator of local DECL.  There are
     911             :    generally very few of these in any particular function.  */
     912             : 
     913             : void
     914      412182 : determine_local_discriminator (tree decl)
     915             : {
     916      412182 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
     917      412182 :   retrofit_lang_decl (decl);
     918      412182 :   tree ctx = DECL_CONTEXT (decl);
     919      412182 :   tree name = (TREE_CODE (decl) == TYPE_DECL
     920      656491 :                && TYPE_UNNAMED_P (TREE_TYPE (decl))
     921      736805 :                ? NULL_TREE : DECL_NAME (decl));
     922      412182 :   size_t nelts = vec_safe_length (local_entities);
     923     9480427 :   for (size_t i = 0; i < nelts; i += 2)
     924             :     {
     925     9068604 :       tree *pair = &(*local_entities)[i];
     926     9068604 :       tree d = pair[0];
     927     9068604 :       tree n = pair[1];
     928     9068604 :       gcc_checking_assert (d != decl);
     929     9068604 :       if (name == n
     930     2195336 :           && TREE_CODE (decl) == TREE_CODE (d)
     931    11263928 :           && ctx == DECL_CONTEXT (d))
     932             :         {
     933         359 :           tree disc = integer_one_node;
     934         547 :           if (DECL_DISCRIMINATOR (d))
     935         206 :             disc = build_int_cst (TREE_TYPE (disc),
     936         304 :                                   TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
     937         359 :           DECL_DISCRIMINATOR (decl) = disc;
     938             :           /* Replace the saved decl.  */
     939         359 :           pair[0] = decl;
     940         359 :           decl = NULL_TREE;
     941         359 :           break;
     942             :         }
     943             :     }
     944             : 
     945      412182 :   if (decl)
     946             :     {
     947      411823 :       vec_safe_reserve (local_entities, 2);
     948      411823 :       local_entities->quick_push (decl);
     949      411823 :       local_entities->quick_push (name);
     950             :     }
     951      412182 : }
     952             : 
     953             : 
     954             : 
     955             : /* Returns true if functions FN1 and FN2 have equivalent trailing
     956             :    requires clauses.  */
     957             : 
     958             : static bool
     959      806741 : function_requirements_equivalent_p (tree newfn, tree oldfn)
     960             : {
     961             :   /* In the concepts TS, the combined constraints are compared.  */
     962      806741 :   if (cxx_dialect < cxx20)
     963             :     {
     964         555 :       tree ci1 = get_constraints (oldfn);
     965         555 :       tree ci2 = get_constraints (newfn);
     966         593 :       tree req1 = ci1 ? CI_ASSOCIATED_CONSTRAINTS (ci1) : NULL_TREE;
     967         602 :       tree req2 = ci2 ? CI_ASSOCIATED_CONSTRAINTS (ci2) : NULL_TREE;
     968         555 :       return cp_tree_equal (req1, req2);
     969             :     }
     970             : 
     971             :   /* Compare only trailing requirements.  */
     972      806186 :   tree reqs1 = get_trailing_function_requirements (newfn);
     973      806186 :   tree reqs2 = get_trailing_function_requirements (oldfn);
     974      806186 :   if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
     975             :     return false;
     976             : 
     977             :   /* Substitution is needed when friends are involved.  */
     978      798482 :   reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
     979      798482 :   reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
     980             : 
     981      798482 :   return cp_tree_equal (reqs1, reqs2);
     982             : }
     983             : 
     984             : /* Two functions of the same name correspond [basic.scope.scope] if
     985             : 
     986             :    + both declare functions with the same non-object-parameter-type-list,
     987             :    equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
     988             :    specified in [temp.friend]), and, if both are non-static members, they have
     989             :    corresponding object parameters, or
     990             : 
     991             :    + both declare function templates with equivalent
     992             :    non-object-parameter-type-lists, return types (if any), template-heads, and
     993             :    trailing requires-clauses (if any), and, if both are non-static members,
     994             :    they have corresponding object parameters.
     995             : 
     996             :    This is a subset of decls_match: it identifies declarations that cannot be
     997             :    overloaded with one another.  This function does not consider DECL_NAME.  */
     998             : 
     999             : bool
    1000     4956532 : fns_correspond (tree newdecl, tree olddecl)
    1001             : {
    1002     4956532 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1003             :     return false;
    1004             : 
    1005     4487165 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1006             :     {
    1007     4476309 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1008             :         return 0;
    1009     1621944 :       newdecl = DECL_TEMPLATE_RESULT (newdecl);
    1010     1621944 :       olddecl = DECL_TEMPLATE_RESULT (olddecl);
    1011             :     }
    1012             : 
    1013     1632800 :   tree f1 = TREE_TYPE (newdecl);
    1014     1632800 :   tree f2 = TREE_TYPE (olddecl);
    1015             : 
    1016     1632800 :   int rq1 = type_memfn_rqual (f1);
    1017     1632800 :   int rq2 = type_memfn_rqual (f2);
    1018             : 
    1019             :   /* If only one is a non-static member function, ignore ref-quals.  */
    1020     1632800 :   if (TREE_CODE (f1) != TREE_CODE (f2))
    1021             :     rq1 = rq2;
    1022             :   /* Two non-static member functions have corresponding object parameters if:
    1023             :      + exactly one is an implicit object member function with no ref-qualifier
    1024             :      and the types of their object parameters ([dcl.fct]), after removing
    1025             :      top-level references, are the same, or
    1026             :      + their object parameters have the same type.  */
    1027             :   /* ??? We treat member functions of different classes as corresponding even
    1028             :      though that means the object parameters have different types.  */
    1029     1632800 :   else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
    1030           0 :     rq1 = rq2;
    1031             : 
    1032     1632800 :   bool types_match = rq1 == rq2;
    1033             : 
    1034     1632800 :   if (types_match)
    1035             :     {
    1036     1632800 :       tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1037     1632800 :       tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    1038     1632800 :       types_match = compparms (p1, p2);
    1039             :     }
    1040             : 
    1041             :   /* Two function declarations match if either has a requires-clause
    1042             :      then both have a requires-clause and their constraints-expressions
    1043             :      are equivalent.  */
    1044     1632800 :   if (types_match && flag_concepts)
    1045      225737 :     types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1046             : 
    1047             :   return types_match;
    1048             : }
    1049             : 
    1050             : /* Subroutine of duplicate_decls: return truthvalue of whether
    1051             :    or not types of these decls match.
    1052             : 
    1053             :    For C++, we must compare the parameter list so that `int' can match
    1054             :    `int&' in a parameter position, but `int&' is not confused with
    1055             :    `const int&'.  */
    1056             : 
    1057             : int
    1058   646216205 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
    1059             : {
    1060   646216205 :   int types_match;
    1061             : 
    1062   646216205 :   if (newdecl == olddecl)
    1063             :     return 1;
    1064             : 
    1065   646174703 :   if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
    1066             :     /* If the two DECLs are not even the same kind of thing, we're not
    1067             :        interested in their types.  */
    1068             :     return 0;
    1069             : 
    1070   317044748 :   gcc_assert (DECL_P (newdecl));
    1071             : 
    1072   317044748 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1073             :     {
    1074             :       /* Specializations of different templates are different functions
    1075             :          even if they have the same type.  */
    1076   167979840 :       tree t1 = (DECL_USE_TEMPLATE (newdecl)
    1077   167979840 :                  ? DECL_TI_TEMPLATE (newdecl)
    1078   167979840 :                  : NULL_TREE);
    1079   167979840 :       tree t2 = (DECL_USE_TEMPLATE (olddecl)
    1080   167979840 :                  ? DECL_TI_TEMPLATE (olddecl)
    1081   167979840 :                  : NULL_TREE);
    1082   167979840 :       if (t1 != t2)
    1083             :         return 0;
    1084             : 
    1085   166322695 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1086   168525849 :           && ! (DECL_EXTERN_C_P (newdecl)
    1087     2203154 :                 && DECL_EXTERN_C_P (olddecl)))
    1088             :         return 0;
    1089             : 
    1090             :       /* A new declaration doesn't match a built-in one unless it
    1091             :          is also extern "C".  */
    1092   154421703 :       if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
    1093   154421703 :           && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
    1094             :         return 0;
    1095             : 
    1096   153935046 :       tree f1 = TREE_TYPE (newdecl);
    1097   153935046 :       tree f2 = TREE_TYPE (olddecl);
    1098   153935046 :       if (TREE_CODE (f1) != TREE_CODE (f2))
    1099             :         return 0;
    1100             : 
    1101             :       /* A declaration with deduced return type should use its pre-deduction
    1102             :          type for declaration matching.  */
    1103   153821684 :       tree r2 = fndecl_declared_return_type (olddecl);
    1104   153821684 :       tree r1 = fndecl_declared_return_type (newdecl);
    1105             : 
    1106   153821684 :       tree p1 = TYPE_ARG_TYPES (f1);
    1107   153821684 :       tree p2 = TYPE_ARG_TYPES (f2);
    1108             : 
    1109   153821684 :       if (same_type_p (r1, r2))
    1110             :         {
    1111   116016661 :           if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
    1112   116016647 :               && fndecl_built_in_p (olddecl))
    1113             :             {
    1114          57 :               types_match = self_promoting_args_p (p1);
    1115          57 :               if (p1 == void_list_node)
    1116           4 :                 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
    1117             :             }
    1118             :           else
    1119   116016521 :             types_match =
    1120   116016521 :               compparms (p1, p2)
    1121    17667405 :               && type_memfn_rqual (f1) == type_memfn_rqual (f2)
    1122   133683856 :               && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
    1123      471628 :                   || comp_type_attributes (TREE_TYPE (newdecl),
    1124      471628 :                                            TREE_TYPE (olddecl)) != 0);
    1125             :         }
    1126             :       else
    1127             :         types_match = 0;
    1128             : 
    1129             :       /* Two function declarations match if either has a requires-clause
    1130             :          then both have a requires-clause and their constraints-expressions
    1131             :          are equivalent.  */
    1132    17667364 :       if (types_match && flag_concepts)
    1133      580988 :         types_match = function_requirements_equivalent_p (newdecl, olddecl);
    1134             : 
    1135             :       /* The decls dont match if they correspond to two different versions
    1136             :          of the same function.   Disallow extern "C" functions to be
    1137             :          versions for now.  */
    1138    17667364 :       if (types_match
    1139    17657234 :           && !DECL_EXTERN_C_P (newdecl)
    1140    14173432 :           && !DECL_EXTERN_C_P (olddecl)
    1141    31837450 :           && targetm.target_option.function_versions (newdecl, olddecl))
    1142             :         {
    1143       11160 :           if (record_versions)
    1144       22120 :             maybe_version_functions (newdecl, olddecl,
    1145       11060 :                                      (!DECL_FUNCTION_VERSIONED (newdecl)
    1146       21048 :                                       || !DECL_FUNCTION_VERSIONED (olddecl)));
    1147       11160 :           return 0;
    1148             :         }
    1149             :     }
    1150   149064908 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1151             :     {
    1152   148111236 :       if (!template_heads_equivalent_p (newdecl, olddecl))
    1153             :         return 0;
    1154             : 
    1155    47739807 :       tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1156    47739807 :       tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1157             : 
    1158    47739807 :       if (TREE_CODE (newres) != TREE_CODE (oldres))
    1159             :         return 0;
    1160             : 
    1161             :       /* Two template types match if they are the same. Otherwise, compare
    1162             :          the underlying declarations.  */
    1163    47739800 :       if (TREE_CODE (newres) == TYPE_DECL)
    1164          25 :         types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
    1165             :       else
    1166    47739775 :         types_match = decls_match (newres, oldres);
    1167             :     }
    1168             :   else
    1169             :     {
    1170             :       /* Need to check scope for variable declaration (VAR_DECL).
    1171             :          For typedef (TYPE_DECL), scope is ignored.  */
    1172      953672 :       if (VAR_P (newdecl)
    1173      662610 :           && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
    1174             :           /* [dcl.link]
    1175             :              Two declarations for an object with C language linkage
    1176             :              with the same name (ignoring the namespace that qualify
    1177             :              it) that appear in different namespace scopes refer to
    1178             :              the same object.  */
    1179     1066118 :           && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
    1180             :         return 0;
    1181             : 
    1182      841290 :       if (TREE_TYPE (newdecl) == error_mark_node)
    1183           0 :         types_match = TREE_TYPE (olddecl) == error_mark_node;
    1184      841290 :       else if (TREE_TYPE (olddecl) == NULL_TREE)
    1185           0 :         types_match = TREE_TYPE (newdecl) == NULL_TREE;
    1186      841290 :       else if (TREE_TYPE (newdecl) == NULL_TREE)
    1187             :         types_match = 0;
    1188             :       else
    1189      841290 :         types_match = comptypes (TREE_TYPE (newdecl),
    1190      841290 :                                  TREE_TYPE (olddecl),
    1191             :                                  COMPARE_REDECLARATION);
    1192             :     }
    1193             : 
    1194             :   return types_match;
    1195             : }
    1196             : 
    1197             : /* Mark DECL as versioned if it isn't already.  */
    1198             : 
    1199             : static void
    1200       22240 : maybe_mark_function_versioned (tree decl)
    1201             : {
    1202       22240 :   if (!DECL_FUNCTION_VERSIONED (decl))
    1203             :     {
    1204        1264 :       DECL_FUNCTION_VERSIONED (decl) = 1;
    1205             :       /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
    1206             :          to include the version marker.  */
    1207        1264 :       if (DECL_ASSEMBLER_NAME_SET_P (decl))
    1208          44 :         mangle_decl (decl);
    1209             :     }
    1210       22240 : }
    1211             : 
    1212             : /* NEWDECL and OLDDECL have identical signatures.  If they are
    1213             :    different versions adjust them and return true.
    1214             :    If RECORD is set to true, record function versions.  */
    1215             : 
    1216             : bool
    1217       14484 : maybe_version_functions (tree newdecl, tree olddecl, bool record)
    1218             : {
    1219       14484 :   if (!targetm.target_option.function_versions (newdecl, olddecl))
    1220             :     return false;
    1221             : 
    1222       11096 :   maybe_mark_function_versioned (olddecl);
    1223       11096 :   if (DECL_LOCAL_DECL_P (olddecl))
    1224             :     {
    1225          24 :       olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
    1226          24 :       maybe_mark_function_versioned (olddecl);
    1227             :     }
    1228             : 
    1229       11096 :   maybe_mark_function_versioned (newdecl);
    1230       11096 :   if (DECL_LOCAL_DECL_P (newdecl))
    1231             :     {
    1232             :       /* Unfortunately, we can get here before pushdecl naturally calls
    1233             :          push_local_extern_decl_alias, so we need to call it directly.  */
    1234          48 :       if (!DECL_LOCAL_DECL_ALIAS (newdecl))
    1235           8 :         push_local_extern_decl_alias (newdecl);
    1236          24 :       newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
    1237          24 :       maybe_mark_function_versioned (newdecl);
    1238             :     }
    1239             : 
    1240       11096 :   if (record)
    1241        1108 :     cgraph_node::record_function_versions (olddecl, newdecl);
    1242             : 
    1243             :   return true;
    1244             : }
    1245             : 
    1246             : /* If NEWDECL is `static' and an `extern' was seen previously,
    1247             :    warn about it.  OLDDECL is the previous declaration.
    1248             : 
    1249             :    Note that this does not apply to the C++ case of declaring
    1250             :    a variable `extern const' and then later `const'.
    1251             : 
    1252             :    Don't complain about built-in functions, since they are beyond
    1253             :    the user's control.  */
    1254             : 
    1255             : void
    1256    12306174 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
    1257             : {
    1258    12306174 :   if (TREE_CODE (newdecl) == TYPE_DECL
    1259    12306174 :       || TREE_CODE (newdecl) == TEMPLATE_DECL
    1260     9984249 :       || TREE_CODE (newdecl) == CONST_DECL
    1261     9984249 :       || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1262    12306158 :     return;
    1263             : 
    1264             :   /* Don't get confused by static member functions; that's a different
    1265             :      use of `static'.  */
    1266     9984249 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    1267     9984249 :       && DECL_STATIC_FUNCTION_P (newdecl))
    1268             :     return;
    1269             : 
    1270             :   /* If the old declaration was `static', or the new one isn't, then
    1271             :      everything is OK.  */
    1272     9876692 :   if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
    1273             :     return;
    1274             : 
    1275             :   /* It's OK to declare a builtin function as `static'.  */
    1276          16 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1277          16 :       && DECL_ARTIFICIAL (olddecl))
    1278             :     return;
    1279             : 
    1280          16 :   auto_diagnostic_group d;
    1281          16 :   if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1282             :                  "%qD was declared %<extern%> and later %<static%>", newdecl))
    1283          16 :     inform (DECL_SOURCE_LOCATION (olddecl),
    1284             :             "previous declaration of %qD", olddecl);
    1285          16 : }
    1286             : 
    1287             : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
    1288             :    function templates.  If their exception specifications do not
    1289             :    match, issue a diagnostic.  */
    1290             : 
    1291             : static void
    1292    12024765 : check_redeclaration_exception_specification (tree new_decl,
    1293             :                                              tree old_decl)
    1294             : {
    1295    12024765 :   tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1296    12024765 :   tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1297             : 
    1298             :   /* Two default specs are equivalent, don't force evaluation.  */
    1299     3905479 :   if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
    1300    12129101 :       && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
    1301             :     return;
    1302             : 
    1303    12017316 :   if (!type_dependent_expression_p (old_decl))
    1304             :     {
    1305     6659459 :       maybe_instantiate_noexcept (new_decl);
    1306     6659459 :       maybe_instantiate_noexcept (old_decl);
    1307             :     }
    1308    12017316 :   new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
    1309    12017316 :   old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
    1310             : 
    1311             :   /* [except.spec]
    1312             : 
    1313             :      If any declaration of a function has an exception-specification,
    1314             :      all declarations, including the definition and an explicit
    1315             :      specialization, of that function shall have an
    1316             :      exception-specification with the same set of type-ids.  */
    1317    12017316 :   if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
    1318     9307537 :       && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
    1319    21324828 :       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
    1320             :     {
    1321         346 :       const char *const msg
    1322             :         = G_("declaration of %qF has a different exception specifier");
    1323         346 :       bool complained = true;
    1324         346 :       location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
    1325         346 :       auto_diagnostic_group d;
    1326         346 :       if (DECL_IN_SYSTEM_HEADER (old_decl))
    1327         245 :         complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
    1328         101 :       else if (!flag_exceptions)
    1329             :         /* We used to silently permit mismatched eh specs with
    1330             :            -fno-exceptions, so make them a pedwarn now.  */
    1331           3 :         complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
    1332             :       else
    1333          98 :         error_at (new_loc, msg, new_decl);
    1334         346 :       if (complained)
    1335         105 :         inform (DECL_SOURCE_LOCATION (old_decl),
    1336             :                 "from previous declaration %qF", old_decl);
    1337         346 :     }
    1338             : }
    1339             : 
    1340             : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
    1341             :    Otherwise issue diagnostics.  */
    1342             : 
    1343             : static bool
    1344    12306190 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
    1345             : {
    1346    12306190 :   old_decl = STRIP_TEMPLATE (old_decl);
    1347    12306190 :   new_decl = STRIP_TEMPLATE (new_decl);
    1348    12306190 :   if (!VAR_OR_FUNCTION_DECL_P (old_decl)
    1349    12299618 :       || !VAR_OR_FUNCTION_DECL_P (new_decl))
    1350             :     return true;
    1351    12299618 :   if (DECL_DECLARED_CONSTEXPR_P (old_decl)
    1352    12299618 :       == DECL_DECLARED_CONSTEXPR_P (new_decl))
    1353             :     {
    1354    12282810 :       if (TREE_CODE (old_decl) != FUNCTION_DECL)
    1355             :         return true;
    1356    24050138 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1357    12025069 :           == DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1358             :         return true;
    1359             :     }
    1360       16810 :   if (TREE_CODE (old_decl) == FUNCTION_DECL)
    1361             :     {
    1362             :       /* With -fimplicit-constexpr, ignore changes in the constexpr
    1363             :          keyword.  */
    1364          21 :       if (flag_implicit_constexpr
    1365          21 :           && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
    1366           0 :               == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
    1367             :         return true;
    1368          21 :       if (fndecl_built_in_p (old_decl))
    1369             :         {
    1370             :           /* Hide a built-in declaration.  */
    1371           0 :           DECL_DECLARED_CONSTEXPR_P (old_decl)
    1372           0 :             = DECL_DECLARED_CONSTEXPR_P (new_decl);
    1373           0 :           if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1374           0 :             SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
    1375           0 :           return true;
    1376             :         }
    1377             :       /* 7.1.5 [dcl.constexpr]
    1378             :          Note: An explicit specialization can differ from the template
    1379             :          declaration with respect to the constexpr specifier.  */
    1380          21 :       if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
    1381          21 :           && DECL_TEMPLATE_SPECIALIZATION (new_decl))
    1382             :         return true;
    1383             : 
    1384          10 :       const char *kind = "constexpr";
    1385          10 :       if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
    1386          18 :           || DECL_IMMEDIATE_FUNCTION_P (new_decl))
    1387             :         kind = "consteval";
    1388          10 :       error_at (DECL_SOURCE_LOCATION (new_decl),
    1389             :                 "redeclaration %qD differs in %qs "
    1390             :                 "from previous declaration", new_decl,
    1391             :                 kind);
    1392          10 :       inform (DECL_SOURCE_LOCATION (old_decl),
    1393             :               "previous declaration %qD", old_decl);
    1394          10 :       return false;
    1395             :     }
    1396             :   return true;
    1397             : }
    1398             : 
    1399             : // If OLDDECL and NEWDECL are concept declarations with the same type
    1400             : // (i.e., and template parameters), but different requirements,
    1401             : // emit diagnostics and return true. Otherwise, return false.
    1402             : static inline bool
    1403           5 : check_concept_refinement (tree olddecl, tree newdecl)
    1404             : {
    1405           5 :   if (!DECL_DECLARED_CONCEPT_P (olddecl) || !DECL_DECLARED_CONCEPT_P (newdecl))
    1406             :     return false;
    1407             : 
    1408           0 :   tree d1 = DECL_TEMPLATE_RESULT (olddecl);
    1409           0 :   tree d2 = DECL_TEMPLATE_RESULT (newdecl);
    1410           0 :   if (TREE_CODE (d1) != TREE_CODE (d2))
    1411             :     return false;
    1412             : 
    1413           0 :   tree t1 = TREE_TYPE (d1);
    1414           0 :   tree t2 = TREE_TYPE (d2);
    1415           0 :   if (TREE_CODE (d1) == FUNCTION_DECL)
    1416             :     {
    1417           0 :       if (compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2))
    1418           0 :           && comp_template_parms (DECL_TEMPLATE_PARMS (olddecl),
    1419           0 :                                   DECL_TEMPLATE_PARMS (newdecl))
    1420           0 :           && !equivalently_constrained (olddecl, newdecl))
    1421             :         {
    1422           0 :           error ("cannot specialize concept %q#D", olddecl);
    1423           0 :           return true;
    1424             :         }
    1425             :     }
    1426             :   return false;
    1427             : }
    1428             : 
    1429             : /* DECL is a redeclaration of a function or function template.  If
    1430             :    it does have default arguments issue a diagnostic.  Note: this
    1431             :    function is used to enforce the requirements in C++11 8.3.6 about
    1432             :    no default arguments in redeclarations.  */
    1433             : 
    1434             : static void
    1435     7730150 : check_redeclaration_no_default_args (tree decl)
    1436             : {
    1437     7730150 :   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
    1438             : 
    1439     7730150 :   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
    1440    22915500 :        t && t != void_list_node; t = TREE_CHAIN (t))
    1441    15185422 :     if (TREE_PURPOSE (t))
    1442             :       {
    1443          72 :         permerror (DECL_SOURCE_LOCATION (decl),
    1444             :                    "redeclaration of %q#D may not have default "
    1445             :                    "arguments", decl);
    1446          72 :         return;
    1447             :       }
    1448             : }
    1449             : 
    1450             : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
    1451             :    in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
    1452             :    the TEMPLATE_DECLs in case of function templates).  This function is used
    1453             :    to enforce the final part of C++17 11.3.6/4, about a single declaration:
    1454             :    "If a friend declaration specifies a default argument expression, that
    1455             :    declaration shall be a definition and shall be the only declaration of
    1456             :    the function or function template in the translation unit."  */
    1457             : 
    1458             : static void
    1459     3459105 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
    1460             : {
    1461     6731343 :   if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
    1462             :     return;
    1463             : 
    1464     1053428 :   for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
    1465      526714 :          t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    1466     1426853 :        t1 && t1 != void_list_node;
    1467      900139 :        t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1468     1262570 :     if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
    1469     2386960 :         || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
    1470             :       {
    1471          28 :         auto_diagnostic_group d;
    1472          28 :         if (permerror (DECL_SOURCE_LOCATION (newdecl),
    1473             :                        "friend declaration of %q#D specifies default "
    1474             :                        "arguments and isn%'t the only declaration", newdecl))
    1475          28 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1476             :                   "previous declaration of %q#D", olddecl);
    1477          28 :         return;
    1478          28 :       }
    1479             : }
    1480             : 
    1481             : /* Merge tree bits that correspond to attributes noreturn, nothrow,
    1482             :    const,  malloc, and pure from NEWDECL with those of OLDDECL.  */
    1483             : 
    1484             : static void
    1485    11616946 : merge_attribute_bits (tree newdecl, tree olddecl)
    1486             : {
    1487    11616946 :   TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
    1488    11616946 :   TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
    1489    11616946 :   TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
    1490    11616946 :   TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
    1491    11616946 :   TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
    1492    11616946 :   TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
    1493    11616946 :   DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
    1494    11616946 :   DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
    1495    11616946 :   DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
    1496    11616946 :   DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
    1497    11616946 :   DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
    1498    11616946 :   DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
    1499    11616946 : }
    1500             : 
    1501             : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn)                   \
    1502             :                           && lookup_attribute ("gnu_inline",          \
    1503             :                                                DECL_ATTRIBUTES (fn)))
    1504             : 
    1505             : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
    1506             :    ambiguates olddecl.  Returns true if an error occurs.  */
    1507             : 
    1508             : static bool
    1509   145795802 : duplicate_function_template_decls (tree newdecl, tree olddecl)
    1510             : {
    1511             : 
    1512   145795802 :   tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1513   145795802 :   tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1514             :   /* Function template declarations can be differentiated by parameter
    1515             :      and return type.  */
    1516   145795802 :   if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
    1517   145795802 :                  TYPE_ARG_TYPES (TREE_TYPE (newres)))
    1518   145795802 :        && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
    1519             :                        TREE_TYPE (TREE_TYPE (olddecl))))
    1520             :     {
    1521             :       /* ... and also by their template-heads and requires-clauses.  */
    1522         392 :       if (template_heads_equivalent_p (newdecl, olddecl)
    1523         392 :           && function_requirements_equivalent_p (newres, oldres))
    1524             :         {
    1525           0 :           error ("ambiguating new declaration %q+#D", newdecl);
    1526           0 :           inform (DECL_SOURCE_LOCATION (olddecl),
    1527             :                   "old declaration %q#D", olddecl);
    1528           0 :           return true;
    1529             :         }
    1530             : 
    1531             :       /* FIXME: The types are the same but the are differences
    1532             :          in either the template heads or function requirements.
    1533             :          We should be able to diagnose a set of common errors
    1534             :          stemming from these declarations. For example:
    1535             : 
    1536             :            template<typename T> requires C void f(...);
    1537             :            template<typename T> void f(...) requires C;
    1538             : 
    1539             :          These are functionally equivalent but not equivalent.  */
    1540             :     }
    1541             : 
    1542             :   return false;
    1543             : }
    1544             : 
    1545             : /* OLD_PARMS is the innermost set of template parameters for some template
    1546             :    declaration, and NEW_PARMS is the corresponding set of template parameters
    1547             :    for a redeclaration of that template.  Merge the default arguments within
    1548             :    these two sets of parameters.  CLASS_P is true iff the template in
    1549             :    question is a class template.  */
    1550             : 
    1551             : bool
    1552     5245048 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
    1553             : {
    1554     5245048 :   gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
    1555             :                        == TREE_VEC_LENGTH (old_parms));
    1556    14750250 :   for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
    1557             :     {
    1558     9505215 :       tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
    1559     9505215 :       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
    1560     9505215 :       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
    1561     9505215 :       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
    1562     9505215 :       if (error_operand_p (new_parm) || error_operand_p (old_parm))
    1563             :         return false;
    1564     9505212 :       if (new_default != NULL_TREE && old_default != NULL_TREE)
    1565             :         {
    1566          10 :           auto_diagnostic_group d;
    1567          10 :           error ("redefinition of default argument for %q+#D", new_parm);
    1568          10 :           inform (DECL_SOURCE_LOCATION (old_parm),
    1569             :                   "original definition appeared here");
    1570          10 :           return false;
    1571          10 :         }
    1572     9505202 :       else if (new_default != NULL_TREE)
    1573             :         /* Update the previous template parameters (which are the ones
    1574             :            that will really count) with the new default value.  */
    1575      106984 :         old_default = new_default;
    1576     9398218 :       else if (class_p && old_default != NULL_TREE)
    1577             :         /* Update the new parameters, too; they'll be used as the
    1578             :            parameters for any members.  */
    1579      654060 :         new_default = old_default;
    1580             :     }
    1581             :   return true;
    1582             : }
    1583             : 
    1584             : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
    1585             :    If the redeclaration is invalid, a diagnostic is issued, and the
    1586             :    error_mark_node is returned.  Otherwise, OLDDECL is returned.
    1587             : 
    1588             :    If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
    1589             :    returned.
    1590             : 
    1591             :    HIDING is true if the new decl is being hidden.  WAS_HIDDEN is true
    1592             :    if the old decl was hidden.
    1593             : 
    1594             :    Hidden decls can be anticipated builtins, injected friends, or
    1595             :    (coming soon) injected from a local-extern decl.   */
    1596             : 
    1597             : tree
    1598   236185212 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
    1599             : {
    1600   236185212 :   unsigned olddecl_uid = DECL_UID (olddecl);
    1601   236185212 :   int types_match = 0;
    1602   236185212 :   int new_defines_function = 0;
    1603   236185212 :   tree new_template_info;
    1604   236185212 :   location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
    1605   236185212 :   location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
    1606             : 
    1607   236185212 :   if (newdecl == olddecl)
    1608             :     return olddecl;
    1609             : 
    1610   235583839 :   types_match = decls_match (newdecl, olddecl);
    1611             : 
    1612             :   /* If either the type of the new decl or the type of the old decl is an
    1613             :      error_mark_node, then that implies that we have already issued an
    1614             :      error (earlier) for some bogus type specification, and in that case,
    1615             :      it is rather pointless to harass the user with yet more error message
    1616             :      about the same declaration, so just pretend the types match here.  */
    1617   235583839 :   if (TREE_TYPE (newdecl) == error_mark_node
    1618   235583839 :       || TREE_TYPE (olddecl) == error_mark_node)
    1619             :     return error_mark_node;
    1620             : 
    1621             :   /* Check for redeclaration and other discrepancies.  */
    1622   235583810 :   if (TREE_CODE (olddecl) == FUNCTION_DECL
    1623   235583810 :       && DECL_IS_UNDECLARED_BUILTIN (olddecl))
    1624             :     {
    1625     4496422 :       if (TREE_CODE (newdecl) != FUNCTION_DECL)
    1626             :         {
    1627             :           /* Avoid warnings redeclaring built-ins which have not been
    1628             :              explicitly declared.  */
    1629      134479 :           if (was_hidden)
    1630             :             {
    1631      134445 :               if (TREE_PUBLIC (newdecl)
    1632      134445 :                   && CP_DECL_CONTEXT (newdecl) == global_namespace)
    1633          16 :                 warning_at (newdecl_loc,
    1634             :                             OPT_Wbuiltin_declaration_mismatch,
    1635             :                             "built-in function %qD declared as non-function",
    1636             :                             newdecl);
    1637      134445 :               return NULL_TREE;
    1638             :             }
    1639             : 
    1640             :           /* If you declare a built-in or predefined function name as static,
    1641             :              the old definition is overridden, but optionally warn this was a
    1642             :              bad choice of name.  */
    1643          34 :           if (! TREE_PUBLIC (newdecl))
    1644             :             {
    1645          34 :               warning_at (newdecl_loc,
    1646             :                           OPT_Wshadow, 
    1647          34 :                           fndecl_built_in_p (olddecl)
    1648             :                           ? G_("shadowing built-in function %q#D")
    1649             :                           : G_("shadowing library function %q#D"), olddecl);
    1650             :               /* Discard the old built-in function.  */
    1651          34 :               return NULL_TREE;
    1652             :             }
    1653             :           /* If the built-in is not ansi, then programs can override
    1654             :              it even globally without an error.  */
    1655           0 :           else if (! fndecl_built_in_p (olddecl))
    1656           0 :             warning_at (newdecl_loc, 0,
    1657             :                         "library function %q#D redeclared as non-function %q#D",
    1658             :                         olddecl, newdecl);
    1659             :           else
    1660           0 :             error_at (newdecl_loc,
    1661             :                       "declaration of %q#D conflicts with built-in "
    1662             :                       "declaration %q#D", newdecl, olddecl);
    1663           0 :           return NULL_TREE;
    1664             :         }
    1665     4361943 :       else if (!types_match)
    1666             :         {
    1667             :           /* Avoid warnings redeclaring built-ins which have not been
    1668             :              explicitly declared.  */
    1669     1652164 :           if (was_hidden)
    1670             :             {
    1671      592251 :               tree t1, t2;
    1672             : 
    1673             :               /* A new declaration doesn't match a built-in one unless it
    1674             :                  is also extern "C".  */
    1675      592251 :               gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
    1676      592251 :               gcc_assert (DECL_EXTERN_C_P (olddecl));
    1677      592251 :               if (!DECL_EXTERN_C_P (newdecl))
    1678             :                 return NULL_TREE;
    1679             : 
    1680      105594 :               for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1681      105594 :                    t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1682      182303 :                    t1 || t2;
    1683       76709 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
    1684             :                 {
    1685      182279 :                   if (!t1 || !t2)
    1686             :                     break;
    1687             :                   /* FILE, tm types are not known at the time
    1688             :                      we create the builtins.  */
    1689      564296 :                   for (unsigned i = 0;
    1690      746359 :                        i < sizeof (builtin_structptr_types)
    1691             :                            / sizeof (builtin_structptr_type);
    1692             :                        ++i)
    1693      669643 :                     if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
    1694             :                       {
    1695      105347 :                         tree t = TREE_VALUE (t1);
    1696             : 
    1697      105347 :                         if (TYPE_PTR_P (t)
    1698      210694 :                             && TYPE_IDENTIFIER (TREE_TYPE (t))
    1699      105347 :                             == get_identifier (builtin_structptr_types[i].str)
    1700      210674 :                             && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
    1701             :                           {
    1702      105327 :                             tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
    1703             : 
    1704      105327 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl))
    1705      105327 :                               = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
    1706      105327 :                             types_match = decls_match (newdecl, olddecl);
    1707      105327 :                             if (types_match)
    1708      105327 :                               return duplicate_decls (newdecl, olddecl,
    1709      105327 :                                                       hiding, was_hidden);
    1710           0 :                             TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
    1711             :                           }
    1712          20 :                         goto next_arg;
    1713             :                       }
    1714             : 
    1715       76716 :                   if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
    1716             :                     break;
    1717       76709 :                 next_arg:;
    1718             :                 }
    1719             : 
    1720         267 :               warning_at (newdecl_loc,
    1721             :                           OPT_Wbuiltin_declaration_mismatch,
    1722             :                           "declaration of %q#D conflicts with built-in "
    1723             :                           "declaration %q#D", newdecl, olddecl);
    1724             :             }
    1725     1059913 :           else if ((DECL_EXTERN_C_P (newdecl)
    1726          20 :                     && DECL_EXTERN_C_P (olddecl))
    1727     2119806 :                    || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1728     1059893 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
    1729             :             {
    1730             :               /* Don't really override olddecl for __* prefixed builtins
    1731             :                  except for __[^b]*_chk, the compiler might be using those
    1732             :                  explicitly.  */
    1733          28 :               if (fndecl_built_in_p (olddecl))
    1734             :                 {
    1735          20 :                   tree id = DECL_NAME (olddecl);
    1736          20 :                   const char *name = IDENTIFIER_POINTER (id);
    1737          20 :                   size_t len;
    1738             : 
    1739          20 :                   if (name[0] == '_'
    1740          20 :                       && name[1] == '_'
    1741          40 :                       && (startswith (name + 2, "builtin_")
    1742           8 :                           || (len = strlen (name)) <= strlen ("___chk")
    1743           8 :                           || memcmp (name + len - strlen ("_chk"),
    1744             :                                      "_chk", strlen ("_chk") + 1) != 0))
    1745             :                     {
    1746          20 :                       if (DECL_INITIAL (newdecl))
    1747             :                         {
    1748           8 :                           error_at (newdecl_loc,
    1749             :                                     "definition of %q#D ambiguates built-in "
    1750             :                                     "declaration %q#D", newdecl, olddecl);
    1751           8 :                           return error_mark_node;
    1752             :                         }
    1753          12 :                       auto_diagnostic_group d;
    1754          12 :                       if (permerror (newdecl_loc,
    1755             :                                      "new declaration %q#D ambiguates built-in"
    1756             :                                      " declaration %q#D", newdecl, olddecl)
    1757          12 :                           && flag_permissive)
    1758           4 :                         inform (newdecl_loc,
    1759             :                                 "ignoring the %q#D declaration", newdecl);
    1760          12 :                       return flag_permissive ? olddecl : error_mark_node;
    1761          12 :                     }
    1762             :                 }
    1763             : 
    1764             :               /* A near match; override the builtin.  */
    1765             : 
    1766           8 :               if (TREE_PUBLIC (newdecl))
    1767           8 :                 warning_at (newdecl_loc,
    1768             :                             OPT_Wbuiltin_declaration_mismatch,
    1769             :                             "new declaration %q#D ambiguates built-in "
    1770             :                             "declaration %q#D", newdecl, olddecl);
    1771             :               else
    1772           0 :                 warning (OPT_Wshadow, 
    1773             :                          fndecl_built_in_p (olddecl)
    1774             :                          ? G_("shadowing built-in function %q#D")
    1775             :                          : G_("shadowing library function %q#D"), olddecl);
    1776             :             }
    1777             :           else
    1778             :             /* Discard the old built-in function.  */
    1779             :             return NULL_TREE;
    1780             : 
    1781             :           /* Replace the old RTL to avoid problems with inlining.  */
    1782         275 :           COPY_DECL_RTL (newdecl, olddecl);
    1783             :         }
    1784             :       else 
    1785             :         {
    1786             :           /* Even if the types match, prefer the new declarations type
    1787             :              for built-ins which have not been explicitly declared,
    1788             :              for exception lists, etc...  */
    1789     2709779 :           tree type = TREE_TYPE (newdecl);
    1790     2709779 :           tree attribs = (*targetm.merge_type_attributes)
    1791     2709779 :             (TREE_TYPE (olddecl), type);
    1792             : 
    1793     2709779 :           type = cp_build_type_attribute_variant (type, attribs);
    1794     2709779 :           TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
    1795             :         }
    1796             : 
    1797             :       /* If a function is explicitly declared "throw ()", propagate that to
    1798             :          the corresponding builtin.  */
    1799     2710054 :       if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
    1800     2592554 :           && was_hidden
    1801     2592511 :           && TREE_NOTHROW (newdecl)
    1802     5108071 :           && !TREE_NOTHROW (olddecl))
    1803             :         {
    1804       20365 :           enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
    1805       20365 :           tree tmpdecl = builtin_decl_explicit (fncode);
    1806       20365 :           if (tmpdecl && tmpdecl != olddecl && types_match)
    1807       20365 :             TREE_NOTHROW (tmpdecl)  = 1;
    1808             :         }
    1809             : 
    1810             :       /* Whether or not the builtin can throw exceptions has no
    1811             :          bearing on this declarator.  */
    1812     2710054 :       TREE_NOTHROW (olddecl) = 0;
    1813             : 
    1814     2710054 :       if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
    1815             :         {
    1816             :           /* If a builtin function is redeclared as `static', merge
    1817             :              the declarations, but make the original one static.  */
    1818           3 :           DECL_THIS_STATIC (olddecl) = 1;
    1819           3 :           TREE_PUBLIC (olddecl) = 0;
    1820             : 
    1821             :           /* Make the old declaration consistent with the new one so
    1822             :              that all remnants of the builtin-ness of this function
    1823             :              will be banished.  */
    1824           3 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    1825           3 :           COPY_DECL_RTL (newdecl, olddecl);
    1826             :         }
    1827             :     }
    1828   231087388 :   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
    1829             :     {
    1830             :       /* C++ Standard, 3.3, clause 4:
    1831             :          "[Note: a namespace name or a class template name must be unique
    1832             :          in its declarative region (7.3.2, clause 14). ]"  */
    1833    57400829 :       if (TREE_CODE (olddecl) == NAMESPACE_DECL
    1834    57400802 :           || TREE_CODE (newdecl) == NAMESPACE_DECL)
    1835             :         /* Namespace conflicts with not namespace.  */;
    1836    34865523 :       else if (DECL_TYPE_TEMPLATE_P (olddecl)
    1837    92266309 :                || DECL_TYPE_TEMPLATE_P (newdecl))
    1838             :         /* Class template conflicts.  */;
    1839    57400778 :       else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
    1840    34865523 :                 && DECL_TEMPLATE_RESULT (olddecl)
    1841    34865523 :                 && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
    1842    92266295 :                || (TREE_CODE (newdecl) == TEMPLATE_DECL
    1843    22505216 :                    && DECL_TEMPLATE_RESULT (newdecl)
    1844    22505216 :                    && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
    1845             :         /* Variable template conflicts.  */;
    1846    57400769 :       else if (concept_definition_p (olddecl)
    1847    57400769 :                || concept_definition_p (newdecl))
    1848             :         /* Concept conflicts.  */;
    1849    57400765 :       else if ((TREE_CODE (newdecl) == FUNCTION_DECL
    1850    34895153 :                 && DECL_FUNCTION_TEMPLATE_P (olddecl))
    1851    57430403 :                || (TREE_CODE (olddecl) == FUNCTION_DECL
    1852    22505227 :                    && DECL_FUNCTION_TEMPLATE_P (newdecl)))
    1853             :         {
    1854             :           /* One is a function and the other is a template
    1855             :              function.  */
    1856    57370706 :           if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
    1857             :             return NULL_TREE;
    1858             : 
    1859             :           /* There can only be one!  */
    1860       42768 :           if (TREE_CODE (newdecl) == TEMPLATE_DECL
    1861       42768 :               && check_raw_literal_operator (olddecl))
    1862           3 :             error_at (newdecl_loc,
    1863             :                       "literal operator %q#D conflicts with"
    1864             :                       " raw literal operator", newdecl);
    1865       42765 :           else if (check_raw_literal_operator (newdecl))
    1866           3 :             error_at (newdecl_loc,
    1867             :                       "raw literal operator %q#D conflicts with"
    1868             :                       " literal operator template", newdecl);
    1869             :           else
    1870             :             return NULL_TREE;
    1871             : 
    1872           6 :           inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1873           6 :           return error_mark_node;
    1874             :         }
    1875         207 :       else if ((VAR_P (olddecl) && DECL_DECOMPOSITION_P (olddecl))
    1876       30264 :                || (VAR_P (newdecl) && DECL_DECOMPOSITION_P (newdecl)))
    1877             :         /* A structured binding must be unique in its declarative region.  */;
    1878       29810 :       else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    1879       30058 :                || DECL_IMPLICIT_TYPEDEF_P (newdecl))
    1880             :         /* One is an implicit typedef, that's ok.  */
    1881             :         return NULL_TREE;
    1882             : 
    1883         133 :       error ("%q#D redeclared as different kind of entity", newdecl);
    1884         133 :       inform (olddecl_loc, "previous declaration %q#D", olddecl);
    1885             : 
    1886         133 :       return error_mark_node;
    1887             :     }
    1888   173686559 :   else if (!types_match)
    1889             :     {
    1890   164060762 :       if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
    1891             :         /* These are certainly not duplicate declarations; they're
    1892             :            from different scopes.  */
    1893             :         return NULL_TREE;
    1894             : 
    1895   164060718 :       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    1896             :         {
    1897   145795814 :           tree oldres = DECL_TEMPLATE_RESULT (olddecl);
    1898   145795814 :           tree newres = DECL_TEMPLATE_RESULT (newdecl);
    1899             : 
    1900             :           /* The name of a class template may not be declared to refer to
    1901             :              any other template, class, function, object, namespace, value,
    1902             :              or type in the same scope.  */
    1903   145795814 :           if (TREE_CODE (oldres) == TYPE_DECL
    1904   145795811 :               || TREE_CODE (newres) == TYPE_DECL)
    1905             :             {
    1906           7 :               error_at (newdecl_loc,
    1907             :                         "conflicting declaration of template %q#D", newdecl);
    1908           7 :               inform (olddecl_loc,
    1909             :                       "previous declaration %q#D", olddecl);
    1910           7 :               return error_mark_node;
    1911             :             }
    1912             : 
    1913   145795807 :           else if (TREE_CODE (oldres) == FUNCTION_DECL
    1914   145795802 :                    && TREE_CODE (newres) == FUNCTION_DECL)
    1915             :             {
    1916   145795802 :               if (duplicate_function_template_decls (newdecl, olddecl))
    1917           0 :                 return error_mark_node;
    1918             :               return NULL_TREE;
    1919             :             }
    1920           5 :           else if (check_concept_refinement (olddecl, newdecl))
    1921           0 :             return error_mark_node;
    1922             :           return NULL_TREE;
    1923             :         }
    1924    18264904 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    1925             :         {
    1926    18264771 :           if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
    1927             :             {
    1928          68 :               error_at (newdecl_loc,
    1929             :                         "conflicting declaration of C function %q#D",
    1930             :                         newdecl);
    1931          68 :               inform (olddecl_loc,
    1932             :                       "previous declaration %q#D", olddecl);
    1933          68 :               return error_mark_node;
    1934             :             }
    1935             :           /* For function versions, params and types match, but they
    1936             :              are not ambiguous.  */
    1937    18264703 :           else if ((!DECL_FUNCTION_VERSIONED (newdecl)
    1938    18254371 :                     && !DECL_FUNCTION_VERSIONED (olddecl))
    1939             :                    // The functions have the same parameter types.
    1940    18254371 :                    && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
    1941    18254371 :                                  TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
    1942             :                    // And the same constraints.
    1943    18264759 :                    && equivalently_constrained (newdecl, olddecl))
    1944             :             {
    1945          55 :               error_at (newdecl_loc,
    1946             :                         "ambiguating new declaration of %q#D", newdecl);
    1947          55 :               inform (olddecl_loc,
    1948             :                       "old declaration %q#D", olddecl);
    1949          55 :               return error_mark_node;
    1950             :             }
    1951             :           else
    1952    18264648 :             return NULL_TREE;
    1953             :         }
    1954             :       else
    1955             :         {
    1956         133 :           error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
    1957         133 :           inform (olddecl_loc,
    1958             :                   "previous declaration as %q#D", olddecl);
    1959         133 :           return error_mark_node;
    1960             :         }
    1961             :     }
    1962     9625797 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    1963     9625797 :            && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
    1964             :     {
    1965             :       /* OMP UDRs are never duplicates. */
    1966          36 :       gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
    1967          36 :       error_at (newdecl_loc,
    1968             :                 "redeclaration of %<pragma omp declare reduction%>");
    1969          36 :       inform (olddecl_loc,
    1970             :               "previous %<pragma omp declare reduction%> declaration");
    1971          36 :       return error_mark_node;
    1972             :     }
    1973     9625761 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    1974     9625761 :             && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
    1975         232 :                  && (!DECL_TEMPLATE_INFO (newdecl)
    1976         232 :                      || (DECL_TI_TEMPLATE (newdecl)
    1977         232 :                          != DECL_TI_TEMPLATE (olddecl))))
    1978     6999972 :                 || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
    1979      408102 :                     && (!DECL_TEMPLATE_INFO (olddecl)
    1980      408102 :                         || (DECL_TI_TEMPLATE (olddecl)
    1981      408102 :                             != DECL_TI_TEMPLATE (newdecl))))))
    1982             :     /* It's OK to have a template specialization and a non-template
    1983             :        with the same type, or to have specializations of two
    1984             :        different templates with the same type.  Note that if one is a
    1985             :        specialization, and the other is an instantiation of the same
    1986             :        template, that we do not exit at this point.  That situation
    1987             :        can occur if we instantiate a template class, and then
    1988             :        specialize one of its methods.  This situation is valid, but
    1989             :        the declarations must be merged in the usual way.  */
    1990             :     return NULL_TREE;
    1991     9625761 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL
    1992     9625761 :            && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
    1993      407941 :                 && !DECL_USE_TEMPLATE (newdecl))
    1994     6999972 :                || (DECL_TEMPLATE_INSTANTIATION (newdecl)
    1995          71 :                    && !DECL_USE_TEMPLATE (olddecl))))
    1996             :     /* One of the declarations is a template instantiation, and the
    1997             :        other is not a template at all.  That's OK.  */
    1998             :     return NULL_TREE;
    1999     9625761 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2000             :     {
    2001             :       /* In [namespace.alias] we have:
    2002             : 
    2003             :            In a declarative region, a namespace-alias-definition can be
    2004             :            used to redefine a namespace-alias declared in that declarative
    2005             :            region to refer only to the namespace to which it already
    2006             :            refers.
    2007             : 
    2008             :          Therefore, if we encounter a second alias directive for the same
    2009             :          alias, we can just ignore the second directive.  */
    2010          24 :       if (DECL_NAMESPACE_ALIAS (newdecl)
    2011          24 :           && (DECL_NAMESPACE_ALIAS (newdecl)
    2012          20 :               == DECL_NAMESPACE_ALIAS (olddecl)))
    2013             :         return olddecl;
    2014             : 
    2015             :       /* Leave it to update_binding to merge or report error.  */
    2016             :       return NULL_TREE;
    2017             :     }
    2018             :   else
    2019             :     {
    2020     9625737 :       const char *errmsg = redeclaration_error_message (newdecl, olddecl);
    2021     9625737 :       if (errmsg)
    2022             :         {
    2023         527 :           auto_diagnostic_group d;
    2024         527 :           error_at (newdecl_loc, errmsg, newdecl);
    2025         527 :           if (DECL_NAME (olddecl) != NULL_TREE)
    2026         527 :             inform (olddecl_loc,
    2027         527 :                     (DECL_INITIAL (olddecl) && namespace_bindings_p ())
    2028             :                     ? G_("%q#D previously defined here")
    2029             :                     : G_("%q#D previously declared here"), olddecl);
    2030         527 :           return error_mark_node;
    2031         527 :         }
    2032     9625210 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL
    2033     6999682 :                && DECL_INITIAL (olddecl) != NULL_TREE
    2034        9492 :                && !prototype_p (TREE_TYPE (olddecl))
    2035     9625210 :                && prototype_p (TREE_TYPE (newdecl)))
    2036             :         {
    2037             :           /* Prototype decl follows defn w/o prototype.  */
    2038           0 :           auto_diagnostic_group d;
    2039           0 :           if (warning_at (newdecl_loc, 0,
    2040             :                           "prototype specified for %q#D", newdecl))
    2041           0 :             inform (olddecl_loc,
    2042             :                     "previous non-prototype definition here");
    2043           0 :         }
    2044     9350681 :       else if (VAR_OR_FUNCTION_DECL_P (olddecl)
    2045    16624892 :                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
    2046             :         {
    2047             :           /* [dcl.link]
    2048             :              If two declarations of the same function or object
    2049             :              specify different linkage-specifications ..., the program
    2050             :              is ill-formed.... Except for functions with C++ linkage,
    2051             :              a function declaration without a linkage specification
    2052             :              shall not precede the first linkage specification for
    2053             :              that function.  A function can be declared without a
    2054             :              linkage specification after an explicit linkage
    2055             :              specification has been seen; the linkage explicitly
    2056             :              specified in the earlier declaration is not affected by
    2057             :              such a function declaration.
    2058             : 
    2059             :              DR 563 raises the question why the restrictions on
    2060             :              functions should not also apply to objects.  Older
    2061             :              versions of G++ silently ignore the linkage-specification
    2062             :              for this example:
    2063             : 
    2064             :                namespace N { 
    2065             :                  extern int i;
    2066             :                  extern "C" int i;
    2067             :                }
    2068             : 
    2069             :              which is clearly wrong.  Therefore, we now treat objects
    2070             :              like functions.  */
    2071        1557 :           if (current_lang_depth () == 0)
    2072             :             {
    2073             :               /* There is no explicit linkage-specification, so we use
    2074             :                  the linkage from the previous declaration.  */
    2075        1549 :               retrofit_lang_decl (newdecl);
    2076        1549 :               SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2077             :             }
    2078             :           else
    2079             :             {
    2080           8 :               auto_diagnostic_group d;
    2081           8 :               error_at (newdecl_loc,
    2082             :                         "conflicting declaration of %q#D with %qL linkage",
    2083           8 :                         newdecl, DECL_LANGUAGE (newdecl));
    2084           8 :               inform (olddecl_loc,
    2085             :                       "previous declaration with %qL linkage",
    2086           8 :                       DECL_LANGUAGE (olddecl));
    2087           8 :             }
    2088             :         }
    2089             : 
    2090     9625210 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
    2091             :         ;
    2092     9202524 :       else if (TREE_CODE (olddecl) == FUNCTION_DECL)
    2093             :         {
    2094             :           /* Note: free functions, as TEMPLATE_DECLs, are handled below.  */
    2095     7456720 :           if (DECL_FUNCTION_MEMBER_P (olddecl)
    2096     6591519 :               && (/* grokfndecl passes member function templates too
    2097             :                      as FUNCTION_DECLs.  */
    2098     5833696 :                   DECL_TEMPLATE_INFO (olddecl)
    2099             :                   /* C++11 8.3.6/6.
    2100             :                      Default arguments for a member function of a class
    2101             :                      template shall be specified on the initial declaration
    2102             :                      of the member function within the class template.  */
    2103      462182 :                   || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
    2104             :             {
    2105     5431282 :               check_redeclaration_no_default_args (newdecl);
    2106             : 
    2107     5431282 :               if (DECL_TEMPLATE_INFO (olddecl)
    2108     5431282 :                   && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
    2109             :                 {
    2110     1480573 :                   tree new_parms = DECL_TEMPLATE_INFO (newdecl)
    2111     1480573 :                     ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
    2112     1480573 :                     : INNERMOST_TEMPLATE_PARMS (current_template_parms);
    2113     1480573 :                   tree old_parms
    2114     1480573 :                     = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
    2115     1480573 :                   merge_default_template_args (new_parms, old_parms,
    2116             :                                                /*class_p=*/false);
    2117             :                 }
    2118             :             }
    2119             :           else
    2120             :             {
    2121     1160237 :               tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
    2122     1160237 :               tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
    2123     1160237 :               int i = 1;
    2124             : 
    2125     2732421 :               for (; t1 && t1 != void_list_node;
    2126     1572184 :                    t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
    2127     1573039 :                 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
    2128             :                   {
    2129          52 :                     if (simple_cst_equal (TREE_PURPOSE (t1),
    2130          52 :                                           TREE_PURPOSE (t2)) == 1)
    2131             :                       {
    2132          16 :                         auto_diagnostic_group d;
    2133          16 :                         if (permerror (newdecl_loc,
    2134             :                                        "default argument given for parameter "
    2135             :                                        "%d of %q#D", i, newdecl))
    2136          16 :                           inform (olddecl_loc,
    2137             :                                   "previous specification in %q#D here",
    2138             :                                   olddecl);
    2139          16 :                       }
    2140             :                     else
    2141             :                       {
    2142          36 :                         auto_diagnostic_group d;
    2143          36 :                         error_at (newdecl_loc,
    2144             :                                   "default argument given for parameter %d "
    2145             :                                   "of %q#D", i, newdecl);
    2146          36 :                         inform (olddecl_loc,
    2147             :                                 "previous specification in %q#D here",
    2148             :                                 olddecl);
    2149          36 :                       }
    2150             :                   }
    2151             : 
    2152             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2153             :                  argument expression, that declaration... shall be the only
    2154             :                  declaration of the function or function template in the
    2155             :                  translation unit."  */
    2156     1160237 :               check_no_redeclaration_friend_default_args (olddecl, newdecl);
    2157             :             }
    2158             :         }
    2159             :     }
    2160             : 
    2161             :   /* Do not merge an implicit typedef with an explicit one.  In:
    2162             : 
    2163             :        class A;
    2164             :        ...
    2165             :        typedef class A A __attribute__ ((foo));
    2166             : 
    2167             :      the attribute should apply only to the typedef.  */
    2168    12335264 :   if (TREE_CODE (olddecl) == TYPE_DECL
    2169    12335264 :       && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
    2170        6554 :           || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
    2171             :     return NULL_TREE;
    2172             : 
    2173    12306204 :   if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
    2174             :     return NULL_TREE;
    2175             : 
    2176    12306190 :   if (!validate_constexpr_redeclaration (olddecl, newdecl))
    2177          10 :     return error_mark_node;
    2178             : 
    2179    12306180 :   if (modules_p ()
    2180       52232 :       && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
    2181       28204 :       && TREE_CODE (olddecl) != NAMESPACE_DECL
    2182    12334384 :       && !hiding)
    2183             :     {
    2184       25675 :       if (!module_may_redeclare (olddecl))
    2185             :         {
    2186           6 :           if (DECL_ARTIFICIAL (olddecl))
    2187           0 :             error ("declaration %qD conflicts with builtin", newdecl);
    2188             :           else
    2189             :             {
    2190           6 :               error ("declaration %qD conflicts with import", newdecl);
    2191           6 :               inform (olddecl_loc, "import declared %q#D here", olddecl);
    2192             :             }
    2193             : 
    2194           6 :           return error_mark_node;
    2195             :         }
    2196             : 
    2197       25669 :       tree not_tmpl = STRIP_TEMPLATE (olddecl);
    2198       51312 :       if (DECL_LANG_SPECIFIC (not_tmpl) && DECL_MODULE_ATTACH_P (not_tmpl))
    2199             :         {
    2200         165 :           if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl))
    2201         165 :               && !DECL_MODULE_EXPORT_P (not_tmpl))
    2202             :             {
    2203          15 :               error ("conflicting exporting declaration %qD", newdecl);
    2204          15 :               inform (olddecl_loc, "previous declaration %q#D here", olddecl);
    2205             :             }
    2206             :         }
    2207       25504 :       else if (DECL_MODULE_EXPORT_P (newdecl))
    2208       12709 :         DECL_MODULE_EXPORT_P (not_tmpl) = true;
    2209             :     }
    2210             : 
    2211             :   /* We have committed to returning OLDDECL at this point.  */
    2212             : 
    2213             :   /* If new decl is `static' and an `extern' was seen previously,
    2214             :      warn about it.  */
    2215    12306174 :   warn_extern_redeclared_static (newdecl, olddecl);
    2216             : 
    2217             :   /* True to merge attributes between the declarations, false to
    2218             :      set OLDDECL's attributes to those of NEWDECL (for template
    2219             :      explicit specializations that specify their own attributes
    2220             :      independent of those specified for the primary template).  */
    2221    12306174 :   const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
    2222     9709720 :                            || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2223    12714260 :                            || DECL_TEMPLATE_SPECIALIZATION (olddecl));
    2224             : 
    2225    12306174 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2226             :     {
    2227     9709720 :       if (merge_attr)
    2228             :         {
    2229     9301850 :           if (diagnose_mismatched_attributes (olddecl, newdecl))
    2230          48 :             inform (olddecl_loc, DECL_INITIAL (olddecl)
    2231             :                     ? G_("previous definition of %qD here")
    2232             :                     : G_("previous declaration of %qD here"), olddecl);
    2233             : 
    2234             :           /* [dcl.attr.noreturn]: The first declaration of a function shall
    2235             :              specify the noreturn attribute if any declaration of that function
    2236             :              specifies the noreturn attribute.  */
    2237     9301850 :           tree a;
    2238     9301850 :           if (TREE_THIS_VOLATILE (newdecl)
    2239       58594 :               && !TREE_THIS_VOLATILE (olddecl)
    2240             :               /* This applies to [[noreturn]] only, not its GNU variants.  */
    2241          91 :               && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
    2242          62 :               && cxx11_attribute_p (a)
    2243     9301871 :               && get_attribute_namespace (a) == NULL_TREE)
    2244             :             {
    2245           9 :               error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
    2246             :                         "but its first declaration was not", newdecl);
    2247           9 :               inform (olddecl_loc, "previous declaration of %qD", olddecl);
    2248             :             }
    2249             :         }
    2250             : 
    2251             :       /* Now that functions must hold information normally held
    2252             :          by field decls, there is extra work to do so that
    2253             :          declaration information does not get destroyed during
    2254             :          definition.  */
    2255     9709720 :       if (DECL_VINDEX (olddecl))
    2256      114161 :         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
    2257     9709720 :       if (DECL_CONTEXT (olddecl))
    2258     9709720 :         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
    2259     9709720 :       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
    2260     9709720 :       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
    2261     9709720 :       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
    2262     9709720 :       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
    2263     9709720 :       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
    2264     9709720 :       DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
    2265     9709720 :       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
    2266     9709720 :       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
    2267     9709720 :       DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
    2268     9709720 :         |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
    2269     9709720 :       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
    2270     1710545 :         DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
    2271     3421090 :           = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
    2272     9709720 :       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
    2273             : 
    2274     9709720 :       duplicate_contracts (newdecl, olddecl);
    2275             : 
    2276             :       /* Optionally warn about more than one declaration for the same
    2277             :          name, but don't warn about a function declaration followed by a
    2278             :          definition.  */
    2279          36 :       if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
    2280          36 :           && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
    2281             :           /* Don't warn about extern decl followed by definition.  */
    2282          36 :           && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
    2283             :           /* Don't warn if at least one is/was hidden.  */
    2284          36 :           && !(hiding || was_hidden)
    2285             :           /* Don't warn about declaration followed by specialization.  */
    2286     9709736 :           && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2287          12 :               || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
    2288             :         {
    2289           8 :           auto_diagnostic_group d;
    2290           8 :           if (warning_at (newdecl_loc,
    2291             :                           OPT_Wredundant_decls,
    2292             :                           "redundant redeclaration of %qD in same scope",
    2293             :                           newdecl))
    2294           8 :             inform (olddecl_loc,
    2295             :                     "previous declaration of %qD", olddecl);
    2296           8 :         }
    2297             : 
    2298             :       /* [dcl.fct.def.delete] A deleted definition of a function shall be the
    2299             :          first declaration of the function or, for an explicit specialization
    2300             :          of a function template, the first declaration of that
    2301             :          specialization.  */
    2302     9709720 :       if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
    2303      407941 :             && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
    2304             :         {
    2305     9301850 :           if (DECL_DELETED_FN (newdecl))
    2306             :             {
    2307          21 :               auto_diagnostic_group d;
    2308          21 :               if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
    2309             :                            "is not first declaration", newdecl))
    2310          21 :                 inform (olddecl_loc,
    2311             :                         "previous declaration of %qD", olddecl);
    2312          21 :             }
    2313     9301850 :           DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
    2314             :         }
    2315             :     }
    2316             : 
    2317             :   /* Deal with C++: must preserve virtual function table size.  */
    2318    12306174 :   if (TREE_CODE (olddecl) == TYPE_DECL)
    2319             :     {
    2320        6551 :       tree newtype = TREE_TYPE (newdecl);
    2321        6551 :       tree oldtype = TREE_TYPE (olddecl);
    2322             : 
    2323        6551 :       if (newtype != error_mark_node && oldtype != error_mark_node
    2324       13102 :           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
    2325        2118 :         CLASSTYPE_FRIEND_CLASSES (newtype)
    2326         706 :           = CLASSTYPE_FRIEND_CLASSES (oldtype);
    2327             : 
    2328        6551 :       DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
    2329             :     }
    2330             : 
    2331             :   /* Copy all the DECL_... slots specified in the new decl except for
    2332             :      any that we copy here from the old type.  */
    2333    12306174 :   if (merge_attr)
    2334    11898304 :     DECL_ATTRIBUTES (newdecl)
    2335    23796608 :       = (*targetm.merge_decl_attributes) (olddecl, newdecl);
    2336             :   else
    2337      407870 :     DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    2338             : 
    2339    12306174 :   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    2340             :     {
    2341     2315374 :       tree old_result = DECL_TEMPLATE_RESULT (olddecl);
    2342     2315374 :       tree new_result = DECL_TEMPLATE_RESULT (newdecl);
    2343     2315374 :       TREE_TYPE (olddecl) = TREE_TYPE (old_result);
    2344             : 
    2345             :       /* The new decl should not already have gathered any
    2346             :          specializations.  */
    2347     2315374 :       gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
    2348             : 
    2349             :       /* Make sure the contracts are equivalent.  */
    2350     2315374 :       duplicate_contracts (newdecl, olddecl);
    2351             : 
    2352             :       /* Remove contracts from old_result so they aren't appended to
    2353             :          old_result by the merge function.  */
    2354     2315374 :       remove_contract_attributes (old_result);
    2355             : 
    2356     2315374 :       DECL_ATTRIBUTES (old_result)
    2357     2315374 :         = (*targetm.merge_decl_attributes) (old_result, new_result);
    2358             : 
    2359     2315374 :       if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2360             :         {
    2361     2315352 :           if (DECL_SOURCE_LOCATION (newdecl)
    2362     2315352 :               != DECL_SOURCE_LOCATION (olddecl))
    2363             :             {
    2364             :               /* Per C++11 8.3.6/4, default arguments cannot be added in
    2365             :                  later declarations of a function template.  */
    2366     2298868 :               check_redeclaration_no_default_args (newdecl);
    2367             :               /* C++17 11.3.6/4: "If a friend declaration specifies a default
    2368             :                  argument expression, that declaration... shall be the only
    2369             :                  declaration of the function or function template in the
    2370             :                  translation unit."  */
    2371     2298868 :               check_no_redeclaration_friend_default_args
    2372     2298868 :                 (old_result, new_result);
    2373             : 
    2374     2298868 :               tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
    2375     2298868 :               tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
    2376     2298868 :               merge_default_template_args (new_parms, old_parms,
    2377             :                                            /*class_p=*/false);
    2378             :             }
    2379     2315352 :           if (!DECL_UNIQUE_FRIEND_P (new_result))
    2380     1980278 :             DECL_UNIQUE_FRIEND_P (old_result) = false;
    2381             : 
    2382     2315352 :           check_default_args (newdecl);
    2383             : 
    2384     4630688 :           if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
    2385     2315352 :               && DECL_INITIAL (new_result))
    2386             :             {
    2387          32 :               if (DECL_INITIAL (old_result))
    2388          16 :                 DECL_UNINLINABLE (old_result) = 1;
    2389             :               else
    2390          16 :                 DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
    2391          32 :               DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
    2392          96 :               DECL_NOT_REALLY_EXTERN (old_result)
    2393          32 :                 = DECL_NOT_REALLY_EXTERN (new_result);
    2394          64 :               DECL_INTERFACE_KNOWN (old_result)
    2395          32 :                 = DECL_INTERFACE_KNOWN (new_result);
    2396          32 :               DECL_DECLARED_INLINE_P (old_result)
    2397          32 :                 = DECL_DECLARED_INLINE_P (new_result);
    2398          32 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2399          32 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2400             :             }
    2401             :           else
    2402             :             {
    2403     2315320 :               DECL_DECLARED_INLINE_P (old_result)
    2404     2315320 :                 |= DECL_DECLARED_INLINE_P (new_result);
    2405     2315320 :               DECL_DISREGARD_INLINE_LIMITS (old_result)
    2406     2315320 :                 |= DECL_DISREGARD_INLINE_LIMITS (new_result);
    2407     2315320 :               check_redeclaration_exception_specification (newdecl, olddecl);
    2408             : 
    2409     2315320 :               merge_attribute_bits (new_result, old_result);
    2410             :             }
    2411             :         }
    2412             : 
    2413             :       /* If the new declaration is a definition, update the file and
    2414             :          line information on the declaration, and also make
    2415             :          the old declaration the same definition.  */
    2416     2315374 :       if (DECL_INITIAL (new_result) != NULL_TREE)
    2417             :         {
    2418     3657534 :           DECL_SOURCE_LOCATION (olddecl)
    2419     3657534 :             = DECL_SOURCE_LOCATION (old_result)
    2420     1828767 :             = DECL_SOURCE_LOCATION (newdecl);
    2421     1828767 :           DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
    2422     1828767 :           if (DECL_FUNCTION_TEMPLATE_P (newdecl))
    2423             :             {
    2424     1828767 :               DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
    2425     6638631 :               for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
    2426     4809864 :                 DECL_CONTEXT (p) = old_result;
    2427             : 
    2428     3657534 :               if (tree fc = DECL_FRIEND_CONTEXT (new_result))
    2429          18 :                 SET_DECL_FRIEND_CONTEXT (old_result, fc);
    2430             :             }
    2431             :         }
    2432             : 
    2433     2315374 :       return olddecl;
    2434             :     }
    2435             : 
    2436     9990800 :   if (types_match)
    2437             :     {
    2438     9990525 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2439     9709445 :         check_redeclaration_exception_specification (newdecl, olddecl);
    2440             : 
    2441             :       /* Automatically handles default parameters.  */
    2442     9990525 :       tree oldtype = TREE_TYPE (olddecl);
    2443     9990525 :       tree newtype;
    2444             : 
    2445             :       /* For typedefs use the old type, as the new type's DECL_NAME points
    2446             :          at newdecl, which will be ggc_freed.  */
    2447     9990525 :       if (TREE_CODE (newdecl) == TYPE_DECL)
    2448             :         {
    2449             :           /* But NEWTYPE might have an attribute, honor that.  */
    2450        6551 :           tree tem = TREE_TYPE (newdecl);
    2451        6551 :           newtype = oldtype;
    2452             : 
    2453        6551 :           if (TYPE_USER_ALIGN (tem))
    2454             :             {
    2455          25 :               if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
    2456           6 :                 SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
    2457          25 :               TYPE_USER_ALIGN (newtype) = true;
    2458             :             }
    2459             : 
    2460             :           /* And remove the new type from the variants list.  */
    2461        6551 :           if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
    2462             :             {
    2463          29 :               tree remove = TREE_TYPE (newdecl);
    2464          29 :               if (TYPE_MAIN_VARIANT (remove) == remove)
    2465             :                 {
    2466          12 :                   gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
    2467             :                   /* If remove is the main variant, no need to remove that
    2468             :                      from the list.  One of the DECL_ORIGINAL_TYPE
    2469             :                      variants, e.g. created for aligned attribute, might still
    2470             :                      refer to the newdecl TYPE_DECL though, so remove that one
    2471             :                      in that case.  */
    2472          12 :                   if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
    2473           8 :                     if (orig != remove)
    2474           8 :                       for (tree t = TYPE_MAIN_VARIANT (orig); t;
    2475           0 :                            t = TYPE_MAIN_VARIANT (t))
    2476           8 :                         if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
    2477             :                           {
    2478          16 :                             TYPE_NEXT_VARIANT (t)
    2479           8 :                               = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
    2480           8 :                             break;
    2481             :                           }
    2482             :                 }           
    2483             :               else
    2484          17 :                 for (tree t = TYPE_MAIN_VARIANT (remove); ;
    2485           0 :                      t = TYPE_NEXT_VARIANT (t))
    2486          17 :                   if (TYPE_NEXT_VARIANT (t) == remove)
    2487             :                     {
    2488          17 :                       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
    2489          17 :                       break;
    2490             :                     }
    2491             :             }
    2492             :         }
    2493     9983974 :       else if (merge_attr)
    2494     9576104 :         newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
    2495             :       else
    2496      407870 :         newtype = TREE_TYPE (newdecl);
    2497             : 
    2498     9990525 :       if (VAR_P (newdecl))
    2499             :         {
    2500      274529 :           DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
    2501             :           /* For already initialized vars, TREE_READONLY could have been
    2502             :              cleared in cp_finish_decl, because the var needs runtime
    2503             :              initialization or destruction.  Make sure not to set
    2504             :              TREE_READONLY on it again.  */
    2505      274529 :           if (DECL_INITIALIZED_P (olddecl)
    2506        1213 :               && !DECL_EXTERNAL (olddecl)
    2507      274613 :               && !TREE_READONLY (olddecl))
    2508          37 :             TREE_READONLY (newdecl) = 0;
    2509      274529 :           DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
    2510      549058 :           DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
    2511      274529 :             |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
    2512      274529 :           if (DECL_DEPENDENT_INIT_P (olddecl))
    2513       78864 :             SET_DECL_DEPENDENT_INIT_P (newdecl, true);
    2514      549058 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
    2515      274529 :             |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
    2516      274529 :           DECL_DECLARED_CONSTEXPR_P (newdecl)
    2517      274529 :             |= DECL_DECLARED_CONSTEXPR_P (olddecl);
    2518      549058 :           DECL_DECLARED_CONSTINIT_P (newdecl)
    2519      274529 :             |= DECL_DECLARED_CONSTINIT_P (olddecl);
    2520             : 
    2521             :           /* Merge the threadprivate attribute from OLDDECL into NEWDECL.  */
    2522      274529 :           if (DECL_LANG_SPECIFIC (olddecl)
    2523      545520 :               && CP_DECL_THREADPRIVATE_P (olddecl))
    2524             :             {
    2525             :               /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed.  */
    2526          36 :               retrofit_lang_decl (newdecl);
    2527          36 :               CP_DECL_THREADPRIVATE_P (newdecl) = 1;
    2528             :             }
    2529             :         }
    2530             : 
    2531             :       /* An explicit specialization of a function template or of a member
    2532             :          function of a class template can be declared transaction_safe
    2533             :          independently of whether the corresponding template entity is declared
    2534             :          transaction_safe. */
    2535        1124 :       if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
    2536        1004 :           && DECL_TEMPLATE_INSTANTIATION (olddecl)
    2537          51 :           && DECL_TEMPLATE_SPECIALIZATION (newdecl)
    2538          51 :           && tx_safe_fn_type_p (newtype)
    2539     9990525 :           && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
    2540           0 :         newtype = tx_unsafe_fn_variant (newtype);
    2541             : 
    2542     9990525 :       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
    2543             : 
    2544     9990525 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2545     9709445 :         check_default_args (newdecl);
    2546             : 
    2547             :       /* Lay the type out, unless already done.  */
    2548     9990525 :       if (! same_type_p (newtype, oldtype)
    2549         399 :           && TREE_TYPE (newdecl) != error_mark_node
    2550     9990924 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2551         319 :         layout_type (TREE_TYPE (newdecl));
    2552             : 
    2553     9990525 :       if ((VAR_P (newdecl)
    2554     9715996 :            || TREE_CODE (newdecl) == PARM_DECL
    2555     9715996 :            || TREE_CODE (newdecl) == RESULT_DECL
    2556     9715996 :            || TREE_CODE (newdecl) == FIELD_DECL
    2557     9715996 :            || TREE_CODE (newdecl) == TYPE_DECL)
    2558     9997076 :           && !(processing_template_decl && uses_template_parms (newdecl)))
    2559      156454 :         layout_decl (newdecl, 0);
    2560             : 
    2561             :       /* Merge deprecatedness.  */
    2562     9990525 :       if (TREE_DEPRECATED (newdecl))
    2563        8605 :         TREE_DEPRECATED (olddecl) = 1;
    2564             : 
    2565             :       /* Merge unavailability.  */
    2566     9990525 :       if (TREE_UNAVAILABLE (newdecl))
    2567           4 :         TREE_UNAVAILABLE (olddecl) = 1;
    2568             : 
    2569             :       /* Preserve function specific target and optimization options */
    2570     9990525 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2571             :         {
    2572     9709445 :           if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
    2573     9709445 :               && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
    2574           0 :             DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
    2575           0 :               = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
    2576             : 
    2577     9709445 :           if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
    2578     9709445 :               && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
    2579           4 :             DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
    2580           4 :               = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
    2581             : 
    2582     9709445 :           if (!DECL_UNIQUE_FRIEND_P (olddecl))
    2583     9659788 :             DECL_UNIQUE_FRIEND_P (newdecl) = false;
    2584             :         }
    2585             :       else
    2586             :         {
    2587             :           /* Merge the const type qualifier.  */
    2588      281080 :           if (TREE_READONLY (newdecl))
    2589       18150 :             TREE_READONLY (olddecl) = 1;
    2590             :           /* Merge the volatile type qualifier.  */
    2591      281080 :           if (TREE_THIS_VOLATILE (newdecl))
    2592           6 :             TREE_THIS_VOLATILE (olddecl) = 1;
    2593             :         }
    2594             : 
    2595             :       /* Merge the initialization information.  */
    2596     9990525 :       if (DECL_INITIAL (newdecl) == NULL_TREE
    2597     9990525 :           && DECL_INITIAL (olddecl) != NULL_TREE)
    2598             :         {
    2599      135389 :           DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
    2600      135389 :           DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
    2601      135389 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2602             :             {
    2603        9393 :               DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
    2604        9393 :               DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
    2605             :             }
    2606             :         }
    2607             : 
    2608     9990525 :       if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2609             :         {
    2610     9709445 :           DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
    2611     9709445 :             |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
    2612     9709445 :           DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
    2613     9709445 :           if (DECL_IS_OPERATOR_NEW_P (olddecl))
    2614       39788 :             DECL_SET_IS_OPERATOR_NEW (newdecl, true);
    2615     9709445 :           DECL_LOOPING_CONST_OR_PURE_P (newdecl)
    2616     9709445 :             |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
    2617     9709445 :           DECL_IS_REPLACEABLE_OPERATOR (newdecl)
    2618     9709445 :             |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
    2619             : 
    2620     9709445 :           if (merge_attr)
    2621     9301575 :             merge_attribute_bits (newdecl, olddecl);
    2622             :           else
    2623             :             {
    2624             :               /* Merge the noreturn bit.  */
    2625      407870 :               TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2626      407870 :               TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2627      407870 :               TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2628      407870 :               DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
    2629      407870 :               DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
    2630             :             }
    2631             :           /* Keep the old RTL.  */
    2632     9709445 :           COPY_DECL_RTL (olddecl, newdecl);
    2633             :         }
    2634      281080 :       else if (VAR_P (newdecl)
    2635      281080 :                && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
    2636             :         {
    2637             :           /* Keep the old RTL.  We cannot keep the old RTL if the old
    2638             :              declaration was for an incomplete object and the new
    2639             :              declaration is not since many attributes of the RTL will
    2640             :              change.  */
    2641      274434 :           COPY_DECL_RTL (olddecl, newdecl);
    2642             :         }
    2643             :     }
    2644             :   /* If cannot merge, then use the new type and qualifiers,
    2645             :      and don't preserve the old rtl.  */
    2646             :   else
    2647             :     {
    2648             :       /* Clean out any memory we had of the old declaration.  */
    2649         275 :       tree oldstatic = value_member (olddecl, static_aggregates);
    2650         275 :       if (oldstatic)
    2651           0 :         TREE_VALUE (oldstatic) = error_mark_node;
    2652             : 
    2653         275 :       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
    2654         275 :       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
    2655         275 :       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
    2656         275 :       TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
    2657         275 :       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
    2658             :     }
    2659             : 
    2660             :   /* Merge the storage class information.  */
    2661     9990800 :   merge_weak (newdecl, olddecl);
    2662             : 
    2663     9990800 :   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
    2664     9990800 :   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
    2665     9990800 :   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
    2666     9990800 :   if (! DECL_EXTERNAL (olddecl))
    2667       12073 :     DECL_EXTERNAL (newdecl) = 0;
    2668     9990800 :   if (! DECL_COMDAT (olddecl))
    2669     3915772 :     DECL_COMDAT (newdecl) = 0;
    2670             : 
    2671     9990800 :   if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
    2672             :     {
    2673          84 :       if (!DECL_LOCAL_DECL_P (olddecl))
    2674             :         /* This can happen if olddecl was brought in from the
    2675             :            enclosing namespace via a using-decl.  The new decl is
    2676             :            then not a block-scope extern at all.  */
    2677           4 :         DECL_LOCAL_DECL_P (newdecl) = false;
    2678             :       else
    2679             :         {
    2680          80 :           retrofit_lang_decl (newdecl);
    2681          80 :           tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
    2682         131 :             = DECL_LOCAL_DECL_ALIAS (olddecl);
    2683          80 :           DECL_ATTRIBUTES (alias)
    2684          80 :             = (*targetm.merge_decl_attributes) (alias, newdecl);
    2685          80 :           if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2686          51 :             merge_attribute_bits (newdecl, alias);
    2687             :         }
    2688             :     }
    2689             : 
    2690     9990800 :   new_template_info = NULL_TREE;
    2691     9990800 :   if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
    2692             :     {
    2693     9980733 :       bool new_redefines_gnu_inline = false;
    2694             : 
    2695     9980733 :       if (new_defines_function
    2696     9980733 :           && ((DECL_INTERFACE_KNOWN (olddecl)
    2697         984 :                && TREE_CODE (olddecl) == FUNCTION_DECL)
    2698     6319008 :               || (TREE_CODE (olddecl) == TEMPLATE_DECL
    2699           0 :                   && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
    2700             :                       == FUNCTION_DECL))))
    2701        1968 :         new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
    2702             : 
    2703             :       if (!new_redefines_gnu_inline)
    2704             :         {
    2705     9980633 :           DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
    2706     9980633 :           DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
    2707     9980633 :           DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
    2708             :         }
    2709             : 
    2710     9980733 :       if (TREE_CODE (newdecl) != TYPE_DECL)
    2711             :         {
    2712     9980706 :           DECL_TEMPLATE_INSTANTIATED (newdecl)
    2713     9980706 :             |= DECL_TEMPLATE_INSTANTIATED (olddecl);
    2714     9980706 :           DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
    2715             : 
    2716             :           /* If the OLDDECL is an instantiation and/or specialization,
    2717             :              then the NEWDECL must be too.  But, it may not yet be marked
    2718             :              as such if the caller has created NEWDECL, but has not yet
    2719             :              figured out that it is a redeclaration.  */
    2720     9980706 :           if (!DECL_USE_TEMPLATE (newdecl))
    2721     9572546 :             DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
    2722             : 
    2723     9980706 :           if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2724     9572605 :             DECL_INITIALIZED_IN_CLASS_P (newdecl)
    2725    19145210 :               |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
    2726             :         }
    2727             : 
    2728             :       /* Don't really know how much of the language-specific
    2729             :          values we should copy from old to new.  */
    2730     9980733 :       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
    2731             : 
    2732     9980733 :       if (LANG_DECL_HAS_MIN (newdecl))
    2733             :         {
    2734    19690480 :           DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
    2735     9980733 :           if (DECL_TEMPLATE_INFO (newdecl))
    2736             :             {
    2737      416484 :               new_template_info = DECL_TEMPLATE_INFO (newdecl);
    2738      416484 :               if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2739      416484 :                   && DECL_TEMPLATE_SPECIALIZATION (newdecl))
    2740             :                 /* Remember the presence of explicit specialization args.  */
    2741      815746 :                 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
    2742      815746 :                   = TINFO_USED_TEMPLATE_ID (new_template_info);
    2743             :             }
    2744             : 
    2745             :           /* We don't want to copy template info from a non-templated friend
    2746             :              (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now.  */
    2747     9980733 :           gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
    2748             :                                || !non_templated_friend_p (olddecl));
    2749     9980733 :           DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
    2750             :         }
    2751             : 
    2752     9980733 :       if (DECL_DECLARES_FUNCTION_P (newdecl))
    2753             :         {
    2754             :           /* Only functions have these fields.  */
    2755     9709720 :           DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
    2756     9709720 :           DECL_BEFRIENDING_CLASSES (newdecl)
    2757     9709720 :             = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
    2758     9709720 :                        DECL_BEFRIENDING_CLASSES (olddecl));
    2759             :           /* DECL_THUNKS is only valid for virtual functions,
    2760             :              otherwise it is a DECL_FRIEND_CONTEXT.  */
    2761     9709720 :           if (DECL_VIRTUAL_P (newdecl))
    2762      462290 :             SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
    2763    18494860 :           else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
    2764        3861 :             SET_DECL_FRIEND_CONTEXT (olddecl, fc);
    2765             :         }
    2766      271013 :       else if (VAR_P (newdecl))
    2767             :         {
    2768             :           /* Only variables have this field.  */
    2769      270986 :           if (VAR_HAD_UNKNOWN_BOUND (olddecl))
    2770         213 :             SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
    2771             :         }
    2772             :     }
    2773             : 
    2774     9990800 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    2775             :     {
    2776     9709720 :       tree parm;
    2777             : 
    2778             :       /* Merge parameter attributes. */
    2779     9709720 :       tree oldarg, newarg;
    2780     9709720 :       for (oldarg = DECL_ARGUMENTS(olddecl), newarg = DECL_ARGUMENTS(newdecl);
    2781    27429638 :            oldarg && newarg;
    2782    17719918 :            oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
    2783             :         {
    2784    17719918 :           DECL_ATTRIBUTES (newarg)
    2785    17719918 :             = (*targetm.merge_decl_attributes) (oldarg, newarg);
    2786    17719918 :           DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
    2787             :         }
    2788             : 
    2789     9709720 :       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
    2790     9709720 :           && !DECL_TEMPLATE_INSTANTIATION (newdecl))
    2791             :         {
    2792             :           /* If newdecl is not a specialization, then it is not a
    2793             :              template-related function at all.  And that means that we
    2794             :              should have exited above, returning 0.  */
    2795      407870 :           gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
    2796             : 
    2797      407870 :           if (DECL_ODR_USED (olddecl))
    2798             :             /* From [temp.expl.spec]:
    2799             : 
    2800             :                If a template, a member template or the member of a class
    2801             :                template is explicitly specialized then that
    2802             :                specialization shall be declared before the first use of
    2803             :                that specialization that would cause an implicit
    2804             :                instantiation to take place, in every translation unit in
    2805             :                which such a use occurs.  */
    2806           0 :             error ("explicit specialization of %qD after first use",
    2807             :                       olddecl);
    2808             : 
    2809      407870 :           SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
    2810      407870 :           DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
    2811      815596 :                                    && DECL_DECLARED_INLINE_P (newdecl));
    2812             : 
    2813             :           /* Don't propagate visibility from the template to the
    2814             :              specialization here.  We'll do that in determine_visibility if
    2815             :              appropriate.  */
    2816      407870 :           DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
    2817             : 
    2818             :           /* [temp.expl.spec/14] We don't inline explicit specialization
    2819             :              just because the primary template says so.  */
    2820      407870 :           gcc_assert (!merge_attr);
    2821             : 
    2822      407870 :           DECL_DECLARED_INLINE_P (olddecl)
    2823      407870 :             = DECL_DECLARED_INLINE_P (newdecl);
    2824             : 
    2825      407870 :           DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2826      407870 :             = DECL_DISREGARD_INLINE_LIMITS (newdecl);
    2827             : 
    2828      407870 :           DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
    2829             :         }
    2830     9301850 :       else if (new_defines_function && DECL_INITIAL (olddecl))
    2831             :         {
    2832             :           /* Never inline re-defined extern inline functions.
    2833             :              FIXME: this could be better handled by keeping both
    2834             :              function as separate declarations.  */
    2835         100 :           DECL_UNINLINABLE (newdecl) = 1;
    2836             :         }
    2837             :       else
    2838             :         {
    2839     9301750 :           if (DECL_PENDING_INLINE_P (olddecl))
    2840             :             {
    2841           8 :               DECL_PENDING_INLINE_P (newdecl) = 1;
    2842           8 :               DECL_PENDING_INLINE_INFO (newdecl)
    2843          16 :                 = DECL_PENDING_INLINE_INFO (olddecl);
    2844             :             }
    2845     9301742 :           else if (DECL_PENDING_INLINE_P (newdecl))
    2846             :             ;
    2847     9301742 :           else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
    2848     9301742 :             DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
    2849    18603484 :               = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
    2850             : 
    2851     9301750 :           DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
    2852             : 
    2853    27905250 :           DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
    2854    18603500 :             = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
    2855             : 
    2856    18603500 :           DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2857     9301750 :             = DECL_DISREGARD_INLINE_LIMITS (olddecl)
    2858     9301750 :             = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
    2859    18319544 :                || DECL_DISREGARD_INLINE_LIMITS (olddecl));
    2860             :         }
    2861             : 
    2862             :       /* Preserve abstractness on cloned [cd]tors.  */
    2863     9709720 :       DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
    2864             : 
    2865             :       /* Update newdecl's parms to point at olddecl.  */
    2866    31508839 :       for (parm = DECL_ARGUMENTS (newdecl); parm;
    2867    21799119 :            parm = DECL_CHAIN (parm))
    2868    21799119 :         DECL_CONTEXT (parm) = olddecl;
    2869             : 
    2870     9709720 :       if (! types_match)
    2871             :         {
    2872         275 :           SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
    2873         275 :           COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
    2874         275 :           COPY_DECL_RTL (newdecl, olddecl);
    2875             :         }
    2876     9709720 :       if (! types_match || new_defines_function)
    2877             :         {
    2878             :           /* These are the final DECL_ARGUMENTS that will be used within the
    2879             :              body; update any references to old DECL_ARGUMENTS in the
    2880             :              contracts, if present.  */
    2881     6320267 :           if (tree contracts = DECL_CONTRACTS (newdecl))
    2882         131 :             remap_contracts (olddecl, newdecl, contracts, true);
    2883             : 
    2884             :           /* These need to be copied so that the names are available.
    2885             :              Note that if the types do match, we'll preserve inline
    2886             :              info and other bits, but if not, we won't.  */
    2887     6320267 :           DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
    2888     6320267 :           DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
    2889             : 
    2890             :           /* In some cases, duplicate_contracts will remove contracts from
    2891             :              OLDDECL, to avoid duplications. Sometimes, the contracts end up
    2892             :              shared. If we removed them, re-add them.  */
    2893     6320267 :           if (!DECL_CONTRACTS (olddecl))
    2894     6320220 :             copy_contract_attributes (olddecl, newdecl);
    2895             :         }
    2896             :       /* If redeclaring a builtin function, it stays built in
    2897             :          if newdecl is a gnu_inline definition, or if newdecl is just
    2898             :          a declaration.  */
    2899     9709720 :       if (fndecl_built_in_p (olddecl)
    2900     9752185 :           && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
    2901             :         {
    2902     2693390 :           copy_decl_built_in_function (newdecl, olddecl);
    2903             :           /* If we're keeping the built-in definition, keep the rtl,
    2904             :              regardless of declaration matches.  */
    2905     2693390 :           COPY_DECL_RTL (olddecl, newdecl);
    2906     2693390 :           if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
    2907             :             {
    2908     2693386 :               enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
    2909     2693386 :               if (builtin_decl_explicit_p (fncode))
    2910             :                 {
    2911             :                   /* A compatible prototype of these builtin functions
    2912             :                      is seen, assume the runtime implements it with
    2913             :                      the expected semantics.  */
    2914     2693386 :                   switch (fncode)
    2915             :                     {
    2916        7293 :                     case BUILT_IN_STPCPY:
    2917        7293 :                       set_builtin_decl_implicit_p (fncode, true);
    2918        7293 :                       break;
    2919     2686093 :                     default:
    2920     2686093 :                       set_builtin_decl_declared_p (fncode, true);
    2921     2686093 :                       break;
    2922             :                     }
    2923             :                 }
    2924             : 
    2925     2693386 :               copy_attributes_to_builtin (newdecl);
    2926             :             }
    2927             :         }
    2928     9709720 :       if (new_defines_function)
    2929             :         /* If defining a function declared with other language
    2930             :            linkage, use the previously declared language linkage.  */
    2931     6319992 :         SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
    2932     3389728 :       else if (types_match)
    2933             :         {
    2934     3389453 :           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
    2935             :           /* Don't clear out the arguments if we're just redeclaring a
    2936             :              function.  */
    2937     3389453 :           if (DECL_ARGUMENTS (olddecl))
    2938             :             {
    2939             :               /* If we removed contracts from previous definition, re-attach
    2940             :                  them. Otherwise, rewrite the contracts so they match the
    2941             :                  parameters of the new declaration.  */
    2942      638280 :               if (DECL_INITIAL (olddecl)
    2943        9261 :                   && DECL_CONTRACTS (newdecl)
    2944      638291 :                   && !DECL_CONTRACTS (olddecl))
    2945          10 :                 copy_contract_attributes (olddecl, newdecl);
    2946             :               else
    2947             :                 {
    2948             :                   /* Temporarily undo the re-contexting of parameters so we can
    2949             :                      actually remap parameters.  The inliner won't replace
    2950             :                      parameters if we don't do this.  */
    2951      638270 :                   tree args = DECL_ARGUMENTS (newdecl);
    2952     2279697 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    2953     1641427 :                     DECL_CONTEXT (p) = newdecl;
    2954             : 
    2955             :                   /* Save new argument names for use in contracts parsing,
    2956             :                      unless we've already started parsing the body of olddecl
    2957             :                      (particular issues arise when newdecl is from a prior
    2958             :                      friend decl with no argument names, see
    2959             :                      modules/contracts-tpl-friend-1).  */
    2960      638270 :                   if (tree contracts = DECL_CONTRACTS (olddecl))
    2961          29 :                     remap_contracts (newdecl, olddecl, contracts, true);
    2962             : 
    2963             :                   /* And reverse this operation again. */
    2964     2279697 :                   for (tree p = args; p; p = DECL_CHAIN (p))
    2965     1641427 :                     DECL_CONTEXT (p) = olddecl;
    2966             :                 }
    2967             : 
    2968      638280 :               DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
    2969             :             }
    2970             :         }
    2971             :     }
    2972      281080 :   else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
    2973           0 :     NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
    2974             : 
    2975             :   /* Now preserve various other info from the definition.  */
    2976     9990800 :   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
    2977     9990800 :   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
    2978     9990800 :   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
    2979     9990800 :   COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
    2980             : 
    2981             :   /* Warn about conflicting visibility specifications.  */
    2982     9990800 :   if (DECL_VISIBILITY_SPECIFIED (olddecl)
    2983     3585874 :       && DECL_VISIBILITY_SPECIFIED (newdecl)
    2984     9991187 :       && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
    2985             :     {
    2986          14 :       auto_diagnostic_group d;
    2987          14 :       if (warning_at (newdecl_loc, OPT_Wattributes,
    2988             :                       "%qD: visibility attribute ignored because it "
    2989             :                       "conflicts with previous declaration", newdecl))
    2990          14 :         inform (olddecl_loc,
    2991             :                 "previous declaration of %qD", olddecl);
    2992          14 :     }
    2993             :   /* Choose the declaration which specified visibility.  */
    2994     9990800 :   if (DECL_VISIBILITY_SPECIFIED (olddecl))
    2995             :     {
    2996     3585874 :       DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
    2997     3585874 :       DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
    2998             :     }
    2999             :   /* Init priority used to be merged from newdecl to olddecl by the memcpy,
    3000             :      so keep this behavior.  */
    3001     9990800 :   if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
    3002             :     {
    3003           4 :       SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
    3004           4 :       DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
    3005             :     }
    3006             :   /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED.  */
    3007     9990800 :   if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
    3008             :     {
    3009          71 :       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
    3010          71 :       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
    3011             :     }
    3012     9990729 :   else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
    3013     9990729 :       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
    3014           0 :     DECL_USER_ALIGN (newdecl) = 1;
    3015             : 
    3016     9990800 :   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
    3017    19981600 :   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
    3018     9990800 :       > DECL_WARN_IF_NOT_ALIGN (newdecl))
    3019           0 :     SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
    3020             :                                 DECL_WARN_IF_NOT_ALIGN (olddecl));
    3021     9990800 :   if (TREE_CODE (newdecl) == FIELD_DECL)
    3022           0 :     DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
    3023             : 
    3024             :   /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
    3025             :      with that from NEWDECL below.  */
    3026     9990800 :   if (DECL_LANG_SPECIFIC (olddecl))
    3027             :     {
    3028     9980738 :       gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
    3029             :                            != DECL_LANG_SPECIFIC (newdecl));
    3030     9980738 :       ggc_free (DECL_LANG_SPECIFIC (olddecl));
    3031             :     }
    3032             : 
    3033             :   /* Merge the USED information.  */
    3034     9990800 :   if (TREE_USED (olddecl))
    3035      342541 :     TREE_USED (newdecl) = 1;
    3036     9648259 :   else if (TREE_USED (newdecl))
    3037          58 :     TREE_USED (olddecl) = 1;
    3038             : 
    3039     9990800 :   if (VAR_P (newdecl))
    3040             :     {
    3041      274529 :       if (DECL_READ_P (olddecl))
    3042       25158 :         DECL_READ_P (newdecl) = 1;
    3043      249371 :       else if (DECL_READ_P (newdecl))
    3044           0 :         DECL_READ_P (olddecl) = 1;
    3045             :     }
    3046             : 
    3047     9990800 :   if (DECL_PRESERVE_P (olddecl))
    3048          56 :     DECL_PRESERVE_P (newdecl) = 1;
    3049     9990744 :   else if (DECL_PRESERVE_P (newdecl))
    3050          70 :     DECL_PRESERVE_P (olddecl) = 1;
    3051             : 
    3052             :   /* Merge the DECL_FUNCTION_VERSIONED information.  newdecl will be copied
    3053             :      to olddecl and deleted.  */
    3054     9990800 :   if (TREE_CODE (newdecl) == FUNCTION_DECL
    3055    19700520 :       && DECL_FUNCTION_VERSIONED (olddecl))
    3056             :     {
    3057             :       /* Set the flag for newdecl so that it gets copied to olddecl.  */
    3058         344 :       DECL_FUNCTION_VERSIONED (newdecl) = 1;
    3059             :       /* newdecl will be purged after copying to olddecl and is no longer
    3060             :          a version.  */
    3061         344 :       cgraph_node::delete_function_version_by_decl (newdecl);
    3062             :     }
    3063             : 
    3064     9990800 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3065             :     {
    3066     9709720 :       int function_size;
    3067     9709720 :       struct symtab_node *snode = symtab_node::get (olddecl);
    3068             : 
    3069     9709720 :       function_size = sizeof (struct tree_decl_common);
    3070             : 
    3071     9709720 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3072             :               (char *) newdecl + sizeof (struct tree_common),
    3073             :               function_size - sizeof (struct tree_common));
    3074             : 
    3075     9709720 :       memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3076             :               (char *) newdecl + sizeof (struct tree_decl_common),
    3077             :               sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
    3078             : 
    3079             :       /* Preserve symtab node mapping.  */
    3080     9709720 :       olddecl->decl_with_vis.symtab_node = snode;
    3081             : 
    3082     9709720 :       if (new_template_info)
    3083             :         /* If newdecl is a template instantiation, it is possible that
    3084             :            the following sequence of events has occurred:
    3085             : 
    3086             :            o A friend function was declared in a class template.  The
    3087             :            class template was instantiated.
    3088             : 
    3089             :            o The instantiation of the friend declaration was
    3090             :            recorded on the instantiation list, and is newdecl.
    3091             : 
    3092             :            o Later, however, instantiate_class_template called pushdecl
    3093             :            on the newdecl to perform name injection.  But, pushdecl in
    3094             :            turn called duplicate_decls when it discovered that another
    3095             :            declaration of a global function with the same name already
    3096             :            existed.
    3097             : 
    3098             :            o Here, in duplicate_decls, we decided to clobber newdecl.
    3099             : 
    3100             :            If we're going to do that, we'd better make sure that
    3101             :            olddecl, and not newdecl, is on the list of
    3102             :            instantiations so that if we try to do the instantiation
    3103             :            again we won't get the clobbered declaration.  */
    3104      416481 :         reregister_specialization (newdecl,
    3105             :                                    new_template_info,
    3106             :                                    olddecl);
    3107             :     }
    3108             :   else
    3109             :     {
    3110      281080 :       size_t size = tree_code_size (TREE_CODE (newdecl));
    3111             : 
    3112      281080 :       memcpy ((char *) olddecl + sizeof (struct tree_common),
    3113             :               (char *) newdecl + sizeof (struct tree_common),
    3114             :               sizeof (struct tree_decl_common) - sizeof (struct tree_common));
    3115             : 
    3116      281080 :       switch (TREE_CODE (newdecl))
    3117             :         {
    3118      281080 :         case LABEL_DECL:
    3119      281080 :         case VAR_DECL:
    3120      281080 :         case RESULT_DECL:
    3121      281080 :         case PARM_DECL:
    3122      281080 :         case FIELD_DECL:
    3123      281080 :         case TYPE_DECL:
    3124      281080 :         case CONST_DECL:
    3125      281080 :           {
    3126      281080 :             struct symtab_node *snode = NULL;
    3127             : 
    3128      281080 :             if (VAR_P (newdecl)
    3129      281080 :                 && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
    3130           3 :                     || DECL_EXTERNAL (olddecl)))
    3131      274529 :               snode = symtab_node::get (olddecl);
    3132      281080 :             memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3133             :                     (char *) newdecl + sizeof (struct tree_decl_common),
    3134             :                     size - sizeof (struct tree_decl_common)
    3135      281080 :                     + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3136      281080 :             if (VAR_P (newdecl))
    3137      274529 :               olddecl->decl_with_vis.symtab_node = snode;
    3138             :           }
    3139             :           break;
    3140           0 :         default:
    3141           0 :           memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
    3142             :                   (char *) newdecl + sizeof (struct tree_decl_common),
    3143             :                   sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
    3144           0 :                   + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
    3145           0 :           break;
    3146             :         }
    3147             :     }
    3148             : 
    3149     9990800 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3150             :     {
    3151     9984249 :       if (DECL_EXTERNAL (olddecl)
    3152             :           || TREE_PUBLIC (olddecl)
    3153     9984249 :           || TREE_STATIC (olddecl))
    3154             :         {
    3155             :           /* Merge the section attribute.
    3156             :              We want to issue an error if the sections conflict but that must be
    3157             :              done later in decl_attributes since we are called before attributes
    3158             :              are assigned.  */
    3159     9984249 :           if (DECL_SECTION_NAME (newdecl) != NULL)
    3160           7 :             set_decl_section_name (olddecl, newdecl);
    3161             : 
    3162     9984249 :           if (DECL_ONE_ONLY (newdecl))
    3163             :             {
    3164           0 :               struct symtab_node *oldsym, *newsym;
    3165           0 :               if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3166           0 :                 oldsym = cgraph_node::get_create (olddecl);
    3167             :               else
    3168           0 :                 oldsym = varpool_node::get_create (olddecl);
    3169           0 :               newsym = symtab_node::get (newdecl);
    3170           0 :               oldsym->set_comdat_group (newsym->get_comdat_group ());
    3171             :             }
    3172             :         }
    3173             : 
    3174     9984249 :       if (VAR_P (newdecl)
    3175     9984249 :           && CP_DECL_THREAD_LOCAL_P (newdecl))
    3176             :         {
    3177         374 :           CP_DECL_THREAD_LOCAL_P (olddecl) = true;
    3178         374 :           if (!processing_template_decl)
    3179         364 :             set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
    3180             :         }
    3181             :     }
    3182             : 
    3183     9990800 :   DECL_UID (olddecl) = olddecl_uid;
    3184             : 
    3185             :   /* NEWDECL contains the merged attribute lists.
    3186             :      Update OLDDECL to be the same.  */
    3187     9990800 :   DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
    3188             : 
    3189             :   /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
    3190             :     so that encode_section_info has a chance to look at the new decl
    3191             :     flags and attributes.  */
    3192     9990800 :   if (DECL_RTL_SET_P (olddecl)
    3193     9990800 :       && (TREE_CODE (olddecl) == FUNCTION_DECL
    3194           0 :           || (VAR_P (olddecl)
    3195           0 :               && TREE_STATIC (olddecl))))
    3196           0 :     make_decl_rtl (olddecl);
    3197             : 
    3198             :   /* The NEWDECL will no longer be needed.  Because every out-of-class
    3199             :      declaration of a member results in a call to duplicate_decls,
    3200             :      freeing these nodes represents in a significant savings.
    3201             : 
    3202             :      Before releasing the node, be sore to remove function from symbol
    3203             :      table that might have been inserted there to record comdat group.
    3204             :      Be sure to however do not free DECL_STRUCT_FUNCTION because this
    3205             :      structure is shared in between newdecl and oldecl.  */
    3206     9990800 :   if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3207     9709720 :     DECL_STRUCT_FUNCTION (newdecl) = NULL;
    3208     9990800 :   if (VAR_OR_FUNCTION_DECL_P (newdecl))
    3209             :     {
    3210     9984249 :       struct symtab_node *snode = symtab_node::get (newdecl);
    3211     9984249 :       if (snode)
    3212         389 :         snode->remove ();
    3213             :     }
    3214             : 
    3215     9990800 :   if (TREE_CODE (olddecl) == FUNCTION_DECL)
    3216             :     {
    3217     9709720 :       tree clone;
    3218    10074294 :       FOR_EACH_CLONE (clone, olddecl)
    3219             :         {
    3220      364574 :           DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
    3221      364574 :           DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
    3222             :         }
    3223             :     }
    3224             : 
    3225             :   /* Remove the associated constraints for newdecl, if any, before
    3226             :      reclaiming memory. */
    3227     9990800 :   if (flag_concepts)
    3228      316622 :     remove_constraints (newdecl);
    3229             : 
    3230     9990800 :   ggc_free (newdecl);
    3231             : 
    3232     9990800 :   return olddecl;
    3233             : }
    3234             : 
    3235             : /* Return zero if the declaration NEWDECL is valid
    3236             :    when the declaration OLDDECL (assumed to be for the same name)
    3237             :    has already been seen.
    3238             :    Otherwise return an error message format string with a %s
    3239             :    where the identifier should go.  */
    3240             : 
    3241             : static const char *
    3242     9625737 : redeclaration_error_message (tree newdecl, tree olddecl)
    3243             : {
    3244     9625765 :   if (TREE_CODE (newdecl) == TYPE_DECL)
    3245             :     {
    3246             :       /* Because C++ can put things into name space for free,
    3247             :          constructs like "typedef struct foo { ... } foo"
    3248             :          would look like an erroneous redeclaration.  */
    3249       35646 :       if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
    3250             :         return NULL;
    3251             :       else
    3252             :         return G_("redefinition of %q#D");
    3253             :     }
    3254     9590119 :   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
    3255             :     {
    3256             :       /* If this is a pure function, its olddecl will actually be
    3257             :          the original initialization to `0' (which we force to call
    3258             :          abort()).  Don't complain about redefinition in this case.  */
    3259    13999944 :       if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
    3260     6999996 :           && DECL_INITIAL (olddecl) == NULL_TREE)
    3261             :         return NULL;
    3262             : 
    3263             :       /* If both functions come from different namespaces, this is not
    3264             :          a redeclaration - this is a conflict with a used function.  */
    3265    13999904 :       if (DECL_NAMESPACE_SCOPE_P (olddecl)
    3266      825182 :           && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
    3267     6999956 :           && ! decls_match (olddecl, newdecl))
    3268             :         return G_("%qD conflicts with used function");
    3269             : 
    3270             :       /* We'll complain about linkage mismatches in
    3271             :          warn_extern_redeclared_static.  */
    3272             : 
    3273             :       /* Defining the same name twice is no good.  */
    3274     6999952 :       if (decl_defined_p (olddecl)
    3275     6999952 :           && decl_defined_p (newdecl))
    3276             :         {
    3277         371 :           if (DECL_NAME (olddecl) == NULL_TREE)
    3278             :             return G_("%q#D not declared in class");
    3279         535 :           else if (!GNU_INLINE_P (olddecl)
    3280         483 :                    || GNU_INLINE_P (newdecl))
    3281         263 :             return G_("redefinition of %q#D");
    3282             :         }
    3283             : 
    3284     7332556 :       if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
    3285             :         {
    3286      299852 :           bool olda = GNU_INLINE_P (olddecl);
    3287      299852 :           bool newa = GNU_INLINE_P (newdecl);
    3288             : 
    3289      299852 :           if (olda != newa)
    3290             :             {
    3291          20 :               if (newa)
    3292             :                 return G_("%q+D redeclared inline with "
    3293             :                           "%<gnu_inline%> attribute");
    3294             :               else
    3295             :                 return G_("%q+D redeclared inline without "
    3296             :                           "%<gnu_inline%> attribute");
    3297             :             }
    3298             :         }
    3299             : 
    3300     6999669 :       if (deduction_guide_p (olddecl)
    3301     6999669 :           && deduction_guide_p (newdecl))
    3302             :         return G_("deduction guide %q+D redeclared");
    3303             : 
    3304             :       /* [class.compare.default]: A definition of a comparison operator as
    3305             :          defaulted that appears in a class shall be the first declaration of
    3306             :          that function.  */
    3307     6999663 :       special_function_kind sfk = special_function_p (olddecl);
    3308     6999663 :       if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
    3309             :         return G_("comparison operator %q+D defaulted after "
    3310             :                   "its first declaration");
    3311             : 
    3312     6999662 :       check_abi_tag_redeclaration
    3313     6999662 :         (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
    3314     6999662 :          lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
    3315             : 
    3316     6999662 :       return NULL;
    3317             :     }
    3318     2590147 :   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
    3319             :     {
    3320     2315402 :       tree nt, ot;
    3321             : 
    3322     2315402 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
    3323             :         return G_("redefinition of %q#D");
    3324             : 
    3325     2315400 :       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
    3326          28 :         return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
    3327          28 :                                             DECL_TEMPLATE_RESULT (olddecl));
    3328             : 
    3329     2315372 :       if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
    3330             :         return NULL;
    3331             : 
    3332     2315359 :       nt = DECL_TEMPLATE_RESULT (newdecl);
    3333     2315359 :       if (DECL_TEMPLATE_INFO (nt))
    3334      254219 :         nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
    3335     2315359 :       ot = DECL_TEMPLATE_RESULT (olddecl);
    3336     2315359 :       if (DECL_TEMPLATE_INFO (ot))
    3337     2315359 :         ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
    3338     4144152 :       if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
    3339     2315406 :           && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
    3340          15 :         return G_("redefinition of %q#D");
    3341             : 
    3342     2876896 :       if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
    3343             :         {
    3344      293638 :           bool olda = GNU_INLINE_P (ot);
    3345      293638 :           bool newa = GNU_INLINE_P (nt);
    3346             : 
    3347      293638 :           if (olda != newa)
    3348             :             {
    3349           0 :               if (newa)
    3350             :                 return G_("%q+D redeclared inline with "
    3351             :                           "%<gnu_inline%> attribute");
    3352             :               else
    3353             :                 return G_("%q+D redeclared inline without "
    3354             :                           "%<gnu_inline%> attribute");
    3355             :             }
    3356             :         }
    3357             : 
    3358     2315344 :       if (deduction_guide_p (olddecl)
    3359     2315344 :           && deduction_guide_p (newdecl))
    3360             :         return G_("deduction guide %q+D redeclared");
    3361             : 
    3362             :       /* Core issue #226 (C++11):
    3363             : 
    3364             :            If a friend function template declaration specifies a
    3365             :            default template-argument, that declaration shall be a
    3366             :            definition and shall be the only declaration of the
    3367             :            function template in the translation unit.  */
    3368     2315342 :       if ((cxx_dialect != cxx98)
    3369     2303231 :           && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
    3370     2467810 :           && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
    3371             :                                        /*is_primary=*/true,
    3372             :                                        /*is_partial=*/false,
    3373             :                                        /*is_friend_decl=*/2))
    3374             :         return G_("redeclaration of friend %q#D "
    3375             :                   "may not have default template arguments");
    3376             : 
    3377     2315339 :       return NULL;
    3378             :     }
    3379      274745 :   else if (VAR_P (newdecl)
    3380      274657 :            && (CP_DECL_THREAD_LOCAL_P (newdecl)
    3381      274657 :                != CP_DECL_THREAD_LOCAL_P (olddecl))
    3382      274789 :            && (! DECL_LANG_SPECIFIC (olddecl)
    3383          40 :                || ! CP_DECL_THREADPRIVATE_P (olddecl)
    3384          36 :                || CP_DECL_THREAD_LOCAL_P (newdecl)))
    3385             :     {
    3386             :       /* Only variables can be thread-local, and all declarations must
    3387             :          agree on this property.  */
    3388           8 :       if (CP_DECL_THREAD_LOCAL_P (newdecl))
    3389             :         return G_("thread-local declaration of %q#D follows "
    3390             :                   "non-thread-local declaration");
    3391             :       else
    3392           4 :         return G_("non-thread-local declaration of %q#D follows "
    3393             :                   "thread-local declaration");
    3394             :     }
    3395      274737 :   else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
    3396             :     {
    3397             :       /* The objects have been declared at namespace scope.  If either
    3398             :          is a member of an anonymous union, then this is an invalid
    3399             :          redeclaration.  For example:
    3400             : 
    3401             :            int i;
    3402             :            union { int i; };
    3403             : 
    3404             :            is invalid.  */
    3405      274612 :       if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
    3406      549297 :           || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
    3407             :         return G_("redeclaration of %q#D");
    3408             :       /* If at least one declaration is a reference, there is no
    3409             :          conflict.  For example:
    3410             : 
    3411             :            int i = 3;
    3412             :            extern int i;
    3413             : 
    3414             :          is valid.  */
    3415      274681 :       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
    3416             :         return NULL;
    3417             : 
    3418             :       /* Static data member declared outside a class definition
    3419             :          if the variable is defined within the class with constexpr
    3420             :          specifier is declaration rather than definition (and
    3421             :          deprecated).  */
    3422        3080 :       if (cxx_dialect >= cxx17
    3423        3013 :           && VAR_P (olddecl)
    3424        2969 :           && DECL_CLASS_SCOPE_P (olddecl)
    3425        2953 :           && DECL_DECLARED_CONSTEXPR_P (olddecl)
    3426        6009 :           && !DECL_INITIAL (newdecl))
    3427             :         {
    3428        2929 :           DECL_EXTERNAL (newdecl) = 1;
    3429             :           /* For now, only warn with explicit -Wdeprecated.  */
    3430        2929 :           if (OPTION_SET_P (warn_deprecated))
    3431             :             {
    3432          32 :               auto_diagnostic_group d;
    3433          32 :               if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
    3434             :                                 "redundant redeclaration of %<constexpr%> "
    3435             :                                 "static data member %qD", newdecl))
    3436           8 :                 inform (DECL_SOURCE_LOCATION (olddecl),
    3437             :                           "previous declaration of %qD", olddecl);
    3438          32 :             }
    3439        2929 :           return NULL;
    3440             :         }
    3441             : 
    3442             :       /* Reject two definitions.  */
    3443             :       return G_("redefinition of %q#D");
    3444             :     }
    3445             :   else
    3446             :     {
    3447             :       /* Objects declared with block scope:  */
    3448             :       /* Reject two definitions, and reject a definition
    3449             :          together with an external reference.  */
    3450          40 :       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
    3451             :         return G_("redeclaration of %q#D");
    3452             :       return NULL;
    3453             :     }
    3454             : }
    3455             : 
    3456             : 
    3457             : /* Hash and equality functions for the named_label table.  */
    3458             : 
    3459             : hashval_t
    3460       61068 : named_label_hash::hash (const value_type entry)
    3461             : {
    3462       61068 :   return IDENTIFIER_HASH_VALUE (entry->name);
    3463             : }
    3464             : 
    3465             : bool
    3466       61961 : named_label_hash::equal (const value_type entry, compare_type name)
    3467             : {
    3468       61961 :   return name == entry->name;
    3469             : }
    3470             : 
    3471             : /* Look for a label named ID in the current function.  If one cannot
    3472             :    be found, create one.  Return the named_label_entry, or NULL on
    3473             :    failure.  */
    3474             : 
    3475             : static named_label_entry *
    3476       17286 : lookup_label_1 (tree id, bool making_local_p)
    3477             : {
    3478       17286 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3479             : 
    3480             :   /* You can't use labels at global scope.  */
    3481       17286 :   if (current_function_decl == NULL_TREE)
    3482             :     {
    3483           4 :       error ("label %qE referenced outside of any function", id);
    3484           4 :       return NULL;
    3485             :     }
    3486             : 
    3487       17282 :   if (!named_labels)
    3488        2366 :     named_labels = hash_table<named_label_hash>::create_ggc (13);
    3489             : 
    3490       17282 :   hashval_t hash = IDENTIFIER_HASH_VALUE (id);
    3491       17282 :   named_label_entry **slot
    3492       17282 :     = named_labels->find_slot_with_hash (id, hash, INSERT);
    3493       17282 :   named_label_entry *old = *slot;
    3494             :   
    3495       17282 :   if (old && old->label_decl)
    3496             :     {
    3497        1907 :       if (!making_local_p)
    3498             :         return old;
    3499             : 
    3500          12 :       if (old->binding_level == current_binding_level)
    3501             :         {
    3502           0 :           error ("local label %qE conflicts with existing label", id);
    3503           0 :           inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
    3504           0 :           return NULL;
    3505             :         }
    3506             :     }
    3507             : 
    3508             :   /* We are making a new decl, create or reuse the named_label_entry  */
    3509       15399 :   named_label_entry *ent = NULL;
    3510          28 :   if (old && !old->label_decl)
    3511             :     ent = old;
    3512             :   else
    3513             :     {
    3514       15371 :       ent = ggc_cleared_alloc<named_label_entry> ();
    3515       15371 :       ent->name = id;
    3516       15371 :       ent->outer = old;
    3517       15371 :       *slot = ent;
    3518             :     }
    3519             : 
    3520             :   /* Now create the LABEL_DECL.  */
    3521       15387 :   tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
    3522             : 
    3523       15387 :   DECL_CONTEXT (decl) = current_function_decl;
    3524       15387 :   SET_DECL_MODE (decl, VOIDmode);
    3525       15387 :   if (making_local_p)
    3526             :     {
    3527         104 :       C_DECLARED_LABEL_FLAG (decl) = true;
    3528         104 :       DECL_CHAIN (decl) = current_binding_level->names;
    3529         104 :       current_binding_level->names = decl;
    3530             :     }
    3531             : 
    3532       15387 :   ent->label_decl = decl;
    3533             : 
    3534       15387 :   return ent;
    3535       17286 : }
    3536             : 
    3537             : /* Wrapper for lookup_label_1.  */
    3538             : 
    3539             : tree
    3540        1795 : lookup_label (tree id)
    3541             : {
    3542        1795 :   named_label_entry *ent = lookup_label_1 (id, false);
    3543        1795 :   return ent ? ent->label_decl : NULL_TREE;
    3544             : }
    3545             : 
    3546             : tree
    3547         104 : declare_local_label (tree id)
    3548             : {
    3549         104 :   named_label_entry *ent = lookup_label_1 (id, true);
    3550         104 :   return ent ? ent->label_decl : NULL_TREE;
    3551             : }
    3552             : 
    3553             : /* Returns true if it is ill-formed to jump past the declaration of DECL.  */
    3554             : 
    3555             : static bool
    3556        9105 : decl_jump_unsafe (tree decl)
    3557             : {
    3558             :   /* [stmt.dcl]/3: A program that jumps from a point where a local variable
    3559             :      with automatic storage duration is not in scope to a point where it is
    3560             :      in scope is ill-formed unless the variable has scalar type, class type
    3561             :      with a trivial default constructor and a trivial destructor, a
    3562             :      cv-qualified version of one of these types, or an array of one of the
    3563             :      preceding types and is declared without an initializer (8.5).  */
    3564        9105 :   tree type = TREE_TYPE (decl);
    3565             : 
    3566        9105 :   return (type != error_mark_node
    3567             :           && VAR_P (decl)
    3568        9081 :           && !TREE_STATIC (decl)
    3569       17282 :           && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
    3570        7022 :               || variably_modified_type_p (type, NULL_TREE)));
    3571             : }
    3572             : 
    3573             : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
    3574             :    to the user.  */
    3575             : 
    3576             : static bool
    3577         288 : identify_goto (tree decl, location_t loc, const location_t *locus,
    3578             :                diagnostic_t diag_kind)
    3579             : {
    3580         288 :   bool complained
    3581         400 :     = emit_diagnostic (diag_kind, loc, 0,
    3582             :                        decl ? N_("jump to label %qD")
    3583             :                        : N_("jump to case label"), decl);
    3584         288 :   if (complained && locus)
    3585         176 :     inform (*locus, "  from here");
    3586         288 :   return complained;
    3587             : }
    3588             : 
    3589             : /* Check that a single previously seen jump to a newly defined label
    3590             :    is OK.  DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
    3591             :    the jump context; NAMES are the names in scope in LEVEL at the jump
    3592             :    context; LOCUS is the source position of the jump or 0.  Returns
    3593             :    true if all is well.  */
    3594             : 
    3595             : static bool
    3596      698844 : check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
    3597             :                        bool exited_omp, const location_t *locus)
    3598             : {
    3599      698844 :   cp_binding_level *b;
    3600      698844 :   bool complained = false;
    3601      698844 :   int identified = 0;
    3602      698844 :   bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
    3603      698844 :   bool saw_ceif = false, saw_se = false;
    3604             : 
    3605      698844 :   if (exited_omp)
    3606             :     {
    3607          16 :       complained = identify_goto (decl, input_location, locus, DK_ERROR);
    3608          16 :       if (complained)
    3609          16 :         inform (input_location, "  exits OpenMP structured block");
    3610             :       saw_omp = true;
    3611             :       identified = 2;
    3612             :     }
    3613             : 
    3614     1397281 :   for (b = current_binding_level; b ; b = b->level_chain)
    3615             :     {
    3616     1397281 :       tree new_decls, old_decls = (b == level ? names : NULL_TREE);
    3617             : 
    3618     1403417 :       for (new_decls = b->names; new_decls != old_decls;
    3619        6380 :            new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
    3620         244 :                         : TREE_CHAIN (new_decls)))
    3621             :         {
    3622        6136 :           bool problem = decl_jump_unsafe (new_decls);
    3623        6136 :           if (! problem)
    3624        6090 :             continue;
    3625             : 
    3626          46 :           if (!identified)
    3627             :             {
    3628          46 :               complained = identify_goto (decl, input_location, locus, DK_ERROR);
    3629          46 :               identified = 1;
    3630             :             }
    3631          46 :           if (complained)
    3632          46 :             inform (DECL_SOURCE_LOCATION (new_decls),
    3633             :                     "  crosses initialization of %q#D", new_decls);
    3634             :         }
    3635             : 
    3636     1397281 :       if (b == level)
    3637             :         break;
    3638             : 
    3639      698437 :       const char *inf = NULL;
    3640      698437 :       location_t loc = input_location;
    3641      698437 :       switch (b->kind)
    3642             :         {
    3643           4 :         case sk_try:
    3644           4 :           if (!saw_eh)
    3645      698437 :             inf = G_("  enters %<try%> block");
    3646             :           saw_eh = true;
    3647             :           break;
    3648             : 
    3649          12 :         case sk_catch:
    3650          12 :           if (!saw_eh)
    3651      698437 :             inf = G_("  enters %<catch%> block");
    3652             :           saw_eh = true;
    3653             :           break;
    3654             : 
    3655         136 :         case sk_omp:
    3656         136 :           if (!saw_omp)
    3657         108 :             inf = G_("  enters OpenMP structured block");
    3658             :           saw_omp = true;
    3659             :           break;
    3660             : 
    3661           4 :         case sk_transaction:
    3662           4 :           if (!saw_tm)
    3663           4 :             inf = G_("  enters synchronized or atomic statement");
    3664             :           saw_tm = true;
    3665             :           break;
    3666             : 
    3667          15 :         case sk_stmt_expr:
    3668          15 :           if (!saw_se)
    3669          15 :             inf = G_("  enters statement expression");
    3670             :           saw_se = true;
    3671             :           break;
    3672             : 
    3673      698168 :         case sk_block:
    3674      698168 :           if (!saw_cxif && level_for_constexpr_if (b->level_chain))
    3675             :             {
    3676           9 :               inf = G_("  enters %<constexpr if%> statement");
    3677           9 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3678             :               saw_cxif = true;
    3679             :             }
    3680      698159 :           else if (!saw_ceif && level_for_consteval_if (b->level_chain))
    3681             :             {
    3682           6 :               inf = G_("  enters %<consteval if%> statement");
    3683           6 :               loc = EXPR_LOCATION (b->level_chain->this_entity);
    3684             :               saw_ceif = true;
    3685             :             }
    3686             :           break;
    3687             : 
    3688             :         default:
    3689             :           break;
    3690             :         }
    3691             : 
    3692      698437 :       if (inf)
    3693             :         {
    3694         158 :           if (identified < 2)
    3695         158 :             complained = identify_goto (decl, input_location, locus, DK_ERROR);
    3696         158 :           identified = 2;
    3697         158 :           if (complained)
    3698         158 :             inform (loc, inf);
    3699             :         }
    3700             :     }
    3701             : 
    3702      698844 :   return !identified;
    3703             : }
    3704             : 
    3705             : static void
    3706         920 : check_previous_goto (tree decl, struct named_label_use_entry *use)
    3707             : {
    3708         920 :   check_previous_goto_1 (decl, use->binding_level,
    3709         920 :                          use->names_in_scope, use->in_omp_scope,
    3710         920 :                          &use->o_goto_locus);
    3711         920 : }
    3712             : 
    3713             : static bool
    3714      697924 : check_switch_goto (cp_binding_level* level)
    3715             : {
    3716      697924 :   return check_previous_goto_1 (NULL_TREE, level, level->names, false, NULL);
    3717             : }
    3718             : 
    3719             : /* Check that a new jump to a label DECL is OK.  Called by
    3720             :    finish_goto_stmt.  */
    3721             : 
    3722             : void
    3723        1641 : check_goto (tree decl)
    3724             : {
    3725             :   /* We can't know where a computed goto is jumping.
    3726             :      So we assume that it's OK.  */
    3727        1641 :   if (TREE_CODE (decl) != LABEL_DECL)
    3728        1641 :     return;
    3729             : 
    3730        1538 :   hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
    3731        1538 :   named_label_entry **slot
    3732        1538 :     = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
    3733        1538 :   named_label_entry *ent = *slot;
    3734             : 
    3735             :   /* If the label hasn't been defined yet, defer checking.  */
    3736        1538 :   if (! DECL_INITIAL (decl))
    3737             :     {
    3738             :       /* Don't bother creating another use if the last goto had the
    3739             :          same data, and will therefore create the same set of errors.  */
    3740        1080 :       if (ent->uses
    3741         285 :           && ent->uses->names_in_scope == current_binding_level->names)
    3742             :         return;
    3743             : 
    3744         928 :       named_label_use_entry *new_use
    3745         928 :         = ggc_alloc<named_label_use_entry> ();
    3746         928 :       new_use->binding_level = current_binding_level;
    3747         928 :       new_use->names_in_scope = current_binding_level->names;
    3748         928 :       new_use->o_goto_locus = input_location;
    3749         928 :       new_use->in_omp_scope = false;
    3750             : 
    3751         928 :       new_use->next = ent->uses;
    3752         928 :       ent->uses = new_use;
    3753         928 :       return;
    3754             :     }
    3755             : 
    3756         458 :   bool saw_catch = false, complained = false;
    3757         458 :   int identified = 0;
    3758         458 :   tree bad;
    3759         458 :   unsigned ix;
    3760             : 
    3761         446 :   if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
    3762         438 :       || ent->in_constexpr_if || ent->in_consteval_if
    3763         434 :       || ent->in_omp_scope || ent->in_stmt_expr
    3764         884 :       || !vec_safe_is_empty (ent->bad_decls))
    3765             :     {
    3766          40 :       diagnostic_t diag_kind = DK_PERMERROR;
    3767          40 :       if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
    3768          21 :           || ent->in_consteval_if || ent->in_transaction_scope
    3769          16 :           || ent->in_omp_scope || ent->in_stmt_expr)
    3770          32 :         diag_kind = DK_ERROR;
    3771          40 :       complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3772             :                                   &input_location, diag_kind);
    3773          40 :       identified = 1 + (diag_kind == DK_ERROR);
    3774             :     }
    3775             : 
    3776         466 :   FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
    3777             :     {
    3778           8 :       bool problem = decl_jump_unsafe (bad);
    3779             : 
    3780           8 :       if (problem && DECL_ARTIFICIAL (bad))
    3781             :         {
    3782             :           /* Can't skip init of __exception_info.  */
    3783           0 :           if (identified == 1)
    3784             :             {
    3785           0 :               complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
    3786             :                                           &input_location, DK_ERROR);
    3787           0 :               identified = 2;
    3788             :             }
    3789           0 :           if (complained)
    3790           0 :             inform (DECL_SOURCE_LOCATION (bad), "  enters %<catch%> block");
    3791             :           saw_catch = true;
    3792             :         }
    3793           8 :       else if (complained)
    3794           8 :         inform (DECL_SOURCE_LOCATION (bad),
    3795             :                 "  skips initialization of %q#D", bad);
    3796             :     }
    3797             : 
    3798         458 :   if (complained)
    3799             :     {
    3800          40 :       if (ent->in_try_scope)
    3801          12 :         inform (input_location, "  enters %<try%> block");
    3802          28 :       else if (ent->in_catch_scope && !saw_catch)
    3803           4 :         inform (input_location, "  enters %<catch%> block");
    3804          24 :       else if (ent->in_transaction_scope)
    3805           4 :         inform (input_location, "  enters synchronized or atomic statement");
    3806          20 :       else if (ent->in_constexpr_if)
    3807           3 :         inform (input_location, "  enters %<constexpr if%> statement");
    3808          17 :       else if (ent->in_consteval_if)
    3809           1 :         inform (input_location, "  enters %<consteval if%> statement");
    3810          16 :       else if (ent->in_stmt_expr)
    3811           4 :         inform (input_location, "  enters statement expression");
    3812             :     }
    3813             : 
    3814         458 :   if (ent->in_omp_scope)
    3815             :     {
    3816           4 :       if (complained)
    3817           4 :         inform (input_location, "  enters OpenMP structured block");
    3818             :     }
    3819         454 :   else if (flag_openmp)
    3820          46 :     for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    3821             :       {
    3822          46 :         if (b == ent->binding_level)
    3823             :           break;
    3824          40 :         if (b->kind == sk_omp)
    3825             :           {
    3826          28 :             if (identified < 2)
    3827             :               {
    3828          56 :                 complained = identify_goto (decl,
    3829          28 :                                             DECL_SOURCE_LOCATION (decl),
    3830             :                                             &input_location, DK_ERROR);
    3831          28 :                 identified = 2;
    3832             :               }
    3833          28 :             if (complained)
    3834          28 :               inform (input_location, "  exits OpenMP structured block");
    3835             :             break;
    3836             :           }
    3837             :       }
    3838             : }
    3839             : 
    3840             : /* Check that a return is ok wrt OpenMP structured blocks.
    3841             :    Called by finish_return_stmt.  Returns true if all is well.  */
    3842             : 
    3843             : bool
    3844       49840 : check_omp_return (void)
    3845             : {
    3846      146674 :   for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
    3847      146674 :     if (b->kind == sk_omp)
    3848             :       {
    3849          20 :         error ("invalid exit from OpenMP structured block");
    3850          20 :         return false;
    3851             :       }
    3852      146654 :     else if (b->kind == sk_function_parms)
    3853             :       break;
    3854             :   return true;
    3855             : }
    3856             : 
    3857             : /* Define a label, specifying the location in the source file.
    3858             :    Return the LABEL_DECL node for the label.  */
    3859             : 
    3860             : tree
    3861       15387 : define_label (location_t location, tree name)
    3862             : {
    3863       15387 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
    3864             : 
    3865             :   /* After labels, make any new cleanups in the function go into their
    3866             :      own new (temporary) binding contour.  */
    3867       15387 :   for (cp_binding_level *p = current_binding_level;
    3868       33397 :        p->kind != sk_function_parms;
    3869       18010 :        p = p->level_chain)
    3870       18010 :     p->more_cleanups_ok = 0;
    3871             : 
    3872       15387 :   named_label_entry *ent = lookup_label_1 (name, false);
    3873       15387 :   tree decl = ent->label_decl;
    3874             : 
    3875       15387 :   if (DECL_INITIAL (decl) != NULL_TREE)
    3876             :     {
    3877           8 :       error ("duplicate label %qD", decl);
    3878           8 :       return error_mark_node;
    3879             :     }
    3880             :   else
    3881             :     {
    3882             :       /* Mark label as having been defined.  */
    3883       15379 :       DECL_INITIAL (decl) = error_mark_node;
    3884             :       /* Say where in the source.  */
    3885       15379 :       DECL_SOURCE_LOCATION (decl) = location;
    3886             : 
    3887       15379 :       ent->binding_level = current_binding_level;
    3888       15379 :       ent->names_in_scope = current_binding_level->names;
    3889             : 
    3890       16299 :       for (named_label_use_entry *use = ent->uses; use; use = use->next)
    3891         920 :         check_previous_goto (decl, use);
    3892       15379 :       ent->uses = NULL;
    3893             :     }
    3894             : 
    3895       15379 :   return decl;
    3896       15387 : }
    3897             : 
    3898             : struct cp_switch
    3899             : {
    3900             :   cp_binding_level *level;
    3901             :   struct cp_switch *next;
    3902             :   /* The SWITCH_STMT being built.  */
    3903             :   tree switch_stmt;
    3904             :   /* A splay-tree mapping the low element of a case range to the high
    3905             :      element, or NULL_TREE if there is no high element.  Used to
    3906             :      determine whether or not a new case label duplicates an old case
    3907             :      label.  We need a tree, rather than simply a hash table, because
    3908             :      of the GNU case range extension.  */
    3909             :   splay_tree cases;
    3910             :   /* Remember whether a default: case label has been seen.  */
    3911             :   bool has_default_p;
    3912             :   /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT.  */
    3913             :   bool break_stmt_seen_p;
    3914             :   /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
    3915             :      where BREAK_STMT doesn't belong to the SWITCH_STMT.  */
    3916             :   bool in_loop_body_p;
    3917             : };
    3918             : 
    3919             : /* A stack of the currently active switch statements.  The innermost
    3920             :    switch statement is on the top of the stack.  There is no need to
    3921             :    mark the stack for garbage collection because it is only active
    3922             :    during the processing of the body of a function, and we never
    3923             :    collect at that point.  */
    3924             : 
    3925             : static struct cp_switch *switch_stack;
    3926             : 
    3927             : /* Called right after a switch-statement condition is parsed.
    3928             :    SWITCH_STMT is the switch statement being parsed.  */
    3929             : 
    3930             : void
    3931      236568 : push_switch (tree switch_stmt)
    3932             : {
    3933      236568 :   struct cp_switch *p = XNEW (struct cp_switch);
    3934      236568 :   p->level = current_binding_level;
    3935      236568 :   p->next = switch_stack;
    3936      236568 :   p->switch_stmt = switch_stmt;
    3937      236568 :   p->cases = splay_tree_new (case_compare, NULL, NULL);
    3938      236568 :   p->has_default_p = false;
    3939      236568 :   p->break_stmt_seen_p = false;
    3940      236568 :   p->in_loop_body_p = false;
    3941      236568 :   switch_stack = p;
    3942      236568 : }
    3943             : 
    3944             : void
    3945      236568 : pop_switch (void)
    3946             : {
    3947      236568 :   struct cp_switch *cs = switch_stack;
    3948             : 
    3949             :   /* Emit warnings as needed.  */
    3950      236568 :   location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
    3951      236568 :   tree cond = SWITCH_STMT_COND (cs->switch_stmt);
    3952      236568 :   const bool bool_cond_p
    3953      236568 :     = (SWITCH_STMT_TYPE (cs->switch_stmt)
    3954      236568 :        && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
    3955      236568 :   if (!processing_template_decl)
    3956      143163 :     c_do_switch_warnings (cs->cases, switch_location,
    3957      143163 :                           SWITCH_STMT_TYPE (cs->switch_stmt), cond,
    3958             :                           bool_cond_p);
    3959             : 
    3960             :   /* For the benefit of block_may_fallthru remember if the switch body
    3961             :      case labels cover all possible values and if there are break; stmts.  */
    3962      236568 :   if (cs->has_default_p
    3963      236568 :       || (!processing_template_decl
    3964       26611 :           && c_switch_covers_all_cases_p (cs->cases,
    3965       26611 :                                           SWITCH_STMT_TYPE (cs->switch_stmt))))
    3966      173650 :     SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
    3967      236568 :   if (!cs->break_stmt_seen_p)
    3968      133123 :     SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
    3969             :   /* Now that we're done with the switch warnings, set the switch type
    3970             :      to the type of the condition if the index type was of scoped enum type.
    3971             :      (Such types don't participate in the integer promotions.)  We do this
    3972             :      because of bit-fields whose declared type is a scoped enum type:
    3973             :      gimplification will use the lowered index type, but convert the
    3974             :      case values to SWITCH_STMT_TYPE, which would have been the declared type
    3975             :      and verify_gimple_switch doesn't accept that.  */
    3976      236568 :   if (is_bitfield_expr_with_lowered_type (cond))
    3977           7 :     SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
    3978      236568 :   gcc_assert (!cs->in_loop_body_p);
    3979      236568 :   splay_tree_delete (cs->cases);
    3980      236568 :   switch_stack = switch_stack->next;
    3981      236568 :   free (cs);
    3982      236568 : }
    3983             : 
    3984             : /* Note that a BREAK_STMT is about to be added.  If it is inside of
    3985             :    a SWITCH_STMT and not inside of a loop body inside of it, note
    3986             :    in switch_stack we've seen a BREAK_STMT.  */
    3987             : 
    3988             : void
    3989     1972132 : note_break_stmt (void)
    3990             : {
    3991     1972132 :   if (switch_stack && !switch_stack->in_loop_body_p)
    3992      617053 :     switch_stack->break_stmt_seen_p = true;
    3993     1972132 : }
    3994             : 
    3995             : /* Note the start of processing of an iteration statement's body.
    3996             :    The note_break_stmt function will do nothing while processing it.
    3997             :    Return a flag that should be passed to note_iteration_stmt_body_end.  */
    3998             : 
    3999             : bool
    4000     9697124 : note_iteration_stmt_body_start (void)
    4001             : {
    4002     9697124 :   if (!switch_stack)
    4003             :     return false;
    4004       44964 :   bool ret = switch_stack->in_loop_body_p;
    4005       44964 :   switch_stack->in_loop_body_p = true;
    4006       44964 :   return ret;
    4007             : }
    4008             : 
    4009             : /* Note the end of processing of an iteration statement's body.  */
    4010             : 
    4011             : void
    4012     9697124 : note_iteration_stmt_body_end (bool prev)
    4013             : {
    4014     9697124 :   if (switch_stack)
    4015       44964 :     switch_stack->in_loop_body_p = prev;
    4016     9697124 : }
    4017             : 
    4018             : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
    4019             :    condition.  Note that if TYPE and VALUE are already integral we don't
    4020             :    really do the conversion because the language-independent
    4021             :    warning/optimization code will work better that way.  */
    4022             : 
    4023             : static tree
    4024     1395584 : case_conversion (tree type, tree value)
    4025             : {
    4026     1395584 :   if (value == NULL_TREE)
    4027             :     return value;
    4028             : 
    4029      581413 :   value = mark_rvalue_use (value);
    4030             : 
    4031      581413 :   if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
    4032      580934 :     type = type_promotes_to (type);
    4033             : 
    4034      581413 :   tree ovalue = value;
    4035             :   /* The constant-expression VALUE shall be a converted constant expression
    4036             :      of the adjusted type of the switch condition, which doesn't allow
    4037             :      narrowing conversions.  */
    4038      581413 :   value = build_converted_constant_expr (type, value, tf_warning_or_error);
    4039             : 
    4040      581413 :   if (cxx_dialect >= cxx11
    4041      581413 :       && (SCOPED_ENUM_P (type)
    4042      578933 :           || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
    4043             :     /* Use the converted value.  */;
    4044             :   else
    4045             :     /* The already integral case.  */
    4046             :     value = ovalue;
    4047             : 
    4048      581413 :   return cxx_constant_value (value);
    4049             : }
    4050             : 
    4051             : /* Note that we've seen a definition of a case label, and complain if this
    4052             :    is a bad place for one.  */
    4053             : 
    4054             : tree
    4055     1467632 : finish_case_label (location_t loc, tree low_value, tree high_value)
    4056             : {
    4057     1467632 :   tree cond, r;
    4058     1467632 :   cp_binding_level *p;
    4059     1467632 :   tree type;
    4060             : 
    4061     1467632 :   if (low_value == NULL_TREE && high_value == NULL_TREE)
    4062      173610 :     switch_stack->has_default_p = true;
    4063             : 
    4064     1467632 :   if (processing_template_decl)
    4065             :     {
    4066      769708 :       tree label;
    4067             : 
    4068             :       /* For templates, just add the case label; we'll do semantic
    4069             :          analysis at instantiation-time.  */
    4070      769708 :       label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
    4071      769708 :       return add_stmt (build_case_label (low_value, high_value, label));
    4072             :     }
    4073             : 
    4074             :   /* Find the condition on which this switch statement depends.  */
    4075      697924 :   cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
    4076      697924 :   if (cond && TREE_CODE (cond) == TREE_LIST)
    4077           0 :     cond = TREE_VALUE (cond);
    4078             : 
    4079      697924 :   if (!check_switch_goto (switch_stack->level))
    4080         112 :     return error_mark_node;
    4081             : 
    4082      697812 :   type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
    4083      697812 :   if (type == error_mark_node)
    4084             :     return error_mark_node;
    4085             : 
    4086      697792 :   low_value = case_conversion (type, low_value);
    4087      697792 :   high_value = case_conversion (type, high_value);
    4088             : 
    4089      697792 :   r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
    4090             : 
    4091             :   /* After labels, make any new cleanups in the function go into their
    4092             :      own new (temporary) binding contour.  */
    4093      697792 :   for (p = current_binding_level;
    4094     3092005 :        p->kind != sk_function_parms;
    4095     2394213 :        p = p->level_chain)
    4096     2394213 :     p->more_cleanups_ok = 0;
    4097             : 
    4098             :   return r;
    4099             : }
    4100             : 
    4101             : struct typename_info {
    4102             :   tree scope;
    4103             :   tree name;
    4104             :   tree template_id;
    4105             :   bool enum_p;
    4106             :   bool class_p;
    4107             : };
    4108             : 
    4109             : struct typename_hasher : ggc_ptr_hash<tree_node>
    4110             : {
    4111             :   typedef typename_info *compare_type;
    4112             : 
    4113             :   /* Hash a TYPENAME_TYPE.  */
    4114             : 
    4115             :   static hashval_t
    4116   295601408 :   hash (tree context, tree fullname)
    4117             :   {
    4118   295601408 :     hashval_t hash = 0;
    4119   295601408 :     hash = iterative_hash_object (context, hash);
    4120   295601408 :     hash = iterative_hash_object (fullname, hash);
    4121   295601408 :     return hash;
    4122             :   }
    4123             : 
    4124             :   static hashval_t
    4125    44130678 :   hash (const typename_info *ti)
    4126             :   {
    4127    44130678 :     return typename_hasher::hash (ti->scope, ti->template_id);
    4128             :   }
    4129             : 
    4130             :   static hashval_t
    4131   251470730 :   hash (tree t)
    4132             :   {
    4133   251470730 :     return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
    4134             :   }
    4135             : 
    4136             :   /* Compare two TYPENAME_TYPEs.  */
    4137             : 
    4138             :   static bool
    4139   300756766 :   equal (tree t1, const typename_info *t2)
    4140             :   {
    4141   300756766 :     return (TYPE_IDENTIFIER (t1) == t2->name
    4142    97395583 :             && TYPE_CONTEXT (t1) == t2->scope
    4143    25772917 :             && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
    4144    25767966 :             && TYPENAME_IS_ENUM_P (t1) == t2->enum_p
    4145   326524676 :             && TYPENAME_IS_CLASS_P (t1) == t2->class_p);
    4146             :   }
    4147             : };
    4148             : 
    4149             : /* Build a TYPENAME_TYPE.  If the type is `typename T::t', CONTEXT is
    4150             :    the type of `T', NAME is the IDENTIFIER_NODE for `t'.
    4151             : 
    4152             :    Returns the new TYPENAME_TYPE.  */
    4153             : 
    4154             : static GTY (()) hash_table<typename_hasher> *typename_htab;
    4155             : 
    4156             : tree
    4157    44130678 : build_typename_type (tree context, tree name, tree fullname,
    4158             :                      enum tag_types tag_type)
    4159             : {
    4160    44130678 :   typename_info ti;
    4161             : 
    4162    44130678 :   if (typename_htab == NULL)
    4163       15468 :     typename_htab = hash_table<typename_hasher>::create_ggc (61);
    4164             : 
    4165    44130678 :   ti.scope = FROB_CONTEXT (context);
    4166    44130678 :   ti.name = name;
    4167    44130678 :   ti.template_id = fullname;
    4168    44130678 :   ti.enum_p = tag_type == enum_type;
    4169    44130678 :   ti.class_p = (tag_type == class_type
    4170             :                 || tag_type == record_type
    4171    44130678 :                 || tag_type == union_type);
    4172    44130678 :   hashval_t hash = typename_hasher::hash (&ti);
    4173             : 
    4174             :   /* See if we already have this type.  */
    4175    44130678 :   tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
    4176    44130678 :   tree t = *e;
    4177    44130678 :   if (*e)
    4178             :     t = *e;
    4179             :   else
    4180             :     {
    4181             :       /* Build the TYPENAME_TYPE.  */
    4182    18362800 :       t = cxx_make_type (TYPENAME_TYPE);
    4183    18362800 :       TYPE_CONTEXT (t) = ti.scope;
    4184    18362800 :       TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
    4185    18362800 :       TYPENAME_IS_ENUM_P (t) = ti.enum_p;
    4186    18362800 :       TYPENAME_IS_CLASS_P (t) = ti.class_p;
    4187             : 
    4188             :       /* Build the corresponding TYPE_DECL.  */
    4189    18362800 :       tree d = build_decl (input_location, TYPE_DECL, name, t);
    4190    18362800 :       TYPE_NAME (t) = d;
    4191    18362800 :       TYPE_STUB_DECL (t) = d;
    4192    18362800 :       DECL_CONTEXT (d) = ti.scope;
    4193    18362800 :       DECL_ARTIFICIAL (d) = 1;
    4194             : 
    4195             :       /* Store it in the hash table.  */
    4196    18362800 :       *e = t;
    4197             : 
    4198             :       /* TYPENAME_TYPEs must always be compared structurally, because
    4199             :          they may or may not resolve down to another type depending on
    4200             :          the currently open classes. */
    4201    18362800 :       SET_TYPE_STRUCTURAL_EQUALITY (t);
    4202             :     }
    4203             : 
    4204    44130678 :   return t;
    4205             : }
    4206             : 
    4207             : /* Resolve `typename CONTEXT::NAME'.  TAG_TYPE indicates the tag
    4208             :    provided to name the type.  Returns an appropriate type, unless an
    4209             :    error occurs, in which case error_mark_node is returned.  If we
    4210             :    locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
    4211             :    return that, rather than the _TYPE it corresponds to, in other
    4212             :    cases we look through the type decl.  If TF_ERROR is set, complain
    4213             :    about errors, otherwise be quiet.  */
    4214             : 
    4215             : tree
    4216    87542499 : make_typename_type (tree context, tree name, enum tag_types tag_type,
    4217             :                     tsubst_flags_t complain)
    4218             : {
    4219    87542499 :   tree fullname;
    4220    87542499 :   tree t;
    4221    87542499 :   bool want_template;
    4222             : 
    4223    87542499 :   if (name == error_mark_node
    4224    87542497 :       || context == NULL_TREE
    4225    87542497 :       || context == error_mark_node)
    4226             :     return error_mark_node;
    4227             : 
    4228    87542482 :   if (TYPE_P (name))
    4229             :     {
    4230           0 :       if (!(TYPE_LANG_SPECIFIC (name)
    4231           0 :             && (CLASSTYPE_IS_TEMPLATE (name)
    4232           0 :                 || CLASSTYPE_USE_TEMPLATE (name))))
    4233           0 :         name = TYPE_IDENTIFIER (name);
    4234             :       else
    4235             :         /* Create a TEMPLATE_ID_EXPR for the type.  */
    4236           0 :         name = build_nt (TEMPLATE_ID_EXPR,
    4237           0 :                          CLASSTYPE_TI_TEMPLATE (name),
    4238           0 :                          CLASSTYPE_TI_ARGS (name));
    4239             :     }
    4240    87542482 :   else if (TREE_CODE (name) == TYPE_DECL)
    4241           0 :     name = DECL_NAME (name);
    4242             : 
    4243    87542482 :   fullname = name;
    4244             : 
    4245    87542482 :   if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    4246             :     {
    4247     3257918 :       name = TREE_OPERAND (name, 0);
    4248     3257918 :       if (DECL_TYPE_TEMPLATE_P (name))
    4249           0 :         name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
    4250     3257918 :       if (TREE_CODE (name) != IDENTIFIER_NODE)
    4251             :         {
    4252           0 :           if (complain & tf_error)
    4253           0 :             error ("%qD is not a type", name);
    4254           0 :           return error_mark_node;
    4255             :         }
    4256             :     }
    4257    87542482 :   if (TREE_CODE (name) == TEMPLATE_DECL)
    4258             :     {
    4259           0 :       if (complain & tf_error)
    4260           0 :         error ("%qD used without template arguments", name);
    4261           0 :       return error_mark_node;
    4262             :     }
    4263    87542482 :   else if (is_overloaded_fn (name))
    4264             :     {
    4265           1 :       if (complain & tf_error)
    4266           1 :         error ("%qD is a function, not a type", name);
    4267           1 :       return error_mark_node;
    4268             :     }
    4269    87542481 :   gcc_assert (identifier_p (name));
    4270    87542481 :   gcc_assert (TYPE_P (context));
    4271             : 
    4272    87542481 :   if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
    4273             :     /* This can happen for C++17 variadic using (c++/88986).  */;
    4274    79873604 :   else if (!MAYBE_CLASS_TYPE_P (context))
    4275             :     {
    4276           6 :       if (complain & tf_error)
    4277           6 :         error ("%q#T is not a class", context);
    4278           6 :       return error_mark_node;
    4279             :     }
    4280             : 
    4281             :   /* When the CONTEXT is a dependent type,  NAME could refer to a
    4282             :      dependent base class of CONTEXT.  But look inside it anyway
    4283             :      if CONTEXT is a currently open scope, in case it refers to a
    4284             :      member of the current instantiation or a non-dependent base;
    4285             :      lookup will stop when we hit a dependent base.  */
    4286    87542475 :   if (!dependent_scope_p (context))
    4287             :     {
    4288             :       /* We generally don't ignore non-types during TYPENAME_TYPE lookup
    4289             :          (as per [temp.res.general]/3), unless
    4290             :            - the tag corresponds to a class-key or 'enum' so
    4291             :              [basic.lookup.elab] applies, or
    4292             :            - the tag corresponds to scope_type or tf_qualifying_scope is
    4293             :              set so [basic.lookup.qual]/1 applies.
    4294             :          TODO: If we'd set/track the scope_type tag thoroughly on all
    4295             :          TYPENAME_TYPEs that are followed by :: then we wouldn't need the
    4296             :          tf_qualifying_scope flag.  */
    4297   103597132 :       bool want_type = (tag_type != none_type && tag_type != typename_type)
    4298    51798566 :         || (complain & tf_qualifying_scope);
    4299    51798566 :       t = lookup_member (context, name, /*protect=*/2, want_type, complain);
    4300             :     }
    4301             :   else
    4302             :     t = NULL_TREE;
    4303             : 
    4304    98182753 :   if ((!t || TREE_CODE (t) == TREE_LIST) && dependent_type_p (context))
    4305    35744974 :     return build_typename_type (context, name, fullname, tag_type);
    4306             : 
    4307    51797501 :   want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
    4308             :   
    4309    51797501 :   if (!t)
    4310             :     {
    4311    10639213 :       if (complain & tf_error)
    4312             :         {
    4313         198 :           if (!COMPLETE_TYPE_P (context))
    4314          22 :             cxx_incomplete_type_error (NULL_TREE, context);
    4315             :           else
    4316         351 :             error (want_template ? G_("no class template named %q#T in %q#T")
    4317             :                    : G_("no type named %q#T in %q#T"), name, context);
    4318             :         }
    4319    10639213 :       return error_mark_node;
    4320             :     }
    4321             :   
    4322             :   /* Pull out the template from an injected-class-name (or multiple).  */
    4323    41158288 :   if (want_template)
    4324     2542006 :     t = maybe_get_template_decl_from_type_decl (t);
    4325             : 
    4326    41158288 :   if (TREE_CODE (t) == TREE_LIST)
    4327             :     {
    4328           4 :       if (complain & tf_error)
    4329             :         {
    4330           4 :           error ("lookup of %qT in %qT is ambiguous", name, context);
    4331           4 :           print_candidates (t);
    4332             :         }
    4333           4 :       return error_mark_node;
    4334             :     }
    4335             : 
    4336    41158284 :   if (want_template && !DECL_TYPE_TEMPLATE_P (t))
    4337             :     {
    4338           7 :       if (complain & tf_error)
    4339           7 :         error ("%<typename %T::%D%> names %q#T, which is not a class template",
    4340             :                context, name, t);
    4341           7 :       return error_mark_node;
    4342             :     }
    4343    41158277 :   if (!want_template && TREE_CODE (t) != TYPE_DECL)
    4344             :     {
    4345          16 :       if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
    4346          42 :           && DECL_TYPE_TEMPLATE_P (t))
    4347             :         /* The caller permits this typename-specifier to name a template
    4348             :            (because it appears in a CTAD-enabled context).  */;
    4349             :       else
    4350             :         {
    4351          24 :           if (complain & tf_error)
    4352          16 :             error ("%<typename %T::%D%> names %q#D, which is not a type",
    4353             :                    context, name, t);
    4354          24 :           return error_mark_node;
    4355             :         }
    4356             :     }
    4357             : 
    4358    41158253 :   if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
    4359             :                                             context, complain))
    4360          25 :     return error_mark_node;
    4361             : 
    4362    41158228 :   if (!want_template && DECL_TYPE_TEMPLATE_P (t))
    4363           8 :     return make_template_placeholder (t);
    4364             : 
    4365    41158220 :   if (want_template)
    4366             :     {
    4367     2541999 :       t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
    4368             :                                  NULL_TREE, context,
    4369             :                                  /*entering_scope=*/0,
    4370             :                                  complain | tf_user);
    4371     2541999 :       if (t == error_mark_node)
    4372             :         return error_mark_node;
    4373     2541994 :       t = TYPE_NAME (t);
    4374             :     }
    4375             :   
    4376    41158215 :   if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
    4377     2027767 :     t = TREE_TYPE (t);
    4378             : 
    4379    41158215 :   maybe_record_typedef_use (t);
    4380             : 
    4381    41158215 :   return t;
    4382             : }
    4383             : 
    4384             : /* Resolve `CONTEXT::template NAME'.  Returns a TEMPLATE_DECL if the name
    4385             :    can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
    4386             :    in which case error_mark_node is returned.
    4387             : 
    4388             :    If PARM_LIST is non-NULL, also make sure that the template parameter
    4389             :    list of TEMPLATE_DECL matches.
    4390             : 
    4391             :    If COMPLAIN zero, don't complain about any errors that occur.  */
    4392             : 
    4393             : tree
    4394       39982 : make_unbound_class_template (tree context, tree name, tree parm_list,
    4395             :                              tsubst_flags_t complain)
    4396             : {
    4397       39982 :   if (TYPE_P (name))
    4398           0 :     name = TYPE_IDENTIFIER (name);
    4399       39982 :   else if (DECL_P (name))
    4400           0 :     name = DECL_NAME (name);
    4401       39982 :   gcc_assert (identifier_p (name));
    4402             : 
    4403       39982 :   if (!dependent_type_p (context)
    4404       39982 :       || currently_open_class (context))
    4405             :     {
    4406        5437 :       tree tmpl = NULL_TREE;
    4407             : 
    4408        5437 :       if (MAYBE_CLASS_TYPE_P (context))
    4409        5429 :         tmpl = lookup_field (context, name, 0, false);
    4410             : 
    4411        5429 :       if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
    4412           4 :         tmpl = maybe_get_template_decl_from_type_decl (tmpl);
    4413             : 
    4414        5425 :       if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
    4415             :         {
    4416          12 :           if (complain & tf_error)
    4417           8 :             error ("no class template named %q#T in %q#T", name, context);
    4418          12 :           return error_mark_node;
    4419             :         }
    4420             : 
    4421        5425 :       if (parm_list
    4422        5425 :           && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
    4423             :         {
    4424           0 :           if (complain & tf_error)
    4425             :             {
    4426           0 :               error ("template parameters do not match template %qD", tmpl);
    4427           0 :               inform (DECL_SOURCE_LOCATION (tmpl),
    4428             :                       "%qD declared here", tmpl);
    4429             :             }
    4430           0 :           return error_mark_node;
    4431             :         }
    4432             : 
    4433        5425 :       if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
    4434             :                                           complain))
    4435           0 :         return error_mark_node;
    4436             : 
    4437             :       return tmpl;
    4438             :     }
    4439             : 
    4440       34545 :   return make_unbound_class_template_raw (context, name, parm_list);
    4441             : }
    4442             : 
    4443             : /* Build an UNBOUND_CLASS_TEMPLATE.  */
    4444             : 
    4445             : tree
    4446       34608 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
    4447             : {
    4448             :   /* Build the UNBOUND_CLASS_TEMPLATE.  */
    4449       34608 :   tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
    4450       34608 :   TYPE_CONTEXT (t) = FROB_CONTEXT (context);
    4451       34608 :   TREE_TYPE (t) = NULL_TREE;
    4452       34608 :   SET_TYPE_STRUCTURAL_EQUALITY (t);
    4453             : 
    4454             :   /* Build the corresponding TEMPLATE_DECL.  */
    4455       34608 :   tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
    4456       34608 :   TYPE_NAME (t) = d;
    4457       34608 :   TYPE_STUB_DECL (t) = d;
    4458       34608 :   DECL_CONTEXT (d) = TYPE_CONTEXT (t);
    4459       34608 :   DECL_ARTIFICIAL (d) = 1;
    4460       34608 :   DECL_TEMPLATE_PARMS (d) = parm_list;
    4461             : 
    4462       34608 :   return t;
    4463             : }
    4464             : 
    4465             : 
    4466             : 
    4467             : /* Push the declarations of builtin types into the global namespace.
    4468             :    RID_INDEX is the index of the builtin type in the array
    4469             :    RID_POINTERS.  NAME is the name used when looking up the builtin
    4470             :    type.  TYPE is the _TYPE node for the builtin type.
    4471             : 
    4472             :    The calls to set_global_binding below should be
    4473             :    eliminated.  Built-in types should not be looked up name; their
    4474             :    names are keywords that the parser can recognize.  However, there
    4475             :    is code in c-common.cc that uses identifier_global_value to look up
    4476             :    built-in types by name.  */
    4477             : 
    4478             : void
    4479     3566966 : record_builtin_type (enum rid rid_index,
    4480             :                      const char* name,
    4481             :                      tree type)
    4482             : {
    4483     3566966 :   tree decl = NULL_TREE;
    4484             : 
    4485     3566966 :   if (name)
    4486             :     {
    4487     2138825 :       tree tname = get_identifier (name);
    4488     2138825 :       tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
    4489     2138825 :       DECL_ARTIFICIAL (tdecl) = 1;
    4490     2138825 :       set_global_binding (tdecl);
    4491     2138825 :       decl = tdecl;
    4492             :     }
    4493             : 
    4494     3566966 :   if ((int) rid_index < (int) RID_MAX)
    4495     2138806 :     if (tree rname = ridpointers[(int) rid_index])
    4496     1692506 :       if (!decl || DECL_NAME (decl) != rname)
    4497             :         {
    4498     1249621 :           tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
    4499     1249621 :           DECL_ARTIFICIAL (rdecl) = 1;
    4500     1249621 :           set_global_binding (rdecl);
    4501     1249621 :           if (!decl)
    4502             :             decl = rdecl;
    4503             :         }
    4504             : 
    4505     3299186 :   if (decl)
    4506             :     {
    4507     3120666 :       if (!TYPE_NAME (type))
    4508     2585106 :         TYPE_NAME (type) = decl;
    4509     3120666 :       debug_hooks->type_decl (decl, 0);
    4510             :     }
    4511     3566966 : }
    4512             : 
    4513             : /* Push a type into the namespace so that the back ends ignore it.  */
    4514             : 
    4515             : static void
    4516      267780 : record_unknown_type (tree type, const char* name)
    4517             : {
    4518      267780 :   tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
    4519             :                                     TYPE_DECL, get_identifier (name), type));
    4520             :   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
    4521      267780 :   DECL_IGNORED_P (decl) = 1;
    4522      267780 :   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    4523      267780 :   TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
    4524      267780 :   SET_TYPE_ALIGN (type, 1);
    4525      267780 :   TYPE_USER_ALIGN (type) = 0;
    4526      267780 :   SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
    4527      267780 : }
    4528             : 
    4529             : /* Create all the predefined identifiers.  */
    4530             : 
    4531             : static void
    4532       89260 : initialize_predefined_identifiers (void)
    4533             : {
    4534       89260 :   struct predefined_identifier
    4535             :   {
    4536             :     const char *name; /* Name.  */
    4537             :     tree *node;  /* Node to store it in.  */
    4538             :     cp_identifier_kind kind;  /* Kind of identifier.  */
    4539             :   };
    4540             : 
    4541             :   /* A table of identifiers to create at startup.  */
    4542       89260 :   static const predefined_identifier predefined_identifiers[] = {
    4543             :     {"C++", &lang_name_cplusplus, cik_normal},
    4544             :     {"C", &lang_name_c, cik_normal},
    4545             :     /* Some of these names have a trailing space so that it is
    4546             :        impossible for them to conflict with names written by users.  */
    4547             :     {"__ct ", &ctor_identifier, cik_ctor},
    4548             :     {"__ct_base ", &base_ctor_identifier, cik_ctor},
    4549             :     {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
    4550             :     {"__dt ", &dtor_identifier, cik_dtor},
    4551             :     {"__dt_base ", &base_dtor_identifier, cik_dtor},
    4552             :     {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
    4553             :     {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
    4554             :     {"__conv_op ", &conv_op_identifier, cik_conv_op},
    4555             :     {"__in_chrg", &in_charge_identifier, cik_normal},
    4556             :     {"__as_base ", &as_base_identifier, cik_normal},
    4557             :     {"this", &this_identifier, cik_normal},
    4558             :     {"__delta", &delta_identifier, cik_normal},
    4559             :     {"__pfn", &pfn_identifier, cik_normal},
    4560             :     {"_vptr", &vptr_identifier, cik_normal},
    4561             :     {"__vtt_parm", &vtt_parm_identifier, cik_normal},
    4562             :     {"::", &global_identifier, cik_normal},
    4563             :       /* The demangler expects anonymous namespaces to be called
    4564             :          something starting with '_GLOBAL__N_'.  It no longer needs
    4565             :          to be unique to the TU.  */
    4566             :     {"_GLOBAL__N_1", &anon_identifier, cik_normal},
    4567             :     {"auto", &auto_identifier, cik_normal},
    4568             :     {"decltype(auto)", &decltype_auto_identifier, cik_normal},
    4569             :     {"initializer_list", &init_list_identifier, cik_normal},
    4570             :     {"__for_range ", &for_range__identifier, cik_normal},
    4571             :     {"__for_begin ", &for_begin__identifier, cik_normal},
    4572             :     {"__for_end ", &for_end__identifier, cik_normal},
    4573             :     {"__for_range", &for_range_identifier, cik_normal},
    4574             :     {"__for_begin", &for_begin_identifier, cik_normal},
    4575             :     {"__for_end", &for_end_identifier, cik_normal},
    4576             :     {"abi_tag", &abi_tag_identifier, cik_normal},
    4577             :     {"aligned", &aligned_identifier, cik_normal},
    4578             :     {"begin", &begin_identifier, cik_normal},
    4579             :     {"end", &end_identifier, cik_normal},
    4580             :     {"get", &get__identifier, cik_normal},
    4581             :     {"gnu", &gnu_identifier, cik_normal},
    4582             :     {"tuple_element", &tuple_element_identifier, cik_normal},
    4583             :     {"tuple_size", &tuple_size_identifier, cik_normal},
    4584             :     {"type", &type_identifier, cik_normal},
    4585             :     {"value", &value_identifier, cik_normal},
    4586             :     {"_FUN", &fun_identifier, cik_normal},
    4587             :     {"__closure", &closure_identifier, cik_normal},
    4588             :     {"heap uninit", &heap_uninit_identifier, cik_normal},
    4589             :     {"heap ", &heap_identifier, cik_normal},
    4590             :     {"heap deleted", &heap_deleted_identifier, cik_normal},
    4591             :     {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
    4592             :     {"heap []", &heap_vec_identifier, cik_normal},
    4593             :     {"omp", &omp_identifier, cik_normal},
    4594             :     {NULL, NULL, cik_normal}
    4595             :   };
    4596             : 
    4597     4195220 :   for (const predefined_identifier *pid = predefined_identifiers;
    4598     4195220 :        pid->name; ++pid)
    4599             :     {
    4600     4105960 :       *pid->node = get_identifier (pid->name);
    4601             :       /* Some of these identifiers already have a special kind.  */
    4602     4105960 :       if (pid->kind != cik_normal)
    4603      714080 :         set_identifier_kind (*pid->node, pid->kind);
    4604             :     }
    4605       89260 : }
    4606             : 
    4607             : /* Create the predefined scalar types of C,
    4608             :    and some nodes representing standard constants (0, 1, (void *)0).
    4609             :    Initialize the global binding level.
    4610             :    Make definitions for built-in primitive functions.  */
    4611             : 
    4612             : void
    4613       89260 : cxx_init_decl_processing (void)
    4614             : {
    4615       89260 :   tree void_ftype;
    4616       89260 :   tree void_ftype_ptr;
    4617             : 
    4618             :   /* Create all the identifiers we need.  */
    4619       89260 :   initialize_predefined_identifiers ();
    4620             : 
    4621             :   /* Create the global variables.  */
    4622       89260 :   push_to_top_level ();
    4623             : 
    4624       89260 :   current_function_decl = NULL_TREE;
    4625       89260 :   current_binding_level = NULL;
    4626             :   /* Enter the global namespace.  */
    4627       89260 :   gcc_assert (global_namespace == NULL_TREE);
    4628       89260 :   global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
    4629             :                                       void_type_node);
    4630       89260 :   TREE_PUBLIC (global_namespace) = true;
    4631       89260 :   DECL_MODULE_EXPORT_P (global_namespace) = true;
    4632       89260 :   DECL_CONTEXT (global_namespace)
    4633       89260 :     = build_translation_unit_decl (get_identifier (main_input_filename));
    4634             :   /* Remember whether we want the empty class passing ABI change warning
    4635             :      in this TU.  */
    4636       89260 :   TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
    4637       89881 :     = warn_abi && abi_version_crosses (12);
    4638       89260 :   debug_hooks->register_main_translation_unit
    4639       89260 :     (DECL_CONTEXT (global_namespace));
    4640       89260 :   begin_scope (sk_namespace, global_namespace);
    4641       89260 :   current_namespace = global_namespace;
    4642             : 
    4643       89260 :   if (flag_visibility_ms_compat)
    4644           8 :     default_visibility = VISIBILITY_HIDDEN;
    4645             : 
    4646             :   /* Initially, C.  */
    4647       89260 :   current_lang_name = lang_name_c;
    4648             : 
    4649             :   /* Create the `std' namespace.  */
    4650       89260 :   push_namespace (get_identifier ("std"));
    4651       89260 :   std_node = current_namespace;
    4652       89260 :   pop_namespace ();
    4653             : 
    4654       89260 :   flag_noexcept_type = (cxx_dialect >= cxx17);
    4655             : 
    4656       89260 :   c_common_nodes_and_builtins ();
    4657             : 
    4658       89260 :   tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
    4659       89260 :   tree decl
    4660       89260 :     = add_builtin_function ("__builtin_is_constant_evaluated",
    4661             :                             bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
    4662             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4663       89260 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4664             : 
    4665             :   /* The concrete return type of __builtin_source_location is
    4666             :      const std::source_location::__impl*, but we can't form the type
    4667             :      at this point.  So we initially declare it with an auto return
    4668             :      type which we then "deduce" from require_deduced_type upon first use.  */
    4669       89260 :   tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
    4670       89260 :   decl = add_builtin_function ("__builtin_source_location",
    4671             :                                auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
    4672             :                                BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4673       89260 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4674             : 
    4675       89260 :   tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
    4676             :                                                         NULL_TREE);
    4677       89260 :   decl
    4678       89260 :     = add_builtin_function ("__builtin_is_corresponding_member",
    4679             :                             bool_vaftype,
    4680             :                             CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
    4681             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4682       89260 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4683             : 
    4684       89260 :   decl
    4685       89260 :     = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
    4686             :                             bool_vaftype,
    4687             :                             CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
    4688             :                             BUILT_IN_FRONTEND, NULL, NULL_TREE);
    4689       89260 :   set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
    4690             : 
    4691       89260 :   integer_two_node = build_int_cst (NULL_TREE, 2);
    4692             : 
    4693             :   /* Guess at the initial static decls size.  */
    4694       89260 :   vec_alloc (static_decls, 500);
    4695             : 
    4696             :   /* ... and keyed classes.  */
    4697       89260 :   vec_alloc (keyed_classes, 100);
    4698             : 
    4699       89260 :   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
    4700       89260 :   truthvalue_type_node = boolean_type_node;
    4701       89260 :   truthvalue_false_node = boolean_false_node;
    4702       89260 :   truthvalue_true_node = boolean_true_node;
    4703             : 
    4704       89260 :   empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
    4705       89260 :   noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
    4706       89260 :   noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
    4707       89260 :   noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
    4708             :                                             NULL_TREE);
    4709             : 
    4710             : #if 0
    4711             :   record_builtin_type (RID_MAX, NULL, string_type_node);
    4712             : #endif
    4713             : 
    4714       89260 :   delta_type_node = ptrdiff_type_node;
    4715       89260 :   vtable_index_type = ptrdiff_type_node;
    4716             : 
    4717       89260 :   vtt_parm_type = build_pointer_type (const_ptr_type_node);
    4718       89260 :   void_ftype = build_function_type_list (void_type_node, NULL_TREE);
    4719       89260 :   void_ftype_ptr = build_function_type_list (void_type_node,
    4720             :                                              ptr_type_node, NULL_TREE);
    4721       89260 :   void_ftype_ptr
    4722       89260 :     = build_exception_variant (void_ftype_ptr, empty_except_spec);
    4723             : 
    4724             :   /* Create the conversion operator marker.  This operator's DECL_NAME
    4725             :      is in the identifier table, so we can use identifier equality to
    4726             :      find it.  */
    4727       89260 :   conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
    4728             :                                     void_ftype);
    4729             : 
    4730             :   /* C++ extensions */
    4731             : 
    4732       89260 :   unknown_type_node = make_node (LANG_TYPE);
    4733       89260 :   record_unknown_type (unknown_type_node, "unknown type");
    4734             : 
    4735             :   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
    4736       89260 :   TREE_TYPE (unknown_type_node) = unknown_type_node;
    4737             : 
    4738             :   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
    4739             :      result.  */
    4740       89260 :   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
    4741       89260 :   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
    4742             : 
    4743       89260 :   init_list_type_node = make_node (LANG_TYPE);
    4744       89260 :   record_unknown_type (init_list_type_node, "init list");
    4745             : 
    4746             :   /* Used when parsing to distinguish parameter-lists () and (void).  */
    4747       89260 :   explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
    4748             : 
    4749       89260 :   {
    4750             :     /* Make sure we get a unique function type, so we can give
    4751             :        its pointer type a name.  (This wins for gdb.) */
    4752       89260 :     tree vfunc_type = make_node (FUNCTION_TYPE);
    4753       89260 :     TREE_TYPE (vfunc_type) = integer_type_node;
    4754       89260 :     TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
    4755       89260 :     layout_type (vfunc_type);
    4756             : 
    4757       89260 :     vtable_entry_type = build_pointer_type (vfunc_type);
    4758             :   }
    4759       89260 :   record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
    4760             : 
    4761       89260 :   vtbl_type_node
    4762       89260 :     = build_cplus_array_type (vtable_entry_type, NULL_TREE);
    4763       89260 :   layout_type (vtbl_type_node);
    4764       89260 :   vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
    4765       89260 :   record_builtin_type (RID_MAX, NULL, vtbl_type_node);
    4766       89260 :   vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
    4767       89260 :   layout_type (vtbl_ptr_type_node);
    4768       89260 :   record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
    4769             : 
    4770       89260 :   push_namespace (get_identifier ("__cxxabiv1"));
    4771       89260 :   abi_node = current_namespace;
    4772       89260 :   pop_namespace ();
    4773             : 
    4774       89260 :   any_targ_node = make_node (LANG_TYPE);
    4775       89260 :   record_unknown_type (any_targ_node, "any type");
    4776             : 
    4777             :   /* Now, C++.  */
    4778       89260 :   current_lang_name = lang_name_cplusplus;
    4779             : 
    4780       89260 :   if (aligned_new_threshold > 1
    4781       89260 :       && !pow2p_hwi (aligned_new_threshold))
    4782             :     {
    4783           0 :       error ("%<-faligned-new=%d%> is not a power of two",
    4784             :              aligned_new_threshold);
    4785           0 :       aligned_new_threshold = 1;
    4786             :     }
    4787       89260 :   if (aligned_new_threshold == -1)
    4788      120329 :     aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
    4789       89260 :   if (aligned_new_threshold == 1)
    4790       58176 :     aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
    4791             : 
    4792       89260 :   {
    4793       89260 :     tree newattrs, extvisattr;
    4794       89260 :     tree newtype, deltype;
    4795       89260 :     tree ptr_ftype_sizetype;
    4796       89260 :     tree new_eh_spec;
    4797             : 
    4798       89260 :     ptr_ftype_sizetype
    4799       89260 :       = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
    4800       89260 :     if (cxx_dialect == cxx98)
    4801             :       {
    4802       12669 :         tree bad_alloc_id;
    4803       12669 :         tree bad_alloc_type_node;
    4804       12669 :         tree bad_alloc_decl;
    4805             : 
    4806       12669 :         push_nested_namespace (std_node);
    4807       12669 :         bad_alloc_id = get_identifier ("bad_alloc");
    4808       12669 :         bad_alloc_type_node = make_class_type (RECORD_TYPE);
    4809       12669 :         TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
    4810       12669 :         bad_alloc_decl
    4811       12669 :           = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
    4812       12669 :         DECL_CONTEXT (bad_alloc_decl) = current_namespace;
    4813       12669 :         pop_nested_namespace (std_node);
    4814             : 
    4815       12669 :         new_eh_spec
    4816       12669 :           = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
    4817             :       }
    4818             :     else
    4819       76591 :       new_eh_spec = noexcept_false_spec;
    4820             : 
    4821             :     /* Ensure attribs.cc is initialized.  */
    4822       89260 :     init_attributes ();
    4823             : 
    4824       89260 :     extvisattr = build_tree_list (get_identifier ("externally_visible"),
    4825             :                                   NULL_TREE);
    4826       89260 :     newattrs = tree_cons (get_identifier ("alloc_size"),
    4827             :                           build_tree_list (NULL_TREE, integer_one_node),
    4828             :                           extvisattr);
    4829       89260 :     newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
    4830       89260 :     newtype = build_exception_variant (newtype, new_eh_spec);
    4831       89260 :     deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
    4832       89260 :     deltype = build_exception_variant (deltype, empty_except_spec);
    4833       89260 :     tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4834       89260 :     DECL_IS_MALLOC (opnew) = 1;
    4835       89260 :     DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4836       89260 :     DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4837       89260 :     opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4838       89260 :     DECL_IS_MALLOC (opnew) = 1;
    4839       89260 :     DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4840       89260 :     DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4841       89260 :     tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4842       89260 :     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4843       89260 :     DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4844       89260 :     opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4845       89260 :     DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4846       89260 :     DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4847       89260 :     if (flag_sized_deallocation)
    4848             :       {
    4849             :         /* Also push the sized deallocation variants:
    4850             :              void operator delete(void*, std::size_t) throw();
    4851             :              void operator delete[](void*, std::size_t) throw();  */
    4852       75769 :         tree void_ftype_ptr_size
    4853       75769 :           = build_function_type_list (void_type_node, ptr_type_node,
    4854             :                                       size_type_node, NULL_TREE);
    4855       75769 :         deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
    4856             :                                                    extvisattr);
    4857       75769 :         deltype = build_exception_variant (deltype, empty_except_spec);
    4858       75769 :         opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4859       75769 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4860       75769 :         DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4861       75769 :         opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4862       75769 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4863       75769 :         DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4864             :       }
    4865             : 
    4866       89260 :     if (aligned_new_threshold)
    4867             :       {
    4868       58178 :         push_nested_namespace (std_node);
    4869       58178 :         tree align_id = get_identifier ("align_val_t");
    4870       58178 :         align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
    4871             :                                       NULL_TREE, /*scoped*/true, NULL);
    4872       58178 :         pop_nested_namespace (std_node);
    4873             : 
    4874             :         /* operator new (size_t, align_val_t); */
    4875       58178 :         newtype = build_function_type_list (ptr_type_node, size_type_node,
    4876             :                                             align_type_node, NULL_TREE);
    4877       58178 :         newtype = cp_build_type_attribute_variant (newtype, newattrs);
    4878       58178 :         newtype = build_exception_variant (newtype, new_eh_spec);
    4879       58178 :         opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
    4880       58178 :         DECL_IS_MALLOC (opnew) = 1;
    4881       58178 :         DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4882       58178 :         DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4883       58178 :         opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
    4884       58178 :         DECL_IS_MALLOC (opnew) = 1;
    4885       58178 :         DECL_SET_IS_OPERATOR_NEW (opnew, true);
    4886       58178 :         DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
    4887             : 
    4888             :         /* operator delete (void *, align_val_t); */
    4889       58178 :         deltype = build_function_type_list (void_type_node, ptr_type_node,
    4890             :                                             align_type_node, NULL_TREE);
    4891       58178 :         deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4892       58178 :         deltype = build_exception_variant (deltype, empty_except_spec);
    4893       58178 :         opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4894       58178 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4895       58178 :         DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4896       58178 :         opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4897       58178 :         DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4898       58178 :         DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4899             : 
    4900       58178 :         if (flag_sized_deallocation)
    4901             :           {
    4902             :             /* operator delete (void *, size_t, align_val_t); */
    4903       58175 :             deltype = build_function_type_list (void_type_node, ptr_type_node,
    4904             :                                                 size_type_node, align_type_node,
    4905             :                                                 NULL_TREE);
    4906       58175 :             deltype = cp_build_type_attribute_variant (deltype, extvisattr);
    4907       58175 :             deltype = build_exception_variant (deltype, empty_except_spec);
    4908       58175 :             opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
    4909       58175 :             DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4910       58175 :             DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4911       58175 :             opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
    4912       58175 :             DECL_SET_IS_OPERATOR_DELETE (opdel, true);
    4913       58175 :             DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
    4914             :           }
    4915             :       }
    4916             : 
    4917             :     /* C++-specific nullptr initialization.  */
    4918       89260 :     if (abi_version_at_least (9))
    4919       89070 :       SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
    4920       89260 :     record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
    4921             :   }
    4922             : 
    4923       89260 :   if (! supports_one_only ())
    4924           0 :     flag_weak = 0;
    4925             : 
    4926       89260 :   abort_fndecl
    4927       89260 :     = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
    4928             :                             ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
    4929       89260 :   if (flag_weak)
    4930             :     /* If no definition is available, resolve references to NULL.  */
    4931       89223 :     declare_weak (abort_fndecl);
    4932             : 
    4933             :   /* Perform other language dependent initializations.  */
    4934       89260 :   init_class_processing ();
    4935       89260 :   init_rtti_processing ();
    4936       89260 :   init_template_processing ();
    4937             : 
    4938       89260 :   if (flag_exceptions)
    4939       88336 :     init_exception_processing ();
    4940             : 
    4941       89260 :   if (modules_p ())
    4942        2882 :     init_modules (parse_in);
    4943             : 
    4944       89260 :   make_fname_decl = cp_make_fname_decl;
    4945       89260 :   start_fname_decls ();
    4946             : 
    4947             :   /* Show we use EH for cleanups.  */
    4948       89260 :   if (flag_exceptions)
    4949       88336 :     using_eh_for_cleanups ();
    4950             : 
    4951             :   /* Check that the hardware interference sizes are at least
    4952             :      alignof(max_align_t), as required by the standard.  */
    4953       89260 :   const int max_align = max_align_t_align () / BITS_PER_UNIT;
    4954       89260 :   if (OPTION_SET_P (param_destruct_interfere_size))
    4955             :     {
    4956           0 :       if (param_destruct_interfere_size < max_align)
    4957           0 :         error ("%<--param destructive-interference-size=%d%> is less than "
    4958             :                "%d", param_destruct_interfere_size, max_align);
    4959           0 :       else if (param_destruct_interfere_size < param_l1_cache_line_size)
    4960           0 :         warning (OPT_Winterference_size,
    4961             :                  "%<--param destructive-interference-size=%d%> "
    4962             :                  "is less than %<--param l1-cache-line-size=%d%>",
    4963             :                  param_destruct_interfere_size, param_l1_cache_line_size);
    4964             :     }
    4965       89260 :   else if (param_destruct_interfere_size)
    4966             :     /* Assume the internal value is OK.  */;
    4967           0 :   else if (param_l1_cache_line_size >= max_align)
    4968           0 :     param_destruct_interfere_size = param_l1_cache_line_size;
    4969             :   /* else leave it unset.  */
    4970             : 
    4971       89260 :   if (OPTION_SET_P (param_construct_interfere_size))
    4972             :     {
    4973           0 :       if (param_construct_interfere_size < max_align)
    4974           0 :         error ("%<--param constructive-interference-size=%d%> is less than "
    4975             :                "%d", param_construct_interfere_size, max_align);
    4976           0 :       else if (param_construct_interfere_size > param_l1_cache_line_size
    4977           0 :                && param_l1_cache_line_size >= max_align)
    4978           0 :         warning (OPT_Winterference_size,
    4979             :                  "%<--param constructive-interference-size=%d%> "
    4980             :                  "is greater than %<--param l1-cache-line-size=%d%>",
    4981             :                  param_construct_interfere_size, param_l1_cache_line_size);
    4982             :     }
    4983       89260 :   else if (param_construct_interfere_size)
    4984             :     /* Assume the internal value is OK.  */;
    4985           0 :   else if (param_l1_cache_line_size >= max_align)
    4986           0 :     param_construct_interfere_size = param_l1_cache_line_size;
    4987       89260 : }
    4988             : 
    4989             : /* Enter an abi node in global-module context.  returns a cookie to
    4990             :    give to pop_abi_namespace.  */
    4991             : 
    4992             : unsigned
    4993       44985 : push_abi_namespace (tree node)
    4994             : {
    4995       44985 :   push_nested_namespace (node);
    4996       44985 :   push_visibility ("default", 2);
    4997       44985 :   unsigned flags = module_kind;
    4998       44985 :   module_kind = 0;
    4999       44985 :   return flags;
    5000             : }
    5001             : 
    5002             : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
    5003             :    you.  */
    5004             : 
    5005             : void
    5006       44985 : pop_abi_namespace (unsigned flags, tree node)
    5007             : {
    5008       44985 :   module_kind = flags;
    5009       41396 :   pop_visibility (2);
    5010       44985 :   pop_nested_namespace (node);
    5011       41396 : }
    5012             : 
    5013             : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
    5014             :    the decl, LOC is the location to give the decl, NAME is the
    5015             :    initialization string and TYPE_DEP indicates whether NAME depended
    5016             :    on the type of the function. We make use of that to detect
    5017             :    __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
    5018             :    at the point of first use, so we mustn't push the decl now.  */
    5019             : 
    5020             : static tree
    5021       47592 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
    5022             : {
    5023       47592 :   tree domain = NULL_TREE;
    5024       47592 :   tree init = NULL_TREE;
    5025             : 
    5026       47592 :   if (!(type_dep && current_function_decl && in_template_context))
    5027             :     {
    5028       14997 :       const char *name = NULL;
    5029       14997 :       bool release_name = false;
    5030             : 
    5031       14997 :       if (current_function_decl == NULL_TREE)
    5032             :         name = "top level";
    5033       14977 :       else if (type_dep == 0)
    5034             :         {
    5035             :           /* __FUNCTION__ */      
    5036         353 :           name = fname_as_string (type_dep);
    5037         353 :           release_name = true;
    5038             :         }
    5039             :       else
    5040             :         {
    5041             :           /* __PRETTY_FUNCTION__ */
    5042       14624 :           gcc_checking_assert (type_dep == 1);
    5043       14624 :           name = cxx_printable_name (current_function_decl, 2);
    5044             :         }
    5045             : 
    5046       14997 :       size_t length = strlen (name);
    5047       14997 :       domain = build_index_type (size_int (length));
    5048       14997 :       init = build_string (length + 1, name);
    5049       14997 :       if (release_name)
    5050         353 :         free (const_cast<char *> (name));
    5051             :     }
    5052             : 
    5053       47592 :   tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
    5054       47592 :   type = build_cplus_array_type (type, domain);
    5055             : 
    5056       47592 :   if (init)
    5057       14997 :     TREE_TYPE (init) = type;
    5058             :   else
    5059       32595 :     init = error_mark_node;
    5060             : 
    5061       47592 :   tree decl = build_decl (loc, VAR_DECL, id, type);
    5062             : 
    5063       47592 :   TREE_READONLY (decl) = 1;
    5064       47592 :   DECL_ARTIFICIAL (decl) = 1;
    5065       47592 :   DECL_DECLARED_CONSTEXPR_P (decl) = 1;
    5066       47592 :   TREE_STATIC (decl) = 1;
    5067             : 
    5068       47592 :   TREE_USED (decl) = 1;
    5069             : 
    5070       47592 :   SET_DECL_VALUE_EXPR (decl, init);
    5071       47592 :   DECL_HAS_VALUE_EXPR_P (decl) = 1;
    5072             :   /* For decl_constant_var_p.  */
    5073       47592 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    5074             : 
    5075       47592 :   if (current_function_decl)
    5076             :     {
    5077       47572 :       DECL_CONTEXT (decl) = current_function_decl;
    5078       47572 :       decl = pushdecl_outermost_localscope (decl);
    5079       47572 :       if (decl != error_mark_node)
    5080       47568 :         add_decl_expr (decl);
    5081             :     }
    5082             :   else
    5083             :     {
    5084          20 :       DECL_THIS_STATIC (decl) = true;
    5085          20 :       decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
    5086             :     }
    5087             : 
    5088       47592 :   return decl;
    5089             : }
    5090             : 
    5091             : /* Install DECL as a builtin function at current global scope.  Return
    5092             :    the new decl (if we found an existing version).  Also installs it
    5093             :    into ::std, if it's not '_*'.  */
    5094             : 
    5095             : tree
    5096   193110703 : cxx_builtin_function (tree decl)
    5097             : {
    5098   193110703 :   retrofit_lang_decl (decl);
    5099             : 
    5100   193110703 :   DECL_ARTIFICIAL (decl) = 1;
    5101   193110703 :   SET_DECL_LANGUAGE (decl, lang_c);
    5102             :   /* Runtime library routines are, by definition, available in an
    5103             :      external shared object.  */
    5104   193110703 :   DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
    5105   193110703 :   DECL_VISIBILITY_SPECIFIED (decl) = 1;
    5106             : 
    5107   193110703 :   tree id = DECL_NAME (decl);
    5108   193110703 :   const char *name = IDENTIFIER_POINTER (id);
    5109   193110703 :   bool hiding = false;
    5110   193110703 :   if (name[0] != '_' || name[1] != '_')
    5111             :     /* In the user's namespace, it must be declared before use.  */
    5112             :     hiding = true;
    5113   161137106 :   else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
    5114   161137106 :            && !startswith (name + 2, "builtin_")
    5115   181806287 :            && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
    5116             :                            "_chk", strlen ("_chk") + 1))
    5117             :     /* Treat __*_chk fortification functions as anticipated as well,
    5118             :        unless they are __builtin_*_chk.  */
    5119             :     hiding = true;
    5120             : 
    5121             :   /* All builtins that don't begin with an '_' should additionally
    5122             :      go in the 'std' namespace.  */
    5123   193110703 :   if (name[0] != '_')
    5124             :     {
    5125    31853068 :       tree std_decl = copy_decl (decl);
    5126             : 
    5127    31853068 :       push_nested_namespace (std_node);
    5128    31853068 :       DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
    5129    31853068 :       pushdecl (std_decl, hiding);
    5130    31853068 :       pop_nested_namespace (std_node);
    5131             :     }
    5132             : 
    5133   193110703 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5134   193110703 :   decl = pushdecl (decl, hiding);
    5135             : 
    5136   193110703 :   return decl;
    5137             : }
    5138             : 
    5139             : /* Like cxx_builtin_function, but guarantee the function is added to the global
    5140             :    scope.  This is to allow function specific options to add new machine
    5141             :    dependent builtins when the target ISA changes via attribute((target(...)))
    5142             :    which saves space on program startup if the program does not use non-generic
    5143             :    ISAs.  */
    5144             : 
    5145             : tree
    5146      605279 : cxx_builtin_function_ext_scope (tree decl)
    5147             : {
    5148      605279 :   push_nested_namespace (global_namespace);
    5149      605279 :   decl = cxx_builtin_function (decl);
    5150      605279 :   pop_nested_namespace (global_namespace);
    5151             : 
    5152      605279 :   return decl;
    5153             : }
    5154             : 
    5155             : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL.  */
    5156             : 
    5157             : tree
    5158           0 : cxx_simulate_builtin_function_decl (tree decl)
    5159             : {
    5160           0 :   retrofit_lang_decl (decl);
    5161             : 
    5162           0 :   DECL_ARTIFICIAL (decl) = 1;
    5163           0 :   SET_DECL_LANGUAGE (decl, lang_cplusplus);
    5164           0 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    5165           0 :   return pushdecl (decl);
    5166             : }
    5167             : 
    5168             : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
    5169             :    function.  Not called directly.  */
    5170             : 
    5171             : static tree
    5172     1360004 : build_library_fn (tree name, enum tree_code operator_code, tree type,
    5173             :                   int ecf_flags)
    5174             : {
    5175     1360004 :   tree fn = build_lang_decl (FUNCTION_DECL, name, type);
    5176     1360004 :   DECL_EXTERNAL (fn) = 1;
    5177     1360004 :   TREE_PUBLIC (fn) = 1;
    5178     1360004 :   DECL_ARTIFICIAL (fn) = 1;
    5179     1360004 :   DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
    5180     1360004 :     = OVL_OP_INFO (false, operator_code)->ovl_op_code;
    5181     1360004 :   SET_DECL_LANGUAGE (fn, lang_c);
    5182             :   /* Runtime library routines are, by definition, available in an
    5183             :      external shared object.  */
    5184     1360004 :   DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
    5185     1360004 :   DECL_VISIBILITY_SPECIFIED (fn) = 1;
    5186     1360004 :   set_call_expr_flags (fn, ecf_flags);
    5187     1360004 :   return fn;
    5188             : }
    5189             : 
    5190             : /* Returns the _DECL for a library function with C++ linkage.  */
    5191             : 
    5192             : static tree
    5193      946049 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
    5194             :                      int ecf_flags)
    5195             : {
    5196      946049 :   tree fn = build_library_fn (name, operator_code, type, ecf_flags);
    5197      946049 :   DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
    5198      946049 :   SET_DECL_LANGUAGE (fn, lang_cplusplus);
    5199      946049 :   return fn;
    5200             : }
    5201             : 
    5202             : /* Like build_library_fn, but takes a C string instead of an
    5203             :    IDENTIFIER_NODE.  */
    5204             : 
    5205             : tree
    5206       92368 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5207             : {
    5208       92368 :   return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
    5209             : }
    5210             : 
    5211             : /* Like build_cp_library_fn, but takes a C string instead of an
    5212             :    IDENTIFIER_NODE.  */
    5213             : 
    5214             : tree
    5215       88409 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
    5216             : {
    5217       88409 :   return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
    5218       88409 :                               ecf_flags);
    5219             : }
    5220             : 
    5221             : /* Like build_library_fn, but also pushes the function so that we will
    5222             :    be able to find it via get_global_binding.  Also, the function
    5223             :    may throw exceptions listed in RAISES.  */
    5224             : 
    5225             : tree
    5226      321587 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
    5227             : {
    5228      321587 :   if (raises)
    5229       30748 :     type = build_exception_variant (type, raises);
    5230             : 
    5231      321587 :   tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
    5232      321587 :   return pushdecl_top_level (fn);
    5233             : }
    5234             : 
    5235             : /* Like build_cp_library_fn, but also pushes the function so that it
    5236             :    will be found by normal lookup.  */
    5237             : 
    5238             : static tree
    5239      857640 : push_cp_library_fn (enum tree_code operator_code, tree type,
    5240             :                     int ecf_flags)
    5241             : {
    5242      857640 :   tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
    5243             :                                  operator_code, type, ecf_flags);
    5244      857640 :   pushdecl (fn);
    5245      857640 :   if (flag_tm)
    5246        3328 :     apply_tm_attr (fn, get_identifier ("transaction_safe"));
    5247      857640 :   return fn;
    5248             : }
    5249             : 
    5250             : /* Like push_library_fn, but also note that this function throws
    5251             :    and does not return.  Used for __throw_foo and the like.  */
    5252             : 
    5253             : tree
    5254       96521 : push_throw_library_fn (tree name, tree type)
    5255             : {
    5256       96521 :   tree fn = push_library_fn (name, type, NULL_TREE, ECF_NORETURN | ECF_COLD);
    5257       96521 :   return fn;
    5258             : }
    5259             : 
    5260             : /* When we call finish_struct for an anonymous union, we create
    5261             :    default copy constructors and such.  But, an anonymous union
    5262             :    shouldn't have such things; this function undoes the damage to the
    5263             :    anonymous union type T.
    5264             : 
    5265             :    (The reason that we create the synthesized methods is that we don't
    5266             :    distinguish `union { int i; }' from `typedef union { int i; } U'.
    5267             :    The first is an anonymous union; the second is just an ordinary
    5268             :    union type.)  */
    5269             : 
    5270             : void
    5271       56924 : fixup_anonymous_aggr (tree t)
    5272             : {
    5273             :   /* Wipe out memory of synthesized methods.  */
    5274       56924 :   TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
    5275       56924 :   TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
    5276       56924 :   TYPE_HAS_COPY_CTOR (t) = 0;
    5277       56924 :   TYPE_HAS_CONST_COPY_CTOR (t) = 0;
    5278       56924 :   TYPE_HAS_COPY_ASSIGN (t) = 0;
    5279       56924 :   TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
    5280             : 
    5281             :   /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
    5282             :      invalid members.  */
    5283      276978 :   for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
    5284             :     {
    5285      220054 :       if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
    5286           0 :         *prev_p = DECL_CHAIN (probe);
    5287             :       else
    5288      220054 :         prev_p = &DECL_CHAIN (probe);
    5289             : 
    5290      220054 :       if (DECL_ARTIFICIAL (probe)
    5291      220054 :           && (!DECL_IMPLICIT_TYPEDEF_P (probe)
    5292       28696 :               || TYPE_ANON_P (TREE_TYPE (probe))))
    5293       82279 :         continue;
    5294             : 
    5295      137775 :       if (TREE_CODE (probe) != FIELD_DECL
    5296      137775 :           || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
    5297             :         {
    5298             :           /* We already complained about static data members in
    5299             :              finish_static_data_member_decl.  */
    5300          87 :           if (!VAR_P (probe))
    5301             :             {
    5302          67 :               auto_diagnostic_group d;
    5303          67 :               if (permerror (DECL_SOURCE_LOCATION (probe),
    5304          67 :                              TREE_CODE (t) == UNION_TYPE
    5305             :                              ? "%q#D invalid; an anonymous union may "
    5306             :                              "only have public non-static data members"
    5307             :                              : "%q#D invalid; an anonymous struct may "
    5308             :                              "only have public non-static data members", probe))
    5309             :                 {
    5310          67 :                   static bool hint;
    5311          67 :                   if (flag_permissive && !hint)
    5312             :                     {
    5313           8 :                       hint = true;
    5314           8 :                       inform (DECL_SOURCE_LOCATION (probe),
    5315             :                               "this flexibility is deprecated and will be "
    5316             :                               "removed");
    5317             :                     }
    5318             :                 }
    5319          67 :             }
    5320             :         }
    5321             :       }
    5322             : 
    5323             :   /* Splice all functions out of CLASSTYPE_MEMBER_VEC.  */
    5324       56924 :   vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
    5325       56924 :   unsigned store = 0;
    5326      108186 :   for (tree elt : vec)
    5327       51262 :     if (!is_overloaded_fn (elt))
    5328       51235 :       (*vec)[store++] = elt;
    5329       56924 :   vec_safe_truncate (vec, store);
    5330             : 
    5331             :   /* Wipe RTTI info.  */
    5332       56924 :   CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
    5333             : 
    5334             :   /* Anonymous aggregates cannot have fields with ctors, dtors or complex
    5335             :      assignment operators (because they cannot have these methods themselves).
    5336             :      For anonymous unions this is already checked because they are not allowed
    5337             :      in any union, otherwise we have to check it.  */
    5338       56924 :   if (TREE_CODE (t) != UNION_TYPE)
    5339             :     {
    5340       14364 :       tree field, type;
    5341             : 
    5342       14364 :       if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
    5343             :         {
    5344          12 :           error_at (location_of (t), "anonymous struct with base classes");
    5345             :           /* Avoid ICE after error on anon-struct9.C.  */
    5346          12 :           TYPE_NEEDS_CONSTRUCTING (t) = false;
    5347             :         }
    5348             : 
    5349       65006 :       for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
    5350       50642 :         if (TREE_CODE (field) == FIELD_DECL)
    5351             :           {
    5352       36159 :             type = TREE_TYPE (field);
    5353       36159 :             if (CLASS_TYPE_P (type))
    5354             :               {
    5355          61 :                 if (TYPE_NEEDS_CONSTRUCTING (type))
    5356           4 :                   error ("member %q+#D with constructor not allowed "
    5357             :                          "in anonymous aggregate", field);
    5358          61 :                 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
    5359           0 :                   error ("member %q+#D with destructor not allowed "
    5360             :                          "in anonymous aggregate", field);
    5361          61 :                 if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
    5362           0 :                   error ("member %q+#D with copy assignment operator "
    5363             :                          "not allowed in anonymous aggregate", field);
    5364             :               }
    5365             :           }
    5366             :     }
    5367       56924 : }
    5368             : 
    5369             : /* Warn for an attribute located at LOCATION that appertains to the
    5370             :    class type CLASS_TYPE that has not been properly placed after its
    5371             :    class-key, in it class-specifier.  */
    5372             : 
    5373             : void
    5374          31 : warn_misplaced_attr_for_class_type (location_t location,
    5375             :                                     tree class_type)
    5376             : {
    5377          31 :   gcc_assert (OVERLOAD_TYPE_P (class_type));
    5378             : 
    5379          31 :   auto_diagnostic_group d;
    5380          31 :   if (warning_at (location, OPT_Wattributes,
    5381             :                   "attribute ignored in declaration "
    5382             :                   "of %q#T", class_type))
    5383          31 :     inform (location,
    5384             :             "attribute for %q#T must follow the %qs keyword",
    5385             :             class_type, class_key_or_enum_as_string (class_type));
    5386          31 : }
    5387             : 
    5388             : /* Returns the cv-qualifiers that apply to the type specified
    5389             :    by the DECLSPECS.  */
    5390             : 
    5391             : static int
    5392   606108103 : get_type_quals (const cp_decl_specifier_seq *declspecs)
    5393             : {
    5394   606108103 :   int type_quals = TYPE_UNQUALIFIED;
    5395             : 
    5396   606108103 :   if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5397    67128706 :     type_quals |= TYPE_QUAL_CONST;
    5398   606108103 :   if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5399     1137520 :     type_quals |= TYPE_QUAL_VOLATILE;
    5400   606108103 :   if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5401          39 :     type_quals |= TYPE_QUAL_RESTRICT;
    5402             : 
    5403   606108103 :   return type_quals;
    5404             : }
    5405             : 
    5406             : /* Make sure that a declaration with no declarator is well-formed, i.e.
    5407             :    just declares a tagged type or anonymous union.
    5408             : 
    5409             :    Returns the type declared; or NULL_TREE if none.  */
    5410             : 
    5411             : tree
    5412    22491757 : check_tag_decl (cp_decl_specifier_seq *declspecs,
    5413             :                 bool explicit_type_instantiation_p)
    5414             : {
    5415    22491757 :   int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
    5416    22491757 :   int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
    5417             :   /* If a class, struct, or enum type is declared by the DECLSPECS
    5418             :      (i.e, if a class-specifier, enum-specifier, or non-typename
    5419             :      elaborated-type-specifier appears in the DECLSPECS),
    5420             :      DECLARED_TYPE is set to the corresponding type.  */
    5421    22491757 :   tree declared_type = NULL_TREE;
    5422    22491757 :   bool error_p = false;
    5423             : 
    5424    22491757 :   if (declspecs->multiple_types_p)
    5425          31 :     error_at (smallest_type_location (declspecs),
    5426             :               "multiple types in one declaration");
    5427    22491726 :   else if (declspecs->redefined_builtin_type)
    5428             :     {
    5429          26 :       location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
    5430          26 :       if (!in_system_header_at (loc))
    5431          10 :         permerror (loc, "redeclaration of C++ built-in type %qT",
    5432             :                    declspecs->redefined_builtin_type);
    5433          26 :       return NULL_TREE;
    5434             :     }
    5435             : 
    5436    22491731 :   if (declspecs->type
    5437    22491714 :       && TYPE_P (declspecs->type)
    5438    44928309 :       && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
    5439    22436460 :            && MAYBE_CLASS_TYPE_P (declspecs->type))
    5440     1161914 :           || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
    5441             :     declared_type = declspecs->type;
    5442       55318 :   else if (declspecs->type == error_mark_node)
    5443         849 :     error_p = true;
    5444             : 
    5445    22491731 :   if (type_uses_auto (declared_type))
    5446             :     {
    5447           9 :       error_at (declspecs->locations[ds_type_spec],
    5448             :                 "%<auto%> can only be specified for variables "
    5449             :                 "or function declarations");
    5450           9 :       return error_mark_node;
    5451             :     }
    5452             : 
    5453    22491722 :   if (declared_type && !OVERLOAD_TYPE_P (declared_type))
    5454             :     declared_type = NULL_TREE;
    5455             : 
    5456    22491722 :   if (!declared_type && !saw_friend && !error_p)
    5457         107 :     permerror (input_location, "declaration does not declare anything");
    5458             :   /* Check for an anonymous union.  */
    5459    22436372 :   else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
    5460    65097793 :            && TYPE_UNNAMED_P (declared_type))
    5461             :     {
    5462             :       /* 7/3 In a simple-declaration, the optional init-declarator-list
    5463             :          can be omitted only when declaring a class (clause 9) or
    5464             :          enumeration (7.2), that is, when the decl-specifier-seq contains
    5465             :          either a class-specifier, an elaborated-type-specifier with
    5466             :          a class-key (9.1), or an enum-specifier.  In these cases and
    5467             :          whenever a class-specifier or enum-specifier is present in the
    5468             :          decl-specifier-seq, the identifiers in these specifiers are among
    5469             :          the names being declared by the declaration (as class-name,
    5470             :          enum-names, or enumerators, depending on the syntax).  In such
    5471             :          cases, and except for the declaration of an unnamed bit-field (9.6),
    5472             :          the decl-specifier-seq shall introduce one or more names into the
    5473             :          program, or shall redeclare a name introduced by a previous
    5474             :          declaration.  [Example:
    5475             :              enum { };                  // ill-formed
    5476             :              typedef class { };         // ill-formed
    5477             :          --end example]  */
    5478       56932 :       if (saw_typedef)
    5479             :         {
    5480           8 :           error_at (declspecs->locations[ds_typedef],
    5481             :                     "missing type-name in typedef-declaration");
    5482           8 :           return NULL_TREE;
    5483             :         }
    5484       56924 :       /* Anonymous unions are objects, so they can have specifiers.  */;
    5485       56924 :       SET_ANON_AGGR_TYPE_P (declared_type);
    5486             : 
    5487       56924 :       if (TREE_CODE (declared_type) != UNION_TYPE)
    5488       14364 :         pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
    5489             :                  OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
    5490             :     }
    5491             : 
    5492             :   else
    5493             :     {
    5494    22434683 :       if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
    5495          11 :         error_at (declspecs->locations[ds_inline],
    5496             :                   "%<inline%> can only be specified for functions");
    5497    22434672 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
    5498           3 :         error_at (declspecs->locations[ds_virtual],
    5499             :                   "%<virtual%> can only be specified for functions");
    5500    22434669 :       else if (saw_friend
    5501    22434669 :                && (!current_class_type
    5502      932226 :                    || current_scope () != current_class_type))
    5503           0 :         error_at (declspecs->locations[ds_friend],
    5504             :                   "%<friend%> can only be specified inside a class");
    5505    22434669 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
    5506           3 :         error_at (declspecs->locations[ds_explicit],
    5507             :                   "%<explicit%> can only be specified for constructors");
    5508    22434666 :       else if (declspecs->storage_class)
    5509           3 :         error_at (declspecs->locations[ds_storage_class],
    5510             :                   "a storage class can only be specified for objects "
    5511             :                   "and functions");
    5512    22434663 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
    5513          11 :         error_at (declspecs->locations[ds_const],
    5514             :                   "%<const%> can only be specified for objects and "
    5515             :                   "functions");
    5516    22434652 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
    5517           3 :         error_at (declspecs->locations[ds_volatile],
    5518             :                   "%<volatile%> can only be specified for objects and "
    5519             :                   "functions");
    5520    22434649 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
    5521           3 :         error_at (declspecs->locations[ds_restrict],
    5522             :                   "%<__restrict%> can only be specified for objects and "
    5523             :                   "functions");
    5524    22434646 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
    5525           3 :         error_at (declspecs->locations[ds_thread],
    5526             :                   "%<__thread%> can only be specified for objects "
    5527             :                   "and functions");
    5528    22434643 :       else if (saw_typedef)
    5529          31 :         warning_at (declspecs->locations[ds_typedef], 0,
    5530             :                     "%<typedef%> was ignored in this declaration");
    5531    22434612 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
    5532           9 :         error_at (declspecs->locations[ds_constexpr],
    5533             :                   "%qs cannot be used for type declarations", "constexpr");
    5534    22434603 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
    5535           1 :         error_at (declspecs->locations[ds_constinit],
    5536             :                   "%qs cannot be used for type declarations", "constinit");
    5537    22434602 :       else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
    5538           1 :         error_at (declspecs->locations[ds_consteval],
    5539             :                   "%qs cannot be used for type declarations", "consteval");
    5540             :     }
    5541             : 
    5542    22491714 :   if (declspecs->attributes && warn_attributes && declared_type)
    5543             :     {
    5544          32 :       location_t loc;
    5545          25 :       if (!CLASS_TYPE_P (declared_type)
    5546          57 :           || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
    5547             :         /* For a non-template class, use the name location.  */
    5548          22 :         loc = location_of (declared_type);
    5549             :       else
    5550             :         /* For a template class (an explicit instantiation), use the
    5551             :            current location.  */
    5552          10 :         loc = input_location;
    5553             : 
    5554          32 :       if (explicit_type_instantiation_p)
    5555             :         /* [dcl.attr.grammar]/4:
    5556             : 
    5557             :                No attribute-specifier-seq shall appertain to an explicit
    5558             :                instantiation.  */
    5559             :         {
    5560           7 :           if (warning_at (loc, OPT_Wattributes,
    5561             :                           "attribute ignored in explicit instantiation %q#T",
    5562             :                           declared_type))
    5563           7 :             inform (loc,
    5564             :                     "no attribute can be applied to "
    5565             :                     "an explicit instantiation");
    5566             :         }
    5567             :       else
    5568          25 :         warn_misplaced_attr_for_class_type (loc, declared_type);
    5569             :     }
    5570             : 
    5571             :   /* Diagnose invalid application of contracts, if any.  */
    5572    22491714 :   if (find_contract (declspecs->attributes))
    5573           1 :     diagnose_misapplied_contracts (declspecs->attributes);
    5574             :   else
    5575    22491713 :     diagnose_misapplied_contracts (declspecs->std_attributes);
    5576             : 
    5577             :   return declared_type;
    5578             : }
    5579             : 
    5580             : /* Called when a declaration is seen that contains no names to declare.
    5581             :    If its type is a reference to a structure, union or enum inherited
    5582             :    from a containing scope, shadow that tag name for the current scope
    5583             :    with a forward reference.
    5584             :    If its type defines a new named structure or union
    5585             :    or defines an enum, it is valid but we need not do anything here.
    5586             :    Otherwise, it is an error.
    5587             : 
    5588             :    C++: may have to grok the declspecs to learn about static,
    5589             :    complain for anonymous unions.
    5590             : 
    5591             :    Returns the TYPE declared -- or NULL_TREE if none.  */
    5592             : 
    5593             : tree
    5594    19921271 : shadow_tag (cp_decl_specifier_seq *declspecs)
    5595             : {
    5596    19921271 :   tree t = check_tag_decl (declspecs,
    5597             :                            /*explicit_type_instantiation_p=*/false);
    5598             : 
    5599    19921271 :   if (!t)
    5600             :     return NULL_TREE;
    5601             : 
    5602    19920404 :   t = maybe_process_partial_specialization (t);
    5603    19920404 :   if (t == error_mark_node)
    5604             :     return NULL_TREE;
    5605             : 
    5606             :   /* This is where the variables in an anonymous union are
    5607             :      declared.  An anonymous union declaration looks like:
    5608             :      union { ... } ;
    5609             :      because there is no declarator after the union, the parser
    5610             :      sends that declaration here.  */
    5611    19919042 :   if (ANON_AGGR_TYPE_P (t))
    5612             :     {
    5613         270 :       fixup_anonymous_aggr (t);
    5614             : 
    5615         270 :       if (TYPE_FIELDS (t))
    5616             :         {
    5617         270 :           tree decl = grokdeclarator (/*declarator=*/NULL,
    5618             :                                       declspecs, NORMAL, 0, NULL);
    5619         270 :           finish_anon_union (decl);
    5620             :         }
    5621             :     }
    5622             : 
    5623             :   return t;
    5624             : }
    5625             : 
    5626             : /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
    5627             : 
    5628             : tree
    5629   219863786 : groktypename (cp_decl_specifier_seq *type_specifiers,
    5630             :               const cp_declarator *declarator,
    5631             :               bool is_template_arg)
    5632             : {
    5633   219863786 :   tree attrs;
    5634   219863786 :   tree type;
    5635   439727572 :   enum decl_context context
    5636   219863786 :     = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
    5637   219863786 :   attrs = type_specifiers->attributes;
    5638   219863786 :   type_specifiers->attributes = NULL_TREE;
    5639   219863786 :   type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
    5640   219863786 :   if (attrs && type != error_mark_node)
    5641             :     {
    5642         646 :       if (CLASS_TYPE_P (type))
    5643           7 :         warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
    5644             :                  "outside of definition", type);
    5645         639 :       else if (MAYBE_CLASS_TYPE_P (type))
    5646             :         /* A template type parameter or other dependent type.  */
    5647          10 :         warning (OPT_Wattributes, "ignoring attributes applied to dependent "
    5648             :                  "type %qT without an associated declaration", type);
    5649             :       else
    5650         629 :         cplus_decl_attributes (&type, attrs, 0);
    5651             :     }
    5652   219863786 :   return type;
    5653             : }
    5654             : 
    5655             : /* Process a DECLARATOR for a function-scope or namespace-scope
    5656             :    variable or function declaration.
    5657             :    (Function definitions go through start_function; class member
    5658             :    declarations appearing in the body of the class go through
    5659             :    grokfield.)  The DECL corresponding to the DECLARATOR is returned.
    5660             :    If an error occurs, the error_mark_node is returned instead.
    5661             : 
    5662             :    DECLSPECS are the decl-specifiers for the declaration.  INITIALIZED is
    5663             :    SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
    5664             :    for an explicitly defaulted function, or SD_DELETED for an explicitly
    5665             :    deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
    5666             :    implicitly initialized via a default constructor.  It can also be
    5667             :    SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
    5668             :    mark the new decl as DECL_DECOMPOSITION_P.
    5669             : 
    5670             :    ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
    5671             :    declaration.
    5672             : 
    5673             :    The scope represented by the context of the returned DECL is pushed
    5674             :    (if it is not the global namespace) and is assigned to
    5675             :    *PUSHED_SCOPE_P.  The caller is then responsible for calling
    5676             :    pop_scope on *PUSHED_SCOPE_P if it is set.  */
    5677             : 
    5678             : tree
    5679    74778314 : start_decl (const cp_declarator *declarator,
    5680             :             cp_decl_specifier_seq *declspecs,
    5681             :             int initialized,
    5682             :             tree attributes,
    5683             :             tree prefix_attributes,
    5684             :             tree *pushed_scope_p)
    5685             : {
    5686    74778314 :   tree decl;
    5687    74778314 :   tree context;
    5688    74778314 :   bool was_public;
    5689    74778314 :   int flags;
    5690    74778314 :   bool alias;
    5691    74778314 :   tree initial;
    5692             : 
    5693    74778314 :   *pushed_scope_p = NULL_TREE;
    5694             : 
    5695    74778314 :   if (prefix_attributes != error_mark_node)
    5696    74778311 :     attributes = attr_chainon (attributes, prefix_attributes);
    5697             : 
    5698    74778314 :   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
    5699             :                          &attributes);
    5700             : 
    5701    74778314 :   if (decl == NULL_TREE || VOID_TYPE_P (decl)
    5702    74778314 :       || decl == error_mark_node
    5703    74775683 :       || prefix_attributes == error_mark_node)
    5704        2634 :     return error_mark_node;
    5705             : 
    5706    74775680 :   context = CP_DECL_CONTEXT (decl);
    5707    74775680 :   if (context != global_namespace)
    5708    11453462 :     *pushed_scope_p = push_scope (context);
    5709             : 
    5710    74775680 :   if (initialized && TREE_CODE (decl) == TYPE_DECL)
    5711             :     {
    5712          12 :       error_at (DECL_SOURCE_LOCATION (decl),
    5713             :                 "typedef %qD is initialized (use %qs instead)",
    5714             :                 decl, "decltype");
    5715          12 :       return error_mark_node;
    5716             :     }
    5717             : 
    5718             :   /* Save the DECL_INITIAL value in case it gets clobbered to assist
    5719             :      with attribute validation.  */
    5720    74775668 :   initial = DECL_INITIAL (decl);
    5721             : 
    5722    74775668 :   if (initialized)
    5723             :     {
    5724    31845418 :       if (! toplevel_bindings_p ()
    5725    31845418 :           && DECL_EXTERNAL (decl))
    5726           4 :         warning (0, "declaration of %q#D has %<extern%> and is initialized",
    5727             :                  decl);
    5728    31845418 :       DECL_EXTERNAL (decl) = 0;
    5729    31845418 :       if (toplevel_bindings_p ())
    5730     2535027 :         TREE_STATIC (decl) = 1;
    5731             :       /* Tell 'cplus_decl_attributes' this is an initialized decl,
    5732             :          even though we might not yet have the initializer expression.  */
    5733    31845418 :       if (!DECL_INITIAL (decl))
    5734    31570946 :         DECL_INITIAL (decl) = error_mark_node;
    5735             :     }
    5736    74775668 :   alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
    5737             :   
    5738    74775668 :   if (alias && TREE_CODE (decl) == FUNCTION_DECL)
    5739        3703 :     record_key_method_defined (decl);
    5740             : 
    5741             :   /* If this is a typedef that names the class for linkage purposes
    5742             :      (7.1.3p8), apply any attributes directly to the type.  */
    5743    74775668 :   if (TREE_CODE (decl) == TYPE_DECL
    5744    13308155 :       && OVERLOAD_TYPE_P (TREE_TYPE (decl))
    5745    80039408 :       && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))))
    5746             :     flags = ATTR_FLAG_TYPE_IN_PLACE;
    5747             :   else
    5748             :     flags = 0;
    5749             : 
    5750             :   /* Set attributes here so if duplicate decl, will have proper attributes.  */
    5751    74775668 :   cplus_decl_attributes (&decl, attributes, flags);
    5752             : 
    5753             :   /* Restore the original DECL_INITIAL that we may have clobbered earlier to
    5754             :      assist with attribute validation.  */
    5755    74775668 :   DECL_INITIAL (decl) = initial;
    5756             : 
    5757             :   /* Dllimported symbols cannot be defined.  Static data members (which
    5758             :      can be initialized in-class and dllimported) go through grokfield,
    5759             :      not here, so we don't need to exclude those decls when checking for
    5760             :      a definition.  */
    5761    74775668 :   if (initialized && DECL_DLLIMPORT_P (decl))
    5762             :     {
    5763           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    5764             :                 "definition of %q#D is marked %<dllimport%>", decl);
    5765           0 :       DECL_DLLIMPORT_P (decl) = 0;
    5766             :     }
    5767             : 
    5768             :   /* If #pragma weak was used, mark the decl weak now.  */
    5769    74775668 :   if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
    5770    29398975 :     maybe_apply_pragma_weak (decl);
    5771             : 
    5772    74775668 :   if (TREE_CODE (decl) == FUNCTION_DECL
    5773    25642026 :       && DECL_DECLARED_INLINE_P (decl)
    5774      318409 :       && DECL_UNINLINABLE (decl)
    5775    74775668 :       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
    5776           0 :     warning_at (DECL_SOURCE_LOCATION (decl), 0,
    5777             :                 "inline function %qD given attribute %qs", decl, "noinline");
    5778             : 
    5779    74775668 :   if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
    5780             :     {
    5781      529063 :       bool this_tmpl = (current_template_depth
    5782      529063 :                         > template_class_depth (context));
    5783      529063 :       if (VAR_P (decl))
    5784             :         {
    5785      270967 :           tree field = lookup_field (context, DECL_NAME (decl), 0, false);
    5786      270967 :           if (field == NULL_TREE
    5787      270967 :               || !(VAR_P (field) || variable_template_p (field)))
    5788           8 :             error ("%q+#D is not a static data member of %q#T", decl, context);
    5789      270959 :           else if (variable_template_p (field)
    5790      270959 :                    && (DECL_LANG_SPECIFIC (decl)
    5791          76 :                        && DECL_TEMPLATE_SPECIALIZATION (decl)))
    5792             :             /* OK, specialization was already checked.  */;
    5793      270912 :           else if (variable_template_p (field) && !this_tmpl)
    5794             :             {
    5795           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    5796             :                         "non-member-template declaration of %qD", decl);
    5797           3 :               inform (DECL_SOURCE_LOCATION (field), "does not match "
    5798             :                       "member template declaration here");
    5799           3 :               return error_mark_node;
    5800             :             }
    5801             :           else
    5802             :             {
    5803      270909 :               if (variable_template_p (field))
    5804          26 :                 field = DECL_TEMPLATE_RESULT (field);
    5805             : 
    5806      270909 :               if (DECL_CONTEXT (field) != context)
    5807             :                 {
    5808           4 :                   if (!same_type_p (DECL_CONTEXT (field), context))
    5809           4 :                     permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
    5810             :                                "to be defined as %<%T::%D%>",
    5811           4 :                                DECL_CONTEXT (field), DECL_NAME (decl),
    5812           4 :                                context, DECL_NAME (decl));
    5813           4 :                   DECL_CONTEXT (decl) = DECL_CONTEXT (field);
    5814             :                 }
    5815             :               /* Static data member are tricky; an in-class initialization
    5816             :                  still doesn't provide a definition, so the in-class
    5817             :                  declaration will have DECL_EXTERNAL set, but will have an
    5818             :                  initialization.  Thus, duplicate_decls won't warn
    5819             :                  about this situation, and so we check here.  */
    5820      270909 :               if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
    5821          12 :                 error ("duplicate initialization of %qD", decl);
    5822      270909 :               field = duplicate_decls (decl, field);
    5823      270909 :               if (field == error_mark_node)
    5824             :                 return error_mark_node;
    5825      270852 :               else if (field)
    5826      270852 :                 decl = field;
    5827             :             }
    5828             :         }
    5829             :       else
    5830             :         {
    5831      258110 :           tree field = check_classfn (context, decl,
    5832             :                                       this_tmpl
    5833          14 :                                       ? current_template_parms
    5834             :                                       : NULL_TREE);
    5835      258017 :           if (field && field != error_mark_node
    5836      516113 :               && duplicate_decls (decl, field))
    5837      258016 :             decl = field;
    5838             :         }
    5839             : 
    5840             :       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
    5841      529003 :       DECL_IN_AGGR_P (decl) = 0;
    5842             :       /* Do not mark DECL as an explicit specialization if it was not
    5843             :          already marked as an instantiation; a declaration should
    5844             :          never be marked as a specialization unless we know what
    5845             :          template is being specialized.  */
    5846      529003 :       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
    5847             :         {
    5848      256022 :           SET_DECL_TEMPLATE_SPECIALIZATION (decl);
    5849      256022 :           if (TREE_CODE (decl) == FUNCTION_DECL)
    5850      241468 :             DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
    5851      241468 :                                   && DECL_DECLARED_INLINE_P (decl));
    5852             :           else
    5853       14554 :             DECL_COMDAT (decl) = false;
    5854             : 
    5855             :           /* [temp.expl.spec] An explicit specialization of a static data
    5856             :              member of a template is a definition if the declaration
    5857             :              includes an initializer; otherwise, it is a declaration.
    5858             : 
    5859             :              We check for processing_specialization so this only applies
    5860             :              to the new specialization syntax.  */
    5861      256022 :           if (!initialized && processing_specialization)
    5862      255828 :             DECL_EXTERNAL (decl) = 1;
    5863             :         }
    5864             : 
    5865      784913 :       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
    5866             :           /* Aliases are definitions. */
    5867      529072 :           && !alias)
    5868             :         {
    5869          33 :           if (DECL_VIRTUAL_P (decl) || !flag_contracts)
    5870          14 :             permerror (declarator->id_loc,
    5871             :                        "declaration of %q#D outside of class is not definition",
    5872             :                        decl);
    5873          19 :           else if (flag_contract_strict_declarations)
    5874           4 :             warning_at (declarator->id_loc, OPT_fcontract_strict_declarations_,
    5875             :                         "declaration of %q#D outside of class is not definition",
    5876             :                         decl);
    5877             :         }
    5878             :     }
    5879             : 
    5880             :   /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works.  */
    5881    74775608 :   if (initialized == SD_DECOMPOSITION)
    5882       26424 :     fit_decomposition_lang_decl (decl, NULL_TREE);
    5883             : 
    5884    74775608 :   was_public = TREE_PUBLIC (decl);
    5885             : 
    5886   123706262 :   if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
    5887    75050104 :       && current_function_decl)
    5888             :     {
    5889             :       /* A function-scope decl of some namespace-scope decl.  */
    5890       25315 :       DECL_LOCAL_DECL_P (decl) = true;
    5891       25315 :       if (named_module_purview_p ())
    5892           3 :         error_at (declarator->id_loc,
    5893             :                   "block-scope extern declaration %q#D not permitted"
    5894             :                   " in module purview", decl);
    5895             :     }
    5896             : 
    5897             :   /* Enter this declaration into the symbol table.  Don't push the plain
    5898             :      VAR_DECL for a variable template.  */
    5899    74775608 :   if (!template_parm_scope_p ()
    5900    74775608 :       || !VAR_P (decl))
    5901    73118646 :     decl = maybe_push_decl (decl);
    5902             : 
    5903    74775608 :   if (processing_template_decl)
    5904    45375970 :     decl = push_template_decl (decl);
    5905             : 
    5906    74775608 :   if (decl == error_mark_node)
    5907             :     return error_mark_node;
    5908             : 
    5909    74775318 :   if (VAR_P (decl)
    5910    35825266 :       && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
    5911      127856 :       && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
    5912             :       /* But not templated variables.  */
    5913    74854838 :       && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
    5914             :     {
    5915             :       /* This is a const variable with implicit 'static'.  Set
    5916             :          DECL_THIS_STATIC so we can tell it from variables that are
    5917             :          !TREE_PUBLIC because of the anonymous namespace.  */
    5918       25852 :       gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
    5919       25852 :       DECL_THIS_STATIC (decl) = 1;
    5920             :     }
    5921             : 
    5922    40208359 :   if (current_function_decl && VAR_P (decl)
    5923    32599019 :       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
    5924    76726453 :       && cxx_dialect < cxx23)
    5925             :     {
    5926     1895644 :       bool ok = false;
    5927     1895644 :       if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
    5928          20 :         error_at (DECL_SOURCE_LOCATION (decl),
    5929             :                   "%qD defined %<thread_local%> in %qs function only "
    5930             :                   "available with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
    5931          10 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    5932             :                   ? "consteval" : "constexpr");
    5933     1895634 :       else if (TREE_STATIC (decl))
    5934          86 :         error_at (DECL_SOURCE_LOCATION (decl),
    5935             :                   "%qD defined %<static%> in %qs function only available "
    5936             :                   "with %<-std=c++2b%> or %<-std=gnu++2b%>", decl,
    5937          43 :                   DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
    5938             :                   ? "consteval" : "constexpr");
    5939             :       else
    5940             :         ok = true;
    5941          53 :       if (!ok)
    5942          53 :         cp_function_chain->invalid_constexpr = true;
    5943             :     }
    5944             : 
    5945    74775318 :   if (!processing_template_decl && VAR_P (decl))
    5946     3323414 :     start_decl_1 (decl, initialized);
    5947             : 
    5948    74775314 :   return decl;
    5949             : }
    5950             : 
    5951             : /* Process the declaration of a variable DECL.  INITIALIZED is true
    5952             :    iff DECL is explicitly initialized.  (INITIALIZED is false if the
    5953             :    variable is initialized via an implicitly-called constructor.)
    5954             :    This function must be called for ordinary variables (including, for
    5955             :    example, implicit instantiations of templates), but must not be
    5956             :    called for template declarations.  */
    5957             : 
    5958             : void
    5959     3329465 : start_decl_1 (tree decl, bool initialized)
    5960             : {
    5961     3329465 :   gcc_checking_assert (!processing_template_decl);
    5962             : 
    5963     3329465 :   if (error_operand_p (decl))
    5964             :     return;
    5965             : 
    5966     3329450 :   gcc_checking_assert (VAR_P (decl));
    5967             : 
    5968     3329450 :   tree type = TREE_TYPE (decl);
    5969     3329450 :   bool complete_p = COMPLETE_TYPE_P (type);
    5970     3329450 :   bool aggregate_definition_p
    5971     3329450 :     = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
    5972             : 
    5973             :   /* If an explicit initializer is present, or if this is a definition
    5974             :      of an aggregate, then we need a complete type at this point.
    5975             :      (Scalars are always complete types, so there is nothing to
    5976             :      check.)  This code just sets COMPLETE_P; errors (if necessary)
    5977             :      are issued below.  */
    5978     3329450 :   if ((initialized || aggregate_definition_p) 
    5979     2506238 :       && !complete_p
    5980     3776604 :       && COMPLETE_TYPE_P (complete_type (type)))
    5981             :     {
    5982      236937 :       complete_p = true;
    5983             :       /* We will not yet have set TREE_READONLY on DECL if the type
    5984             :          was "const", but incomplete, before this point.  But, now, we
    5985             :          have a complete type, so we can try again.  */
    5986      236937 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    5987             :     }
    5988             : 
    5989     3329446 :   if (initialized)
    5990             :     /* Is it valid for this decl to have an initializer at all?  */
    5991             :     {
    5992             :       /* Don't allow initializations for incomplete types except for
    5993             :          arrays which might be completed by the initialization.  */
    5994     2152066 :       if (complete_p)
    5995             :         ;                       /* A complete type is ok.  */
    5996      209986 :       else if (type_uses_auto (type))
    5997             :         ;                       /* An auto type is ok.  */
    5998       46036 :       else if (TREE_CODE (type) != ARRAY_TYPE)
    5999             :         {
    6000          29 :           auto_diagnostic_group d;
    6001          29 :           error ("variable %q#D has initializer but incomplete type", decl);
    6002          51 :           maybe_suggest_missing_header (input_location,
    6003          29 :                                         TYPE_IDENTIFIER (type),
    6004          29 :                                         CP_TYPE_CONTEXT (type));
    6005          29 :           type = TREE_TYPE (decl) = error_mark_node;
    6006          29 :         }
    6007       46007 :       else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
    6008             :         {
    6009           0 :           if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
    6010           0 :             error ("elements of array %q#D have incomplete type", decl);
    6011             :           /* else we already gave an error in start_decl.  */
    6012             :         }
    6013             :     }
    6014     1177380 :   else if (aggregate_definition_p && !complete_p)
    6015             :     {
    6016         227 :       if (type_uses_auto (type))
    6017          44 :         gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
    6018             :       else
    6019             :         {
    6020         183 :           auto_diagnostic_group d;
    6021         183 :           error ("aggregate %q#D has incomplete type and cannot be defined",
    6022             :                  decl);
    6023         315 :           maybe_suggest_missing_header (input_location,
    6024         183 :                                         TYPE_IDENTIFIER (type),
    6025         183 :                                         CP_TYPE_CONTEXT (type));
    6026             :           /* Change the type so that assemble_variable will give
    6027             :              DECL an rtl we can live with: (mem (const_int 0)).  */
    6028         183 :           type = TREE_TYPE (decl) = error_mark_node;
    6029         183 :         }
    6030             :     }
    6031             : 
    6032             :   /* Create a new scope to hold this declaration if necessary.
    6033             :      Whether or not a new scope is necessary cannot be determined
    6034             :      until after the type has been completed; if the type is a
    6035             :      specialization of a class template it is not until after
    6036             :      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
    6037             :      will be set correctly.  */
    6038     3329446 :   maybe_push_cleanup_level (type);
    6039             : }
    6040             : 
    6041             : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
    6042             :    C++20 P0960.  TYPE is the type of the object we're initializing.  */
    6043             : 
    6044             : tree
    6045         104 : do_aggregate_paren_init (tree init, tree type)
    6046             : {
    6047         104 :   tree val = TREE_VALUE (init);
    6048             : 
    6049         104 :   if (TREE_CHAIN (init) == NULL_TREE)
    6050             :     {
    6051             :       /* If the list has a single element and it's a string literal,
    6052             :          then it's the initializer for the array as a whole.  */
    6053          65 :       if (TREE_CODE (type) == ARRAY_TYPE
    6054          65 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    6055          83 :           && TREE_CODE (tree_strip_any_location_wrapper (val))
    6056             :              == STRING_CST)
    6057             :         return val;
    6058             :       /* Handle non-standard extensions like compound literals.  This also
    6059             :          prevents triggering aggregate parenthesized-initialization in
    6060             :          compiler-generated code for =default.  */
    6061          49 :       else if (same_type_ignoring_top_level_qualifiers_p (type,
    6062          49 :                                                           TREE_TYPE (val)))
    6063             :         return val;
    6064             :     }
    6065             : 
    6066          71 :   init = build_constructor_from_list (init_list_type_node, init);
    6067          71 :   CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
    6068          71 :   CONSTRUCTOR_IS_PAREN_INIT (init) = true;
    6069          71 :   return init;
    6070             : }
    6071             : 
    6072             : /* Handle initialization of references.  DECL, TYPE, and INIT have the
    6073             :    same meaning as in cp_finish_decl.  *CLEANUP must be NULL on entry,
    6074             :    but will be set to a new CLEANUP_STMT if a temporary is created
    6075             :    that must be destroyed subsequently.
    6076             : 
    6077             :    Returns an initializer expression to use to initialize DECL, or
    6078             :    NULL if the initialization can be performed statically.
    6079             : 
    6080             :    Quotes on semantics can be found in ARM 8.4.3.  */
    6081             : 
    6082             : static tree
    6083      155711 : grok_reference_init (tree decl, tree type, tree init, int flags)
    6084             : {
    6085      155711 :   if (init == NULL_TREE)
    6086             :     {
    6087          16 :       if ((DECL_LANG_SPECIFIC (decl) == 0
    6088           4 :            || DECL_IN_AGGR_P (decl) == 0)
    6089          20 :           && ! DECL_THIS_EXTERN (decl))
    6090          16 :         error_at (DECL_SOURCE_LOCATION (decl),
    6091             :                   "%qD declared as reference but not initialized", decl);
    6092          16 :       return NULL_TREE;
    6093             :     }
    6094             : 
    6095      155695 :   tree ttype = TREE_TYPE (type);
    6096      155695 :   if (TREE_CODE (init) == TREE_LIST)
    6097             :     {
    6098             :       /* This handles (C++20 only) code like
    6099             : 
    6100             :            const A& r(1, 2, 3);
    6101             : 
    6102             :          where we treat the parenthesized list as a CONSTRUCTOR.  */
    6103        1160 :       if (TREE_TYPE (init) == NULL_TREE
    6104        1160 :           && CP_AGGREGATE_TYPE_P (ttype)
    6105          29 :           && !DECL_DECOMPOSITION_P (decl)
    6106        1186 :           && (cxx_dialect >= cxx20))
    6107             :         {
    6108             :           /* We don't know yet if we should treat const A& r(1) as
    6109             :              const A& r{1}.  */
    6110          14 :           if (list_length (init) == 1)
    6111             :             {
    6112           7 :               flags |= LOOKUP_AGGREGATE_PAREN_INIT;
    6113           7 :               init = build_x_compound_expr_from_list (init, ELK_INIT,
    6114             :                                                       tf_warning_or_error);
    6115             :             }
    6116             :           /* If the list had more than one element, the code is ill-formed
    6117             :              pre-C++20, so we can build a constructor right away.  */
    6118             :           else
    6119           7 :             init = do_aggregate_paren_init (init, ttype);
    6120             :         }
    6121             :       else
    6122        1146 :         init = build_x_compound_expr_from_list (init, ELK_INIT,
    6123             :                                                 tf_warning_or_error);
    6124             :     }
    6125             : 
    6126      155695 :   if (TREE_CODE (ttype) != ARRAY_TYPE
    6127      155695 :       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
    6128             :     /* Note: default conversion is only called in very special cases.  */
    6129          15 :     init = decay_conversion (init, tf_warning_or_error);
    6130             : 
    6131             :   /* check_initializer handles this for non-reference variables, but for
    6132             :      references we need to do it here or the initializer will get the
    6133             :      incomplete array type and confuse later calls to
    6134             :      cp_complete_array_type.  */
    6135      155695 :   if (TREE_CODE (ttype) == ARRAY_TYPE
    6136        2116 :       && TYPE_DOMAIN (ttype) == NULL_TREE
    6137      155756 :       && (BRACE_ENCLOSED_INITIALIZER_P (init)
    6138          44 :           || TREE_CODE (init) == STRING_CST))
    6139             :     {
    6140          17 :       cp_complete_array_type (&ttype, init, false);
    6141          17 :       if (ttype != TREE_TYPE (type))
    6142          17 :         type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
    6143             :     }
    6144             : 
    6145             :   /* Convert INIT to the reference type TYPE.  This may involve the
    6146             :      creation of a temporary, whose lifetime must be the same as that
    6147             :      of the reference.  If so, a DECL_EXPR for the temporary will be
    6148             :      added just after the DECL_EXPR for DECL.  That's why we don't set
    6149             :      DECL_INITIAL for local references (instead assigning to them
    6150             :      explicitly); we need to allow the temporary to be initialized
    6151             :      first.  */
    6152      155695 :   return initialize_reference (type, init, flags,
    6153      155695 :                                tf_warning_or_error);
    6154             : }
    6155             : 
    6156             : /* Designated initializers in arrays are not supported in GNU C++.
    6157             :    The parser cannot detect this error since it does not know whether
    6158             :    a given brace-enclosed initializer is for a class type or for an
    6159             :    array.  This function checks that CE does not use a designated
    6160             :    initializer.  If it does, an error is issued.  Returns true if CE
    6161             :    is valid, i.e., does not have a designated initializer.  */
    6162             : 
    6163             : bool
    6164     6265007 : check_array_designated_initializer (constructor_elt *ce,
    6165             :                                     unsigned HOST_WIDE_INT index)
    6166             : {
    6167             :   /* Designated initializers for array elements are not supported.  */
    6168     6265007 :   if (ce->index)
    6169             :     {
    6170             :       /* The parser only allows identifiers as designated
    6171             :          initializers.  */
    6172     3277026 :       if (ce->index == error_mark_node)
    6173             :         {
    6174           0 :           error ("name used in a GNU-style designated "
    6175             :                  "initializer for an array");
    6176           0 :           return false;
    6177             :         }
    6178     3277026 :       else if (identifier_p (ce->index))
    6179             :         {
    6180          23 :           error ("name %qD used in a GNU-style designated "
    6181             :                  "initializer for an array", ce->index);
    6182          23 :           return false;
    6183             :         }
    6184             : 
    6185     3277003 :       tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
    6186             :                                                   ce->index, true);
    6187     3277003 :       if (ce_index
    6188     3276999 :           && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
    6189     6553999 :           && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
    6190             :               == INTEGER_CST))
    6191             :         {
    6192             :           /* A C99 designator is OK if it matches the current index.  */
    6193     3276996 :           if (wi::to_wide (ce_index) == index)
    6194             :             {
    6195     3276988 :               ce->index = ce_index;
    6196     3276988 :               return true;
    6197             :             }
    6198             :           else
    6199           8 :             sorry ("non-trivial designated initializers not supported");
    6200             :         }
    6201             :       else
    6202           7 :         error_at (cp_expr_loc_or_input_loc (ce->index),
    6203             :                   "C99 designator %qE is not an integral constant-expression",
    6204             :                   ce->index);
    6205             : 
    6206          15 :       return false;
    6207             :     }
    6208             : 
    6209             :   return true;
    6210             : }
    6211             : 
    6212             : /* When parsing `int a[] = {1, 2};' we don't know the size of the
    6213             :    array until we finish parsing the initializer.  If that's the
    6214             :    situation we're in, update DECL accordingly.  */
    6215             : 
    6216             : static void
    6217    32118723 : maybe_deduce_size_from_array_init (tree decl, tree init)
    6218             : {
    6219    32118723 :   tree type = TREE_TYPE (decl);
    6220             : 
    6221    32118723 :   if (TREE_CODE (type) == ARRAY_TYPE
    6222      515765 :       && TYPE_DOMAIN (type) == NULL_TREE
    6223    32442192 :       && TREE_CODE (decl) != TYPE_DECL)
    6224             :     {
    6225             :       /* do_default is really a C-ism to deal with tentative definitions.
    6226             :          But let's leave it here to ease the eventual merge.  */
    6227      323469 :       int do_default = !DECL_EXTERNAL (decl);
    6228      323469 :       tree initializer = init ? init : DECL_INITIAL (decl);
    6229      323469 :       int failure = 0;
    6230             : 
    6231             :       /* Check that there are no designated initializers in INIT, as
    6232             :          those are not supported in GNU C++, and as the middle-end
    6233             :          will crash if presented with a non-numeric designated
    6234             :          initializer.  */
    6235      323469 :       if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
    6236             :         {
    6237       39784 :           vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
    6238       39784 :           constructor_elt *ce;
    6239       39784 :           HOST_WIDE_INT i;
    6240     1733411 :           FOR_EACH_VEC_SAFE_ELT (v, i, ce)
    6241             :             {
    6242     1693730 :               if (instantiation_dependent_expression_p (ce->index))
    6243    32118723 :                 return;
    6244     1693722 :               if (!check_array_designated_initializer (ce, i))
    6245           3 :                 failure = 1;
    6246             :               /* If an un-designated initializer is type-dependent, we can't
    6247             :                  check brace elision yet.  */
    6248     1693722 :               if (ce->index == NULL_TREE
    6249     1693722 :                   && type_dependent_expression_p (ce->value))
    6250             :                 return;
    6251             :             }
    6252             :         }
    6253             : 
    6254       39681 :       if (failure)
    6255           3 :         TREE_TYPE (decl) = error_mark_node;
    6256             :       else
    6257             :         {
    6258      323363 :           failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
    6259             :                                             do_default);
    6260      323363 :           if (failure == 1)
    6261             :             {
    6262          44 :               error_at (cp_expr_loc_or_loc (initializer,
    6263          40 :                                          DECL_SOURCE_LOCATION (decl)),
    6264             :                         "initializer fails to determine size of %qD", decl);
    6265             :             }
    6266      323323 :           else if (failure == 2)
    6267             :             {
    6268          33 :               if (do_default)
    6269             :                 {
    6270           8 :                   error_at (DECL_SOURCE_LOCATION (decl),
    6271             :                             "array size missing in %qD", decl);
    6272             :                 }
    6273             :               /* If a `static' var's size isn't known, make it extern as
    6274             :                  well as static, so it does not get allocated.  If it's not
    6275             :                  `static', then don't mark it extern; finish_incomplete_decl
    6276             :                  will give it a default size and it will get allocated.  */
    6277          25 :               else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
    6278           0 :                 DECL_EXTERNAL (decl) = 1;
    6279             :             }
    6280      323290 :           else if (failure == 3)
    6281             :             {
    6282           8 :               error_at (DECL_SOURCE_LOCATION (decl),
    6283             :                         "zero-size array %qD", decl);
    6284             :             }
    6285             :         }
    6286             : 
    6287      323366 :       cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
    6288             : 
    6289      323366 :       relayout_decl (decl);
    6290             :     }
    6291             : }
    6292             : 
    6293             : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
    6294             :    any appropriate error messages regarding the layout.  */
    6295             : 
    6296             : static void
    6297    26579538 : layout_var_decl (tree decl)
    6298             : {
    6299    26579538 :   tree type;
    6300             : 
    6301    26579538 :   type = TREE_TYPE (decl);
    6302    26579538 :   if (type == error_mark_node)
    6303             :     return;
    6304             : 
    6305             :   /* If we haven't already laid out this declaration, do so now.
    6306             :      Note that we must not call complete type for an external object
    6307             :      because it's type might involve templates that we are not
    6308             :      supposed to instantiate yet.  (And it's perfectly valid to say
    6309             :      `extern X x' for some incomplete type `X'.)  */
    6310    26579485 :   if (!DECL_EXTERNAL (decl))
    6311    20803040 :     complete_type (type);
    6312    26579485 :   if (!DECL_SIZE (decl)
    6313      982341 :       && TREE_TYPE (decl) != error_mark_node
    6314    27561826 :       && complete_or_array_type_p (type))
    6315      963107 :     layout_decl (decl, 0);
    6316             : 
    6317    26579485 :   if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
    6318             :     {
    6319             :       /* An automatic variable with an incomplete type: that is an error.
    6320             :          Don't talk about array types here, since we took care of that
    6321             :          message in grokdeclarator.  */
    6322          22 :       error_at (DECL_SOURCE_LOCATION (decl),
    6323             :                 "storage size of %qD isn%'t known", decl);
    6324          22 :       TREE_TYPE (decl) = error_mark_node;
    6325             :     }
    6326             : #if 0
    6327             :   /* Keep this code around in case we later want to control debug info
    6328             :      based on whether a type is "used".  (jason 1999-11-11) */
    6329             : 
    6330             :   else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
    6331             :     /* Let debugger know it should output info for this type.  */
    6332             :     note_debug_info_needed (ttype);
    6333             : 
    6334             :   if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
    6335             :     note_debug_info_needed (DECL_CONTEXT (decl));
    6336             : #endif
    6337             : 
    6338    47382525 :   if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
    6339    12520599 :       && DECL_SIZE (decl) != NULL_TREE
    6340    38981910 :       && ! TREE_CONSTANT (DECL_SIZE (decl)))
    6341             :     {
    6342           8 :       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6343           8 :           && !DECL_LOCAL_DECL_P (decl))
    6344           0 :         constant_expression_warning (DECL_SIZE (decl));
    6345             :       else
    6346             :         {
    6347           8 :           error_at (DECL_SOURCE_LOCATION (decl),
    6348             :                     "storage size of %qD isn%'t constant", decl);
    6349           8 :           TREE_TYPE (decl) = error_mark_node;
    6350           8 :           type = error_mark_node;
    6351             :         }
    6352             :     }
    6353             : 
    6354             :   /* If the final element initializes a flexible array field, add the size of
    6355             :      that initializer to DECL's size.  */
    6356    26579485 :   if (type != error_mark_node
    6357    26579477 :       && DECL_INITIAL (decl)
    6358    12267398 :       && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    6359     2043272 :       && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
    6360     1847157 :       && DECL_SIZE (decl) != NULL_TREE
    6361     1847157 :       && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
    6362     1847157 :       && COMPLETE_TYPE_P (type)
    6363     1847157 :       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
    6364    28426642 :       && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
    6365             :     {
    6366     1847157 :       constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
    6367     1847157 :       if (elt.index)
    6368             :         {
    6369     1691411 :           tree itype = TREE_TYPE (elt.index);
    6370     1691411 :           tree vtype = TREE_TYPE (elt.value);
    6371     1691411 :           if (TREE_CODE (itype) == ARRAY_TYPE
    6372       29846 :               && TYPE_DOMAIN (itype) == NULL
    6373         290 :               && TREE_CODE (vtype) == ARRAY_TYPE
    6374     1691701 :               && COMPLETE_TYPE_P (vtype))
    6375             :             {
    6376         290 :               DECL_SIZE (decl)
    6377         290 :                 = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (vtype));
    6378         290 :               DECL_SIZE_UNIT (decl)
    6379         580 :                 = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
    6380             :                               TYPE_SIZE_UNIT (vtype));
    6381             :             }
    6382             :         }
    6383             :     }
    6384             : }
    6385             : 
    6386             : /* If a local static variable is declared in an inline function, or if
    6387             :    we have a weak definition, we must endeavor to create only one
    6388             :    instance of the variable at link-time.  */
    6389             : 
    6390             : void
    6391    27772035 : maybe_commonize_var (tree decl)
    6392             : {
    6393             :   /* Don't mess with __FUNCTION__ and similar.  */
    6394    27772035 :   if (DECL_ARTIFICIAL (decl))
    6395             :     return;
    6396             : 
    6397             :   /* Static data in a function with comdat linkage also has comdat
    6398             :      linkage.  */
    6399    24452378 :   if ((TREE_STATIC (decl)
    6400    10035608 :        && DECL_FUNCTION_SCOPE_P (decl)
    6401       85216 :        && vague_linkage_p (DECL_CONTEXT (decl)))
    6402    44636890 :       || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
    6403             :     {
    6404     7352491 :       if (flag_weak)
    6405             :         {
    6406             :           /* With weak symbols, we simply make the variable COMDAT;
    6407             :              that will cause copies in multiple translations units to
    6408             :              be merged.  */
    6409     7352465 :           comdat_linkage (decl);
    6410             :         }
    6411             :       else
    6412             :         {
    6413          26 :           if (DECL_INITIAL (decl) == NULL_TREE
    6414          26 :               || DECL_INITIAL (decl) == error_mark_node)
    6415             :             {
    6416             :               /* Without weak symbols, we can use COMMON to merge
    6417             :                  uninitialized variables.  */
    6418          24 :               TREE_PUBLIC (decl) = 1;
    6419          24 :               DECL_COMMON (decl) = 1;
    6420             :             }
    6421             :           else
    6422             :             {
    6423             :               /* While for initialized variables, we must use internal
    6424             :                  linkage -- which means that multiple copies will not
    6425             :                  be merged.  */
    6426           2 :               TREE_PUBLIC (decl) = 0;
    6427           2 :               DECL_COMMON (decl) = 0;
    6428           2 :               DECL_INTERFACE_KNOWN (decl) = 1;
    6429           2 :               const char *msg;
    6430           2 :               if (DECL_INLINE_VAR_P (decl))
    6431             :                 msg = G_("sorry: semantics of inline variable "
    6432             :                          "%q#D are wrong (you%'ll wind up with "
    6433             :                          "multiple copies)");
    6434             :               else
    6435             :                 msg = G_("sorry: semantics of inline function "
    6436             :                          "static data %q#D are wrong (you%'ll wind "
    6437             :                          "up with multiple copies)");
    6438           2 :               if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
    6439             :                               msg, decl))
    6440           2 :                 inform (DECL_SOURCE_LOCATION (decl),
    6441             :                         "you can work around this by removing the initializer");
    6442             :             }
    6443             :         }
    6444             :     }
    6445             : }
    6446             : 
    6447             : /* Issue an error message if DECL is an uninitialized const variable.
    6448             :    CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
    6449             :    context from potential_constant_expression.  Returns true if all is well,
    6450             :    false otherwise.  */
    6451             : 
    6452             : bool
    6453     3175676 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
    6454             :                                    tsubst_flags_t complain)
    6455             : {
    6456     3175676 :   tree type = strip_array_types (TREE_TYPE (decl));
    6457             : 
    6458             :   /* ``Unless explicitly declared extern, a const object does not have
    6459             :      external linkage and must be initialized. ($8.4; $12.1)'' ARM
    6460             :      7.1.6 */
    6461     3175676 :   if (VAR_P (decl)
    6462     3175676 :       && !TYPE_REF_P (type)
    6463     3172798 :       && (CP_TYPE_CONST_P (type)
    6464             :           /* C++20 permits trivial default initialization in constexpr
    6465             :              context (P1331R2).  */
    6466     2702576 :           || (cxx_dialect < cxx20
    6467     2533833 :               && (constexpr_context_p
    6468     2267090 :                   || var_in_constexpr_fn (decl))))
    6469     4035711 :       && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
    6470             :     {
    6471      467074 :       tree field = default_init_uninitialized_part (type);
    6472      467074 :       if (!field)
    6473             :         return true;
    6474             : 
    6475      125092 :       bool show_notes = true;
    6476             : 
    6477      125092 :       if (!constexpr_context_p || cxx_dialect >= cxx20)
    6478             :         {
    6479      121301 :           if (CP_TYPE_CONST_P (type))
    6480             :             {
    6481          77 :               if (complain & tf_error)
    6482          75 :                 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
    6483             :                                         "uninitialized %<const %D%>", decl);
    6484             :             }
    6485             :           else
    6486             :             {
    6487      121224 :               if (!is_instantiation_of_constexpr (current_function_decl)
    6488      121224 :                   && (complain & tf_error))
    6489          21 :                 error_at (DECL_SOURCE_LOCATION (decl),
    6490             :                           "uninitialized variable %qD in %<constexpr%> "
    6491             :                           "function", decl);
    6492             :               else
    6493             :                 show_notes = false;
    6494      121224 :               cp_function_chain->invalid_constexpr = true;
    6495             :             }
    6496             :         }
    6497        3791 :       else if (complain & tf_error)
    6498           2 :         error_at (DECL_SOURCE_LOCATION (decl),
    6499             :                   "uninitialized variable %qD in %<constexpr%> context",
    6500             :                   decl);
    6501             : 
    6502      125092 :       if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
    6503             :         {
    6504          59 :           tree defaulted_ctor;
    6505             : 
    6506          59 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
    6507             :                   "%q#T has no user-provided default constructor", type);
    6508          59 :           defaulted_ctor = in_class_defaulted_default_constructor (type);
    6509          59 :           if (defaulted_ctor)
    6510          23 :             inform (DECL_SOURCE_LOCATION (defaulted_ctor),
    6511             :                     "constructor is not user-provided because it is "
    6512             :                     "explicitly defaulted in the class body");
    6513          59 :           inform (DECL_SOURCE_LOCATION (field),
    6514             :                   "and the implicitly-defined constructor does not "
    6515             :                   "initialize %q#D", field);
    6516             :         }
    6517             : 
    6518      125092 :       return false;
    6519             :     }
    6520             : 
    6521             :   return true;
    6522             : }
    6523             : 
    6524             : /* Structure holding the current initializer being processed by reshape_init.
    6525             :    CUR is a pointer to the current element being processed, END is a pointer
    6526             :    after the last element present in the initializer.  */
    6527             : struct reshape_iter
    6528             : {
    6529             :   constructor_elt *cur;
    6530             :   constructor_elt *end;
    6531             : };
    6532             : 
    6533             : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
    6534             : 
    6535             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6536             :    returned is the next FIELD_DECL (possibly FIELD itself) that can be
    6537             :    initialized as if for an aggregate class.  If there are no more such fields,
    6538             :    the return value will be NULL.  */
    6539             : 
    6540             : tree
    6541     5467832 : next_aggregate_field (tree field)
    6542             : {
    6543     5467832 :   while (field
    6544    21757038 :          && (TREE_CODE (field) != FIELD_DECL
    6545     3398387 :              || DECL_UNNAMED_BIT_FIELD (field)
    6546     3398285 :              || (DECL_ARTIFICIAL (field)
    6547             :                  /* In C++17, aggregates can have bases.  */
    6548       20729 :                  && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
    6549    16289206 :     field = DECL_CHAIN (field);
    6550             : 
    6551     5467832 :   return field;
    6552             : }
    6553             : 
    6554             : /* FIELD is an element of TYPE_FIELDS or NULL.  In the former case, the value
    6555             :    returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
    6556             :    to a subobject.  If there are no more such fields, the return value will be
    6557             :    NULL.  */
    6558             : 
    6559             : tree
    6560      128911 : next_subobject_field (tree field)
    6561             : {
    6562      128911 :   while (field
    6563     1997018 :          && (TREE_CODE (field) != FIELD_DECL
    6564       73783 :              || DECL_UNNAMED_BIT_FIELD (field)
    6565       73772 :              || (DECL_ARTIFICIAL (field)
    6566        4758 :                  && !DECL_FIELD_IS_BASE (field)
    6567         572 :                  && !DECL_VIRTUAL_P (field))))
    6568     1868107 :     field = DECL_CHAIN (field);
    6569             : 
    6570      128911 :   return field;
    6571             : }
    6572             : 
    6573             : /* Return true for [dcl.init.list] direct-list-initialization from
    6574             :    single element of enumeration with a fixed underlying type.  */
    6575             : 
    6576             : bool
    6577    60134630 : is_direct_enum_init (tree type, tree init)
    6578             : {
    6579    60134630 :   if (cxx_dialect >= cxx17
    6580    57603792 :       && TREE_CODE (type) == ENUMERAL_TYPE
    6581     2999679 :       && ENUM_FIXED_UNDERLYING_TYPE_P (type)
    6582     1637219 :       && TREE_CODE (init) == CONSTRUCTOR
    6583      201824 :       && CONSTRUCTOR_IS_DIRECT_INIT (init)
    6584       98891 :       && CONSTRUCTOR_NELTS (init) == 1
    6585             :       /* DR 2374: The single element needs to be implicitly
    6586             :          convertible to the underlying type of the enum.  */
    6587    60134906 :       && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
    6588         276 :                           TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
    6589         276 :                           CONSTRUCTOR_ELT (init, 0)->value,
    6590             :                           LOOKUP_IMPLICIT, tf_none))
    6591             :     return true;
    6592             :   return false;
    6593             : }
    6594             : 
    6595             : /* Subroutine of reshape_init_array and reshape_init_vector, which does
    6596             :    the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
    6597             :    INTEGER_CST representing the size of the array minus one (the maximum index),
    6598             :    or NULL_TREE if the array was declared without specifying the size. D is
    6599             :    the iterator within the constructor.  */
    6600             : 
    6601             : static tree
    6602      235682 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
    6603             :                       tree first_initializer_p, tsubst_flags_t complain)
    6604             : {
    6605      235682 :   tree new_init;
    6606      235682 :   bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
    6607      235682 :   unsigned HOST_WIDE_INT max_index_cst = 0;
    6608      235682 :   unsigned HOST_WIDE_INT index;
    6609             : 
    6610             :   /* The initializer for an array is always a CONSTRUCTOR.  If this is the
    6611             :      outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
    6612             :      to build a new one.  But don't reuse if not complaining; if this is
    6613             :      tentative, we might also reshape to another type (95319).  */
    6614      235682 :   bool reuse = (first_initializer_p
    6615      195810 :                 && (complain & tf_error)
    6616      195181 :                 && !CP_AGGREGATE_TYPE_P (elt_type)
    6617      398149 :                 && !TREE_SIDE_EFFECTS (first_initializer_p));
    6618       74027 :   if (reuse)
    6619             :     new_init = first_initializer_p;
    6620             :   else
    6621       74027 :     new_init = build_constructor (init_list_type_node, NULL);
    6622             : 
    6623      235682 :   if (sized_array_p)
    6624             :     {
    6625             :       /* Minus 1 is used for zero sized arrays.  */
    6626      188254 :       if (integer_all_onesp (max_index))
    6627             :         return new_init;
    6628             : 
    6629      188223 :       if (tree_fits_uhwi_p (max_index))
    6630      188223 :         max_index_cst = tree_to_uhwi (max_index);
    6631             :       /* sizetype is sign extended, not zero extended.  */
    6632             :       else
    6633           0 :         max_index_cst = tree_to_uhwi (fold_convert (size_type_node, max_index));
    6634             :     }
    6635             : 
    6636             :   /* Loop until there are no more initializers.  */
    6637     2713213 :   for (index = 0;
    6638     2713213 :        d->cur != d->end && (!sized_array_p || index <= max_index_cst);
    6639             :        ++index)
    6640             :     {
    6641     2477704 :       tree elt_init;
    6642     2477704 :       constructor_elt *old_cur = d->cur;
    6643             : 
    6644     2477704 :       if (d->cur->index)
    6645      359243 :         CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    6646     2477704 :       check_array_designated_initializer (d->cur, index);
    6647     2477704 :       elt_init = reshape_init_r (elt_type, d,
    6648             :                                  /*first_initializer_p=*/NULL_TREE,
    6649             :                                  complain);
    6650     2477704 :       if (elt_init == error_mark_node)
    6651         138 :         return error_mark_node;
    6652     2477566 :       tree idx = size_int (index);
    6653     2477566 :       if (reuse)
    6654             :         {
    6655     2107053 :           old_cur->index = idx;
    6656     2107053 :           old_cur->value = elt_init;
    6657             :         }
    6658             :       else
    6659      370513 :         CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    6660             :                                 idx, elt_init);
    6661     2477566 :       if (!TREE_CONSTANT (elt_init))
    6662      103650 :         TREE_CONSTANT (new_init) = false;
    6663             : 
    6664             :       /* This can happen with an invalid initializer (c++/54501).  */
    6665     2477566 :       if (d->cur == old_cur && !sized_array_p)
    6666             :         break;
    6667             :     }
    6668             : 
    6669             :   return new_init;
    6670             : }
    6671             : 
    6672             : /* Subroutine of reshape_init_r, processes the initializers for arrays.
    6673             :    Parameters are the same of reshape_init_r.  */
    6674             : 
    6675             : static tree
    6676      196811 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
    6677             :                     tsubst_flags_t complain)
    6678             : {
    6679      196811 :   tree max_index = NULL_TREE;
    6680             : 
    6681      196811 :   gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
    6682             : 
    6683      196811 :   if (TYPE_DOMAIN (type))
    6684      149435 :     max_index = array_type_nelts (type);
    6685             : 
    6686      196811 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    6687      196811 :                                first_initializer_p, complain);
    6688             : }
    6689             : 
    6690             : /* Subroutine of reshape_init_r, processes the initializers for vectors.
    6691             :    Parameters are the same of reshape_init_r.  */
    6692             : 
    6693             : static tree
    6694       38871 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
    6695             : {
    6696       38871 :   tree max_index = NULL_TREE;
    6697             : 
    6698       38871 :   gcc_assert (VECTOR_TYPE_P (type));
    6699             : 
    6700       38871 :   if (COMPOUND_LITERAL_P (d->cur->value))
    6701             :     {
    6702           0 :       tree value = d->cur->value;
    6703           0 :       if (!same_type_p (TREE_TYPE (value), type))
    6704             :         {
    6705           0 :           if (complain & tf_error)
    6706           0 :             error ("invalid type %qT as initializer for a vector of type %qT",
    6707           0 :                    TREE_TYPE (d->cur->value), type);
    6708           0 :           value = error_mark_node;
    6709             :         }
    6710           0 :       ++d->cur;
    6711           0 :       return value;
    6712             :     }
    6713             : 
    6714             :   /* For a vector, we initialize it as an array of the appropriate size.  */
    6715       38871 :   if (VECTOR_TYPE_P (type))
    6716       38871 :     max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
    6717             : 
    6718       38871 :   return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
    6719       38871 :                                NULL_TREE, complain);
    6720             : }
    6721             : 
    6722             : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
    6723             :    INIT, in isolation from any designator or other initializers.  */
    6724             : 
    6725             : static tree
    6726       65421 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
    6727             : {
    6728             :   /* We could also implement this by wrapping init in a new CONSTRUCTOR and
    6729             :      calling reshape_init, but this way can just live on the stack.  */
    6730       65421 :   constructor_elt elt = { /*index=*/NULL_TREE, init };
    6731       65421 :   reshape_iter iter = { &elt, &elt + 1 };
    6732       65421 :   return reshape_init_r (type, &iter,
    6733             :                          /*first_initializer_p=*/NULL_TREE,
    6734       65421 :                          complain);
    6735             : }
    6736             : 
    6737             : /* Subroutine of reshape_init_r, processes the initializers for classes
    6738             :    or union. Parameters are the same of reshape_init_r.  */
    6739             : 
    6740             : static tree
    6741     1243118 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
    6742             :                     tsubst_flags_t complain)
    6743             : {
    6744     1243118 :   tree field;
    6745     1243118 :   tree new_init;
    6746             : 
    6747     1243118 :   gcc_assert (CLASS_TYPE_P (type));
    6748             : 
    6749             :   /* The initializer for a class is always a CONSTRUCTOR.  */
    6750     1243118 :   new_init = build_constructor (init_list_type_node, NULL);
    6751             : 
    6752     1243118 :   int binfo_idx = -1;
    6753     1243118 :   tree binfo = TYPE_BINFO (type);
    6754     1243118 :   tree base_binfo = NULL_TREE;
    6755     1243118 :   if (cxx_dialect >= cxx17 && uses_template_parms (type))
    6756             :     {
    6757             :       /* We get here from maybe_aggr_guide for C++20 class template argument
    6758             :          deduction.  In this case we need to look through the binfo because a
    6759             :          template doesn't have base fields.  */
    6760          99 :       binfo_idx = 0;
    6761          99 :       BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
    6762             :     }
    6763           6 :   if (base_binfo)
    6764             :     field = base_binfo;
    6765             :   else
    6766     1243112 :     field = next_aggregate_field (TYPE_FIELDS (type));
    6767             : 
    6768     1243118 :   if (!field)
    6769             :     {
    6770             :       /* [dcl.init.aggr]
    6771             : 
    6772             :         An initializer for an aggregate member that is an
    6773             :         empty class shall have the form of an empty
    6774             :         initializer-list {}.  */
    6775         257 :       if (!first_initializer_p)
    6776             :         {
    6777         216 :           if (complain & tf_error)
    6778          15 :             error ("initializer for %qT must be brace-enclosed", type);
    6779         216 :           return error_mark_node;
    6780             :         }
    6781             :       return new_init;
    6782             :     }
    6783             : 
    6784             :   /* For C++20 CTAD, handle pack expansions in the base list.  */
    6785             :   tree last_was_pack_expansion = NULL_TREE;
    6786             : 
    6787             :   /* Loop through the initializable fields, gathering initializers.  */
    6788     3873055 :   while (d->cur != d->end)
    6789             :     {
    6790     2710383 :       tree field_init;
    6791     2710383 :       constructor_elt *old_cur = d->cur;
    6792     2710383 :       bool direct_desig = false;
    6793             : 
    6794             :       /* Handle C++20 designated initializers.  */
    6795     2710383 :       if (d->cur->index)
    6796             :         {
    6797       65525 :           if (d->cur->index == error_mark_node)
    6798           7 :             return error_mark_node;
    6799             : 
    6800       65518 :           if (TREE_CODE (d->cur->index) == FIELD_DECL)
    6801             :             {
    6802             :               /* We already reshaped this; we should have returned early from
    6803             :                  reshape_init.  */
    6804           0 :               gcc_checking_assert (false);
    6805             :               if (field != d->cur->index)
    6806             :                 {
    6807             :                   if (tree id = DECL_NAME (d->cur->index))
    6808             :                     gcc_checking_assert (d->cur->index
    6809             :                                          == get_class_binding (type, id));
    6810             :                   field = d->cur->index;
    6811             :                 }
    6812             :             }
    6813       65518 :           else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    6814             :             {
    6815       65510 :               CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
    6816       65510 :               field = get_class_binding (type, d->cur->index);
    6817       65510 :               direct_desig = true;
    6818             :             }
    6819             :           else
    6820             :             {
    6821           8 :               if (complain & tf_error)
    6822           8 :                 error ("%<[%E] =%> used in a GNU-style designated initializer"
    6823             :                        " for class %qT", d->cur->index, type);
    6824           8 :               return error_mark_node;
    6825             :             }
    6826             : 
    6827       65510 :           if (!field && ANON_AGGR_TYPE_P (type))
    6828             :             /* Apparently the designator isn't for a member of this anonymous
    6829             :                struct, so head back to the enclosing class.  */
    6830             :             break;
    6831             : 
    6832       65507 :           if (!field || TREE_CODE (field) != FIELD_DECL)
    6833             :             {
    6834          14 :               if (complain & tf_error)
    6835           4 :                 error ("%qT has no non-static data member named %qD", type,
    6836           4 :                        d->cur->index);
    6837          14 :               return error_mark_node;
    6838             :             }
    6839             : 
    6840             :           /* If the element is an anonymous union object and the initializer
    6841             :              list is a designated-initializer-list, the anonymous union object
    6842             :              is initialized by the designated-initializer-list { D }, where D
    6843             :              is the designated-initializer-clause naming a member of the
    6844             :              anonymous union object.  */
    6845       65493 :           tree ictx = DECL_CONTEXT (field);
    6846       65493 :           if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
    6847             :             {
    6848             :               /* Find the anon aggr that is a direct member of TYPE.  */
    6849          82 :               while (ANON_AGGR_TYPE_P (ictx))
    6850             :                 {
    6851          81 :                   tree cctx = TYPE_CONTEXT (ictx);
    6852          81 :                   if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
    6853          71 :                     goto found;
    6854             :                   ictx = cctx;
    6855             :                 }
    6856             : 
    6857             :               /* Not found, e.g. FIELD is a member of a base class.  */
    6858           1 :               if (complain & tf_error)
    6859           1 :                 error ("%qD is not a direct member of %qT", field, type);
    6860           1 :               return error_mark_node;
    6861             : 
    6862          71 :             found:
    6863             :               /* Now find the TYPE member with that anon aggr type.  */
    6864          71 :               tree aafield = TYPE_FIELDS (type);
    6865         456 :               for (; aafield; aafield = TREE_CHAIN (aafield))
    6866         456 :                 if (TREE_TYPE (aafield) == ictx)
    6867             :                   break;
    6868           0 :               gcc_assert (aafield);
    6869             :               field = aafield;
    6870             :               direct_desig = false;
    6871             :             }
    6872             :         }
    6873             : 
    6874             :       /* If we processed all the member of the class, we are done.  */
    6875     2710279 :       if (!field)
    6876             :         break;
    6877             : 
    6878     5420114 :       last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
    6879     2710060 :                                  ? field : NULL_TREE);
    6880     2710060 :       if (last_was_pack_expansion)
    6881             :         /* Each non-trailing aggregate element that is a pack expansion is
    6882             :            assumed to correspond to no elements of the initializer list.  */
    6883           6 :         goto continue_;
    6884             : 
    6885     2710054 :       if (direct_desig)
    6886             :         {
    6887             :           /* The designated field F is initialized from this one element.
    6888             : 
    6889             :              Note that we don't want to do this if we found the designator
    6890             :              inside an anon aggr above; we use the normal code to implement:
    6891             : 
    6892             :              "If the element is an anonymous union member and the initializer
    6893             :              list is a brace-enclosed designated- initializer-list, the element
    6894             :              is initialized by the designated-initializer-list { D }, where D
    6895             :              is the designated- initializer-clause naming a member of the
    6896             :              anonymous union member."  */
    6897       65421 :           field_init = reshape_single_init (TREE_TYPE (field),
    6898       65421 :                                             d->cur->value, complain);
    6899       65421 :           d->cur++;
    6900             :         }
    6901             :       else
    6902     2644633 :         field_init = reshape_init_r (TREE_TYPE (field), d,
    6903             :                                      /*first_initializer_p=*/NULL_TREE,
    6904             :                                      complain);
    6905             : 
    6906     2710054 :       if (field_init == error_mark_node)
    6907         238 :         return error_mark_node;
    6908             : 
    6909     2709816 :       if (d->cur == old_cur && d->cur->index)
    6910             :         {
    6911             :           /* This can happen with an invalid initializer for a flexible
    6912             :              array member (c++/54441).  */
    6913           0 :           if (complain & tf_error)
    6914           0 :             error ("invalid initializer for %q#D", field);
    6915           0 :           return error_mark_node;
    6916             :         }
    6917             : 
    6918     2709816 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
    6919             : 
    6920             :       /* [dcl.init.aggr]
    6921             : 
    6922             :         When a union  is  initialized with a brace-enclosed
    6923             :         initializer, the braces shall only contain an
    6924             :         initializer for the first member of the union.  */
    6925     2709816 :       if (TREE_CODE (type) == UNION_TYPE)
    6926             :         break;
    6927             : 
    6928     2630188 :     continue_:
    6929     2630194 :       if (base_binfo)
    6930             :         {
    6931           9 :           if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
    6932             :             field = base_binfo;
    6933             :           else
    6934           6 :             field = next_aggregate_field (TYPE_FIELDS (type));
    6935             :         }
    6936             :       else
    6937     2630185 :         field = next_aggregate_field (DECL_CHAIN (field));
    6938             :     }
    6939             : 
    6940             :   /* A trailing aggregate element that is a pack expansion is assumed to
    6941             :      correspond to all remaining elements of the initializer list (if any).  */
    6942     1242593 :   if (last_was_pack_expansion)
    6943             :     {
    6944           5 :       CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
    6945             :                               last_was_pack_expansion, d->cur->value);
    6946          14 :       while (d->cur != d->end)
    6947           9 :         d->cur++;
    6948             :     }
    6949             : 
    6950             :   return new_init;
    6951             : }
    6952             : 
    6953             : /* Subroutine of reshape_init_r.  We're in a context where C99 initializer
    6954             :    designators are not valid; either complain or return true to indicate
    6955             :    that reshape_init_r should return error_mark_node.  */
    6956             : 
    6957             : static bool
    6958        4918 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
    6959             : {
    6960        4918 :   if (d->cur->index)
    6961             :     {
    6962          40 :       if (complain & tf_error)
    6963          60 :         error_at (cp_expr_loc_or_input_loc (d->cur->index),
    6964             :                   "C99 designator %qE outside aggregate initializer",
    6965             :                   d->cur->index);
    6966             :       else
    6967             :         return true;
    6968             :     }
    6969             :   return false;
    6970             : }
    6971             : 
    6972             : /* Subroutine of reshape_init, which processes a single initializer (part of
    6973             :    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    6974             :    iterator within the CONSTRUCTOR which points to the initializer to process.
    6975             :    If this is the first initializer of the outermost CONSTRUCTOR node,
    6976             :    FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE.  */
    6977             : 
    6978             : static tree
    6979     6669713 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
    6980             :                 tsubst_flags_t complain)
    6981             : {
    6982     6669713 :   tree init = d->cur->value;
    6983             : 
    6984     6669713 :   if (error_operand_p (init))
    6985          90 :     return error_mark_node;
    6986             : 
    6987     1481869 :   if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
    6988     6674373 :       && has_designator_problem (d, complain))
    6989           0 :     return error_mark_node;
    6990             : 
    6991     6669623 :   tree stripped_init = tree_strip_any_location_wrapper (init);
    6992             : 
    6993     6669623 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    6994             :     {
    6995             :       /* A complex type can be initialized from one or two initializers,
    6996             :          but braces are not elided.  */
    6997         557 :       d->cur++;
    6998         557 :       if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
    6999             :         {
    7000          10 :           if (CONSTRUCTOR_NELTS (stripped_init) > 2)
    7001             :             {
    7002           0 :               if (complain & tf_error)
    7003           0 :                 error ("too many initializers for %qT", type);
    7004             :               else
    7005           0 :                 return error_mark_node;
    7006             :             }
    7007             :         }
    7008         547 :       else if (first_initializer_p && d->cur != d->end)
    7009             :         {
    7010          37 :           vec<constructor_elt, va_gc> *v = 0;
    7011          37 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
    7012          37 :           CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, d->cur->value);
    7013          37 :           if (has_designator_problem (d, complain))
    7014           0 :             return error_mark_node;
    7015          37 :           d->cur++;
    7016          37 :           init = build_constructor (init_list_type_node, v);
    7017             :         }
    7018         557 :       return init;
    7019             :     }
    7020             : 
    7021             :   /* A non-aggregate type is always initialized with a single
    7022             :      initializer.  */
    7023    13290557 :   if (!CP_AGGREGATE_TYPE_P (type)
    7024             :       /* As is an array with dependent bound, which we can see
    7025             :          during C++20 aggregate CTAD.  */
    7026     8636004 :       || (cxx_dialect >= cxx20
    7027       82713 :           && TREE_CODE (type) == ARRAY_TYPE
    7028       13917 :           && uses_template_parms (TYPE_DOMAIN (type))))
    7029             :     {
    7030             :       /* It is invalid to initialize a non-aggregate type with a
    7031             :          brace-enclosed initializer before C++0x.
    7032             :          We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
    7033             :          of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
    7034             :          a CONSTRUCTOR (with a record type).  */
    7035     4654557 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR
    7036             :           /* Don't complain about a capture-init.  */
    7037      210774 :           && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
    7038     4865298 :           && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
    7039             :         {
    7040      210694 :           if (SCALAR_TYPE_P (type))
    7041             :             {
    7042         471 :               if (cxx_dialect < cxx11)
    7043             :                 {
    7044          18 :                   if (complain & tf_error)
    7045          18 :                     error ("braces around scalar initializer for type %qT",
    7046             :                            type);
    7047          18 :                   init = error_mark_node;
    7048             :                 }
    7049         453 :               else if (first_initializer_p
    7050         453 :                        || (CONSTRUCTOR_NELTS (stripped_init) > 0
    7051         296 :                            && (BRACE_ENCLOSED_INITIALIZER_P
    7052             :                                (CONSTRUCTOR_ELT (stripped_init,0)->value))))
    7053             :                 {
    7054          18 :                   if (complain & tf_error)
    7055          18 :                     error ("too many braces around scalar initializer "
    7056             :                            "for type %qT", type);
    7057          18 :                   init = error_mark_node;
    7058             :                 }
    7059             :             }
    7060             :           else
    7061      210223 :             maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7062             :         }
    7063             : 
    7064     4654557 :       d->cur++;
    7065     4654557 :       return init;
    7066             :     }
    7067             : 
    7068             :   /* "If T is a class type and the initializer list has a single element of
    7069             :      type cv U, where U is T or a class derived from T, the object is
    7070             :      initialized from that element."  Even if T is an aggregate.  */
    7071     1993810 :   if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
    7072     1707518 :       && first_initializer_p
    7073             :       /* But not if it's a designated init.  */
    7074     1269774 :       && !d->cur->index
    7075     1243774 :       && d->end - d->cur == 1
    7076     2273703 :       && reference_related_p (type, TREE_TYPE (init)))
    7077             :     {
    7078         370 :       d->cur++;
    7079         370 :       return init;
    7080             :     }
    7081             : 
    7082             :   /* [dcl.init.aggr]
    7083             : 
    7084             :      All implicit type conversions (clause _conv_) are considered when
    7085             :      initializing the aggregate member with an initializer from an
    7086             :      initializer-list.  If the initializer can initialize a member,
    7087             :      the member is initialized.  Otherwise, if the member is itself a
    7088             :      non-empty subaggregate, brace elision is assumed and the
    7089             :      initializer is considered for the initialization of the first
    7090             :      member of the subaggregate.  */
    7091      895657 :   if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
    7092             :       /* But don't try this for the first initializer, since that would be
    7093             :          looking through the outermost braces; A a2 = { a1 }; is not a
    7094             :          valid aggregate initialization.  */
    7095     1118547 :       && !first_initializer_p
    7096     2018642 :       && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
    7097        2582 :           || can_convert_arg (type, TREE_TYPE (init), init, LOOKUP_NORMAL,
    7098             :                               complain)))
    7099             :     {
    7100        1941 :       d->cur++;
    7101        1941 :       return init;
    7102             :     }
    7103             : 
    7104             :   /* [dcl.init.string]
    7105             : 
    7106             :       A char array (whether plain char, signed char, or unsigned char)
    7107             :       can be initialized by a string-literal (optionally enclosed in
    7108             :       braces); a wchar_t array can be initialized by a wide
    7109             :       string-literal (optionally enclosed in braces).  */
    7110     2012198 :   if (TREE_CODE (type) == ARRAY_TYPE
    7111     2012198 :       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
    7112             :     {
    7113       44975 :       tree str_init = init;
    7114       44975 :       tree stripped_str_init = stripped_init;
    7115       44975 :       reshape_iter stripd = {};
    7116             : 
    7117             :       /* Strip one level of braces if and only if they enclose a single
    7118             :          element (as allowed by [dcl.init.string]).  */
    7119       44975 :       if (!first_initializer_p
    7120        8388 :           && TREE_CODE (stripped_str_init) == CONSTRUCTOR
    7121       52794 :           && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
    7122             :         {
    7123         324 :           stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
    7124         324 :           str_init = stripd.cur->value;
    7125         324 :           stripped_str_init = tree_strip_any_location_wrapper (str_init);
    7126             :         }
    7127             : 
    7128             :       /* If it's a string literal, then it's the initializer for the array
    7129             :          as a whole. Otherwise, continue with normal initialization for
    7130             :          array types (one value per array element).  */
    7131       44975 :       if (TREE_CODE (stripped_str_init) == STRING_CST)
    7132             :         {
    7133          58 :           if ((first_initializer_p && has_designator_problem (d, complain))
    7134         659 :               || (stripd.cur && has_designator_problem (&stripd, complain)))
    7135         601 :             return error_mark_node;
    7136         601 :           d->cur++;
    7137         601 :           return str_init;
    7138             :         }
    7139             :     }
    7140             : 
    7141             :   /* The following cases are about aggregates. If we are not within a full
    7142             :      initializer already, and there is not a CONSTRUCTOR, it means that there
    7143             :      is a missing set of braces (that is, we are processing the case for
    7144             :      which reshape_init exists).  */
    7145     2011597 :   bool braces_elided_p = false;
    7146     2011597 :   if (!first_initializer_p)
    7147             :     {
    7148      534906 :       if (TREE_CODE (stripped_init) == CONSTRUCTOR)
    7149             :         {
    7150      532820 :           tree init_type = TREE_TYPE (init);
    7151      532820 :           if (init_type && TYPE_PTRMEMFUNC_P (init_type))
    7152             :             /* There is no need to call reshape_init for pointer-to-member
    7153             :                function initializers, as they are always constructed correctly
    7154             :                by the front end.  Here we have e.g. {.__pfn=0B, .__delta=0},
    7155             :                which is missing outermost braces.  We should warn below, and
    7156             :                one of the routines below will wrap it in additional { }.  */;
    7157             :           /* For a nested compound literal, proceed to specialized routines,
    7158             :              to handle initialization of arrays and similar.  */
    7159      532808 :           else if (COMPOUND_LITERAL_P (stripped_init))
    7160           6 :             gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7161             :           /* If we have an unresolved designator, we need to find the member it
    7162             :              designates within TYPE, so proceed to the routines below.  For
    7163             :              FIELD_DECL or INTEGER_CST designators, we're already initializing
    7164             :              the designated element.  */
    7165      532802 :           else if (d->cur->index
    7166          17 :                    && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
    7167             :             /* Brace elision with designators is only permitted for anonymous
    7168             :                aggregates.  */
    7169           5 :             gcc_checking_assert (ANON_AGGR_TYPE_P (type));
    7170             :           /* A CONSTRUCTOR of the target's type is a previously
    7171             :              digested initializer.  */
    7172      532797 :           else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
    7173             :             {
    7174           0 :               ++d->cur;
    7175           0 :               return init;
    7176             :             }
    7177             :           else
    7178             :             {
    7179             :               /* Something that hasn't been reshaped yet.  */
    7180      532797 :               ++d->cur;
    7181      532797 :               gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
    7182      532797 :               return reshape_init (type, init, complain);
    7183             :             }
    7184             :         }
    7185             : 
    7186        2109 :       if (complain & tf_warning)
    7187        1889 :         warning (OPT_Wmissing_braces,
    7188             :                  "missing braces around initializer for %qT",
    7189             :                  type);
    7190             :       braces_elided_p = true;
    7191             :     }
    7192             : 
    7193             :   /* Dispatch to specialized routines.  */
    7194     1478800 :   tree new_init;
    7195     1478800 :   if (CLASS_TYPE_P (type))
    7196     1243118 :     new_init = reshape_init_class (type, d, first_initializer_p, complain);
    7197      235682 :   else if (TREE_CODE (type) == ARRAY_TYPE)
    7198      196811 :     new_init = reshape_init_array (type, d, first_initializer_p, complain);
    7199       38871 :   else if (VECTOR_TYPE_P (type))
    7200       38871 :     new_init = reshape_init_vector (type, d, complain);
    7201             :   else
    7202           0 :     gcc_unreachable();
    7203             : 
    7204     1478800 :   if (braces_elided_p
    7205        2109 :       && TREE_CODE (new_init) == CONSTRUCTOR)
    7206        1886 :     CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
    7207             : 
    7208             :   return new_init;
    7209             : }
    7210             : 
    7211             : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
    7212             :    brace-enclosed aggregate initializer.
    7213             : 
    7214             :    INIT is the CONSTRUCTOR containing the list of initializers describing
    7215             :    a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
    7216             :    It may not presently match the shape of the TYPE; for example:
    7217             : 
    7218             :      struct S { int a; int b; };
    7219             :      struct S a[] = { 1, 2, 3, 4 };
    7220             : 
    7221             :    Here INIT will hold a vector of four elements, rather than a
    7222             :    vector of two elements, each itself a vector of two elements.  This
    7223             :    routine transforms INIT from the former form into the latter.  The
    7224             :    revised CONSTRUCTOR node is returned.  */
    7225             : 
    7226             : tree
    7227     4490481 : reshape_init (tree type, tree init, tsubst_flags_t complain)
    7228             : {
    7229     4490481 :   vec<constructor_elt, va_gc> *v;
    7230     4490481 :   reshape_iter d;
    7231     4490481 :   tree new_init;
    7232             : 
    7233     4490481 :   gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
    7234             : 
    7235     4490481 :   v = CONSTRUCTOR_ELTS (init);
    7236             : 
    7237             :   /* An empty constructor does not need reshaping, and it is always a valid
    7238             :      initializer.  */
    7239     4490745 :   if (vec_safe_is_empty (v))
    7240             :     return init;
    7241             : 
    7242     1482444 :   if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
    7243             :     /* Already reshaped.  */
    7244             :     return init;
    7245             : 
    7246             :   /* Brace elision is not performed for a CONSTRUCTOR representing
    7247             :      parenthesized aggregate initialization.  */
    7248     1482333 :   if (CONSTRUCTOR_IS_PAREN_INIT (init))
    7249             :     {
    7250         166 :       tree elt = (*v)[0].value;
    7251             :       /* If we're initializing a char array from a string-literal that is
    7252             :          enclosed in braces, unwrap it here.  */
    7253         166 :       if (TREE_CODE (type) == ARRAY_TYPE
    7254         102 :           && vec_safe_length (v) == 1
    7255          58 :           && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
    7256         181 :           && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
    7257             :         return elt;
    7258         153 :       return init;
    7259             :     }
    7260             : 
    7261             :   /* Handle [dcl.init.list] direct-list-initialization from
    7262             :      single element of enumeration with a fixed underlying type.  */
    7263     1482167 :   if (is_direct_enum_init (type, init))
    7264             :     {
    7265         212 :       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
    7266         212 :       type = cv_unqualified (type);
    7267         212 :       if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
    7268             :         {
    7269         182 :           warning_sentinel w (warn_useless_cast);
    7270         182 :           warning_sentinel w2 (warn_ignored_qualifiers);
    7271         182 :           return cp_build_c_cast (input_location, type, elt,
    7272             :                                   tf_warning_or_error);
    7273         182 :         }
    7274             :       else
    7275          30 :         return error_mark_node;
    7276             :     }
    7277             : 
    7278             :   /* Recurse on this CONSTRUCTOR.  */
    7279     1481955 :   d.cur = &(*v)[0];
    7280     1481955 :   d.end = d.cur + v->length ();
    7281             : 
    7282     1481955 :   new_init = reshape_init_r (type, &d, init, complain);
    7283     1481955 :   if (new_init == error_mark_node)
    7284             :     return error_mark_node;
    7285             : 
    7286             :   /* Make sure all the element of the constructor were used. Otherwise,
    7287             :      issue an error about exceeding initializers.  */
    7288     1481462 :   if (d.cur != d.end)
    7289             :     {
    7290         121 :       if (complain & tf_error)
    7291          67 :         error ("too many initializers for %qT", type);
    7292         121 :       return error_mark_node;
    7293             :     }
    7294             : 
    7295     1481341 :   if (CONSTRUCTOR_IS_DIRECT_INIT (init)
    7296     1481341 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7297       79674 :     CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
    7298     1481341 :   if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
    7299     1481341 :       && BRACE_ENCLOSED_INITIALIZER_P (new_init))
    7300       15624 :     gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
    7301             :                          || seen_error ());
    7302             : 
    7303             :   return new_init;
    7304             : }
    7305             : 
    7306             : /* Verify array initializer.  Returns true if errors have been reported.  */
    7307             : 
    7308             : bool
    7309      510929 : check_array_initializer (tree decl, tree type, tree init)
    7310             : {
    7311      510929 :   tree element_type = TREE_TYPE (type);
    7312             : 
    7313             :   /* Structured binding when initialized with an array type needs
    7314             :      to have complete type.  */
    7315      510929 :   if (decl
    7316      508229 :       && DECL_DECOMPOSITION_P (decl)
    7317          74 :       && !DECL_DECOMP_BASE (decl)
    7318      511003 :       && !COMPLETE_TYPE_P (type))
    7319             :     {
    7320           0 :       error_at (DECL_SOURCE_LOCATION (decl),
    7321             :                 "structured binding has incomplete type %qT", type);
    7322           0 :       TREE_TYPE (decl) = error_mark_node;
    7323           0 :       return true;
    7324             :     }
    7325             : 
    7326             :   /* The array type itself need not be complete, because the
    7327             :      initializer may tell us how many elements are in the array.
    7328             :      But, the elements of the array must be complete.  */
    7329      510929 :   if (!COMPLETE_TYPE_P (complete_type (element_type)))
    7330             :     {
    7331          19 :       if (decl)
    7332          11 :         error_at (DECL_SOURCE_LOCATION (decl),
    7333             :                   "elements of array %q#D have incomplete type", decl);
    7334             :       else
    7335           8 :         error ("elements of array %q#T have incomplete type", type);
    7336          19 :       return true;
    7337             :     }
    7338             : 
    7339      510910 :   location_t loc = (decl ? location_of (decl) : input_location);
    7340      510910 :   if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
    7341             :     return true;
    7342             : 
    7343             :   /* A compound literal can't have variable size.  */
    7344      510910 :   if (init && !decl
    7345      510910 :       && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
    7346        2688 :           || !TREE_CONSTANT (TYPE_SIZE (element_type))))
    7347             :     {
    7348           4 :       error ("variable-sized compound literal");
    7349           4 :       return true;
    7350             :     }
    7351             :   return false;
    7352             : }
    7353             : 
    7354             : /* Subroutine of check_initializer; args are passed down from that function.
    7355             :    Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init.  */
    7356             : 
    7357             : static tree
    7358      960547 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
    7359             : {
    7360      960547 :   gcc_assert (stmts_are_full_exprs_p ());
    7361      960547 :   if (init)
    7362      739731 :     maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
    7363      960547 :   return build_aggr_init (decl, init, flags, tf_warning_or_error);
    7364             : }
    7365             : 
    7366             : /* Verify INIT (the initializer for DECL), and record the
    7367             :    initialization in DECL_INITIAL, if appropriate.  CLEANUP is as for
    7368             :    grok_reference_init.
    7369             : 
    7370             :    If the return value is non-NULL, it is an expression that must be
    7371             :    evaluated dynamically to initialize DECL.  */
    7372             : 
    7373             : static tree
    7374    22683612 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
    7375             : {
    7376    22683612 :   tree type;
    7377    22683612 :   tree init_code = NULL;
    7378    22683612 :   tree core_type;
    7379             : 
    7380             :   /* Things that are going to be initialized need to have complete
    7381             :      type.  */
    7382    22683612 :   TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
    7383             : 
    7384    22683612 :   if (DECL_HAS_VALUE_EXPR_P (decl))
    7385             :     {
    7386             :       /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
    7387             :          it doesn't have storage to be initialized.  */
    7388          91 :       gcc_assert (init == NULL_TREE);
    7389             :       return NULL_TREE;
    7390             :     }
    7391             : 
    7392    22683521 :   if (type == error_mark_node)
    7393             :     /* We will have already complained.  */
    7394             :     return NULL_TREE;
    7395             : 
    7396    22683521 :   if (TREE_CODE (type) == ARRAY_TYPE)
    7397             :     {
    7398      508229 :       if (check_array_initializer (decl, type, init))
    7399             :         return NULL_TREE;
    7400             :     }
    7401    22175292 :   else if (!COMPLETE_TYPE_P (type))
    7402             :     {
    7403          38 :       error_at (DECL_SOURCE_LOCATION (decl),
    7404             :                 "%q#D has incomplete type", decl);
    7405          38 :       TREE_TYPE (decl) = error_mark_node;
    7406          38 :       return NULL_TREE;
    7407             :     }
    7408             :   else
    7409             :     /* There is no way to make a variable-sized class type in GNU C++.  */
    7410    22175254 :     gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
    7411             : 
    7412    22683472 :   if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
    7413             :     {
    7414      552310 :       int init_len = CONSTRUCTOR_NELTS (init);
    7415      552310 :       if (SCALAR_TYPE_P (type))
    7416             :         {
    7417        3307 :           if (init_len == 0)
    7418             :             {
    7419        1122 :               maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
    7420        1122 :               init = build_zero_init (type, NULL_TREE, false);
    7421             :             }
    7422        2185 :           else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
    7423             :             {
    7424          16 :               error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7425             :                         "scalar object %qD requires one element in "
    7426             :                         "initializer", decl);
    7427           8 :               TREE_TYPE (decl) = error_mark_node;
    7428           8 :               return NULL_TREE;
    7429             :             }
    7430             :         }
    7431             :     }
    7432             : 
    7433    22683464 :   if (TREE_CODE (decl) == CONST_DECL)
    7434             :     {
    7435           0 :       gcc_assert (!TYPE_REF_P (type));
    7436             : 
    7437           0 :       DECL_INITIAL (decl) = init;
    7438             : 
    7439           0 :       gcc_assert (init != NULL_TREE);
    7440             :       init = NULL_TREE;
    7441             :     }
    7442    22683464 :   else if (!init && DECL_REALLY_EXTERN (decl))
    7443             :     ;
    7444     2697193 :   else if (init || type_build_ctor_call (type)
    7445    25159837 :            || TYPE_REF_P (type))
    7446             :     {
    7447    20207107 :       if (TYPE_REF_P (type))
    7448             :         {
    7449      155711 :           init = grok_reference_init (decl, type, init, flags);
    7450      155711 :           flags |= LOOKUP_ALREADY_DIGESTED;
    7451             :         }
    7452    20051396 :       else if (!init)
    7453      220820 :         check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    7454             :                                            tf_warning_or_error);
    7455             :       /* Do not reshape constructors of vectors (they don't need to be
    7456             :          reshaped.  */
    7457    19830576 :       else if (BRACE_ENCLOSED_INITIALIZER_P (init))
    7458             :         {
    7459      550936 :           if (is_std_init_list (type))
    7460             :             {
    7461         238 :               init = perform_implicit_conversion (type, init,
    7462             :                                                   tf_warning_or_error);
    7463         238 :               flags |= LOOKUP_ALREADY_DIGESTED;
    7464             :             }
    7465      550698 :           else if (TYPE_NON_AGGREGATE_CLASS (type))
    7466             :             {
    7467             :               /* Don't reshape if the class has constructors.  */
    7468       88253 :               if (cxx_dialect == cxx98)
    7469           6 :                 error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
    7470             :                           "in C++98 %qD must be initialized by "
    7471             :                           "constructor, not by %<{...}%>",
    7472             :                           decl);
    7473             :             }
    7474      462445 :           else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
    7475             :             {
    7476           0 :               error ("opaque vector types cannot be initialized");
    7477           0 :               init = error_mark_node;
    7478             :             }
    7479             :           else
    7480             :             {
    7481      462445 :               init = reshape_init (type, init, tf_warning_or_error);
    7482      462445 :               flags |= LOOKUP_NO_NARROWING;
    7483             :             }
    7484             :         }
    7485             :       /* [dcl.init] "Otherwise, if the destination type is an array, the object
    7486             :          is initialized as follows..."  So handle things like
    7487             : 
    7488             :           int a[](1, 2, 3);
    7489             : 
    7490             :          which is permitted in C++20 by P0960.  */
    7491    19279640 :       else if (TREE_CODE (init) == TREE_LIST
    7492      383858 :                && TREE_TYPE (init) == NULL_TREE
    7493      383858 :                && TREE_CODE (type) == ARRAY_TYPE
    7494          82 :                && !DECL_DECOMPOSITION_P (decl)
    7495    19279714 :                && (cxx_dialect >= cxx20))
    7496          47 :         init = do_aggregate_paren_init (init, type);
    7497    19279593 :       else if (TREE_CODE (init) == TREE_LIST
    7498      383811 :                && TREE_TYPE (init) != unknown_type_node
    7499    19663404 :                && !MAYBE_CLASS_TYPE_P (type))
    7500             :         {
    7501       94133 :           gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    7502             : 
    7503             :           /* We get here with code like `int a (2);' */
    7504       94133 :           init = build_x_compound_expr_from_list (init, ELK_INIT,
    7505             :                                                   tf_warning_or_error);
    7506             :         }
    7507             : 
    7508             :       /* If DECL has an array type without a specific bound, deduce the
    7509             :          array size from the initializer.  */
    7510    20207107 :       maybe_deduce_size_from_array_init (decl, init);
    7511    20207107 :       type = TREE_TYPE (decl);
    7512    20207107 :       if (type == error_mark_node)
    7513             :         return NULL_TREE;
    7514             : 
    7515    39229486 :       if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
    7516     1345105 :            && !(flags & LOOKUP_ALREADY_DIGESTED)
    7517     1344867 :            && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
    7518      473599 :                 && CP_AGGREGATE_TYPE_P (type)
    7519      385346 :                 && (CLASS_TYPE_P (type)
    7520             :                     /* The call to build_aggr_init below could end up
    7521             :                        calling build_vec_init, which may break when we
    7522             :                        are processing a template.  */
    7523        1074 :                     || processing_template_decl
    7524        1011 :                     || !TYPE_NEEDS_CONSTRUCTING (type)
    7525         975 :                     || type_has_extended_temps (type))))
    7526    39453716 :           || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
    7527             :         {
    7528      960547 :           init_code = build_aggr_init_full_exprs (decl, init, flags);
    7529             : 
    7530             :           /* A constructor call is a non-trivial initializer even if
    7531             :              it isn't explicitly written.  */
    7532      960547 :           if (TREE_SIDE_EFFECTS (init_code))
    7533      956977 :             DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
    7534             : 
    7535             :           /* If this is a constexpr initializer, expand_default_init will
    7536             :              have returned an INIT_EXPR rather than a CALL_EXPR.  In that
    7537             :              case, pull the initializer back out and pass it down into
    7538             :              store_init_value.  */
    7539     2365588 :           while (true)
    7540             :             {
    7541     2365588 :               if (TREE_CODE (init_code) == EXPR_STMT
    7542     1410562 :                   || TREE_CODE (init_code) == STMT_EXPR
    7543     1410280 :                   || TREE_CODE (init_code) == CONVERT_EXPR)
    7544     1404792 :                 init_code = TREE_OPERAND (init_code, 0);
    7545      960796 :               else if (TREE_CODE (init_code) == BIND_EXPR)
    7546         249 :                 init_code = BIND_EXPR_BODY (init_code);
    7547             :               else
    7548             :                 break;
    7549             :             }
    7550      960547 :           if (TREE_CODE (init_code) == INIT_EXPR)
    7551             :             {
    7552             :               /* In C++20, the call to build_aggr_init could have created
    7553             :                  an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
    7554             :                  A(1, 2).  */
    7555      450435 :               tree rhs = TREE_OPERAND (init_code, 1);
    7556      450435 :               if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
    7557             :                 /* Avoid leaking TARGET_EXPR into template trees.  */
    7558         233 :                 rhs = build_implicit_conv_flags (type, init, flags);
    7559      450435 :               init = rhs;
    7560             : 
    7561      450435 :               init_code = NULL_TREE;
    7562             :               /* Don't call digest_init; it's unnecessary and will complain
    7563             :                  about aggregate initialization of non-aggregate classes.  */
    7564      450435 :               flags |= LOOKUP_ALREADY_DIGESTED;
    7565             :             }
    7566      510112 :           else if (DECL_DECLARED_CONSTEXPR_P (decl)
    7567     1019980 :                    || DECL_DECLARED_CONSTINIT_P (decl))
    7568             :             {
    7569             :               /* Declared constexpr or constinit, but no suitable initializer;
    7570             :                  massage init appropriately so we can pass it into
    7571             :                  store_init_value for the error.  */
    7572         249 :               tree new_init = NULL_TREE;
    7573         249 :               if (!processing_template_decl
    7574         203 :                   && TREE_CODE (init_code) == CALL_EXPR)
    7575         179 :                 new_init = build_cplus_new (type, init_code, tf_none);
    7576          63 :               else if (CLASS_TYPE_P (type)
    7577         133 :                        && (!init || TREE_CODE (init) == TREE_LIST))
    7578          19 :                 new_init = build_functional_cast (input_location, type,
    7579             :                                                   init, tf_none);
    7580         198 :               if (new_init)
    7581             :                 {
    7582         198 :                   init = new_init;
    7583         198 :                   if (TREE_CODE (init) == TARGET_EXPR
    7584         186 :                       && !(flags & LOOKUP_ONLYCONVERTING))
    7585         186 :                     TARGET_EXPR_DIRECT_INIT_P (init) = true;
    7586             :                 }
    7587             :               init_code = NULL_TREE;
    7588             :             }
    7589             :           else
    7590             :             init = NULL_TREE;
    7591             :         }
    7592             : 
    7593    20207100 :       if (init && TREE_CODE (init) != TREE_VEC)
    7594             :         {
    7595    19697221 :           init_code = store_init_value (decl, init, cleanups, flags);
    7596             : 
    7597    19686437 :           if (DECL_INITIAL (decl)
    7598    11937808 :               && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
    7599    20256499 :               && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
    7600             :             {
    7601      373901 :               tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
    7602      373901 :               if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
    7603      373901 :                   && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
    7604          48 :                 cp_complete_array_type (&TREE_TYPE (elt), elt, false);
    7605             :             }
    7606             : 
    7607      624970 :           if (pedantic && TREE_CODE (type) == ARRAY_TYPE
    7608       53093 :               && DECL_INITIAL (decl)
    7609       52945 :               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
    7610    19737282 :               && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
    7611           8 :             warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
    7612           4 :                                          DECL_SOURCE_LOCATION (decl)),
    7613             :                         0, "array %qD initialized by parenthesized "
    7614             :                         "string literal %qE",
    7615           4 :                         decl, DECL_INITIAL (decl));
    7616             :           init = NULL_TREE;
    7617             :         }
    7618             :     }
    7619             :   else
    7620             :     {
    7621     4952714 :       if (CLASS_TYPE_P (core_type = strip_array_types (type))
    7622     2911519 :           && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
    7623      435148 :               || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
    7624          21 :         diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
    7625             :                                                   /*complain=*/true);
    7626             : 
    7627     2476357 :       check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
    7628             :                                          tf_warning_or_error);
    7629             :     }
    7630             : 
    7631     2476357 :   if (init && init != error_mark_node)
    7632           0 :     init_code = cp_build_init_expr (decl, init);
    7633             : 
    7634     8260587 :   if (init_code && !TREE_SIDE_EFFECTS (init_code)
    7635    22676415 :       && init_code != error_mark_node)
    7636             :     init_code = NULL_TREE;
    7637             : 
    7638    22671053 :   if (init_code)
    7639             :     {
    7640             :       /* We might have set these in cp_finish_decl.  */
    7641     8258967 :       DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
    7642     8258967 :       TREE_CONSTANT (decl) = false;
    7643             :     }
    7644             : 
    7645     8258967 :   if (init_code
    7646     8258967 :       && DECL_IN_AGGR_P (decl)
    7647           7 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    7648             :     {
    7649           0 :       static int explained = 0;
    7650             : 
    7651           0 :       if (cxx_dialect < cxx11)
    7652           0 :         error ("initializer invalid for static member with constructor");
    7653           0 :       else if (cxx_dialect < cxx17)
    7654           0 :         error ("non-constant in-class initialization invalid for static "
    7655             :                "member %qD", decl);
    7656             :       else
    7657           0 :         error ("non-constant in-class initialization invalid for non-inline "
    7658             :                "static member %qD", decl);
    7659           0 :       if (!explained)
    7660             :         {
    7661           0 :           inform (input_location,
    7662             :                   "(an out of class initialization is required)");
    7663           0 :           explained = 1;
    7664             :         }
    7665           0 :       return NULL_TREE;
    7666             :     }
    7667             : 
    7668             :   return init_code;
    7669             : }
    7670             : 
    7671             : /* If DECL is not a local variable, give it RTL.  */
    7672             : 
    7673             : static void
    7674    61997370 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
    7675             : {
    7676    61997370 :   int toplev = toplevel_bindings_p ();
    7677    61997370 :   int defer_p;
    7678             : 
    7679             :   /* Set the DECL_ASSEMBLER_NAME for the object.  */
    7680    61997370 :   if (asmspec)
    7681             :     {
    7682             :       /* The `register' keyword, when used together with an
    7683             :          asm-specification, indicates that the variable should be
    7684             :          placed in a particular register.  */
    7685      474788 :       if (VAR_P (decl) && DECL_REGISTER (decl))
    7686             :         {
    7687          98 :           set_user_assembler_name (decl, asmspec);
    7688          98 :           DECL_HARD_REGISTER (decl) = 1;
    7689             :         }
    7690             :       else
    7691             :         {
    7692      474690 :           if (TREE_CODE (decl) == FUNCTION_DECL
    7693      474690 :               && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
    7694       58222 :             set_builtin_user_assembler_name (decl, asmspec);
    7695      474690 :           set_user_assembler_name (decl, asmspec);
    7696      474690 :           if (DECL_LOCAL_DECL_P (decl))
    7697          12 :             if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
    7698             :               /* We have to propagate the name to the ns-alias.
    7699             :                  This is horrible, as we're affecting a
    7700             :                  possibly-shared decl.  Again, a one-true-decl
    7701             :                  model breaks down.  */
    7702           8 :               if (ns_decl != error_mark_node)
    7703           8 :                 set_user_assembler_name (ns_decl, asmspec);
    7704             :         }
    7705             :     }
    7706             : 
    7707             :   /* Handle non-variables up front.  */
    7708    61997370 :   if (!VAR_P (decl))
    7709             :     {
    7710    35435033 :       rest_of_decl_compilation (decl, toplev, at_eof);
    7711    35435033 :       return;
    7712             :     }
    7713             : 
    7714             :   /* If we see a class member here, it should be a static data
    7715             :      member.  */
    7716    26562337 :   if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
    7717             :     {
    7718     2555660 :       gcc_assert (TREE_STATIC (decl));
    7719             :       /* An in-class declaration of a static data member should be
    7720             :          external; it is only a declaration, and not a definition.  */
    7721     2555660 :       if (init == NULL_TREE)
    7722     2555653 :         gcc_assert (DECL_EXTERNAL (decl)
    7723             :                     || !TREE_PUBLIC (decl));
    7724             :     }
    7725             : 
    7726             :   /* We don't create any RTL for local variables.  */
    7727    26562337 :   if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    7728             :     return;
    7729             : 
    7730             :   /* We defer emission of local statics until the corresponding
    7731             :      DECL_EXPR is expanded.  But with constexpr its function might never
    7732             :      be expanded, so go ahead and tell cgraph about the variable now.  */
    7733    25006870 :   defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
    7734       85258 :               && !var_in_maybe_constexpr_fn (decl))
    7735    24921712 :              || DECL_VIRTUAL_P (decl));
    7736             : 
    7737             :   /* Defer template instantiations.  */
    7738    12503435 :   if (DECL_LANG_SPECIFIC (decl)
    7739    12503435 :       && DECL_IMPLICIT_INSTANTIATION (decl))
    7740             :     defer_p = 1;
    7741             : 
    7742             :   /* If we're not deferring, go ahead and assemble the variable.  */
    7743     9568271 :   if (!defer_p)
    7744     7977541 :     rest_of_decl_compilation (decl, toplev, at_eof);
    7745             : }
    7746             : 
    7747             : /* walk_tree helper for wrap_temporary_cleanups, below.  */
    7748             : 
    7749             : static tree
    7750     6790207 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
    7751             : {
    7752             :   /* Stop at types or full-expression boundaries.  */
    7753     6790207 :   if (TYPE_P (*stmt_p)
    7754     6790169 :       || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
    7755             :     {
    7756         279 :       *walk_subtrees = 0;
    7757         279 :       return NULL_TREE;
    7758             :     }
    7759             : 
    7760     6789928 :   if (TREE_CODE (*stmt_p) == TARGET_EXPR)
    7761             :     {
    7762      109543 :       tree guard = (tree)data;
    7763      109543 :       tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
    7764             : 
    7765       95955 :       if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
    7766      198247 :           && !expr_noexcept_p (tcleanup, tf_none))
    7767             :         {
    7768         116 :           tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
    7769             :           /* Tell honor_protect_cleanup_actions to handle this as a separate
    7770             :              cleanup.  */
    7771         116 :           TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
    7772         116 :           TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
    7773             :         }
    7774             :     }
    7775             : 
    7776             :   return NULL_TREE;
    7777             : }
    7778             : 
    7779             : /* We're initializing a local variable which has a cleanup GUARD.  If there
    7780             :    are any temporaries used in the initializer INIT of this variable, we
    7781             :    need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
    7782             :    variable will be cleaned up properly if one of them throws.
    7783             : 
    7784             :    Unfortunately, there's no way to express this properly in terms of
    7785             :    nesting, as the regions for the temporaries overlap the region for the
    7786             :    variable itself; if there are two temporaries, the variable needs to be
    7787             :    the first thing destroyed if either of them throws.  However, we only
    7788             :    want to run the variable's cleanup if it actually got constructed.  So
    7789             :    we need to guard the temporary cleanups with the variable's cleanup if
    7790             :    they are run on the normal path, but not if they are run on the
    7791             :    exceptional path.  We implement this by telling
    7792             :    honor_protect_cleanup_actions to strip the variable cleanup from the
    7793             :    exceptional path.
    7794             : 
    7795             :    Another approach could be to make the variable cleanup region enclose
    7796             :    initialization, but depend on a flag to indicate that the variable is
    7797             :    initialized; that's effectively what we do for arrays.  But the current
    7798             :    approach works fine for non-arrays, and has no code overhead in the usual
    7799             :    case where the temporary destructors are noexcept.  */
    7800             : 
    7801             : static void
    7802      502743 : wrap_temporary_cleanups (tree init, tree guard)
    7803             : {
    7804      502743 :   if (TREE_CODE (guard) == BIND_EXPR)
    7805             :     {
    7806             :       /* An array cleanup region already encloses any temporary cleanups,
    7807             :          don't wrap it around them again.  */
    7808         397 :       gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
    7809             :       return;
    7810             :     }
    7811      502346 :   cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
    7812             : }
    7813             : 
    7814             : /* Generate code to initialize DECL (a local variable).  */
    7815             : 
    7816             : static void
    7817    14058882 : initialize_local_var (tree decl, tree init)
    7818             : {
    7819    14058882 :   tree type = TREE_TYPE (decl);
    7820    14058882 :   tree cleanup;
    7821    14058882 :   int already_used;
    7822             : 
    7823    14058882 :   gcc_assert (VAR_P (decl)
    7824             :               || TREE_CODE (decl) == RESULT_DECL);
    7825    14058882 :   gcc_assert (!TREE_STATIC (decl));
    7826             : 
    7827    14058882 :   if (DECL_SIZE (decl) == NULL_TREE)
    7828             :     {
    7829             :       /* If we used it already as memory, it must stay in memory.  */
    7830           0 :       DECL_INITIAL (decl) = NULL_TREE;
    7831           0 :       TREE_ADDRESSABLE (decl) = TREE_USED (decl);
    7832           0 :       return;
    7833             :     }
    7834             : 
    7835    14058882 :   if (type == error_mark_node)
    7836             :     return;
    7837             : 
    7838             :   /* Compute and store the initial value.  */
    7839    14058882 :   already_used = TREE_USED (decl) || TREE_USED (type);
    7840    14058882 :   if (TREE_USED (type))
    7841          41 :     DECL_READ_P (decl) = 1;
    7842             : 
    7843             :   /* Generate a cleanup, if necessary.  */
    7844    14058882 :   cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    7845             : 
    7846             :   /* Perform the initialization.  */
    7847    14058882 :   if (init)
    7848             :     {
    7849     8247153 :       tree rinit = (TREE_CODE (init) == INIT_EXPR
    7850     8247153 :                     ? TREE_OPERAND (init, 1) : NULL_TREE);
    7851     7720627 :       if (rinit && !TREE_SIDE_EFFECTS (rinit)
    7852    12265422 :           && TREE_OPERAND (init, 0) == decl)
    7853             :         {
    7854             :           /* Stick simple initializers in DECL_INITIAL so that
    7855             :              -Wno-init-self works (c++/34772).  */
    7856     4544792 :           DECL_INITIAL (decl) = rinit;
    7857             : 
    7858     4544792 :           if (warn_init_self && TYPE_REF_P (type))
    7859             :             {
    7860        2161 :               STRIP_NOPS (rinit);
    7861        2161 :               if (rinit == decl)
    7862           4 :                 warning_at (DECL_SOURCE_LOCATION (decl),
    7863             :                             OPT_Winit_self,
    7864             :                             "reference %qD is initialized with itself", decl);
    7865             :             }
    7866             :         }
    7867             :       else
    7868             :         {
    7869     3702361 :           int saved_stmts_are_full_exprs_p;
    7870             : 
    7871             :           /* If we're only initializing a single object, guard the
    7872             :              destructors of any temporaries used in its initializer with
    7873             :              its destructor.  */
    7874     3702361 :           if (cleanup)
    7875      502169 :             wrap_temporary_cleanups (init, cleanup);
    7876             : 
    7877     3702361 :           gcc_assert (building_stmt_list_p ());
    7878     3702361 :           saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
    7879     3702361 :           current_stmt_tree ()->stmts_are_full_exprs_p = 1;
    7880     3702361 :           finish_expr_stmt (init);
    7881     3702361 :           current_stmt_tree ()->stmts_are_full_exprs_p =
    7882             :             saved_stmts_are_full_exprs_p;
    7883             :         }
    7884             :     }
    7885             : 
    7886             :   /* Set this to 0 so we can tell whether an aggregate which was
    7887             :      initialized was ever used.  Don't do this if it has a
    7888             :      destructor, so we don't complain about the 'resource
    7889             :      allocation is initialization' idiom.  Now set
    7890             :      attribute((unused)) on types so decls of that type will be
    7891             :      marked used. (see TREE_USED, above.)  */
    7892    14058882 :   if (TYPE_NEEDS_CONSTRUCTING (type)
    7893      821336 :       && ! already_used
    7894        2794 :       && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    7895    14061267 :       && DECL_NAME (decl))
    7896        2380 :     TREE_USED (decl) = 0;
    7897    14056502 :   else if (already_used)
    7898    12582919 :     TREE_USED (decl) = 1;
    7899             : 
    7900    14058882 :   if (cleanup)
    7901      510762 :     finish_decl_cleanup (decl, cleanup);
    7902             : }
    7903             : 
    7904             : /* DECL is a VAR_DECL for a compiler-generated variable with static
    7905             :    storage duration (like a virtual table) whose initializer is a
    7906             :    compile-time constant.  Initialize the variable and provide it to the
    7907             :    back end.  */
    7908             : 
    7909             : void
    7910     1473509 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
    7911             : {
    7912     1473509 :   tree init;
    7913     1473509 :   gcc_assert (DECL_ARTIFICIAL (decl));
    7914     1473509 :   init = build_constructor (TREE_TYPE (decl), v);
    7915     1473509 :   gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
    7916     1473509 :   DECL_INITIAL (decl) = init;
    7917     1473509 :   DECL_INITIALIZED_P (decl) = 1;
    7918             :   /* Mark the decl as constexpr so that we can access its content
    7919             :      at compile time.  */
    7920     1473509 :   DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
    7921     1473509 :   DECL_DECLARED_CONSTEXPR_P (decl) = true;
    7922     1473509 :   determine_visibility (decl);
    7923     1473509 :   layout_var_decl (decl);
    7924     1473509 :   maybe_commonize_var (decl);
    7925     1473509 :   make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
    7926     1473509 : }
    7927             : 
    7928             : /* INIT is the initializer for a variable, as represented by the
    7929             :    parser.  Returns true iff INIT is value-dependent.  */
    7930             : 
    7931             : static bool
    7932     5139773 : value_dependent_init_p (tree init)
    7933             : {
    7934     5139773 :   if (TREE_CODE (init) == TREE_LIST)
    7935             :     /* A parenthesized initializer, e.g.: int i (3, 2); ? */
    7936          47 :     return any_value_dependent_elements_p (init);
    7937     5139726 :   else if (TREE_CODE (init) == CONSTRUCTOR)
    7938             :   /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
    7939             :     {
    7940       22283 :       if (dependent_type_p (TREE_TYPE (init)))
    7941             :         return true;
    7942             : 
    7943       22277 :       vec<constructor_elt, va_gc> *elts;
    7944       22277 :       size_t nelts;
    7945       22277 :       size_t i;
    7946             : 
    7947       22277 :       elts = CONSTRUCTOR_ELTS (init);
    7948       22277 :       nelts = vec_safe_length (elts);
    7949      380615 :       for (i = 0; i < nelts; ++i)
    7950      365330 :         if (value_dependent_init_p ((*elts)[i].value))
    7951             :           return true;
    7952             :     }
    7953             :   else
    7954             :     /* It must be a simple expression, e.g., int i = 3;  */
    7955     5117443 :     return value_dependent_expression_p (init);
    7956             :   
    7957             :   return false;
    7958             : }
    7959             : 
    7960             : // Returns true if a DECL is VAR_DECL with the concept specifier.
    7961             : static inline bool
    7962     1117141 : is_concept_var (tree decl)
    7963             : {
    7964     1117141 :   return (VAR_P (decl)
    7965             :           // Not all variables have DECL_LANG_SPECIFIC.
    7966     1117141 :           && DECL_LANG_SPECIFIC (decl)
    7967     1407241 :           && DECL_DECLARED_CONCEPT_P (decl));
    7968             : }
    7969             : 
    7970             : /* A helper function to be called via walk_tree.  If any label exists
    7971             :    under *TP, it is (going to be) forced.  Set has_forced_label_in_static.  */
    7972             : 
    7973             : static tree
    7974         439 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
    7975             : {
    7976         439 :   if (TYPE_P (*tp))
    7977           0 :     *walk_subtrees = 0;
    7978         439 :   if (TREE_CODE (*tp) == LABEL_DECL)
    7979           8 :     cfun->has_forced_label_in_static = 1;
    7980         439 :   return NULL_TREE;
    7981             : }
    7982             : 
    7983             : /* Return true if DECL has either a trivial destructor, or for C++20
    7984             :    is constexpr and has a constexpr destructor.  */
    7985             : 
    7986             : static bool
    7987    15967285 : decl_maybe_constant_destruction (tree decl, tree type)
    7988             : {
    7989    15967285 :   return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
    7990    15967285 :           || (cxx_dialect >= cxx20
    7991      108728 :               && VAR_P (decl)
    7992      108644 :               && DECL_DECLARED_CONSTEXPR_P (decl)
    7993         109 :               && type_has_constexpr_destructor (strip_array_types (type))));
    7994             : }
    7995             : 
    7996             : static tree declare_simd_adjust_this (tree *, int *, void *);
    7997             : 
    7998             : /* Helper function of omp_declare_variant_finalize.  Finalize one
    7999             :    "omp declare variant base" attribute.  Return true if it should be
    8000             :    removed.  */
    8001             : 
    8002             : static bool
    8003        1141 : omp_declare_variant_finalize_one (tree decl, tree attr)
    8004             : {
    8005        1141 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8006             :     {
    8007         124 :       walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8008             :                  DECL_ARGUMENTS (decl), NULL);
    8009         124 :       walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
    8010             :                  DECL_ARGUMENTS (decl), NULL);
    8011             :     }
    8012             : 
    8013        1141 :   tree ctx = TREE_VALUE (TREE_VALUE (attr));
    8014        1141 :   tree simd = omp_get_context_selector (ctx, "construct", "simd");
    8015        1141 :   if (simd)
    8016             :     {
    8017          68 :       TREE_VALUE (simd)
    8018          68 :         = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
    8019          68 :                                                  TREE_VALUE (simd));
    8020             :       /* FIXME, adjusting simd args unimplemented.  */
    8021          68 :       return true;
    8022             :     }
    8023             : 
    8024        1073 :   tree chain = TREE_CHAIN (TREE_VALUE (attr));
    8025        1073 :   location_t varid_loc
    8026        1073 :     = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
    8027        1073 :   location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
    8028        1073 :   cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
    8029        1073 :   tree variant = TREE_PURPOSE (TREE_VALUE (attr));
    8030             : 
    8031        1073 :   location_t save_loc = input_location;
    8032        1073 :   input_location = varid_loc;
    8033             : 
    8034        1073 :   releasing_vec args;
    8035        1073 :   tree parm = DECL_ARGUMENTS (decl);
    8036        1073 :   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
    8037         124 :     parm = DECL_CHAIN (parm);
    8038        1774 :   for (; parm; parm = DECL_CHAIN (parm))
    8039         701 :     if (type_dependent_expression_p (parm))
    8040          24 :       vec_safe_push (args, build_constructor (TREE_TYPE (parm), NULL));
    8041         725 :     else if (MAYBE_CLASS_TYPE_P (TREE_TYPE (parm)))
    8042          48 :       vec_safe_push (args, build_local_temp (TREE_TYPE (parm)));
    8043             :     else
    8044         629 :       vec_safe_push (args, build_zero_cst (TREE_TYPE (parm)));
    8045             : 
    8046        1073 :   bool koenig_p = false;
    8047        1073 :   if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
    8048             :     {
    8049        1065 :       if (identifier_p (variant)
    8050             :           /* In C++20, we may need to perform ADL for a template
    8051             :              name.  */
    8052        1049 :           || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
    8053          24 :               && identifier_p (TREE_OPERAND (variant, 0))))
    8054             :         {
    8055          16 :           if (!args->is_empty ())
    8056             :             {
    8057          16 :               koenig_p = true;
    8058          16 :               if (!any_type_dependent_arguments_p (args))
    8059          16 :                 variant = perform_koenig_lookup (variant, args,
    8060             :                                                  tf_warning_or_error);
    8061             :             }
    8062             :           else
    8063           0 :             variant = unqualified_fn_lookup_error (variant);
    8064             :         }
    8065        1049 :       else if (!args->is_empty () && is_overloaded_fn (variant))
    8066             :         {
    8067         389 :           tree fn = get_first_fn (variant);
    8068         389 :           fn = STRIP_TEMPLATE (fn);
    8069         389 :           if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
    8070         389 :                  || DECL_FUNCTION_MEMBER_P (fn)
    8071         273 :                  || DECL_LOCAL_DECL_P (fn)))
    8072             :             {
    8073         273 :               koenig_p = true;
    8074         273 :               if (!any_type_dependent_arguments_p (args))
    8075         273 :                 variant = perform_koenig_lookup (variant, args,
    8076             :                                                  tf_warning_or_error);
    8077             :             }
    8078             :         }
    8079             :     }
    8080             : 
    8081        1073 :   if (idk == CP_ID_KIND_QUALIFIED)
    8082           8 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
    8083             :                                 koenig_p, tf_warning_or_error);
    8084             :   else
    8085        1065 :     variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
    8086             :                                 koenig_p, tf_warning_or_error);
    8087        1073 :   if (variant == error_mark_node && !processing_template_decl)
    8088             :     return true;
    8089             : 
    8090        1041 :   variant = cp_get_callee_fndecl_nofold (variant);
    8091        1041 :   input_location = save_loc;
    8092             : 
    8093        1041 :   if (variant)
    8094             :     {
    8095        1009 :       const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
    8096        1009 :       if (!comptypes (TREE_TYPE (decl), TREE_TYPE (variant), 0))
    8097             :         {
    8098          72 :           error_at (varid_loc, "variant %qD and base %qD have incompatible "
    8099             :                                "types", variant, decl);
    8100          72 :           return true;
    8101             :         }
    8102         937 :       if (fndecl_built_in_p (variant)
    8103         937 :           && (startswith (varname, "__builtin_")
    8104           0 :               || startswith (varname, "__sync_")
    8105           0 :               || startswith (varname, "__atomic_")))
    8106             :         {
    8107           8 :           error_at (varid_loc, "variant %qD is a built-in", variant);
    8108           8 :           return true;
    8109             :         }
    8110             :       else
    8111             :         {
    8112         929 :           tree construct = omp_get_context_selector (ctx, "construct", NULL);
    8113         929 :           omp_mark_declare_variant (match_loc, variant, construct);
    8114         929 :           if (!omp_context_selector_matches (ctx))
    8115             :             return true;
    8116         566 :           TREE_PURPOSE (TREE_VALUE (attr)) = variant;
    8117             :         }
    8118             :     }
    8119          32 :   else if (!processing_template_decl)
    8120             :     {
    8121           0 :       error_at (varid_loc, "could not find variant declaration");
    8122           0 :       return true;
    8123             :     }
    8124             : 
    8125             :   return false;
    8126        1141 : }
    8127             : 
    8128             : /* Helper function, finish up "omp declare variant base" attribute
    8129             :    now that there is a DECL.  ATTR is the first "omp declare variant base"
    8130             :    attribute.  */
    8131             : 
    8132             : void
    8133        1036 : omp_declare_variant_finalize (tree decl, tree attr)
    8134             : {
    8135        1036 :   size_t attr_len = strlen ("omp declare variant base");
    8136        1036 :   tree *list = &DECL_ATTRIBUTES (decl);
    8137        1036 :   bool remove_all = false;
    8138        1036 :   location_t match_loc = DECL_SOURCE_LOCATION (decl);
    8139        1036 :   if (TREE_CHAIN (TREE_VALUE (attr))
    8140        1036 :       && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
    8141        2072 :       && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
    8142        1036 :     match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
    8143        2072 :   if (DECL_CONSTRUCTOR_P (decl))
    8144             :     {
    8145          36 :       error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
    8146          36 :       remove_all = true;
    8147             :     }
    8148        1000 :   else if (DECL_DESTRUCTOR_P (decl))
    8149             :     {
    8150          12 :       error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
    8151          12 :       remove_all = true;
    8152             :     }
    8153         988 :   else if (DECL_DEFAULTED_FN (decl))
    8154             :     {
    8155           3 :       error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
    8156           3 :       remove_all = true;
    8157             :     }
    8158         985 :   else if (DECL_DELETED_FN (decl))
    8159             :     {
    8160           3 :       error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
    8161           3 :       remove_all = true;
    8162             :     }
    8163         982 :   else if (DECL_VIRTUAL_P (decl))
    8164             :     {
    8165           0 :       error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
    8166           0 :       remove_all = true;
    8167             :     }
    8168             :   /* This loop is like private_lookup_attribute, except that it works
    8169             :      with tree * rather than tree, as we might want to remove the
    8170             :      attributes that are diagnosed as errorneous.  */
    8171        2237 :   while (*list)
    8172             :     {
    8173        1201 :       tree attr = get_attribute_name (*list);
    8174        1201 :       size_t ident_len = IDENTIFIER_LENGTH (attr);
    8175        3000 :       if (cmp_attribs ("omp declare variant base", attr_len,
    8176        1201 :                        IDENTIFIER_POINTER (attr), ident_len))
    8177             :         {
    8178        1195 :           if (remove_all || omp_declare_variant_finalize_one (decl, *list))
    8179             :             {
    8180         597 :               *list = TREE_CHAIN (*list);
    8181         597 :               continue;
    8182             :             }
    8183             :         }
    8184         604 :       list = &TREE_CHAIN (*list);
    8185             :     }
    8186        1036 : }
    8187             : 
    8188             : /* Finish processing of a declaration;
    8189             :    install its line number and initial value.
    8190             :    If the length of an array type is not known before,
    8191             :    it must be determined now, from the initial value, or it is an error.
    8192             : 
    8193             :    INIT is the initializer (if any) for DECL.  If INIT_CONST_EXPR_P is
    8194             :    true, then INIT is an integral constant expression.
    8195             : 
    8196             :    FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
    8197             :    if the (init) syntax was used.  */
    8198             : 
    8199             : void
    8200   175483284 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
    8201             :                 tree asmspec_tree, int flags)
    8202             : {
    8203   175483284 :   vec<tree, va_gc> *cleanups = NULL;
    8204   175483284 :   const char *asmspec = NULL;
    8205   175483284 :   int was_readonly = 0;
    8206   175483284 :   bool var_definition_p = false;
    8207   175483284 :   tree auto_node;
    8208             : 
    8209   175483284 :   if (decl == error_mark_node)
    8210   108995334 :     return;
    8211   175483259 :   else if (! decl)
    8212             :     {
    8213           0 :       if (init)
    8214           0 :         error ("assignment (not initialization) in declaration");
    8215           0 :       return;
    8216             :     }
    8217             : 
    8218   175483259 :   gcc_assert (TREE_CODE (decl) != RESULT_DECL);
    8219             :   /* Parameters are handled by store_parm_decls, not cp_finish_decl.  */
    8220   175483259 :   gcc_assert (TREE_CODE (decl) != PARM_DECL);
    8221             : 
    8222   175483259 :   tree type = TREE_TYPE (decl);
    8223   175483259 :   if (type == error_mark_node)
    8224             :     return;
    8225             : 
    8226   175482814 :   if (VAR_P (decl) && is_copy_initialization (init))
    8227    45668277 :     flags |= LOOKUP_ONLYCONVERTING;
    8228             : 
    8229             :   /* Warn about register storage specifiers except when in GNU global
    8230             :      or local register variable extension.  */
    8231   175482814 :   if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
    8232             :     {
    8233        2568 :       if (cxx_dialect >= cxx17)
    8234        1276 :         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8235             :                  "ISO C++17 does not allow %<register%> storage "
    8236             :                  "class specifier");
    8237             :       else
    8238        1292 :         warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
    8239             :                     "%<register%> storage class specifier used");
    8240             :     }
    8241             : 
    8242             :   /* If a name was specified, get the string.  */
    8243   175482814 :   if (at_namespace_scope_p ())
    8244    36365190 :     asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
    8245   175482814 :   if (asmspec_tree && asmspec_tree != error_mark_node)
    8246      474792 :     asmspec = TREE_STRING_POINTER (asmspec_tree);
    8247             : 
    8248   175482814 :   bool in_class_decl
    8249   175482814 :     = (current_class_type
    8250   106425075 :        && CP_DECL_CONTEXT (decl) == current_class_type
    8251    73528039 :        && TYPE_BEING_DEFINED (current_class_type)
    8252   248042220 :        && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
    8253             : 
    8254    70632269 :   if (in_class_decl
    8255    70632269 :       && (DECL_INITIAL (decl) || init))
    8256    49937053 :     DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
    8257             : 
    8258   175482814 :   if (VAR_P (decl)
    8259   175482814 :       && (auto_node = type_uses_auto (type)))
    8260             :     {
    8261     3796005 :       tree d_init;
    8262     3796005 :       if (init == NULL_TREE)
    8263             :         {
    8264         117 :           if (DECL_LANG_SPECIFIC (decl)
    8265          65 :               && DECL_TEMPLATE_INSTANTIATION (decl)
    8266         180 :               && !DECL_TEMPLATE_INSTANTIATED (decl))
    8267             :             {
    8268             :               /* init is null because we're deferring instantiating the
    8269             :                  initializer until we need it.  Well, we need it now.  */
    8270          58 :               instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
    8271          58 :               return;
    8272             :             }
    8273             : 
    8274          59 :           if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8275             :             /* Class deduction with no initializer is OK.  */;
    8276             :           else
    8277             :             {
    8278             :               /* Ordinary auto deduction without an initializer, a situation
    8279             :                  which grokdeclarator already detects and rejects for the most
    8280             :                  part.  But we can still get here if we're instantiating a
    8281             :                  variable template before we've fully parsed (and attached) its
    8282             :                  initializer, e.g. template<class> auto x = x<int>;  */
    8283           3 :               error_at (DECL_SOURCE_LOCATION (decl),
    8284             :                         "declaration of %q#D has no initializer", decl);
    8285           3 :               TREE_TYPE (decl) = error_mark_node;
    8286           3 :               return;
    8287             :             }
    8288             :         }
    8289     3795944 :       d_init = init;
    8290     3795944 :       if (d_init)
    8291             :         {
    8292     3795888 :           if (TREE_CODE (d_init) == TREE_LIST
    8293     3803638 :               && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
    8294        7203 :             d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
    8295             :                                                       tf_warning_or_error);
    8296     3795888 :           d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
    8297             :           /* Force auto deduction now.  Use tf_none to avoid redundant warnings
    8298             :              on deprecated-14.C.  */
    8299     3795888 :           mark_single_function (d_init, tf_none);
    8300             :         }
    8301     3795944 :       enum auto_deduction_context adc = adc_variable_type;
    8302     3795944 :       if (DECL_DECOMPOSITION_P (decl))
    8303             :         adc = adc_decomp_type;
    8304     3795944 :       tree outer_targs = NULL_TREE;
    8305     3795944 :       if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
    8306         134 :           && DECL_LANG_SPECIFIC (decl)
    8307          42 :           && DECL_TEMPLATE_INFO (decl)
    8308     3795963 :           && !DECL_FUNCTION_SCOPE_P (decl))
    8309             :         /* The outer template arguments might be needed for satisfaction.
    8310             :            (For function scope variables, do_auto_deduction will obtain the
    8311             :            outer template arguments from current_function_decl.)  */
    8312          19 :         outer_targs = DECL_TI_ARGS (decl);
    8313     3795944 :       type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
    8314             :                                                    tf_warning_or_error, adc,
    8315             :                                                    outer_targs, flags);
    8316     3795944 :       if (type == error_mark_node)
    8317             :         return;
    8318     3795410 :       if (TREE_CODE (type) == FUNCTION_TYPE)
    8319             :         {
    8320           3 :           error ("initializer for %<decltype(auto) %D%> has function type; "
    8321             :                  "did you forget the %<()%>?", decl);
    8322           3 :           TREE_TYPE (decl) = error_mark_node;
    8323           3 :           return;
    8324             :         }
    8325             :       /* As in start_decl_1, complete so TREE_READONLY is set properly.  */
    8326     3795407 :       if (!processing_template_decl
    8327      665897 :           && !type_uses_auto (type)
    8328     4461297 :           && !COMPLETE_TYPE_P (complete_type (type)))
    8329             :         {
    8330          12 :           error_at (location_of (decl),
    8331             :                     "deduced type %qT for %qD is incomplete", type, decl);
    8332          12 :           cxx_incomplete_type_inform (type);
    8333          12 :           TREE_TYPE (decl) = error_mark_node;
    8334          12 :           return;
    8335             :         }
    8336     3795395 :       cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
    8337             : 
    8338             :       /* Update the type of the corresponding TEMPLATE_DECL to match.  */
    8339     3795395 :       if (DECL_LANG_SPECIFIC (decl)
    8340       27659 :           && DECL_TEMPLATE_INFO (decl)
    8341     3795799 :           && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl)
    8342         287 :         TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type;
    8343             :     }
    8344             : 
    8345   175482204 :   if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
    8346             :     {
    8347          48 :       DECL_DECLARED_CONSTEXPR_P (decl) = 0;
    8348          48 :       if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
    8349             :         {
    8350           6 :           init = NULL_TREE;
    8351           6 :           DECL_EXTERNAL (decl) = 1;
    8352             :         }
    8353             :     }
    8354             : 
    8355   175482204 :   if (VAR_P (decl)
    8356    58938313 :       && DECL_CLASS_SCOPE_P (decl)
    8357     8950510 :       && verify_type_context (DECL_SOURCE_LOCATION (decl),
    8358             :                               TCTX_STATIC_STORAGE, type)
    8359   184432714 :       && DECL_INITIALIZED_IN_CLASS_P (decl))
    8360     8173826 :     check_static_variable_definition (decl, type);
    8361             : 
    8362   175482204 :   if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
    8363             :     {
    8364    11040710 :       type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
    8365    11040710 :                                    ? TCTX_THREAD_STORAGE
    8366    11040710 :                                    : TCTX_STATIC_STORAGE);
    8367    11040710 :       verify_type_context (input_location, context, TREE_TYPE (decl));
    8368             :     }
    8369             : 
    8370   175482204 :   if (init && TREE_CODE (decl) == FUNCTION_DECL)
    8371             :     {
    8372      274485 :       tree clone;
    8373      274485 :       if (init == ridpointers[(int)RID_DELETE])
    8374             :         {
    8375             :           /* FIXME check this is 1st decl.  */
    8376      257889 :           DECL_DELETED_FN (decl) = 1;
    8377      257889 :           DECL_DECLARED_INLINE_P (decl) = 1;
    8378      257889 :           DECL_INITIAL (decl) = error_mark_node;
    8379      257907 :           FOR_EACH_CLONE (clone, decl)
    8380             :             {
    8381          18 :               DECL_DELETED_FN (clone) = 1;
    8382          18 :               DECL_DECLARED_INLINE_P (clone) = 1;
    8383          18 :               DECL_INITIAL (clone) = error_mark_node;
    8384             :             }
    8385      257889 :           init = NULL_TREE;
    8386             :         }
    8387       16596 :       else if (init == ridpointers[(int)RID_DEFAULT])
    8388             :         {
    8389       16580 :           if (defaultable_fn_check (decl))
    8390       16571 :             DECL_DEFAULTED_FN (decl) = 1;
    8391             :           else
    8392           9 :             DECL_INITIAL (decl) = NULL_TREE;
    8393             :         }
    8394             :     }
    8395             : 
    8396   175482204 :   if (init && VAR_P (decl))
    8397             :     {
    8398    49483952 :       DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
    8399             :       /* If DECL is a reference, then we want to know whether init is a
    8400             :          reference constant; init_const_expr_p as passed tells us whether
    8401             :          it's an rvalue constant.  */
    8402    49483952 :       if (TYPE_REF_P (type))
    8403     1344002 :         init_const_expr_p = potential_constant_expression (init);
    8404    49483952 :       if (init_const_expr_p)
    8405             :         {
    8406             :           /* Set these flags now for templates.  We'll update the flags in
    8407             :              store_init_value for instantiations.  */
    8408    40618729 :           DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
    8409    40618729 :           if (decl_maybe_constant_var_p (decl)
    8410             :               /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */
    8411    40618729 :               && !TYPE_REF_P (type))
    8412    12950038 :             TREE_CONSTANT (decl) = true;
    8413             :         }
    8414             :       /* This is handled mostly by gimplify.cc, but we have to deal with
    8415             :          not warning about int x = x; as it is a GCC extension to turn off
    8416             :          this warning but only if warn_init_self is zero.  */
    8417    49483952 :       if (!DECL_EXTERNAL (decl)
    8418    48415119 :           && !TREE_STATIC (decl)
    8419    39273378 :           && decl == tree_strip_any_location_wrapper (init)
    8420    49486452 :           && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
    8421        2468 :         suppress_warning (decl, OPT_Winit_self);
    8422             :     }
    8423   125998252 :   else if (VAR_P (decl)
    8424     9454361 :            && COMPLETE_TYPE_P (type)
    8425     7422427 :            && !TYPE_REF_P (type)
    8426     7422069 :            && !dependent_type_p (type)
    8427   133241408 :            && is_really_empty_class (type, /*ignore_vptr*/false))
    8428             :     /* We have no initializer but there's nothing to initialize anyway.
    8429             :        Treat DECL as constant due to c++/109876.  */
    8430      308297 :     TREE_CONSTANT (decl) = true;
    8431             : 
    8432   175482204 :   if (flag_openmp
    8433      214782 :       && TREE_CODE (decl) == FUNCTION_DECL
    8434             :       /* #pragma omp declare variant on methods handled in finish_struct
    8435             :          instead.  */
    8436   175577270 :       && (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
    8437       25157 :           || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
    8438       70117 :     if (tree attr = lookup_attribute ("omp declare variant base",
    8439       70117 :                                       DECL_ATTRIBUTES (decl)))
    8440         747 :       omp_declare_variant_finalize (decl, attr);
    8441             : 
    8442   175482204 :   if (processing_template_decl)
    8443             :     {
    8444   102941707 :       bool type_dependent_p;
    8445             : 
    8446             :       /* Add this declaration to the statement-tree.  */
    8447   102941707 :       if (at_function_scope_p ())
    8448    38058505 :         add_decl_expr (decl);
    8449             : 
    8450   102941707 :       type_dependent_p = dependent_type_p (type);
    8451             : 
    8452   102941707 :       if (check_for_bare_parameter_packs (init))
    8453             :         {
    8454           3 :           init = NULL_TREE;
    8455           3 :           DECL_INITIAL (decl) = NULL_TREE;
    8456             :         }
    8457             : 
    8458             :       /* Generally, initializers in templates are expanded when the
    8459             :          template is instantiated.  But, if DECL is a variable constant
    8460             :          then it can be used in future constant expressions, so its value
    8461             :          must be available. */
    8462             : 
    8463   102941707 :       bool dep_init = false;
    8464             : 
    8465   102941707 :       if (!VAR_P (decl) || type_dependent_p)
    8466             :         /* We can't do anything if the decl has dependent type.  */;
    8467    13056960 :       else if (!init && is_concept_var (decl))
    8468             :         {
    8469           2 :           error ("variable concept has no initializer");
    8470           2 :           init = boolean_true_node;
    8471             :         }
    8472    13056958 :       else if (init
    8473    11939819 :                && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
    8474     9020838 :                && !TYPE_REF_P (type)
    8475     9005328 :                && decl_maybe_constant_var_p (decl)
    8476    17831401 :                && !(dep_init = value_dependent_init_p (init)))
    8477             :         {
    8478             :           /* This variable seems to be a non-dependent constant, so process
    8479             :              its initializer.  If check_initializer returns non-null the
    8480             :              initialization wasn't constant after all.  */
    8481     1145342 :           tree init_code;
    8482     1145342 :           cleanups = make_tree_vector ();
    8483     1145342 :           init_code = check_initializer (decl, init, flags, &cleanups);
    8484     1145342 :           if (init_code == NULL_TREE)
    8485     1145342 :             init = NULL_TREE;
    8486     1145342 :           release_tree_vector (cleanups);
    8487             :         }
    8488             :       else
    8489             :         {
    8490    11911616 :           gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
    8491             :           /* Try to deduce array size.  */
    8492    11911616 :           maybe_deduce_size_from_array_init (decl, init);
    8493             :           /* And complain about multiple initializers.  */
    8494    10794477 :           if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
    8495    11974957 :               && !MAYBE_CLASS_TYPE_P (type))
    8496          11 :             init = build_x_compound_expr_from_list (init, ELK_INIT,
    8497             :                                                     tf_warning_or_error);
    8498             :         }
    8499             : 
    8500   102941707 :       if (init)
    8501    29732821 :         DECL_INITIAL (decl) = init;
    8502             : 
    8503   102941707 :       if (dep_init)
    8504             :         {
    8505     3629101 :           retrofit_lang_decl (decl);
    8506     3629101 :           SET_DECL_DEPENDENT_INIT_P (decl, true);
    8507             :         }
    8508             : 
    8509   102941707 :       if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
    8510             :         {
    8511           4 :           set_user_assembler_name (decl, asmspec);
    8512           4 :           DECL_HARD_REGISTER (decl) = 1;
    8513             :         }
    8514   102941707 :       return;
    8515             :     }
    8516             : 
    8517             :   /* Just store non-static data member initializers for later.  */
    8518    72540497 :   if (init && TREE_CODE (decl) == FIELD_DECL)
    8519      222347 :     DECL_INITIAL (decl) = init;
    8520             : 
    8521             :   /* Take care of TYPE_DECLs up front.  */
    8522    72540497 :   if (TREE_CODE (decl) == TYPE_DECL)
    8523             :     {
    8524     6052543 :       if (type != error_mark_node
    8525     6052543 :           && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
    8526             :         {
    8527     2673870 :           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
    8528           0 :             warning (0, "shadowing previous type declaration of %q#D", decl);
    8529     2673870 :           set_identifier_type_value (DECL_NAME (decl), decl);
    8530             :         }
    8531             : 
    8532             :       /* If we have installed this as the canonical typedef for this
    8533             :          type, and that type has not been defined yet, delay emitting
    8534             :          the debug information for it, as we will emit it later.  */
    8535     6052543 :       if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
    8536     6052543 :           && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    8537      321692 :         TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
    8538             : 
    8539     6052543 :       rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
    8540             :                                 at_eof);
    8541     6052543 :       return;
    8542             :     }
    8543             : 
    8544             :   /* A reference will be modified here, as it is initialized.  */
    8545    66487954 :   if (! DECL_EXTERNAL (decl)
    8546    26820166 :       && TREE_READONLY (decl)
    8547    78413524 :       && TYPE_REF_P (type))
    8548             :     {
    8549      130789 :       was_readonly = 1;
    8550      130789 :       TREE_READONLY (decl) = 0;
    8551             :     }
    8552             : 
    8553             :   /* This needs to happen before extend_ref_init_temps.  */
    8554    66487954 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    8555             :     {
    8556    60534649 :       if (VAR_P (decl))
    8557    25099616 :         maybe_commonize_var (decl);
    8558    60534649 :       determine_visibility (decl);
    8559             :     }
    8560             : 
    8561    66487954 :   if (VAR_P (decl))
    8562             :     {
    8563    25099616 :       duration_kind dk = decl_storage_duration (decl);
    8564             :       /* [dcl.constinit]/1 "The constinit specifier shall be applied
    8565             :          only to a declaration of a variable with static or thread storage
    8566             :          duration."  */
    8567    25099616 :       if (DECL_DECLARED_CONSTINIT_P (decl)
    8568    25099616 :           && !(dk == dk_thread || dk == dk_static))
    8569             :         {
    8570           4 :           error_at (DECL_SOURCE_LOCATION (decl),
    8571             :                     "%<constinit%> can only be applied to a variable with "
    8572             :                     "static or thread storage duration");
    8573           4 :           return;
    8574             :         }
    8575             : 
    8576             :       /* If this is a local variable that will need a mangled name,
    8577             :          register it now.  We must do this before processing the
    8578             :          initializer for the variable, since the initialization might
    8579             :          require a guard variable, and since the mangled name of the
    8580             :          guard variable will depend on the mangled name of this
    8581             :          variable.  */
    8582    50199224 :       if (DECL_FUNCTION_SCOPE_P (decl)
    8583    14144160 :           && TREE_STATIC (decl)
    8584    25184870 :           && !DECL_ARTIFICIAL (decl))
    8585             :         {
    8586             :           /* The variable holding an anonymous union will have had its
    8587             :              discriminator set in finish_anon_union, after which it's
    8588             :              NAME will have been cleared.  */
    8589       85144 :           if (DECL_NAME (decl))
    8590       85092 :             determine_local_discriminator (decl);
    8591             :           /* Normally has_forced_label_in_static is set during GIMPLE
    8592             :              lowering, but [cd]tors are never actually compiled directly.
    8593             :              We need to set this early so we can deal with the label
    8594             :              address extension.  */
    8595       85144 :           if ((DECL_CONSTRUCTOR_P (current_function_decl)
    8596       85108 :                || DECL_DESTRUCTOR_P (current_function_decl))
    8597       85155 :               && init)
    8598             :             {
    8599          36 :               walk_tree (&init, notice_forced_label_r, NULL, NULL);
    8600          36 :               add_local_decl (cfun, decl);
    8601             :             }
    8602             :           /* And make sure it's in the symbol table for
    8603             :              c_parse_final_cleanups to find.  */
    8604       85144 :           varpool_node::get_create (decl);
    8605             :         }
    8606             : 
    8607             :       /* Convert the initializer to the type of DECL, if we have not
    8608             :          already initialized DECL.  */
    8609    25099612 :       if (!DECL_INITIALIZED_P (decl)
    8610             :           /* If !DECL_EXTERNAL then DECL is being defined.  In the
    8611             :              case of a static data member initialized inside the
    8612             :              class-specifier, there can be an initializer even if DECL
    8613             :              is *not* defined.  */
    8614    25099612 :           && (!DECL_EXTERNAL (decl) || init))
    8615             :         {
    8616    21538270 :           cleanups = make_tree_vector ();
    8617    21538270 :           init = check_initializer (decl, init, flags, &cleanups);
    8618             : 
    8619             :           /* Handle:
    8620             : 
    8621             :              [dcl.init]
    8622             : 
    8623             :              The memory occupied by any object of static storage
    8624             :              duration is zero-initialized at program startup before
    8625             :              any other initialization takes place.
    8626             : 
    8627             :              We cannot create an appropriate initializer until after
    8628             :              the type of DECL is finalized.  If DECL_INITIAL is set,
    8629             :              then the DECL is statically initialized, and any
    8630             :              necessary zero-initialization has already been performed.  */
    8631    21527486 :           if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
    8632      267502 :             DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
    8633             :                                                    /*nelts=*/NULL_TREE,
    8634             :                                                    /*static_storage_p=*/true);
    8635             :           /* Remember that the initialization for this variable has
    8636             :              taken place.  */
    8637    21527486 :           DECL_INITIALIZED_P (decl) = 1;
    8638             :           /* This declaration is the definition of this variable,
    8639             :              unless we are initializing a static data member within
    8640             :              the class specifier.  */
    8641    21527486 :           if (!DECL_EXTERNAL (decl))
    8642    25088828 :             var_definition_p = true;
    8643             :         }
    8644             :       /* If the variable has an array type, lay out the type, even if
    8645             :          there is no initializer.  It is valid to index through the
    8646             :          array, and we must get TYPE_ALIGN set correctly on the array
    8647             :          type.  */
    8648     3561342 :       else if (TREE_CODE (type) == ARRAY_TYPE)
    8649      161734 :         layout_type (type);
    8650             : 
    8651    25088828 :       if (TREE_STATIC (decl)
    8652    10565267 :           && !at_function_scope_p ()
    8653    35568837 :           && current_function_decl == NULL)
    8654             :         /* So decl is a global variable or a static member of a
    8655             :            non local class. Record the types it uses
    8656             :            so that we can decide later to emit debug info for them.  */
    8657    10479993 :         record_types_used_by_current_var_decl (decl);
    8658             :     }
    8659             : 
    8660             :   /* Add this declaration to the statement-tree.  This needs to happen
    8661             :      after the call to check_initializer so that the DECL_EXPR for a
    8662             :      reference temp is added before the DECL_EXPR for the reference itself.  */
    8663    66477166 :   if (DECL_FUNCTION_SCOPE_P (decl))
    8664             :     {
    8665             :       /* If we're building a variable sized type, and we might be
    8666             :          reachable other than via the top of the current binding
    8667             :          level, then create a new BIND_EXPR so that we deallocate
    8668             :          the object at the right time.  */
    8669    14144160 :       if (VAR_P (decl)
    8670    14144160 :           && DECL_SIZE (decl)
    8671    13487819 :           && !TREE_CONSTANT (DECL_SIZE (decl))
    8672    14145115 :           && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
    8673             :         {
    8674           4 :           tree bind;
    8675           4 :           bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
    8676           4 :           TREE_SIDE_EFFECTS (bind) = 1;
    8677           4 :           add_stmt (bind);
    8678           4 :           BIND_EXPR_BODY (bind) = push_stmt_list ();
    8679             :         }
    8680    14144160 :       add_decl_expr (decl);
    8681             :     }
    8682             : 
    8683             :   /* Let the middle end know about variables and functions -- but not
    8684             :      static data members in uninstantiated class templates.  */
    8685    66477166 :   if (VAR_OR_FUNCTION_DECL_P (decl))
    8686             :     {
    8687    60523861 :       if (VAR_P (decl))
    8688             :         {
    8689    25088828 :           layout_var_decl (decl);
    8690    25088828 :           if (!flag_weak)
    8691             :             /* Check again now that we have an initializer.  */
    8692          58 :             maybe_commonize_var (decl);
    8693             :           /* A class-scope constexpr variable with an out-of-class declaration.
    8694             :              C++17 makes them implicitly inline, but still force it out.  */
    8695    34631763 :           if (DECL_INLINE_VAR_P (decl)
    8696     6377487 :               && !DECL_VAR_DECLARED_INLINE_P (decl)
    8697     4992645 :               && !DECL_TEMPLATE_INSTANTIATION (decl)
    8698    14909449 :               && !in_class_decl)
    8699          54 :             mark_needed (decl);
    8700             :         }
    8701             : 
    8702    60523861 :       if (var_definition_p
    8703             :           /* With -fmerge-all-constants, gimplify_init_constructor
    8704             :              might add TREE_STATIC to aggregate variables.  */
    8705    20801811 :           && (TREE_STATIC (decl)
    8706    14058902 :               || (flag_merge_constants >= 2
    8707          39 :                   && AGGREGATE_TYPE_P (type))))
    8708             :         {
    8709             :           /* If a TREE_READONLY variable needs initialization
    8710             :              at runtime, it is no longer readonly and we need to
    8711             :              avoid MEM_READONLY_P being set on RTL created for it.  */
    8712     6742913 :           if (init)
    8713             :             {
    8714       11807 :               if (TREE_READONLY (decl))
    8715         497 :                 TREE_READONLY (decl) = 0;
    8716             :               was_readonly = 0;
    8717             :             }
    8718     6731106 :           else if (was_readonly)
    8719        1255 :             TREE_READONLY (decl) = 1;
    8720             : 
    8721             :           /* Likewise if it needs destruction.  */
    8722     6742913 :           if (!decl_maybe_constant_destruction (decl, type))
    8723        2760 :             TREE_READONLY (decl) = 0;
    8724             :         }
    8725    53780948 :       else if (VAR_P (decl)
    8726    18345915 :                && CP_DECL_THREAD_LOCAL_P (decl)
    8727       14169 :                && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
    8728       14169 :                && (was_readonly || TREE_READONLY (decl))
    8729    53780960 :                && var_needs_tls_wrapper (decl))
    8730             :         {
    8731             :           /* TLS variables need dynamic initialization by the TLS wrapper
    8732             :              function, we don't want to hoist accesses to it before the
    8733             :              wrapper.  */
    8734           6 :           was_readonly = 0;
    8735           6 :           TREE_READONLY (decl) = 0;
    8736             :         }
    8737             : 
    8738    60523861 :       make_rtl_for_nonlocal_decl (decl, init, asmspec);
    8739             : 
    8740             :       /* Check for abstractness of the type.  */
    8741    60523861 :       if (var_definition_p)
    8742    20801811 :         abstract_virtuals_error (decl, type);
    8743             : 
    8744    60523861 :       if (TREE_TYPE (decl) == error_mark_node)
    8745             :         /* No initialization required.  */
    8746             :         ;
    8747    60523778 :       else if (TREE_CODE (decl) == FUNCTION_DECL)
    8748             :         {
    8749    35435033 :           if (init)
    8750             :             {
    8751         548 :               if (init == ridpointers[(int)RID_DEFAULT])
    8752             :                 {
    8753             :                   /* An out-of-class default definition is defined at
    8754             :                      the point where it is explicitly defaulted.  */
    8755         532 :                   if (DECL_DELETED_FN (decl))
    8756           6 :                     maybe_explain_implicit_delete (decl);
    8757         526 :                   else if (DECL_INITIAL (decl) == error_mark_node)
    8758         517 :                     synthesize_method (decl);
    8759             :                 }
    8760             :               else
    8761          32 :                 error_at (cp_expr_loc_or_loc (init,
    8762          16 :                                               DECL_SOURCE_LOCATION (decl)),
    8763             :                           "function %q#D is initialized like a variable",
    8764             :                           decl);
    8765             :             }
    8766             :           /* else no initialization required.  */
    8767             :         }
    8768    25088745 :       else if (DECL_EXTERNAL (decl)
    8769    25088745 :                && ! (DECL_LANG_SPECIFIC (decl)
    8770     4011291 :                      && DECL_NOT_REALLY_EXTERN (decl)))
    8771             :         {
    8772             :           /* check_initializer will have done any constant initialization.  */
    8773             :         }
    8774             :       /* A variable definition.  */
    8775    22056365 :       else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
    8776             :         /* Initialize the local variable.  */
    8777    14058882 :         initialize_local_var (decl, init);
    8778             : 
    8779             :       /* If a variable is defined, and then a subsequent
    8780             :          definition with external linkage is encountered, we will
    8781             :          get here twice for the same variable.  We want to avoid
    8782             :          calling expand_static_init more than once.  For variables
    8783             :          that are not static data members, we can call
    8784             :          expand_static_init only when we actually process the
    8785             :          initializer.  It is not legal to redeclare a static data
    8786             :          member, so this issue does not arise in that case.  */
    8787     7997483 :       else if (var_definition_p && TREE_STATIC (decl))
    8788     6742859 :         expand_static_init (decl, init);
    8789             :     }
    8790             : 
    8791             :   /* If a CLEANUP_STMT was created to destroy a temporary bound to a
    8792             :      reference, insert it in the statement-tree now.  */
    8793    66477166 :   if (cleanups)
    8794             :     {
    8795    21528060 :       for (tree t : *cleanups)
    8796             :         {
    8797         574 :           push_cleanup (NULL_TREE, t, false);
    8798             :           /* As in initialize_local_var.  */
    8799         574 :           wrap_temporary_cleanups (init, t);
    8800             :         }
    8801    21527486 :       release_tree_vector (cleanups);
    8802             :     }
    8803             : 
    8804    66477166 :   if (was_readonly)
    8805      130335 :     TREE_READONLY (decl) = 1;
    8806             : 
    8807    66477166 :   if (flag_openmp
    8808      131435 :       && VAR_P (decl)
    8809    66520486 :       && lookup_attribute ("omp declare target implicit",
    8810       43320 :                            DECL_ATTRIBUTES (decl)))
    8811             :     {
    8812          65 :       DECL_ATTRIBUTES (decl)
    8813          65 :         = remove_attribute ("omp declare target implicit",
    8814          65 :                             DECL_ATTRIBUTES (decl));
    8815          65 :       complete_type (TREE_TYPE (decl));
    8816          65 :       if (!omp_mappable_type (TREE_TYPE (decl)))
    8817             :         {
    8818          40 :           error ("%q+D in declare target directive does not have mappable"
    8819             :                  " type", decl);
    8820          40 :           if (TREE_TYPE (decl) != error_mark_node
    8821          40 :               && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
    8822          40 :             cxx_incomplete_type_inform (TREE_TYPE (decl));
    8823             :         }
    8824          25 :       else if (!lookup_attribute ("omp declare target",
    8825          25 :                                   DECL_ATTRIBUTES (decl))
    8826          50 :                && !lookup_attribute ("omp declare target link",
    8827          25 :                                      DECL_ATTRIBUTES (decl)))
    8828             :         {
    8829          25 :           DECL_ATTRIBUTES (decl)
    8830          25 :             = tree_cons (get_identifier ("omp declare target"),
    8831          25 :                          NULL_TREE, DECL_ATTRIBUTES (decl));
    8832          25 :           symtab_node *node = symtab_node::get (decl);
    8833          25 :           if (node != NULL)
    8834             :             {
    8835          21 :               node->offloadable = 1;
    8836          21 :               if (ENABLE_OFFLOADING)
    8837             :                 {
    8838             :                   g->have_offload = true;
    8839             :                   if (is_a <varpool_node *> (node))
    8840             :                     vec_safe_push (offload_vars, decl);
    8841             :                 }
    8842             :             }
    8843             :         }
    8844             :     }
    8845             : 
    8846             :   /* This is the last point we can lower alignment so give the target the
    8847             :      chance to do so.  */
    8848    66477166 :   if (VAR_P (decl)
    8849    25088828 :       && !is_global_var (decl)
    8850    80536068 :       && !DECL_HARD_REGISTER (decl))
    8851    14058846 :     targetm.lower_local_decl_alignment (decl);
    8852             : 
    8853    66477166 :   invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
    8854             : }
    8855             : 
    8856             : /* For class TYPE return itself or some its bases that contain
    8857             :    any direct non-static data members.  Return error_mark_node if an
    8858             :    error has been diagnosed.  */
    8859             : 
    8860             : static tree
    8861        1311 : find_decomp_class_base (location_t loc, tree type, tree ret)
    8862             : {
    8863        1311 :   bool member_seen = false;
    8864       17295 :   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
    8865       29237 :     if (TREE_CODE (field) != FIELD_DECL
    8866        2876 :         || DECL_ARTIFICIAL (field)
    8867       18802 :         || DECL_UNNAMED_BIT_FIELD (field))
    8868       13232 :       continue;
    8869        2773 :     else if (ret)
    8870             :       return type;
    8871        2756 :     else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
    8872             :       {
    8873           2 :         if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
    8874           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    8875             :                          "anonymous struct member", type);
    8876             :         else
    8877           1 :           error_at (loc, "cannot decompose class type %qT because it has an "
    8878             :                          "anonymous union member", type);
    8879           2 :         inform (DECL_SOURCE_LOCATION (field), "declared here");
    8880           2 :         return error_mark_node;
    8881             :       }
    8882        2754 :     else if (!accessible_p (type, field, true))
    8883             :       {
    8884           2 :         error_at (loc, "cannot decompose inaccessible member %qD of %qT",
    8885             :                   field, type);
    8886           2 :         inform (DECL_SOURCE_LOCATION (field),
    8887           2 :                 TREE_PRIVATE (field)
    8888             :                 ? G_("declared private here")
    8889             :                 : G_("declared protected here"));
    8890           2 :         return error_mark_node;
    8891             :       }
    8892             :     else
    8893             :       member_seen = true;
    8894             : 
    8895        1290 :   tree base_binfo, binfo;
    8896        1290 :   tree orig_ret = ret;
    8897        1290 :   int i;
    8898        1290 :   if (member_seen)
    8899        1245 :     ret = type;
    8900        1344 :   for (binfo = TYPE_BINFO (type), i = 0;
    8901        1344 :        BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
    8902             :     {
    8903          62 :       tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret);
    8904          62 :       if (t == error_mark_node)
    8905           0 :         return error_mark_node;
    8906          62 :       if (t != NULL_TREE && t != ret)
    8907             :         {
    8908          35 :           if (ret == type)
    8909             :             {
    8910           4 :               error_at (loc, "cannot decompose class type %qT: both it and "
    8911             :                              "its base class %qT have non-static data members",
    8912             :                         type, t);
    8913           4 :               return error_mark_node;
    8914             :             }
    8915          31 :           else if (orig_ret != NULL_TREE)
    8916           0 :             return t;
    8917          31 :           else if (ret != NULL_TREE)
    8918             :             {
    8919           4 :               error_at (loc, "cannot decompose class type %qT: its base "
    8920             :                              "classes %qT and %qT have non-static data "
    8921             :                              "members", type, ret, t);
    8922           4 :               return error_mark_node;
    8923             :             }
    8924             :           else
    8925             :             ret = t;
    8926             :         }
    8927             :     }
    8928             :   return ret;
    8929             : }
    8930             : 
    8931             : /* Return std::tuple_size<TYPE>::value.  */
    8932             : 
    8933             : static tree
    8934        2364 : get_tuple_size (tree type)
    8935             : {
    8936        2364 :   tree args = make_tree_vec (1);
    8937        2364 :   TREE_VEC_ELT (args, 0) = type;
    8938        2364 :   tree inst = lookup_template_class (tuple_size_identifier, args,
    8939             :                                      /*in_decl*/NULL_TREE,
    8940             :                                      /*context*/std_node,
    8941             :                                      /*entering_scope*/false, tf_none);
    8942        2364 :   inst = complete_type (inst);
    8943        2364 :   if (inst == error_mark_node || !COMPLETE_TYPE_P (inst))
    8944             :     return NULL_TREE;
    8945        1094 :   tree val = lookup_qualified_name (inst, value_identifier,
    8946             :                                     LOOK_want::NORMAL, /*complain*/false);
    8947        1094 :   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
    8948        1092 :     val = maybe_constant_value (val);
    8949        1094 :   if (TREE_CODE (val) == INTEGER_CST)
    8950             :     return val;
    8951             :   else
    8952           2 :     return error_mark_node;
    8953             : }
    8954             : 
    8955             : /* Return std::tuple_element<I,TYPE>::type.  */
    8956             : 
    8957             : static tree
    8958        2170 : get_tuple_element_type (tree type, unsigned i)
    8959             : {
    8960        2170 :   tree args = make_tree_vec (2);
    8961        2170 :   TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
    8962        2170 :   TREE_VEC_ELT (args, 1) = type;
    8963        2170 :   tree inst = lookup_template_class (tuple_element_identifier, args,
    8964             :                                      /*in_decl*/NULL_TREE,
    8965             :                                      /*context*/std_node,
    8966             :                                      /*entering_scope*/false,
    8967             :                                      tf_warning_or_error);
    8968        2170 :   return make_typename_type (inst, type_identifier,
    8969        2170 :                              none_type, tf_warning_or_error);
    8970             : }
    8971             : 
    8972             : /* Return e.get<i>() or get<i>(e).  */
    8973             : 
    8974             : static tree
    8975        2176 : get_tuple_decomp_init (tree decl, unsigned i)
    8976             : {
    8977        2176 :   tree targs = make_tree_vec (1);
    8978        2176 :   TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
    8979             : 
    8980        2176 :   tree etype = TREE_TYPE (decl);
    8981        2176 :   tree e = convert_from_reference (decl);
    8982             : 
    8983             :   /* [The id-expression] e is an lvalue if the type of the entity e is an
    8984             :      lvalue reference and an xvalue otherwise.  */
    8985        2176 :   if (!TYPE_REF_P (etype)
    8986        2176 :       || TYPE_REF_IS_RVALUE (etype))
    8987        2084 :     e = move (e);
    8988             : 
    8989        2176 :   tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
    8990             :                                     LOOK_want::NORMAL, /*complain*/false);
    8991        2176 :   bool use_member_get = false;
    8992             : 
    8993             :   /* To use a member get, member lookup must find at least one
    8994             :      declaration that is a function template
    8995             :      whose first template parameter is a non-type parameter.  */
    8996        6266 :   for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
    8997             :     {
    8998        2176 :       tree fn = *iter;
    8999        2176 :       if (TREE_CODE (fn) == TEMPLATE_DECL)
    9000             :         {
    9001         264 :           tree tparms = DECL_TEMPLATE_PARMS (fn);
    9002         264 :           tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
    9003         264 :           if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
    9004             :             {
    9005             :               use_member_get = true;
    9006             :               break;
    9007             :             }
    9008             :         }
    9009             :     }
    9010             : 
    9011        2176 :   if (use_member_get)
    9012             :     {
    9013         262 :       fns = lookup_template_function (fns, targs);
    9014         262 :       return build_new_method_call (e, fns, /*args*/NULL,
    9015             :                                     /*path*/NULL_TREE, LOOKUP_NORMAL,
    9016         262 :                                     /*fn_p*/NULL, tf_warning_or_error);
    9017             :     }
    9018             :   else
    9019             :     {
    9020        1914 :       releasing_vec args (make_tree_vector_single (e));
    9021        1914 :       fns = lookup_template_function (get__identifier, targs);
    9022        1914 :       fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
    9023        1914 :       return finish_call_expr (fns, &args, /*novirt*/false,
    9024             :                                /*koenig*/true, tf_warning_or_error);
    9025        1914 :     }
    9026             : }
    9027             : 
    9028             : /* It's impossible to recover the decltype of a tuple decomposition variable
    9029             :    based on the actual type of the variable, so store it in a hash table.  */
    9030             : 
    9031             : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
    9032             : 
    9033             : tree
    9034          32 : lookup_decomp_type (tree v)
    9035             : {
    9036          32 :   return *decomp_type_table->get (v);
    9037             : }
    9038             : 
    9039             : /* Mangle a decomposition declaration if needed.  Arguments like
    9040             :    in cp_finish_decomp.  */
    9041             : 
    9042             : void
    9043       14518 : cp_maybe_mangle_decomp (tree decl, tree first, unsigned int count)
    9044             : {
    9045       14518 :   if (!processing_template_decl
    9046        2222 :       && !error_operand_p (decl)
    9047       16740 :       && TREE_STATIC (decl))
    9048             :     {
    9049         151 :       auto_vec<tree, 16> v;
    9050         151 :       v.safe_grow (count, true);
    9051         151 :       tree d = first;
    9052         509 :       for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
    9053         358 :         v[count - i - 1] = d;
    9054         151 :       SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
    9055         151 :       maybe_apply_pragma_weak (decl);
    9056         151 :     }
    9057       14518 : }
    9058             : 
    9059             : /* Finish a decomposition declaration.  DECL is the underlying declaration
    9060             :    "e", FIRST is the head of a chain of decls for the individual identifiers
    9061             :    chained through DECL_CHAIN in reverse order and COUNT is the number of
    9062             :    those decls.  */
    9063             : 
    9064             : void
    9065       14730 : cp_finish_decomp (tree decl, tree first, unsigned int count)
    9066             : {
    9067       14730 :   if (error_operand_p (decl))
    9068             :     {
    9069          31 :      error_out:
    9070         273 :       while (count--)
    9071             :         {
    9072         167 :           TREE_TYPE (first) = error_mark_node;
    9073         167 :           if (DECL_HAS_VALUE_EXPR_P (first))
    9074             :             {
    9075           9 :               SET_DECL_VALUE_EXPR (first, NULL_TREE);
    9076           9 :               DECL_HAS_VALUE_EXPR_P (first) = 0;
    9077             :             }
    9078         167 :           first = DECL_CHAIN (first);
    9079             :         }
    9080         106 :       if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
    9081          43 :         SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
    9082       12272 :       return;
    9083             :     }
    9084             : 
    9085       14699 :   location_t loc = DECL_SOURCE_LOCATION (decl);
    9086       14699 :   if (type_dependent_expression_p (decl)
    9087             :       /* This happens for range for when not in templates.
    9088             :          Still add the DECL_VALUE_EXPRs for later processing.  */
    9089       14699 :       || (!processing_template_decl
    9090        2246 :           && type_uses_auto (TREE_TYPE (decl))))
    9091             :     {
    9092       36620 :       for (unsigned int i = 0; i < count; i++)
    9093             :         {
    9094       24454 :           if (!DECL_HAS_VALUE_EXPR_P (first))
    9095             :             {
    9096       24454 :               tree v = build_nt (ARRAY_REF, decl,
    9097       24454 :                                  size_int (count - i - 1),
    9098             :                                  NULL_TREE, NULL_TREE);
    9099       24454 :               SET_DECL_VALUE_EXPR (first, v);
    9100       24454 :               DECL_HAS_VALUE_EXPR_P (first) = 1;
    9101             :             }
    9102       24454 :           if (processing_template_decl)
    9103       24244 :             fit_decomposition_lang_decl (first, decl);
    9104       24454 :           first = DECL_CHAIN (first);
    9105             :         }
    9106             :       return;
    9107             :     }
    9108             : 
    9109        4991 :   auto_vec<tree, 16> v;
    9110        2533 :   v.safe_grow (count, true);
    9111        2533 :   tree d = first;
    9112        7975 :   for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
    9113             :     {
    9114        5442 :       v[count - i - 1] = d;
    9115        5442 :       fit_decomposition_lang_decl (d, decl);
    9116             :     }
    9117             : 
    9118        2533 :   tree type = TREE_TYPE (decl);
    9119        2533 :   tree dexp = decl;
    9120             : 
    9121        2533 :   if (TYPE_REF_P (type))
    9122             :     {
    9123         268 :       dexp = convert_from_reference (dexp);
    9124         268 :       type = complete_type (TREE_TYPE (type));
    9125         268 :       if (type == error_mark_node)
    9126         273 :         goto error_out;
    9127         268 :       if (!COMPLETE_TYPE_P (type))
    9128             :         {
    9129           3 :           error_at (loc, "structured binding refers to incomplete type %qT",
    9130             :                     type);
    9131           3 :           goto error_out;
    9132             :         }
    9133             :     }
    9134             : 
    9135        2530 :   tree eltype = NULL_TREE;
    9136        2530 :   unsigned HOST_WIDE_INT eltscnt = 0;
    9137        2530 :   if (TREE_CODE (type) == ARRAY_TYPE)
    9138             :     {
    9139         148 :       tree nelts;
    9140         148 :       nelts = array_type_nelts_top (type);
    9141         148 :       if (nelts == error_mark_node)
    9142           0 :         goto error_out;
    9143         148 :       if (!tree_fits_uhwi_p (nelts))
    9144             :         {
    9145           0 :           error_at (loc, "cannot decompose variable length array %qT", type);
    9146           0 :           goto error_out;
    9147             :         }
    9148         148 :       eltscnt = tree_to_uhwi (nelts);
    9149         148 :       if (count != eltscnt)
    9150             :         {
    9151           8 :        cnt_mismatch:
    9152          13 :           if (count > eltscnt)
    9153           9 :             error_n (loc, count,
    9154             :                      "%u name provided for structured binding",
    9155             :                      "%u names provided for structured binding", count);
    9156             :           else
    9157           4 :             error_n (loc, count,
    9158             :                      "only %u name provided for structured binding",
    9159             :                      "only %u names provided for structured binding", count);
    9160          13 :           inform_n (loc, eltscnt,
    9161             :                     "while %qT decomposes into %wu element",
    9162             :                     "while %qT decomposes into %wu elements",
    9163             :                     type, eltscnt);
    9164          13 :           goto error_out;
    9165             :         }
    9166         140 :       eltype = TREE_TYPE (type);
    9167         520 :       for (unsigned int i = 0; i < count; i++)
    9168             :         {
    9169         380 :           TREE_TYPE (v[i]) = eltype;
    9170         380 :           layout_decl (v[i], 0);
    9171         380 :           if (processing_template_decl)
    9172          22 :             continue;
    9173         358 :           tree t = unshare_expr (dexp);
    9174         358 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
    9175         358 :           SET_DECL_VALUE_EXPR (v[i], t);
    9176         358 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9177             :         }
    9178             :     }
    9179             :   /* 2 GNU extensions.  */
    9180        2382 :   else if (TREE_CODE (type) == COMPLEX_TYPE)
    9181             :     {
    9182          12 :       eltscnt = 2;
    9183          12 :       if (count != eltscnt)
    9184           0 :         goto cnt_mismatch;
    9185          12 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9186          36 :       for (unsigned int i = 0; i < count; i++)
    9187             :         {
    9188          24 :           TREE_TYPE (v[i]) = eltype;
    9189          24 :           layout_decl (v[i], 0);
    9190          24 :           if (processing_template_decl)
    9191           0 :             continue;
    9192          24 :           tree t = unshare_expr (dexp);
    9193          36 :           t = build1 (i ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
    9194          24 :           SET_DECL_VALUE_EXPR (v[i], t);
    9195          24 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9196             :         }
    9197             :     }
    9198        2370 :   else if (TREE_CODE (type) == VECTOR_TYPE)
    9199             :     {
    9200           6 :       if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
    9201             :         {
    9202             :           error_at (loc, "cannot decompose variable length vector %qT", type);
    9203             :           goto error_out;
    9204             :         }
    9205           6 :       if (count != eltscnt)
    9206           0 :         goto cnt_mismatch;
    9207           6 :       eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
    9208          30 :       for (unsigned int i = 0; i < count; i++)
    9209             :         {
    9210          24 :           TREE_TYPE (v[i]) = eltype;
    9211          24 :           layout_decl (v[i], 0);
    9212          24 :           if (processing_template_decl)
    9213           0 :             continue;
    9214          24 :           tree t = unshare_expr (dexp);
    9215          24 :           convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
    9216             :                                                  &t, size_int (i));
    9217          24 :           t = build4 (ARRAY_REF, eltype, t, size_int (i), NULL_TREE, NULL_TREE);
    9218          24 :           SET_DECL_VALUE_EXPR (v[i], t);
    9219          24 :           DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9220             :         }
    9221             :     }
    9222        2364 :   else if (tree tsize = get_tuple_size (type))
    9223             :     {
    9224        1094 :       if (tsize == error_mark_node)
    9225             :         {
    9226           2 :           error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
    9227             :                          "constant expression", type);
    9228           2 :           goto error_out;
    9229             :         }
    9230        1092 :       if (!tree_fits_uhwi_p (tsize))
    9231             :         {
    9232          12 :           error_n (loc, count,
    9233             :                    "%u name provided for structured binding",
    9234             :                    "%u names provided for structured binding", count);
    9235          12 :           inform (loc, "while %qT decomposes into %E elements",
    9236             :                   type, tsize);
    9237          12 :           goto error_out;
    9238             :         }
    9239        1080 :       eltscnt = tree_to_uhwi (tsize);
    9240        1080 :       if (count != eltscnt)
    9241           2 :         goto cnt_mismatch;
    9242        1078 :       int save_read = DECL_READ_P (decl);       
    9243        3240 :       for (unsigned i = 0; i < count; ++i)
    9244             :         {
    9245        2176 :           location_t sloc = input_location;
    9246        2176 :           location_t dloc = DECL_SOURCE_LOCATION (v[i]);
    9247             : 
    9248        2176 :           input_location = dloc;
    9249        2176 :           tree init = get_tuple_decomp_init (decl, i);
    9250        2176 :           tree eltype = (init == error_mark_node ? error_mark_node
    9251        2170 :                          : get_tuple_element_type (type, i));
    9252        2176 :           input_location = sloc;
    9253             : 
    9254        2176 :           if (VOID_TYPE_P (eltype))
    9255             :             {
    9256           2 :               error ("%<std::tuple_element<%u, %T>::type%> is %<void%>",
    9257             :                      i, type);
    9258           2 :               eltype = error_mark_node;
    9259             :             }
    9260        2176 :           if (init == error_mark_node || eltype == error_mark_node)
    9261             :             {
    9262          14 :               inform (dloc, "in initialization of structured binding "
    9263          14 :                       "variable %qD", v[i]);
    9264          14 :               goto error_out;
    9265             :             }
    9266             :           /* Save the decltype away before reference collapse.  */
    9267        2162 :           hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
    9268        2162 :           eltype = cp_build_reference_type (eltype, !lvalue_p (init));
    9269        2162 :           TREE_TYPE (v[i]) = eltype;
    9270        2162 :           layout_decl (v[i], 0);
    9271        2162 :           if (DECL_HAS_VALUE_EXPR_P (v[i]))
    9272             :             {
    9273             :               /* In this case the names are variables, not just proxies.  */
    9274         173 :               SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
    9275         173 :               DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
    9276             :             }
    9277        2162 :           if (!processing_template_decl)
    9278             :             {
    9279        1854 :               copy_linkage (v[i], decl);
    9280        1854 :               cp_finish_decl (v[i], init, /*constexpr*/false,
    9281             :                               /*asm*/NULL_TREE, LOOKUP_NORMAL);
    9282             :             }
    9283             :         }
    9284             :       /* Ignore reads from the underlying decl performed during initialization
    9285             :          of the individual variables.  If those will be read, we'll mark
    9286             :          the underlying decl as read at that point.  */
    9287        1064 :       DECL_READ_P (decl) = save_read;
    9288             :     }
    9289        1270 :   else if (TREE_CODE (type) == UNION_TYPE)
    9290             :     {
    9291           0 :       error_at (loc, "cannot decompose union type %qT", type);
    9292           0 :       goto error_out;
    9293             :     }
    9294        1270 :   else if (!CLASS_TYPE_P (type))
    9295             :     {
    9296          13 :       error_at (loc, "cannot decompose non-array non-class type %qT", type);
    9297          13 :       goto error_out;
    9298             :     }
    9299        2514 :   else if (LAMBDA_TYPE_P (type))
    9300             :     {
    9301           6 :       error_at (loc, "cannot decompose lambda closure type %qT", type);
    9302           6 :       goto error_out;
    9303             :     }
    9304        1251 :   else if (processing_template_decl && complete_type (type) == error_mark_node)
    9305           0 :     goto error_out;
    9306        1251 :   else if (processing_template_decl && !COMPLETE_TYPE_P (type))
    9307           2 :     pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
    9308             :              type);
    9309             :   else
    9310             :     {
    9311        1249 :       tree btype = find_decomp_class_base (loc, type, NULL_TREE);
    9312        1249 :       if (btype == error_mark_node)
    9313          12 :         goto error_out;
    9314        1237 :       else if (btype == NULL_TREE)
    9315             :         {
    9316           0 :           error_at (loc, "cannot decompose class type %qT without non-static "
    9317             :                          "data members", type);
    9318           0 :           goto error_out;
    9319             :         }
    9320       16195 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
    9321       27175 :         if (TREE_CODE (field) != FIELD_DECL
    9322        2758 :             || DECL_ARTIFICIAL (field)
    9323       17711 :             || DECL_UNNAMED_BIT_FIELD (field))
    9324       12217 :           continue;
    9325             :         else
    9326        2741 :           eltscnt++;
    9327        1237 :       if (count != eltscnt)
    9328           3 :         goto cnt_mismatch;
    9329        1234 :       tree t = dexp;
    9330        1234 :       if (type != btype)
    9331             :         {
    9332          17 :           t = convert_to_base (t, btype, /*check_access*/true,
    9333             :                                /*nonnull*/false, tf_warning_or_error);
    9334          17 :           type = btype;
    9335             :         }
    9336        1234 :       unsigned int i = 0;
    9337       16146 :       for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
    9338       27090 :         if (TREE_CODE (field) != FIELD_DECL
    9339        2751 :             || DECL_ARTIFICIAL (field)
    9340       17658 :             || DECL_UNNAMED_BIT_FIELD (field))
    9341       12178 :           continue;
    9342             :         else
    9343             :           {
    9344        2734 :             tree tt = finish_non_static_data_member (field, unshare_expr (t),
    9345             :                                                      NULL_TREE);
    9346        2734 :             if (REFERENCE_REF_P (tt))
    9347          19 :               tt = TREE_OPERAND (tt, 0);
    9348        2734 :             TREE_TYPE (v[i]) = TREE_TYPE (tt);
    9349        2734 :             layout_decl (v[i], 0);
    9350        2734 :             if (!processing_template_decl)
    9351             :               {
    9352        2358 :                 SET_DECL_VALUE_EXPR (v[i], tt);
    9353        2358 :                 DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9354             :               }
    9355        2734 :             i++;
    9356             :           }
    9357             :     }
    9358        2458 :   if (processing_template_decl)
    9359             :     {
    9360        1042 :       for (unsigned int i = 0; i < count; i++)
    9361         708 :         if (!DECL_HAS_VALUE_EXPR_P (v[i]))
    9362             :           {
    9363         584 :             tree a = build_nt (ARRAY_REF, decl, size_int (i),
    9364             :                                NULL_TREE, NULL_TREE);
    9365         584 :             SET_DECL_VALUE_EXPR (v[i], a);
    9366         584 :             DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
    9367             :           }
    9368             :     }
    9369             : }
    9370             : 
    9371             : /* Returns a declaration for a VAR_DECL as if:
    9372             : 
    9373             :      extern "C" TYPE NAME;
    9374             : 
    9375             :    had been seen.  Used to create compiler-generated global
    9376             :    variables.  */
    9377             : 
    9378             : static tree
    9379        1804 : declare_global_var (tree name, tree type)
    9380             : {
    9381        1804 :   auto cookie = push_abi_namespace (global_namespace);
    9382        1804 :   tree decl = build_decl (input_location, VAR_DECL, name, type);
    9383        1804 :   TREE_PUBLIC (decl) = 1;
    9384        1804 :   DECL_EXTERNAL (decl) = 1;
    9385        1804 :   DECL_ARTIFICIAL (decl) = 1;
    9386        1804 :   DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
    9387             :   /* If the user has explicitly declared this variable (perhaps
    9388             :      because the code we are compiling is part of a low-level runtime
    9389             :      library), then it is possible that our declaration will be merged
    9390             :      with theirs by pushdecl.  */
    9391        1804 :   decl = pushdecl (decl);
    9392        1804 :   cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
    9393        1804 :   pop_abi_namespace (cookie, global_namespace);
    9394             : 
    9395        1804 :   return decl;
    9396             : }
    9397             : 
    9398             : /* Returns the type for the argument to "__cxa_atexit" (or "atexit",
    9399             :    if "__cxa_atexit" is not being used) corresponding to the function
    9400             :    to be called when the program exits.  */
    9401             : 
    9402             : static tree
    9403        4584 : get_atexit_fn_ptr_type (void)
    9404             : {
    9405        4584 :   tree fn_type;
    9406             : 
    9407        4584 :   if (!atexit_fn_ptr_type_node)
    9408             :     {
    9409        1816 :       tree arg_type;
    9410        1816 :       if (flag_use_cxa_atexit 
    9411        1816 :           && !targetm.cxx.use_atexit_for_cxa_atexit ())
    9412             :         /* The parameter to "__cxa_atexit" is "void (*)(void *)".  */
    9413        1804 :         arg_type = ptr_type_node;
    9414             :       else
    9415             :         /* The parameter to "atexit" is "void (*)(void)".  */
    9416             :         arg_type = NULL_TREE;
    9417             :       
    9418        1816 :       fn_type = build_function_type_list (void_type_node,
    9419             :                                           arg_type, NULL_TREE);
    9420        1816 :       atexit_fn_ptr_type_node = build_pointer_type (fn_type);
    9421             :     }
    9422             : 
    9423        4584 :   return atexit_fn_ptr_type_node;
    9424             : }
    9425             : 
    9426             : /* Returns a pointer to the `atexit' function.  Note that if
    9427             :    FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
    9428             :    `__cxa_atexit' function specified in the IA64 C++ ABI.  */
    9429             : 
    9430             : static tree
    9431        2703 : get_atexit_node (void)
    9432             : {
    9433        2703 :   tree atexit_fndecl;
    9434        2703 :   tree fn_type;
    9435        2703 :   tree fn_ptr_type;
    9436        2703 :   const char *name;
    9437        2703 :   bool use_aeabi_atexit;
    9438        2703 :   tree ctx = global_namespace;
    9439             : 
    9440        2703 :   if (atexit_node)
    9441             :     return atexit_node;
    9442             : 
    9443        1785 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
    9444             :     {
    9445             :       /* The declaration for `__cxa_atexit' is:
    9446             : 
    9447             :            int __cxa_atexit (void (*)(void *), void *, void *)
    9448             : 
    9449             :          We build up the argument types and then the function type
    9450             :          itself.  */
    9451        1773 :       tree argtype0, argtype1, argtype2;
    9452             : 
    9453        1773 :       use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
    9454             :       /* First, build the pointer-to-function type for the first
    9455             :          argument.  */
    9456        1773 :       fn_ptr_type = get_atexit_fn_ptr_type ();
    9457             :       /* Then, build the rest of the argument types.  */
    9458        1773 :       argtype2 = ptr_type_node;
    9459        1773 :       if (use_aeabi_atexit)
    9460             :         {
    9461             :           argtype1 = fn_ptr_type;
    9462             :           argtype0 = ptr_type_node;
    9463             :         }
    9464             :       else
    9465             :         {
    9466        1773 :           argtype1 = ptr_type_node;
    9467        1773 :           argtype0 = fn_ptr_type;
    9468             :         }
    9469             :       /* And the final __cxa_atexit type.  */
    9470        1773 :       fn_type = build_function_type_list (integer_type_node,
    9471             :                                           argtype0, argtype1, argtype2,
    9472             :                                           NULL_TREE);
    9473             :       /* ... which needs noexcept.  */
    9474        1773 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
    9475        1773 :       if (use_aeabi_atexit)
    9476             :         {
    9477           0 :           name = "__aeabi_atexit";
    9478           0 :           push_to_top_level ();
    9479           0 :           int n = push_namespace (get_identifier ("__aeabiv1"), false);
    9480           0 :           ctx = current_namespace;
    9481           0 :           while (n--)
    9482           0 :             pop_namespace ();
    9483           0 :           pop_from_top_level ();
    9484             :         }
    9485             :       else
    9486             :         {
    9487        1773 :           name = "__cxa_atexit";
    9488        1773 :           ctx = abi_node;
    9489             :         }
    9490             :     }
    9491             :   else
    9492             :     {
    9493             :       /* The declaration for `atexit' is:
    9494             : 
    9495             :            int atexit (void (*)());
    9496             : 
    9497             :          We build up the argument types and then the function type
    9498             :          itself.  */
    9499          12 :       fn_ptr_type = get_atexit_fn_ptr_type ();
    9500             :       /* Build the final atexit type.  */
    9501          12 :       fn_type = build_function_type_list (integer_type_node,
    9502             :                                           fn_ptr_type, NULL_TREE);
    9503             :       /* ... which needs noexcept.  */
    9504          12 :       fn_type = build_exception_variant (fn_type, noexcept_true_spec);
    9505          12 :       name = "atexit";
    9506             :     }
    9507             : 
    9508             :   /* Now, build the function declaration.  */
    9509        1785 :   push_lang_context (lang_name_c);
    9510        1785 :   auto cookie = push_abi_namespace (ctx);
    9511        1785 :   atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
    9512        1785 :   DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
    9513             :   /* Install as hidden builtin so we're (a) more relaxed about
    9514             :     exception spec matching and (b) will not give a confusing location
    9515             :     in diagnostic and (c) won't magically appear in user-visible name
    9516             :     lookups.  */
    9517        1785 :   DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
    9518        1785 :   atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
    9519        1785 :   pop_abi_namespace (cookie, ctx);
    9520        1785 :   mark_used (atexit_fndecl);
    9521        1785 :   pop_lang_context ();
    9522        1785 :   atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
    9523             : 
    9524        1785 :   return atexit_node;
    9525             : }
    9526             : 
    9527             : /* Like get_atexit_node, but for thread-local cleanups.  */
    9528             : 
    9529             : static tree
    9530          48 : get_thread_atexit_node (void)
    9531             : {
    9532             :   /* The declaration for `__cxa_thread_atexit' is:
    9533             : 
    9534             :      int __cxa_thread_atexit (void (*)(void *), void *, void *) */
    9535          48 :   tree fn_type = build_function_type_list (integer_type_node,
    9536             :                                            get_atexit_fn_ptr_type (),
    9537             :                                            ptr_type_node, ptr_type_node,
    9538             :                                            NULL_TREE);
    9539             : 
    9540             :   /* Now, build the function declaration.  */
    9541          48 :   tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
    9542             :                                              ECF_LEAF | ECF_NOTHROW);
    9543          48 :   return decay_conversion (atexit_fndecl, tf_warning_or_error);
    9544             : }
    9545             : 
    9546             : /* Returns the __dso_handle VAR_DECL.  */
    9547             : 
    9548             : static tree
    9549        2739 : get_dso_handle_node (void)
    9550             : {
    9551        2739 :   if (dso_handle_node)
    9552             :     return dso_handle_node;
    9553             : 
    9554             :   /* Declare the variable.  */
    9555        1804 :   dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
    9556             :                                         ptr_type_node);
    9557             : 
    9558             : #ifdef HAVE_GAS_HIDDEN
    9559        1804 :   if (dso_handle_node != error_mark_node)
    9560             :     {
    9561        1800 :       DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
    9562        1800 :       DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
    9563             :     }
    9564             : #endif
    9565             : 
    9566        1804 :   return dso_handle_node;
    9567             : }
    9568             : 
    9569             : /* Begin a new function with internal linkage whose job will be simply
    9570             :    to destroy some particular variable.  */
    9571             : 
    9572             : static GTY(()) int start_cleanup_cnt;
    9573             : 
    9574             : static tree
    9575         366 : start_cleanup_fn (void)
    9576             : {
    9577         366 :   char name[32];
    9578             : 
    9579         366 :   push_to_top_level ();
    9580             : 
    9581             :   /* No need to mangle this.  */
    9582         366 :   push_lang_context (lang_name_c);
    9583             : 
    9584             :   /* Build the name of the function.  */
    9585         366 :   sprintf (name, "__tcf_%d", start_cleanup_cnt++);
    9586             :   /* Build the function declaration.  */
    9587         366 :   tree fntype = TREE_TYPE (get_atexit_fn_ptr_type ());
    9588         366 :   tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
    9589         366 :   DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
    9590             :   /* It's a function with internal linkage, generated by the
    9591             :      compiler.  */
    9592         366 :   TREE_PUBLIC (fndecl) = 0;
    9593         366 :   DECL_ARTIFICIAL (fndecl) = 1;
    9594             :   /* Make the function `inline' so that it is only emitted if it is
    9595             :      actually needed.  It is unlikely that it will be inlined, since
    9596             :      it is only called via a function pointer, but we avoid unnecessary
    9597             :      emissions this way.  */
    9598         366 :   DECL_DECLARED_INLINE_P (fndecl) = 1;
    9599         366 :   DECL_INTERFACE_KNOWN (fndecl) = 1;
    9600         366 :   if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
    9601             :     {
    9602             :       /* Build the parameter.  */
    9603         354 :       tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
    9604         354 :       TREE_USED (parmdecl) = 1;
    9605         354 :       DECL_READ_P (parmdecl) = 1;
    9606         354 :       DECL_ARGUMENTS (fndecl) = parmdecl;
    9607             :     }
    9608             : 
    9609         366 :   fndecl = pushdecl (fndecl, /*hidden=*/true);
    9610         366 :   start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
    9611             : 
    9612         366 :   pop_lang_context ();
    9613             : 
    9614         366 :   return current_function_decl;
    9615             : }
    9616             : 
    9617             : /* Finish the cleanup function begun by start_cleanup_fn.  */
    9618             : 
    9619             : static void
    9620         366 : end_cleanup_fn (void)
    9621             : {
    9622         366 :   expand_or_defer_fn (finish_function (/*inline_p=*/false));
    9623             : 
    9624         366 :   pop_from_top_level ();
    9625         366 : }
    9626             : 
    9627             : /* Generate code to handle the destruction of DECL, an object with
    9628             :    static storage duration.  */
    9629             : 
    9630             : tree
    9631       12242 : register_dtor_fn (tree decl)
    9632             : {
    9633       12242 :   tree cleanup;
    9634       12242 :   tree addr;
    9635       12242 :   tree compound_stmt;
    9636       12242 :   tree fcall;
    9637       12242 :   tree type;
    9638       12242 :   bool ob_parm, dso_parm, use_dtor;
    9639       12242 :   tree arg0, arg1, arg2;
    9640       12242 :   tree atex_node;
    9641             : 
    9642       12242 :   type = TREE_TYPE (decl);
    9643       12242 :   if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
    9644        9491 :     return void_node;
    9645             : 
    9646        2751 :   if (decl_maybe_constant_destruction (decl, type)
    9647        2751 :       && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
    9648             :     {
    9649           0 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    9650           0 :       return void_node;
    9651             :     }
    9652             : 
    9653             :   /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
    9654             :      "__aeabi_atexit"), and DECL is a class object, we can just pass the
    9655             :      destructor to "__cxa_atexit"; we don't have to build a temporary
    9656             :      function to do the cleanup.  */
    9657        5502 :   dso_parm = (flag_use_cxa_atexit
    9658        2751 :               && !targetm.cxx.use_atexit_for_cxa_atexit ());
    9659        2751 :   ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
    9660        2739 :   use_dtor = ob_parm && CLASS_TYPE_P (type);
    9661        2751 :   if (use_dtor)
    9662             :     {
    9663        2385 :       cleanup = get_class_binding (type, complete_dtor_identifier);
    9664             : 
    9665             :       /* Make sure it is accessible.  */
    9666        2385 :       perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
    9667             :                                      tf_warning_or_error);
    9668             :     }
    9669             :   else
    9670             :     {
    9671             :       /* Call build_cleanup before we enter the anonymous function so
    9672             :          that any access checks will be done relative to the current
    9673             :          scope, rather than the scope of the anonymous function.  */
    9674         366 :       build_cleanup (decl);
    9675             :   
    9676             :       /* Now start the function.  */
    9677         366 :       cleanup = start_cleanup_fn ();
    9678             :       
    9679             :       /* Now, recompute the cleanup.  It may contain SAVE_EXPRs that refer
    9680             :          to the original function, rather than the anonymous one.  That
    9681             :          will make the back end think that nested functions are in use,
    9682             :          which causes confusion.  */
    9683         366 :       push_deferring_access_checks (dk_no_check);
    9684         366 :       fcall = build_cleanup (decl);
    9685         366 :       pop_deferring_access_checks ();
    9686             :       
    9687             :       /* Create the body of the anonymous function.  */
    9688         366 :       compound_stmt = begin_compound_stmt (BCS_FN_BODY);
    9689         366 :       finish_expr_stmt (fcall);
    9690         366 :       finish_compound_stmt (compound_stmt);
    9691         366 :       end_cleanup_fn ();
    9692             :     }
    9693             : 
    9694             :   /* Call atexit with the cleanup function.  */
    9695        2751 :   mark_used (cleanup);
    9696        2751 :   cleanup = build_address (cleanup);
    9697             : 
    9698        2751 :   if (CP_DECL_THREAD_LOCAL_P (decl))
    9699          48 :     atex_node = get_thread_atexit_node ();
    9700             :   else
    9701        2703 :     atex_node = get_atexit_node ();
    9702             : 
    9703        2751 :   if (use_dtor)
    9704             :     {
    9705             :       /* We must convert CLEANUP to the type that "__cxa_atexit"
    9706             :          expects.  */
    9707        2385 :       cleanup = build_nop (get_atexit_fn_ptr_type (), cleanup);
    9708             :       /* "__cxa_atexit" will pass the address of DECL to the
    9709             :          cleanup function.  */
    9710        2385 :       mark_used (decl);
    9711        2385 :       addr = build_address (decl);
    9712             :       /* The declared type of the parameter to "__cxa_atexit" is
    9713             :          "void *".  For plain "T*", we could just let the
    9714             :          machinery in cp_build_function_call convert it -- but if the
    9715             :          type is "cv-qualified T *", then we need to convert it
    9716             :          before passing it in, to avoid spurious errors.  */
    9717        2385 :       addr = build_nop (ptr_type_node, addr);
    9718             :     }
    9719             :   else
    9720             :     /* Since the cleanup functions we build ignore the address
    9721             :        they're given, there's no reason to pass the actual address
    9722             :        in, and, in general, it's cheaper to pass NULL than any
    9723             :        other value.  */
    9724         366 :     addr = null_pointer_node;
    9725             : 
    9726        2751 :   if (dso_parm)
    9727        2739 :     arg2 = cp_build_addr_expr (get_dso_handle_node (),
    9728             :                                tf_warning_or_error);
    9729          12 :   else if (ob_parm)
    9730             :     /* Just pass NULL to the dso handle parm if we don't actually
    9731             :        have a DSO handle on this target.  */
    9732           0 :     arg2 = null_pointer_node;
    9733             :   else
    9734             :     arg2 = NULL_TREE;
    9735             : 
    9736        2739 :   if (ob_parm)
    9737             :     {
    9738        2739 :       if (!CP_DECL_THREAD_LOCAL_P (decl)
    9739        2739 :           && targetm.cxx.use_aeabi_atexit ())
    9740             :         {
    9741             :           arg1 = cleanup;
    9742             :           arg0 = addr;
    9743             :         }
    9744             :       else
    9745             :         {
    9746             :           arg1 = addr;
    9747             :           arg0 = cleanup;
    9748             :         }
    9749             :     }
    9750             :   else
    9751             :     {
    9752             :       arg0 = cleanup;
    9753             :       arg1 = NULL_TREE;
    9754             :     }
    9755        2751 :   return cp_build_function_call_nary (atex_node, tf_warning_or_error,
    9756        2751 :                                       arg0, arg1, arg2, NULL_TREE);
    9757             : }
    9758             : 
    9759             : /* DECL is a VAR_DECL with static storage duration.  INIT, if present,
    9760             :    is its initializer.  Generate code to handle the construction
    9761             :    and destruction of DECL.  */
    9762             : 
    9763             : static void
    9764     6742859 : expand_static_init (tree decl, tree init)
    9765             : {
    9766     6742859 :   gcc_assert (VAR_P (decl));
    9767     6742859 :   gcc_assert (TREE_STATIC (decl));
    9768             : 
    9769             :   /* Some variables require no dynamic initialization.  */
    9770     6742859 :   if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
    9771             :     {
    9772             :       /* Make sure the destructor is callable.  */
    9773     6740103 :       cxx_maybe_build_cleanup (decl, tf_warning_or_error);
    9774     6740103 :       if (!init)
    9775             :         return;
    9776             :     }
    9777             : 
    9778       12872 :   if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
    9779       12238 :       && !DECL_FUNCTION_SCOPE_P (decl))
    9780             :     {
    9781          18 :       location_t dloc = DECL_SOURCE_LOCATION (decl);
    9782          18 :       if (init)
    9783          15 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
    9784             :                   "needs dynamic initialization", decl);
    9785             :       else
    9786           3 :         error_at (dloc, "non-local variable %qD declared %<__thread%> "
    9787             :                   "has a non-trivial destructor", decl);
    9788          18 :       static bool informed;
    9789          18 :       if (!informed)
    9790             :         {
    9791           7 :           inform (dloc, "C++11 %<thread_local%> allows dynamic "
    9792             :                   "initialization and destruction");
    9793           7 :           informed = true;
    9794             :         }
    9795          18 :       return;
    9796             :     }
    9797             : 
    9798       12202 :   if (DECL_FUNCTION_SCOPE_P (decl))
    9799             :     {
    9800             :       /* Emit code to perform this initialization but once.  */
    9801        3066 :       tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
    9802        3066 :       tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
    9803        3066 :       tree guard, guard_addr;
    9804        3066 :       tree flag, begin;
    9805             :       /* We don't need thread-safety code for thread-local vars.  */
    9806        3066 :       bool thread_guard = (flag_threadsafe_statics
    9807        3066 :                            && !CP_DECL_THREAD_LOCAL_P (decl));
    9808             : 
    9809             :       /* Emit code to perform this initialization but once.  This code
    9810             :          looks like:
    9811             : 
    9812             :            static <type> guard;
    9813             :            if (!__atomic_load (guard.first_byte)) {
    9814             :              if (__cxa_guard_acquire (&guard)) {
    9815             :                bool flag = false;
    9816             :                try {
    9817             :                  // Do initialization.
    9818             :                  flag = true; __cxa_guard_release (&guard);
    9819             :                  // Register variable for destruction at end of program.
    9820             :                } catch {
    9821             :                  if (!flag) __cxa_guard_abort (&guard);
    9822             :                }
    9823             :              }
    9824             :            }
    9825             : 
    9826             :          Note that the `flag' variable is only set to 1 *after* the
    9827             :          initialization is complete.  This ensures that an exception,
    9828             :          thrown during the construction, will cause the variable to
    9829             :          reinitialized when we pass through this code again, as per:
    9830             : 
    9831             :            [stmt.dcl]
    9832             : 
    9833             :            If the initialization exits by throwing an exception, the
    9834             :            initialization is not complete, so it will be tried again
    9835             :            the next time control enters the declaration.
    9836             : 
    9837             :          This process should be thread-safe, too; multiple threads
    9838             :          should not be able to initialize the variable more than
    9839             :          once.  */
    9840             : 
    9841             :       /* Create the guard variable.  */
    9842        3066 :       guard = get_guard (decl);
    9843             : 
    9844             :       /* Begin the conditional initialization.  */
    9845        3066 :       if_stmt = begin_if_stmt ();
    9846             : 
    9847        3066 :       finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
    9848        3066 :       then_clause = begin_compound_stmt (BCS_NO_SCOPE);
    9849             : 
    9850        3066 :       if (thread_guard)
    9851             :         {
    9852        3015 :           tree vfntype = NULL_TREE;
    9853        3015 :           tree acquire_name, release_name, abort_name;
    9854        3015 :           tree acquire_fn, release_fn, abort_fn;
    9855        3015 :           guard_addr = build_address (guard);
    9856             : 
    9857        3015 :           acquire_name = get_identifier ("__cxa_guard_acquire");
    9858        3015 :           release_name = get_identifier ("__cxa_guard_release");
    9859        3015 :           abort_name = get_identifier ("__cxa_guard_abort");
    9860        3015 :           acquire_fn = get_global_binding (acquire_name);
    9861        3015 :           release_fn = get_global_binding (release_name);
    9862        3015 :           abort_fn = get_global_binding (abort_name);
    9863        3015 :           if (!acquire_fn)
    9864        1594 :             acquire_fn = push_library_fn
    9865        1594 :               (acquire_name, build_function_type_list (integer_type_node,
    9866        1594 :                                                        TREE_TYPE (guard_addr),
    9867             :                                                        NULL_TREE),
    9868             :                NULL_TREE, ECF_NOTHROW);
    9869        3015 :           if (!release_fn || !abort_fn)
    9870        1598 :             vfntype = build_function_type_list (void_type_node,
    9871        1598 :                                                 TREE_TYPE (guard_addr),
    9872             :                                                 NULL_TREE);
    9873        1598 :           if (!release_fn)
    9874        1598 :             release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
    9875             :                                           ECF_NOTHROW);
    9876        3015 :           if (!abort_fn)
    9877        1598 :             abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
    9878             :                                         ECF_NOTHROW | ECF_LEAF);
    9879             : 
    9880        3015 :           inner_if_stmt = begin_if_stmt ();
    9881        3015 :           finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
    9882             :                                inner_if_stmt);
    9883             : 
    9884        3015 :           inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
    9885        3015 :           begin = get_target_expr (boolean_false_node);
    9886        3015 :           flag = TARGET_EXPR_SLOT (begin);
    9887             : 
    9888        3015 :           TARGET_EXPR_CLEANUP (begin)
    9889        3015 :             = build3 (COND_EXPR, void_type_node, flag,
    9890             :                       void_node,
    9891             :                       build_call_n (abort_fn, 1, guard_addr));
    9892        3015 :           CLEANUP_EH_ONLY (begin) = 1;
    9893             : 
    9894             :           /* Do the initialization itself.  */
    9895        3015 :           init = add_stmt_to_compound (begin, init);
    9896        3015 :           init = add_stmt_to_compound (init,
    9897             :                                        build2 (MODIFY_EXPR, void_type_node,
    9898             :                                                flag, boolean_true_node));
    9899             : 
    9900             :           /* Use atexit to register a function for destroying this static
    9901             :              variable.  Do this before calling __cxa_guard_release.  */
    9902        3015 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
    9903             : 
    9904        3015 :           init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
    9905             :                                                            guard_addr));
    9906             :         }
    9907             :       else
    9908             :         {
    9909          51 :           init = add_stmt_to_compound (init, set_guard (guard));
    9910             : 
    9911             :           /* Use atexit to register a function for destroying this static
    9912             :              variable.  */
    9913          51 :           init = add_stmt_to_compound (init, register_dtor_fn (decl));
    9914             :         }
    9915             : 
    9916        3066 :       finish_expr_stmt (init);
    9917             : 
    9918        3066 :       if (thread_guard)
    9919             :         {
    9920        3015 :           finish_compound_stmt (inner_then_clause);
    9921        3015 :           finish_then_clause (inner_if_stmt);
    9922        3015 :           finish_if_stmt (inner_if_stmt);
    9923             :         }
    9924             : 
    9925        3066 :       finish_compound_stmt (then_clause);
    9926        3066 :       finish_then_clause (if_stmt);
    9927        3066 :       finish_if_stmt (if_stmt);
    9928             :     }
    9929        9136 :   else if (CP_DECL_THREAD_LOCAL_P (decl))
    9930         587 :     tls_aggregates = tree_cons (init, decl, tls_aggregates);
    9931             :   else
    9932        8549 :     static_aggregates = tree_cons (init, decl, static_aggregates);
    9933             : }
    9934             : 
    9935             : 
    9936             : /* Make TYPE a complete type based on INITIAL_VALUE.
    9937             :    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
    9938             :    2 if there was no information (in which case assume 0 if DO_DEFAULT),
    9939             :    3 if the initializer list is empty (in pedantic mode). */
    9940             : 
    9941             : int
    9942      324152 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
    9943             : {
    9944      324152 :   int failure;
    9945      324152 :   tree type, elt_type;
    9946             : 
    9947             :   /* Don't get confused by a CONSTRUCTOR for some other type.  */
    9948      324119 :   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
    9949       40405 :       && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
    9950      324470 :       && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
    9951             :     return 1;
    9952             : 
    9953      324148 :   if (initial_value)
    9954             :     {
    9955             :       /* An array of character type can be initialized from a
    9956             :          brace-enclosed string constant so call reshape_init to
    9957             :          remove the optional braces from a braced string literal.  */
    9958      324115 :       if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
    9959      324115 :           && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
    9960       14037 :         initial_value = reshape_init (*ptype, initial_value,
    9961             :                                       tf_warning_or_error);
    9962             : 
    9963             :       /* If any of the elements are parameter packs, we can't actually
    9964             :          complete this type now because the array size is dependent.  */
    9965      324115 :       if (TREE_CODE (initial_value) == CONSTRUCTOR)
    9966     1816010 :         for (auto &e: CONSTRUCTOR_ELTS (initial_value))
    9967     1695217 :           if (PACK_EXPANSION_P (e.value))
    9968             :             return 0;
    9969             :     }
    9970             : 
    9971      324148 :   failure = complete_array_type (ptype, initial_value, do_default);
    9972             : 
    9973             :   /* We can create the array before the element type is complete, which
    9974             :      means that we didn't have these two bits set in the original type
    9975             :      either.  In completing the type, we are expected to propagate these
    9976             :      bits.  See also complete_type which does the same thing for arrays
    9977             :      of fixed size.  */
    9978      324148 :   type = *ptype;
    9979      648292 :   if (type != error_mark_node && TYPE_DOMAIN (type))
    9980             :     {
    9981      324119 :       elt_type = TREE_TYPE (type);
    9982      324119 :       TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
    9983      648238 :       TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
    9984      324119 :         = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
    9985             :     }
    9986             : 
    9987             :   return failure;
    9988             : }
    9989             : 
    9990             : /* As above, but either give an error or reject zero-size arrays, depending
    9991             :    on COMPLAIN.  */
    9992             : 
    9993             : int
    9994         319 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
    9995             :                                  bool do_default, tsubst_flags_t complain)
    9996             : {
    9997         319 :   int failure;
    9998         319 :   bool sfinae = !(complain & tf_error);
    9999             :   /* In SFINAE context we can't be lenient about zero-size arrays.  */
   10000         319 :   if (sfinae)
   10001           3 :     ++pedantic;
   10002         319 :   failure = cp_complete_array_type (ptype, initial_value, do_default);
   10003         319 :   if (sfinae)
   10004           3 :     --pedantic;
   10005         319 :   if (failure)
   10006             :     {
   10007           3 :       if (sfinae)
   10008             :         /* Not an error.  */;
   10009           0 :       else if (failure == 1)
   10010           0 :         error ("initializer fails to determine size of %qT", *ptype);
   10011           0 :       else if (failure == 2)
   10012             :         {
   10013           0 :           if (do_default)
   10014           0 :             error ("array size missing in %qT", *ptype);
   10015             :         }
   10016           0 :       else if (failure == 3)
   10017           0 :         error ("zero-size array %qT", *ptype);
   10018           3 :       *ptype = error_mark_node;
   10019             :     }
   10020         319 :   return failure;
   10021             : }
   10022             : 
   10023             : /* Return zero if something is declared to be a member of type
   10024             :    CTYPE when in the context of CUR_TYPE.  STRING is the error
   10025             :    message to print in that case.  Otherwise, quietly return 1.  */
   10026             : 
   10027             : static int
   10028    15719957 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
   10029             : {
   10030    15719957 :   if (ctype && ctype != cur_type)
   10031             :     {
   10032           0 :       if (flags == DTOR_FLAG)
   10033           0 :         error ("destructor for alien class %qT cannot be a member", ctype);
   10034             :       else
   10035           0 :         error ("constructor for alien class %qT cannot be a member", ctype);
   10036           0 :       return 0;
   10037             :     }
   10038             :   return 1;
   10039             : }
   10040             : 
   10041             : /* Subroutine of `grokdeclarator'.  */
   10042             : 
   10043             : /* Generate errors possibly applicable for a given set of specifiers.
   10044             :    This is for ARM $7.1.2.  */
   10045             : 
   10046             : static void
   10047   270872640 : bad_specifiers (tree object,
   10048             :                 enum bad_spec_place type,
   10049             :                 int virtualp,
   10050             :                 int quals,
   10051             :                 int inlinep,
   10052             :                 int friendp,
   10053             :                 int raises,
   10054             :                 const location_t* locations)
   10055             : {
   10056   270872640 :   switch (type)
   10057             :     {
   10058    36175535 :       case BSP_VAR:
   10059    36175535 :         if (virtualp)
   10060           0 :           error_at (locations[ds_virtual],
   10061             :                     "%qD declared as a %<virtual%> variable", object);
   10062    36175535 :         if (quals)
   10063           4 :           error ("%<const%> and %<volatile%> function specifiers on "
   10064             :                  "%qD invalid in variable declaration", object);
   10065             :         break;
   10066   187839912 :       case BSP_PARM:
   10067   187839912 :         if (virtualp)
   10068           0 :           error_at (locations[ds_virtual],
   10069             :                     "%qD declared as a %<virtual%> parameter", object);
   10070   187839912 :         if (inlinep)
   10071           7 :           error_at (locations[ds_inline],
   10072             :                     "%qD declared as an %<inline%> parameter", object);
   10073   187839912 :         if (quals)
   10074           3 :           error ("%<const%> and %<volatile%> function specifiers on "
   10075             :                  "%qD invalid in parameter declaration", object);
   10076             :         break;
   10077    29554905 :       case BSP_TYPE:
   10078    29554905 :         if (virtualp)
   10079           0 :           error_at (locations[ds_virtual],
   10080             :                     "%qD declared as a %<virtual%> type", object);
   10081    29554905 :         if (inlinep)
   10082           7 :           error_at (locations[ds_inline],
   10083             :                     "%qD declared as an %<inline%> type", object);
   10084    29554905 :         if (quals)
   10085           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10086             :                  "%qD invalid in type declaration", object);
   10087             :         break;
   10088    17302288 :       case BSP_FIELD:
   10089    17302288 :         if (virtualp)
   10090           7 :           error_at (locations[ds_virtual],
   10091             :                     "%qD declared as a %<virtual%> field", object);
   10092    17302288 :         if (inlinep)
   10093           7 :           error_at (locations[ds_inline],
   10094             :                     "%qD declared as an %<inline%> field", object);
   10095    17302288 :         if (quals)
   10096           0 :           error ("%<const%> and %<volatile%> function specifiers on "
   10097             :                  "%qD invalid in field declaration", object);
   10098             :         break;
   10099           0 :       default:
   10100           0 :         gcc_unreachable();
   10101             :     }
   10102   270872640 :   if (friendp)
   10103           0 :     error ("%q+D declared as a friend", object);
   10104   270872640 :   if (raises
   10105       18925 :       && !flag_noexcept_type
   10106   270872665 :       && (TREE_CODE (object) == TYPE_DECL
   10107          19 :           || (!TYPE_PTRFN_P (TREE_TYPE (object))
   10108           8 :               && !TYPE_REFFN_P (TREE_TYPE (object))
   10109           6 :               && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
   10110           6 :     error ("%q+D declared with an exception specification", object);
   10111   270872640 : }
   10112             : 
   10113             : /* DECL is a member function or static data member and is presently
   10114             :    being defined.  Check that the definition is taking place in a
   10115             :    valid namespace.  */
   10116             : 
   10117             : static void
   10118    53858028 : check_class_member_definition_namespace (tree decl)
   10119             : {
   10120             :   /* These checks only apply to member functions and static data
   10121             :      members.  */
   10122    53858028 :   gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
   10123             :   /* We check for problems with specializations in pt.cc in
   10124             :      check_specialization_namespace, where we can issue better
   10125             :      diagnostics.  */
   10126    53858028 :   if (processing_specialization)
   10127             :     return;
   10128             :   /* We check this in check_explicit_instantiation_namespace.  */
   10129    53743878 :   if (processing_explicit_instantiation)
   10130             :     return;
   10131             :   /* [class.mfct]
   10132             : 
   10133             :      A member function definition that appears outside of the
   10134             :      class definition shall appear in a namespace scope enclosing
   10135             :      the class definition.
   10136             : 
   10137             :      [class.static.data]
   10138             : 
   10139             :      The definition for a static data member shall appear in a
   10140             :      namespace scope enclosing the member's class definition.  */
   10141    53743831 :   if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
   10142          24 :     permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
   10143          24 :                decl, DECL_CONTEXT (decl));
   10144             : }
   10145             : 
   10146             : /* Build a PARM_DECL for the "this" parameter of FN.  TYPE is the
   10147             :    METHOD_TYPE for a non-static member function; QUALS are the
   10148             :    cv-qualifiers that apply to the function.  */
   10149             : 
   10150             : tree
   10151   131792482 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
   10152             : {
   10153   131792482 :   tree this_type;
   10154   131792482 :   tree qual_type;
   10155   131792482 :   tree parm;
   10156   131792482 :   cp_cv_quals this_quals;
   10157             : 
   10158   131792482 :   if (CLASS_TYPE_P (type))
   10159             :     {
   10160    59815436 :       this_type
   10161    59815436 :         = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
   10162    59815436 :       this_type = build_pointer_type (this_type);
   10163             :     }
   10164             :   else
   10165    71977046 :     this_type = type_of_this_parm (type);
   10166             :   /* The `this' parameter is implicitly `const'; it cannot be
   10167             :      assigned to.  */
   10168   131792482 :   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
   10169   131792482 :   qual_type = cp_build_qualified_type (this_type, this_quals);
   10170   131792482 :   parm = build_artificial_parm (fn, this_identifier, qual_type);
   10171   131792482 :   cp_apply_type_quals_to_decl (this_quals, parm);
   10172   131792482 :   return parm;
   10173             : }
   10174             : 
   10175             : /* DECL is a static member function.  Complain if it was declared
   10176             :    with function-cv-quals.  */
   10177             : 
   10178             : static void
   10179     6027564 : check_static_quals (tree decl, cp_cv_quals quals)
   10180             : {
   10181           0 :   if (quals != TYPE_UNQUALIFIED)
   10182           7 :     error ("static member function %q#D declared with type qualifiers",
   10183             :            decl);
   10184           0 : }
   10185             : 
   10186             : // Check that FN takes no arguments and returns bool.
   10187             : static void
   10188         129 : check_concept_fn (tree fn)
   10189             : {
   10190             :   // A constraint is nullary.
   10191         129 :   if (DECL_ARGUMENTS (fn))
   10192           1 :     error_at (DECL_SOURCE_LOCATION (fn),
   10193             :               "concept %q#D declared with function parameters", fn);
   10194             : 
   10195             :   // The declared return type of the concept shall be bool, and
   10196             :   // it shall not be deduced from it definition.
   10197         129 :   tree type = TREE_TYPE (TREE_TYPE (fn));
   10198         129 :   if (is_auto (type))
   10199           1 :     error_at (DECL_SOURCE_LOCATION (fn),
   10200             :               "concept %q#D declared with a deduced return type", fn);
   10201         128 :   else if (type != boolean_type_node)
   10202           2 :     error_at (DECL_SOURCE_LOCATION (fn),
   10203             :               "concept %q#D with non-%<bool%> return type %qT", fn, type);
   10204         129 : }
   10205             : 
   10206             : /* Helper function.  Replace the temporary this parameter injected
   10207             :    during cp_finish_omp_declare_simd with the real this parameter.  */
   10208             : 
   10209             : static tree
   10210        3045 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
   10211             : {
   10212        3045 :   tree this_parm = (tree) data;
   10213        3045 :   if (TREE_CODE (*tp) == PARM_DECL
   10214         553 :       && DECL_NAME (*tp) == this_identifier
   10215        3367 :       && *tp != this_parm)
   10216         322 :     *tp = this_parm;
   10217        2723 :   else if (TYPE_P (*tp))
   10218          44 :     *walk_subtrees = 0;
   10219        3045 :   return NULL_TREE;
   10220             : }
   10221             : 
   10222             : /* CTYPE is class type, or null if non-class.
   10223             :    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
   10224             :    or METHOD_TYPE.
   10225             :    DECLARATOR is the function's name.
   10226             :    PARMS is a chain of PARM_DECLs for the function.
   10227             :    VIRTUALP is truthvalue of whether the function is virtual or not.
   10228             :    FLAGS are to be passed through to `grokclassfn'.
   10229             :    QUALS are qualifiers indicating whether the function is `const'
   10230             :    or `volatile'.
   10231             :    RAISES is a list of exceptions that this function can raise.
   10232             :    CHECK is 1 if we must find this method in CTYPE, 0 if we should
   10233             :    not look, and -1 if we should not call `grokclassfn' at all.
   10234             : 
   10235             :    SFK is the kind of special function (if any) for the new function.
   10236             : 
   10237             :    Returns `NULL_TREE' if something goes wrong, after issuing
   10238             :    applicable error messages.  */
   10239             : 
   10240             : static tree
   10241   114498364 : grokfndecl (tree ctype,
   10242             :             tree type,
   10243             :             tree declarator,
   10244             :             tree parms,
   10245             :             tree orig_declarator,
   10246             :             const cp_decl_specifier_seq *declspecs,
   10247             :             tree decl_reqs,
   10248             :             int virtualp,
   10249             :             enum overload_flags flags,
   10250             :             cp_cv_quals quals,
   10251             :             cp_ref_qualifier rqual,
   10252             :             tree raises,
   10253             :             int check,
   10254             :             int friendp,
   10255             :             int publicp,
   10256             :             int inlinep,
   10257             :             bool deletedp,
   10258             :             special_function_kind sfk,
   10259             :             bool funcdef_flag,
   10260             :             bool late_return_type_p,
   10261             :             int template_count,
   10262             :             tree in_namespace,
   10263             :             tree* attrlist,
   10264             :             location_t location)
   10265             : {
   10266   114498364 :   tree decl;
   10267   114498364 :   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
   10268   114498364 :   tree t;
   10269             : 
   10270   114498364 :   if (location == UNKNOWN_LOCATION)
   10271           0 :     location = input_location;
   10272             : 
   10273             :   /* Was the concept specifier present?  */
   10274   114498364 :   bool concept_p = inlinep & 4;
   10275             : 
   10276             :   /* Concept declarations must have a corresponding definition.  */
   10277   114498364 :   if (concept_p && !funcdef_flag)
   10278             :     {
   10279           1 :       error_at (location, "concept %qD has no definition", declarator);
   10280           1 :       return NULL_TREE;
   10281             :     }
   10282             : 
   10283   114498363 :   type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
   10284             : 
   10285   114498363 :   decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
   10286             : 
   10287             :   /* Set the constraints on the declaration. */
   10288   114498363 :   if (flag_concepts)
   10289             :     {
   10290     5132778 :       tree tmpl_reqs = NULL_TREE;
   10291     5132778 :       tree ctx = friendp ? current_class_type : ctype;
   10292     5132778 :       bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
   10293     5132778 :       bool memtmpl = (!block_local
   10294     5132778 :                       && (current_template_depth
   10295     5129203 :                           > template_class_depth (ctx)));
   10296     1650610 :       if (memtmpl)
   10297             :         {
   10298     1650610 :           if (!current_template_parms)
   10299             :             /* If there are no template parameters, something must have
   10300             :                gone wrong.  */
   10301           0 :             gcc_assert (seen_error ());
   10302             :           else
   10303     1650610 :             tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
   10304             :         }
   10305     5132778 :       tree ci = build_constraints (tmpl_reqs, decl_reqs);
   10306     5132778 :       if (concept_p && ci)
   10307             :         {
   10308           2 :           error_at (location, "a function concept cannot be constrained");
   10309           2 :           ci = NULL_TREE;
   10310             :         }
   10311             :       /* C++20 CA378: Remove non-templated constrained functions.  */
   10312     5132778 :       if (ci
   10313      353720 :           && (block_local
   10314      353718 :               || (!flag_concepts_ts
   10315      352648 :                   && (!processing_template_decl
   10316      352635 :                       || (friendp && !memtmpl && !funcdef_flag)))))
   10317             :         {
   10318          16 :           error_at (location, "constraints on a non-templated function");
   10319          16 :           ci = NULL_TREE;
   10320             :         }
   10321     5132778 :       set_constraints (decl, ci);
   10322             :     }
   10323             : 
   10324   114498363 :   if (TREE_CODE (type) == METHOD_TYPE)
   10325             :     {
   10326    58626689 :       tree parm = build_this_parm (decl, type, quals);
   10327    58626689 :       DECL_CHAIN (parm) = parms;
   10328    58626689 :       parms = parm;
   10329             : 
   10330             :       /* Allocate space to hold the vptr bit if needed.  */
   10331    58626689 :       SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
   10332             :     }
   10333             : 
   10334   114498363 :   DECL_ARGUMENTS (decl) = parms;
   10335   350210185 :   for (t = parms; t; t = DECL_CHAIN (t))
   10336   235711822 :     DECL_CONTEXT (t) = decl;
   10337             : 
   10338             :   /* Propagate volatile out from type to decl.  */
   10339   114498363 :   if (TYPE_VOLATILE (type))
   10340           0 :     TREE_THIS_VOLATILE (decl) = 1;
   10341             : 
   10342             :   /* Setup decl according to sfk.  */
   10343   114498363 :   switch (sfk)
   10344             :     {
   10345    14376602 :     case sfk_constructor:
   10346    14376602 :     case sfk_copy_constructor:
   10347    14376602 :     case sfk_move_constructor:
   10348    14376602 :       DECL_CXX_CONSTRUCTOR_P (decl) = 1;
   10349    14376602 :       DECL_NAME (decl) = ctor_identifier;
   10350    14376602 :       break;
   10351     2029168 :     case sfk_destructor:
   10352     2029168 :       DECL_CXX_DESTRUCTOR_P (decl) = 1;
   10353     2029168 :       DECL_NAME (decl) = dtor_identifier;
   10354     2029168 :       break;
   10355             :     default:
   10356             :       break;
   10357             :     }
   10358             : 
   10359   114498363 :   if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
   10360             :     {
   10361        8447 :       if (funcdef_flag)
   10362           4 :         error_at (location,
   10363             :                   "defining explicit specialization %qD in friend declaration",
   10364             :                   orig_declarator);
   10365             :       else
   10366             :         {
   10367        8443 :           tree fns = TREE_OPERAND (orig_declarator, 0);
   10368        8443 :           tree args = TREE_OPERAND (orig_declarator, 1);
   10369             : 
   10370        8443 :           if (PROCESSING_REAL_TEMPLATE_DECL_P ())
   10371             :             {
   10372             :               /* Something like `template <class T> friend void f<T>()'.  */
   10373           8 :               error_at (location,
   10374             :                         "invalid use of template-id %qD in declaration "
   10375             :                         "of primary template",
   10376             :                         orig_declarator);
   10377           8 :               return NULL_TREE;
   10378             :             }
   10379             : 
   10380             :           /* A friend declaration of the form friend void f<>().  Record
   10381             :              the information in the TEMPLATE_ID_EXPR.  */
   10382        8435 :           SET_DECL_IMPLICIT_INSTANTIATION (decl);
   10383             : 
   10384        8435 :           gcc_assert (identifier_p (fns) || OVL_P (fns));
   10385        8435 :           DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
   10386             : 
   10387       41697 :           for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
   10388       33267 :             if (TREE_PURPOSE (t)
   10389       33267 :                 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
   10390             :             {
   10391           5 :               error_at (defparse_location (TREE_PURPOSE (t)),
   10392             :                         "default arguments are not allowed in declaration "
   10393             :                         "of friend template specialization %qD",
   10394             :                         decl);
   10395           5 :               return NULL_TREE;
   10396             :             }
   10397             : 
   10398        8430 :           if (inlinep & 1)
   10399             :             {
   10400           5 :               error_at (declspecs->locations[ds_inline],
   10401             :                         "%<inline%> is not allowed in declaration of friend "
   10402             :                         "template specialization %qD",
   10403             :                         decl);
   10404           5 :               return NULL_TREE;
   10405             :             }
   10406             :         }
   10407             :     }
   10408             : 
   10409             :   /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
   10410             :      expression, that declaration shall be a definition..."  */
   10411   114498345 :   if (friendp && !funcdef_flag)
   10412             :     {
   10413      781534 :       for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
   10414     2352295 :            t && t != void_list_node; t = TREE_CHAIN (t))
   10415     1570793 :         if (TREE_PURPOSE (t))
   10416             :           {
   10417          32 :             permerror (DECL_SOURCE_LOCATION (decl),
   10418             :                        "friend declaration of %qD specifies default "
   10419             :                        "arguments and isn%'t a definition", decl);
   10420          32 :             break;
   10421             :           }
   10422             :     }
   10423             : 
   10424             :   /* If this decl has namespace scope, set that up.  */
   10425   114498345 :   if (in_namespace)
   10426       60871 :     set_decl_namespace (decl, in_namespace, friendp);
   10427   114437474 :   else if (ctype)
   10428    64546121 :     DECL_CONTEXT (decl) = ctype;
   10429             :   else
   10430    49891353 :     DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
   10431             : 
   10432             :   /* `main' and builtins have implicit 'C' linkage.  */
   10433   114498345 :   if (ctype == NULL_TREE
   10434    49952224 :       && DECL_FILE_SCOPE_P (decl)
   10435    21996716 :       && current_lang_name == lang_name_cplusplus
   10436   116818357 :       && (MAIN_NAME_P (declarator)
   10437     2289051 :           || (IDENTIFIER_LENGTH (declarator) > 10
   10438     1631861 :               && IDENTIFIER_POINTER (declarator)[0] == '_'
   10439     1284519 :               && IDENTIFIER_POINTER (declarator)[1] == '_'
   10440      249834 :               && startswith (IDENTIFIER_POINTER (declarator) + 2,
   10441             :                              "builtin_"))
   10442     2289027 :           || (targetcm.cxx_implicit_extern_c
   10443           0 :               && (targetcm.cxx_implicit_extern_c
   10444           0 :                   (IDENTIFIER_POINTER (declarator))))))
   10445       30985 :     SET_DECL_LANGUAGE (decl, lang_c);
   10446             : 
   10447             :   /* Should probably propagate const out from type to decl I bet (mrs).  */
   10448   114498345 :   if (staticp)
   10449             :     {
   10450     5919432 :       DECL_STATIC_FUNCTION_P (decl) = 1;
   10451     5919432 :       DECL_CONTEXT (decl) = ctype;
   10452             :     }
   10453             : 
   10454   114498345 :   if (deletedp)
   10455     2229355 :     DECL_DELETED_FN (decl) = 1;
   10456             : 
   10457   114498345 :   if (ctype && funcdef_flag)
   10458    53587008 :     check_class_member_definition_namespace (decl);
   10459             : 
   10460   114498345 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   10461             :     {
   10462       30957 :       if (PROCESSING_REAL_TEMPLATE_DECL_P())
   10463          12 :         error_at (location, "cannot declare %<::main%> to be a template");
   10464       30957 :       if (inlinep & 1)
   10465           4 :         error_at (declspecs->locations[ds_inline],
   10466             :                   "cannot declare %<::main%> to be inline");
   10467       30957 :       if (inlinep & 2)
   10468           6 :         error_at (declspecs->locations[ds_constexpr],
   10469             :                   "cannot declare %<::main%> to be %qs", "constexpr");
   10470       30957 :       if (inlinep & 8)
   10471           1 :         error_at (declspecs->locations[ds_consteval],
   10472             :                   "cannot declare %<::main%> to be %qs", "consteval");
   10473       30957 :       if (!publicp)
   10474           0 :         error_at (location, "cannot declare %<::main%> to be static");
   10475             :       inlinep = 0;
   10476             :       publicp = 1;
   10477             :     }
   10478             : 
   10479             :   /* Members of anonymous types and local classes have no linkage; make
   10480             :      them internal.  If a typedef is made later, this will be changed.  */
   10481   114498345 :   if (ctype && (!TREE_PUBLIC (TYPE_MAIN_DECL (ctype))
   10482    64527292 :                 || decl_function_context (TYPE_MAIN_DECL (ctype))))
   10483             :     publicp = 0;
   10484             : 
   10485   114037787 :   if (publicp && cxx_dialect == cxx98)
   10486             :     {
   10487             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   10488             :          or enumeration declared in a local scope) shall not be used to
   10489             :          declare an entity with linkage.
   10490             : 
   10491             :          DR 757 relaxes this restriction for C++0x.  */
   10492      738417 :       no_linkage_error (decl);
   10493             :     }
   10494             : 
   10495   114498345 :   TREE_PUBLIC (decl) = publicp;
   10496   114498345 :   if (! publicp)
   10497             :     {
   10498      844132 :       DECL_INTERFACE_KNOWN (decl) = 1;
   10499      844132 :       DECL_NOT_REALLY_EXTERN (decl) = 1;
   10500             :     }
   10501             : 
   10502             :   /* If the declaration was declared inline, mark it as such.  */
   10503   114498345 :   if (inlinep)
   10504             :     {
   10505    30351902 :       DECL_DECLARED_INLINE_P (decl) = 1;
   10506    30351902 :       if (publicp)
   10507    29967371 :         DECL_COMDAT (decl) = 1;
   10508             :     }
   10509    30351902 :   if (inlinep & 2)
   10510    14961195 :     DECL_DECLARED_CONSTEXPR_P (decl) = true;
   10511    99537150 :   else if (inlinep & 8)
   10512             :     {
   10513        2535 :       DECL_DECLARED_CONSTEXPR_P (decl) = true;
   10514        2535 :       SET_DECL_IMMEDIATE_FUNCTION_P (decl);
   10515             :     }
   10516             : 
   10517             :   // If the concept declaration specifier was found, check
   10518             :   // that the declaration satisfies the necessary requirements.
   10519   114498345 :   if (concept_p)
   10520             :     {
   10521         129 :       DECL_DECLARED_CONCEPT_P (decl) = true;
   10522         129 :       check_concept_fn (decl);
   10523             :     }
   10524             : 
   10525   114498345 :   DECL_EXTERNAL (decl) = 1;
   10526   114498345 :   if (TREE_CODE (type) == FUNCTION_TYPE)
   10527             :     {
   10528    55871656 :       if (quals || rqual)
   10529          35 :         TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
   10530             :                                               TYPE_UNQUALIFIED,
   10531             :                                               REF_QUAL_NONE);
   10532             : 
   10533          35 :       if (quals)
   10534             :         {
   10535          32 :           error (ctype
   10536             :                  ? G_("static member function %qD cannot have cv-qualifier")
   10537             :                  : G_("non-member function %qD cannot have cv-qualifier"),
   10538             :                  decl);
   10539          32 :           quals = TYPE_UNQUALIFIED;
   10540             :         }
   10541             : 
   10542    55871656 :       if (rqual)
   10543             :         {
   10544           3 :           error (ctype
   10545             :                  ? G_("static member function %qD cannot have ref-qualifier")
   10546             :                  : G_("non-member function %qD cannot have ref-qualifier"),
   10547             :                  decl);
   10548           3 :           rqual = REF_QUAL_NONE;
   10549             :         }
   10550             :     }
   10551             : 
   10552   114498345 :   if (deduction_guide_p (decl))
   10553             :     {
   10554      552053 :       tree type = TREE_TYPE (DECL_NAME (decl));
   10555      552053 :       if (in_namespace == NULL_TREE
   10556      552053 :           && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
   10557             :         {
   10558           2 :           error_at (location, "deduction guide %qD must be declared in the "
   10559             :                               "same scope as %qT", decl, type);
   10560           2 :           inform (location_of (type), "  declared here");
   10561           2 :           return NULL_TREE;
   10562             :         }
   10563     1104102 :       if (DECL_CLASS_SCOPE_P (decl)
   10564      552068 :           && current_access_specifier != declared_access (TYPE_NAME (type)))
   10565             :         {
   10566           2 :           error_at (location, "deduction guide %qD must have the same access "
   10567             :                               "as %qT", decl, type);
   10568           2 :           inform (location_of (type), "  declared here");
   10569             :         }
   10570      552051 :       if (funcdef_flag)
   10571           2 :         error_at (location,
   10572             :                   "deduction guide %qD must not have a function body", decl);
   10573             :     }
   10574   113946292 :   else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
   10575   113946292 :            && !grok_op_properties (decl, /*complain=*/true))
   10576             :     return NULL_TREE;
   10577   113946104 :   else if (UDLIT_OPER_P (DECL_NAME (decl)))
   10578             :     {
   10579      195262 :       bool long_long_unsigned_p;
   10580      195262 :       bool long_double_p;
   10581      195262 :       const char *suffix = NULL;
   10582             :       /* [over.literal]/6: Literal operators shall not have C linkage. */
   10583      195262 :       if (DECL_LANGUAGE (decl) == lang_c)
   10584             :         {
   10585           6 :           error_at (location, "literal operator with C linkage");
   10586           6 :           maybe_show_extern_c_location ();
   10587          54 :           return NULL_TREE;
   10588             :         }
   10589             : 
   10590      195256 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   10591             :         {
   10592      195250 :           if (!check_literal_operator_args (decl, &long_long_unsigned_p,
   10593             :                                             &long_double_p))
   10594             :             {
   10595          42 :               error_at (location, "%qD has invalid argument list", decl);
   10596          42 :               return NULL_TREE;
   10597             :             }
   10598             : 
   10599      195208 :           suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
   10600      195208 :           if (long_long_unsigned_p)
   10601             :             {
   10602       20870 :               if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
   10603          66 :                 warning_at (location, 0, "integer suffix %qs"
   10604             :                             " shadowed by implementation", suffix);
   10605             :             }
   10606      174338 :           else if (long_double_p)
   10607             :             {
   10608       63488 :               if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
   10609          78 :                 warning_at (location, 0, "floating-point suffix %qs"
   10610             :                             " shadowed by implementation", suffix);
   10611             :             }
   10612             :           /* 17.6.3.3.5  */
   10613      195208 :           if (suffix[0] != '_'
   10614      194753 :               && !current_function_decl && !(friendp && !funcdef_flag))
   10615      194747 :             warning_at (location, OPT_Wliteral_suffix,
   10616             :                         "literal operator suffixes not preceded by %<_%>"
   10617             :                         " are reserved for future standardization");
   10618             :         }
   10619             :       else
   10620             :         {
   10621           6 :           error_at (location, "%qD must be a non-member function", decl);
   10622           6 :           return NULL_TREE;
   10623             :         }
   10624             :     }
   10625             : 
   10626   113946052 :   if (funcdef_flag)
   10627             :     /* Make the init_value nonzero so pushdecl knows this is not
   10628             :        tentative.  error_mark_node is replaced later with the BLOCK.  */
   10629    76498756 :     DECL_INITIAL (decl) = error_mark_node;
   10630             : 
   10631   114498101 :   if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
   10632    41866377 :     TREE_NOTHROW (decl) = 1;
   10633             : 
   10634   114498101 :   if (flag_openmp || flag_openmp_simd)
   10635             :     {
   10636             :       /* Adjust "omp declare simd" attributes.  */
   10637      141886 :       tree ods = lookup_attribute ("omp declare simd", *attrlist);
   10638      141886 :       if (ods)
   10639             :         {
   10640             :           tree attr;
   10641        2348 :           for (attr = ods; attr;
   10642        1221 :                attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
   10643             :             {
   10644        1221 :               if (TREE_CODE (type) == METHOD_TYPE)
   10645         262 :                 walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
   10646             :                            DECL_ARGUMENTS (decl), NULL);
   10647        1221 :               if (TREE_VALUE (attr) != NULL_TREE)
   10648             :                 {
   10649         977 :                   tree cl = TREE_VALUE (TREE_VALUE (attr));
   10650         977 :                   cl = c_omp_declare_simd_clauses_to_numbers
   10651         977 :                                                 (DECL_ARGUMENTS (decl), cl);
   10652         977 :                   if (cl)
   10653         977 :                     TREE_VALUE (TREE_VALUE (attr)) = cl;
   10654             :                   else
   10655           0 :                     TREE_VALUE (attr) = NULL_TREE;
   10656             :                 }
   10657             :             }
   10658             :         }
   10659             :     }
   10660             : 
   10661             :   /* Caller will do the rest of this.  */
   10662   114498101 :   if (check < 0)
   10663     2022684 :     return decl;
   10664             : 
   10665   112475417 :   if (ctype != NULL_TREE)
   10666    64545750 :     grokclassfn (ctype, decl, flags);
   10667             : 
   10668             :   /* 12.4/3  */
   10669   112475417 :   if (cxx_dialect >= cxx11
   10670   223467994 :       && DECL_DESTRUCTOR_P (decl)
   10671     2015320 :       && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
   10672   112594779 :       && !processing_template_decl)
   10673       60664 :     deduce_noexcept_on_destructor (decl);
   10674             : 
   10675   112475417 :   set_originating_module (decl);
   10676             : 
   10677   337426251 :   decl = check_explicit_specialization (orig_declarator, decl,
   10678             :                                         template_count,
   10679   224950834 :                                         2 * funcdef_flag +
   10680   112475417 :                                         4 * (friendp != 0) +
   10681   112475417 :                                         8 * concept_p,
   10682             :                                         *attrlist);
   10683   112475417 :   if (decl == error_mark_node)
   10684             :     return NULL_TREE;
   10685             : 
   10686   112475133 :   if (DECL_STATIC_FUNCTION_P (decl))
   10687     5920244 :     check_static_quals (decl, quals);
   10688             : 
   10689   112475133 :   if (attrlist)
   10690             :     {
   10691   112475133 :       cplus_decl_attributes (&decl, *attrlist, 0);
   10692   112475133 :       *attrlist = NULL_TREE;
   10693             :     }
   10694             : 
   10695   112475133 :   if (DECL_HAS_CONTRACTS_P (decl))
   10696         449 :     rebuild_postconditions (decl);
   10697             : 
   10698             :   /* Check main's type after attributes have been applied.  */
   10699   112475133 :   if (ctype == NULL_TREE && DECL_MAIN_P (decl))
   10700             :     {
   10701       30941 :       if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
   10702             :                         integer_type_node))
   10703             :         {
   10704          25 :           tree oldtypeargs = TYPE_ARG_TYPES (TREE_TYPE (decl));
   10705          25 :           tree newtype;
   10706          25 :           error_at (declspecs->locations[ds_type_spec],
   10707             :                     "%<::main%> must return %<int%>");
   10708          25 :           newtype = build_function_type (integer_type_node, oldtypeargs);
   10709          25 :           TREE_TYPE (decl) = newtype;
   10710             :         }
   10711       30941 :       if (warn_main)
   10712       30919 :         check_main_parameter_types (decl);
   10713             :     }
   10714             : 
   10715   112475133 :   if (ctype != NULL_TREE && check)
   10716             :     {
   10717     6472657 :       tree old_decl = check_classfn (ctype, decl,
   10718     6472657 :                                      (current_template_depth
   10719     6472657 :                                       > template_class_depth (ctype))
   10720     1481301 :                                      ? current_template_parms
   10721             :                                      : NULL_TREE);
   10722             : 
   10723     6472657 :       if (old_decl == error_mark_node)
   10724             :         return NULL_TREE;
   10725             : 
   10726     6472560 :       if (old_decl)
   10727             :         {
   10728     6177062 :           tree ok;
   10729     6177062 :           tree pushed_scope;
   10730             : 
   10731     6177062 :           if (TREE_CODE (old_decl) == TEMPLATE_DECL)
   10732             :             /* Because grokfndecl is always supposed to return a
   10733             :                FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
   10734             :                here.  We depend on our callers to figure out that its
   10735             :                really a template that's being returned.  */
   10736     1481285 :             old_decl = DECL_TEMPLATE_RESULT (old_decl);
   10737             : 
   10738     6177062 :           if (DECL_STATIC_FUNCTION_P (old_decl)
   10739     6177062 :               && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
   10740             :             {
   10741             :               /* Remove the `this' parm added by grokclassfn.  */
   10742      107320 :               revert_static_member_fn (decl);
   10743      107320 :               check_static_quals (decl, quals);
   10744             :             }
   10745     6177062 :           if (DECL_ARTIFICIAL (old_decl))
   10746             :             {
   10747          12 :               error ("definition of implicitly-declared %qD", old_decl);
   10748          12 :               return NULL_TREE;
   10749             :             }
   10750     6177050 :           else if (DECL_DEFAULTED_FN (old_decl))
   10751             :             {
   10752           3 :               error ("definition of explicitly-defaulted %q+D", decl);
   10753           3 :               inform (DECL_SOURCE_LOCATION (old_decl),
   10754             :                       "%q#D explicitly defaulted here", old_decl);
   10755           3 :               return NULL_TREE;
   10756             :             }
   10757             : 
   10758             :           /* Since we've smashed OLD_DECL to its
   10759             :              DECL_TEMPLATE_RESULT, we must do the same to DECL.  */
   10760     6177047 :           if (TREE_CODE (decl) == TEMPLATE_DECL)
   10761         703 :             decl = DECL_TEMPLATE_RESULT (decl);
   10762             : 
   10763             :           /* Attempt to merge the declarations.  This can fail, in
   10764             :              the case of some invalid specialization declarations.  */
   10765     6177047 :           pushed_scope = push_scope (ctype);
   10766     6177047 :           ok = duplicate_decls (decl, old_decl);
   10767     6177047 :           if (pushed_scope)
   10768     6177047 :             pop_scope (pushed_scope);
   10769     6177047 :           if (!ok)
   10770             :             {
   10771           0 :               error ("no %q#D member function declared in class %qT",
   10772             :                      decl, ctype);
   10773           0 :               return NULL_TREE;
   10774             :             }
   10775     6177047 :           if (ok == error_mark_node)
   10776             :             return NULL_TREE;
   10777             :           return old_decl;
   10778             :         }
   10779             :     }
   10780             : 
   10781   212595948 :   if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
   10782             :     return NULL_TREE;
   10783             : 
   10784   106297970 :   if (ctype == NULL_TREE || check)
   10785    48224952 :     return decl;
   10786             : 
   10787    58073018 :   if (virtualp)
   10788     2826399 :     DECL_VIRTUAL_P (decl) = 1;
   10789             : 
   10790    58073018 :   return decl;
   10791             : }
   10792             : 
   10793             : /* decl is a FUNCTION_DECL.
   10794             :    specifiers are the parsed virt-specifiers.
   10795             : 
   10796             :    Set flags to reflect the virt-specifiers.
   10797             : 
   10798             :    Returns decl.  */
   10799             : 
   10800             : static tree
   10801    60095819 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
   10802             : {
   10803    60095819 :   if (decl == NULL_TREE)
   10804             :     return decl;
   10805    60095702 :   if (specifiers & VIRT_SPEC_OVERRIDE)
   10806       86921 :     DECL_OVERRIDE_P (decl) = 1;
   10807    60095702 :   if (specifiers & VIRT_SPEC_FINAL)
   10808         354 :     DECL_FINAL_P (decl) = 1;
   10809             :   return decl;
   10810             : }
   10811             : 
   10812             : /* DECL is a VAR_DECL for a static data member.  Set flags to reflect
   10813             :    the linkage that DECL will receive in the object file.  */
   10814             : 
   10815             : static void
   10816     6551891 : set_linkage_for_static_data_member (tree decl)
   10817             : {
   10818             :   /* A static data member always has static storage duration and
   10819             :      external linkage.  Note that static data members are forbidden in
   10820             :      local classes -- the only situation in which a class has
   10821             :      non-external linkage.  */
   10822     6551891 :   TREE_PUBLIC (decl) = 1;
   10823     6551891 :   TREE_STATIC (decl) = 1;
   10824             :   /* For non-template classes, static data members are always put
   10825             :      out in exactly those files where they are defined, just as
   10826             :      with ordinary namespace-scope variables.  */
   10827     6551891 :   if (!processing_template_decl)
   10828     4829294 :     DECL_INTERFACE_KNOWN (decl) = 1;
   10829     6551891 : }
   10830             : 
   10831             : /* Create a VAR_DECL named NAME with the indicated TYPE.
   10832             : 
   10833             :    If SCOPE is non-NULL, it is the class type or namespace containing
   10834             :    the variable.  If SCOPE is NULL, the variable should is created in
   10835             :    the innermost enclosing scope.  */
   10836             : 
   10837             : static tree
   10838    36175556 : grokvardecl (tree type,
   10839             :              tree name,
   10840             :              tree orig_declarator,
   10841             :              const cp_decl_specifier_seq *declspecs,
   10842             :              int initialized,
   10843             :              int type_quals,
   10844             :              int inlinep,
   10845             :              bool conceptp,
   10846             :              int template_count,
   10847             :              tree scope,
   10848             :              location_t location)
   10849             : {
   10850    36175556 :   tree decl;
   10851    36175556 :   tree explicit_scope;
   10852             : 
   10853    36175556 :   gcc_assert (!name || identifier_p (name));
   10854             : 
   10855    36175556 :   bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
   10856    36175556 :   bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
   10857             : 
   10858             :   /* Compute the scope in which to place the variable, but remember
   10859             :      whether or not that scope was explicitly specified by the user.   */
   10860    36175556 :   explicit_scope = scope;
   10861    36175556 :   if (!scope)
   10862             :     {
   10863             :       /* An explicit "extern" specifier indicates a namespace-scope
   10864             :          variable.  */
   10865    35904431 :       if (declspecs->storage_class == sc_extern)
   10866      463283 :         scope = current_decl_namespace ();
   10867    35441148 :       else if (!at_function_scope_p ())
   10868     2493388 :         scope = current_scope ();
   10869             :     }
   10870             : 
   10871    35904431 :   if (scope
   10872     3227796 :       && (/* If the variable is a namespace-scope variable declared in a
   10873             :              template, we need DECL_LANG_SPECIFIC.  */
   10874     3227796 :           (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
   10875             :           /* Similarly for namespace-scope variables with language linkage
   10876             :              other than C++.  */
   10877     2956776 :           || (TREE_CODE (scope) == NAMESPACE_DECL
   10878     1432736 :               && current_lang_name != lang_name_cplusplus)
   10879             :           /* Similarly for static data members.  */
   10880     1528506 :           || TYPE_P (scope)
   10881             :           /* Similarly for explicit specializations.  */
   10882     1257486 :           || (orig_declarator
   10883     1257278 :               && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
   10884     2103329 :     decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   10885             :   else
   10886    34072227 :     decl = build_decl (location, VAR_DECL, name, type);
   10887             : 
   10888    36175556 :   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
   10889         105 :     set_decl_namespace (decl, explicit_scope, 0);
   10890             :   else
   10891    36175451 :     DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
   10892             : 
   10893    36175556 :   if (declspecs->storage_class == sc_extern)
   10894             :     {
   10895      463283 :       DECL_THIS_EXTERN (decl) = 1;
   10896      463283 :       DECL_EXTERNAL (decl) = !initialized;
   10897             :     }
   10898             : 
   10899    36175556 :   if (DECL_CLASS_SCOPE_P (decl))
   10900             :     {
   10901      271020 :       set_linkage_for_static_data_member (decl);
   10902             :       /* This function is only called with out-of-class definitions.  */
   10903      271020 :       DECL_EXTERNAL (decl) = 0;
   10904      271020 :       check_class_member_definition_namespace (decl);
   10905             :     }
   10906             :   /* At top level, either `static' or no s.c. makes a definition
   10907             :      (perhaps tentative), and absence of `static' makes it public.  */
   10908    35904536 :   else if (toplevel_bindings_p ())
   10909             :     {
   10910     5911056 :       TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
   10911     2955528 :                             && (DECL_THIS_EXTERN (decl)
   10912     2445073 :                                 || ! constp
   10913     2445073 :                                 || volatilep
   10914     2374270 :                                 || inlinep));
   10915     2955528 :       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
   10916             :     }
   10917             :   /* Not at top level, only `static' makes a static definition.  */
   10918             :   else
   10919             :     {
   10920    32949008 :       TREE_STATIC (decl) = declspecs->storage_class == sc_static;
   10921    32949008 :       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
   10922             :     }
   10923             : 
   10924    36175556 :   set_originating_module (decl);
   10925             : 
   10926    36175556 :   if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
   10927             :     {
   10928       14638 :       if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
   10929             :         {
   10930       14628 :           CP_DECL_THREAD_LOCAL_P (decl) = true;
   10931       14628 :           if (!processing_template_decl)
   10932       14604 :             set_decl_tls_model (decl, decl_default_tls_model (decl));
   10933             :         }
   10934       14638 :       if (declspecs->gnu_thread_keyword_p)
   10935       13925 :         SET_DECL_GNU_TLS_P (decl);
   10936             :     }
   10937             : 
   10938             :   /* If the type of the decl has no linkage, make sure that we'll
   10939             :      notice that in mark_used.  */
   10940    36175556 :   if (cxx_dialect > cxx98
   10941    35978649 :       && decl_linkage (decl) != lk_none
   10942    35630225 :       && DECL_LANG_SPECIFIC (decl) == NULL
   10943    33443493 :       && !DECL_EXTERN_C_P (decl)
   10944    69619049 :       && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
   10945        3295 :     retrofit_lang_decl (decl);
   10946             : 
   10947    36175556 :   if (TREE_PUBLIC (decl))
   10948             :     {
   10949             :       /* [basic.link]: A name with no linkage (notably, the name of a class
   10950             :          or enumeration declared in a local scope) shall not be used to
   10951             :          declare an entity with linkage.
   10952             : 
   10953             :          DR 757 relaxes this restriction for C++0x.  */
   10954     3099758 :       if (cxx_dialect < cxx11)
   10955       18142 :         no_linkage_error (decl);
   10956             :     }
   10957             :   else
   10958    33075798 :     DECL_INTERFACE_KNOWN (decl) = 1;
   10959             : 
   10960    36175556 :   if (DECL_NAME (decl)
   10961    35822030 :       && MAIN_NAME_P (DECL_NAME (decl))
   10962    36175568 :       && scope == global_namespace)
   10963           8 :     error_at (DECL_SOURCE_LOCATION (decl),
   10964             :               "cannot declare %<::main%> to be a global variable");
   10965             : 
   10966             :   /* Check that the variable can be safely declared as a concept.
   10967             :      Note that this also forbids explicit specializations.  */
   10968    36175556 :   if (conceptp)
   10969             :     {
   10970         127 :       if (!processing_template_decl)
   10971             :         {
   10972           6 :           error_at (declspecs->locations[ds_concept],
   10973             :                     "a non-template variable cannot be %<concept%>");
   10974           6 :           return NULL_TREE;
   10975             :         }
   10976         121 :       else if (!at_namespace_scope_p ())
   10977             :         {
   10978           1 :           error_at (declspecs->locations[ds_concept],
   10979             :                     "concept must be defined at namespace scope");
   10980           1 :           return NULL_TREE;
   10981             :         }
   10982             :       else
   10983         120 :         DECL_DECLARED_CONCEPT_P (decl) = true;
   10984         120 :       if (!same_type_ignoring_top_level_qualifiers_p (type, boolean_type_node))
   10985           1 :         error_at (declspecs->locations[ds_type_spec],
   10986             :                   "concept must have type %<bool%>");
   10987         120 :       if (TEMPLATE_PARMS_CONSTRAINTS (current_template_parms))
   10988             :         {
   10989           1 :           error_at (location, "a variable concept cannot be constrained");
   10990           1 :           TEMPLATE_PARMS_CONSTRAINTS (current_template_parms) = NULL_TREE;
   10991             :         }
   10992             :     }
   10993    36175429 :   else if (flag_concepts
   10994    36175429 :            && current_template_depth > template_class_depth (scope))
   10995             :     {
   10996     1252656 :       tree ci = current_template_constraints ();
   10997     1252656 :       set_constraints (decl, ci);
   10998             :     }
   10999             : 
   11000             :   // Handle explicit specializations and instantiations of variable templates.
   11001    36175549 :   if (orig_declarator)
   11002    35822023 :     decl = check_explicit_specialization (orig_declarator, decl,
   11003             :                                           template_count, conceptp * 8);
   11004             : 
   11005    36175549 :   return decl != error_mark_node ? decl : NULL_TREE;
   11006             : }
   11007             : 
   11008             : /* Create and return a canonical pointer to member function type, for
   11009             :    TYPE, which is a POINTER_TYPE to a METHOD_TYPE.  */
   11010             : 
   11011             : tree
   11012     2739480 : build_ptrmemfunc_type (tree type)
   11013             : {
   11014     2739480 :   tree field, fields;
   11015     2739480 :   tree t;
   11016             : 
   11017     2739480 :   if (type == error_mark_node)
   11018             :     return type;
   11019             : 
   11020             :   /* Make sure that we always have the unqualified pointer-to-member
   11021             :      type first.  */
   11022     2739480 :   if (cp_cv_quals quals = cp_type_quals (type))
   11023             :     {
   11024         399 :       tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
   11025         399 :       return cp_build_qualified_type (unqual, quals);
   11026             :     }
   11027             : 
   11028             :   /* If a canonical type already exists for this type, use it.  We use
   11029             :      this method instead of type_hash_canon, because it only does a
   11030             :      simple equality check on the list of field members.  */
   11031             : 
   11032     2739081 :   t = TYPE_PTRMEMFUNC_TYPE (type);
   11033     2739081 :   if (t)
   11034             :     return t;
   11035             : 
   11036      828967 :   t = make_node (RECORD_TYPE);
   11037             : 
   11038             :   /* Let the front end know this is a pointer to member function.  */
   11039      828967 :   TYPE_PTRMEMFUNC_FLAG (t) = 1;
   11040             : 
   11041      828967 :   field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
   11042      828967 :   DECL_NONADDRESSABLE_P (field) = 1;
   11043      828967 :   fields = field;
   11044             : 
   11045      828967 :   field = build_decl (input_location, FIELD_DECL, delta_identifier, 
   11046             :                       delta_type_node);
   11047      828967 :   DECL_NONADDRESSABLE_P (field) = 1;
   11048      828967 :   DECL_CHAIN (field) = fields;
   11049      828967 :   fields = field;
   11050             : 
   11051      828967 :   finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
   11052             : 
   11053             :   /* Zap out the name so that the back end will give us the debugging
   11054             :      information for this anonymous RECORD_TYPE.  */
   11055      828967 :   TYPE_NAME (t) = NULL_TREE;
   11056             : 
   11057             :   /* Cache this pointer-to-member type so that we can find it again
   11058             :      later.  */
   11059      828967 :   TYPE_PTRMEMFUNC_TYPE (type) = t;
   11060             : 
   11061      828967 :   if (TYPE_STRUCTURAL_EQUALITY_P (type))
   11062      450713 :     SET_TYPE_STRUCTURAL_EQUALITY (t);
   11063      378254 :   else if (TYPE_CANONICAL (type) != type)
   11064      246655 :     TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
   11065             : 
   11066             :   return t;
   11067             : }
   11068             : 
   11069             : /* Create and return a pointer to data member type.  */
   11070             : 
   11071             : tree
   11072      266055 : build_ptrmem_type (tree class_type, tree member_type)
   11073             : {
   11074      266055 :   if (TREE_CODE (member_type) == METHOD_TYPE)
   11075             :     {
   11076       45208 :       cp_cv_quals quals = type_memfn_quals (member_type);
   11077       45208 :       cp_ref_qualifier rqual = type_memfn_rqual (member_type);
   11078       45208 :       member_type = build_memfn_type (member_type, class_type, quals, rqual);
   11079       45208 :       return build_ptrmemfunc_type (build_pointer_type (member_type));
   11080             :     }
   11081             :   else
   11082             :     {
   11083      220847 :       gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
   11084      220847 :       return build_offset_type (class_type, member_type);
   11085             :     }
   11086             : }
   11087             : 
   11088             : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
   11089             :    Check to see that the definition is valid.  Issue appropriate error
   11090             :    messages.  */
   11091             : 
   11092             : static void
   11093     8173826 : check_static_variable_definition (tree decl, tree type)
   11094             : {
   11095             :   /* Avoid redundant diagnostics on out-of-class definitions.  */
   11096     8173826 :   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
   11097             :     ;
   11098             :   /* Can't check yet if we don't know the type.  */
   11099     7609384 :   else if (dependent_type_p (type))
   11100             :     ;
   11101             :   /* If DECL is declared constexpr, we'll do the appropriate checks
   11102             :      in check_initializer.  Similarly for inline static data members.  */
   11103     7467209 :   else if (DECL_P (decl)
   11104     7467209 :       && (DECL_DECLARED_CONSTEXPR_P (decl)
   11105     1639412 :           || DECL_VAR_DECLARED_INLINE_P (decl)))
   11106             :     ;
   11107     1639123 :   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   11108             :     {
   11109          66 :       if (!COMPLETE_TYPE_P (type))
   11110          15 :         error_at (DECL_SOURCE_LOCATION (decl),
   11111             :                   "in-class initialization of static data member %q#D of "
   11112             :                   "incomplete type", decl);
   11113          51 :       else if (literal_type_p (type))
   11114          45 :         permerror (DECL_SOURCE_LOCATION (decl),
   11115             :                    "%<constexpr%> needed for in-class initialization of "
   11116             :                    "static data member %q#D of non-integral type", decl);
   11117             :       else
   11118           6 :         error_at (DECL_SOURCE_LOCATION (decl),
   11119             :                   "in-class initialization of static data member %q#D of "
   11120             :                   "non-literal type", decl);
   11121             :     }
   11122             :   /* Motion 10 at San Diego: If a static const integral data member is
   11123             :      initialized with an integral constant expression, the initializer
   11124             :      may appear either in the declaration (within the class), or in
   11125             :      the definition, but not both.  If it appears in the class, the
   11126             :      member is a member constant.  The file-scope definition is always
   11127             :      required.  */
   11128     1639057 :   else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
   11129          11 :     error_at (DECL_SOURCE_LOCATION (decl),
   11130             :               "invalid in-class initialization of static data member "
   11131             :               "of non-integral type %qT",
   11132             :               type);
   11133     1639046 :   else if (!CP_TYPE_CONST_P (type))
   11134           5 :     error_at (DECL_SOURCE_LOCATION (decl),
   11135             :               "ISO C++ forbids in-class initialization of non-const "
   11136             :               "static member %qD",
   11137             :               decl);
   11138     1639041 :   else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
   11139           5 :     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   11140             :              "ISO C++ forbids initialization of member constant "
   11141             :              "%qD of non-integral type %qT", decl, type);
   11142     8173826 : }
   11143             : 
   11144             : /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any
   11145             :    SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
   11146             :    expressions out into temporary variables so that walk_tree doesn't
   11147             :    step into them (c++/15764).  */
   11148             : 
   11149             : static tree
   11150        3345 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
   11151             : {
   11152        3345 :   hash_set<tree> *pset = (hash_set<tree> *)data;
   11153        3345 :   tree expr = *expr_p;
   11154        3345 :   if (TREE_CODE (expr) == SAVE_EXPR)
   11155             :     {
   11156        1400 :       tree op = TREE_OPERAND (expr, 0);
   11157        1400 :       cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
   11158        1400 :       if (TREE_SIDE_EFFECTS (op))
   11159          68 :         TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
   11160        1400 :       *walk_subtrees = 0;
   11161             :     }
   11162        1945 :   else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
   11163        1723 :     *walk_subtrees = 0;
   11164        3345 :   return NULL;
   11165             : }
   11166             : 
   11167             : /* Entry point for the above.  */
   11168             : 
   11169             : static void
   11170        1471 : stabilize_vla_size (tree size)
   11171             : {
   11172        1471 :   hash_set<tree> pset;
   11173             :   /* Break out any function calls into temporary variables.  */
   11174        1471 :   cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
   11175        1471 : }
   11176             : 
   11177             : /* Reduce a SIZEOF_EXPR to its value.  */
   11178             : 
   11179             : tree
   11180     7745881 : fold_sizeof_expr (tree t)
   11181             : {
   11182     7745881 :   tree r;
   11183     7745881 :   if (SIZEOF_EXPR_TYPE_P (t))
   11184     7313750 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   11185     7313750 :                                     TREE_TYPE (TREE_OPERAND (t, 0)),
   11186             :                                     SIZEOF_EXPR, false, false);
   11187      432131 :   else if (TYPE_P (TREE_OPERAND (t, 0)))
   11188           0 :     r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
   11189           0 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   11190             :                                     false, false);
   11191             :   else
   11192      432131 :     r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
   11193      432131 :                                     TREE_OPERAND (t, 0), SIZEOF_EXPR,
   11194             :                                     false, false);
   11195     7745881 :   if (r == error_mark_node)
   11196          60 :     r = size_one_node;
   11197     7745881 :   return r;
   11198             : }
   11199             : 
   11200             : /* Given the SIZE (i.e., number of elements) in an array, compute
   11201             :    an appropriate index type for the array.  If non-NULL, NAME is
   11202             :    the name of the entity being declared.  */
   11203             : 
   11204             : static tree
   11205     1843739 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
   11206             :                               tsubst_flags_t complain)
   11207             : {
   11208     1843739 :   if (error_operand_p (size))
   11209          31 :     return error_mark_node;
   11210             : 
   11211             :   /* The type of the index being computed.  */
   11212     1843708 :   tree itype;
   11213             : 
   11214             :   /* The original numeric size as seen in the source code before
   11215             :      conversion to size_t.  */
   11216     1843708 :   tree origsize = size;
   11217             : 
   11218     1843708 :   location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
   11219             : 
   11220     1843708 :   if (!type_dependent_expression_p (size))
   11221             :     {
   11222     1817992 :       origsize = size = mark_rvalue_use (size);
   11223             : 
   11224       26623 :       if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
   11225     1818163 :           && TREE_SIDE_EFFECTS (size))
   11226             :         /* In C++98, we mark a non-constant array bound with a magic
   11227             :            NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case.  */;
   11228             :       else
   11229             :         {
   11230     1817991 :           size = build_converted_constant_expr (size_type_node, size, complain);
   11231             :           /* Pedantically a constant expression is required here and so
   11232             :              __builtin_is_constant_evaluated () should fold to true if it
   11233             :              is successfully folded into a constant.  */
   11234     1817991 :           size = fold_non_dependent_expr (size, complain,
   11235             :                                           /*manifestly_const_eval=*/true);
   11236             : 
   11237     1817991 :           if (!TREE_CONSTANT (size))
   11238       66881 :             size = origsize;
   11239             :         }
   11240             : 
   11241     1817992 :       if (error_operand_p (size))
   11242           3 :         return error_mark_node;
   11243             : 
   11244             :       /* The array bound must be an integer type.  */
   11245     1817989 :       tree type = TREE_TYPE (size);
   11246     1817989 :       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
   11247             :         {
   11248          25 :           if (!(complain & tf_error))
   11249           0 :             return error_mark_node;
   11250          25 :           if (name)
   11251          21 :             error_at (loc, "size of array %qD has non-integral type %qT",
   11252             :                       name, type);
   11253             :           else
   11254           4 :             error_at (loc, "size of array has non-integral type %qT", type);
   11255          25 :           size = integer_one_node;
   11256             :         }
   11257             :     }
   11258             : 
   11259             :   /* A type is dependent if it is...an array type constructed from any
   11260             :      dependent type or whose size is specified by a constant expression
   11261             :      that is value-dependent.  */
   11262             :   /* We can only call value_dependent_expression_p on integral constant
   11263             :      expressions.  */
   11264     1843705 :   if (processing_template_decl
   11265      813319 :       && potential_constant_expression (size)
   11266     2656998 :       && value_dependent_expression_p (size))
   11267             :     {
   11268             :       /* Just build the index type and mark that it requires
   11269             :          structural equality checks.  */
   11270      510909 :     in_template:
   11271      510909 :       itype = build_index_type (build_min (MINUS_EXPR, sizetype,
   11272             :                                            size, size_one_node));
   11273      510909 :       TYPE_DEPENDENT_P (itype) = 1;
   11274      510909 :       TYPE_DEPENDENT_P_VALID (itype) = 1;
   11275      510909 :       SET_TYPE_STRUCTURAL_EQUALITY (itype);
   11276      510909 :       return itype;
   11277             :     }
   11278             : 
   11279     1332865 :   if (TREE_CODE (size) != INTEGER_CST)
   11280             :     {
   11281        1843 :       tree folded = cp_fully_fold (size);
   11282        1843 :       if (TREE_CODE (folded) == INTEGER_CST)
   11283             :         {
   11284         147 :           if (name)
   11285          39 :             pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
   11286             :                      "integral constant-expression", name);
   11287             :           else
   11288         108 :             pedwarn (loc, OPT_Wpedantic,
   11289             :                      "size of array is not an integral constant-expression");
   11290             :         }
   11291        1843 :       if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
   11292             :         /* We might have lost the TREE_CONSTANT flag e.g. when we are
   11293             :            folding a conversion from a pointer to integral type.  In that
   11294             :            case issue an error below and don't treat this as a VLA.  */;
   11295             :       else
   11296             :         /* Use the folded result for VLAs, too; it will have resolved
   11297             :            SIZEOF_EXPR.  */
   11298             :         size = folded;
   11299             :     }
   11300             : 
   11301             :   /* Normally, the array-bound will be a constant.  */
   11302     1332865 :   if (TREE_CODE (size) == INTEGER_CST)
   11303             :     {
   11304             :       /* The size to use in diagnostics that reflects the constant
   11305             :          size used in the source, rather than SIZE massaged above.  */
   11306     1331169 :       tree diagsize = size;
   11307             : 
   11308             :       /* If the original size before conversion to size_t was signed
   11309             :          and negative, convert it to ssizetype to restore the sign.  */
   11310     1331169 :       if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
   11311             :           && TREE_CODE (size) == INTEGER_CST
   11312     1331169 :           && tree_int_cst_sign_bit (size))
   11313             :         {
   11314         160 :           diagsize = fold_convert (ssizetype, size);
   11315             : 
   11316             :           /* Clear the overflow bit that may have been set as a result
   11317             :              of the conversion from the sizetype of the new size to
   11318             :              ssizetype.  */
   11319         160 :           TREE_OVERFLOW (diagsize) = false;
   11320             :         }
   11321             : 
   11322             :       /* Verify that the array has a positive number of elements
   11323             :          and issue the appropriate diagnostic if it doesn't.  */
   11324     1331169 :       if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
   11325             :         {
   11326         463 :           if (!(complain & tf_error))
   11327          11 :             return error_mark_node;
   11328         452 :           size = integer_one_node;
   11329             :         }
   11330             :       /* As an extension we allow zero-sized arrays.  */
   11331     1330706 :       else if (integer_zerop (size))
   11332             :         {
   11333        3052 :           if (!(complain & tf_error))
   11334             :             /* We must fail if performing argument deduction (as
   11335             :                indicated by the state of complain), so that
   11336             :                another substitution can be found.  */
   11337           8 :             return error_mark_node;
   11338        3044 :           else if (name)
   11339        2953 :             pedwarn (loc, OPT_Wpedantic,
   11340             :                      "ISO C++ forbids zero-size array %qD", name);
   11341             :           else
   11342          91 :             pedwarn (loc, OPT_Wpedantic,
   11343             :                      "ISO C++ forbids zero-size array");
   11344             :         }
   11345             :     }
   11346        1696 :   else if (TREE_CONSTANT (size)
   11347             :            /* We don't allow VLAs at non-function scopes, or during
   11348             :               tentative template substitution.  */
   11349        1683 :            || !at_function_scope_p ()
   11350        3236 :            || !(complain & tf_error))
   11351             :     {
   11352         156 :       if (!(complain & tf_error))
   11353         101 :         return error_mark_node;
   11354             :       /* `(int) &fn' is not a valid array bound.  */
   11355          55 :       if (name)
   11356          44 :         error_at (loc,
   11357             :                   "size of array %qD is not an integral constant-expression",
   11358             :                   name);
   11359             :       else
   11360          11 :         error_at (loc, "size of array is not an integral constant-expression");
   11361          55 :       size = integer_one_node;
   11362             :     }
   11363        1540 :   else if (pedantic && warn_vla != 0)
   11364             :     {
   11365          39 :       if (name)
   11366          19 :         pedwarn (name_loc, OPT_Wvla,
   11367             :                  "ISO C++ forbids variable length array %qD", name);
   11368             :       else
   11369          20 :         pedwarn (input_location, OPT_Wvla,
   11370             :                  "ISO C++ forbids variable length array");
   11371             :     }
   11372        1501 :   else if (warn_vla > 0)
   11373             :     {
   11374           4 :       if (name)
   11375           4 :         warning_at (name_loc, OPT_Wvla, 
   11376             :                     "variable length array %qD is used", name);
   11377             :       else
   11378           0 :         warning (OPT_Wvla, 
   11379             :                  "variable length array is used");
   11380             :     }
   11381             : 
   11382     1332745 :   if (processing_template_decl && !TREE_CONSTANT (size))
   11383          69 :     goto in_template;
   11384             :   else
   11385             :     {
   11386     1332676 :       if (!TREE_CONSTANT (size))
   11387             :         {
   11388             :           /* A variable sized array.  Arrange for the SAVE_EXPR on the inside
   11389             :              of the MINUS_EXPR, which allows the -1 to get folded with the +1
   11390             :              that happens when building TYPE_SIZE.  */
   11391        1471 :           size = variable_size (size);
   11392        1471 :           stabilize_vla_size (size);
   11393             :         }
   11394             : 
   11395             :       /* Compute the index of the largest element in the array.  It is
   11396             :          one less than the number of elements in the array.  We save
   11397             :          and restore PROCESSING_TEMPLATE_DECL so that computations in
   11398             :          cp_build_binary_op will be appropriately folded.  */
   11399     1332676 :       {
   11400     1332676 :         processing_template_decl_sentinel s;
   11401     1332676 :         itype = cp_build_binary_op (input_location,
   11402             :                                     MINUS_EXPR,
   11403             :                                     cp_convert (ssizetype, size, complain),
   11404             :                                     cp_convert (ssizetype, integer_one_node,
   11405             :                                                 complain),
   11406             :                                     complain);
   11407     1332676 :         itype = maybe_constant_value (itype, NULL_TREE, mce_true);
   11408     1332676 :       }
   11409             : 
   11410     1332676 :       if (!TREE_CONSTANT (itype))
   11411             :         {
   11412        1471 :           if (sanitize_flags_p (SANITIZE_VLA)
   11413        1471 :               && current_function_decl != NULL_TREE)
   11414             :             {
   11415             :               /* We have to add 1 -- in the ubsan routine we generate
   11416             :                  LE_EXPR rather than LT_EXPR.  */
   11417          92 :               tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
   11418             :                                     build_one_cst (TREE_TYPE (itype)));
   11419          92 :               t = ubsan_instrument_vla (input_location, t);
   11420          92 :               finish_expr_stmt (t);
   11421             :             }
   11422             :         }
   11423             :       /* Make sure that there was no overflow when creating to a signed
   11424             :          index type.  (For example, on a 32-bit machine, an array with
   11425             :          size 2^32 - 1 is too big.)  */
   11426     1331205 :       else if (TREE_CODE (itype) == INTEGER_CST
   11427     1331205 :                && TREE_OVERFLOW (itype))
   11428             :         {
   11429           0 :           if (!(complain & tf_error))
   11430           0 :             return error_mark_node;
   11431           0 :           error ("overflow in array dimension");
   11432           0 :           TREE_OVERFLOW (itype) = 0;
   11433             :         }
   11434             :     }
   11435             : 
   11436             :   /* Create and return the appropriate index type.  */
   11437     1332676 :   itype = build_index_type (itype);
   11438             : 
   11439             :   /* If the index type were dependent, we would have returned early, so
   11440             :      remember that it isn't.  */
   11441     1332676 :   TYPE_DEPENDENT_P (itype) = 0;
   11442     1332676 :   TYPE_DEPENDENT_P_VALID (itype) = 1;
   11443     1332676 :   return itype;
   11444             : }
   11445             : 
   11446             : tree
   11447       94671 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   11448             : {
   11449       94671 :   return compute_array_index_type_loc (input_location, name, size, complain);
   11450             : }
   11451             : 
   11452             : /* Returns the scope (if any) in which the entity declared by
   11453             :    DECLARATOR will be located.  If the entity was declared with an
   11454             :    unqualified name, NULL_TREE is returned.  */
   11455             : 
   11456             : tree
   11457   456772037 : get_scope_of_declarator (const cp_declarator *declarator)
   11458             : {
   11459   535027416 :   while (declarator && declarator->kind != cdk_id)
   11460    78255379 :     declarator = declarator->declarator;
   11461             : 
   11462             :   /* If the declarator-id is a SCOPE_REF, the scope in which the
   11463             :      declaration occurs is the first operand.  */
   11464   456772037 :   if (declarator
   11465   455858601 :       && declarator->u.id.qualifying_scope)
   11466             :     return declarator->u.id.qualifying_scope;
   11467             : 
   11468             :   /* Otherwise, the declarator is not a qualified name; the entity will
   11469             :      be declared in the current scope.  */
   11470             :   return NULL_TREE;
   11471             : }
   11472             : 
   11473             : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
   11474             :    indicated TYPE.  If non-NULL, NAME is the NAME of the declaration
   11475             :    with this type.  */
   11476             : 
   11477             : static tree
   11478     2338426 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
   11479             : {
   11480     2338426 :   tree itype = NULL_TREE;
   11481             : 
   11482             :   /* If things have already gone awry, bail now.  */
   11483     2338426 :   if (type == error_mark_node || size == error_mark_node)
   11484             :     return error_mark_node;
   11485             : 
   11486             :   /* [dcl.type.class.deduct] prohibits forming an array of placeholder
   11487             :      for a deduced class type.  */
   11488     2338350 :   if (template_placeholder_p (type))
   11489             :     {
   11490           4 :       if (name)
   11491           0 :         error_at (loc, "%qD declared as array of template placeholder "
   11492             :                   "type %qT", name, type);
   11493             :       else
   11494           4 :         error ("creating array of template placeholder type %qT", type);
   11495           4 :       return error_mark_node;
   11496             :     }
   11497             : 
   11498             :   /* If there are some types which cannot be array elements,
   11499             :      issue an error-message and return.  */
   11500     2338346 :   switch (TREE_CODE (type))
   11501             :     {
   11502           4 :     case VOID_TYPE:
   11503           4 :       if (name)
   11504           0 :         error_at (loc, "declaration of %qD as array of void", name);
   11505             :       else
   11506           4 :         error ("creating array of void");
   11507           4 :       return error_mark_node;
   11508             : 
   11509           4 :     case FUNCTION_TYPE:
   11510           4 :       if (name)
   11511           4 :         error_at (loc, "declaration of %qD as array of functions", name);
   11512             :       else
   11513           0 :         error ("creating array of functions");
   11514           4 :       return error_mark_node;
   11515             : 
   11516          27 :     case REFERENCE_TYPE:
   11517          27 :       if (name)
   11518          19 :         error_at (loc, "declaration of %qD as array of references", name);
   11519             :       else
   11520           8 :         error ("creating array of references");
   11521          27 :       return error_mark_node;
   11522             : 
   11523           0 :     case METHOD_TYPE:
   11524           0 :       if (name)
   11525           0 :         error_at (loc, "declaration of %qD as array of function members",
   11526             :                   name);
   11527             :       else
   11528           0 :         error ("creating array of function members");
   11529           0 :       return error_mark_node;
   11530             : 
   11531     2338311 :     default:
   11532     2338311 :       break;
   11533             :     }
   11534             : 
   11535     2338311 :   if (!verify_type_context (name ? loc : input_location,
   11536             :                             TCTX_ARRAY_ELEMENT, type))
   11537           0 :     return error_mark_node;
   11538             : 
   11539             :   /* [dcl.array]
   11540             : 
   11541             :      The constant expressions that specify the bounds of the arrays
   11542             :      can be omitted only for the first member of the sequence.  */
   11543     2338311 :   if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
   11544             :     {
   11545          40 :       if (name)
   11546          32 :         error_at (loc, "declaration of %qD as multidimensional array must "
   11547             :                   "have bounds for all dimensions except the first",
   11548             :                   name);
   11549             :       else
   11550           8 :         error ("multidimensional array must have bounds for all "
   11551             :                "dimensions except the first");
   11552             : 
   11553          40 :       return error_mark_node;
   11554             :     }
   11555             : 
   11556             :   /* Figure out the index type for the array.  */
   11557     2338271 :   if (size)
   11558             :     {
   11559     1749068 :       itype = compute_array_index_type_loc (loc, name, size,
   11560             :                                             tf_warning_or_error);
   11561     1749068 :       if (type_uses_auto (type)
   11562     1749068 :           && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
   11563             :         {
   11564           9 :           sorry_at (loc, "variable-length array of %<auto%>");
   11565           9 :           return error_mark_node;
   11566             :         }
   11567             :     }
   11568             : 
   11569     2338262 :   return build_cplus_array_type (type, itype);
   11570             : }
   11571             : 
   11572             : /* Returns the smallest location that is not UNKNOWN_LOCATION.  */
   11573             : 
   11574             : static location_t
   11575   607245898 : min_location (location_t loca, location_t locb)
   11576             : {
   11577   607245898 :   if (loca == UNKNOWN_LOCATION
   11578   607245898 :       || (locb != UNKNOWN_LOCATION
   11579    68114429 :           && linemap_location_before_p (line_table, locb, loca)))
   11580   539993332 :     return locb;
   11581             :   return loca;
   11582             : }
   11583             : 
   11584             : /* Returns the smallest location != UNKNOWN_LOCATION among the
   11585             :    three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
   11586             :    and LOCATIONS[ds_restrict].  */
   11587             : 
   11588             : static location_t
   11589   606108223 : smallest_type_quals_location (int type_quals, const location_t* locations)
   11590             : {
   11591   606108223 :   location_t loc = UNKNOWN_LOCATION;
   11592             : 
   11593   606108223 :   if (type_quals & TYPE_QUAL_CONST)
   11594    67128746 :     loc = locations[ds_const];
   11595             : 
   11596   606108223 :   if (type_quals & TYPE_QUAL_VOLATILE)
   11597     1137556 :     loc = min_location (loc, locations[ds_volatile]);
   11598             : 
   11599   606108223 :   if (type_quals & TYPE_QUAL_RESTRICT)
   11600          51 :     loc = min_location (loc, locations[ds_restrict]);
   11601             : 
   11602   606108223 :   return loc;
   11603             : }
   11604             : 
   11605             : /* Returns the smallest among the latter and locations[ds_type_spec].  */
   11606             : 
   11607             : static location_t
   11608   606108199 : smallest_type_location (int type_quals, const location_t* locations)
   11609             : {
   11610   606108199 :   location_t loc = smallest_type_quals_location (type_quals, locations);
   11611   606108199 :   return min_location (loc, locations[ds_type_spec]);
   11612             : }
   11613             : 
   11614             : static location_t
   11615          31 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
   11616             : {
   11617          31 :   int type_quals = get_type_quals (declspecs);
   11618          31 :   return smallest_type_location (type_quals, declspecs->locations);
   11619             : }
   11620             : 
   11621             : /* Check that it's OK to declare a function with the indicated TYPE
   11622             :    and TYPE_QUALS.  SFK indicates the kind of special function (if any)
   11623             :    that this function is.  OPTYPE is the type given in a conversion
   11624             :    operator declaration, or the class type for a constructor/destructor.
   11625             :    Returns the actual return type of the function; that may be different
   11626             :    than TYPE if an error occurs, or for certain special functions.  */
   11627             : 
   11628             : static tree
   11629    17270887 : check_special_function_return_type (special_function_kind sfk,
   11630             :                                     tree type,
   11631             :                                     tree optype,
   11632             :                                     int type_quals,
   11633             :                                     const location_t* locations)
   11634             : {
   11635    17270887 :   switch (sfk)
   11636             :     {
   11637    14376646 :     case sfk_constructor:
   11638    14376646 :       if (type)
   11639          32 :         error_at (smallest_type_location (type_quals, locations),
   11640             :                   "return type specification for constructor invalid");
   11641    14376614 :       else if (type_quals != TYPE_UNQUALIFIED)
   11642          20 :         error_at (smallest_type_quals_location (type_quals, locations),
   11643             :                   "qualifiers are not allowed on constructor declaration");
   11644             : 
   11645    14376646 :       if (targetm.cxx.cdtor_returns_this ())
   11646           0 :         type = build_pointer_type (optype);
   11647             :       else
   11648    14376646 :         type = void_type_node;
   11649             :       break;
   11650             : 
   11651     2029216 :     case sfk_destructor:
   11652     2029216 :       if (type)
   11653          28 :         error_at (smallest_type_location (type_quals, locations),
   11654             :                   "return type specification for destructor invalid");
   11655     2029188 :       else if (type_quals != TYPE_UNQUALIFIED)
   11656           0 :         error_at (smallest_type_quals_location (type_quals, locations),
   11657             :                   "qualifiers are not allowed on destructor declaration");
   11658             : 
   11659             :       /* We can't use the proper return type here because we run into
   11660             :          problems with ambiguous bases and covariant returns.  */
   11661     2029216 :       if (targetm.cxx.cdtor_returns_this ())
   11662           0 :         type = build_pointer_type (void_type_node);
   11663             :       else
   11664     2029216 :         type = void_type_node;
   11665             :       break;
   11666             : 
   11667      312968 :     case sfk_conversion:
   11668      312968 :       if (type)
   11669          36 :         error_at (smallest_type_location (type_quals, locations),
   11670             :                   "return type specified for %<operator %T%>", optype);
   11671      312932 :       else if (type_quals != TYPE_UNQUALIFIED)
   11672           4 :         error_at (smallest_type_quals_location (type_quals, locations),
   11673             :                   "qualifiers are not allowed on declaration of "
   11674             :                   "%<operator %T%>", optype);
   11675             : 
   11676             :       type = optype;
   11677             :       break;
   11678             : 
   11679      552057 :     case sfk_deduction_guide:
   11680      552057 :       if (type)
   11681           0 :         error_at (smallest_type_location (type_quals, locations),
   11682             :                   "return type specified for deduction guide");
   11683      552057 :       else if (type_quals != TYPE_UNQUALIFIED)
   11684           0 :         error_at (smallest_type_quals_location (type_quals, locations),
   11685             :                   "qualifiers are not allowed on declaration of "
   11686             :                   "deduction guide");
   11687      552057 :       if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
   11688             :         {
   11689           2 :           error ("template template parameter %qT in declaration of "
   11690             :                  "deduction guide", optype);
   11691           2 :           type = error_mark_node;
   11692             :         }
   11693             :       else
   11694      552055 :         type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
   11695    14353482 :       for (int i = 0; i < ds_last; ++i)
   11696    13801425 :         if (i != ds_explicit && locations[i])
   11697           2 :           error_at (locations[i],
   11698             :                     "%<decl-specifier%> in declaration of deduction guide");
   11699             :       break;
   11700             : 
   11701           0 :     default:
   11702           0 :       gcc_unreachable ();
   11703             :     }
   11704             : 
   11705    17270887 :   return type;
   11706             : }
   11707             : 
   11708             : /* A variable or data member (whose unqualified name is IDENTIFIER)
   11709             :    has been declared with the indicated TYPE.  If the TYPE is not
   11710             :    acceptable, issue an error message and return a type to use for
   11711             :    error-recovery purposes.  */
   11712             : 
   11713             : tree
   11714   182335960 : check_var_type (tree identifier, tree type, location_t loc)
   11715             : {
   11716   182335960 :   if (VOID_TYPE_P (type))
   11717             :     {
   11718         100 :       if (!identifier)
   11719           0 :         error_at (loc, "unnamed variable or field declared void");
   11720         100 :       else if (identifier_p (identifier))
   11721             :         {
   11722         100 :           gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
   11723         100 :           error_at (loc, "variable or field %qE declared void",
   11724             :                     identifier);
   11725             :         }
   11726             :       else
   11727           0 :         error_at (loc, "variable or field declared void");
   11728         100 :       type = error_mark_node;
   11729             :     }
   11730             : 
   11731   182335960 :   return type;
   11732             : }
   11733             : 
   11734             : /* Handle declaring DECL as an inline variable.  */
   11735             : 
   11736             : static void
   11737     2313287 : mark_inline_variable (tree decl, location_t loc)
   11738             : {
   11739     2313287 :   bool inlinep = true;
   11740     2313287 :   if (! toplevel_bindings_p ())
   11741             :     {
   11742           6 :       error_at (loc, "%<inline%> specifier invalid for variable "
   11743             :                 "%qD declared at block scope", decl);
   11744           6 :       inlinep = false;
   11745             :     }
   11746     2313281 :   else if (cxx_dialect < cxx17)
   11747          60 :     pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
   11748             :              "with %<-std=c++17%> or %<-std=gnu++17%>");
   11749          66 :   if (inlinep)
   11750             :     {
   11751     2313281 :       retrofit_lang_decl (decl);
   11752     2313281 :       SET_DECL_VAR_DECLARED_INLINE_P (decl);
   11753             :     }
   11754     2313287 : }
   11755             : 
   11756             : 
   11757             : /* Assign a typedef-given name to a class or enumeration type declared
   11758             :    as anonymous at first.  This was split out of grokdeclarator
   11759             :    because it is also used in libcc1.  */
   11760             : 
   11761             : void
   11762      287292 : name_unnamed_type (tree type, tree decl)
   11763             : {
   11764      861876 :   gcc_assert (TYPE_UNNAMED_P (type));
   11765             : 
   11766             :   /* Replace the anonymous decl with the real decl.  Be careful not to
   11767             :      rename other typedefs (such as the self-reference) of type.  */
   11768      287292 :   tree orig = TYPE_NAME (type);
   11769      860272 :   for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
   11770      572980 :     if (TYPE_NAME (t) == orig)
   11771      287292 :       TYPE_NAME (t) = decl;
   11772             : 
   11773             :   /* If this is a typedef within a template class, the nested
   11774             :      type is a (non-primary) template.  The name for the
   11775             :      template needs updating as well.  */
   11776      287292 :   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
   11777          63 :     DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
   11778             : 
   11779             :   /* Adjust linkage now that we aren't unnamed anymore.  */
   11780      287292 :   reset_type_linkage (type);
   11781             : 
   11782             :   /* FIXME remangle member functions; member functions of a
   11783             :      type with external linkage have external linkage.  */
   11784             : 
   11785             :   /* Check that our job is done, and that it would fail if we
   11786             :      attempted to do it again.  */
   11787      574584 :   gcc_assert (!TYPE_UNNAMED_P (type));
   11788      287292 : }
   11789             : 
   11790             : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
   11791             :    is allowed.  TYPE might contain a decltype(auto).  Returns true if
   11792             :    there was a problem, false otherwise.  */
   11793             : 
   11794             : static bool
   11795   387152200 : check_decltype_auto (location_t loc, tree type)
   11796             : {
   11797   387152200 :   if (tree a = type_uses_auto (type))
   11798             :     {
   11799     4050632 :       if (AUTO_IS_DECLTYPE (a))
   11800             :         {
   11801      156564 :           if (a != type)
   11802             :             {
   11803          33 :               error_at (loc, "%qT as type rather than plain "
   11804             :                         "%<decltype(auto)%>", type);
   11805          33 :               return true;
   11806             :             }
   11807      156531 :           else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
   11808             :             {
   11809          35 :               error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
   11810          35 :               return true;
   11811             :             }
   11812             :         }
   11813             :     }
   11814             :   return false;
   11815             : }
   11816             : 
   11817             : /* Given declspecs and a declarator (abstract or otherwise), determine
   11818             :    the name and type of the object declared and construct a DECL node
   11819             :    for it.
   11820             : 
   11821             :    DECLSPECS points to the representation of declaration-specifier
   11822             :    sequence that precedes declarator.
   11823             : 
   11824             :    DECL_CONTEXT says which syntactic context this declaration is in:
   11825             :      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
   11826             :      FUNCDEF for a function definition.  Like NORMAL but a few different
   11827             :       error messages in each case.  Return value may be zero meaning
   11828             :       this definition is too screwy to try to parse.
   11829             :      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
   11830             :       handle member functions (which have FIELD context).
   11831             :       Return value may be zero meaning this definition is too screwy to
   11832             :       try to parse.
   11833             :      PARM for a parameter declaration (either within a function prototype
   11834             :       or before a function body).  Make a PARM_DECL, or return void_type_node.
   11835             :      TPARM for a template parameter declaration.
   11836             :      CATCHPARM for a parameter declaration before a catch clause.
   11837             :      TYPENAME if for a typename (in a cast or sizeof).
   11838             :       Don't make a DECL node; just return the ..._TYPE node.
   11839             :      FIELD for a struct or union field; make a FIELD_DECL.
   11840             :      BITFIELD for a field with specified width.
   11841             : 
   11842             :    INITIALIZED is as for start_decl.
   11843             : 
   11844             :    ATTRLIST is a pointer to the list of attributes, which may be NULL
   11845             :    if there are none; *ATTRLIST may be modified if attributes from inside
   11846             :    the declarator should be applied to the declaration.
   11847             : 
   11848             :    When this function is called, scoping variables (such as
   11849             :    CURRENT_CLASS_TYPE) should reflect the scope in which the
   11850             :    declaration occurs, not the scope in which the new declaration will
   11851             :    be placed.  For example, on:
   11852             : 
   11853             :      void S::f() { ... }
   11854             : 
   11855             :    when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
   11856             :    should not be `S'.
   11857             : 
   11858             :    Returns a DECL (if a declarator is present), a TYPE (if there is no
   11859             :    declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
   11860             :    error occurs. */
   11861             : 
   11862             : tree
   11863   606108072 : grokdeclarator (const cp_declarator *declarator,
   11864             :                 cp_decl_specifier_seq *declspecs,
   11865             :                 enum decl_context decl_context,
   11866             :                 int initialized,
   11867             :                 tree* attrlist)
   11868             : {
   11869   606108072 :   tree type = NULL_TREE;
   11870   606108072 :   int longlong = 0;
   11871   606108072 :   int explicit_intN = 0;
   11872   606108072 :   int int_n_alt = 0;
   11873   606108072 :   int virtualp, explicitp, friendp, inlinep, staticp;
   11874   606108072 :   int explicit_int = 0;
   11875   606108072 :   int explicit_char = 0;
   11876   606108072 :   int defaulted_int = 0;
   11877             : 
   11878   606108072 :   tree typedef_decl = NULL_TREE;
   11879   606108072 :   const char *name = NULL;
   11880   606108072 :   tree typedef_type = NULL_TREE;
   11881             :   /* True if this declarator is a function definition.  */
   11882   606108072 :   bool funcdef_flag = false;
   11883   606108072 :   cp_declarator_kind innermost_code = cdk_error;
   11884   606108072 :   int bitfield = 0;
   11885             : #if 0
   11886             :   /* See the code below that used this.  */
   11887             :   tree decl_attr = NULL_TREE;
   11888             : #endif
   11889             : 
   11890             :   /* Keep track of what sort of function is being processed
   11891             :      so that we can warn about default return values, or explicit
   11892             :      return values which do not match prescribed defaults.  */
   11893   606108072 :   special_function_kind sfk = sfk_none;
   11894             : 
   11895   606108072 :   tree dname = NULL_TREE;
   11896   606108072 :   tree ctor_return_type = NULL_TREE;
   11897   606108072 :   enum overload_flags flags = NO_SPECIAL;
   11898             :   /* cv-qualifiers that apply to the declarator, for a declaration of
   11899             :      a member function.  */
   11900   606108072 :   cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
   11901             :   /* virt-specifiers that apply to the declarator, for a declaration of
   11902             :      a member function.  */
   11903   606108072 :   cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
   11904             :   /* ref-qualifier that applies to the declarator, for a declaration of
   11905             :      a member function.  */
   11906   606108072 :   cp_ref_qualifier rqual = REF_QUAL_NONE;
   11907             :   /* cv-qualifiers that apply to the type specified by the DECLSPECS.  */
   11908   606108072 :   int type_quals = get_type_quals (declspecs);
   11909   606108072 :   tree raises = NULL_TREE;
   11910   606108072 :   int template_count = 0;
   11911   606108072 :   tree returned_attrs = NULL_TREE;
   11912   606108072 :   tree parms = NULL_TREE;
   11913   606108072 :   const cp_declarator *id_declarator;
   11914             :   /* The unqualified name of the declarator; either an
   11915             :      IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR.  */
   11916   606108072 :   tree unqualified_id;
   11917             :   /* The class type, if any, in which this entity is located,
   11918             :      or NULL_TREE if none.  Note that this value may be different from
   11919             :      the current class type; for example if an attempt is made to declare
   11920             :      "A::f" inside "B", this value will be "A".  */
   11921   606108072 :   tree ctype = current_class_type;
   11922             :   /* The NAMESPACE_DECL for the namespace in which this entity is
   11923             :      located.  If an unqualified name is used to declare the entity,
   11924             :      this value will be NULL_TREE, even if the entity is located at
   11925             :      namespace scope.  */
   11926   606108072 :   tree in_namespace = NULL_TREE;
   11927   606108072 :   cp_storage_class storage_class;
   11928   606108072 :   bool unsigned_p, signed_p, short_p, long_p, thread_p;
   11929   606108072 :   bool type_was_error_mark_node = false;
   11930   606108072 :   bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
   11931   606108072 :   bool template_type_arg = false;
   11932   606108072 :   bool template_parm_flag = false;
   11933   606108072 :   bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
   11934   606108072 :   bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
   11935   606108072 :   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   11936   606108072 :   bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
   11937   606108072 :   bool late_return_type_p = false;
   11938   606108072 :   bool array_parameter_p = false;
   11939   606108072 :   tree reqs = NULL_TREE;
   11940             : 
   11941   606108072 :   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
   11942   606108072 :   unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
   11943   606108072 :   short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
   11944   606108072 :   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   11945   606108072 :   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   11946   606108072 :   explicit_intN = declspecs->explicit_intN_p;
   11947   606108072 :   int_n_alt = declspecs->int_n_alt;
   11948   606108072 :   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
   11949             : 
   11950             :   // Was concept_p specified? Note that ds_concept
   11951             :   // implies ds_constexpr!
   11952   606108072 :   bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
   11953   606108072 :   if (concept_p)
   11954         283 :     constexpr_p = true;
   11955             : 
   11956   606108072 :   if (decl_context == FUNCDEF)
   11957             :     funcdef_flag = true, decl_context = NORMAL;
   11958   578777721 :   else if (decl_context == MEMFUNCDEF)
   11959             :     funcdef_flag = true, decl_context = FIELD;
   11960   535455775 :   else if (decl_context == BITFIELD)
   11961             :     bitfield = 1, decl_context = FIELD;
   11962   535211723 :   else if (decl_context == TEMPLATE_TYPE_ARG)
   11963             :     template_type_arg = true, decl_context = TYPENAME;
   11964   349083130 :   else if (decl_context == TPARM)
   11965     8588355 :     template_parm_flag = true, decl_context = PARM;
   11966             : 
   11967   606108072 :   if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
   11968     5846728 :     funcdef_flag = true;
   11969             : 
   11970   606108072 :   location_t typespec_loc = loc_or_input_loc (smallest_type_location
   11971             :                                               (type_quals,
   11972   606108072 :                                                declspecs->locations));
   11973   606108072 :   location_t id_loc;
   11974   606108072 :   location_t init_loc;
   11975   606108072 :   if (declarator)
   11976             :     {
   11977   379579116 :       id_loc = loc_or_input_loc (declarator->id_loc);
   11978   379579116 :       init_loc = loc_or_input_loc (declarator->init_loc);
   11979             :     }
   11980             :   else
   11981   226528956 :     init_loc = id_loc = input_location;
   11982             : 
   11983             :   /* Look inside a declarator for the name being declared
   11984             :      and get it as a string, for an error message.  */
   11985   606108072 :   for (id_declarator = declarator;
   11986   845715901 :        id_declarator;
   11987   239607829 :        id_declarator = id_declarator->declarator)
   11988             :     {
   11989   594543896 :       if (id_declarator->kind != cdk_id)
   11990   239607862 :         innermost_code = id_declarator->kind;
   11991             : 
   11992   594543896 :       switch (id_declarator->kind)
   11993             :         {
   11994   116383336 :         case cdk_function:
   11995   116383336 :           if (id_declarator->declarator
   11996   116009044 :               && id_declarator->declarator->kind == cdk_id)
   11997             :             {
   11998   114602189 :               sfk = id_declarator->declarator->u.id.sfk;
   11999   114602189 :               if (sfk == sfk_destructor)
   12000     2029220 :                 flags = DTOR_FLAG;
   12001             :             }
   12002             :           break;
   12003             : 
   12004   354936034 :         case cdk_id:
   12005   354936034 :           {
   12006   354936034 :             tree qualifying_scope = id_declarator->u.id.qualifying_scope;
   12007   354936034 :             tree decl = id_declarator->u.id.unqualified_name;
   12008   354936034 :             if (!decl)
   12009             :               break;
   12010   354936034 :             if (qualifying_scope)
   12011             :               {
   12012     6805338 :                 if (check_for_bare_parameter_packs (qualifying_scope,
   12013     6805338 :                                                     id_declarator->id_loc))
   12014           6 :                   return error_mark_node;
   12015     6805332 :                 if (at_function_scope_p ())
   12016             :                   {
   12017             :                     /* [dcl.meaning] 
   12018             : 
   12019             :                        A declarator-id shall not be qualified except
   12020             :                        for ... 
   12021             : 
   12022             :                        None of the cases are permitted in block
   12023             :                        scope.  */
   12024           0 :                     if (qualifying_scope == global_namespace)
   12025           0 :                       error ("invalid use of qualified-name %<::%D%>",
   12026             :                              decl);
   12027           0 :                     else if (TYPE_P (qualifying_scope))
   12028           0 :                       error ("invalid use of qualified-name %<%T::%D%>",
   12029             :                              qualifying_scope, decl);
   12030             :                     else 
   12031           0 :                       error ("invalid use of qualified-name %<%D::%D%>",
   12032             :                              qualifying_scope, decl);
   12033           0 :                     return error_mark_node;
   12034             :                   }
   12035     6805332 :                 else if (TYPE_P (qualifying_scope))
   12036             :                   {
   12037     6744304 :                     ctype = qualifying_scope;
   12038     6744304 :                     if (!MAYBE_CLASS_TYPE_P (ctype))
   12039             :                       {
   12040           7 :                         error_at (id_declarator->id_loc,
   12041             :                                   "%q#T is not a class or namespace", ctype);
   12042           7 :                         ctype = NULL_TREE;
   12043             :                       }
   12044     6744297 :                     else if (innermost_code != cdk_function
   12045      271087 :                              && current_class_type
   12046     6744316 :                              && !uniquely_derived_from_p (ctype,
   12047             :                                                           current_class_type))
   12048             :                       {
   12049          11 :                         error_at (id_declarator->id_loc,
   12050             :                                   "invalid use of qualified-name %<%T::%D%>",
   12051             :                                   qualifying_scope, decl);
   12052          11 :                         return error_mark_node;
   12053             :                       }
   12054             :                   }
   12055       61028 :                 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
   12056   354936017 :                   in_namespace = qualifying_scope;
   12057             :               }
   12058   354936017 :             switch (TREE_CODE (decl))
   12059             :               {
   12060     2029240 :               case BIT_NOT_EXPR:
   12061     2029240 :                 {
   12062     2029240 :                   if (innermost_code != cdk_function)
   12063             :                     {
   12064           8 :                       error_at (EXPR_LOCATION (decl),
   12065             :                                 "declaration of %qE as non-function", decl);
   12066           8 :                       return error_mark_node;
   12067             :                     }
   12068     2029232 :                   else if (!qualifying_scope
   12069     2029232 :                            && !(current_class_type && at_class_scope_p ()))
   12070             :                     {
   12071          12 :                       error_at (EXPR_LOCATION (decl),
   12072             :                                 "declaration of %qE as non-member", decl);
   12073          12 :                       return error_mark_node;
   12074             :                     }
   12075             : 
   12076     2029220 :                   tree type = TREE_OPERAND (decl, 0);
   12077     2029220 :                   if (TYPE_P (type))
   12078     2029216 :                     type = constructor_name (type);
   12079     2029220 :                   name = identifier_to_locale (IDENTIFIER_POINTER (type));
   12080     2029220 :                   dname = decl;
   12081             :                 }
   12082     2029220 :                 break;
   12083             : 
   12084     1109794 :               case TEMPLATE_ID_EXPR:
   12085     1109794 :                 {
   12086     1109794 :                   tree fns = TREE_OPERAND (decl, 0);
   12087             : 
   12088     1109794 :                   dname = fns;
   12089     1720912 :                   if (!identifier_p (dname))
   12090     1109783 :                     dname = OVL_NAME (dname);
   12091             :                 }
   12092             :                 /* Fall through.  */
   12093             : 
   12094   352906777 :               case IDENTIFIER_NODE:
   12095   352906777 :                 if (identifier_p (decl))
   12096             :                   dname = decl;
   12097             : 
   12098   352906777 :                 if (IDENTIFIER_KEYWORD_P (dname))
   12099             :                   {
   12100           0 :                     error ("declarator-id missing; using reserved word %qD",
   12101             :                            dname);
   12102           0 :                     name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12103             :                   }
   12104   352906777 :                 else if (!IDENTIFIER_CONV_OP_P (dname))
   12105   352593806 :                   name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12106             :                 else
   12107             :                   {
   12108      312971 :                     gcc_assert (flags == NO_SPECIAL);
   12109      312971 :                     flags = TYPENAME_FLAG;
   12110      312971 :                     sfk = sfk_conversion;
   12111      312971 :                     tree glob = get_global_binding (dname);
   12112      312971 :                     if (glob && TREE_CODE (glob) == TYPE_DECL)
   12113           0 :                       name = identifier_to_locale (IDENTIFIER_POINTER (dname));
   12114             :                     else
   12115             :                       name = "<invalid operator>";
   12116             :                   }
   12117             :                 break;
   12118             : 
   12119           0 :               default:
   12120           0 :                 gcc_unreachable ();
   12121             :               }
   12122             :             break;
   12123             :           }
   12124             : 
   12125             :         case cdk_array:
   12126             :         case cdk_pointer:
   12127             :         case cdk_reference:
   12128             :         case cdk_ptrmem:
   12129             :           break;
   12130             : 
   12131             :         case cdk_decomp:
   12132   594543826 :           name = "structured binding";
   12133             :           break;
   12134             : 
   12135          33 :         case cdk_error:
   12136          33 :           return error_mark_node;
   12137             : 
   12138           0 :         default:
   12139           0 :           gcc_unreachable ();
   12140             :         }
   12141   594543826 :       if (id_declarator->kind == cdk_id)
   12142             :         break;
   12143             :     }
   12144             : 
   12145             :   /* [dcl.fct.edf]
   12146             : 
   12147             :      The declarator in a function-definition shall have the form
   12148             :      D1 ( parameter-declaration-clause) ...  */
   12149   606108002 :   if (funcdef_flag && innermost_code != cdk_function)
   12150             :     {
   12151           4 :       error_at (id_loc, "function definition does not declare parameters");
   12152           4 :       return error_mark_node;
   12153             :     }
   12154             : 
   12155   606107998 :   if (flags == TYPENAME_FLAG
   12156   606107998 :       && innermost_code != cdk_function
   12157           3 :       && ! (ctype && !declspecs->any_specifiers_p))
   12158             :     {
   12159           3 :       error_at (id_loc, "declaration of %qD as non-function", dname);
   12160           3 :       return error_mark_node;
   12161             :     }
   12162             : 
   12163   606107995 :   if (dname && identifier_p (dname))
   12164             :     {
   12165   352906770 :       if (UDLIT_OPER_P (dname)
   12166   352906770 :           && innermost_code != cdk_function)
   12167             :         {
   12168           6 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   12169           6 :           return error_mark_node;
   12170             :         }
   12171             : 
   12172   352906764 :       if (IDENTIFIER_ANY_OP_P (dname))
   12173             :         {
   12174    20145848 :           if (typedef_p)
   12175             :             {
   12176           4 :               error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
   12177           4 :               return error_mark_node;
   12178             :             }
   12179    20145844 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   12180             :             {
   12181          20 :               error_at (id_loc, "declaration of %qD as parameter", dname);
   12182          20 :               return error_mark_node;
   12183             :             }
   12184             :         }
   12185             :     }
   12186             : 
   12187             :   /* Anything declared one level down from the top level
   12188             :      must be one of the parameters of a function
   12189             :      (because the body is at least two levels down).  */
   12190             : 
   12191             :   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
   12192             :      by not allowing C++ class definitions to specify their parameters
   12193             :      with xdecls (must be spec.d in the parmlist).
   12194             : 
   12195             :      Since we now wait to push a class scope until we are sure that
   12196             :      we are in a legitimate method context, we must set oldcname
   12197             :      explicitly (since current_class_name is not yet alive).
   12198             : 
   12199             :      We also want to avoid calling this a PARM if it is in a namespace.  */
   12200             : 
   12201   606107965 :   if (decl_context == NORMAL && !toplevel_bindings_p ())
   12202             :     {
   12203    40208730 :       cp_binding_level *b = current_binding_level;
   12204    40208730 :       current_binding_level = b->level_chain;
   12205    40208730 :       if (current_binding_level != 0 && toplevel_bindings_p ())
   12206             :         decl_context = PARM;
   12207    40208730 :       current_binding_level = b;
   12208             :     }
   12209             : 
   12210   606107965 :   if (name == NULL)
   12211   251158935 :     name = decl_context == PARM ? "parameter" : "type name";
   12212             : 
   12213   606107965 :   if (consteval_p && constexpr_p)
   12214             :     {
   12215           2 :       error_at (declspecs->locations[ds_consteval],
   12216             :                 "both %qs and %qs specified", "constexpr", "consteval");
   12217           2 :       return error_mark_node;
   12218             :     }
   12219             : 
   12220   606107963 :   if (concept_p && typedef_p)
   12221             :     {
   12222           3 :       error_at (declspecs->locations[ds_concept],
   12223             :                 "%qs cannot appear in a typedef declaration", "concept");
   12224           3 :       return error_mark_node;
   12225             :     }
   12226             : 
   12227   606107960 :   if (constexpr_p && typedef_p)
   12228             :     {
   12229           3 :       error_at (declspecs->locations[ds_constexpr],
   12230             :                 "%qs cannot appear in a typedef declaration", "constexpr");
   12231           3 :       return error_mark_node;
   12232             :     }
   12233             : 
   12234   606107957 :   if (consteval_p && typedef_p)
   12235             :     {
   12236           1 :       error_at (declspecs->locations[ds_consteval],
   12237             :                 "%qs cannot appear in a typedef declaration", "consteval");
   12238           1 :       return error_mark_node;
   12239             :     }
   12240             : 
   12241   606107956 :   if (constinit_p && typedef_p)
   12242             :     {
   12243           1 :       error_at (declspecs->locations[ds_constinit],
   12244             :                 "%qs cannot appear in a typedef declaration", "constinit");
   12245           1 :       return error_mark_node;
   12246             :     }
   12247             : 
   12248             :   /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
   12249             :      keywords shall appear in a decl-specifier-seq."  */
   12250   606107955 :   if (constinit_p && constexpr_p)
   12251             :     {
   12252           2 :       gcc_rich_location richloc (declspecs->locations[ds_constinit]);
   12253           2 :       richloc.add_range (declspecs->locations[ds_constexpr]);
   12254           2 :       error_at (&richloc,
   12255             :                 "can use at most one of the %<constinit%> and %<constexpr%> "
   12256             :                 "specifiers");
   12257           2 :       return error_mark_node;
   12258           2 :     }
   12259             : 
   12260             :   /* If there were multiple types specified in the decl-specifier-seq,
   12261             :      issue an error message.  */
   12262   606107953 :   if (declspecs->multiple_types_p)
   12263             :     {
   12264        1975 :       error_at (typespec_loc,
   12265             :                 "two or more data types in declaration of %qs", name);
   12266        1975 :       return error_mark_node;
   12267             :     }
   12268             : 
   12269   606105978 :   if (declspecs->conflicting_specifiers_p)
   12270          38 :     return error_mark_node;
   12271             : 
   12272             :   /* Extract the basic type from the decl-specifier-seq.  */
   12273   606105940 :   type = declspecs->type;
   12274   606105940 :   if (type == error_mark_node)
   12275             :     {
   12276        1047 :       type = NULL_TREE;
   12277        1047 :       type_was_error_mark_node = true;
   12278             :     }
   12279             : 
   12280             :   /* Ignore erroneous attributes.  */
   12281   606105940 :   if (attrlist && *attrlist == error_mark_node)
   12282          12 :     *attrlist = NULL_TREE;
   12283             : 
   12284             :   /* An object declared as __attribute__((unavailable)) suppresses
   12285             :      any reports of being declared with unavailable or deprecated
   12286             :      items.  An object declared as __attribute__((deprecated))
   12287             :      suppresses warnings of uses of other deprecated items.  */
   12288   606105940 :   auto ds = make_temp_override (deprecated_state);
   12289   606105940 :   if (attrlist && lookup_attribute ("unavailable", *attrlist))
   12290         194 :     deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
   12291   606105746 :   else if (attrlist && lookup_attribute ("deprecated", *attrlist))
   12292      461167 :     deprecated_state = DEPRECATED_SUPPRESS;
   12293             : 
   12294   606105940 :   cp_handle_deprecated_or_unavailable (type);
   12295   606105940 :   if (type && TREE_CODE (type) == TYPE_DECL)
   12296             :     {
   12297   416655500 :       cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
   12298   416655500 :       typedef_decl = type;
   12299   416655500 :       type = TREE_TYPE (typedef_decl);
   12300   416655500 :       if (DECL_ARTIFICIAL (typedef_decl))
   12301   299067906 :         cp_handle_deprecated_or_unavailable (type);
   12302             :     }
   12303             :   /* No type at all: default to `int', and set DEFAULTED_INT
   12304             :      because it was not a user-defined typedef.  */
   12305   606105940 :   if (type == NULL_TREE)
   12306             :     {
   12307    23197665 :       if (signed_p || unsigned_p || long_p || short_p)
   12308             :         {
   12309             :           /* These imply 'int'.  */
   12310     5925338 :           type = integer_type_node;
   12311     5925338 :           defaulted_int = 1;
   12312             :         }
   12313             :       /* If we just have "complex", it is equivalent to "complex double".  */
   12314    17272327 :       else if (!longlong && !explicit_intN
   12315    17272327 :                && decl_spec_seq_has_spec_p (declspecs, ds_complex))
   12316             :         {
   12317          68 :           type = double_type_node;
   12318          68 :           pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
   12319             :                    "ISO C++ does not support plain %<complex%> meaning "
   12320             :                    "%<double complex%>");
   12321             :         }
   12322             :     }
   12323             :   /* Gather flags.  */
   12324   606105940 :   explicit_int = declspecs->explicit_int_p;
   12325   606105940 :   explicit_char = declspecs->explicit_char_p;
   12326             : 
   12327             : #if 0
   12328             :   /* See the code below that used this.  */
   12329             :   if (typedef_decl)
   12330             :     decl_attr = DECL_ATTRIBUTES (typedef_decl);
   12331             : #endif
   12332   606105940 :   typedef_type = type;
   12333             : 
   12334   606105940 :   if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
   12335      865025 :     ctor_return_type = TREE_TYPE (dname);
   12336             :   else
   12337             :     ctor_return_type = ctype;
   12338             : 
   12339   606105940 :   if (sfk != sfk_none)
   12340             :     {
   12341    17270887 :       type = check_special_function_return_type (sfk, type,
   12342             :                                                  ctor_return_type,
   12343             :                                                  type_quals,
   12344             :                                                  declspecs->locations);
   12345    17270887 :       type_quals = TYPE_UNQUALIFIED;
   12346             :     }
   12347   588835053 :   else if (type == NULL_TREE)
   12348             :     {
   12349        1468 :       int is_main;
   12350             : 
   12351        1468 :       explicit_int = -1;
   12352             : 
   12353             :       /* We handle `main' specially here, because 'main () { }' is so
   12354             :          common.  With no options, it is allowed.  With -Wreturn-type,
   12355             :          it is a warning.  It is only an error with -pedantic-errors.  */
   12356        2936 :       is_main = (funcdef_flag
   12357        3196 :                  && dname && identifier_p (dname)
   12358         260 :                  && MAIN_NAME_P (dname)
   12359          86 :                  && ctype == NULL_TREE
   12360          86 :                  && in_namespace == NULL_TREE
   12361        1554 :                  && current_namespace == global_namespace);
   12362             : 
   12363        1468 :       if (type_was_error_mark_node)
   12364             :         /* We've already issued an error, don't complain more.  */;
   12365         421 :       else if (in_system_header_at (id_loc) || flag_ms_extensions)
   12366             :         /* Allow it, sigh.  */;
   12367         351 :       else if (! is_main)
   12368         271 :         permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
   12369             :                    name);
   12370          80 :       else if (pedantic)
   12371           5 :         pedwarn (id_loc, OPT_Wpedantic,
   12372             :                  "ISO C++ forbids declaration of %qs with no type", name);
   12373             :       else
   12374          75 :         warning_at (id_loc, OPT_Wreturn_type,
   12375             :                     "ISO C++ forbids declaration of %qs with no type", name);
   12376             : 
   12377        1468 :       if (type_was_error_mark_node && template_parm_flag)
   12378             :         /* FIXME we should be able to propagate the error_mark_node as is
   12379             :            for other contexts too.  */
   12380         120 :         type = error_mark_node;
   12381             :       else
   12382        1348 :         type = integer_type_node;
   12383             :     }
   12384             : 
   12385   606105940 :   ctype = NULL_TREE;
   12386             : 
   12387   606105940 :   if (explicit_intN)
   12388             :     {
   12389      623815 :       if (! int_n_enabled_p[declspecs->int_n_idx])
   12390             :         {
   12391           0 :           error_at (declspecs->locations[ds_type_spec],
   12392             :                     "%<__int%d%> is not supported by this target",
   12393           0 :                     int_n_data[declspecs->int_n_idx].bitsize);
   12394           0 :           explicit_intN = false;
   12395             :         }
   12396             :       /* Don't pedwarn if the alternate "__intN__" form has been used instead
   12397             :          of "__intN".  */
   12398      623815 :       else if (!int_n_alt && pedantic)
   12399        2959 :         pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
   12400             :                  "ISO C++ does not support %<__int%d%> for %qs",
   12401        2959 :                  int_n_data[declspecs->int_n_idx].bitsize, name);
   12402             :     }
   12403             : 
   12404             :   /* Now process the modifiers that were specified
   12405             :      and check for invalid combinations.  */
   12406             : 
   12407             :   /* Long double is a special combination.  */
   12408   606105940 :   if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
   12409             :     {
   12410     6222287 :       long_p = false;
   12411     6222287 :       type = cp_build_qualified_type (long_double_type_node,
   12412             :                                       cp_type_quals (type));
   12413             :     }
   12414             : 
   12415             :   /* Check all other uses of type modifiers.  */
   12416             : 
   12417   606105940 :   if (unsigned_p || signed_p || long_p || short_p)
   12418             :     {
   12419    13378075 :       location_t loc;
   12420    13378075 :       const char *key;
   12421    13378075 :       if (unsigned_p)
   12422             :         {
   12423     8969675 :           key = "unsigned";
   12424     8969675 :           loc = declspecs->locations[ds_unsigned];
   12425             :         }
   12426     4408400 :       else if (signed_p)
   12427             :         {
   12428      787478 :           key = "signed";
   12429      787478 :           loc = declspecs->locations[ds_signed];
   12430             :         }
   12431     3620922 :       else if (longlong)
   12432             :         {
   12433     1119595 :           key = "long long";
   12434     1119595 :           loc = declspecs->locations[ds_long_long];
   12435             :         }
   12436     2501327 :       else if (long_p)
   12437             :         {
   12438     2132302 :           key = "long";
   12439     2132302 :           loc = declspecs->locations[ds_long];
   12440             :         }
   12441             :       else /* if (short_p) */
   12442             :         {
   12443      369025 :           key = "short";
   12444      369025 :           loc = declspecs->locations[ds_short];
   12445             :         }
   12446             : 
   12447    13378075 :       int ok = 0;
   12448             : 
   12449    13378075 :       if (signed_p && unsigned_p)
   12450             :         {
   12451          72 :           gcc_rich_location richloc (declspecs->locations[ds_signed]);
   12452          72 :           richloc.add_range (declspecs->locations[ds_unsigned]);
   12453          72 :           error_at (&richloc,
   12454             :                     "%<signed%> and %<unsigned%> specified together");
   12455          72 :         }
   12456    13378003 :       else if (long_p && short_p)
   12457             :         {
   12458           8 :           gcc_rich_location richloc (declspecs->locations[ds_long]);
   12459           8 :           richloc.add_range (declspecs->locations[ds_short]);
   12460           8 :           error_at (&richloc, "%<long%> and %<short%> specified together");
   12461           8 :         }
   12462    13377995 :       else if (TREE_CODE (type) != INTEGER_TYPE
   12463    13377978 :                || type == char8_type_node
   12464    13377946 :                || type == char16_type_node
   12465    13377922 :                || type == char32_type_node
   12466    13377898 :                || ((long_p || short_p)
   12467     7227247 :                    && (explicit_char || explicit_intN)))
   12468         541 :         error_at (loc, "%qs specified with %qT", key, type);
   12469    13377454 :       else if (!explicit_int && !defaulted_int
   12470    13377454 :                && !explicit_char && !explicit_intN)
   12471             :         {
   12472          32 :           if (typedef_decl)
   12473             :             {
   12474          28 :               pedwarn (loc, OPT_Wpedantic,
   12475             :                        "%qs specified with typedef-name %qD",
   12476             :                        key, typedef_decl);
   12477          28 :               ok = !flag_pedantic_errors;
   12478             :               /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
   12479             :                  and is not built as a typedef.  */
   12480          28 :               if (is_typedef_decl (typedef_decl))
   12481          19 :                 type = DECL_ORIGINAL_TYPE (typedef_decl);
   12482             :             }
   12483           4 :           else if (declspecs->decltype_p)
   12484           0 :             error_at (loc, "%qs specified with %<decltype%>", key);
   12485             :           else
   12486           4 :             error_at (loc, "%qs specified with %<typeof%>", key);
   12487             :         }
   12488             :       else
   12489             :         ok = 1;
   12490             : 
   12491             :       /* Discard the type modifiers if they are invalid.  */
   12492         653 :       if (! ok)
   12493             :         {
   12494             :           unsigned_p = false;
   12495             :           signed_p = false;
   12496             :           long_p = false;
   12497             :           short_p = false;
   12498             :           longlong = 0;
   12499             :         }
   12500             :     }
   12501             : 
   12502             :   /* Decide whether an integer type is signed or not.
   12503             :      Optionally treat bitfields as signed by default.  */
   12504   606105940 :   if (unsigned_p
   12505             :       /* [class.bit]
   12506             : 
   12507             :          It is implementation-defined whether a plain (neither
   12508             :          explicitly signed or unsigned) char, short, int, or long
   12509             :          bit-field is signed or unsigned.
   12510             : 
   12511             :          Naturally, we extend this to long long as well.  Note that
   12512             :          this does not include wchar_t.  */
   12513   606105940 :       || (bitfield && !flag_signed_bitfields
   12514          22 :           && !signed_p
   12515             :           /* A typedef for plain `int' without `signed' can be
   12516             :              controlled just like plain `int', but a typedef for
   12517             :              `signed int' cannot be so controlled.  */
   12518          22 :           && !(typedef_decl
   12519          22 :                && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
   12520          16 :           && TREE_CODE (type) == INTEGER_TYPE
   12521          12 :           && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
   12522             :     {
   12523     8969393 :       if (explicit_intN)
   12524      291288 :         type = int_n_trees[declspecs->int_n_idx].unsigned_type;
   12525     8678105 :       else if (longlong)
   12526     1018792 :         type = long_long_unsigned_type_node;
   12527     7659313 :       else if (long_p)
   12528     1518079 :         type = long_unsigned_type_node;
   12529     6141234 :       else if (short_p)
   12530      881078 :         type = short_unsigned_type_node;
   12531     5260156 :       else if (type == char_type_node)
   12532     1030670 :         type = unsigned_char_type_node;
   12533     4229486 :       else if (typedef_decl)
   12534          28 :         type = c_common_unsigned_type (type);
   12535             :       else
   12536     4229458 :         type = unsigned_type_node;
   12537             :     }
   12538   597136547 :   else if (signed_p && type == char_type_node)
   12539      484720 :     type = signed_char_type_node;
   12540   596651827 :   else if (explicit_intN)
   12541      332527 :     type = int_n_trees[declspecs->int_n_idx].signed_type;
   12542   596319300 :   else if (longlong)
   12543     1176327 :     type = long_long_integer_type_node;
   12544   595142973 :   else if (long_p)
   12545     2196139 :     type = long_integer_type_node;
   12546   592946834 :   else if (short_p)
   12547      436388 :     type = short_integer_type_node;
   12548   592510446 :   else if (signed_p && typedef_decl)
   12549           9 :     type = c_common_signed_type (type);
   12550             : 
   12551   606105940 :   if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
   12552             :     {
   12553      789481 :       if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
   12554           4 :         error_at (declspecs->locations[ds_complex],
   12555             :                   "complex invalid for %qs", name);
   12556             :       /* If a modifier is specified, the resulting complex is the complex
   12557             :          form of TYPE.  E.g, "complex short" is "complex short int".  */
   12558      789477 :       else if (type == integer_type_node)
   12559         182 :         type = complex_integer_type_node;
   12560      789295 :       else if (type == float_type_node)
   12561      256968 :         type = complex_float_type_node;
   12562      532327 :       else if (type == double_type_node)
   12563      257496 :         type = complex_double_type_node;
   12564      274831 :       else if (type == long_double_type_node)
   12565      257002 :         type = complex_long_double_type_node;
   12566             :       else
   12567       17829 :         type = build_complex_type (type);
   12568             :     }
   12569             : 
   12570             :   /* If we're using the injected-class-name to form a compound type or a
   12571             :      declaration, replace it with the underlying class so we don't get
   12572             :      redundant typedefs in the debug output.  But if we are returning the
   12573             :      type unchanged, leave it alone so that it's available to
   12574             :      maybe_get_template_decl_from_type_decl.  */
   12575   121482940 :   if (CLASS_TYPE_P (type)
   12576   121451353 :       && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
   12577    17453316 :       && type == TREE_TYPE (TYPE_NAME (type))
   12578   623559256 :       && (declarator || type_quals))
   12579    16879761 :     type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
   12580             : 
   12581   606105940 :   type_quals |= cp_type_quals (type);
   12582  1212211880 :   type = cp_build_qualified_type
   12583  1212211880 :     (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
   12584   488518346 :                           || declspecs->decltype_p)
   12585             :                          ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
   12586             :   /* We might have ignored or rejected some of the qualifiers.  */
   12587   606105940 :   type_quals = cp_type_quals (type);
   12588             : 
   12589   586665670 :   if (cxx_dialect >= cxx17 && type && is_auto (type)
   12590     5967079 :       && innermost_code != cdk_function
   12591             :       /* Placeholder in parm gets a better error below.  */
   12592     3526488 :       && !(decl_context == PARM || decl_context == CATCHPARM)
   12593   609632014 :       && id_declarator && declarator != id_declarator)
   12594      516482 :     if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
   12595             :       {
   12596          12 :         auto_diagnostic_group g;
   12597          12 :         gcc_rich_location richloc (typespec_loc);
   12598          12 :         richloc.add_fixit_insert_after ("<>");
   12599          12 :         error_at (&richloc, "missing template argument list after %qE; "
   12600             :                   "for deduction, template placeholder must be followed "
   12601             :                   "by a simple declarator-id", tmpl);
   12602          12 :         inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
   12603          12 :         type = error_mark_node;
   12604          12 :       }
   12605             : 
   12606   606105940 :   staticp = 0;
   12607   606105940 :   inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
   12608   606105940 :   virtualp =  decl_spec_seq_has_spec_p (declspecs, ds_virtual);
   12609   606105940 :   explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
   12610             : 
   12611   606105940 :   storage_class = declspecs->storage_class;
   12612   606105940 :   if (storage_class == sc_static)
   12613    12744723 :     staticp = 1 + (decl_context == FIELD);
   12614   593361217 :   else if (decl_context == FIELD && sfk == sfk_deduction_guide)
   12615             :     /* Treat class-scope deduction guides as static member functions
   12616             :        so that they get a FUNCTION_TYPE instead of a METHOD_TYPE.  */
   12617    12199231 :     staticp = 2;
   12618             : 
   12619   606105940 :   if (virtualp)
   12620             :     {
   12621     2826462 :       if (staticp == 2)
   12622             :         {
   12623          27 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   12624          27 :           richloc.add_range (declspecs->locations[ds_storage_class]);
   12625          27 :           error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
   12626             :                     "and %<static%>", dname);
   12627          27 :           storage_class = sc_none;
   12628          27 :           staticp = 0;
   12629          27 :         }
   12630     2826462 :       if (constexpr_p && pedantic && cxx_dialect < cxx20)
   12631             :         {
   12632           6 :           gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   12633           6 :           richloc.add_range (declspecs->locations[ds_constexpr]);
   12634           6 :           pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
   12635             :                    "declared both %<virtual%> and %<constexpr%> only in "
   12636             :                    "%<-std=c++20%> or %<-std=gnu++20%>", dname);
   12637           6 :         }
   12638             :     }
   12639   606105940 :   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   12640             : 
   12641             :   /* Issue errors about use of storage classes for parameters.  */
   12642   606105940 :   if (decl_context == PARM)
   12643             :     {
   12644   187840061 :       if (typedef_p)
   12645             :         {
   12646          32 :           error_at (declspecs->locations[ds_typedef],
   12647             :                     "typedef declaration invalid in parameter declaration");
   12648          32 :           return error_mark_node;
   12649             :         }
   12650   187840029 :       else if (template_parm_flag && storage_class != sc_none)
   12651             :         {
   12652          21 :           error_at (min_location (declspecs->locations[ds_thread],
   12653             :                                   declspecs->locations[ds_storage_class]),
   12654             :                     "storage class specified for template parameter %qs",
   12655             :                     name);
   12656          21 :           return error_mark_node;
   12657             :         }
   12658   187840008 :       else if (storage_class == sc_static
   12659   187840008 :                || storage_class == sc_extern
   12660   187840004 :                || thread_p)
   12661             :         {
   12662          12 :           error_at (min_location (declspecs->locations[ds_thread],
   12663             :                                   declspecs->locations[ds_storage_class]),
   12664             :                     "storage class specified for parameter %qs", name);
   12665          12 :           return error_mark_node;
   12666             :         }
   12667             : 
   12668             :       /* Function parameters cannot be concept. */
   12669   187839996 :       if (concept_p)
   12670             :         {
   12671           3 :           error_at (declspecs->locations[ds_concept],
   12672             :                     "a parameter cannot be declared %qs", "concept");
   12673           3 :           concept_p = 0;
   12674           3 :           constexpr_p = 0;
   12675             :         }
   12676             :       /* Function parameters cannot be constexpr.  If we saw one, moan
   12677             :          and pretend it wasn't there.  */
   12678   187839993 :       else if (constexpr_p)
   12679             :         {
   12680           9 :           error_at (declspecs->locations[ds_constexpr],
   12681             :                     "a parameter cannot be declared %qs", "constexpr");
   12682           9 :           constexpr_p = 0;
   12683             :         }
   12684   187839996 :       if (constinit_p)
   12685             :         {
   12686           2 :           error_at (declspecs->locations[ds_constinit],
   12687             :                     "a parameter cannot be declared %qs", "constinit");
   12688           2 :           constinit_p = 0;
   12689             :         }
   12690   187839996 :       if (consteval_p)
   12691             :         {
   12692           1 :           error_at (declspecs->locations[ds_consteval],
   12693             :                     "a parameter cannot be declared %qs", "consteval");
   12694           1 :           consteval_p = 0;
   12695             :         }
   12696             :     }
   12697             : 
   12698             :   /* Give error if `virtual' is used outside of class declaration.  */
   12699   606105875 :   if (virtualp
   12700     2826462 :       && (current_class_name == NULL_TREE || decl_context != FIELD))
   12701             :     {
   12702          21 :       error_at (declspecs->locations[ds_virtual],
   12703             :                 "%<virtual%> outside class declaration");
   12704          21 :       virtualp = 0;
   12705             :     }
   12706             : 
   12707   606105875 :   if (innermost_code == cdk_decomp)
   12708             :     {
   12709       26140 :       location_t loc = (declarator->kind == cdk_reference
   12710       13070 :                         ? declarator->declarator->id_loc : declarator->id_loc);
   12711       13070 :       if (inlinep)
   12712           1 :         error_at (declspecs->locations[ds_inline],
   12713             :                   "structured binding declaration cannot be %qs", "inline");
   12714       13070 :       if (typedef_p)
   12715           1 :         error_at (declspecs->locations[ds_typedef],
   12716             :                   "structured binding declaration cannot be %qs", "typedef");
   12717       13070 :       if (constexpr_p && !concept_p)
   12718           1 :         error_at (declspecs->locations[ds_constexpr], "structured "
   12719             :                   "binding declaration cannot be %qs", "constexpr");
   12720       13070 :       if (consteval_p)
   12721           1 :         error_at (declspecs->locations[ds_consteval], "structured "
   12722             :                   "binding declaration cannot be %qs", "consteval");
   12723       13070 :       if (thread_p && cxx_dialect < cxx20)
   12724          10 :         pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
   12725             :                  "structured binding declaration can be %qs only in "
   12726             :                  "%<-std=c++20%> or %<-std=gnu++20%>",
   12727          10 :                  declspecs->gnu_thread_keyword_p
   12728             :                  ? "__thread" : "thread_local");
   12729       13070 :       if (concept_p)
   12730           0 :         error_at (declspecs->locations[ds_concept],
   12731             :                   "structured binding declaration cannot be %qs", "concept");
   12732             :       /* [dcl.struct.bind] "A cv that includes volatile is deprecated."  */
   12733       13070 :       if (type_quals & TYPE_QUAL_VOLATILE)
   12734          14 :         warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
   12735             :                     "%<volatile%>-qualified structured binding is deprecated");
   12736       13070 :       switch (storage_class)
   12737             :         {
   12738             :         case sc_none:
   12739             :           break;
   12740           0 :         case sc_register:
   12741           0 :           error_at (loc, "structured binding declaration cannot be %qs",
   12742             :                     "register");
   12743           0 :           break;
   12744          25 :         case sc_static:
   12745          25 :           if (cxx_dialect < cxx20)
   12746          17 :             pedwarn (loc, OPT_Wc__20_extensions,
   12747             :                      "structured binding declaration can be %qs only in "
   12748             :                      "%<-std=c++20%> or %<-std=gnu++20%>", "static");
   12749             :           break;
   12750           1 :         case sc_extern:
   12751           1 :           error_at (loc, "structured binding declaration cannot be %qs",
   12752             :                     "extern");
   12753           1 :           break;
   12754           0 :         case sc_mutable:
   12755           0 :           error_at (loc, "structured binding declaration cannot be %qs",
   12756             :                     "mutable");
   12757           0 :           break;
   12758           0 :         case sc_auto:
   12759           0 :           error_at (loc, "structured binding declaration cannot be "
   12760             :                     "C++98 %<auto%>");
   12761           0 :           break;
   12762           0 :         default:
   12763           0 :           gcc_unreachable ();
   12764             :         }
   12765       13070 :       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
   12766       13070 :           || TYPE_IDENTIFIER (type) != auto_identifier)
   12767             :         {
   12768           3 :           if (type != error_mark_node)
   12769             :             {
   12770           3 :               auto_diagnostic_group d;
   12771           3 :               error_at (loc, "structured binding declaration cannot have "
   12772             :                         "type %qT", type);
   12773           3 :               inform (loc,
   12774             :                       "type must be cv-qualified %<auto%> or reference to "
   12775             :                       "cv-qualified %<auto%>");
   12776           3 :             }
   12777           3 :           type = build_qualified_type (make_auto (), type_quals);
   12778           3 :           declspecs->type = type;
   12779             :         }
   12780       13067 :       else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
   12781          17 :         pedwarn (loc, OPT_Wpedantic,
   12782             :                  "structured binding declaration cannot have constrained "
   12783             :                  "%<auto%> type %qT", type);
   12784       13070 :       inlinep = 0;
   12785       13070 :       typedef_p = 0;
   12786       13070 :       constexpr_p = 0;
   12787       13070 :       consteval_p = 0;
   12788       13070 :       concept_p = 0;
   12789       13070 :       if (storage_class != sc_static)
   12790             :         {
   12791       13045 :           storage_class = sc_none;
   12792       13045 :           declspecs->storage_class = sc_none;
   12793             :         }
   12794             :     }
   12795             : 
   12796             :   /* Static anonymous unions are dealt with here.  */
   12797   606105875 :   if (staticp && decl_context == TYPENAME
   12798           0 :       && declspecs->type
   12799   606105875 :       && ANON_AGGR_TYPE_P (declspecs->type))
   12800             :     decl_context = FIELD;
   12801             : 
   12802             :   /* Warn about storage classes that are invalid for certain
   12803             :      kinds of declarations (parameters, typenames, etc.).  */
   12804   606105875 :   if (thread_p
   12805       15058 :       && ((storage_class
   12806       15058 :            && storage_class != sc_extern
   12807         488 :            && storage_class != sc_static)
   12808       15044 :           || typedef_p))
   12809             :     {
   12810          22 :       location_t loc
   12811          22 :         = min_location (declspecs->locations[ds_thread],
   12812             :                         declspecs->locations[ds_storage_class]);
   12813          22 :       error_at (loc, "multiple storage classes in declaration of %qs", name);
   12814          22 :       thread_p = false;
   12815             :     }
   12816   606105875 :   if (decl_context != NORMAL
   12817   502568751 :       && ((storage_class != sc_none
   12818   502568751 :            && storage_class != sc_mutable)
   12819   490369493 :           || thread_p))
   12820             :     {
   12821    12199262 :       if ((decl_context == PARM || decl_context == CATCHPARM)
   12822          54 :           && (storage_class == sc_register
   12823          54 :               || storage_class == sc_auto))
   12824             :         ;
   12825    12199208 :       else if (typedef_p)
   12826             :         ;
   12827    12199208 :       else if (decl_context == FIELD
   12828             :                /* C++ allows static class elements.  */
   12829    12199208 :                && storage_class == sc_static)
   12830             :         /* C++ also allows inlines and signed and unsigned elements,
   12831             :            but in those cases we don't come in here.  */
   12832             :         ;
   12833             :       else
   12834             :         {
   12835          21 :           location_t loc
   12836          21 :             = min_location (declspecs->locations[ds_thread],
   12837             :                             declspecs->locations[ds_storage_class]);
   12838          21 :           if (decl_context == FIELD)
   12839          21 :             error_at (loc, "storage class specified for %qs", name);
   12840           0 :           else if (decl_context == PARM || decl_context == CATCHPARM)
   12841           0 :             error_at (loc, "storage class specified for parameter %qs", name);
   12842             :           else
   12843           0 :             error_at (loc, "storage class specified for typename");
   12844          21 :           if (storage_class == sc_register
   12845          21 :               || storage_class == sc_auto
   12846          21 :               || storage_class == sc_extern
   12847           4 :               || thread_p)
   12848          21 :             storage_class = sc_none;
   12849             :         }
   12850             :     }
   12851   593906613 :   else if (storage_class == sc_extern && funcdef_flag
   12852   593906613 :            && ! toplevel_bindings_p ())
   12853           0 :     error ("nested function %qs declared %<extern%>", name);
   12854   593906613 :   else if (toplevel_bindings_p ())
   12855             :     {
   12856   273872861 :       if (storage_class == sc_auto)
   12857           2 :         error_at (declspecs->locations[ds_storage_class],
   12858             :                   "top-level declaration of %qs specifies %<auto%>", name);
   12859             :     }
   12860   320033752 :   else if (thread_p
   12861   320033752 :            && storage_class != sc_extern
   12862          84 :            && storage_class != sc_static)
   12863             :     {
   12864          55 :       if (declspecs->gnu_thread_keyword_p)
   12865           4 :         pedwarn (declspecs->locations[ds_thread],
   12866             :                  0, "function-scope %qs implicitly auto and "
   12867             :                  "declared %<__thread%>", name);
   12868             : 
   12869             :       /* When thread_local is applied to a variable of block scope the
   12870             :          storage-class-specifier static is implied if it does not appear
   12871             :          explicitly.  */
   12872          55 :       storage_class = declspecs->storage_class = sc_static;
   12873          55 :       staticp = 1;
   12874             :     }
   12875             : 
   12876   606105875 :   if (storage_class && friendp)
   12877             :     {
   12878          16 :       error_at (min_location (declspecs->locations[ds_thread],
   12879             :                               declspecs->locations[ds_storage_class]),
   12880             :                 "storage class specifiers invalid in friend function "
   12881             :                 "declarations");
   12882          16 :       storage_class = sc_none;
   12883          16 :       staticp = 0;
   12884             :     }
   12885             : 
   12886   606105875 :   if (!id_declarator)
   12887             :     unqualified_id = NULL_TREE;
   12888             :   else
   12889             :     {
   12890   354933963 :       unqualified_id = id_declarator->u.id.unqualified_name;
   12891   354933963 :       switch (TREE_CODE (unqualified_id))
   12892             :         {
   12893     2029220 :         case BIT_NOT_EXPR:
   12894     2029220 :           unqualified_id = TREE_OPERAND (unqualified_id, 0);
   12895     2029220 :           if (TYPE_P (unqualified_id))
   12896     2029216 :             unqualified_id = constructor_name (unqualified_id);
   12897             :           break;
   12898             : 
   12899             :         case IDENTIFIER_NODE:
   12900             :         case TEMPLATE_ID_EXPR:
   12901             :           break;
   12902             : 
   12903           0 :         default:
   12904           0 :           gcc_unreachable ();
   12905             :         }
   12906             :     }
   12907             : 
   12908   606105875 :   if (declspecs->std_attributes
   12909   606105875 :       && !diagnose_misapplied_contracts (declspecs->std_attributes))
   12910             :     {
   12911          24 :       location_t attr_loc = declspecs->locations[ds_std_attribute];
   12912          24 :       if (warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
   12913          24 :         inform (attr_loc, "an attribute that appertains to a type-specifier "
   12914             :                 "is ignored");
   12915             :     }
   12916             : 
   12917   606105875 :   if (attrlist)
   12918   597022802 :     diagnose_misapplied_contracts (*attrlist);
   12919             : 
   12920             :   /* Determine the type of the entity declared by recurring on the
   12921             :      declarator.  */
   12922   845698313 :   for (; declarator; declarator = declarator->declarator)
   12923             :     {
   12924   594539497 :       const cp_declarator *inner_declarator;
   12925   594539497 :       tree attrs;
   12926             : 
   12927   594539497 :       if (type == error_mark_node)
   12928         617 :         return error_mark_node;
   12929             : 
   12930   594539140 :       attrs = declarator->attributes;
   12931   594539140 :       if (attrs)
   12932             :         {
   12933       11376 :           int attr_flags;
   12934             : 
   12935       11376 :           attr_flags = 0;
   12936       11376 :           if (declarator->kind == cdk_id)
   12937       10733 :             attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
   12938       11376 :           if (declarator->kind == cdk_function)
   12939         618 :             attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
   12940       11376 :           if (declarator->kind == cdk_array)
   12941           2 :             attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
   12942       11376 :           tree late_attrs = NULL_TREE;
   12943       11376 :           if (decl_context != PARM && decl_context != TYPENAME)
   12944             :             /* Assume that any attributes that get applied late to
   12945             :                templates will DTRT when applied to the declaration
   12946             :                as a whole.  */
   12947       11364 :             late_attrs = splice_template_attributes (&attrs, type);
   12948       11376 :           returned_attrs = decl_attributes (&type,
   12949             :                                             attr_chainon (returned_attrs,
   12950             :                                                           attrs),
   12951             :                                             attr_flags);
   12952       11376 :           returned_attrs = attr_chainon (late_attrs, returned_attrs);
   12953             :         }
   12954             : 
   12955   594539140 :       inner_declarator = declarator->declarator;
   12956             : 
   12957             :       /* Check that contracts aren't misapplied.  */
   12958   594539140 :       if (tree contract_attr = find_contract (declarator->std_attributes))
   12959         470 :         if (declarator->kind != cdk_function
   12960         465 :             || innermost_code != cdk_function)
   12961           7 :           diagnose_misapplied_contracts (contract_attr);
   12962             : 
   12963             :       /* We don't want to warn in parameter context because we don't
   12964             :          yet know if the parse will succeed, and this might turn out
   12965             :          to be a constructor call.  */
   12966   594539140 :       if (decl_context != PARM
   12967   594539140 :           && decl_context != TYPENAME
   12968   337906572 :           && !typedef_p
   12969   307361457 :           && declarator->parenthesized != UNKNOWN_LOCATION
   12970             :           /* If the type is class-like and the inner name used a
   12971             :              global namespace qualifier, we need the parens.
   12972             :              Unfortunately all we can tell is whether a qualified name
   12973             :              was used or not.  */
   12974   594539332 :           && !(inner_declarator
   12975         124 :                && inner_declarator->kind == cdk_id
   12976         103 :                && inner_declarator->u.id.qualifying_scope
   12977          21 :                && (MAYBE_CLASS_TYPE_P (type)
   12978          12 :                    || TREE_CODE (type) == ENUMERAL_TYPE)))
   12979             :         {
   12980         180 :           if (warning_at (declarator->parenthesized, OPT_Wparentheses,
   12981             :                           "unnecessary parentheses in declaration of %qs",
   12982             :                           name))
   12983             :             {
   12984          54 :               gcc_rich_location iloc (declarator->parenthesized);
   12985          54 :               iloc.add_fixit_remove (get_start (declarator->parenthesized));
   12986          54 :               iloc.add_fixit_remove (get_finish (declarator->parenthesized));
   12987          54 :               inform (&iloc, "remove parentheses");
   12988          54 :             }
   12989             :         }
   12990   594539140 :       if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
   12991             :         break;
   12992             : 
   12993   239592698 :       switch (declarator->kind)
   12994             :         {
   12995     2338426 :         case cdk_array:
   12996     4676852 :           type = create_array_type_for_decl (dname, type,
   12997     2338426 :                                              declarator->u.array.bounds,
   12998     2338426 :                                              declarator->id_loc);
   12999     2338426 :           if (!valid_array_size_p (dname
   13000             :                                    ? declarator->id_loc : input_location,
   13001             :                                    type, dname))
   13002         356 :             type = error_mark_node;
   13003             : 
   13004     2338426 :           if (declarator->std_attributes)
   13005             :             /* [dcl.array]/1:
   13006             : 
   13007             :                The optional attribute-specifier-seq appertains to the
   13008             :                array.  */
   13009          22 :             returned_attrs = attr_chainon (returned_attrs,
   13010             :                                            declarator->std_attributes);
   13011             :           break;
   13012             : 
   13013   116383299 :         case cdk_function:
   13014   116383299 :           {
   13015   116383299 :             tree arg_types;
   13016   116383299 :             int funcdecl_p;
   13017             : 
   13018             :             /* Declaring a function type.  */
   13019             : 
   13020             :             /* Pick up type qualifiers which should be applied to `this'.  */
   13021   116383299 :             memfn_quals = declarator->u.function.qualifiers;
   13022             :             /* Pick up virt-specifiers.  */
   13023   116383299 :             virt_specifiers = declarator->u.function.virt_specifiers;
   13024             :             /* And ref-qualifier, too */
   13025   116383299 :             rqual = declarator->u.function.ref_qualifier;
   13026             :             /* And tx-qualifier.  */
   13027   116383299 :             tree tx_qual = declarator->u.function.tx_qualifier;
   13028             :             /* Pick up the exception specifications.  */
   13029   116383299 :             raises = declarator->u.function.exception_specification;
   13030             :             /* If the exception-specification is ill-formed, let's pretend
   13031             :                there wasn't one.  */
   13032   116383299 :             if (raises == error_mark_node)
   13033           9 :               raises = NULL_TREE;
   13034             : 
   13035   116383299 :             if (reqs)
   13036           1 :               error_at (location_of (reqs), "requires-clause on return type");
   13037   116383299 :             reqs = declarator->u.function.requires_clause;
   13038             : 
   13039             :             /* Say it's a definition only for the CALL_EXPR
   13040             :                closest to the identifier.  */
   13041   116383299 :             funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
   13042             : 
   13043             :             /* Handle a late-specified return type.  */
   13044   116383299 :             tree late_return_type = declarator->u.function.late_return_type;
   13045   116383299 :             if (tree auto_node = type_uses_auto (type))
   13046             :               {
   13047     2462077 :                 if (!late_return_type)
   13048             :                   {
   13049      617304 :                     if (!funcdecl_p)
   13050             :                       /* auto (*fp)() = f; is OK.  */;
   13051      617271 :                     else if (current_class_type
   13052     1100627 :                              && LAMBDA_TYPE_P (current_class_type))
   13053             :                       /* OK for C++11 lambdas.  */;
   13054      440888 :                     else if (cxx_dialect < cxx14)
   13055             :                       {
   13056           0 :                         error_at (typespec_loc, "%qs function uses "
   13057             :                                   "%<auto%> type specifier without "
   13058             :                                   "trailing return type", name);
   13059           0 :                         inform (typespec_loc,
   13060             :                                 "deduced return type only available "
   13061             :                                 "with %<-std=c++14%> or %<-std=gnu++14%>");
   13062             :                       }
   13063      440888 :                     else if (virtualp)
   13064             :                       {
   13065           6 :                         error_at (typespec_loc, "virtual function "
   13066             :                                   "cannot have deduced return type");
   13067           6 :                         virtualp = false;
   13068             :                       }
   13069             :                   }
   13070     1844773 :                 else if (!is_auto (type) && sfk != sfk_conversion)
   13071             :                   {
   13072          15 :                     error_at (typespec_loc, "%qs function with trailing "
   13073             :                               "return type has %qT as its type rather "
   13074             :                               "than plain %<auto%>", name, type);
   13075         256 :                     return error_mark_node;
   13076             :                   }
   13077     1844758 :                 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
   13078             :                   {
   13079           9 :                     if (funcdecl_p)
   13080           3 :                       error_at (typespec_loc,
   13081             :                                 "%qs function with trailing return type "
   13082             :                                 "has %<decltype(auto)%> as its type "
   13083             :                                 "rather than plain %<auto%>", name);
   13084             :                     else
   13085           6 :                       error_at (typespec_loc,
   13086             :                                 "invalid use of %<decltype(auto)%>");
   13087           9 :                     return error_mark_node;
   13088             :                   }
   13089     2462053 :                 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
   13090     2462053 :                 if (!tmpl)
   13091     1909992 :                   if (tree late_auto = type_uses_auto (late_return_type))
   13092         504 :                     tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
   13093     1909992 :                 if (tmpl)
   13094             :                   {
   13095      552065 :                     if (!funcdecl_p || !dguide_name_p (unqualified_id))
   13096             :                       {
   13097          10 :                         auto_diagnostic_group g;
   13098          10 :                         error_at (typespec_loc, "deduced class "
   13099             :                                   "type %qD in function return type",
   13100          10 :                                   DECL_NAME (tmpl));
   13101          10 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   13102             :                                 "%qD declared here", tmpl);
   13103          10 :                         return error_mark_node;
   13104          10 :                       }
   13105      552055 :                     else if (!late_return_type)
   13106             :                       {
   13107           2 :                         error_at (declarator->id_loc, "deduction guide "
   13108             :                                   "for %qT must have trailing return "
   13109           2 :                                   "type", TREE_TYPE (tmpl));
   13110           2 :                         inform (DECL_SOURCE_LOCATION (tmpl),
   13111             :                                 "%qD declared here", tmpl);
   13112           2 :                         return error_mark_node;
   13113             :                       }
   13114      552053 :                     else if (CLASS_TYPE_P (late_return_type)
   13115      552053 :                               && CLASSTYPE_TEMPLATE_INFO (late_return_type)
   13116     1104106 :                               && (CLASSTYPE_TI_TEMPLATE (late_return_type)
   13117             :                                   == tmpl))
   13118             :                       /* OK */;
   13119             :                     else
   13120           0 :                       error ("trailing return type %qT of deduction guide "
   13121             :                               "is not a specialization of %qT",
   13122           0 :                               late_return_type, TREE_TYPE (tmpl));
   13123             :                   }
   13124             :               }
   13125   113921222 :             else if (late_return_type
   13126   113921222 :                      && sfk != sfk_conversion)
   13127             :               {
   13128          37 :                 if (late_return_type == error_mark_node)
   13129             :                   return error_mark_node;
   13130          37 :                 if (cxx_dialect < cxx11)
   13131             :                   /* Not using maybe_warn_cpp0x because this should
   13132             :                      always be an error.  */
   13133           1 :                   error_at (typespec_loc,
   13134             :                             "trailing return type only available "
   13135             :                             "with %<-std=c++11%> or %<-std=gnu++11%>");
   13136             :                 else
   13137          36 :                   error_at (typespec_loc, "%qs function with trailing "
   13138             :                             "return type not declared with %<auto%> "
   13139             :                             "type specifier", name);
   13140          37 :                 return error_mark_node;
   13141             :               }
   13142   116383226 :             if (late_return_type && sfk == sfk_conversion)
   13143             :               {
   13144          15 :                 error ("a conversion function cannot have a trailing return type");
   13145          15 :                 return error_mark_node;
   13146             :               }
   13147   116383211 :             type = splice_late_return_type (type, late_return_type);
   13148   116383211 :             if (type == error_mark_node)
   13149          72 :               return error_mark_node;
   13150             : 
   13151   116383139 :             if (late_return_type)
   13152             :               {
   13153     1844664 :                 late_return_type_p = true;
   13154     1844664 :                 type_quals = cp_type_quals (type);
   13155             :               }
   13156             : 
   13157   116383139 :             if (type_quals != TYPE_UNQUALIFIED)
   13158             :               {
   13159             :                 /* It's wrong, for instance, to issue a -Wignored-qualifiers
   13160             :                    warning for
   13161             :                     static_assert(!is_same_v<void(*)(), const void(*)()>);
   13162             :                     because there the qualifier matters.  */
   13163       10051 :                 if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
   13164         271 :                   warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
   13165             :                               "qualifiers ignored on function return type");
   13166             :                 /* [dcl.fct] "A volatile-qualified return type is
   13167             :                    deprecated."  */
   13168       10051 :                 if (type_quals & TYPE_QUAL_VOLATILE)
   13169         726 :                   warning_at (typespec_loc, OPT_Wvolatile,
   13170             :                               "%<volatile%>-qualified return type is "
   13171             :                               "deprecated");
   13172             : 
   13173             :                 /* We now know that the TYPE_QUALS don't apply to the
   13174             :                    decl, but to its return type.  */
   13175             :                 type_quals = TYPE_UNQUALIFIED;
   13176             :               }
   13177             : 
   13178             :             /* Error about some types functions can't return.  */
   13179             : 
   13180   116383139 :             if (TREE_CODE (type) == FUNCTION_TYPE)
   13181             :               {
   13182          36 :                 error_at (typespec_loc, "%qs declared as function returning "
   13183             :                           "a function", name);
   13184          36 :                 return error_mark_node;
   13185             :               }
   13186   116383103 :             if (TREE_CODE (type) == ARRAY_TYPE)
   13187             :               {
   13188           6 :                 error_at (typespec_loc, "%qs declared as function returning "
   13189             :                           "an array", name);
   13190           6 :                 return error_mark_node;
   13191             :               }
   13192   116383097 :             if (constinit_p && funcdecl_p)
   13193             :               {
   13194           5 :                 error_at (declspecs->locations[ds_constinit],
   13195             :                           "%<constinit%> on function return type is not "
   13196             :                           "allowed");
   13197           5 :                 return error_mark_node;
   13198             :               }
   13199             : 
   13200   116383092 :             if (check_decltype_auto (typespec_loc, type))
   13201          49 :               return error_mark_node;
   13202             : 
   13203   116383043 :             if (ctype == NULL_TREE
   13204   116383043 :                 && decl_context == FIELD
   13205             :                 && funcdecl_p
   13206    60312965 :                 && friendp == 0)
   13207    58073344 :               ctype = current_class_type;
   13208             : 
   13209   116383043 :             if (ctype && (sfk == sfk_constructor
   13210    58073344 :                           || sfk == sfk_destructor))
   13211             :               {
   13212             :                 /* We are within a class's scope. If our declarator name
   13213             :                    is the same as the class name, and we are defining
   13214             :                    a function, then it is a constructor/destructor, and
   13215             :                    therefore returns a void type.  */
   13216             : 
   13217             :                 /* ISO C++ 12.4/2.  A destructor may not be declared
   13218             :                    const or volatile.  A destructor may not be static.
   13219             :                    A destructor may not be declared with ref-qualifier.
   13220             : 
   13221             :                    ISO C++ 12.1.  A constructor may not be declared
   13222             :                    const or volatile.  A constructor may not be
   13223             :                    virtual.  A constructor may not be static.
   13224             :                    A constructor may not be declared with ref-qualifier. */
   13225    15719957 :                 if (staticp == 2)
   13226          12 :                   error_at (declspecs->locations[ds_storage_class],
   13227             :                             (flags == DTOR_FLAG)
   13228             :                             ? G_("destructor cannot be static member "
   13229             :                                  "function")
   13230             :                             : G_("constructor cannot be static member "
   13231             :                                  "function"));
   13232    15719957 :                 if (memfn_quals)
   13233             :                   {
   13234          12 :                     error ((flags == DTOR_FLAG)
   13235             :                            ? G_("destructors may not be cv-qualified")
   13236             :                            : G_("constructors may not be cv-qualified"));
   13237          12 :                     memfn_quals = TYPE_UNQUALIFIED;
   13238             :                   }
   13239             : 
   13240    15719957 :                 if (rqual)
   13241             :                   {
   13242           6 :                     maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
   13243           6 :                     error ((flags == DTOR_FLAG)
   13244             :                            ? G_("destructors may not be ref-qualified")
   13245             :                            : G_("constructors may not be ref-qualified"));
   13246           6 :                     rqual = REF_QUAL_NONE;
   13247             :                   }
   13248             : 
   13249    15719957 :                 if (decl_context == FIELD
   13250    15719957 :                     && !member_function_or_else (ctype,
   13251             :                                                  current_class_type,
   13252             :                                                  flags))
   13253           0 :                   return error_mark_node;
   13254             : 
   13255    15719957 :                 if (flags != DTOR_FLAG)
   13256             :                   {
   13257             :                     /* It's a constructor.  */
   13258    13811305 :                     if (explicitp == 1)
   13259     3384110 :                       explicitp = 2;
   13260    13811305 :                     if (virtualp)
   13261             :                       {
   13262           3 :                         permerror (declspecs->locations[ds_virtual],
   13263             :                                    "constructors cannot be declared %<virtual%>");
   13264           3 :                         virtualp = 0;
   13265             :                       }
   13266    13811305 :                     if (decl_context == FIELD
   13267    13811305 :                         && sfk != sfk_constructor)
   13268           0 :                       return error_mark_node;
   13269             :                   }
   13270    15719957 :                 if (decl_context == FIELD)
   13271    15719957 :                   staticp = 0;
   13272             :               }
   13273   100663086 :             else if (friendp)
   13274             :               {
   13275     2022797 :                 if (virtualp)
   13276             :                   {
   13277             :                     /* Cannot be both friend and virtual.  */
   13278          14 :                     gcc_rich_location richloc (declspecs->locations[ds_virtual]);
   13279          14 :                     richloc.add_range (declspecs->locations[ds_friend]);
   13280          14 :                     error_at (&richloc, "virtual functions cannot be friends");
   13281          14 :                     friendp = 0;
   13282          14 :                   }
   13283     2022797 :                 if (decl_context == NORMAL)
   13284           0 :                   error_at (declarator->id_loc,
   13285             :                             "friend declaration not in class definition");
   13286     2022797 :                 if (current_function_decl && funcdef_flag)
   13287             :                   {
   13288          11 :                     error_at (declarator->id_loc,
   13289             :                               "cannot define friend function %qs in a local "
   13290             :                               "class definition", name);
   13291          11 :                     friendp = 0;
   13292             :                   }
   13293             :                 /* [class.friend]/6: A function can be defined in a friend
   13294             :                    declaration if the function name is unqualified.  */
   13295     2022797 :                 if (funcdef_flag && in_namespace)
   13296             :                   {
   13297           8 :                     if (in_namespace == global_namespace)
   13298           4 :                       error_at (declarator->id_loc,
   13299             :                                 "friend function definition %qs cannot have "
   13300             :                                 "a name qualified with %<::%>", name);
   13301             :                     else
   13302           4 :                       error_at (declarator->id_loc,
   13303             :                                 "friend function definition %qs cannot have "
   13304             :                                 "a name qualified with %<%D::%>", name,
   13305             :                                 in_namespace);
   13306             :                   }
   13307             :               }
   13308    98640289 :             else if (ctype && sfk == sfk_conversion)
   13309             :               {
   13310      312539 :                 if (explicitp == 1)
   13311             :                   {
   13312      132075 :                     maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
   13313      132075 :                     explicitp = 2;
   13314             :                   }
   13315             :               }
   13316    98327750 :             else if (sfk == sfk_deduction_guide)
   13317             :               {
   13318      552053 :                 if (explicitp == 1)
   13319   116383043 :                   explicitp = 2;
   13320             :               }
   13321             : 
   13322   116383043 :             tree pushed_scope = NULL_TREE;
   13323   116383043 :             if (funcdecl_p
   13324   116383043 :                 && decl_context != FIELD
   13325    54505799 :                 && inner_declarator->u.id.qualifying_scope
   13326   122857072 :                 && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
   13327     6472775 :               pushed_scope
   13328     6472775 :                 = push_scope (inner_declarator->u.id.qualifying_scope);
   13329             : 
   13330   116383043 :             arg_types = grokparms (declarator->u.function.parameters, &parms);
   13331             : 
   13332   116383043 :             if (pushed_scope)
   13333     6472775 :               pop_scope (pushed_scope);
   13334             : 
   13335   116383043 :             if (inner_declarator
   13336   116008766 :                 && inner_declarator->kind == cdk_id
   13337   114601940 :                 && inner_declarator->u.id.sfk == sfk_destructor
   13338     2029211 :                 && arg_types != void_list_node)
   13339             :               {
   13340          24 :                 error_at (declarator->id_loc,
   13341             :                           "destructors may not have parameters");
   13342          24 :                 arg_types = void_list_node;
   13343          24 :                 parms = NULL_TREE;
   13344             :               }
   13345             : 
   13346   116383043 :             type = build_function_type (type, arg_types);
   13347             : 
   13348   116383043 :             tree attrs = declarator->std_attributes;
   13349   116383043 :             if (tx_qual)
   13350             :               {
   13351         152 :                 tree att = build_tree_list (tx_qual, NULL_TREE);
   13352             :                 /* transaction_safe applies to the type, but
   13353             :                    transaction_safe_dynamic applies to the function.  */
   13354         152 :                 if (is_attribute_p ("transaction_safe", tx_qual))
   13355         121 :                   attrs = attr_chainon (attrs, att);
   13356             :                 else
   13357          31 :                   returned_attrs = attr_chainon (returned_attrs, att);
   13358             :               }
   13359             : 
   13360             :             /* Actually apply the contract attributes to the declaration.  */
   13361   116383841 :             for (tree *p = &attrs; *p;)
   13362             :               {
   13363         798 :                 tree l = *p;
   13364         798 :                 if (cxx_contract_attribute_p (l))
   13365             :                   {
   13366         650 :                     *p = TREE_CHAIN (l);
   13367             :                     /* Intentionally reverse order of contracts so they're
   13368             :                        reversed back into their lexical order.  */
   13369         650 :                     TREE_CHAIN (l) = NULL_TREE;
   13370         650 :                     returned_attrs = chainon (l, returned_attrs);
   13371             :                   }
   13372             :                 else
   13373         148 :                   p = &TREE_CHAIN (l);
   13374             :              }
   13375             : 
   13376   116383043 :             if (attrs)
   13377             :               /* [dcl.fct]/2:
   13378             : 
   13379             :                  The optional attribute-specifier-seq appertains to
   13380             :                  the function type.  */
   13381         148 :               cplus_decl_attributes (&type, attrs, 0);
   13382             : 
   13383   116383043 :             if (raises)
   13384    44270069 :               type = build_exception_variant (type, raises);
   13385             :           }
   13386   116383043 :           break;
   13387             : 
   13388   120870973 :         case cdk_pointer:
   13389   120870973 :         case cdk_reference:
   13390   120870973 :         case cdk_ptrmem:
   13391             :           /* Filter out pointers-to-references and references-to-references.
   13392             :              We can get these if a TYPE_DECL is used.  */
   13393             : 
   13394   120870973 :           if (TYPE_REF_P (type))
   13395             :             {
   13396         236 :               if (declarator->kind != cdk_reference)
   13397             :                 {
   13398           4 :                   error ("cannot declare pointer to %q#T", type);
   13399           4 :                   type = TREE_TYPE (type);
   13400             :                 }
   13401             : 
   13402             :               /* In C++0x, we allow reference to reference declarations
   13403             :                  that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
   13404             :                  and template type arguments [14.3.1/4 temp.arg.type]. The
   13405             :                  check for direct reference to reference declarations, which
   13406             :                  are still forbidden, occurs below. Reasoning behind the change
   13407             :                  can be found in DR106, DR540, and the rvalue reference
   13408             :                  proposals. */
   13409         232 :               else if (cxx_dialect == cxx98)
   13410             :                 {
   13411           0 :                   error ("cannot declare reference to %q#T", type);
   13412           0 :                   type = TREE_TYPE (type);
   13413             :                 }
   13414             :             }
   13415   120870737 :           else if (VOID_TYPE_P (type))
   13416             :             {
   13417     3220949 :               if (declarator->kind == cdk_reference)
   13418           3 :                 error ("cannot declare reference to %q#T", type);
   13419     3220946 :               else if (declarator->kind == cdk_ptrmem)
   13420           4 :                 error ("cannot declare pointer to %q#T member", type);
   13421             :             }
   13422             : 
   13423             :           /* We now know that the TYPE_QUALS don't apply to the decl,
   13424             :              but to the target of the pointer.  */
   13425   120870973 :           type_quals = TYPE_UNQUALIFIED;
   13426             : 
   13427             :           /* This code used to handle METHOD_TYPE, but I don't think it's
   13428             :              possible to get it here anymore.  */
   13429   120870973 :           gcc_assert (TREE_CODE (type) != METHOD_TYPE);
   13430   120870973 :           if (declarator->kind == cdk_ptrmem
   13431      903879 :               && TREE_CODE (type) == FUNCTION_TYPE)
   13432             :             {
   13433      724677 :               memfn_quals |= type_memfn_quals (type);
   13434     1449354 :               type = build_memfn_type (type,
   13435      724677 :                                        declarator->u.pointer.class_type,
   13436             :                                        memfn_quals,
   13437             :                                        rqual);
   13438      724677 :               if (type == error_mark_node)
   13439           4 :                 return error_mark_node;
   13440             : 
   13441             :               rqual = REF_QUAL_NONE;
   13442             :               memfn_quals = TYPE_UNQUALIFIED;
   13443             :             }
   13444             : 
   13445   120870969 :           if (TREE_CODE (type) == FUNCTION_TYPE
   13446   120870969 :               && (type_memfn_quals (type) != TYPE_UNQUALIFIED
   13447      722914 :                   || type_memfn_rqual (type) != REF_QUAL_NONE))
   13448          17 :             error (declarator->kind == cdk_reference
   13449             :                    ? G_("cannot declare reference to qualified function type %qT")
   13450             :                    : G_("cannot declare pointer to qualified function type %qT"),
   13451             :                    type);
   13452             : 
   13453             :           /* When the pointed-to type involves components of variable size,
   13454             :              care must be taken to ensure that the size evaluation code is
   13455             :              emitted early enough to dominate all the possible later uses
   13456             :              and late enough for the variables on which it depends to have
   13457             :              been assigned.
   13458             : 
   13459             :              This is expected to happen automatically when the pointed-to
   13460             :              type has a name/declaration of it's own, but special attention
   13461             :              is required if the type is anonymous.
   13462             : 
   13463             :              We handle the NORMAL and FIELD contexts here by inserting a
   13464             :              dummy statement that just evaluates the size at a safe point
   13465             :              and ensures it is not deferred until e.g. within a deeper
   13466             :              conditional context (c++/43555).
   13467             : 
   13468             :              We expect nothing to be needed here for PARM or TYPENAME.
   13469             :              Evaluating the size at this point for TYPENAME would
   13470             :              actually be incorrect, as we might be in the middle of an
   13471             :              expression with side effects on the pointed-to type size
   13472             :              "arguments" prior to the pointer declaration point and the
   13473             :              size evaluation could end up prior to the side effects.  */
   13474             : 
   13475   120870969 :           if (!TYPE_NAME (type)
   13476     3587717 :               && (decl_context == NORMAL || decl_context == FIELD)
   13477      428176 :               && at_function_scope_p ()
   13478   120902093 :               && variably_modified_type_p (type, NULL_TREE))
   13479             :             {
   13480         111 :               TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
   13481             :                                              NULL_TREE, type);
   13482         111 :               add_decl_expr (TYPE_NAME (type));
   13483             :             }
   13484             : 
   13485   120870969 :           if (declarator->kind == cdk_reference)
   13486             :             {
   13487             :               /* In C++0x, the type we are creating a reference to might be
   13488             :                  a typedef which is itself a reference type. In that case,
   13489             :                  we follow the reference collapsing rules in
   13490             :                  [7.1.3/8 dcl.typedef] to create the final reference type:
   13491             : 
   13492             :                  "If a typedef TD names a type that is a reference to a type
   13493             :                  T, an attempt to create the type 'lvalue reference to cv TD'
   13494             :                  creates the type 'lvalue reference to T,' while an attempt
   13495             :                  to create the type "rvalue reference to cv TD' creates the
   13496             :                  type TD."
   13497             :               */
   13498    77800690 :               if (VOID_TYPE_P (type))
   13499             :                 /* We already gave an error.  */;
   13500    77800687 :               else if (TYPE_REF_P (type))
   13501             :                 {
   13502         232 :                   if (declarator->u.reference.rvalue_ref)
   13503             :                     /* Leave type alone.  */;
   13504             :                   else
   13505         115 :                     type = cp_build_reference_type (TREE_TYPE (type), false);
   13506             :                 }
   13507             :               else
   13508    77800455 :                 type = cp_build_reference_type
   13509    77800455 :                   (type, declarator->u.reference.rvalue_ref);
   13510             : 
   13511             :               /* In C++0x, we need this check for direct reference to
   13512             :                  reference declarations, which are forbidden by
   13513             :                  [8.3.2/5 dcl.ref]. Reference to reference declarations
   13514             :                  are only allowed indirectly through typedefs and template
   13515             :                  type arguments. Example:
   13516             : 
   13517             :                    void foo(int & &);      // invalid ref-to-ref decl
   13518             : 
   13519             :                    typedef int & int_ref;
   13520             :                    void foo(int_ref &);    // valid ref-to-ref decl
   13521             :               */
   13522    77800690 :               if (inner_declarator && inner_declarator->kind == cdk_reference)
   13523           0 :                 error ("cannot declare reference to %q#T, which is not "
   13524             :                        "a typedef or a template type argument", type);
   13525             :             }
   13526    43070279 :           else if (TREE_CODE (type) == METHOD_TYPE)
   13527      724673 :             type = build_ptrmemfunc_type (build_pointer_type (type));
   13528    42345606 :           else if (declarator->kind == cdk_ptrmem)
   13529             :             {
   13530      179202 :               gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
   13531             :                           != NAMESPACE_DECL);
   13532      179202 :               if (declarator->u.pointer.class_type == error_mark_node)
   13533             :                 /* We will already have complained.  */
   13534           4 :                 type = error_mark_node;
   13535             :               else
   13536      179198 :                 type = build_ptrmem_type (declarator->u.pointer.class_type,
   13537             :                                           type);
   13538             :             }
   13539             :           else
   13540    42166404 :             type = build_pointer_type (type);
   13541             : 
   13542             :           /* Process a list of type modifier keywords (such as
   13543             :              const or volatile) that were given inside the `*' or `&'.  */
   13544             : 
   13545   120870969 :           if (declarator->u.pointer.qualifiers)
   13546             :             {
   13547     5587453 :               type
   13548     5587453 :                 = cp_build_qualified_type (type,
   13549             :                                            declarator->u.pointer.qualifiers);
   13550     5587453 :               type_quals = cp_type_quals (type);
   13551             :             }
   13552             : 
   13553             :           /* Apply C++11 attributes to the pointer, and not to the
   13554             :              type pointed to.  This is unlike what is done for GNU
   13555             :              attributes above.  It is to comply with [dcl.ptr]/1:
   13556             : 
   13557             :                  [the optional attribute-specifier-seq (7.6.1) appertains
   13558             :                   to the pointer and not to the object pointed to].  */
   13559   120870969 :           if (declarator->std_attributes)
   13560          12 :             decl_attributes (&type, declarator->std_attributes,
   13561             :                              0);
   13562             : 
   13563             :           ctype = NULL_TREE;
   13564             :           break;
   13565             : 
   13566             :         case cdk_error:
   13567             :           break;
   13568             : 
   13569           0 :         default:
   13570           0 :           gcc_unreachable ();
   13571             :         }
   13572             :     }
   13573             : 
   13574   606105258 :   id_loc = declarator ? declarator->id_loc : input_location;
   13575             : 
   13576   606105258 :   if (innermost_code != cdk_function
   13577             :     /* Don't check this if it can be the artifical decltype(auto)
   13578             :        we created when building a constraint in a compound-requirement:
   13579             :        that the type-constraint is plain is going to be checked in
   13580             :        cp_parser_compound_requirement.  */
   13581   606105258 :       && decl_context != TYPENAME
   13582   606105258 :       && check_decltype_auto (id_loc, type))
   13583          19 :     return error_mark_node;
   13584             : 
   13585             :   /* A `constexpr' specifier used in an object declaration declares
   13586             :      the object as `const'.  */
   13587   606105239 :   if (constexpr_p && innermost_code != cdk_function)
   13588             :     {
   13589             :       /* DR1688 says that a `constexpr' specifier in combination with
   13590             :          `volatile' is valid.  */
   13591             : 
   13592     7963274 :       if (!TYPE_REF_P (type))
   13593             :         {
   13594     7956226 :           type_quals |= TYPE_QUAL_CONST;
   13595     7956226 :           type = cp_build_qualified_type (type, type_quals);
   13596             :         }
   13597             :     }
   13598             : 
   13599   354933356 :   if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
   13600     1109792 :       && !FUNC_OR_METHOD_TYPE_P (type)
   13601   606603905 :       && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
   13602             :     {
   13603           0 :       error ("template-id %qD used as a declarator",
   13604             :              unqualified_id);
   13605           0 :       unqualified_id = dname;
   13606             :     }
   13607             : 
   13608             :   /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
   13609             :      qualified with a class-name, turn it into a METHOD_TYPE, unless
   13610             :      we know that the function is static.  We take advantage of this
   13611             :      opportunity to do other processing that pertains to entities
   13612             :      explicitly declared to be class members.  Note that if DECLARATOR
   13613             :      is non-NULL, we know it is a cdk_id declarator; otherwise, we
   13614             :      would not have exited the loop above.  */
   13615   606105239 :   if (declarator
   13616   354946426 :       && declarator->kind == cdk_id
   13617   354933356 :       && declarator->u.id.qualifying_scope
   13618   619654763 :       && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
   13619             :     {
   13620     6744286 :       ctype = declarator->u.id.qualifying_scope;
   13621     6744286 :       ctype = TYPE_MAIN_VARIANT (ctype);
   13622     6744286 :       template_count = num_template_headers_for_class (ctype);
   13623             : 
   13624     6744286 :       if (ctype == current_class_type)
   13625             :         {
   13626          72 :           if (friendp)
   13627             :             {
   13628          20 :               permerror (declspecs->locations[ds_friend],
   13629             :                          "member functions are implicitly "
   13630             :                          "friends of their class");
   13631          20 :               friendp = 0;
   13632             :             }
   13633             :           else
   13634          52 :             permerror (id_loc, "extra qualification %<%T::%> on member %qs",
   13635             :                        ctype, name);
   13636             :         }
   13637     6744214 :       else if (/* If the qualifying type is already complete, then we
   13638             :                   can skip the following checks.  */
   13639     6744214 :                !COMPLETE_TYPE_P (ctype)
   13640         199 :                && (/* If the function is being defined, then
   13641             :                       qualifying type must certainly be complete.  */
   13642             :                    funcdef_flag
   13643             :                    /* A friend declaration of "T::f" is OK, even if
   13644             :                       "T" is a template parameter.  But, if this
   13645             :                       function is not a friend, the qualifying type
   13646             :                       must be a class.  */
   13647         146 :                    || (!friendp && !CLASS_TYPE_P (ctype))
   13648             :                    /* For a declaration, the type need not be
   13649             :                       complete, if either it is dependent (since there
   13650             :                       is no meaningful definition of complete in that
   13651             :                       case) or the qualifying class is currently being
   13652             :                       defined.  */
   13653         163 :                    || !(dependent_type_p (ctype)
   13654          32 :                         || currently_open_class (ctype)))
   13655             :                /* Check that the qualifying type is complete.  */
   13656     6744302 :                && !complete_type_or_else (ctype, NULL_TREE))
   13657          88 :         return error_mark_node;
   13658     6744126 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   13659             :         {
   13660     6473077 :           if (current_class_type
   13661         338 :               && (!friendp || funcdef_flag || initialized))
   13662             :             {
   13663          74 :               error_at (id_loc, funcdef_flag || initialized
   13664             :                         ? G_("cannot define member function %<%T::%s%> "
   13665             :                              "within %qT")
   13666             :                         : G_("cannot declare member function %<%T::%s%> "
   13667             :                              "within %qT"),
   13668             :                         ctype, name, current_class_type);
   13669          61 :               return error_mark_node;
   13670             :             }
   13671             :         }
   13672      271049 :       else if (typedef_p && current_class_type)
   13673             :         {
   13674           0 :           error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
   13675             :                     ctype, name, current_class_type);
   13676           0 :           return error_mark_node;
   13677             :         }
   13678             :     }
   13679             : 
   13680   606105090 :   if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
   13681    33548854 :     ctype = current_class_type;
   13682             : 
   13683             :   /* Now TYPE has the actual type.  */
   13684             : 
   13685   606105090 :   if (returned_attrs)
   13686             :     {
   13687        3215 :       if (attrlist)
   13688        3215 :         *attrlist = attr_chainon (returned_attrs, *attrlist);
   13689             :       else
   13690             :         attrlist = &returned_attrs;
   13691             :     }
   13692             : 
   13693   606105090 :   if (declarator
   13694   354946277 :       && declarator->kind == cdk_id
   13695   354933207 :       && declarator->std_attributes
   13696       52159 :       && attrlist != NULL)
   13697             :     {
   13698             :       /* [dcl.meaning]/1: The optional attribute-specifier-seq following
   13699             :          a declarator-id appertains to the entity that is declared.  */
   13700       52156 :       if (declarator->std_attributes != error_mark_node)
   13701       52138 :         *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
   13702             :       else
   13703             :         /* We should have already diagnosed the issue (c++/78344).  */
   13704          18 :         gcc_assert (seen_error ());
   13705             :     }
   13706             : 
   13707             :   /* Handle parameter packs. */
   13708   606105090 :   if (parameter_pack_p)
   13709             :     {
   13710     1877224 :       if (decl_context == PARM)
   13711             :         /* Turn the type into a pack expansion.*/
   13712     1877224 :         type = make_pack_expansion (type);
   13713             :       else
   13714           0 :         error ("non-parameter %qs cannot be a parameter pack", name);
   13715             :     }
   13716             : 
   13717   606105090 :   if ((decl_context == FIELD || decl_context == PARM)
   13718   281484866 :       && !processing_template_decl
   13719   697020207 :       && variably_modified_type_p (type, NULL_TREE))
   13720             :     {
   13721          16 :       if (decl_context == FIELD)
   13722           8 :         error_at (id_loc,
   13723             :                   "data member may not have variably modified type %qT", type);
   13724             :       else
   13725           8 :         error_at (id_loc,
   13726             :                   "parameter may not have variably modified type %qT", type);
   13727          16 :       type = error_mark_node;
   13728             :     }
   13729             : 
   13730   606105090 :   if (explicitp == 1 || (explicitp && friendp))
   13731             :     {
   13732             :       /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
   13733             :          in the declaration of a constructor or conversion function within
   13734             :          a class definition.  */
   13735          32 :       if (!current_class_type)
   13736          14 :         error_at (declspecs->locations[ds_explicit],
   13737             :                   "%<explicit%> outside class declaration");
   13738          18 :       else if (friendp)
   13739          15 :         error_at (declspecs->locations[ds_explicit],
   13740             :                   "%<explicit%> in friend declaration");
   13741             :       else
   13742           3 :         error_at (declspecs->locations[ds_explicit],
   13743             :                   "only declarations of constructors and conversion operators "
   13744             :                   "can be %<explicit%>");
   13745             :       explicitp = 0;
   13746             :     }
   13747             : 
   13748   606105090 :   if (storage_class == sc_mutable)
   13749             :     {
   13750      110094 :       location_t sloc = declspecs->locations[ds_storage_class];
   13751      110094 :       if (decl_context != FIELD || friendp)
   13752             :         {
   13753          16 :           error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
   13754             :                     name);
   13755          16 :           storage_class = sc_none;
   13756             :         }
   13757      110078 :       else if (decl_context == TYPENAME || typedef_p)
   13758             :         {
   13759           0 :           error_at (sloc,
   13760             :                     "non-object member %qs cannot be declared %<mutable%>",
   13761             :                     name);
   13762           0 :           storage_class = sc_none;
   13763             :         }
   13764      110078 :       else if (FUNC_OR_METHOD_TYPE_P (type))
   13765             :         {
   13766           4 :           error_at (sloc, "function %qs cannot be declared %<mutable%>",
   13767             :                     name);
   13768           4 :           storage_class = sc_none;
   13769             :         }
   13770      110074 :       else if (staticp)
   13771             :         {
   13772           0 :           error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
   13773             :                     name);
   13774           0 :           storage_class = sc_none;
   13775             :         }
   13776      110074 :       else if (type_quals & TYPE_QUAL_CONST)
   13777             :         {
   13778          12 :           error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
   13779             :                     name);
   13780          12 :           storage_class = sc_none;
   13781             :         }
   13782      110062 :       else if (TYPE_REF_P (type))
   13783             :         {
   13784           8 :           permerror (sloc, "reference %qs cannot be declared %<mutable%>",
   13785             :                      name);
   13786           8 :           storage_class = sc_none;
   13787             :         }
   13788             :     }
   13789             : 
   13790             :   /* If this is declaring a typedef name, return a TYPE_DECL.  */
   13791   606105090 :   if (typedef_p && decl_context != TYPENAME)
   13792             :     {
   13793    29554913 :       bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
   13794    29554913 :       tree decl;
   13795             : 
   13796    29554913 :       if (funcdef_flag)
   13797             :         {
   13798           8 :           if (decl_context == NORMAL)
   13799           4 :             error_at (id_loc,
   13800             :                       "typedef may not be a function definition");
   13801             :           else
   13802           4 :             error_at (id_loc,
   13803             :                       "typedef may not be a member function definition");
   13804           8 :           return error_mark_node;
   13805             :         }
   13806             : 
   13807             :       /* This declaration:
   13808             : 
   13809             :            typedef void f(int) const;
   13810             : 
   13811             :          declares a function type which is not a member of any
   13812             :          particular class, but which is cv-qualified; for
   13813             :          example "f S::*" declares a pointer to a const-qualified
   13814             :          member function of S.  We record the cv-qualification in the
   13815             :          function type.  */
   13816    29554905 :       if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
   13817             :         {
   13818          78 :           type = apply_memfn_quals (type, memfn_quals, rqual);
   13819             :           
   13820             :           /* We have now dealt with these qualifiers.  */
   13821          78 :           memfn_quals = TYPE_UNQUALIFIED;
   13822          78 :           rqual = REF_QUAL_NONE;
   13823             :         }
   13824             : 
   13825    29554905 :       if (type_uses_auto (type))
   13826             :         {
   13827          38 :           if (alias_p)
   13828          17 :             error_at (declspecs->locations[ds_type_spec],
   13829             :                       "%<auto%> not allowed in alias declaration");
   13830             :           else
   13831          21 :             error_at (declspecs->locations[ds_type_spec],
   13832             :                       "typedef declared %<auto%>");
   13833          38 :           type = error_mark_node;
   13834             :         }
   13835             : 
   13836    29554905 :       if (reqs)
   13837           1 :         error_at (location_of (reqs), "requires-clause on typedef");
   13838             : 
   13839    29554905 :       if (id_declarator && declarator->u.id.qualifying_scope)
   13840             :         {
   13841          29 :           error_at (id_loc, "typedef name may not be a nested-name-specifier");
   13842          29 :           type = error_mark_node;
   13843             :         }
   13844             : 
   13845    29554905 :       if (decl_context == FIELD)
   13846    16246738 :         decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
   13847             :       else
   13848    13308167 :         decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
   13849             : 
   13850    29554905 :       if (decl_context != FIELD)
   13851             :         {
   13852    13308167 :           if (!current_function_decl)
   13853     5722890 :             DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
   13854     7585277 :           else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
   13855             :             /* The TYPE_DECL is "abstract" because there will be
   13856             :                clones of this constructor/destructor, and there will
   13857             :                be copies of this TYPE_DECL generated in those
   13858             :                clones.  The decloning optimization (for space) may
   13859             :                revert this subsequently if it determines that
   13860             :                the clones should share a common implementation.  */
   13861       86956 :             DECL_ABSTRACT_P (decl) = true;
   13862             : 
   13863    13308167 :           set_originating_module (decl);
   13864             :         }
   13865    16246738 :       else if (current_class_type
   13866    16246738 :                && constructor_name_p (unqualified_id, current_class_type))
   13867           3 :         permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
   13868             :                    "as enclosing class",
   13869             :                    unqualified_id);
   13870             : 
   13871             :       /* If the user declares "typedef struct {...} foo" then the
   13872             :          struct will have an anonymous name.  Fill that name in now.
   13873             :          Nothing can refer to it, so nothing needs know about the name
   13874             :          change.  */
   13875    29554905 :       if (type != error_mark_node
   13876    29554838 :           && unqualified_id
   13877    29554834 :           && TYPE_NAME (type)
   13878    27738700 :           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
   13879    55617905 :           && TYPE_UNNAMED_P (type)
   13880      287330 :           && declspecs->type_definition_p
   13881      287321 :           && attributes_naming_typedef_ok (*attrlist)
   13882    29842222 :           && cp_type_quals (type) == TYPE_UNQUALIFIED)
   13883      287292 :         name_unnamed_type (type, decl);
   13884             : 
   13885    29554905 :       if (signed_p
   13886    29554905 :           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
   13887      262544 :         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
   13888             : 
   13889    29554905 :       bad_specifiers (decl, BSP_TYPE, virtualp,
   13890             :                       memfn_quals != TYPE_UNQUALIFIED,
   13891             :                       inlinep, friendp, raises != NULL_TREE,
   13892             :                       declspecs->locations);
   13893             : 
   13894    29554905 :       if (alias_p)
   13895             :         /* Acknowledge that this was written:
   13896             :              `using analias = atype;'.  */
   13897     9915472 :         TYPE_DECL_ALIAS_P (decl) = 1;
   13898             : 
   13899    29554905 :       return decl;
   13900             :     }
   13901             : 
   13902             :   /* Detect the case of an array type of unspecified size
   13903             :      which came, as such, direct from a typedef name.
   13904             :      We must copy the type, so that the array's domain can be
   13905             :      individually set by the object's initializer.  */
   13906             : 
   13907   576550177 :   if (type && typedef_type
   13908   559278116 :       && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
   13909   576999492 :       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
   13910          92 :     type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   13911             : 
   13912             :   /* Detect where we're using a typedef of function type to declare a
   13913             :      function. PARMS will not be set, so we must create it now.  */
   13914             : 
   13915   576550177 :   if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
   13916             :     {
   13917       12436 :       tree decls = NULL_TREE;
   13918       12436 :       tree args;
   13919             : 
   13920       12436 :       for (args = TYPE_ARG_TYPES (type);
   13921       27998 :            args && args != void_list_node;
   13922       15562 :            args = TREE_CHAIN (args))
   13923             :         {
   13924       15562 :           tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
   13925       15562 :                                           TREE_VALUE (args));
   13926             : 
   13927       15562 :           DECL_CHAIN (decl) = decls;
   13928       15562 :           decls = decl;
   13929             :         }
   13930             : 
   13931       12436 :       parms = nreverse (decls);
   13932             : 
   13933       12436 :       if (decl_context != TYPENAME)
   13934             :         {
   13935             :           /* The qualifiers on the function type become the qualifiers on
   13936             :              the non-static member function. */
   13937       11809 :           memfn_quals |= type_memfn_quals (type);
   13938       11809 :           rqual = type_memfn_rqual (type);
   13939       11809 :           type_quals = TYPE_UNQUALIFIED;
   13940       11809 :           raises = TYPE_RAISES_EXCEPTIONS (type);
   13941             :         }
   13942             :     }
   13943             : 
   13944             :   /* If this is a type name (such as, in a cast or sizeof),
   13945             :      compute the type and return it now.  */
   13946             : 
   13947   576550177 :   if (decl_context == TYPENAME)
   13948             :     {
   13949             :       /* Note that here we don't care about type_quals.  */
   13950             : 
   13951             :       /* Special case: "friend class foo" looks like a TYPENAME context.  */
   13952   220733859 :       if (friendp)
   13953             :         {
   13954           0 :           if (inlinep)
   13955             :             {
   13956           0 :               error ("%<inline%> specified for friend class declaration");
   13957           0 :               inlinep = 0;
   13958             :             }
   13959             : 
   13960           0 :           if (!current_aggr)
   13961             :             {
   13962             :               /* Don't allow friend declaration without a class-key.  */
   13963           0 :               if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   13964           0 :                 permerror (input_location, "template parameters cannot be friends");
   13965           0 :               else if (TREE_CODE (type) == TYPENAME_TYPE)
   13966           0 :                 permerror (input_location, "friend declaration requires class-key, "
   13967             :                            "i.e. %<friend class %T::%D%>",
   13968           0 :                            TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
   13969             :               else
   13970           0 :                 permerror (input_location, "friend declaration requires class-key, "
   13971             :                            "i.e. %<friend %#T%>",
   13972             :                            type);
   13973             :             }
   13974             : 
   13975             :           /* Only try to do this stuff if we didn't already give up.  */
   13976           0 :           if (type != integer_type_node)
   13977             :             {
   13978             :               /* A friendly class?  */
   13979           0 :               if (current_class_type)
   13980           0 :                 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
   13981             :                                    /*complain=*/true);
   13982             :               else
   13983           0 :                 error ("trying to make class %qT a friend of global scope",
   13984             :                        type);
   13985             : 
   13986           0 :               type = void_type_node;
   13987             :             }
   13988             :         }
   13989   220733859 :       else if (memfn_quals || rqual)
   13990             :         {
   13991       51506 :           if (ctype == NULL_TREE
   13992       51506 :               && TREE_CODE (type) == METHOD_TYPE)
   13993           0 :             ctype = TYPE_METHOD_BASETYPE (type);
   13994             : 
   13995       51506 :           if (ctype)
   13996           0 :             type = build_memfn_type (type, ctype, memfn_quals, rqual);
   13997             :           /* Core issue #547: need to allow this in template type args.
   13998             :              Allow it in general in C++11 for alias-declarations.  */
   13999       51506 :           else if ((template_type_arg || cxx_dialect >= cxx11)
   14000       51504 :                    && TREE_CODE (type) == FUNCTION_TYPE)
   14001       51501 :             type = apply_memfn_quals (type, memfn_quals, rqual);
   14002             :           else
   14003           5 :             error ("invalid qualifiers on non-member function type");
   14004             :         }
   14005             : 
   14006   220733859 :       if (reqs)
   14007           1 :         error_at (location_of (reqs), "requires-clause on type-id");
   14008             : 
   14009   220733859 :       return type;
   14010             :     }
   14011   355816318 :   else if (unqualified_id == NULL_TREE && decl_context != PARM
   14012      454842 :            && decl_context != CATCHPARM
   14013      114646 :            && TREE_CODE (type) != UNION_TYPE
   14014      114386 :            && ! bitfield
   14015      114386 :            && innermost_code != cdk_decomp)
   14016             :     {
   14017          10 :       error ("abstract declarator %qT used as declaration", type);
   14018          10 :       return error_mark_node;
   14019             :     }
   14020             : 
   14021   355816308 :   if (!FUNC_OR_METHOD_TYPE_P (type))
   14022             :     {
   14023             :       /* Only functions may be declared using an operator-function-id.  */
   14024   452047758 :       if (dname && IDENTIFIER_ANY_OP_P (dname))
   14025             :         {
   14026          11 :           error_at (id_loc, "declaration of %qD as non-function", dname);
   14027          11 :           return error_mark_node;
   14028             :         }
   14029             : 
   14030   241242689 :       if (reqs)
   14031           5 :         error_at (location_of (reqs),
   14032             :                   "requires-clause on declaration of non-function type %qT",
   14033             :                   type);
   14034             :     }
   14035             : 
   14036             :   /* We don't check parameter types here because we can emit a better
   14037             :      error message later.  */
   14038   355816297 :   if (decl_context != PARM)
   14039             :     {
   14040   167976385 :       type = check_var_type (unqualified_id, type, id_loc);
   14041   167976385 :       if (type == error_mark_node)
   14042             :         return error_mark_node;
   14043             :     }
   14044             : 
   14045             :   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
   14046             :      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
   14047             : 
   14048   355816202 :   if (decl_context == PARM || decl_context == CATCHPARM)
   14049             :     {
   14050   188189637 :       if (ctype || in_namespace)
   14051           0 :         error ("cannot use %<::%> in parameter declaration");
   14052             : 
   14053   188189637 :       tree auto_node = type_uses_auto (type);
   14054   188189637 :       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
   14055             :         {
   14056          66 :           if (cxx_dialect >= cxx14)
   14057             :             {
   14058         120 :               if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
   14059           1 :                 error_at (typespec_loc,
   14060             :                           "cannot declare a parameter with %<decltype(auto)%>");
   14061          65 :               else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   14062             :                 {
   14063           3 :                   auto_diagnostic_group g;
   14064           3 :                   gcc_rich_location richloc (typespec_loc);
   14065           3 :                   richloc.add_fixit_insert_after ("<>");
   14066           3 :                   error_at (&richloc,
   14067             :                             "missing template argument list after %qE; template "
   14068             :                             "placeholder not permitted in parameter", c);
   14069           3 :                   if (decl_context == PARM && cxx_dialect >= cxx20)
   14070           2 :                     inform (typespec_loc, "or use %<auto%> for an "
   14071             :                             "abbreviated function template");
   14072           3 :                   inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
   14073           3 :                 }
   14074             :               else
   14075          62 :                 error_at (typespec_loc,
   14076             :                           "%<auto%> parameter not permitted in this context");
   14077             :             }
   14078             :           else
   14079           0 :             error_at (typespec_loc, "parameter declared %<auto%>");
   14080          66 :           type = error_mark_node;
   14081             :         }
   14082             : 
   14083             :       /* A parameter declared as an array of T is really a pointer to T.
   14084             :          One declared as a function is really a pointer to a function.
   14085             :          One declared as a member is really a pointer to member.  */
   14086             : 
   14087   188189637 :       if (TREE_CODE (type) == ARRAY_TYPE)
   14088             :         {
   14089             :           /* Transfer const-ness of array into that of type pointed to.  */
   14090      540825 :           type = build_pointer_type (TREE_TYPE (type));
   14091      540825 :           type_quals = TYPE_UNQUALIFIED;
   14092      540825 :           array_parameter_p = true;
   14093             :         }
   14094   187648812 :       else if (TREE_CODE (type) == FUNCTION_TYPE)
   14095       75192 :         type = build_pointer_type (type);
   14096             :     }
   14097             : 
   14098    82119470 :   if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
   14099   414444051 :       && !(unqualified_id
   14100   117254283 :            && identifier_p (unqualified_id)
   14101    58627561 :            && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
   14102             :     {
   14103    58626722 :       cp_cv_quals real_quals = memfn_quals;
   14104    58626722 :       if (cxx_dialect < cxx14 && constexpr_p
   14105      572778 :           && sfk != sfk_constructor && sfk != sfk_destructor)
   14106        1781 :         real_quals |= TYPE_QUAL_CONST;
   14107    58626722 :       type = build_memfn_type (type, ctype, real_quals, rqual);
   14108             :     }
   14109             : 
   14110   355816202 :   {
   14111   355816202 :     tree decl = NULL_TREE;
   14112             : 
   14113   355816202 :     if (decl_context == PARM)
   14114             :       {
   14115   187839912 :         decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
   14116   187839912 :         DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
   14117             : 
   14118   187839912 :         bad_specifiers (decl, BSP_PARM, virtualp,
   14119             :                         memfn_quals != TYPE_UNQUALIFIED,
   14120             :                         inlinep, friendp, raises != NULL_TREE,
   14121             :                         declspecs->locations);
   14122             :       }
   14123   167976290 :     else if (decl_context == FIELD)
   14124             :       {
   14125    77398189 :         if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
   14126    11021425 :           if (tree auto_node = type_uses_auto (type))
   14127             :             {
   14128          21 :               location_t tloc = declspecs->locations[ds_type_spec];
   14129          21 :               if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   14130           6 :                 error_at (tloc, "invalid use of template-name %qE without an "
   14131             :                           "argument list",
   14132           6 :                           CLASS_PLACEHOLDER_TEMPLATE (auto_node));
   14133             :               else
   14134          15 :                 error_at (tloc, "non-static data member declared with "
   14135             :                           "placeholder %qT", auto_node);
   14136          21 :               type = error_mark_node;
   14137             :             }
   14138             : 
   14139             :         /* The C99 flexible array extension.  */
   14140    65199013 :         if (!staticp && TREE_CODE (type) == ARRAY_TYPE
   14141    78194276 :             && TYPE_DOMAIN (type) == NULL_TREE)
   14142             :           {
   14143        1369 :             if (ctype
   14144        1369 :                 && (TREE_CODE (ctype) == UNION_TYPE
   14145        1369 :                     || TREE_CODE (ctype) == QUAL_UNION_TYPE))
   14146             :               {
   14147          32 :                 error_at (id_loc, "flexible array member in union");
   14148          32 :                 type = error_mark_node;
   14149             :               }
   14150             :             else
   14151             :               {
   14152             :                 /* Array is a flexible member.  */
   14153        1337 :                 if (name)
   14154        1337 :                   pedwarn (id_loc, OPT_Wpedantic,
   14155             :                            "ISO C++ forbids flexible array member %qs", name);
   14156             :                 else
   14157             :                   pedwarn (input_location, OPT_Wpedantic,
   14158             :                            "ISO C++ forbids flexible array members");
   14159             : 
   14160             :                 /* Flexible array member has a null domain.  */
   14161        1337 :                 type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
   14162             :               }
   14163             :           }
   14164             : 
   14165    77398189 :         if (type == error_mark_node)
   14166             :           {
   14167             :             /* Happens when declaring arrays of sizes which
   14168             :                are error_mark_node, for example.  */
   14169          53 :             decl = NULL_TREE;
   14170             :           }
   14171    77398136 :         else if (in_namespace && !friendp)
   14172             :           {
   14173             :             /* Something like struct S { int N::j; };  */
   14174           8 :             error_at (id_loc, "invalid use of %<::%>");
   14175           8 :             return error_mark_node;
   14176             :           }
   14177    77398128 :         else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
   14178             :           {
   14179    60095863 :             int publicp = 0;
   14180    60095863 :             tree function_context;
   14181             : 
   14182    60095863 :             if (friendp == 0)
   14183             :               {
   14184             :                 /* This should never happen in pure C++ (the check
   14185             :                    could be an assert).  It could happen in
   14186             :                    Objective-C++ if someone writes invalid code that
   14187             :                    uses a function declaration for an instance
   14188             :                    variable or property (instance variables and
   14189             :                    properties are parsed as FIELD_DECLs, but they are
   14190             :                    part of an Objective-C class, not a C++ class).
   14191             :                    That code is invalid and is caught by this
   14192             :                    check.  */
   14193    58073138 :                 if (!ctype)
   14194             :                   {
   14195           0 :                     error ("declaration of function %qD in invalid context",
   14196             :                            unqualified_id);
   14197           0 :                     return error_mark_node;
   14198             :                   }
   14199             : 
   14200             :                 /* ``A union may [ ... ] not [ have ] virtual functions.''
   14201             :                    ARM 9.5 */
   14202    58073138 :                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
   14203             :                   {
   14204           3 :                     error_at (declspecs->locations[ds_virtual],
   14205             :                               "function %qD declared %<virtual%> inside a union",
   14206             :                               unqualified_id);
   14207           3 :                     return error_mark_node;
   14208             :                   }
   14209             : 
   14210     2826410 :                 if (virtualp
   14211    62922270 :                     && identifier_p (unqualified_id)
   14212     2826410 :                     && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   14213             :                   {
   14214          11 :                     error_at (declspecs->locations[ds_virtual],
   14215             :                               "%qD cannot be declared %<virtual%>, since it "
   14216             :                               "is always static", unqualified_id);
   14217          11 :                     virtualp = 0;
   14218             :                   }
   14219             :               }
   14220             : 
   14221             :             /* Check that the name used for a destructor makes sense.  */
   14222    60095860 :             if (sfk == sfk_destructor)
   14223             :               {
   14224     1908699 :                 tree uqname = id_declarator->u.id.unqualified_name;
   14225             : 
   14226     1908699 :                 if (!ctype)
   14227             :                   {
   14228          16 :                     gcc_assert (friendp);
   14229          16 :                     error_at (id_loc, "expected qualified name in friend "
   14230             :                               "declaration for destructor %qD", uqname);
   14231          16 :                     return error_mark_node;
   14232             :                   }
   14233             : 
   14234     1908683 :                 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
   14235             :                   {
   14236          11 :                     error_at (id_loc, "declaration of %qD as member of %qT",
   14237             :                               uqname, ctype);
   14238          11 :                     return error_mark_node;
   14239             :                   }
   14240     1908672 :                 if (concept_p)
   14241             :                   {
   14242           3 :                     error_at (declspecs->locations[ds_concept],
   14243             :                               "a destructor cannot be %qs", "concept");
   14244           3 :                     return error_mark_node;
   14245             :                   }
   14246     1908669 :                 if (constexpr_p && cxx_dialect < cxx20)
   14247             :                   {
   14248           4 :                     error_at (declspecs->locations[ds_constexpr],
   14249             :                               "%<constexpr%> destructors only available"
   14250             :                               " with %<-std=c++20%> or %<-std=gnu++20%>");
   14251           4 :                     return error_mark_node;
   14252             :                   }
   14253     1908665 :                 if (consteval_p)
   14254             :                   {
   14255           1 :                     error_at (declspecs->locations[ds_consteval],
   14256             :                               "a destructor cannot be %qs", "consteval");
   14257           1 :                     return error_mark_node;
   14258             :                   }
   14259             :               }
   14260    58187161 :             else if (sfk == sfk_constructor && friendp && !ctype)
   14261             :               {
   14262           0 :                 error ("expected qualified name in friend declaration "
   14263             :                        "for constructor %qD",
   14264           0 :                        id_declarator->u.id.unqualified_name);
   14265           0 :                 return error_mark_node;
   14266             :               }
   14267    60095825 :             if (sfk == sfk_constructor)
   14268    13811333 :               if (concept_p)
   14269             :                 {
   14270           3 :                   error_at (declspecs->locations[ds_concept],
   14271             :                             "a constructor cannot be %<concept%>");
   14272           3 :                   return error_mark_node;
   14273             :                 }
   14274    46284492 :             if (concept_p)
   14275             :               {
   14276           5 :                 error_at (declspecs->locations[ds_concept],
   14277             :                           "a concept cannot be a member function");
   14278           5 :                 concept_p = false;
   14279             :               }
   14280    60095817 :             else if (consteval_p
   14281    60097965 :                      && identifier_p (unqualified_id)
   14282    60097960 :                      && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   14283             :               {
   14284           3 :                 error_at (declspecs->locations[ds_consteval],
   14285             :                           "%qD cannot be %qs", unqualified_id, "consteval");
   14286           3 :                 consteval_p = false;
   14287             :               }
   14288             : 
   14289    60095822 :             if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   14290             :               {
   14291        8474 :                 tree tmpl = TREE_OPERAND (unqualified_id, 0);
   14292        8474 :                 if (variable_template_p (tmpl))
   14293             :                   {
   14294           3 :                     error_at (id_loc, "specialization of variable template "
   14295             :                               "%qD declared as function", tmpl);
   14296           3 :                     inform (DECL_SOURCE_LOCATION (tmpl),
   14297             :                             "variable template declared here");
   14298           3 :                     return error_mark_node;
   14299             :                   }
   14300             :               }
   14301             : 
   14302             :             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
   14303    60095819 :             function_context
   14304    60095819 :               = (ctype != NULL_TREE
   14305    60095819 :                  ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
   14306   120191638 :             publicp = ((! friendp || ! staticp)
   14307    60095819 :                        && function_context == NULL_TREE);
   14308             : 
   14309    60095819 :             decl = grokfndecl (ctype, type,
   14310    60095819 :                                TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
   14311             :                                ? unqualified_id : dname,
   14312             :                                parms,
   14313             :                                unqualified_id,
   14314             :                                declspecs,
   14315             :                                reqs,
   14316             :                                virtualp, flags, memfn_quals, rqual, raises,
   14317             :                                friendp ? -1 : 0, friendp, publicp,
   14318    60095819 :                                inlinep | (2 * constexpr_p) | (4 * concept_p)
   14319    60095819 :                                        | (8 * consteval_p),
   14320             :                                initialized == SD_DELETED, sfk,
   14321             :                                funcdef_flag, late_return_type_p,
   14322             :                                template_count, in_namespace,
   14323             :                                attrlist, id_loc);
   14324    60095819 :             decl = set_virt_specifiers (decl, virt_specifiers);
   14325    60095819 :             if (decl == NULL_TREE)
   14326         117 :               return error_mark_node;
   14327             : #if 0
   14328             :             /* This clobbers the attrs stored in `decl' from `attrlist'.  */
   14329             :             /* The decl and setting of decl_attr is also turned off.  */
   14330             :             decl = build_decl_attribute_variant (decl, decl_attr);
   14331             : #endif
   14332             : 
   14333             :             /* [class.conv.ctor]
   14334             : 
   14335             :                A constructor declared without the function-specifier
   14336             :                explicit that can be called with a single parameter
   14337             :                specifies a conversion from the type of its first
   14338             :                parameter to the type of its class.  Such a constructor
   14339             :                is called a converting constructor.  */
   14340    60095702 :             if (explicitp == 2)
   14341     3516185 :               DECL_NONCONVERTING_P (decl) = 1;
   14342             : 
   14343    60095702 :             if (declspecs->explicit_specifier)
   14344       13654 :               store_explicit_specifier (decl, declspecs->explicit_specifier);
   14345             :           }
   14346    17302265 :         else if (!staticp
   14347    17302265 :                  && ((current_class_type
   14348    11021394 :                       && same_type_p (type, current_class_type))
   14349    11021297 :                      || (!dependent_type_p (type)
   14350     7206702 :                          && !COMPLETE_TYPE_P (complete_type (type))
   14351        1393 :                          && (!complete_or_array_type_p (type)
   14352        1310 :                              || initialized == SD_UNINITIALIZED))))
   14353             :           {
   14354        1460 :             if (TREE_CODE (type) != ARRAY_TYPE
   14355        1460 :                 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
   14356             :               {
   14357         180 :                 if (unqualified_id)
   14358             :                   {
   14359         124 :                     error_at (id_loc, "field %qD has incomplete type %qT",
   14360             :                               unqualified_id, type);
   14361         124 :                     cxx_incomplete_type_inform (strip_array_types (type));
   14362             :                   }
   14363             :                 else
   14364          56 :                   error ("name %qT has incomplete type", type);
   14365             : 
   14366         180 :                 type = error_mark_node;
   14367         180 :                 decl = NULL_TREE;
   14368             :               }
   14369             :           }
   14370    28320723 :         else if (!verify_type_context (input_location,
   14371             :                                        staticp
   14372             :                                        ? TCTX_STATIC_STORAGE
   14373             :                                        : TCTX_FIELD, type))
   14374             :           {
   14375           0 :             type = error_mark_node;
   14376           0 :             decl = NULL_TREE;
   14377             :           }
   14378             :         else
   14379             :           {
   14380    17300797 :             if (friendp)
   14381             :               {
   14382          18 :                 if (unqualified_id)
   14383          14 :                   error_at (id_loc,
   14384             :                             "%qE is neither function nor member function; "
   14385             :                             "cannot be declared friend", unqualified_id);
   14386             :                 else
   14387           4 :                   error ("unnamed field is neither function nor member "
   14388             :                          "function; cannot be declared friend");
   14389          18 :                 return error_mark_node;
   14390             :               }
   14391    17300779 :             decl = NULL_TREE;
   14392             :           }
   14393             : 
   14394    77397994 :         if (friendp)
   14395             :           {
   14396             :             /* Packages tend to use GNU attributes on friends, so we only
   14397             :                warn for standard attributes.  */
   14398     2022688 :             if (attrlist
   14399     2022688 :                 && !funcdef_flag
   14400      781534 :                 && cxx11_attribute_p (*attrlist)
   14401     2022709 :                 && !all_attributes_are_contracts_p (*attrlist))
   14402             :               {
   14403          18 :                 *attrlist = NULL_TREE;
   14404          18 :                 if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
   14405          18 :                   inform (id_loc, "an attribute that appertains to a friend "
   14406             :                           "declaration that is not a definition is ignored");
   14407             :               }
   14408             :             /* Friends are treated specially.  */
   14409     2022688 :             if (ctype == current_class_type)
   14410             :               ;  /* We already issued a permerror.  */
   14411     2022688 :             else if (decl && DECL_NAME (decl))
   14412             :               {
   14413     2022684 :                 set_originating_module (decl, true);
   14414             : 
   14415     2022684 :                 if (initialized)
   14416             :                   /* Kludge: We need funcdef_flag to be true in do_friend for
   14417             :                      in-class defaulted functions, but that breaks grokfndecl.
   14418             :                      So set it here.  */
   14419        6332 :                   funcdef_flag = true;
   14420             : 
   14421     2022684 :                 cplus_decl_attributes (&decl, *attrlist, 0);
   14422     2022684 :                 *attrlist = NULL_TREE;
   14423             : 
   14424     2022684 :                 tree scope = ctype ? ctype : in_namespace;
   14425     2022684 :                 decl = do_friend (scope, unqualified_id, decl,
   14426             :                                   flags, funcdef_flag);
   14427     2022684 :                 return decl;
   14428             :               }
   14429             :             else
   14430           4 :               return error_mark_node;
   14431             :           }
   14432             : 
   14433             :         /* Structure field.  It may not be a function, except for C++.  */
   14434             : 
   14435    75375306 :         if (decl == NULL_TREE)
   14436             :           {
   14437    17302288 :             if (staticp)
   14438             :               {
   14439             :                 /* C++ allows static class members.  All other work
   14440             :                    for this is done by grokfield.  */
   14441     6280871 :                 decl = build_lang_decl_loc (id_loc, VAR_DECL,
   14442             :                                             unqualified_id, type);
   14443     6280871 :                 set_linkage_for_static_data_member (decl);
   14444     6280871 :                 if (concept_p)
   14445           5 :                   error_at (declspecs->locations[ds_concept],
   14446             :                             "static data member %qE declared %qs",
   14447             :                             unqualified_id, "concept");
   14448     6280866 :                 else if (constexpr_p && !initialized)
   14449             :                   {
   14450           9 :                     error_at (DECL_SOURCE_LOCATION (decl),
   14451             :                               "%<constexpr%> static data member %qD must "
   14452             :                               "have an initializer", decl);
   14453           9 :                     constexpr_p = false;
   14454             :                   }
   14455     6280871 :                 if (consteval_p)
   14456           1 :                   error_at (declspecs->locations[ds_consteval],
   14457             :                             "static data member %qE declared %qs",
   14458             :                             unqualified_id, "consteval");
   14459             : 
   14460     6280871 :                 if (inlinep)
   14461         523 :                   mark_inline_variable (decl, declspecs->locations[ds_inline]);
   14462             : 
   14463     6280871 :                 if (!DECL_VAR_DECLARED_INLINE_P (decl)
   14464     6280871 :                     && !(cxx_dialect >= cxx17 && constexpr_p))
   14465             :                   /* Even if there is an in-class initialization, DECL
   14466             :                      is considered undefined until an out-of-class
   14467             :                      definition is provided, unless this is an inline
   14468             :                      variable.  */
   14469     1261970 :                   DECL_EXTERNAL (decl) = 1;
   14470             : 
   14471     6280871 :                 if (thread_p)
   14472             :                   {
   14473         388 :                     CP_DECL_THREAD_LOCAL_P (decl) = true;
   14474         388 :                     if (!processing_template_decl)
   14475         363 :                       set_decl_tls_model (decl, decl_default_tls_model (decl));
   14476         388 :                     if (declspecs->gnu_thread_keyword_p)
   14477          39 :                       SET_DECL_GNU_TLS_P (decl);
   14478             :                   }
   14479             : 
   14480             :                 /* Set the constraints on the declaration.  */
   14481     6280871 :                 bool memtmpl = (current_template_depth
   14482     6280871 :                                 > template_class_depth (current_class_type));
   14483     6280871 :                 if (memtmpl)
   14484             :                   {
   14485       45394 :                     tree ci = current_template_constraints ();
   14486       45394 :                     set_constraints (decl, ci);
   14487             :                   }
   14488             :               }
   14489             :             else
   14490             :               {
   14491    11021417 :                 if (concept_p)
   14492             :                   {
   14493           4 :                     error_at (declspecs->locations[ds_concept],
   14494             :                               "non-static data member %qE declared %qs",
   14495             :                               unqualified_id, "concept");
   14496           4 :                     concept_p = false;
   14497           4 :                     constexpr_p = false;
   14498             :                   }
   14499    11021413 :                 else if (constexpr_p)
   14500             :                   {
   14501           6 :                     error_at (declspecs->locations[ds_constexpr],
   14502             :                               "non-static data member %qE declared %qs",
   14503             :                               unqualified_id, "constexpr");
   14504           6 :                     constexpr_p = false;
   14505             :                   }
   14506    11021417 :                 if (constinit_p)
   14507             :                   {
   14508           2 :                     error_at (declspecs->locations[ds_constinit],
   14509             :                               "non-static data member %qE declared %qs",
   14510             :                               unqualified_id, "constinit");
   14511           2 :                     constinit_p = false;
   14512             :                   }
   14513    11021417 :                 if (consteval_p)
   14514             :                   {
   14515           1 :                     error_at (declspecs->locations[ds_consteval],
   14516             :                               "non-static data member %qE declared %qs",
   14517             :                               unqualified_id, "consteval");
   14518           1 :                     consteval_p = false;
   14519             :                   }
   14520    11021417 :                 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
   14521    11021417 :                 DECL_NONADDRESSABLE_P (decl) = bitfield;
   14522    11021417 :                 if (bitfield && !unqualified_id)
   14523      101294 :                   DECL_PADDING_P (decl) = 1;
   14524             : 
   14525    11021417 :                 if (storage_class == sc_mutable)
   14526             :                   {
   14527      110054 :                     DECL_MUTABLE_P (decl) = 1;
   14528      110054 :                     storage_class = sc_none;
   14529             :                   }
   14530             : 
   14531    11021417 :                 if (initialized)
   14532             :                   {
   14533             :                     /* An attempt is being made to initialize a non-static
   14534             :                        member.  This is new in C++11.  */
   14535      441513 :                     maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
   14536             : 
   14537             :                     /* If this has been parsed with static storage class, but
   14538             :                        errors forced staticp to be cleared, ensure NSDMI is
   14539             :                        not present.  */
   14540      441513 :                     if (declspecs->storage_class == sc_static)
   14541           3 :                       DECL_INITIAL (decl) = error_mark_node;
   14542             :                   }
   14543             :               }
   14544             : 
   14545    28323705 :             bad_specifiers (decl, BSP_FIELD, virtualp,
   14546             :                             memfn_quals != TYPE_UNQUALIFIED,
   14547             :                             staticp ? false : inlinep, friendp,
   14548             :                             raises != NULL_TREE,
   14549             :                             declspecs->locations);
   14550             :           }
   14551             :       }
   14552    90578101 :     else if (FUNC_OR_METHOD_TYPE_P (type))
   14553             :       {
   14554    54402545 :         tree original_name;
   14555    54402545 :         int publicp = 0;
   14556             : 
   14557    54402545 :         if (!unqualified_id)
   14558           0 :           return error_mark_node;
   14559             : 
   14560    54402545 :         if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
   14561             :           original_name = dname;
   14562             :         else
   14563    53799900 :           original_name = unqualified_id;
   14564             :         // FIXME:gcc_assert (original_name == dname);
   14565             : 
   14566    54402545 :         if (storage_class == sc_auto)
   14567           1 :           error_at (declspecs->locations[ds_storage_class],
   14568             :                     "storage class %<auto%> invalid for function %qs", name);
   14569    54402544 :         else if (storage_class == sc_register)
   14570          10 :           error_at (declspecs->locations[ds_storage_class],
   14571             :                     "storage class %<register%> invalid for function %qs",
   14572             :                     name);
   14573    54402534 :         else if (thread_p)
   14574             :           {
   14575          16 :             if (declspecs->gnu_thread_keyword_p)
   14576          16 :               error_at (declspecs->locations[ds_thread],
   14577             :                         "storage class %<__thread%> invalid for function %qs",
   14578             :                         name);
   14579             :             else
   14580           0 :               error_at (declspecs->locations[ds_thread],
   14581             :                         "storage class %<thread_local%> invalid for "
   14582             :                         "function %qs", name);
   14583             :           }
   14584             : 
   14585    54402545 :         if (virt_specifiers)
   14586           6 :           error ("virt-specifiers in %qs not allowed outside a class "
   14587             :                  "definition", name);
   14588             :         /* Function declaration not at top level.
   14589             :            Storage classes other than `extern' are not allowed
   14590             :            and `extern' makes no difference.  */
   14591    54402545 :         if (! toplevel_bindings_p ()
   14592       24075 :             && (storage_class == sc_static
   14593       24064 :                 || decl_spec_seq_has_spec_p (declspecs, ds_inline))
   14594    54402559 :             && pedantic)
   14595             :           {
   14596          10 :             if (storage_class == sc_static)
   14597           7 :               pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic, 
   14598             :                        "%<static%> specifier invalid for function %qs "
   14599             :                        "declared out of global scope", name);
   14600             :             else
   14601           3 :               pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic, 
   14602             :                        "%<inline%> specifier invalid for function %qs "
   14603             :                        "declared out of global scope", name);
   14604             :           }
   14605             : 
   14606    54402545 :         if (ctype == NULL_TREE)
   14607             :           {
   14608    47929814 :             if (virtualp)
   14609             :               {
   14610           0 :                 error ("virtual non-class function %qs", name);
   14611           0 :                 virtualp = 0;
   14612             :               }
   14613    47929814 :             else if (sfk == sfk_constructor
   14614    47929814 :                      || sfk == sfk_destructor)
   14615             :               {
   14616           4 :                 error (funcdef_flag
   14617             :                        ? G_("%qs defined in a non-class scope")
   14618             :                        : G_("%qs declared in a non-class scope"), name);
   14619           4 :                 sfk = sfk_none;
   14620             :               }
   14621             :           }
   14622    54402545 :         if (consteval_p
   14623    54402944 :             && identifier_p (unqualified_id)
   14624    54402944 :             && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
   14625             :           {
   14626           3 :             error_at (declspecs->locations[ds_consteval],
   14627             :                       "%qD cannot be %qs", unqualified_id, "consteval");
   14628           3 :             consteval_p = false;
   14629             :           }
   14630             : 
   14631             :         /* Record whether the function is public.  */
   14632    54402545 :         publicp = (ctype != NULL_TREE
   14633    54402545 :                    || storage_class != sc_static);
   14634             : 
   14635   108805090 :         decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
   14636             :                            declspecs,
   14637             :                            reqs, virtualp, flags, memfn_quals, rqual, raises,
   14638             :                            1, friendp,
   14639             :                            publicp,
   14640    54402545 :                            inlinep | (2 * constexpr_p) | (4 * concept_p)
   14641    54402545 :                                    | (8 * consteval_p),
   14642             :                            initialized == SD_DELETED,
   14643             :                            sfk,
   14644             :                            funcdef_flag,
   14645             :                            late_return_type_p,
   14646             :                            template_count, in_namespace, attrlist,
   14647             :                            id_loc);
   14648    54402545 :         if (decl == NULL_TREE)
   14649         573 :           return error_mark_node;
   14650             : 
   14651    54401972 :         if (explicitp == 2)
   14652         135 :           DECL_NONCONVERTING_P (decl) = 1;
   14653    54401972 :         if (staticp == 1)
   14654             :           {
   14655      383562 :             int invalid_static = 0;
   14656             : 
   14657             :             /* Don't allow a static member function in a class, and forbid
   14658             :                declaring main to be static.  */
   14659      383562 :             if (TREE_CODE (type) == METHOD_TYPE)
   14660             :               {
   14661           0 :                 permerror (input_location, "cannot declare member function %qD to have "
   14662             :                            "static linkage", decl);
   14663           0 :                 invalid_static = 1;
   14664             :               }
   14665      383562 :             else if (current_function_decl)
   14666             :               {
   14667             :                 /* 7.1.1: There can be no static function declarations within a
   14668             :                    block.  */
   14669          11 :                 error_at (declspecs->locations[ds_storage_class],
   14670             :                           "cannot declare static function inside another function");
   14671          11 :                 invalid_static = 1;
   14672             :               }
   14673             : 
   14674          11 :             if (invalid_static)
   14675             :               {
   14676    54401972 :                 staticp = 0;
   14677             :                 storage_class = sc_none;
   14678             :               }
   14679             :           }
   14680    54401972 :         if (declspecs->explicit_specifier)
   14681           1 :           store_explicit_specifier (decl, declspecs->explicit_specifier);
   14682             :       }
   14683             :     else
   14684             :       {
   14685             :         /* It's a variable.  */
   14686             : 
   14687             :         /* An uninitialized decl with `extern' is a reference.  */
   14688    72080092 :         decl = grokvardecl (type, dname, unqualified_id,
   14689             :                             declspecs,
   14690             :                             initialized,
   14691             :                             type_quals,
   14692             :                             inlinep,
   14693             :                             concept_p,
   14694             :                             template_count,
   14695             :                             ctype ? ctype : in_namespace,
   14696             :                             id_loc);
   14697    36175556 :         if (decl == NULL_TREE)
   14698          21 :           return error_mark_node;
   14699             : 
   14700    36175535 :         bad_specifiers (decl, BSP_VAR, virtualp,
   14701             :                         memfn_quals != TYPE_UNQUALIFIED,
   14702             :                         inlinep, friendp, raises != NULL_TREE,
   14703             :                         declspecs->locations);
   14704             : 
   14705    36175535 :         if (ctype)
   14706             :           {
   14707      271018 :             DECL_CONTEXT (decl) = ctype;
   14708      271018 :             if (staticp == 1)
   14709             :               {
   14710           8 :                 permerror (declspecs->locations[ds_storage_class],
   14711             :                            "%<static%> may not be used when defining "
   14712             :                            "(as opposed to declaring) a static data member");
   14713           8 :                 staticp = 0;
   14714           8 :                 storage_class = sc_none;
   14715             :               }
   14716      271018 :             if (storage_class == sc_register && TREE_STATIC (decl))
   14717             :               {
   14718           0 :                 error ("static member %qD declared %<register%>", decl);
   14719           0 :                 storage_class = sc_none;
   14720             :               }
   14721      271018 :             if (storage_class == sc_extern && pedantic)
   14722             :               {
   14723           0 :                 pedwarn (input_location, OPT_Wpedantic, 
   14724             :                          "cannot explicitly declare member %q#D to have "
   14725             :                          "extern linkage", decl);
   14726           0 :                 storage_class = sc_none;
   14727             :               }
   14728             :           }
   14729    35904517 :         else if (constexpr_p && DECL_EXTERNAL (decl))
   14730             :           {
   14731          12 :             error_at (DECL_SOURCE_LOCATION (decl),
   14732             :                       "declaration of %<constexpr%> variable %qD "
   14733             :                       "is not a definition", decl);
   14734          12 :             constexpr_p = false;
   14735             :           }
   14736    36175535 :         if (consteval_p)
   14737             :           {
   14738           1 :             error_at (DECL_SOURCE_LOCATION (decl),
   14739             :                       "a variable cannot be declared %<consteval%>");
   14740           1 :             consteval_p = false;
   14741             :           }
   14742             : 
   14743    36175535 :         if (inlinep)
   14744     2312764 :           mark_inline_variable (decl, declspecs->locations[ds_inline]);
   14745    36175535 :         if (innermost_code == cdk_decomp)
   14746             :           {
   14747       13070 :             gcc_assert (declarator && declarator->kind == cdk_decomp);
   14748       13070 :             DECL_SOURCE_LOCATION (decl) = id_loc;
   14749       13070 :             DECL_ARTIFICIAL (decl) = 1;
   14750       13070 :             fit_decomposition_lang_decl (decl, NULL_TREE);
   14751             :           }
   14752             :       }
   14753             : 
   14754   353792725 :     if (VAR_P (decl) && !initialized)
   14755     4657162 :       if (tree auto_node = type_uses_auto (type))
   14756          70 :         if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
   14757             :           {
   14758          18 :             location_t loc = declspecs->locations[ds_type_spec];
   14759          18 :             error_at (loc, "declaration of %q#D has no initializer", decl);
   14760          18 :             TREE_TYPE (decl) = error_mark_node;
   14761             :           }
   14762             : 
   14763   353792725 :     if (storage_class == sc_extern && initialized && !funcdef_flag)
   14764             :       {
   14765         250 :         if (toplevel_bindings_p ())
   14766             :           {
   14767             :             /* It's common practice (and completely valid) to have a const
   14768             :                be initialized and declared extern.  */
   14769         242 :             if (!(type_quals & TYPE_QUAL_CONST))
   14770          25 :               warning_at (DECL_SOURCE_LOCATION (decl), 0,
   14771             :                           "%qs initialized and declared %<extern%>", name);
   14772             :           }
   14773             :         else
   14774             :           {
   14775           8 :             error_at (DECL_SOURCE_LOCATION (decl),
   14776             :                       "%qs has both %<extern%> and initializer", name);
   14777           8 :             return error_mark_node;
   14778             :           }
   14779             :       }
   14780             : 
   14781             :     /* Record `register' declaration for warnings on &
   14782             :        and in case doing stupid register allocation.  */
   14783             : 
   14784   353792717 :     if (storage_class == sc_register)
   14785             :       {
   14786        2720 :         DECL_REGISTER (decl) = 1;
   14787             :         /* Warn about register storage specifiers on PARM_DECLs.  */
   14788        2720 :         if (TREE_CODE (decl) == PARM_DECL)
   14789             :           {
   14790          48 :             if (cxx_dialect >= cxx17)
   14791          22 :               pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   14792             :                        "ISO C++17 does not allow %<register%> storage "
   14793             :                        "class specifier");
   14794             :             else
   14795          26 :               warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
   14796             :                           "%<register%> storage class specifier used");
   14797             :           }
   14798             :       }
   14799   353789997 :     else if (storage_class == sc_extern)
   14800    21575418 :       DECL_THIS_EXTERN (decl) = 1;
   14801   332214579 :     else if (storage_class == sc_static)
   14802    12744657 :       DECL_THIS_STATIC (decl) = 1;
   14803             : 
   14804   353792717 :     if (VAR_P (decl))
   14805             :       {
   14806             :         /* Set constexpr flag on vars (functions got it in grokfndecl).  */
   14807    42456398 :         if (constexpr_p)
   14808     7963236 :           DECL_DECLARED_CONSTEXPR_P (decl) = true;
   14809             :         /* And the constinit flag (which only applies to variables).  */
   14810    34493162 :         else if (constinit_p)
   14811         152 :           DECL_DECLARED_CONSTINIT_P (decl) = true;
   14812             :       }
   14813   311336319 :     else if (TREE_CODE (decl) == FUNCTION_DECL)
   14814             :       {
   14815             :         /* If we saw a return type, record its location.  */
   14816   112474990 :         location_t loc = declspecs->locations[ds_type_spec];
   14817   112474990 :         if (loc == UNKNOWN_LOCATION)
   14818             :           /* Build DECL_RESULT in start_preparsed_function.  */;
   14819    94080524 :         else if (!DECL_RESULT (decl))
   14820             :           {
   14821    94054148 :             tree restype = TREE_TYPE (TREE_TYPE (decl));
   14822    94054148 :             tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   14823    94054148 :             DECL_ARTIFICIAL (resdecl) = 1;
   14824    94054148 :             DECL_IGNORED_P (resdecl) = 1;
   14825    94054148 :             DECL_RESULT (decl) = resdecl;
   14826             :           }
   14827       26376 :         else if (funcdef_flag)
   14828           4 :           DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
   14829             :       }
   14830             : 
   14831             :     /* Record constancy and volatility on the DECL itself .  There's
   14832             :        no need to do this when processing a template; we'll do this
   14833             :        for the instantiated declaration based on the type of DECL.  */
   14834   353792717 :     if (!processing_template_decl)
   14835   121410835 :       cp_apply_type_quals_to_decl (type_quals, decl);
   14836             : 
   14837   353792717 :     return decl;
   14838             :   }
   14839   606108064 : }
   14840             : 
   14841             : /* Subroutine of start_function.  Ensure that each of the parameter
   14842             :    types (as listed in PARMS) is complete, as is required for a
   14843             :    function definition.  */
   14844             : 
   14845             : static void
   14846    90434883 : require_complete_types_for_parms (tree parms)
   14847             : {
   14848   272267141 :   for (; parms; parms = DECL_CHAIN (parms))
   14849             :     {
   14850   181832258 :       if (dependent_type_p (TREE_TYPE (parms)))
   14851   107061433 :         continue;
   14852    74770825 :       if (!VOID_TYPE_P (TREE_TYPE (parms))
   14853    74770825 :           && complete_type_or_else (TREE_TYPE (parms), parms))
   14854             :         {
   14855    74770737 :           relayout_decl (parms);
   14856    74770737 :           DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
   14857             : 
   14858    74770737 :           abstract_virtuals_error (parms, TREE_TYPE (parms));
   14859    74770737 :           maybe_warn_parm_abi (TREE_TYPE (parms),
   14860    74770737 :                                DECL_SOURCE_LOCATION (parms));
   14861             :         }
   14862             :       else
   14863             :         /* grokparms or complete_type_or_else will have already issued
   14864             :            an error.  */
   14865          88 :         TREE_TYPE (parms) = error_mark_node;
   14866             :     }
   14867    90434883 : }
   14868             : 
   14869             : /* Returns nonzero if T is a local variable.  */
   14870             : 
   14871             : int
   14872    45561096 : local_variable_p (const_tree t)
   14873             : {
   14874    45561096 :   if ((VAR_P (t)
   14875    38087673 :        && (DECL_LOCAL_DECL_P (t)
   14876    38087673 :            || !DECL_CONTEXT (t)
   14877    38057689 :            || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
   14878    47166492 :       || (TREE_CODE (t) == PARM_DECL))
   14879    36482307 :     return 1;
   14880             : 
   14881             :   return 0;
   14882             : }
   14883             : 
   14884             : /* Like local_variable_p, but suitable for use as a tree-walking
   14885             :    function.  */
   14886             : 
   14887             : static tree
   14888     3470448 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
   14889             :                          void * /*data*/)
   14890             : {
   14891     3470448 :   if (unevaluated_p (TREE_CODE (*tp)))
   14892             :     {
   14893             :       /* DR 2082 permits local variables in unevaluated contexts
   14894             :          within a default argument.  */
   14895          16 :       *walk_subtrees = 0;
   14896          16 :       return NULL_TREE;
   14897             :     }
   14898             : 
   14899     3470432 :   if (local_variable_p (*tp)
   14900     3470432 :       && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
   14901             :     return *tp;
   14902     3470432 :   else if (TYPE_P (*tp))
   14903          16 :     *walk_subtrees = 0;
   14904             : 
   14905             :   return NULL_TREE;
   14906             : }
   14907             : 
   14908             : /* Check that ARG, which is a default-argument expression for a
   14909             :    parameter DECL, is valid.  Returns ARG, or ERROR_MARK_NODE, if
   14910             :    something goes wrong.  DECL may also be a _TYPE node, rather than a
   14911             :    DECL, if there is no DECL available.  */
   14912             : 
   14913             : tree
   14914     1744071 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
   14915             : {
   14916     1744071 :   tree var;
   14917     1744071 :   tree decl_type;
   14918             : 
   14919     1744071 :   if (TREE_CODE (arg) == DEFERRED_PARSE)
   14920             :     /* We get a DEFERRED_PARSE when looking at an in-class declaration
   14921             :        with a default argument.  Ignore the argument for now; we'll
   14922             :        deal with it after the class is complete.  */
   14923             :     return arg;
   14924             : 
   14925     1260131 :   if (TYPE_P (decl))
   14926             :     {
   14927             :       decl_type = decl;
   14928             :       decl = NULL_TREE;
   14929             :     }
   14930             :   else
   14931      392005 :     decl_type = TREE_TYPE (decl);
   14932             : 
   14933     1260131 :   if (arg == error_mark_node
   14934     1259996 :       || decl == error_mark_node
   14935     1259984 :       || TREE_TYPE (arg) == error_mark_node
   14936     2520115 :       || decl_type == error_mark_node)
   14937             :     /* Something already went wrong.  There's no need to check
   14938             :        further.  */
   14939             :     return error_mark_node;
   14940             : 
   14941             :   /* [dcl.fct.default]
   14942             : 
   14943             :      A default argument expression is implicitly converted to the
   14944             :      parameter type.  */
   14945     1259984 :   ++cp_unevaluated_operand;
   14946             :   /* Avoid digest_init clobbering the initializer.  */
   14947     1259984 :   tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
   14948     1259984 :   perform_implicit_conversion_flags (decl_type, carg, complain,
   14949             :                                      LOOKUP_IMPLICIT);
   14950     1259984 :   --cp_unevaluated_operand;
   14951             : 
   14952             :   /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
   14953             :      the call sites.  */
   14954      904281 :   if (TYPE_PTR_OR_PTRMEM_P (decl_type)
   14955      355715 :       && null_ptr_cst_p (arg)
   14956             :       /* Don't lose side-effects as in PR90473.  */
   14957     1513632 :       && !TREE_SIDE_EFFECTS (arg))
   14958      253645 :     return nullptr_node;
   14959             : 
   14960             :   /* [dcl.fct.default]
   14961             : 
   14962             :      Local variables shall not be used in default argument
   14963             :      expressions.
   14964             : 
   14965             :      The keyword `this' shall not be used in a default argument of a
   14966             :      member function.  */
   14967     1006339 :   var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
   14968     1006339 :   if (var)
   14969             :     {
   14970           0 :       if (complain & tf_warning_or_error)
   14971             :         {
   14972           0 :           if (DECL_NAME (var) == this_identifier)
   14973           0 :             permerror (input_location, "default argument %qE uses %qD",
   14974             :                        arg, var);
   14975             :           else
   14976           0 :             error ("default argument %qE uses local variable %qD", arg, var);
   14977             :         }
   14978           0 :       return error_mark_node;
   14979             :     }
   14980             : 
   14981             :   /* All is well.  */
   14982     1006339 :   return arg;
   14983             : }
   14984             : 
   14985             : /* Returns a deprecated type used within TYPE, or NULL_TREE if none.  */
   14986             : 
   14987             : static tree
   14988   178291078 : type_is_deprecated (tree type)
   14989             : {
   14990   262851492 :   enum tree_code code;
   14991   262851492 :   if (TREE_DEPRECATED (type))
   14992             :     return type;
   14993   262851407 :   if (TYPE_NAME (type))
   14994             :     {
   14995   175541843 :       if (TREE_DEPRECATED (TYPE_NAME (type)))
   14996             :         return type;
   14997             :       else
   14998             :         {
   14999   175541835 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   15000   175541835 :           return NULL_TREE;
   15001             :         }
   15002             :     }
   15003             : 
   15004             :   /* Do warn about using typedefs to a deprecated class.  */
   15005    87309564 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   15006           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   15007             : 
   15008    87309564 :   code = TREE_CODE (type);
   15009             : 
   15010    87309564 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   15011    87309564 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   15012     3325280 :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   15013    84477537 :     return type_is_deprecated (TREE_TYPE (type));
   15014             : 
   15015     2832027 :   if (TYPE_PTRMEMFUNC_P (type))
   15016       82877 :     return type_is_deprecated
   15017       82877 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   15018             : 
   15019             :   return NULL_TREE;
   15020             : }
   15021             : 
   15022             : /* Returns an unavailable type used within TYPE, or NULL_TREE if none.  */
   15023             : 
   15024             : static tree
   15025   178794300 : type_is_unavailable (tree type)
   15026             : {
   15027   263683628 :   enum tree_code code;
   15028   263683628 :   if (TREE_UNAVAILABLE (type))
   15029             :     return type;
   15030   263683620 :   if (TYPE_NAME (type))
   15031             :     {
   15032   176017838 :       if (TREE_UNAVAILABLE (TYPE_NAME (type)))
   15033             :         return type;
   15034             :       else
   15035             :         {
   15036   176017830 :           cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
   15037   176017830 :           return NULL_TREE;
   15038             :         }
   15039             :     }
   15040             : 
   15041             :   /* Do warn about using typedefs to a deprecated class.  */
   15042    87665782 :   if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
   15043           0 :     return type_is_deprecated (TYPE_MAIN_VARIANT (type));
   15044             : 
   15045    87665782 :   code = TREE_CODE (type);
   15046             : 
   15047    87665782 :   if (code == POINTER_TYPE || code == REFERENCE_TYPE
   15048    87665782 :       || code == OFFSET_TYPE || code == FUNCTION_TYPE
   15049     3450244 :       || code == METHOD_TYPE || code == ARRAY_TYPE)
   15050    84728323 :     return type_is_unavailable (TREE_TYPE (type));
   15051             : 
   15052     2937459 :   if (TYPE_PTRMEMFUNC_P (type))
   15053      161005 :     return type_is_unavailable
   15054      161005 :       (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
   15055             : 
   15056             :   return NULL_TREE;
   15057             : }
   15058             : 
   15059             : /* Decode the list of parameter types for a function type.
   15060             :    Given the list of things declared inside the parens,
   15061             :    return a list of types.
   15062             : 
   15063             :    If this parameter does not end with an ellipsis, we append
   15064             :    void_list_node.
   15065             : 
   15066             :    *PARMS is set to the chain of PARM_DECLs created.  */
   15067             : 
   15068             : tree
   15069   116548349 : grokparms (tree parmlist, tree *parms)
   15070             : {
   15071   116548349 :   tree result = NULL_TREE;
   15072   116548349 :   tree decls = NULL_TREE;
   15073   116548349 :   tree parm;
   15074   116548349 :   int any_error = 0;
   15075             : 
   15076   295799607 :   for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
   15077             :     {
   15078   294889660 :       tree type = NULL_TREE;
   15079   294889660 :       tree init = TREE_PURPOSE (parm);
   15080   294889660 :       tree decl = TREE_VALUE (parm);
   15081             : 
   15082   294889660 :       if (parm == void_list_node || parm == explicit_void_list_node)
   15083             :         break;
   15084             : 
   15085   179251274 :       if (! decl || TREE_TYPE (decl) == error_mark_node)
   15086             :         {
   15087         126 :           any_error = 1;
   15088         126 :           continue;
   15089             :         }
   15090             : 
   15091   179251148 :       type = TREE_TYPE (decl);
   15092   179251148 :       if (VOID_TYPE_P (type))
   15093             :         {
   15094         102 :           if (same_type_p (type, void_type_node)
   15095          91 :               && !init
   15096          75 :               && !DECL_NAME (decl) && !result
   15097         134 :               && TREE_CHAIN (parm) == void_list_node)
   15098             :             /* DR 577: A parameter list consisting of a single
   15099             :                unnamed parameter of non-dependent type 'void'.  */
   15100             :             break;
   15101          86 :           else if (cv_qualified_p (type))
   15102          11 :             error_at (DECL_SOURCE_LOCATION (decl),
   15103             :                       "invalid use of cv-qualified type %qT in "
   15104             :                       "parameter declaration", type);
   15105             :           else
   15106          75 :             error_at (DECL_SOURCE_LOCATION (decl),
   15107             :                       "invalid use of type %<void%> in parameter "
   15108             :                       "declaration");
   15109             :           /* It's not a good idea to actually create parameters of
   15110             :              type `void'; other parts of the compiler assume that a
   15111             :              void type terminates the parameter list.  */
   15112          86 :           type = error_mark_node;
   15113          86 :           TREE_TYPE (decl) = error_mark_node;
   15114             :         }
   15115             : 
   15116   179251132 :       if (type != error_mark_node)
   15117             :         {
   15118   179251046 :           if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   15119             :             {
   15120   178794300 :               tree unavailtype = type_is_unavailable (type);
   15121   178794300 :               if (unavailtype)
   15122          16 :                 cp_handle_deprecated_or_unavailable (unavailtype);
   15123             :             }
   15124   179251046 :           if (deprecated_state != DEPRECATED_SUPPRESS
   15125   179251046 :               && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
   15126             :             {
   15127   178291078 :               tree deptype = type_is_deprecated (type);
   15128   178291078 :               if (deptype)
   15129          93 :                 cp_handle_deprecated_or_unavailable (deptype);
   15130             :             }
   15131             : 
   15132             :           /* [dcl.fct] "A parameter with volatile-qualified type is
   15133             :              deprecated."  */
   15134   179251046 :           if (CP_TYPE_VOLATILE_P (type))
   15135         599 :             warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
   15136             :                         "%<volatile%>-qualified parameter is "
   15137             :                         "deprecated");
   15138             : 
   15139             :           /* Top-level qualifiers on the parameters are
   15140             :              ignored for function types.  */
   15141   179251046 :           type = cp_build_qualified_type (type, 0);
   15142   179251046 :           if (TREE_CODE (type) == METHOD_TYPE)
   15143             :             {
   15144           0 :               error ("parameter %qD invalidly declared method type", decl);
   15145           0 :               type = build_pointer_type (type);
   15146           0 :               TREE_TYPE (decl) = type;
   15147             :             }
   15148   179251046 :           else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
   15149             :             {
   15150             :               /* Before C++17 DR 393:
   15151             :                  [dcl.fct]/6, parameter types cannot contain pointers
   15152             :                  (references) to arrays of unknown bound.  */
   15153     2284284 :               tree t = TREE_TYPE (type);
   15154     2284284 :               int ptr = TYPE_PTR_P (type);
   15155             : 
   15156     2459212 :               while (1)
   15157             :                 {
   15158     2371748 :                   if (TYPE_PTR_P (t))
   15159             :                     ptr = 1;
   15160     2288970 :                   else if (TREE_CODE (t) != ARRAY_TYPE)
   15161             :                     break;
   15162        4699 :                   else if (!TYPE_DOMAIN (t))
   15163             :                     break;
   15164       87464 :                   t = TREE_TYPE (t);
   15165             :                 }
   15166     2284284 :               if (TREE_CODE (t) == ARRAY_TYPE)
   15167          20 :                 pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
   15168             :                          ptr
   15169             :                          ? G_("parameter %qD includes pointer to array of "
   15170             :                               "unknown bound %qT")
   15171             :                          : G_("parameter %qD includes reference to array of "
   15172             :                               "unknown bound %qT"),
   15173             :                          decl, t);
   15174             :             }
   15175             : 
   15176   179251046 :           if (init && !processing_template_decl)
   15177      875933 :             init = check_default_argument (decl, init, tf_warning_or_error);
   15178             :         }
   15179             : 
   15180   179251132 :       DECL_CHAIN (decl) = decls;
   15181   179251132 :       decls = decl;
   15182   179251132 :       result = tree_cons (init, type, result);
   15183             :     }
   15184   116548349 :   decls = nreverse (decls);
   15185   116548349 :   result = nreverse (result);
   15186   116548349 :   if (parm)
   15187   115638402 :     result = chainon (result, void_list_node);
   15188   116548349 :   *parms = decls;
   15189   116548349 :   if (any_error)
   15190         110 :     result = NULL_TREE;
   15191             : 
   15192         110 :   if (any_error)
   15193             :     /* We had parm errors, recover by giving the function (...) type.  */
   15194             :     result = NULL_TREE;
   15195             : 
   15196   116548349 :   return result;
   15197             : }
   15198             : 
   15199             : 
   15200             : /* D is a constructor or overloaded `operator='.
   15201             : 
   15202             :    Let T be the class in which D is declared. Then, this function
   15203             :    returns:
   15204             : 
   15205             :    -1 if D's is an ill-formed constructor or copy assignment operator
   15206             :       whose first parameter is of type `T'.
   15207             :    0  if D is not a copy constructor or copy assignment
   15208             :       operator.
   15209             :    1  if D is a copy constructor or copy assignment operator whose
   15210             :       first parameter is a reference to non-const qualified T.
   15211             :    2  if D is a copy constructor or copy assignment operator whose
   15212             :       first parameter is a reference to const qualified T.
   15213             : 
   15214             :    This function can be used as a predicate. Positive values indicate
   15215             :    a copy constructor and nonzero values indicate a copy assignment
   15216             :    operator.  */
   15217             : 
   15218             : int
   15219   172942881 : copy_fn_p (const_tree d)
   15220             : {
   15221   172942881 :   tree args;
   15222   172942881 :   tree arg_type;
   15223   172942881 :   int result = 1;
   15224             : 
   15225   172942881 :   gcc_assert (DECL_FUNCTION_MEMBER_P (d));
   15226             : 
   15227   172942881 :   if (TREE_CODE (d) == TEMPLATE_DECL
   15228   172942881 :       || (DECL_TEMPLATE_INFO (d)
   15229    81823260 :           && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   15230             :     /* Instantiations of template member functions are never copy
   15231             :        functions.  Note that member functions of templated classes are
   15232             :        represented as template functions internally, and we must
   15233             :        accept those as copy functions.  */
   15234             :     return 0;
   15235             : 
   15236   143457154 :   if (!DECL_CONSTRUCTOR_P (d)
   15237   143457154 :       && DECL_NAME (d) != assign_op_identifier)
   15238             :     return 0;
   15239             : 
   15240   142401661 :   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   15241   142401661 :   if (!args)
   15242             :     return 0;
   15243             : 
   15244   142394756 :   arg_type = TREE_VALUE (args);
   15245   142394756 :   if (arg_type == error_mark_node)
   15246             :     return 0;
   15247             : 
   15248   142394710 :   if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
   15249             :     {
   15250             :       /* Pass by value copy assignment operator.  */
   15251             :       result = -1;
   15252             :     }
   15253   142394258 :   else if (TYPE_REF_P (arg_type)
   15254    88333219 :            && !TYPE_REF_IS_RVALUE (arg_type)
   15255   198565691 :            && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
   15256             :     {
   15257    43635340 :       if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
   15258    43590266 :         result = 2;
   15259             :     }
   15260             :   else
   15261             :     return 0;
   15262             : 
   15263    43635792 :   args = TREE_CHAIN (args);
   15264             : 
   15265    45417691 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15266             :     /* There are more non-optional args.  */
   15267             :     return 0;
   15268             : 
   15269             :   return result;
   15270             : }
   15271             : 
   15272             : /* D is a constructor or overloaded `operator='.
   15273             : 
   15274             :    Let T be the class in which D is declared. Then, this function
   15275             :    returns true when D is a move constructor or move assignment
   15276             :    operator, false otherwise.  */
   15277             : 
   15278             : bool
   15279    62152965 : move_fn_p (const_tree d)
   15280             : {
   15281    62152965 :   if (cxx_dialect == cxx98)
   15282             :     /* There are no move constructors if we are in C++98 mode.  */
   15283             :     return false;
   15284             : 
   15285    62102311 :   if (TREE_CODE (d) == TEMPLATE_DECL
   15286    62102311 :       || (DECL_TEMPLATE_INFO (d)
   15287    25480464 :          && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
   15288             :     /* Instantiations of template member functions are never move
   15289             :        functions.  Note that member functions of templated classes are
   15290             :        represented as template functions internally, and we must
   15291             :        accept those as move functions.  */
   15292             :     return 0;
   15293             : 
   15294    49805229 :   return move_signature_fn_p (d);
   15295             : }
   15296             : 
   15297             : /* D is a constructor or overloaded `operator='.
   15298             : 
   15299             :    Then, this function returns true when D has the same signature as a move
   15300             :    constructor or move assignment operator (because either it is such a
   15301             :    ctor/op= or it is a template specialization with the same signature),
   15302             :    false otherwise.  */
   15303             : 
   15304             : bool
   15305    49805229 : move_signature_fn_p (const_tree d)
   15306             : {
   15307    49805229 :   tree args;
   15308    49805229 :   tree arg_type;
   15309    49805229 :   bool result = false;
   15310             : 
   15311    49805229 :   if (!DECL_CONSTRUCTOR_P (d)
   15312    49805229 :       && DECL_NAME (d) != assign_op_identifier)
   15313             :     return 0;
   15314             : 
   15315    49805180 :   args = FUNCTION_FIRST_USER_PARMTYPE (d);
   15316    49805180 :   if (!args)
   15317             :     return 0;
   15318             : 
   15319    49802717 :   arg_type = TREE_VALUE (args);
   15320    49802717 :   if (arg_type == error_mark_node)
   15321             :     return 0;
   15322             : 
   15323    49802705 :   if (TYPE_REF_P (arg_type)
   15324    25810144 :       && TYPE_REF_IS_RVALUE (arg_type)
   15325    70231929 :       && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
   15326             :                       DECL_CONTEXT (d)))
   15327             :     result = true;
   15328             : 
   15329    49802705 :   args = TREE_CHAIN (args);
   15330             : 
   15331    54671561 :   if (args && args != void_list_node && !TREE_PURPOSE (args))
   15332             :     /* There are more non-optional args.  */
   15333             :     return false;
   15334             : 
   15335             :   return result;
   15336             : }
   15337             : 
   15338             : /* Remember any special properties of member function DECL.  */
   15339             : 
   15340             : void
   15341   184508125 : grok_special_member_properties (tree decl)
   15342             : {
   15343   184508125 :   tree class_type;
   15344             : 
   15345   184508125 :   if (TREE_CODE (decl) == USING_DECL
   15346   184508125 :       || !DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
   15347             :     return;
   15348             : 
   15349   172647968 :   class_type = DECL_CONTEXT (decl);
   15350   172647968 :   if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
   15351             :     {
   15352    74976579 :       int ctor = copy_fn_p (decl);
   15353             : 
   15354    74976579 :       if (!DECL_ARTIFICIAL (decl))
   15355    58402950 :         TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
   15356             : 
   15357    74976579 :       if (ctor > 0)
   15358             :         {
   15359             :           /* [class.copy]
   15360             : 
   15361             :              A non-template constructor for class X is a copy
   15362             :              constructor if its first parameter is of type X&, const
   15363             :              X&, volatile X& or const volatile X&, and either there
   15364             :              are no other parameters or else all other parameters have
   15365             :              default arguments.  */
   15366    14385030 :           TYPE_HAS_COPY_CTOR (class_type) = 1;
   15367    14385030 :           if (ctor > 1)
   15368    14374164 :             TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
   15369             :         }
   15370             : 
   15371    74976579 :       if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
   15372    15487794 :         TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
   15373             : 
   15374    74976579 :       if (is_list_ctor (decl))
   15375      929983 :         TYPE_HAS_LIST_CTOR (class_type) = 1;
   15376             : 
   15377    74976579 :       if (maybe_constexpr_fn (decl)
   15378    74976579 :           && !ctor && !move_fn_p (decl))
   15379    14008061 :         TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
   15380             :     }
   15381    97671389 :   else if (DECL_NAME (decl) == assign_op_identifier)
   15382             :     {
   15383             :       /* [class.copy]
   15384             : 
   15385             :          A non-template assignment operator for class X is a copy
   15386             :          assignment operator if its parameter is of type X, X&, const
   15387             :          X&, volatile X& or const volatile X&.  */
   15388             : 
   15389     8563158 :       int assop = copy_fn_p (decl);
   15390             : 
   15391     8563158 :       if (assop)
   15392             :         {
   15393     4270784 :           TYPE_HAS_COPY_ASSIGN (class_type) = 1;
   15394     4270784 :           if (assop != 1)
   15395     4249515 :             TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
   15396             :         }
   15397             :     }
   15398    89108231 :   else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
   15399     1025972 :     TYPE_HAS_CONVERSION (class_type) = true;
   15400             :   
   15401             :   /* Destructors are handled in check_methods.  */
   15402             : }
   15403             : 
   15404             : /* Check a constructor DECL has the correct form.  Complains
   15405             :    if the class has a constructor of the form X(X).  */
   15406             : 
   15407             : bool
   15408    27191727 : grok_ctor_properties (const_tree ctype, const_tree decl)
   15409             : {
   15410    27191727 :   int ctor_parm = copy_fn_p (decl);
   15411             : 
   15412    27191727 :   if (ctor_parm < 0)
   15413             :     {
   15414             :       /* [class.copy]
   15415             : 
   15416             :          A declaration of a constructor for a class X is ill-formed if
   15417             :          its first parameter is of type (optionally cv-qualified) X
   15418             :          and either there are no other parameters or else all other
   15419             :          parameters have default arguments.
   15420             : 
   15421             :          We *don't* complain about member template instantiations that
   15422             :          have this form, though; they can occur as we try to decide
   15423             :          what constructor to use during overload resolution.  Since
   15424             :          overload resolution will never prefer such a constructor to
   15425             :          the non-template copy constructor (which is either explicitly
   15426             :          or implicitly defined), there's no need to worry about their
   15427             :          existence.  Theoretically, they should never even be
   15428             :          instantiated, but that's hard to forestall.  */
   15429          12 :       error_at (DECL_SOURCE_LOCATION (decl),
   15430             :                 "invalid constructor; you probably meant %<%T (const %T&)%>",
   15431             :                 ctype, ctype);
   15432          12 :       return false;
   15433             :     }
   15434             : 
   15435             :   return true;
   15436             : }
   15437             : 
   15438             : /* DECL is a declaration for an overloaded or conversion operator.  If
   15439             :    COMPLAIN is true, errors are issued for invalid declarations.  */
   15440             : 
   15441             : bool
   15442    31846671 : grok_op_properties (tree decl, bool complain)
   15443             : {
   15444    31846671 :   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
   15445    31846671 :   bool methodp = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE;
   15446    31846671 :   tree name = DECL_NAME (decl);
   15447    31846671 :   location_t loc = DECL_SOURCE_LOCATION (decl);
   15448             : 
   15449    31846671 :   tree class_type = DECL_CONTEXT (decl);
   15450    31846671 :   if (class_type && !CLASS_TYPE_P (class_type))
   15451             :     class_type = NULL_TREE;
   15452             : 
   15453    31846671 :   tree_code operator_code;
   15454    31846671 :   unsigned op_flags;
   15455    31846671 :   if (IDENTIFIER_CONV_OP_P (name))
   15456             :     {
   15457             :       /* Conversion operators are TYPE_EXPR for the purposes of this
   15458             :          function.  */
   15459             :       operator_code = TYPE_EXPR;
   15460             :       op_flags = OVL_OP_FLAG_UNARY;
   15461             :     }
   15462             :   else
   15463             :     {
   15464    31035171 :       const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
   15465             : 
   15466    31035171 :       operator_code = ovl_op->tree_code;
   15467    31035171 :       op_flags = ovl_op->flags;
   15468    31035171 :       gcc_checking_assert (operator_code != ERROR_MARK);
   15469    31035171 :       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   15470             :     }
   15471             : 
   15472    31846671 :   if (op_flags & OVL_OP_FLAG_ALLOC)
   15473             :     {
   15474             :       /* operator new and operator delete are quite special.  */
   15475      241652 :       if (class_type)
   15476        2181 :         switch (op_flags)
   15477             :           {
   15478        1061 :           case OVL_OP_FLAG_ALLOC:
   15479        1061 :             TYPE_HAS_NEW_OPERATOR (class_type) = 1;
   15480        1061 :             break;
   15481             : 
   15482         800 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
   15483         800 :             TYPE_GETS_DELETE (class_type) |= 1;
   15484         800 :             break;
   15485             : 
   15486         162 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
   15487         162 :             TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
   15488         162 :             break;
   15489             : 
   15490         158 :           case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
   15491         158 :             TYPE_GETS_DELETE (class_type) |= 2;
   15492         158 :             break;
   15493             : 
   15494           0 :           default:
   15495           0 :             gcc_unreachable ();
   15496             :           }
   15497             : 
   15498             :       /* [basic.std.dynamic.allocation]/1:
   15499             : 
   15500             :          A program is ill-formed if an allocation function is declared
   15501             :          in a namespace scope other than global scope or declared
   15502             :          static in global scope.
   15503             : 
   15504             :          The same also holds true for deallocation functions.  */
   15505      241652 :       if (DECL_NAMESPACE_SCOPE_P (decl))
   15506             :         {
   15507      239471 :           if (CP_DECL_CONTEXT (decl) != global_namespace)
   15508             :             {
   15509           8 :               error_at (loc, "%qD may not be declared within a namespace",
   15510             :                         decl);
   15511           8 :               return false;
   15512             :             }
   15513             : 
   15514      239463 :           if (!TREE_PUBLIC (decl))
   15515             :             {
   15516           8 :               error_at (loc, "%qD may not be declared as static", decl);
   15517           8 :               return false;
   15518             :             }
   15519             :         }
   15520             : 
   15521      241636 :       if (op_flags & OVL_OP_FLAG_DELETE)
   15522             :         {
   15523      139300 :           DECL_SET_IS_OPERATOR_DELETE (decl, true);
   15524      139300 :           coerce_delete_type (decl, loc);
   15525             :         }
   15526             :       else
   15527             :         {
   15528      102336 :           DECL_SET_IS_OPERATOR_NEW (decl, true);
   15529      102336 :           TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
   15530             :         }
   15531             : 
   15532      241636 :       return true;
   15533             :     }
   15534             : 
   15535             :   /* An operator function must either be a non-static member function
   15536             :      or have at least one parameter of a class, a reference to a class,
   15537             :      an enumeration, or a reference to an enumeration.  13.4.0.6 */
   15538    31605019 :   if (! methodp || DECL_STATIC_FUNCTION_P (decl))
   15539             :     {
   15540     9330260 :       if (operator_code == TYPE_EXPR
   15541     9330260 :           || operator_code == COMPONENT_REF
   15542     9330232 :           || operator_code == NOP_EXPR)
   15543             :         {
   15544          40 :           error_at (loc, "%qD must be a non-static member function", decl);
   15545          40 :           return false;
   15546             :         }
   15547             : 
   15548     9330220 :       if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
   15549             :         {
   15550         103 :           if (! DECL_STATIC_FUNCTION_P (decl))
   15551             :             {
   15552          16 :               error_at (loc, "%qD must be a member function", decl);
   15553          16 :               return false;
   15554             :             }
   15555          87 :           if (cxx_dialect < cxx23
   15556             :               /* For lambdas we diagnose static lambda specifier elsewhere.  */
   15557          99 :               && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
   15558             :               /* For instantiations, we have diagnosed this already.  */
   15559         122 :               && ! DECL_USE_TEMPLATE (decl))
   15560          29 :             pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
   15561             :                      "function only with %<-std=c++23%> or %<-std=gnu++23%>",
   15562             :                      decl);
   15563          87 :           if (operator_code == ARRAY_REF)
   15564             :             /* static operator[] should have exactly one argument
   15565             :                for C++20 and earlier, so that it isn't multidimensional.  */
   15566             :             op_flags = OVL_OP_FLAG_UNARY;
   15567             :         }
   15568     9330117 :       else if (DECL_STATIC_FUNCTION_P (decl))
   15569             :         {
   15570           9 :           error_at (loc, "%qD must be either a non-static member "
   15571             :                     "function or a non-member function", decl);
   15572           9 :           return false;
   15573             :         }
   15574             :       else
   15575      317037 :         for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
   15576             :           {
   15577     9647145 :             if (!arg || arg == void_list_node)
   15578             :               {
   15579          24 :                 if (complain)
   15580          20 :                   error_at (loc, "%qD must have an argument of class or "
   15581             :                             "enumerated type", decl);
   15582          24 :                 return false;
   15583             :               }
   15584             :       
   15585     9647121 :             tree type = non_reference (TREE_VALUE (arg));
   15586     9647121 :             if (type == error_mark_node)
   15587             :               return false;
   15588             : 
   15589             :             /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
   15590             :                because these checks are performed even on template
   15591             :                functions.  */
   15592     8115809 :             if (MAYBE_CLASS_TYPE_P (type)
   15593    10629989 :                 || TREE_CODE (type) == ENUMERAL_TYPE)
   15594             :               break;
   15595      317037 :           }
   15596             :     }
   15597             : 
   15598    31604889 :   if (operator_code == CALL_EXPR)
   15599             :     /* There are no further restrictions on the arguments to an overloaded
   15600             :        "operator ()".  */
   15601             :     return true;
   15602             : 
   15603             :   /* C++23 allows an arbitrary number of parameters and default arguments for
   15604             :      operator[], and none of the other checks below apply.  */
   15605    28452172 :   if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
   15606             :     return true;
   15607             : 
   15608    28446886 :   if (operator_code == COND_EXPR)
   15609             :     {
   15610             :       /* 13.4.0.3 */
   15611           8 :       error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
   15612           8 :       return false;
   15613             :     }
   15614             : 
   15615             :   /* Count the number of arguments and check for ellipsis.  */
   15616             :   int arity = 0;
   15617    81775416 :   for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
   15618             :     {
   15619    53328558 :       if (!arg)
   15620             :         {
   15621          20 :           error_at (loc, "%qD must not have variable number of arguments",
   15622             :                     decl);
   15623          20 :           return false;
   15624             :         }
   15625    53328538 :       ++arity;
   15626             :     }
   15627             : 
   15628             :   /* Verify correct number of arguments.  */
   15629    28446858 :   switch (op_flags)
   15630             :     {
   15631     4626164 :     case OVL_OP_FLAG_AMBIARY:
   15632     4626164 :       if (arity == 1)
   15633             :         {
   15634             :           /* We have a unary instance of an ambi-ary op.  Remap to the
   15635             :              unary one.  */
   15636     2131639 :           unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
   15637     2131639 :           const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
   15638     2131639 :           gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
   15639     2131639 :           operator_code = ovl_op->tree_code;
   15640     2131639 :           DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
   15641             :         }
   15642     2494525 :       else if (arity != 2)
   15643             :         {
   15644             :           /* This was an ambiguous operator but is invalid. */
   15645           4 :           error_at (loc,
   15646             :                     methodp
   15647             :                     ? G_("%qD must have either zero or one argument")
   15648             :                     : G_("%qD must have either one or two arguments"), decl);
   15649           4 :           return false;
   15650             :         }
   15651     2494521 :       else if ((operator_code == POSTINCREMENT_EXPR
   15652     2494521 :                 || operator_code == POSTDECREMENT_EXPR)
   15653     1289275 :                && ! processing_template_decl
   15654             :                /* x++ and x--'s second argument must be an int.  */
   15655     3415461 :                && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
   15656             :                                  integer_type_node))
   15657             :         {
   15658          20 :           error_at (loc,
   15659             :                     methodp
   15660             :                     ? G_("postfix %qD must have %<int%> as its argument")
   15661             :                     : G_("postfix %qD must have %<int%> as its second argument"),
   15662             :                     decl);
   15663          20 :           return false;
   15664             :         }
   15665             :       break;
   15666             : 
   15667     1433575 :     case OVL_OP_FLAG_UNARY:
   15668     1433575 :       if (arity != 1)
   15669             :         {
   15670          14 :           error_at (loc,
   15671             :                     methodp
   15672             :                     ? G_("%qD must have no arguments")
   15673             :                     : G_("%qD must have exactly one argument"), decl);
   15674          14 :           return false;
   15675             :         }
   15676             :       break;
   15677             : 
   15678    22387119 :     case OVL_OP_FLAG_BINARY:
   15679    22387119 :       if (arity != 2)
   15680             :         {
   15681           1 :           error_at (loc,
   15682             :                     methodp
   15683             :                     ? G_("%qD must have exactly one argument")
   15684             :                     : G_("%qD must have exactly two arguments"), decl);
   15685           1 :           return false;
   15686             :         }
   15687             :       break;
   15688             : 
   15689           0 :     default:
   15690           0 :       gcc_unreachable ();
   15691             :     }
   15692             : 
   15693             :   /* There can be no default arguments.  */
   15694    81775237 :   for (tree arg = argtypes; arg && arg != void_list_node;
   15695    53328418 :        arg = TREE_CHAIN (arg))
   15696    53328438 :     if (TREE_PURPOSE (arg))
   15697             :       {
   15698          20 :         TREE_PURPOSE (arg) = NULL_TREE;
   15699          20 :         error_at (loc, "%qD cannot have default arguments", decl);
   15700          20 :         return false;
   15701             :       }
   15702             : 
   15703             :   /* At this point the declaration is well-formed.  It may not be
   15704             :      sensible though.  */
   15705             : 
   15706             :   /* Check member function warnings only on the in-class declaration.
   15707             :      There's no point warning on an out-of-class definition.  */
   15708    28446799 :   if (class_type && class_type != current_class_type)
   15709             :     return true;
   15710             : 
   15711             :   /* Warn about conversion operators that will never be used.  */
   15712    27061626 :   if (IDENTIFIER_CONV_OP_P (name)
   15713      811074 :       && ! DECL_TEMPLATE_INFO (decl)
   15714    27374153 :       && warn_class_conversion)
   15715             :     {
   15716      312483 :       tree t = TREE_TYPE (name);
   15717      312483 :       int ref = TYPE_REF_P (t);
   15718             : 
   15719      312483 :       if (ref)
   15720       16867 :         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
   15721             : 
   15722      312483 :       if (VOID_TYPE_P (t))
   15723          12 :         warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
   15724             :                     "will never use a type conversion operator", class_type);
   15725      312471 :       else if (class_type)
   15726             :         {
   15727      312471 :           if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
   15728          32 :             warning_at (loc, OPT_Wclass_conversion,
   15729             :                         ref
   15730             :                         ? G_("converting %qT to a reference to the same type "
   15731             :                              "will never use a type conversion operator")
   15732             :                         : G_("converting %qT to the same type "
   15733             :                              "will never use a type conversion operator"),
   15734             :                         class_type);
   15735             :           /* Don't force t to be complete here.  */
   15736      256239 :           else if (MAYBE_CLASS_TYPE_P (t)
   15737      115306 :                    && COMPLETE_TYPE_P (t)
   15738      335583 :                    && DERIVED_FROM_P (t, class_type))
   15739          40 :             warning_at (loc, OPT_Wclass_conversion,
   15740             :                         ref
   15741             :                         ? G_("converting %qT to a reference to a base class "
   15742             :                              "%qT will never use a type conversion operator")
   15743             :                         : G_("converting %qT to a base class %qT "
   15744             :                              "will never use a type conversion operator"),
   15745             :                         class_type, t);
   15746             :         }
   15747             :     }
   15748             : 
   15749    27061626 :   if (!warn_ecpp)
   15750             :     return true;
   15751             : 
   15752             :   /* Effective C++ rules below.  */
   15753             : 
   15754             :   /* More Effective C++ rule 7.  */
   15755          72 :   if (operator_code == TRUTH_ANDIF_EXPR
   15756          72 :       || operator_code == TRUTH_ORIF_EXPR
   15757          72 :       || operator_code == COMPOUND_EXPR)
   15758           0 :     warning_at (loc, OPT_Weffc__,
   15759             :                 "user-defined %qD always evaluates both arguments", decl);
   15760             :   
   15761             :   /* More Effective C++ rule 6.  */
   15762          72 :   if (operator_code == POSTINCREMENT_EXPR
   15763             :       || operator_code == POSTDECREMENT_EXPR
   15764             :       || operator_code == PREINCREMENT_EXPR
   15765          72 :       || operator_code == PREDECREMENT_EXPR)
   15766             :     {
   15767           0 :       tree arg = TREE_VALUE (argtypes);
   15768           0 :       tree ret = TREE_TYPE (TREE_TYPE (decl));
   15769           0 :       if (methodp || TYPE_REF_P (arg))
   15770           0 :         arg = TREE_TYPE (arg);
   15771           0 :       arg = TYPE_MAIN_VARIANT (arg);
   15772             : 
   15773           0 :       if (operator_code == PREINCREMENT_EXPR
   15774             :           || operator_code == PREDECREMENT_EXPR)
   15775             :         {
   15776           0 :           if (!TYPE_REF_P (ret)
   15777           0 :               || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
   15778           0 :             warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
   15779             :                         build_reference_type (arg));
   15780             :         }
   15781             :       else
   15782             :         {
   15783           0 :           if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
   15784           0 :             warning_at (loc, OPT_Weffc__,
   15785             :                         "postfix %qD should return %qT", decl, arg);
   15786             :         }
   15787             :     }
   15788             : 
   15789             :   /* Effective C++ rule 23.  */
   15790          72 :   if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
   15791             :       && (operator_code == PLUS_EXPR
   15792          12 :           || operator_code == MINUS_EXPR
   15793          12 :           || operator_code == TRUNC_DIV_EXPR
   15794             :           || operator_code == MULT_EXPR
   15795             :           || operator_code == TRUNC_MOD_EXPR)
   15796          80 :       && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
   15797           4 :     warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
   15798             : 
   15799             :   return true;
   15800             : }
   15801             : 
   15802             : /* Return a string giving the keyword associate with CODE.  */
   15803             : 
   15804             : static const char *
   15805         139 : tag_name (enum tag_types code)
   15806             : {
   15807         139 :   switch (code)
   15808             :     {
   15809             :     case record_type:
   15810             :       return "struct";
   15811             :     case class_type:
   15812             :       return "class";
   15813             :     case union_type:
   15814             :       return "union";
   15815             :     case enum_type:
   15816             :       return "enum";
   15817             :     case typename_type:
   15818             :       return "typename";
   15819           0 :     default:
   15820           0 :       gcc_unreachable ();
   15821             :     }
   15822             : }
   15823             : 
   15824             : /* Name lookup in an elaborated-type-specifier (after the keyword
   15825             :    indicated by TAG_CODE) has found the TYPE_DECL DECL.  If the
   15826             :    elaborated-type-specifier is invalid, issue a diagnostic and return
   15827             :    error_mark_node; otherwise, return the *_TYPE to which it referred.
   15828             :    If ALLOW_TEMPLATE_P is true, TYPE may be a class template.  */
   15829             : 
   15830             : tree
   15831     7647587 : check_elaborated_type_specifier (enum tag_types tag_code,
   15832             :                                  tree decl,
   15833             :                                  bool allow_template_p)
   15834             : {
   15835     7647587 :   tree type;
   15836             : 
   15837             :   /* In the case of:
   15838             : 
   15839             :        struct S { struct S *p; };
   15840             : 
   15841             :      name lookup will find the TYPE_DECL for the implicit "S::S"
   15842             :      typedef.  Adjust for that here.  */
   15843     7647587 :   if (DECL_SELF_REFERENCE_P (decl))
   15844      196867 :     decl = TYPE_NAME (TREE_TYPE (decl));
   15845             : 
   15846     7647587 :   type = TREE_TYPE (decl);
   15847             : 
   15848             :   /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
   15849             :      is false for this case as well.  */
   15850     7647587 :   if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
   15851             :     {
   15852          12 :       error ("using template type parameter %qT after %qs",
   15853             :              type, tag_name (tag_code));
   15854          12 :       return error_mark_node;
   15855             :     }
   15856             :   /* Accept template template parameters.  */
   15857     7647575 :   else if (allow_template_p
   15858     4320264 :            && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
   15859     4320249 :                || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
   15860             :     ;
   15861             :   /*   [dcl.type.elab]
   15862             : 
   15863             :        If the identifier resolves to a typedef-name or the
   15864             :        simple-template-id resolves to an alias template
   15865             :        specialization, the elaborated-type-specifier is ill-formed.
   15866             : 
   15867             :      In other words, the only legitimate declaration to use in the
   15868             :      elaborated type specifier is the implicit typedef created when
   15869             :      the type is declared.  */
   15870     7647557 :   else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
   15871      196999 :            && !DECL_SELF_REFERENCE_P (decl)
   15872     7647689 :            && tag_code != typename_type)
   15873             :     {
   15874          95 :       if (alias_template_specialization_p (type, nt_opaque))
   15875          21 :         error ("using alias template specialization %qT after %qs",
   15876             :                type, tag_name (tag_code));
   15877             :       else
   15878          74 :         error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
   15879          95 :       inform (DECL_SOURCE_LOCATION (decl),
   15880             :               "%qD has a previous declaration here", decl);
   15881          95 :       return error_mark_node;
   15882             :     }
   15883     7647462 :   else if (TREE_CODE (type) != RECORD_TYPE
   15884     7647462 :            && TREE_CODE (type) != UNION_TYPE
   15885             :            && tag_code != enum_type
   15886       50881 :            && tag_code != typename_type)
   15887             :     {
   15888           8 :       error ("%qT referred to as %qs", type, tag_name (tag_code));
   15889           8 :       inform (location_of (type), "%qT has a previous declaration here", type);
   15890           8 :       return error_mark_node;
   15891             :     }
   15892     7647454 :   else if (TREE_CODE (type) != ENUMERAL_TYPE
   15893     7596615 :            && tag_code == enum_type)
   15894             :     {
   15895           4 :       error ("%qT referred to as enum", type);
   15896           4 :       inform (location_of (type), "%qT has a previous declaration here", type);
   15897           4 :       return error_mark_node;
   15898             :     }
   15899     7647450 :   else if (!allow_template_p
   15900     3327233 :            && TREE_CODE (type) == RECORD_TYPE
   15901    10882651 :            && CLASSTYPE_IS_TEMPLATE (type))
   15902             :     {
   15903             :       /* If a class template appears as elaborated type specifier
   15904             :          without a template header such as:
   15905             : 
   15906             :            template <class T> class C {};
   15907             :            void f(class C);             // No template header here
   15908             : 
   15909             :          then the required template argument is missing.  */
   15910          24 :       error ("template argument required for %<%s %T%>",
   15911             :              tag_name (tag_code),
   15912          24 :              DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
   15913          24 :       return error_mark_node;
   15914             :     }
   15915             : 
   15916             :   return type;
   15917             : }
   15918             : 
   15919             : /* Lookup NAME of an elaborated type specifier according to SCOPE and
   15920             :    issue diagnostics if necessary.  Return *_TYPE node upon success,
   15921             :    NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
   15922             :    error.  */
   15923             : 
   15924             : static tree
   15925    15131555 : lookup_and_check_tag (enum tag_types tag_code, tree name,
   15926             :                       TAG_how how, bool template_header_p)
   15927             : {
   15928    15131555 :   tree decl;
   15929    15131555 :   if (how == TAG_how::GLOBAL)
   15930             :     {
   15931             :       /* First try ordinary name lookup, ignoring hidden class name
   15932             :          injected via friend declaration.  */
   15933     1356105 :       decl = lookup_name (name, LOOK_want::TYPE);
   15934     1356105 :       decl = strip_using_decl (decl);
   15935             :       /* If that fails, the name will be placed in the smallest
   15936             :          non-class, non-function-prototype scope according to 3.3.1/5.
   15937             :          We may already have a hidden name declared as friend in this
   15938             :          scope.  So lookup again but not ignoring hidden names.
   15939             :          If we find one, that name will be made visible rather than
   15940             :          creating a new tag.  */
   15941     1356105 :       if (!decl)
   15942       13787 :         decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
   15943             :     }
   15944             :   else
   15945    13775450 :     decl = lookup_elaborated_type (name, how);
   15946             : 
   15947    13789237 :   if (!decl)
   15948             :     /* We found nothing.  */
   15949             :     return NULL_TREE;
   15950             : 
   15951     3233572 :   if (TREE_CODE (decl) == TREE_LIST)
   15952             :     {
   15953           4 :       error ("reference to %qD is ambiguous", name);
   15954           4 :       print_candidates (decl);
   15955           4 :       return error_mark_node;
   15956             :     }
   15957             : 
   15958     1293294 :   if (DECL_CLASS_TEMPLATE_P (decl)
   15959     1293287 :       && !template_header_p
   15960     4526855 :       && how == TAG_how::CURRENT_ONLY)
   15961             :     {
   15962          16 :       error ("class template %qD redeclared as non-template", name);
   15963          16 :       inform (location_of (decl), "previous declaration here");
   15964          16 :       CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
   15965          16 :       return error_mark_node;
   15966             :     }
   15967             : 
   15968     1293278 :   if (DECL_CLASS_TEMPLATE_P (decl)
   15969             :       /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
   15970             :          so ignore a template template parameter.  */
   15971     3233559 :       || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
   15972     1293274 :     decl = DECL_TEMPLATE_RESULT (decl);
   15973             : 
   15974     3233552 :   if (TREE_CODE (decl) != TYPE_DECL)
   15975             :     /* Found not-a-type.  */
   15976             :     return NULL_TREE;
   15977             :   
   15978             :   /* Look for invalid nested type:
   15979             :      class C {
   15980             :      class C {};
   15981             :      };  */
   15982     3233508 :   if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
   15983             :     {
   15984           8 :       error ("%qD has the same name as the class in which it is "
   15985             :              "declared", decl);
   15986           8 :       return error_mark_node;
   15987             :     }
   15988             : 
   15989             :   /* Two cases we need to consider when deciding if a class
   15990             :      template is allowed as an elaborated type specifier:
   15991             :      1. It is a self reference to its own class.
   15992             :      2. It comes with a template header.
   15993             : 
   15994             :      For example:
   15995             : 
   15996             :      template <class T> class C {
   15997             :        class C *c1;             // DECL_SELF_REFERENCE_P is true
   15998             :        class D;
   15999             :      };
   16000             :      template <class U> class C; // template_header_p is true
   16001             :      template <class T> class C<T>::D {
   16002             :        class C *c2;             // DECL_SELF_REFERENCE_P is true
   16003             :      };  */
   16004             : 
   16005     9700500 :   tree t = check_elaborated_type_specifier (tag_code, decl,
   16006             :                                             template_header_p
   16007     6270153 :                                             | DECL_SELF_REFERENCE_P (decl));
   16008     1361028 :   if (template_header_p && t && CLASS_TYPE_P (t)
   16009     4594507 :       && (!CLASSTYPE_TEMPLATE_INFO (t)
   16010     1360983 :           || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
   16011             :     {
   16012          28 :       error ("%qT is not a template", t);
   16013          28 :       inform (location_of (t), "previous declaration here");
   16014          56 :       if (TYPE_CLASS_SCOPE_P (t)
   16015          32 :           && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
   16016           4 :         inform (input_location,
   16017             :                 "perhaps you want to explicitly add %<%T::%>",
   16018           4 :                 TYPE_CONTEXT (t));
   16019          28 :       return error_mark_node;
   16020             :     }
   16021             : 
   16022             :   return t;
   16023             : }
   16024             : 
   16025             : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
   16026             :    Define the tag as a forward-reference if it is not defined.
   16027             : 
   16028             :    If a declaration is given, process it here, and report an error if
   16029             :    multiple declarations are not identical.
   16030             : 
   16031             :    SCOPE is TS_CURRENT when this is also a definition.  Only look in
   16032             :    the current frame for the name (since C++ allows new names in any
   16033             :    scope.)  It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
   16034             :    declaration.  Only look beginning from the current scope outward up
   16035             :    till the nearest non-class scope.  Otherwise it is TS_GLOBAL.
   16036             : 
   16037             :    TEMPLATE_HEADER_P is true when this declaration is preceded by
   16038             :    a set of template parameters.  */
   16039             : 
   16040             : tree
   16041    14402308 : xref_tag (enum tag_types tag_code, tree name,
   16042             :           TAG_how how, bool template_header_p)
   16043             : {
   16044    14402308 :   enum tree_code code;
   16045    14402308 :   tree context = NULL_TREE;
   16046             : 
   16047    14402308 :   auto_cond_timevar tv (TV_NAME_LOOKUP);
   16048             : 
   16049    14402308 :   gcc_assert (identifier_p (name));
   16050             : 
   16051    14402308 :   switch (tag_code)
   16052             :     {
   16053             :     case record_type:
   16054             :     case class_type:
   16055             :       code = RECORD_TYPE;
   16056             :       break;
   16057             :     case union_type:
   16058             :       code = UNION_TYPE;
   16059             :       break;
   16060             :     case enum_type:
   16061             :       code = ENUMERAL_TYPE;
   16062             :       break;
   16063           0 :     default:
   16064           0 :       gcc_unreachable ();
   16065             :     }
   16066             : 
   16067             :   /* In case of anonymous name, xref_tag is only called to
   16068             :      make type node and push name.  Name lookup is not required.  */
   16069    14402308 :   tree t = NULL_TREE;
   16070    14402308 :   if (!IDENTIFIER_ANON_P (name))
   16071    13661795 :     t = lookup_and_check_tag  (tag_code, name, how, template_header_p);
   16072             : 
   16073    14402308 :   if (t == error_mark_node)
   16074             :     return error_mark_node;
   16075             : 
   16076     1687300 :   if (how != TAG_how::CURRENT_ONLY && t && current_class_type
   16077      645448 :       && template_class_depth (current_class_type)
   16078    14596926 :       && template_header_p)
   16079             :     {
   16080      154577 :       if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
   16081             :         return t;
   16082             : 
   16083             :       /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
   16084             :          a definition of this tag.  Since, in addition, we are
   16085             :          currently processing a (member) template declaration of a
   16086             :          template class, we must be very careful; consider:
   16087             : 
   16088             :            template <class X> struct S1
   16089             : 
   16090             :            template <class U> struct S2
   16091             :            {
   16092             :              template <class V> friend struct S1;
   16093             :            };
   16094             : 
   16095             :          Here, the S2::S1 declaration should not be confused with the
   16096             :          outer declaration.  In particular, the inner version should
   16097             :          have a template parameter of level 2, not level 1.
   16098             : 
   16099             :          On the other hand, when presented with:
   16100             : 
   16101             :            template <class T> struct S1
   16102             :            {
   16103             :              template <class U> struct S2 {};
   16104             :              template <class U> friend struct S2;
   16105             :            };
   16106             : 
   16107             :          the friend must find S1::S2 eventually.  We accomplish this
   16108             :          by making sure that the new type we create to represent this
   16109             :          declaration has the right TYPE_CONTEXT.  */
   16110      154574 :       context = TYPE_CONTEXT (t);
   16111      154574 :       t = NULL_TREE;
   16112             :     }
   16113             : 
   16114    14402158 :   if (! t)
   16115             :     {
   16116             :       /* If no such tag is yet defined, create a forward-reference node
   16117             :          and record it as the "definition".
   16118             :          When a real declaration of this type is found,
   16119             :          the forward-reference will be altered into a real type.  */
   16120    11348586 :       if (code == ENUMERAL_TYPE)
   16121             :         {
   16122          17 :           error ("use of enum %q#D without previous declaration", name);
   16123          17 :           return error_mark_node;
   16124             :         }
   16125             : 
   16126    11348569 :       t = make_class_type (code);
   16127    11348569 :       TYPE_CONTEXT (t) = context;
   16128    11348569 :       if (IDENTIFIER_LAMBDA_P (name))
   16129             :         /* Mark it as a lambda type right now.  Our caller will
   16130             :            correct the value.  */
   16131      248401 :         CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node;
   16132    11348569 :       t = pushtag (name, t, how);
   16133             :     }
   16134             :   else
   16135             :     {
   16136     3053572 :       if (template_header_p && MAYBE_CLASS_TYPE_P (t))
   16137             :         {
   16138             :           /* Check that we aren't trying to overload a class with different
   16139             :              constraints.  */
   16140     1206405 :           if (!redeclare_class_template (t, current_template_parms,
   16141             :                                          current_template_constraints ()))
   16142          60 :             return error_mark_node;
   16143             :         }
   16144     1847167 :       else if (!processing_template_decl
   16145     1798515 :                && CLASS_TYPE_P (t)
   16146     3620374 :                && CLASSTYPE_IS_TEMPLATE (t))
   16147             :         {
   16148           0 :           error ("redeclaration of %qT as a non-template", t);
   16149           0 :           inform (location_of (t), "previous declaration %qD", t);
   16150           0 :           return error_mark_node;
   16151             :         }
   16152             : 
   16153     3053512 :       if (modules_p ()
   16154     3053512 :           && how == TAG_how::CURRENT_ONLY)
   16155             :         {
   16156       10085 :           tree decl = TYPE_NAME (t);
   16157       10085 :           if (!module_may_redeclare (decl))
   16158             :             {
   16159           6 :               error ("cannot declare %qD in a different module", decl);
   16160           6 :               inform (DECL_SOURCE_LOCATION (decl), "declared here");
   16161           6 :               return error_mark_node;
   16162             :             }
   16163             : 
   16164       10079 :           tree maybe_tmpl = decl;
   16165       10079 :           if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
   16166        7313 :             maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
   16167             : 
   16168       10079 :           if (DECL_LANG_SPECIFIC (decl)
   16169        5093 :               && DECL_MODULE_IMPORT_P (decl)
   16170       10112 :               && TREE_CODE (CP_DECL_CONTEXT (decl)) == NAMESPACE_DECL)
   16171             :             {
   16172             :               /* Push it into this TU's symbol slot.  */
   16173          33 :               gcc_checking_assert (current_namespace == CP_DECL_CONTEXT (decl));
   16174          33 :               if (maybe_tmpl != decl)
   16175             :                 /* We're in the template parm binding level.
   16176             :                    Pushtag has logic to slide under that, but we're
   16177             :                    not pushing a *new* type.  */
   16178          15 :                 push_nested_namespace (CP_DECL_CONTEXT (decl));
   16179             : 
   16180          33 :               pushdecl (maybe_tmpl);
   16181          33 :               if (maybe_tmpl != decl)
   16182          15 :                 pop_nested_namespace (CP_DECL_CONTEXT (decl));
   16183             :             }
   16184             : 
   16185       10079 :           set_instantiating_module (maybe_tmpl);
   16186             :         }
   16187             :     }
   16188             : 
   16189             :   return t;
   16190    14402308 : }
   16191             : 
   16192             : /* Create the binfo hierarchy for REF with (possibly NULL) base list
   16193             :    BASE_LIST.  For each element on BASE_LIST the TREE_PURPOSE is an
   16194             :    access_* node, and the TREE_VALUE is the type of the base-class.
   16195             :    Non-NULL TREE_TYPE indicates virtual inheritance.  */
   16196             : 
   16197             : void
   16198    37256584 : xref_basetypes (tree ref, tree base_list)
   16199             : {
   16200    37256584 :   tree *basep;
   16201    37256584 :   tree binfo, base_binfo;
   16202    37256584 :   unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases.  */
   16203    37256584 :   unsigned max_bases = 0;  /* Maximum direct bases.  */
   16204    37256584 :   unsigned max_dvbases = 0; /* Maximum direct virtual bases.  */
   16205    37256584 :   int i;
   16206    37256584 :   tree default_access;
   16207    37256584 :   tree igo_prev; /* Track Inheritance Graph Order.  */
   16208             : 
   16209    37256584 :   if (ref == error_mark_node)
   16210          16 :     return;
   16211             : 
   16212             :   /* The base of a derived class is private by default, all others are
   16213             :      public.  */
   16214    74513168 :   default_access = (TREE_CODE (ref) == RECORD_TYPE
   16215    36879141 :                     && CLASSTYPE_DECLARED_CLASS (ref)
   16216    74135725 :                     ? access_private_node : access_public_node);
   16217             : 
   16218             :   /* First, make sure that any templates in base-classes are
   16219             :      instantiated.  This ensures that if we call ourselves recursively
   16220             :      we do not get confused about which classes are marked and which
   16221             :      are not.  */
   16222    37256584 :   basep = &base_list;
   16223    58112656 :   while (*basep)
   16224             :     {
   16225    20856072 :       tree basetype = TREE_VALUE (*basep);
   16226             : 
   16227             :       /* The dependent_type_p call below should really be dependent_scope_p
   16228             :          so that we give a hard error about using an incomplete type as a
   16229             :          base, but we allow it with a pedwarn for backward
   16230             :          compatibility.  */
   16231    20856072 :       if (processing_template_decl
   16232    20856072 :           && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
   16233           4 :         cxx_incomplete_type_diagnostic (NULL_TREE, basetype, DK_PEDWARN);
   16234    20856072 :       if (!dependent_type_p (basetype)
   16235    20856072 :           && !complete_type_or_else (basetype, NULL))
   16236             :         /* An incomplete type.  Remove it from the list.  */
   16237          16 :         *basep = TREE_CHAIN (*basep);
   16238             :       else
   16239             :         {
   16240    20856056 :           max_bases++;
   16241    20856056 :           if (TREE_TYPE (*basep))
   16242       52764 :             max_dvbases++;
   16243    20856056 :           if (CLASS_TYPE_P (basetype))
   16244    20075618 :             max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   16245    20856056 :           basep = &TREE_CHAIN (*basep);
   16246             :         }
   16247             :     }
   16248    37256584 :   max_vbases += max_dvbases;
   16249             : 
   16250    37256584 :   TYPE_MARKED_P (ref) = 1;
   16251             : 
   16252             :   /* The binfo slot should be empty, unless this is an (ill-formed)
   16253             :      redefinition.  */
   16254    37256584 :   gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
   16255             : 
   16256    37256584 :   gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
   16257             : 
   16258    37256584 :   binfo = make_tree_binfo (max_bases);
   16259             : 
   16260    37256584 :   TYPE_BINFO (ref) = binfo;
   16261    37256584 :   BINFO_OFFSET (binfo) = size_zero_node;
   16262    37256584 :   BINFO_TYPE (binfo) = ref;
   16263             : 
   16264             :   /* Apply base-class info set up to the variants of this type.  */
   16265    37256584 :   fixup_type_variants (ref);
   16266             : 
   16267    37256584 :   if (max_bases)
   16268             :     {
   16269    20135164 :       vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases);
   16270             :       /* A C++98 POD cannot have base classes.  */
   16271    20135164 :       CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
   16272             : 
   16273    20135164 :       if (TREE_CODE (ref) == UNION_TYPE)
   16274             :         {
   16275          16 :           error ("derived union %qT invalid", ref);
   16276          16 :           return;
   16277             :         }
   16278             :     }
   16279             : 
   16280    20135148 :   if (max_bases > 1)
   16281      501878 :     warning (OPT_Wmultiple_inheritance,
   16282             :              "%qT defined with multiple direct bases", ref);
   16283             : 
   16284    37256568 :   if (max_vbases)
   16285             :     {
   16286             :       /* An aggregate can't have virtual base classes.  */
   16287      153572 :       CLASSTYPE_NON_AGGREGATE (ref) = true;
   16288             : 
   16289      153572 :       vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
   16290             : 
   16291      153572 :       if (max_dvbases)
   16292       51600 :         warning (OPT_Wvirtual_inheritance,
   16293             :                  "%qT defined with direct virtual base", ref);
   16294             :     }
   16295             : 
   16296    58112608 :   for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
   16297             :     {
   16298    20856040 :       tree access = TREE_PURPOSE (base_list);
   16299    20856040 :       int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
   16300    20856040 :       tree basetype = TREE_VALUE (base_list);
   16301             : 
   16302    20856040 :       if (access == access_default_node)
   16303     3132317 :         access = default_access;
   16304             : 
   16305             :       /* Before C++17, an aggregate cannot have base classes.  In C++17, an
   16306             :          aggregate can't have virtual, private, or protected base classes.  */
   16307    20856040 :       if (cxx_dialect < cxx17
   16308    20512878 :           || access != access_public_node
   16309    19733747 :           || via_virtual)
   16310     1171055 :         CLASSTYPE_NON_AGGREGATE (ref) = true;
   16311             : 
   16312    20856040 :       if (PACK_EXPANSION_P (basetype))
   16313       13834 :         basetype = PACK_EXPANSION_PATTERN (basetype);
   16314    20856040 :       if (TREE_CODE (basetype) == TYPE_DECL)
   16315           0 :         basetype = TREE_TYPE (basetype);
   16316    20856040 :       if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
   16317             :         {
   16318          30 :           error ("base type %qT fails to be a struct or class type",
   16319             :                  basetype);
   16320          30 :           goto dropped_base;
   16321             :         }
   16322             : 
   16323    20856010 :       base_binfo = NULL_TREE;
   16324    20856010 :       if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
   16325             :         {
   16326    16077098 :           base_binfo = TYPE_BINFO (basetype);
   16327             :           /* The original basetype could have been a typedef'd type.  */
   16328    16077098 :           basetype = BINFO_TYPE (base_binfo);
   16329             : 
   16330             :           /* Inherit flags from the base.  */
   16331    48231294 :           TYPE_HAS_NEW_OPERATOR (ref)
   16332    16077098 :             |= TYPE_HAS_NEW_OPERATOR (basetype);
   16333    48231294 :           TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
   16334    16077098 :             |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
   16335    16077098 :           TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
   16336    16077098 :           TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
   16337    48231294 :           CLASSTYPE_DIAMOND_SHAPED_P (ref)
   16338    16077098 :             |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
   16339    48231294 :           CLASSTYPE_REPEATED_BASE_P (ref)
   16340    16077098 :             |= CLASSTYPE_REPEATED_BASE_P (basetype);
   16341             :         }
   16342             : 
   16343             :       /* We must do this test after we've seen through a typedef
   16344             :          type.  */
   16345    20856010 :       if (TYPE_MARKED_P (basetype))
   16346             :         {
   16347          24 :           if (basetype == ref)
   16348           0 :             error ("recursive type %qT undefined", basetype);
   16349             :           else
   16350          24 :             error ("duplicate base type %qT invalid", basetype);
   16351          24 :           goto dropped_base;
   16352             :         }
   16353             : 
   16354    20855986 :       if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
   16355             :         /* Regenerate the pack expansion for the bases. */
   16356       13834 :         basetype = make_pack_expansion (basetype);
   16357             : 
   16358    20855986 :       TYPE_MARKED_P (basetype) = 1;
   16359             : 
   16360    20855986 :       base_binfo = copy_binfo (base_binfo, basetype, ref,
   16361             :                                &igo_prev, via_virtual);
   16362    20855986 :       if (!BINFO_INHERITANCE_CHAIN (base_binfo))
   16363    20803241 :         BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
   16364             : 
   16365    20855986 :       BINFO_BASE_APPEND (binfo, base_binfo);
   16366    20855986 :       BINFO_BASE_ACCESS_APPEND (binfo, access);
   16367    20855986 :       continue;
   16368             : 
   16369          54 :     dropped_base:
   16370             :       /* Update max_vbases to reflect the reality that we are dropping
   16371             :          this base:  if it reaches zero we want to undo the vec_alloc
   16372             :          above to avoid inconsistencies during error-recovery: eg, in
   16373             :          build_special_member_call, CLASSTYPE_VBASECLASSES non null
   16374             :          and vtt null (c++/27952).  */
   16375          54 :       if (via_virtual)
   16376          15 :         max_vbases--;
   16377          54 :       if (CLASS_TYPE_P (basetype))
   16378          40 :         max_vbases
   16379          44 :           -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
   16380    20855986 :     }
   16381             : 
   16382    37256568 :   if (CLASSTYPE_VBASECLASSES (ref)
   16383    37256568 :       && max_vbases == 0)
   16384          15 :     vec_free (CLASSTYPE_VBASECLASSES (ref));
   16385             : 
   16386    37410125 :   if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
   16387             :     /* If we didn't get max_vbases vbases, we must have shared at
   16388             :        least one of them, and are therefore diamond shaped.  */
   16389       16812 :     CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
   16390             : 
   16391             :   /* Unmark all the types.  */
   16392    58112554 :   for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
   16393    20855986 :     TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   16394    37256568 :   TYPE_MARKED_P (ref) = 0;
   16395             : 
   16396             :   /* Now see if we have a repeated base type.  */
   16397    37256568 :   if (!CLASSTYPE_REPEATED_BASE_P (ref))
   16398             :     {
   16399    98440968 :       for (base_binfo = binfo; base_binfo;
   16400    61184901 :            base_binfo = TREE_CHAIN (base_binfo))
   16401             :         {
   16402    61185678 :           if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   16403             :             {
   16404         777 :               CLASSTYPE_REPEATED_BASE_P (ref) = 1;
   16405         777 :               break;
   16406             :             }
   16407    61184901 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
   16408             :         }
   16409    98440968 :       for (base_binfo = binfo; base_binfo;
   16410    61184901 :            base_binfo = TREE_CHAIN (base_binfo))
   16411    61185678 :         if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
   16412    61184901 :           TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
   16413             :         else
   16414             :           break;
   16415             :     }
   16416             : }
   16417             : 
   16418             : 
   16419             : /* Copies the enum-related properties from type SRC to type DST.
   16420             :    Used with the underlying type of an enum and the enum itself.  */
   16421             : static void
   16422     1227746 : copy_type_enum (tree dst, tree src)
   16423             : {
   16424     1227746 :   tree t;
   16425     2455501 :   for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
   16426             :     {
   16427     1227755 :       TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
   16428     1227755 :       TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
   16429     1227755 :       TYPE_SIZE (t) = TYPE_SIZE (src);
   16430     1227755 :       TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
   16431     1227755 :       SET_TYPE_MODE (dst, TYPE_MODE (src));
   16432     1227755 :       TYPE_PRECISION (t) = TYPE_PRECISION (src);
   16433     1227755 :       unsigned valign = TYPE_ALIGN (src);
   16434     1227755 :       if (TYPE_USER_ALIGN (t))
   16435           4 :         valign = MAX (valign, TYPE_ALIGN (t));
   16436             :       else
   16437     1227751 :         TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
   16438     1227755 :       SET_TYPE_ALIGN (t, valign);
   16439     1227755 :       TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
   16440             :     }
   16441     1227746 : }
   16442             : 
   16443             : /* Begin compiling the definition of an enumeration type.
   16444             :    NAME is its name, 
   16445             : 
   16446             :    if ENUMTYPE is not NULL_TREE then the type has alredy been found.
   16447             : 
   16448             :    UNDERLYING_TYPE is the type that will be used as the storage for
   16449             :    the enumeration type. This should be NULL_TREE if no storage type
   16450             :    was specified.
   16451             : 
   16452             :    ATTRIBUTES are any attributes specified after the enum-key.
   16453             : 
   16454             :    SCOPED_ENUM_P is true if this is a scoped enumeration type.
   16455             : 
   16456             :    if IS_NEW is not NULL, gets TRUE iff a new type is created.
   16457             : 
   16458             :    Returns the type object, as yet incomplete.
   16459             :    Also records info about it so that build_enumerator
   16460             :    may be used to declare the individual values as they are read.  */
   16461             : 
   16462             : tree
   16463     1469891 : start_enum (tree name, tree enumtype, tree underlying_type,
   16464             :             tree attributes, bool scoped_enum_p, bool *is_new)
   16465             : {
   16466     1469891 :   tree prevtype = NULL_TREE;
   16467     1469891 :   gcc_assert (identifier_p (name));
   16468             : 
   16469     1469891 :   if (is_new)
   16470     1180440 :     *is_new = false;
   16471             :   /* [C++0x dcl.enum]p5:
   16472             : 
   16473             :     If not explicitly specified, the underlying type of a scoped
   16474             :     enumeration type is int.  */
   16475     1469891 :   if (!underlying_type && scoped_enum_p)
   16476       75651 :     underlying_type = integer_type_node;
   16477             : 
   16478     1469891 :   if (underlying_type)
   16479      279053 :     underlying_type = cv_unqualified (underlying_type);
   16480             : 
   16481             :   /* If this is the real definition for a previous forward reference,
   16482             :      fill in the contents in the same object that used to be the
   16483             :      forward reference.  */
   16484     1469891 :   if (!enumtype)
   16485     1469760 :     enumtype = lookup_and_check_tag (enum_type, name,
   16486             :                                      /*tag_scope=*/TAG_how::CURRENT_ONLY,
   16487             :                                      /*template_header_p=*/false);
   16488             : 
   16489             :   /* In case of a template_decl, the only check that should be deferred
   16490             :      to instantiation time is the comparison of underlying types.  */
   16491     1469891 :   if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
   16492             :     {
   16493       25538 :       if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
   16494             :         {
   16495           6 :           error_at (input_location, "scoped/unscoped mismatch "
   16496             :                     "in enum %q#T", enumtype);
   16497           6 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   16498             :                   "previous definition here");
   16499           6 :           enumtype = error_mark_node;
   16500             :         }
   16501       25353 :       else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
   16502             :         {
   16503           3 :           error_at (input_location, "underlying type mismatch "
   16504             :                     "in enum %q#T", enumtype);
   16505           3 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   16506             :                   "previous definition here");
   16507           3 :           enumtype = error_mark_node;
   16508             :         }
   16509       25345 :       else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
   16510       50695 :                && !same_type_p (underlying_type,
   16511             :                                 ENUM_UNDERLYING_TYPE (enumtype)))
   16512             :         {
   16513          27 :           error_at (input_location, "different underlying type "
   16514             :                     "in enum %q#T", enumtype);
   16515          27 :           inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   16516             :                   "previous definition here");
   16517          27 :           underlying_type = NULL_TREE;
   16518             :         }
   16519             : 
   16520       25359 :       if (modules_p ())
   16521             :         {
   16522         195 :           if (!module_may_redeclare (TYPE_NAME (enumtype)))
   16523             :             {
   16524           0 :               error ("cannot define %qD in different module",
   16525           0 :                      TYPE_NAME (enumtype));
   16526           0 :               inform (DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)),
   16527             :                       "declared here");
   16528           0 :               enumtype = error_mark_node;
   16529             :             }
   16530         195 :           set_instantiating_module (TYPE_NAME (enumtype));
   16531             :         }
   16532             :     }
   16533             : 
   16534     1469891 :   if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
   16535       25350 :       || processing_template_decl)
   16536             :     {
   16537             :       /* In case of error, make a dummy enum to allow parsing to
   16538             :          continue.  */
   16539     1444628 :       if (enumtype == error_mark_node)
   16540             :         {
   16541           9 :           name = make_anon_name ();
   16542           9 :           enumtype = NULL_TREE;
   16543             :         }
   16544             : 
   16545             :       /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
   16546             :          of an opaque enum, or an opaque enum of an already defined
   16547             :          enumeration (C++11).
   16548             :          In any other case, it'll be NULL_TREE. */
   16549     1444628 :       if (!enumtype)
   16550             :         {
   16551     1444537 :           if (is_new)
   16552     1155086 :             *is_new = true;
   16553             :         }
   16554     1444628 :       prevtype = enumtype;
   16555             : 
   16556             :       /* Do not push the decl more than once.  */
   16557     1444628 :       if (!enumtype
   16558          91 :           || TREE_CODE (enumtype) != ENUMERAL_TYPE)
   16559             :         {
   16560     1444541 :           enumtype = cxx_make_type (ENUMERAL_TYPE);
   16561     1444541 :           enumtype = pushtag (name, enumtype);
   16562             : 
   16563             :           /* std::byte aliases anything.  */
   16564     1444541 :           if (enumtype != error_mark_node
   16565     1444518 :               && TYPE_CONTEXT (enumtype) == std_node
   16566     1907689 :               && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
   16567        9564 :             TYPE_ALIAS_SET (enumtype) = 0;
   16568             :         }
   16569             :       else
   16570          87 :           enumtype = xref_tag (enum_type, name);
   16571             : 
   16572     1444628 :       if (enumtype == error_mark_node)
   16573             :         return error_mark_node;
   16574             : 
   16575             :       /* The enum is considered opaque until the opening '{' of the
   16576             :          enumerator list.  */
   16577     1444605 :       SET_OPAQUE_ENUM_P (enumtype, true);
   16578     1444605 :       ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
   16579             :     }
   16580             : 
   16581     1469868 :   SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
   16582             : 
   16583     1469868 :   cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
   16584             : 
   16585     1469868 :   if (underlying_type)
   16586             :     {
   16587      279023 :       if (ENUM_UNDERLYING_TYPE (enumtype))
   16588             :         /* We already checked that it matches, don't change it to a different
   16589             :            typedef variant.  */;
   16590      253705 :       else if (CP_INTEGRAL_TYPE_P (underlying_type))
   16591             :         {
   16592      253648 :           copy_type_enum (enumtype, underlying_type);
   16593      253648 :           ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   16594             :         }
   16595          57 :       else if (dependent_type_p (underlying_type))
   16596          45 :         ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
   16597             :       else
   16598             :         {
   16599          12 :           error ("underlying type %qT of %qT must be an integral type", 
   16600             :                  underlying_type, enumtype);
   16601          12 :           ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
   16602             :         }
   16603             :     }
   16604             : 
   16605             :   /* If into a template class, the returned enum is always the first
   16606             :      declaration (opaque or not) seen. This way all the references to
   16607             :      this type will be to the same declaration. The following ones are used
   16608             :      only to check for definition errors.  */
   16609     1469868 :   if (prevtype && processing_template_decl)
   16610             :     return prevtype;
   16611             :   else
   16612     1469781 :     return enumtype;
   16613             : }
   16614             : 
   16615             : /* After processing and defining all the values of an enumeration type,
   16616             :    install their decls in the enumeration type.
   16617             :    ENUMTYPE is the type object.  */
   16618             : 
   16619             : void
   16620     1393432 : finish_enum_value_list (tree enumtype)
   16621             : {
   16622     1393432 :   tree values;
   16623     1393432 :   tree underlying_type;
   16624     1393432 :   tree decl;
   16625     1393432 :   tree value;
   16626     1393432 :   tree minnode, maxnode;
   16627     1393432 :   tree t;
   16628             : 
   16629     1393432 :   bool fixed_underlying_type_p 
   16630     1393432 :     = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
   16631             : 
   16632             :   /* We built up the VALUES in reverse order.  */
   16633     1393432 :   TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
   16634             : 
   16635             :   /* For an enum defined in a template, just set the type of the values;
   16636             :      all further processing is postponed until the template is
   16637             :      instantiated.  We need to set the type so that tsubst of a CONST_DECL
   16638             :      works.  */
   16639     1393432 :   if (processing_template_decl)
   16640             :     {
   16641      259430 :       for (values = TYPE_VALUES (enumtype);
   16642      489739 :            values;
   16643      259430 :            values = TREE_CHAIN (values))
   16644      259430 :         TREE_TYPE (TREE_VALUE (values)) = enumtype;
   16645             :       return;
   16646             :     }
   16647             : 
   16648             :   /* Determine the minimum and maximum values of the enumerators.  */
   16649     1163123 :   if (TYPE_VALUES (enumtype))
   16650             :     {
   16651             :       minnode = maxnode = NULL_TREE;
   16652             : 
   16653     7200620 :       for (values = TYPE_VALUES (enumtype);
   16654     8344543 :            values;
   16655     7200620 :            values = TREE_CHAIN (values))
   16656             :         {
   16657     7200620 :           decl = TREE_VALUE (values);
   16658             : 
   16659             :           /* [dcl.enum]: Following the closing brace of an enum-specifier,
   16660             :              each enumerator has the type of its enumeration.  Prior to the
   16661             :              closing brace, the type of each enumerator is the type of its
   16662             :              initializing value.  */
   16663     7200620 :           TREE_TYPE (decl) = enumtype;
   16664             : 
   16665             :           /* Update the minimum and maximum values, if appropriate.  */
   16666     7200620 :           value = DECL_INITIAL (decl);
   16667     7200620 :           if (TREE_CODE (value) != INTEGER_CST)
   16668           6 :             value = integer_zero_node;
   16669             :           /* Figure out what the minimum and maximum values of the
   16670             :              enumerators are.  */
   16671     7200620 :           if (!minnode)
   16672             :             minnode = maxnode = value;
   16673     6056697 :           else if (tree_int_cst_lt (maxnode, value))
   16674             :             maxnode = value;
   16675      945140 :           else if (tree_int_cst_lt (value, minnode))
   16676      100547 :             minnode = value;
   16677             :         }
   16678             :     }
   16679             :   else
   16680             :     /* [dcl.enum]
   16681             : 
   16682             :        If the enumerator-list is empty, the underlying type is as if
   16683             :        the enumeration had a single enumerator with value 0.  */
   16684       19200 :     minnode = maxnode = integer_zero_node;
   16685             : 
   16686     1163123 :   if (!fixed_underlying_type_p)
   16687             :     {
   16688             :       /* Compute the number of bits require to represent all values of the
   16689             :          enumeration.  We must do this before the type of MINNODE and
   16690             :          MAXNODE are transformed, since tree_int_cst_min_precision relies
   16691             :          on the TREE_TYPE of the value it is passed.  */
   16692      974098 :       signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
   16693      974098 :       int lowprec = tree_int_cst_min_precision (minnode, sgn);
   16694      974098 :       int highprec = tree_int_cst_min_precision (maxnode, sgn);
   16695      974098 :       int precision = MAX (lowprec, highprec);
   16696      974098 :       unsigned int itk;
   16697      974098 :       bool use_short_enum;
   16698             : 
   16699             :       /* Determine the underlying type of the enumeration.
   16700             : 
   16701             :          [dcl.enum]
   16702             : 
   16703             :          The underlying type of an enumeration is an integral type that
   16704             :          can represent all the enumerator values defined in the
   16705             :          enumeration.  It is implementation-defined which integral type is
   16706             :          used as the underlying type for an enumeration except that the
   16707             :          underlying type shall not be larger than int unless the value of
   16708             :          an enumerator cannot fit in an int or unsigned int.
   16709             : 
   16710             :          We use "int" or an "unsigned int" as the underlying type, even if
   16711             :          a smaller integral type would work, unless the user has
   16712             :          explicitly requested that we use the smallest possible type.  The
   16713             :          user can request that for all enumerations with a command line
   16714             :          flag, or for just one enumeration with an attribute.  */
   16715             : 
   16716     1948196 :       use_short_enum = flag_short_enums
   16717      974098 :         || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
   16718             : 
   16719             :       /* If the precision of the type was specified with an attribute and it
   16720             :          was too small, give an error.  Otherwise, use it.  */
   16721      974098 :       if (TYPE_PRECISION (enumtype))
   16722             :         {
   16723          12 :           if (precision > TYPE_PRECISION (enumtype))
   16724           0 :             error ("specified mode too small for enumerated values");
   16725             :           else
   16726             :             {
   16727          12 :               use_short_enum = true;
   16728          12 :               precision = TYPE_PRECISION (enumtype);
   16729             :             }
   16730             :         }
   16731             : 
   16732     2867520 :       for (itk = (use_short_enum ? itk_char : itk_int);
   16733     1893512 :            itk != itk_none;
   16734             :            itk++)
   16735             :         {
   16736     1893508 :           underlying_type = integer_types[itk];
   16737     1893508 :           if (underlying_type != NULL_TREE
   16738     1893484 :               && TYPE_PRECISION (underlying_type) >= precision
   16739     3785063 :               && TYPE_SIGN (underlying_type) == sgn)
   16740             :             break;
   16741             :         }
   16742      974098 :       if (itk == itk_none)
   16743             :         {
   16744             :           /* DR 377
   16745             : 
   16746             :              IF no integral type can represent all the enumerator values, the
   16747             :              enumeration is ill-formed.  */
   16748           4 :           error ("no integral type can represent all of the enumerator values "
   16749             :                  "for %qT", enumtype);
   16750           4 :           precision = TYPE_PRECISION (long_long_integer_type_node);
   16751           4 :           underlying_type = integer_types[itk_unsigned_long_long];
   16752             :         }
   16753             : 
   16754             :       /* [dcl.enum]
   16755             : 
   16756             :          The value of sizeof() applied to an enumeration type, an object
   16757             :          of an enumeration type, or an enumerator, is the value of sizeof()
   16758             :          applied to the underlying type.  */
   16759      974098 :       copy_type_enum (enumtype, underlying_type);
   16760             : 
   16761             :       /* Compute the minimum and maximum values for the type.
   16762             : 
   16763             :          [dcl.enum]
   16764             : 
   16765             :          For an enumeration where emin is the smallest enumerator and emax
   16766             :          is the largest, the values of the enumeration are the values of the
   16767             :          underlying type in the range bmin to bmax, where bmin and bmax are,
   16768             :          respectively, the smallest and largest values of the smallest bit-
   16769             :          field that can store emin and emax.  */
   16770             : 
   16771             :       /* The middle-end currently assumes that types with TYPE_PRECISION
   16772             :          narrower than their underlying type are suitably zero or sign
   16773             :          extended to fill their mode.  Similarly, it assumes that the front
   16774             :          end assures that a value of a particular type must be within
   16775             :          TYPE_MIN_VALUE and TYPE_MAX_VALUE.
   16776             : 
   16777             :          We used to set these fields based on bmin and bmax, but that led
   16778             :          to invalid assumptions like optimizing away bounds checking.  So
   16779             :          now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
   16780             :          TYPE_MAX_VALUE to the values for the mode above and only restrict
   16781             :          the ENUM_UNDERLYING_TYPE for the benefit of diagnostics.  */
   16782      974098 :       ENUM_UNDERLYING_TYPE (enumtype)
   16783      974098 :         = build_distinct_type_copy (underlying_type);
   16784      974098 :       TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
   16785      974098 :       set_min_and_max_values_for_integral_type
   16786      974098 :         (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
   16787             : 
   16788             :       /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE.  */
   16789      974098 :       if (flag_strict_enums)
   16790          39 :         set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
   16791             :     }
   16792             :   else
   16793      189025 :     underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
   16794             : 
   16795             :   /* If the enum is exported, mark the consts too.  */
   16796     1163123 :   bool export_p = (UNSCOPED_ENUM_P (enumtype)
   16797     1016058 :                    && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
   16798     1163990 :                    && at_namespace_scope_p ());
   16799             : 
   16800             :   /* Convert each of the enumerators to the type of the underlying
   16801             :      type of the enumeration.  */
   16802     8363743 :   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
   16803             :     {
   16804     7200620 :       decl = TREE_VALUE (values);
   16805     7200620 :       iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
   16806     7200620 :       if (fixed_underlying_type_p)
   16807             :         /* If the enumeration type has a fixed underlying type, we
   16808             :            already checked all of the enumerator values.  */
   16809     1676010 :         value = DECL_INITIAL (decl);
   16810             :       else
   16811     5524610 :         value = perform_implicit_conversion (underlying_type,
   16812     5524610 :                                              DECL_INITIAL (decl),
   16813             :                                              tf_warning_or_error);
   16814             :       /* Do not clobber shared ints.  */
   16815     7200620 :       if (value != error_mark_node)
   16816             :         {
   16817     7200617 :           value = copy_node (value);
   16818             : 
   16819     7200617 :           TREE_TYPE (value) = enumtype;
   16820             :         }
   16821     7200620 :       DECL_INITIAL (decl) = value;
   16822     7200620 :       if (export_p)
   16823        8082 :         DECL_MODULE_EXPORT_P (decl) = true;
   16824     7200620 :     }
   16825             : 
   16826             :   /* Fix up all variant types of this enum type.  */
   16827     2326259 :   for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
   16828     1163136 :     TYPE_VALUES (t) = TYPE_VALUES (enumtype);
   16829             : 
   16830     1163123 :   if (at_class_scope_p ()
   16831      649112 :       && COMPLETE_TYPE_P (current_class_type)
   16832     1163183 :       && UNSCOPED_ENUM_P (enumtype))
   16833             :     {
   16834          42 :       insert_late_enum_def_bindings (current_class_type, enumtype);
   16835             :       /* TYPE_FIELDS needs fixup.  */
   16836          42 :       fixup_type_variants (current_class_type);
   16837             :     }
   16838             : 
   16839             :   /* Finish debugging output for this type.  */
   16840     1163123 :   rest_of_type_compilation (enumtype, namespace_bindings_p ());
   16841             : 
   16842             :   /* Each enumerator now has the type of its enumeration.  Clear the cache
   16843             :      so that this change in types doesn't confuse us later on.  */
   16844     1163123 :   clear_cv_and_fold_caches ();
   16845             : }
   16846             : 
   16847             : /* Finishes the enum type. This is called only the first time an
   16848             :    enumeration is seen, be it opaque or odinary.
   16849             :    ENUMTYPE is the type object.  */
   16850             : 
   16851             : void
   16852     1386275 : finish_enum (tree enumtype)
   16853             : {
   16854     1386275 :   if (processing_template_decl)
   16855             :     {
   16856      230336 :       if (at_function_scope_p ())
   16857         265 :         add_stmt (build_min (TAG_DEFN, enumtype));
   16858      230336 :       return;
   16859             :     }
   16860             : 
   16861             :   /* If this is a forward declaration, there should not be any variants,
   16862             :      though we can get a variant in the middle of an enum-specifier with
   16863             :      wacky code like 'enum E { e = sizeof(const E*) };'  */
   16864     2311878 :   gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
   16865             :               && (TYPE_VALUES (enumtype)
   16866             :                   || !TYPE_NEXT_VARIANT (enumtype)));
   16867             : }
   16868             : 
   16869             : /* Build and install a CONST_DECL for an enumeration constant of the
   16870             :    enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
   16871             :    Apply ATTRIBUTES if available.  LOC is the location of NAME.
   16872             :    Assignment of sequential values by default is handled here.  */
   16873             : 
   16874             : tree
   16875     7460035 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
   16876             :                   location_t loc)
   16877             : {
   16878     7460035 :   tree decl;
   16879     7460035 :   tree context;
   16880     7460035 :   tree type;
   16881             : 
   16882             :   /* scalar_constant_value will pull out this expression, so make sure
   16883             :      it's folded as appropriate.  */
   16884     7460035 :   if (processing_template_decl)
   16885      259430 :     value = fold_non_dependent_expr (value);
   16886             : 
   16887             :   /* If the VALUE was erroneous, pretend it wasn't there; that will
   16888             :      result in the enum being assigned the next value in sequence.  */
   16889     7460035 :   if (value == error_mark_node)
   16890             :     value = NULL_TREE;
   16891             : 
   16892             :   /* Remove no-op casts from the value.  */
   16893     7459990 :   if (value)
   16894     5301868 :     STRIP_TYPE_NOPS (value);
   16895             : 
   16896     7460035 :   if (! processing_template_decl)
   16897             :     {
   16898             :       /* Validate and default VALUE.  */
   16899     7200605 :       if (value != NULL_TREE)
   16900             :         {
   16901     3033266 :           if (!ENUM_UNDERLYING_TYPE (enumtype))
   16902             :             {
   16903     1836447 :               tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
   16904             :                                                            value, true);
   16905     1836447 :               if (tmp_value)
   16906     3033266 :                 value = tmp_value;
   16907             :             }
   16908     1196819 :           else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   16909             :                    (TREE_TYPE (value)))
   16910          39 :             value = perform_implicit_conversion_flags
   16911          39 :               (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
   16912             :                LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
   16913             : 
   16914     3033266 :           if (value == error_mark_node)
   16915             :             value = NULL_TREE;
   16916             : 
   16917     3033245 :           if (value != NULL_TREE)
   16918             :             {
   16919     3033245 :               if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
   16920             :                   (TREE_TYPE (value)))
   16921             :                 {
   16922          19 :                   error_at (cp_expr_loc_or_input_loc (value),
   16923             :                             "enumerator value for %qD must have integral or "
   16924             :                             "unscoped enumeration type", name);
   16925          19 :                   value = NULL_TREE;
   16926             :                 }
   16927             :               else
   16928             :                 {
   16929     3033226 :                   value = cxx_constant_value (value);
   16930             : 
   16931     3033226 :                   if (TREE_CODE (value) != INTEGER_CST)
   16932             :                     {
   16933          53 :                       error ("enumerator value for %qD is not an integer "
   16934             :                              "constant", name);
   16935          53 :                       value = NULL_TREE;
   16936             :                     }
   16937             :                 }
   16938             :             }
   16939             :         }
   16940             : 
   16941             :       /* Default based on previous value.  */
   16942          72 :       if (value == NULL_TREE)
   16943             :         {
   16944     4167432 :           if (TYPE_VALUES (enumtype))
   16945             :             {
   16946     3864070 :               tree prev_value;
   16947             : 
   16948             :               /* C++03 7.2/4: If no initializer is specified for the first
   16949             :                  enumerator, the type is an unspecified integral
   16950             :                  type. Otherwise the type is the same as the type of the
   16951             :                  initializing value of the preceding enumerator unless the
   16952             :                  incremented value is not representable in that type, in
   16953             :                  which case the type is an unspecified integral type
   16954             :                  sufficient to contain the incremented value.  */
   16955     3864070 :               prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
   16956     3864070 :               if (TREE_CODE (prev_value) != INTEGER_CST)
   16957           3 :                 value = error_mark_node;
   16958             :               else
   16959             :                 {
   16960     3864067 :                   wi::overflow_type overflowed;
   16961     3864067 :                   tree type = TREE_TYPE (prev_value);
   16962     3864067 :                   signop sgn = TYPE_SIGN (type);
   16963     3864067 :                   widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
   16964             :                                            &overflowed);
   16965     3864067 :                   if (!overflowed)
   16966             :                     {
   16967     3864067 :                       bool pos = !wi::neg_p (wi, sgn);
   16968     3864067 :                       if (!wi::fits_to_tree_p (wi, type))
   16969             :                         {
   16970             :                           unsigned int itk;
   16971          63 :                           for (itk = itk_int; itk != itk_none; itk++)
   16972             :                             {
   16973          63 :                               type = integer_types[itk];
   16974          63 :                               if (type != NULL_TREE
   16975          63 :                                   && (pos || !TYPE_UNSIGNED (type))
   16976         126 :                                   && wi::fits_to_tree_p (wi, type))
   16977             :                                 break;
   16978             :                             }
   16979          21 :                           if (type && cxx_dialect < cxx11
   16980           6 :                               && itk > itk_unsigned_long)
   16981           3 :                             pedwarn (input_location, OPT_Wlong_long,
   16982             :                                      pos ? G_("\
   16983             : incremented enumerator value is too large for %<unsigned long%>") : G_("\
   16984             : incremented enumerator value is too large for %<long%>"));
   16985             :                         }
   16986     3864067 :                       if (type == NULL_TREE)
   16987           0 :                         overflowed = wi::OVF_UNKNOWN;
   16988             :                       else
   16989     3864067 :                         value = wide_int_to_tree (type, wi);
   16990             :                     }
   16991             : 
   16992     3864067 :                   if (overflowed)
   16993             :                     {
   16994           0 :                       error ("overflow in enumeration values at %qD", name);
   16995           0 :                       value = error_mark_node;
   16996             :                     }
   16997             :                 }
   16998             :             }
   16999             :           else
   17000      303362 :             value = integer_zero_node;
   17001             :         }
   17002             : 
   17003             :       /* Remove no-op casts from the value.  */
   17004     7200605 :       STRIP_TYPE_NOPS (value);
   17005             : 
   17006             :       /* If the underlying type of the enum is fixed, check whether
   17007             :          the enumerator values fits in the underlying type.  If it
   17008             :          does not fit, the program is ill-formed [C++0x dcl.enum].  */
   17009     7200605 :       if (ENUM_UNDERLYING_TYPE (enumtype)
   17010             :           && value
   17011     7200605 :           && TREE_CODE (value) == INTEGER_CST)
   17012             :         {
   17013     1675992 :           if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
   17014           9 :             error ("enumerator value %qE is outside the range of underlying "
   17015           9 :                    "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
   17016             : 
   17017             :           /* Convert the value to the appropriate type.  */
   17018     1675992 :           value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
   17019             :         }
   17020             :     }
   17021             : 
   17022             :   /* C++ associates enums with global, function, or class declarations.  */
   17023     7460035 :   context = current_scope ();
   17024             : 
   17025             :   /* Build the actual enumeration constant.  Note that the enumeration
   17026             :      constants have the underlying type of the enum (if it is fixed)
   17027             :      or the type of their initializer (if the underlying type of the
   17028             :      enum is not fixed):
   17029             : 
   17030             :       [ C++0x dcl.enum ]
   17031             : 
   17032             :         If the underlying type is fixed, the type of each enumerator
   17033             :         prior to the closing brace is the underlying type; if the
   17034             :         initializing value of an enumerator cannot be represented by
   17035             :         the underlying type, the program is ill-formed. If the
   17036             :         underlying type is not fixed, the type of each enumerator is
   17037             :         the type of its initializing value.
   17038             : 
   17039             :     If the underlying type is not fixed, it will be computed by
   17040             :     finish_enum and we will reset the type of this enumerator.  Of
   17041             :     course, if we're processing a template, there may be no value.  */
   17042     7460035 :   type = value ? TREE_TYPE (value) : NULL_TREE;
   17043             : 
   17044     7460035 :   decl = build_decl (loc, CONST_DECL, name, type);
   17045             :   
   17046     7460035 :   DECL_CONTEXT (decl) = enumtype;
   17047     7460035 :   TREE_CONSTANT (decl) = 1;
   17048     7460035 :   TREE_READONLY (decl) = 1;
   17049     7460035 :   DECL_INITIAL (decl) = value;
   17050             : 
   17051     7460035 :   if (attributes)
   17052         136 :     cplus_decl_attributes (&decl, attributes, 0);
   17053             : 
   17054     7460035 :   if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
   17055             :     {
   17056             :       /* In something like `struct S { enum E { i = 7 }; };' we put `i'
   17057             :          on the TYPE_FIELDS list for `S'.  (That's so that you can say
   17058             :          things like `S::i' later.)  */
   17059             : 
   17060             :       /* The enumerator may be getting declared outside of its enclosing
   17061             :          class, like so:
   17062             : 
   17063             :            class S { public: enum E : int; }; enum S::E : int { i = 7; };
   17064             : 
   17065             :          For which case we need to make sure that the access of `S::i'
   17066             :          matches the access of `S::E'.  */
   17067     1379667 :       auto cas = make_temp_override (current_access_specifier);
   17068     1379667 :       set_current_access_from_decl (TYPE_NAME (enumtype));
   17069     1379667 :       finish_member_declaration (decl);
   17070     1379667 :     }
   17071             :   else
   17072     6080368 :     pushdecl (decl);
   17073             : 
   17074             :   /* Add this enumeration constant to the list for this type.  */
   17075     7460035 :   TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
   17076             : 
   17077     7460035 :   return decl;
   17078             : }
   17079             : 
   17080             : /* Look for an enumerator with the given NAME within the enumeration
   17081             :    type ENUMTYPE.  This routine is used primarily for qualified name
   17082             :    lookup into an enumerator in C++0x, e.g.,
   17083             : 
   17084             :      enum class Color { Red, Green, Blue };
   17085             : 
   17086             :      Color color = Color::Red;
   17087             : 
   17088             :    Returns the value corresponding to the enumerator, or
   17089             :    NULL_TREE if no such enumerator was found.  */
   17090             : tree
   17091     3800123 : lookup_enumerator (tree enumtype, tree name)
   17092             : {
   17093     3800123 :   tree e;
   17094     3800123 :   gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
   17095             : 
   17096     3800123 :   e = purpose_member (name, TYPE_VALUES (enumtype));
   17097     7600149 :   return e? TREE_VALUE (e) : NULL_TREE;
   17098             : }
   17099             : 
   17100             : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL.  */
   17101             : 
   17102             : tree
   17103           0 : cxx_simulate_enum_decl (location_t loc, const char *name,
   17104             :                         vec<string_int_pair> *values)
   17105             : {
   17106           0 :   location_t saved_loc = input_location;
   17107           0 :   input_location = loc;
   17108             : 
   17109           0 :   tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
   17110             :                               NULL_TREE, false, NULL);
   17111           0 :   if (!OPAQUE_ENUM_P (enumtype))
   17112             :     {
   17113           0 :       error_at (loc, "multiple definition of %q#T", enumtype);
   17114           0 :       inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
   17115             :               "previous definition here");
   17116           0 :       return enumtype;
   17117             :     }
   17118           0 :   SET_OPAQUE_ENUM_P (enumtype, false);
   17119           0 :   DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
   17120             : 
   17121           0 :   for (const string_int_pair &value : values)
   17122           0 :     build_enumerator (get_identifier (value.first),
   17123           0 :                       build_int_cst (integer_type_node, value.second),
   17124             :                       enumtype, NULL_TREE, loc);
   17125             : 
   17126           0 :   finish_enum_value_list (enumtype);
   17127           0 :   finish_enum (enumtype);
   17128             : 
   17129           0 :   input_location = saved_loc;
   17130           0 :   return enumtype;
   17131             : }
   17132             : 
   17133             : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL.  */
   17134             : 
   17135             : tree
   17136           0 : cxx_simulate_record_decl (location_t loc, const char *name,
   17137             :                           array_slice<const tree> fields)
   17138             : {
   17139           0 :   iloc_sentinel ils (loc);
   17140             : 
   17141           0 :   tree ident = get_identifier (name);
   17142           0 :   tree type = xref_tag (/*tag_code=*/record_type, ident);
   17143           0 :   if (type != error_mark_node
   17144           0 :       && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
   17145             :     {
   17146           0 :       error ("redefinition of %q#T", type);
   17147           0 :       type = error_mark_node;
   17148             :     }
   17149           0 :   if (type == error_mark_node)
   17150           0 :     return lhd_simulate_record_decl (loc, name, fields);
   17151             : 
   17152           0 :   xref_basetypes (type, NULL_TREE);
   17153           0 :   type = begin_class_definition (type);
   17154           0 :   if (type == error_mark_node)
   17155           0 :     return lhd_simulate_record_decl (loc, name, fields);
   17156             : 
   17157           0 :   for (tree field : fields)
   17158           0 :     finish_member_declaration (field);
   17159             : 
   17160           0 :   type = finish_struct (type, NULL_TREE);
   17161             : 
   17162           0 :   tree decl = build_decl (loc, TYPE_DECL, ident, type);
   17163           0 :   set_underlying_type (decl);
   17164           0 :   lang_hooks.decls.pushdecl (decl);
   17165             : 
   17166           0 :   return type;
   17167           0 : }
   17168             : 
   17169             : /* We're defining DECL.  Make sure that its type is OK.  */
   17170             : 
   17171             : static void
   17172    90434883 : check_function_type (tree decl, tree current_function_parms)
   17173             : {
   17174    90434883 :   tree fntype = TREE_TYPE (decl);
   17175    90434883 :   tree return_type = complete_type (TREE_TYPE (fntype));
   17176             : 
   17177             :   /* In a function definition, arg types must be complete.  */
   17178    90434883 :   require_complete_types_for_parms (current_function_parms);
   17179             : 
   17180    90434883 :   if (dependent_type_p (return_type)
   17181    90434883 :       || type_uses_auto (return_type))
   17182    27169365 :     return;
   17183    63265518 :   if (!COMPLETE_OR_VOID_TYPE_P (return_type))
   17184             :     {
   17185          15 :       tree args = TYPE_ARG_TYPES (fntype);
   17186             : 
   17187          15 :       error ("return type %q#T is incomplete", return_type);
   17188             : 
   17189             :       /* Make it return void instead.  */
   17190          15 :       if (TREE_CODE (fntype) == METHOD_TYPE)
   17191           4 :         fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
   17192             :                                              void_type_node,
   17193           4 :                                              TREE_CHAIN (args));
   17194             :       else
   17195          11 :         fntype = build_function_type (void_type_node, args);
   17196          15 :       fntype = (cp_build_type_attribute_variant
   17197          15 :                 (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
   17198          15 :       fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
   17199          15 :       TREE_TYPE (decl) = fntype;
   17200             :     }
   17201             :   else
   17202             :     {
   17203    63265503 :       abstract_virtuals_error (decl, TREE_TYPE (fntype));
   17204    63265503 :       maybe_warn_parm_abi (TREE_TYPE (fntype),
   17205    63265503 :                            DECL_SOURCE_LOCATION (decl));
   17206             :     }
   17207             : }
   17208             : 
   17209             : /* True iff FN is an implicitly-defined default constructor.  */
   17210             : 
   17211             : static bool
   17212     2945705 : implicit_default_ctor_p (tree fn)
   17213             : {
   17214     2945705 :   return (DECL_CONSTRUCTOR_P (fn)
   17215     2945705 :           && !user_provided_p (fn)
   17216     3312711 :           && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
   17217             : }
   17218             : 
   17219             : /* Clobber the contents of *this to let the back end know that the object
   17220             :    storage is dead when we enter the constructor or leave the destructor.  */
   17221             : 
   17222             : static tree
   17223     3524665 : build_clobber_this ()
   17224             : {
   17225             :   /* Clobbering an empty base is pointless, and harmful if its one byte
   17226             :      TYPE_SIZE overlays real data.  */
   17227     3524665 :   if (is_empty_class (current_class_type))
   17228           0 :     return void_node;
   17229             : 
   17230             :   /* If we have virtual bases, clobber the whole object, but only if we're in
   17231             :      charge.  If we don't have virtual bases, clobber the as-base type so we
   17232             :      don't mess with tail padding.  */
   17233     3524665 :   bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
   17234             : 
   17235     3524665 :   tree ctype = current_class_type;
   17236     3524665 :   if (!vbases)
   17237     3514986 :     ctype = CLASSTYPE_AS_BASE (ctype);
   17238             : 
   17239     3524665 :   tree clobber = build_clobber (ctype);
   17240             : 
   17241     3524665 :   tree thisref = current_class_ref;
   17242     3524665 :   if (ctype != current_class_type)
   17243             :     {
   17244      384877 :       thisref = build_nop (build_reference_type (ctype), current_class_ptr);
   17245      384877 :       thisref = convert_from_reference (thisref);
   17246             :     }
   17247             : 
   17248     3524665 :   tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
   17249     3524665 :   if (vbases)
   17250        9679 :     exprstmt = build_if_in_charge (exprstmt);
   17251             : 
   17252             :   return exprstmt;
   17253             : }
   17254             : 
   17255             : /* Create the FUNCTION_DECL for a function definition.
   17256             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   17257             :    they describe the function's name and the type it returns,
   17258             :    but twisted together in a fashion that parallels the syntax of C.
   17259             : 
   17260             :    FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
   17261             :    DECLARATOR is really the DECL for the function we are about to
   17262             :    process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
   17263             :    indicating that the function is an inline defined in-class.
   17264             : 
   17265             :    This function creates a binding context for the function body
   17266             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   17267             : 
   17268             :    For C++, we must first check whether that datum makes any sense.
   17269             :    For example, "class A local_a(1,2);" means that variable local_a
   17270             :    is an aggregate of type A, which should have a constructor
   17271             :    applied to it with the argument list [1, 2].
   17272             : 
   17273             :    On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
   17274             :    or may be a BLOCK if the function has been defined previously
   17275             :    in this translation unit.  On exit, DECL_INITIAL (decl1) will be
   17276             :    error_mark_node if the function has never been defined, or
   17277             :    a BLOCK if the function has been defined somewhere.  */
   17278             : 
   17279             : bool
   17280    90434919 : start_preparsed_function (tree decl1, tree attrs, int flags)
   17281             : {
   17282    90434919 :   tree ctype = NULL_TREE;
   17283    90434919 :   bool doing_friend = false;
   17284             : 
   17285             :   /* Sanity check.  */
   17286    90434919 :   gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
   17287    90434919 :   gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
   17288             : 
   17289    90434919 :   tree fntype = TREE_TYPE (decl1);
   17290    90434919 :   if (TREE_CODE (fntype) == METHOD_TYPE)
   17291    57171039 :     ctype = TYPE_METHOD_BASETYPE (fntype);
   17292             :   else
   17293             :     {
   17294    66527760 :       ctype = DECL_FRIEND_CONTEXT (decl1);
   17295             : 
   17296    33263880 :       if (ctype)
   17297    90434919 :         doing_friend = true;
   17298             :     }
   17299             : 
   17300    90434919 :   if (DECL_DECLARED_INLINE_P (decl1)
   17301    90434919 :       && lookup_attribute ("noinline", attrs))
   17302           0 :     warning_at (DECL_SOURCE_LOCATION (decl1), 0,
   17303             :                 "inline function %qD given attribute %qs", decl1, "noinline");
   17304             : 
   17305             :   /* Handle gnu_inline attribute.  */
   17306    90434919 :   if (GNU_INLINE_P (decl1))
   17307             :     {
   17308     1380776 :       DECL_EXTERNAL (decl1) = 1;
   17309     1380776 :       DECL_NOT_REALLY_EXTERN (decl1) = 0;
   17310     1380776 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   17311     1380776 :       DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
   17312             :     }
   17313             : 
   17314    90434919 :   if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
   17315             :     /* This is a constructor, we must ensure that any default args
   17316             :        introduced by this definition are propagated to the clones
   17317             :        now. The clones are used directly in overload resolution.  */
   17318    11911272 :     adjust_clone_args (decl1);
   17319             : 
   17320             :   /* Sometimes we don't notice that a function is a static member, and
   17321             :      build a METHOD_TYPE for it.  Fix that up now.  */
   17322    90434919 :   gcc_assert (!(ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)
   17323             :                 && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
   17324             : 
   17325             :   /* Set up current_class_type, and enter the scope of the class, if
   17326             :      appropriate.  */
   17327    90434919 :   if (ctype)
   17328    58430888 :     push_nested_class (ctype);
   17329    32004031 :   else if (DECL_STATIC_FUNCTION_P (decl1))
   17330     7135367 :     push_nested_class (DECL_CONTEXT (decl1));
   17331             : 
   17332             :   /* Now that we have entered the scope of the class, we must restore
   17333             :      the bindings for any template parameters surrounding DECL1, if it
   17334             :      is an inline member template.  (Order is important; consider the
   17335             :      case where a template parameter has the same name as a field of
   17336             :      the class.)  It is not until after this point that
   17337             :      PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly.  */
   17338    90434919 :   if (flags & SF_INCLASS_INLINE)
   17339    43396591 :     maybe_begin_member_template_processing (decl1);
   17340             : 
   17341             :   /* Effective C++ rule 15.  */
   17342    90434919 :   if (warn_ecpp
   17343         164 :       && DECL_ASSIGNMENT_OPERATOR_P (decl1)
   17344          40 :       && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
   17345    90434959 :       && VOID_TYPE_P (TREE_TYPE (fntype)))
   17346           0 :     warning (OPT_Weffc__,
   17347             :              "%<operator=%> should return a reference to %<*this%>");
   17348             : 
   17349             :   /* Make the init_value nonzero so pushdecl knows this is not tentative.
   17350             :      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
   17351    90434919 :   if (!DECL_INITIAL (decl1))
   17352    16938117 :     DECL_INITIAL (decl1) = error_mark_node;
   17353             : 
   17354             :   /* This function exists in static storage.
   17355             :      (This does not mean `static' in the C sense!)  */
   17356    90434919 :   TREE_STATIC (decl1) = 1;
   17357             : 
   17358             :   /* We must call push_template_decl after current_class_type is set
   17359             :      up.  (If we are processing inline definitions after exiting a
   17360             :      class scope, current_class_type will be NULL_TREE until set above
   17361             :      by push_nested_class.)  */
   17362    90434919 :   if (processing_template_decl)
   17363             :     {
   17364    55998184 :       tree newdecl1 = push_template_decl (decl1, doing_friend);
   17365    55998184 :       if (newdecl1 == error_mark_node)
   17366             :         {
   17367          36 :           if (ctype || DECL_STATIC_FUNCTION_P (decl1))
   17368           8 :             pop_nested_class ();
   17369          36 :           return false;
   17370             :         }
   17371             :       decl1 = newdecl1;
   17372             :     }
   17373             : 
   17374             :   /* Make sure the parameter and return types are reasonable.  When
   17375             :      you declare a function, these types can be incomplete, but they
   17376             :      must be complete when you define the function.  */
   17377    90434883 :   check_function_type (decl1, DECL_ARGUMENTS (decl1));
   17378             : 
   17379             :   /* Build the return declaration for the function.  */
   17380    90434883 :   tree restype = TREE_TYPE (fntype);
   17381             : 
   17382    90434883 :   if (DECL_RESULT (decl1) == NULL_TREE)
   17383             :     {
   17384             :       /* In a template instantiation, copy the return type location.  When
   17385             :          parsing, the location will be set in grokdeclarator.  */
   17386    33382629 :       location_t loc = input_location;
   17387    33382629 :       if (DECL_TEMPLATE_INSTANTIATION (decl1))
   17388             :         {
   17389    15049889 :           tree tmpl = template_for_substitution (decl1);
   17390    15049889 :           if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
   17391    14534772 :             loc = DECL_SOURCE_LOCATION (res);
   17392             :         }
   17393             : 
   17394    33382629 :       tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
   17395    33382629 :       DECL_ARTIFICIAL (resdecl) = 1;
   17396    33382629 :       DECL_IGNORED_P (resdecl) = 1;
   17397    33382629 :       DECL_RESULT (decl1) = resdecl;
   17398             : 
   17399    33382629 :       cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
   17400             :     }
   17401             : 
   17402             :   /* Record the decl so that the function name is defined.
   17403             :      If we already have a decl for this name, and it is a FUNCTION_DECL,
   17404             :      use the old decl.  */
   17405    90434883 :   if (!processing_template_decl && !(flags & SF_PRE_PARSED))
   17406             :     {
   17407             :       /* A specialization is not used to guide overload resolution.  */
   17408    13675878 :       if (!DECL_FUNCTION_MEMBER_P (decl1)
   17409    13667909 :           && !(DECL_USE_TEMPLATE (decl1) &&
   17410         605 :                PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
   17411             :         {
   17412     6552750 :           tree olddecl = pushdecl (decl1);
   17413             : 
   17414     6552750 :           if (olddecl == error_mark_node)
   17415             :             /* If something went wrong when registering the declaration,
   17416             :                use DECL1; we have to have a FUNCTION_DECL to use when
   17417             :                parsing the body of the function.  */
   17418             :             ;
   17419             :           else
   17420             :             {
   17421             :               /* Otherwise, OLDDECL is either a previous declaration
   17422             :                  of the same function or DECL1 itself.  */
   17423             : 
   17424     6552485 :               if (warn_missing_declarations
   17425          28 :                   && olddecl == decl1
   17426          20 :                   && !DECL_MAIN_P (decl1)
   17427          20 :                   && TREE_PUBLIC (decl1)
   17428     6552501 :                   && !DECL_DECLARED_INLINE_P (decl1))
   17429             :                 {
   17430          12 :                   tree context;
   17431             : 
   17432             :                   /* Check whether DECL1 is in an anonymous
   17433             :                      namespace.  */
   17434          12 :                   for (context = DECL_CONTEXT (decl1);
   17435          24 :                        context;
   17436          12 :                        context = DECL_CONTEXT (context))
   17437             :                     {
   17438          16 :                       if (TREE_CODE (context) == NAMESPACE_DECL
   17439          16 :                           && DECL_NAME (context) == NULL_TREE)
   17440             :                         break;
   17441             :                     }
   17442             : 
   17443          12 :                   if (context == NULL)
   17444           8 :                     warning_at (DECL_SOURCE_LOCATION (decl1),
   17445             :                                 OPT_Wmissing_declarations,
   17446             :                                 "no previous declaration for %qD", decl1);
   17447             :                 }
   17448             : 
   17449             :               decl1 = olddecl;
   17450             :             }
   17451             :         }
   17452             :       else
   17453             :         {
   17454             :           /* We need to set the DECL_CONTEXT.  */
   17455      561804 :           if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
   17456           0 :             DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
   17457             :         }
   17458     7114554 :       fntype = TREE_TYPE (decl1);
   17459     7114554 :       restype = TREE_TYPE (fntype);
   17460             : 
   17461             :       /* If #pragma weak applies, mark the decl appropriately now.
   17462             :          The pragma only applies to global functions.  Because
   17463             :          determining whether or not the #pragma applies involves
   17464             :          computing the mangled name for the declaration, we cannot
   17465             :          apply the pragma until after we have merged this declaration
   17466             :          with any previous declarations; if the original declaration
   17467             :          has a linkage specification, that specification applies to
   17468             :          the definition as well, and may affect the mangled name.  */
   17469     7114554 :       if (DECL_FILE_SCOPE_P (decl1))
   17470     1992006 :         maybe_apply_pragma_weak (decl1);
   17471             :     }
   17472             : 
   17473             :   /* We are now in the scope of the function being defined.  */
   17474    90434883 :   current_function_decl = decl1;
   17475             : 
   17476             :   /* Save the parm names or decls from this function's declarator
   17477             :      where store_parm_decls will find them.  */
   17478    90434883 :   tree current_function_parms = DECL_ARGUMENTS (decl1);
   17479             : 
   17480             :   /* Let the user know we're compiling this function.  */
   17481    90434883 :   announce_function (decl1);
   17482             : 
   17483    90434883 :   gcc_assert (DECL_INITIAL (decl1));
   17484             : 
   17485             :   /* This function may already have been parsed, in which case just
   17486             :      return; our caller will skip over the body without parsing.  */
   17487    90434883 :   if (DECL_INITIAL (decl1) != error_mark_node)
   17488             :     return true;
   17489             : 
   17490             :   /* Initialize RTL machinery.  We cannot do this until
   17491             :      CURRENT_FUNCTION_DECL and DECL_RESULT are set up.  We do this
   17492             :      even when processing a template; this is how we get
   17493             :      CFUN set up, and our per-function variables initialized.
   17494             :      FIXME factor out the non-RTL stuff.  */
   17495    90434883 :   cp_binding_level *bl = current_binding_level;
   17496    90434883 :   allocate_struct_function (decl1, processing_template_decl);
   17497             : 
   17498             :   /* Initialize the language data structures.  Whenever we start
   17499             :      a new function, we destroy temporaries in the usual way.  */
   17500    90434883 :   cfun->language = ggc_cleared_alloc<language_function> ();
   17501    90434883 :   current_stmt_tree ()->stmts_are_full_exprs_p = 1;
   17502    90434883 :   current_binding_level = bl;
   17503             : 
   17504             :   /* If we are (erroneously) defining a function that we have already
   17505             :      defined before, wipe out what we knew before.  */
   17506    90434883 :   gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
   17507    90434883 :   FNDECL_USED_AUTO (decl1) = false;
   17508    90434883 :   DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
   17509             : 
   17510    90434883 :   if (!processing_template_decl && type_uses_auto (restype))
   17511             :     {
   17512       83104 :       FNDECL_USED_AUTO (decl1) = true;
   17513       83104 :       DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
   17514             :     }
   17515             : 
   17516             :   /* Start the statement-tree, start the tree now.  */
   17517    90434883 :   DECL_SAVED_TREE (decl1) = push_stmt_list ();
   17518             : 
   17519    90434883 :   if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1))
   17520             :     {
   17521             :       /* We know that this was set up by `grokclassfn'.  We do not
   17522             :          wait until `store_parm_decls', since evil parse errors may
   17523             :          never get us to that point.  Here we keep the consistency
   17524             :          between `current_class_type' and `current_class_ptr'.  */
   17525    57171031 :       tree t = DECL_ARGUMENTS (decl1);
   17526             : 
   17527    57171031 :       gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
   17528    57171031 :       gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
   17529             : 
   17530    57171031 :       cp_function_chain->x_current_class_ref
   17531    57171031 :         = cp_build_fold_indirect_ref (t);
   17532             :       /* Set this second to avoid shortcut in cp_build_indirect_ref.  */
   17533    57171031 :       cp_function_chain->x_current_class_ptr = t;
   17534             : 
   17535             :       /* Constructors and destructors need to know whether they're "in
   17536             :          charge" of initializing virtual base classes.  */
   17537    57171031 :       t = DECL_CHAIN (t);
   17538    57171031 :       if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
   17539             :         {
   17540      964245 :           current_in_charge_parm = t;
   17541      964245 :           t = DECL_CHAIN (t);
   17542             :         }
   17543    57171031 :       if (DECL_HAS_VTT_PARM_P (decl1))
   17544             :         {
   17545       24439 :           gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
   17546       24439 :           current_vtt_parm = t;
   17547             :         }
   17548             :     }
   17549             : 
   17550    90434883 :   bool honor_interface = (!DECL_TEMPLATE_INSTANTIATION (decl1)
   17551             :                           /* Implicitly-defined methods (like the
   17552             :                              destructor for a class in which no destructor
   17553             :                              is explicitly declared) must not be defined
   17554             :                              until their definition is needed.  So, we
   17555             :                              ignore interface specifications for
   17556             :                              compiler-generated functions.  */
   17557    90434883 :                           && !DECL_ARTIFICIAL (decl1));
   17558    90434883 :   struct c_fileinfo *finfo
   17559    90434883 :     = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
   17560             : 
   17561    90434883 :   if (processing_template_decl)
   17562             :     /* Don't mess with interface flags.  */;
   17563    34436735 :   else if (DECL_INTERFACE_KNOWN (decl1))
   17564             :     {
   17565    11968140 :       tree ctx = decl_function_context (decl1);
   17566             : 
   17567    11968140 :       if (DECL_NOT_REALLY_EXTERN (decl1))
   17568     9247442 :         DECL_EXTERNAL (decl1) = 0;
   17569             : 
   17570    11968140 :       if (ctx != NULL_TREE && vague_linkage_p (ctx))
   17571             :         /* This is a function in a local class in an extern inline
   17572             :            or template function.  */
   17573     1469425 :         comdat_linkage (decl1);
   17574             :     }
   17575             :   /* If this function belongs to an interface, it is public.
   17576             :      If it belongs to someone else's interface, it is also external.
   17577             :      This only affects inlines and template instantiations.  */
   17578    22468595 :   else if (!finfo->interface_unknown && honor_interface)
   17579             :     {
   17580         140 :       if (DECL_DECLARED_INLINE_P (decl1)
   17581         140 :           || DECL_TEMPLATE_INSTANTIATION (decl1))
   17582             :         {
   17583         112 :           DECL_EXTERNAL (decl1)
   17584         224 :             = (finfo->interface_only
   17585         112 :                || (DECL_DECLARED_INLINE_P (decl1)
   17586          53 :                    && ! flag_implement_inlines
   17587           0 :                    && !DECL_VINDEX (decl1)));
   17588             : 
   17589             :           /* For WIN32 we also want to put these in linkonce sections.  */
   17590         112 :           maybe_make_one_only (decl1);
   17591             :         }
   17592             :       else
   17593          28 :         DECL_EXTERNAL (decl1) = 0;
   17594         140 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   17595             :       /* If this function is in an interface implemented in this file,
   17596             :          make sure that the back end knows to emit this function
   17597             :          here.  */
   17598         140 :       if (!DECL_EXTERNAL (decl1))
   17599          81 :         mark_needed (decl1);
   17600             :     }
   17601    22468455 :   else if (finfo->interface_unknown && finfo->interface_only
   17602           0 :            && honor_interface)
   17603             :     {
   17604             :       /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
   17605             :          interface, we will have both finfo->interface_unknown and
   17606             :          finfo->interface_only set.  In that case, we don't want to
   17607             :          use the normal heuristics because someone will supply a
   17608             :          #pragma implementation elsewhere, and deducing it here would
   17609             :          produce a conflict.  */
   17610           0 :       comdat_linkage (decl1);
   17611           0 :       DECL_EXTERNAL (decl1) = 0;
   17612           0 :       DECL_INTERFACE_KNOWN (decl1) = 1;
   17613           0 :       DECL_DEFER_OUTPUT (decl1) = 1;
   17614             :     }
   17615             :   else
   17616             :     {
   17617             :       /* This is a definition, not a reference.
   17618             :          So clear DECL_EXTERNAL, unless this is a GNU extern inline.  */
   17619    22468455 :       if (!GNU_INLINE_P (decl1))
   17620    22468455 :         DECL_EXTERNAL (decl1) = 0;
   17621             : 
   17622    22468455 :       if ((DECL_DECLARED_INLINE_P (decl1)
   17623     1462899 :            || DECL_TEMPLATE_INSTANTIATION (decl1))
   17624    23716765 :           && ! DECL_INTERFACE_KNOWN (decl1))
   17625    22253866 :         DECL_DEFER_OUTPUT (decl1) = 1;
   17626             :       else
   17627      214589 :         DECL_INTERFACE_KNOWN (decl1) = 1;
   17628             :     }
   17629             : 
   17630             :   /* Determine the ELF visibility attribute for the function.  We must not
   17631             :      do this before calling "pushdecl", as we must allow "duplicate_decls"
   17632             :      to merge any attributes appropriately.  We also need to wait until
   17633             :      linkage is set.  */
   17634    90434883 :   if (!DECL_CLONED_FUNCTION_P (decl1))
   17635    81640768 :     determine_visibility (decl1);
   17636             : 
   17637    90434883 :   if (!processing_template_decl)
   17638    34436735 :     maybe_instantiate_noexcept (decl1);
   17639             : 
   17640    90434883 :   begin_scope (sk_function_parms, decl1);
   17641             : 
   17642    90434883 :   ++function_depth;
   17643             : 
   17644    90434883 :   start_fname_decls ();
   17645             : 
   17646    90434883 :   store_parm_decls (current_function_parms);
   17647             : 
   17648    90434883 :   start_function_contracts (decl1);
   17649             : 
   17650    90434883 :   if (!processing_template_decl
   17651    34436735 :       && (flag_lifetime_dse > 1)
   17652    68865050 :       && DECL_CONSTRUCTOR_P (decl1)
   17653    10045453 :       && !DECL_CLONED_FUNCTION_P (decl1)
   17654             :       /* Clobbering an empty base is harmful if it overlays real data.  */
   17655     3343775 :       && !is_empty_class (current_class_type)
   17656             :       /* We can't clobber safely for an implicitly-defined default constructor
   17657             :          because part of the initialization might happen before we enter the
   17658             :          constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
   17659    93380033 :       && !implicit_default_ctor_p (decl1))
   17660     2731627 :     finish_expr_stmt (build_clobber_this ());
   17661             : 
   17662    90434883 :   if (!processing_template_decl
   17663    68873470 :       && DECL_CONSTRUCTOR_P (decl1)
   17664    10046722 :       && sanitize_flags_p (SANITIZE_VPTR)
   17665        1665 :       && !DECL_CLONED_FUNCTION_P (decl1)
   17666    90435438 :       && !implicit_default_ctor_p (decl1))
   17667         432 :     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
   17668             : 
   17669    90434883 :   if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
   17670    90434195 :     start_lambda_scope (decl1);
   17671             : 
   17672             :   return true;
   17673             : }
   17674             : 
   17675             : 
   17676             : /* Like start_preparsed_function, except that instead of a
   17677             :    FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
   17678             : 
   17679             :    Returns true on success.  If the DECLARATOR is not suitable
   17680             :    for a function, we return false, which tells the parser to
   17681             :    skip the entire function.  */
   17682             : 
   17683             : bool
   17684    27330351 : start_function (cp_decl_specifier_seq *declspecs,
   17685             :                 const cp_declarator *declarator,
   17686             :                 tree attrs)
   17687             : {
   17688    27330351 :   tree decl1;
   17689             : 
   17690    27330351 :   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
   17691    27330351 :   invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
   17692    27330351 :   if (decl1 == error_mark_node)
   17693             :     return false;
   17694             : 
   17695    27330031 :   if (DECL_MAIN_P (decl1))
   17696             :     /* main must return int.  grokfndecl should have corrected it
   17697             :        (and issued a diagnostic) if the user got it wrong.  */
   17698       30907 :     gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
   17699             :                              integer_type_node));
   17700             : 
   17701    27330031 :   return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
   17702             : }
   17703             : 
   17704             : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
   17705             :    FN.  */
   17706             : 
   17707             : static bool
   17708   172077974 : use_eh_spec_block (tree fn)
   17709             : {
   17710   170231899 :   return (flag_exceptions && flag_enforce_eh_specs
   17711   170231899 :           && !processing_template_decl
   17712             :           /* We insert the EH_SPEC_BLOCK only in the original
   17713             :              function; then, it is copied automatically to the
   17714             :              clones.  */
   17715    58605791 :           && !DECL_CLONED_FUNCTION_P (fn)
   17716             :           /* Implicitly-generated constructors and destructors have
   17717             :              exception specifications.  However, those specifications
   17718             :              are the union of the possible exceptions specified by the
   17719             :              constructors/destructors for bases and members, so no
   17720             :              unallowed exception will ever reach this function.  By
   17721             :              not creating the EH_SPEC_BLOCK we save a little memory,
   17722             :              and we avoid spurious warnings about unreachable
   17723             :              code.  */
   17724    49853381 :           && !DECL_DEFAULTED_FN (fn)
   17725   220539469 :           && !type_throw_all_p (TREE_TYPE (fn)));
   17726             : }
   17727             : 
   17728             : /* Helper function to push ARGS into the current lexical scope.  DECL
   17729             :    is the function declaration.  NONPARMS is used to handle enum
   17730             :    constants.  */
   17731             : 
   17732             : void
   17733    88738632 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
   17734             : {
   17735             :   /* If we're doing semantic analysis, then we'll call pushdecl
   17736             :      for each of these.  We must do them in reverse order so that
   17737             :      they end in the correct forward order.  */
   17738    88738632 :   args = nreverse (args);
   17739             : 
   17740    88738632 :   tree next;
   17741   274239588 :   for (tree parm = args; parm; parm = next)
   17742             :     {
   17743   185500956 :       next = DECL_CHAIN (parm);
   17744   185500956 :       if (TREE_CODE (parm) == PARM_DECL)
   17745   185500956 :         pushdecl (parm);
   17746           0 :       else if (nonparms)
   17747             :         {
   17748             :           /* If we find an enum constant or a type tag, put it aside for
   17749             :              the moment.  */
   17750           0 :           TREE_CHAIN (parm) = NULL_TREE;
   17751           0 :           *nonparms = chainon (*nonparms, parm);
   17752             :         }
   17753             :     }
   17754             : 
   17755             :   /* Get the decls in their original chain order and record in the
   17756             :      function.  This is all and only the PARM_DECLs that were
   17757             :      pushed into scope by the loop above.  */
   17758    88738632 :   DECL_ARGUMENTS (decl) = get_local_decls ();
   17759    88738632 : }
   17760             : 
   17761             : /* Store the parameter declarations into the current function declaration.
   17762             :    This is called after parsing the parameter declarations, before
   17763             :    digesting the body of the function.
   17764             : 
   17765             :    Also install to binding contour return value identifier, if any.  */
   17766             : 
   17767             : static void
   17768    90437259 : store_parm_decls (tree current_function_parms)
   17769             : {
   17770    90437259 :   tree fndecl = current_function_decl;
   17771             : 
   17772             :   /* This is a chain of any other decls that came in among the parm
   17773             :      declarations.  If a parm is declared with  enum {foo, bar} x;
   17774             :      then CONST_DECLs for foo and bar are put here.  */
   17775    90437259 :   tree nonparms = NULL_TREE;
   17776             : 
   17777    90437259 :   if (current_function_parms)
   17778             :     {
   17779             :       /* This case is when the function was defined with an ANSI prototype.
   17780             :          The parms already have decls, so we need not do anything here
   17781             :          except record them as in effect
   17782             :          and complain if any redundant old-style parm decls were written.  */
   17783             : 
   17784    87101642 :       tree specparms = current_function_parms;
   17785             : 
   17786             :       /* Must clear this because it might contain TYPE_DECLs declared
   17787             :              at class level.  */
   17788    87101642 :       current_binding_level->names = NULL;
   17789             : 
   17790    87101642 :       do_push_parm_decls (fndecl, specparms, &nonparms);
   17791             :     }
   17792             :   else
   17793     3335617 :     DECL_ARGUMENTS (fndecl) = NULL_TREE;
   17794             : 
   17795             :   /* Now store the final chain of decls for the arguments
   17796             :      as the decl-chain of the current lexical scope.
   17797             :      Put the enumerators in as well, at the front so that
   17798             :      DECL_ARGUMENTS is not modified.  */
   17799    90437259 :   current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
   17800             : 
   17801    90437259 :   if (use_eh_spec_block (current_function_decl))
   17802    10840804 :     current_eh_spec_block = begin_eh_spec_block ();
   17803    90437259 : }
   17804             : 
   17805             : 
   17806             : /* Set the return value of the [cd]tor if the ABI wants that.  */
   17807             : 
   17808             : void
   17809     4474395 : maybe_return_this (void)
   17810             : {
   17811     4474395 :   if (targetm.cxx.cdtor_returns_this ())
   17812             :     {
   17813             :       /* Return the address of the object.  */
   17814           0 :       tree val = DECL_ARGUMENTS (current_function_decl);
   17815           0 :       suppress_warning (val, OPT_Wuse_after_free);
   17816           0 :       val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
   17817           0 :       val = build2 (MODIFY_EXPR, TREE_TYPE (val),
   17818           0 :                     DECL_RESULT (current_function_decl), val);
   17819           0 :       tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
   17820           0 :       add_stmt (exprstmt);
   17821             :     }
   17822     4474395 : }
   17823             : 
   17824             : /* Do all the processing for the beginning of a destructor; set up the
   17825             :    vtable pointers and cleanups for bases and members.  */
   17826             : 
   17827             : static void
   17828      956910 : begin_destructor_body (void)
   17829             : {
   17830      956910 :   tree compound_stmt;
   17831             : 
   17832             :   /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
   17833             :      issued an error message.  We still want to try to process the
   17834             :      body of the function, but initialize_vtbl_ptrs will crash if
   17835             :      TYPE_BINFO is NULL.  */
   17836      956910 :   if (COMPLETE_TYPE_P (current_class_type))
   17837             :     {
   17838      956910 :       compound_stmt = begin_compound_stmt (0);
   17839             :       /* Make all virtual function table pointers in non-virtual base
   17840             :          classes point to CURRENT_CLASS_TYPE's virtual function
   17841             :          tables.  */
   17842      956910 :       initialize_vtbl_ptrs (current_class_ptr);
   17843      956910 :       finish_compound_stmt (compound_stmt);
   17844             : 
   17845      956910 :       if (flag_lifetime_dse
   17846             :           /* Clobbering an empty base is harmful if it overlays real data.  */
   17847      956910 :           && !is_empty_class (current_class_type))
   17848             :       {
   17849      793117 :         if (sanitize_flags_p (SANITIZE_VPTR)
   17850         221 :             && (flag_sanitize_recover & SANITIZE_VPTR) == 0
   17851      793196 :             && TYPE_CONTAINS_VPTR_P (current_class_type))
   17852             :           {
   17853          79 :             tree binfo = TYPE_BINFO (current_class_type);
   17854          79 :             tree ref
   17855          79 :               = cp_build_fold_indirect_ref (current_class_ptr);
   17856             : 
   17857          79 :             tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
   17858          79 :             tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
   17859          79 :             tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
   17860             :                                               NOP_EXPR, vtbl,
   17861             :                                               tf_warning_or_error);
   17862             :             /* If the vptr is shared with some virtual nearly empty base,
   17863             :                don't clear it if not in charge, the dtor of the virtual
   17864             :                nearly empty base will do that later.  */
   17865          79 :             if (CLASSTYPE_VBASECLASSES (current_class_type))
   17866             :               {
   17867             :                 tree c = current_class_type;
   17868          82 :                 while (CLASSTYPE_PRIMARY_BINFO (c))
   17869             :                   {
   17870          78 :                     if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
   17871             :                       {
   17872          45 :                         stmt = convert_to_void (stmt, ICV_STATEMENT,
   17873             :                                                 tf_warning_or_error);
   17874          45 :                         stmt = build_if_in_charge (stmt);
   17875          45 :                         break;
   17876             :                       }
   17877          33 :                     c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
   17878             :                   }
   17879             :               }
   17880          79 :             finish_decl_cleanup (NULL_TREE, stmt);
   17881             :           }
   17882             :         else
   17883      793038 :           finish_decl_cleanup (NULL_TREE, build_clobber_this ());
   17884             :       }
   17885             : 
   17886             :       /* And insert cleanups for our bases and members so that they
   17887             :          will be properly destroyed if we throw.  */
   17888      956910 :       push_base_cleanups ();
   17889             :     }
   17890      956910 : }
   17891             : 
   17892             : /* Do the necessary processing for the beginning of a function body, which
   17893             :    in this case includes member-initializers, but not the catch clauses of
   17894             :    a function-try-block.  Currently, this means opening a binding level
   17895             :    for the member-initializers (in a ctor), member cleanups (in a dtor),
   17896             :    and capture proxies (in a lambda operator()).  */
   17897             : 
   17898             : tree
   17899    73567750 : begin_function_body (void)
   17900             : {
   17901   149777546 :   if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
   17902             :     return NULL_TREE;
   17903             : 
   17904    13911147 :   if (processing_template_decl)
   17905             :     /* Do nothing now.  */;
   17906             :   else
   17907             :     /* Always keep the BLOCK node associated with the outermost pair of
   17908             :        curly braces of a function.  These are needed for correct
   17909             :        operation of dwarfout.c.  */
   17910     4352349 :     keep_next_level (true);
   17911             : 
   17912    13911147 :   tree stmt = begin_compound_stmt (BCS_FN_BODY);
   17913             : 
   17914    13911147 :   if (processing_template_decl)
   17915             :     /* Do nothing now.  */;
   17916     8704698 :   else if (DECL_DESTRUCTOR_P (current_function_decl))
   17917      956910 :     begin_destructor_body ();
   17918             : 
   17919             :   return stmt;
   17920             : }
   17921             : 
   17922             : /* Do the processing for the end of a function body.  Currently, this means
   17923             :    closing out the cleanups for fully-constructed bases and members, and in
   17924             :    the case of the destructor, deleting the object if desired.  Again, this
   17925             :    is only meaningful for [cd]tors, since they are the only functions where
   17926             :    there is a significant distinction between the main body and any
   17927             :    function catch clauses.  Handling, say, main() return semantics here
   17928             :    would be wrong, as flowing off the end of a function catch clause for
   17929             :    main() would also need to return 0.  */
   17930             : 
   17931             : void
   17932    73567725 : finish_function_body (tree compstmt)
   17933             : {
   17934    73567725 :   if (compstmt == NULL_TREE)
   17935             :     return;
   17936             : 
   17937             :   /* Close the block.  */
   17938    13911147 :   finish_compound_stmt (compstmt);
   17939             : 
   17940    13911147 :   if (processing_template_decl)
   17941             :     /* Do nothing now.  */;
   17942     4352349 :   else if (DECL_CONSTRUCTOR_P (current_function_decl)
   17943     4352349 :            || DECL_DESTRUCTOR_P (current_function_decl))
   17944     4301108 :     maybe_return_this ();
   17945             : }
   17946             : 
   17947             : /* Given a function, returns the BLOCK corresponding to the outermost level
   17948             :    of curly braces, skipping the artificial block created for constructor
   17949             :    initializers.  */
   17950             : 
   17951             : tree
   17952      202812 : outer_curly_brace_block (tree fndecl)
   17953             : {
   17954      202812 :   tree block = DECL_INITIAL (fndecl);
   17955      202812 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   17956             :     return block;
   17957         155 :   block = BLOCK_SUBBLOCKS (block);
   17958         155 :   if (BLOCK_OUTER_CURLY_BRACE_P (block))
   17959             :     return block;
   17960           0 :   block = BLOCK_SUBBLOCKS (block);
   17961           0 :   gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
   17962             :   return block;
   17963             : }
   17964             : 
   17965             : /* If FNDECL is a class's key method, add the class to the list of
   17966             :    keyed classes that should be emitted.  */
   17967             : 
   17968             : static void
   17969    90438546 : record_key_method_defined (tree fndecl)
   17970             : {
   17971    90438546 :   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
   17972    57171063 :       && DECL_VIRTUAL_P (fndecl)
   17973    92140117 :       && !processing_template_decl)
   17974             :     {
   17975      779459 :       tree fnclass = DECL_CONTEXT (fndecl);
   17976      779459 :       if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
   17977        1906 :         vec_safe_push (keyed_classes, fnclass);
   17978             :     }
   17979    90438546 : }
   17980             : 
   17981             : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
   17982             :    of "return *this;" immediately before its location, using FNDECL's
   17983             :    first statement (if any) to give the indentation, if appropriate.  */
   17984             : 
   17985             : static void
   17986          24 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
   17987             : {
   17988          24 :   location_t indent = UNKNOWN_LOCATION;
   17989          24 :   tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
   17990          24 :   if (stmts)
   17991          12 :     indent = EXPR_LOCATION (stmts);
   17992          24 :   richloc->add_fixit_insert_formatted ("return *this;",
   17993             :                                        richloc->get_loc (),
   17994             :                                        indent);
   17995          24 : }
   17996             : 
   17997             : /* This function carries out the subset of finish_function operations needed
   17998             :    to emit the compiler-generated outlined helper functions used by the
   17999             :    coroutines implementation.  */
   18000             : 
   18001             : static void
   18002        2376 : emit_coro_helper (tree helper)
   18003             : {
   18004             :   /* This is a partial set of the operations done by finish_function()
   18005             :      plus emitting the result.  */
   18006        2376 :   set_cfun (NULL);
   18007        2376 :   current_function_decl = helper;
   18008        2376 :   begin_scope (sk_function_parms, NULL);
   18009        2376 :   store_parm_decls (DECL_ARGUMENTS (helper));
   18010        2376 :   announce_function (helper);
   18011        2376 :   allocate_struct_function (helper, false);
   18012        2376 :   cfun->language = ggc_cleared_alloc<language_function> ();
   18013        2376 :   poplevel (1, 0, 1);
   18014        2376 :   maybe_save_constexpr_fundef (helper);
   18015             :   /* We must start each function with a clear fold cache.  */
   18016        2376 :   clear_fold_cache ();
   18017        2376 :   cp_fold_function (helper);
   18018        2376 :   DECL_CONTEXT (DECL_RESULT (helper)) = helper;
   18019        2376 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (helper)) = helper;
   18020             :   /* This function has coroutine IFNs that we should handle in middle
   18021             :      end lowering.  */
   18022        2376 :   cfun->coroutine_component = true;
   18023        2376 :   cp_genericize (helper);
   18024        2376 :   expand_or_defer_fn (helper);
   18025        2376 : }
   18026             : 
   18027             : /* Finish up a function declaration and compile that function
   18028             :    all the way to assembler language output.  The free the storage
   18029             :    for the function definition. INLINE_P is TRUE if we just
   18030             :    finished processing the body of an in-class inline function
   18031             :    definition.  (This processing will have taken place after the
   18032             :    class definition is complete.)  */
   18033             : 
   18034             : tree
   18035    90434843 : finish_function (bool inline_p)
   18036             : {
   18037    90434843 :   tree fndecl = current_function_decl;
   18038    90434843 :   tree fntype, ctype = NULL_TREE;
   18039    90434843 :   tree resumer = NULL_TREE, destroyer = NULL_TREE;
   18040    90434843 :   bool coro_p = flag_coroutines
   18041     4698734 :                 && !processing_template_decl
   18042    92431646 :                 && DECL_COROUTINE_P (fndecl);
   18043    90434843 :   bool coro_emit_helpers = false;
   18044             : 
   18045             :   /* When we get some parse errors, we can end up without a
   18046             :      current_function_decl, so cope.  */
   18047    90434843 :   if (fndecl == NULL_TREE)
   18048           0 :     return error_mark_node;
   18049             : 
   18050    90434843 :   if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   18051    90434155 :     finish_lambda_scope ();
   18052             : 
   18053    90434843 :   if (c_dialect_objc ())
   18054           0 :     objc_finish_function ();
   18055             : 
   18056    90434843 :   record_key_method_defined (fndecl);
   18057             : 
   18058    90434843 :   fntype = TREE_TYPE (fndecl);
   18059             : 
   18060             :   /*  TREE_READONLY (fndecl) = 1;
   18061             :       This caused &foo to be of type ptr-to-const-function
   18062             :       which then got a warning when stored in a ptr-to-function variable.  */
   18063             : 
   18064    90434843 :   gcc_assert (building_stmt_list_p ());
   18065             :   /* The current function is being defined, so its DECL_INITIAL should
   18066             :      be set, and unless there's a multiple definition, it should be
   18067             :      error_mark_node.  */
   18068    90434843 :   gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
   18069             : 
   18070    90434843 :   if (coro_p)
   18071             :     {
   18072             :       /* Only try to emit the coroutine outlined helper functions if the
   18073             :          transforms succeeded.  Otherwise, treat errors in the same way as
   18074             :          a regular function.  */
   18075        1201 :       coro_emit_helpers = morph_fn_to_coro (fndecl, &resumer, &destroyer);
   18076             : 
   18077             :       /* We should handle coroutine IFNs in middle end lowering.  */
   18078        1201 :       cfun->coroutine_component = true;
   18079             : 
   18080             :       /* Do not try to process the ramp's EH unless outlining succeeded.  */
   18081        1201 :       if (coro_emit_helpers && use_eh_spec_block (fndecl))
   18082         381 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   18083             :                               (TREE_TYPE (fndecl)),
   18084         381 :                               current_eh_spec_block);
   18085             :     }
   18086             :   else
   18087             :   /* For a cloned function, we've already got all the code we need;
   18088             :      there's no need to add any extra bits.  */
   18089    90433642 :   if (!DECL_CLONED_FUNCTION_P (fndecl))
   18090             :     {
   18091             :       /* Make it so that `main' always returns 0 by default.  */
   18092    81639527 :       if (DECL_MAIN_FREESTANDING_P (current_function_decl)
   18093    81670420 :           && !TREE_THIS_VOLATILE (current_function_decl))
   18094       30893 :         finish_return_stmt (integer_zero_node);
   18095             : 
   18096    81639527 :       if (use_eh_spec_block (current_function_decl))
   18097    10840423 :         finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
   18098             :                               (TREE_TYPE (current_function_decl)),
   18099    10840423 :                               current_eh_spec_block);
   18100             :     }
   18101             : 
   18102             :   /* If we're saving up tree structure, tie off the function now.  */
   18103    90434843 :   DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
   18104             : 
   18105    90434843 :   finish_fname_decls ();
   18106             : 
   18107             :   /* This must come after expand_function_end because cleanups might
   18108             :      have declarations (from inline functions) that need to go into
   18109             :      this function's blocks.  */
   18110             : 
   18111             :   /* If the current binding level isn't the outermost binding level
   18112             :      for this function, either there is a bug, or we have experienced
   18113             :      syntax errors and the statement tree is malformed.  */
   18114    90434843 :   if (current_binding_level->kind != sk_function_parms)
   18115             :     {
   18116             :       /* Make sure we have already experienced errors.  */
   18117           4 :       gcc_assert (errorcount);
   18118             : 
   18119             :       /* Throw away the broken statement tree and extra binding
   18120             :          levels.  */
   18121           4 :       DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
   18122             : 
   18123           8 :       while (current_binding_level->kind != sk_function_parms)
   18124             :         {
   18125           4 :           if (current_binding_level->kind == sk_class)
   18126           0 :             pop_nested_class ();
   18127             :           else
   18128           4 :             poplevel (0, 0, 0);
   18129             :         }
   18130             :     }
   18131    90434843 :   poplevel (1, 0, 1);
   18132             : 
   18133             :   /* Statements should always be full-expressions at the outermost set
   18134             :      of curly braces for a function.  */
   18135    90434843 :   gcc_assert (stmts_are_full_exprs_p ());
   18136             : 
   18137             :   /* If there are no return statements in a function with auto return type,
   18138             :      the return type is void.  But if the declared type is something like
   18139             :      auto*, this is an error.  */
   18140    34436695 :   if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
   18141    90517947 :       && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   18142             :     {
   18143       38472 :       if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
   18144       38457 :           && !current_function_returns_value
   18145       38472 :           && !current_function_returns_null)
   18146             :         {
   18147             :           /* We haven't applied return type deduction because we haven't
   18148             :              seen any return statements. Do that now.  */
   18149       38318 :           tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   18150       38318 :           do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
   18151             :                              void_node, node, tf_warning_or_error,
   18152             :                              adc_return_type);
   18153             : 
   18154       38318 :           apply_deduced_return_type (fndecl, void_type_node);
   18155       38318 :           fntype = TREE_TYPE (fndecl);
   18156             :         }
   18157         154 :       else if (!current_function_returns_value
   18158         154 :                && !current_function_returns_null)
   18159             :         {
   18160          12 :           error ("no return statements in function returning %qT",
   18161           6 :                  DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
   18162           6 :           inform (input_location, "only plain %<auto%> return type can be "
   18163             :                   "deduced to %<void%>");
   18164             :         }
   18165             :     }
   18166             : 
   18167             :   /* Remember that we were in class scope.  */
   18168    90434843 :   if (current_class_name)
   18169    65566243 :     ctype = current_class_type;
   18170             : 
   18171    90434843 :   if (DECL_DELETED_FN (fndecl))
   18172             :     {
   18173          28 :       DECL_INITIAL (fndecl) = error_mark_node;
   18174          28 :       DECL_SAVED_TREE (fndecl) = NULL_TREE;
   18175          28 :       goto cleanup;
   18176             :     }
   18177             : 
   18178             :   // If this is a concept, check that the definition is reasonable.
   18179    90434815 :   if (DECL_DECLARED_CONCEPT_P (fndecl))
   18180         129 :     check_function_concept (fndecl);
   18181             : 
   18182    90434815 :   if (flag_openmp)
   18183       69745 :     if (tree attr = lookup_attribute ("omp declare variant base",
   18184       69745 :                                       DECL_ATTRIBUTES (fndecl)))
   18185         111 :       omp_declare_variant_finalize (fndecl, attr);
   18186             : 
   18187             :   /* Complain if there's just no return statement.  */
   18188    90434815 :   if ((warn_return_type
   18189       43719 :        || (cxx_dialect >= cxx14
   18190       36301 :            && DECL_DECLARED_CONSTEXPR_P (fndecl)))
   18191    90399279 :       && !VOID_TYPE_P (TREE_TYPE (fntype))
   18192    55356217 :       && !dependent_type_p (TREE_TYPE (fntype))
   18193    28276949 :       && !current_function_returns_value && !current_function_returns_null
   18194             :       /* Don't complain if we abort or throw.  */
   18195             :       && !current_function_returns_abnormally
   18196             :       /* Don't complain if there's an infinite loop.  */
   18197    28276949 :       && !current_function_infinite_loop
   18198             :       /* Don't complain if we are declared noreturn.  */
   18199         853 :       && !TREE_THIS_VOLATILE (fndecl)
   18200         845 :       && !DECL_NAME (DECL_RESULT (fndecl))
   18201         845 :       && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
   18202             :       /* Structor return values (if any) are set by the compiler.  */
   18203        1354 :       && !DECL_CONSTRUCTOR_P (fndecl)
   18204         677 :       && !DECL_DESTRUCTOR_P (fndecl)
   18205    90435492 :       && targetm.warn_func_return (fndecl))
   18206             :     {
   18207         669 :       gcc_rich_location richloc (input_location);
   18208             :       /* Potentially add a "return *this;" fix-it hint for
   18209             :          assignment operators.  */
   18210         669 :       if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
   18211             :         {
   18212          52 :           tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
   18213          52 :           if (TREE_CODE (valtype) == REFERENCE_TYPE
   18214          40 :               && current_class_ref
   18215          32 :               && same_type_ignoring_top_level_qualifiers_p
   18216          32 :                   (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
   18217          76 :               && global_dc->option_enabled (OPT_Wreturn_type,
   18218             :                                             global_dc->lang_mask,
   18219             :                                             global_dc->option_state))
   18220          24 :             add_return_star_this_fixit (&richloc, fndecl);
   18221             :         }
   18222         669 :       if (cxx_dialect >= cxx14
   18223         669 :           && DECL_DECLARED_CONSTEXPR_P (fndecl))
   18224           3 :         error_at (&richloc, "no return statement in %<constexpr%> function "
   18225             :                             "returning non-void");
   18226         666 :       else if (warning_at (&richloc, OPT_Wreturn_type,
   18227             :                            "no return statement in function returning "
   18228             :                            "non-void"))
   18229         200 :         suppress_warning (fndecl, OPT_Wreturn_type);
   18230         669 :     }
   18231             : 
   18232             :   /* Lambda closure members are implicitly constexpr if possible.  */
   18233    90434815 :   if (cxx_dialect >= cxx17
   18234   153248411 :       && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
   18235      292557 :     DECL_DECLARED_CONSTEXPR_P (fndecl)
   18236      292557 :       = ((processing_template_decl
   18237       80713 :           || is_valid_constexpr_fn (fndecl, /*complain*/false))
   18238      584644 :          && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
   18239             : 
   18240             :   /* Save constexpr function body before it gets munged by
   18241             :      the NRV transformation.   */
   18242    90434815 :   maybe_save_constexpr_fundef (fndecl);
   18243             : 
   18244             :   /* Invoke the pre-genericize plugin before we start munging things.  */
   18245    90434815 :   if (!processing_template_decl)
   18246    34436667 :     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
   18247             : 
   18248             :   /* Perform delayed folding before NRV transformation.  */
   18249    90434815 :   if (!processing_template_decl
   18250    68873334 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   18251   124870070 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   18252    34434735 :     cp_fold_function (fndecl);
   18253             : 
   18254             :   /* Set up the named return value optimization, if we can.  Candidate
   18255             :      variables are selected in check_return_expr.  */
   18256    90434815 :   if (tree r = current_function_return_value)
   18257             :     {
   18258    21307810 :       if (r != error_mark_node)
   18259      113509 :         finalize_nrv (fndecl, r);
   18260    21307810 :       current_function_return_value = NULL_TREE;
   18261             :     }
   18262             : 
   18263             :   /* Must mark the RESULT_DECL as being in this function.  */
   18264    90434815 :   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
   18265             : 
   18266             :   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
   18267             :      to the FUNCTION_DECL node itself.  */
   18268    90434815 :   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
   18269             : 
   18270             :   /* Store the end of the function, so that we get good line number
   18271             :      info for the epilogue.  */
   18272    90434815 :   cfun->function_end_locus = input_location;
   18273             : 
   18274             :   /* Complain about parameters that are only set, but never otherwise used.  */
   18275    90434815 :   if (warn_unused_but_set_parameter
   18276      812298 :       && !processing_template_decl
   18277      406481 :       && errorcount == unused_but_set_errorcount
   18278    90841296 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   18279             :     {
   18280      317243 :       tree decl;
   18281             : 
   18282      317243 :       for (decl = DECL_ARGUMENTS (fndecl);
   18283      858784 :            decl;
   18284      541541 :            decl = DECL_CHAIN (decl))
   18285      541541 :         if (TREE_USED (decl)
   18286      541541 :             && TREE_CODE (decl) == PARM_DECL
   18287      435627 :             && !DECL_READ_P (decl)
   18288           8 :             && DECL_NAME (decl)
   18289           8 :             && !DECL_ARTIFICIAL (decl)
   18290           8 :             && !warning_suppressed_p (decl,OPT_Wunused_but_set_parameter)
   18291           8 :             && !DECL_IN_SYSTEM_HEADER (decl)
   18292           8 :             && TREE_TYPE (decl) != error_mark_node
   18293           8 :             && !TYPE_REF_P (TREE_TYPE (decl))
   18294      541549 :             && (!CLASS_TYPE_P (TREE_TYPE (decl))
   18295           0 :                 || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
   18296           8 :           warning_at (DECL_SOURCE_LOCATION (decl),
   18297             :                       OPT_Wunused_but_set_parameter,
   18298             :                       "parameter %qD set but not used", decl);
   18299      317243 :       unused_but_set_errorcount = errorcount;
   18300             :     }
   18301             : 
   18302             :   /* Complain about locally defined typedefs that are not used in this
   18303             :      function.  */
   18304    90434815 :   maybe_warn_unused_local_typedefs ();
   18305             : 
   18306             :   /* Possibly warn about unused parameters.  */
   18307    90434815 :   if (warn_unused_parameter
   18308      561500 :       && !processing_template_decl 
   18309    90696485 :       && !DECL_CLONED_FUNCTION_P (fndecl))
   18310      199692 :     do_warn_unused_parameter (fndecl);
   18311             : 
   18312             :   /* Genericize before inlining.  */
   18313    90434815 :   if (!processing_template_decl
   18314    68873334 :       && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
   18315   124870070 :       && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
   18316    34434735 :     cp_genericize (fndecl);
   18317             : 
   18318             :   /* If this function can't throw any exceptions, remember that.  */
   18319    90434815 :   if (!processing_template_decl
   18320    34436667 :       && !cp_function_chain->can_throw
   18321    25358353 :       && !flag_non_call_exceptions
   18322   115788063 :       && !decl_replaceable_p (fndecl,
   18323    25353248 :                               opt_for_fn (fndecl, flag_semantic_interposition)))
   18324    25171646 :     TREE_NOTHROW (fndecl) = 1;
   18325             : 
   18326             :   /* Emit the resumer and destroyer functions now, providing that we have
   18327             :      not encountered some fatal error.  */
   18328    90434815 :   if (coro_emit_helpers)
   18329             :     {
   18330        1188 :       emit_coro_helper (resumer);
   18331        1188 :       emit_coro_helper (destroyer);
   18332             :     }
   18333             : 
   18334    90433627 :  cleanup:
   18335             :   /* We're leaving the context of this function, so zap cfun.  It's still in
   18336             :      DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation.  */
   18337    90434843 :   set_cfun (NULL);
   18338    90434843 :   current_function_decl = NULL;
   18339             : 
   18340             :   /* If this is an in-class inline definition, we may have to pop the
   18341             :      bindings for the template parameters that we added in
   18342             :      maybe_begin_member_template_processing when start_function was
   18343             :      called.  */
   18344    90434843 :   if (inline_p)
   18345    43396591 :     maybe_end_member_template_processing ();
   18346             : 
   18347             :   /* Leave the scope of the class.  */
   18348    90434843 :   if (ctype)
   18349    65566243 :     pop_nested_class ();
   18350             : 
   18351    90434843 :   --function_depth;
   18352             : 
   18353             :   /* Clean up.  */
   18354    90434843 :   current_function_decl = NULL_TREE;
   18355             : 
   18356    90434843 :   invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
   18357             : 
   18358    90434843 :   finish_function_contracts (fndecl);
   18359             : 
   18360    90434843 :   return fndecl;
   18361             : }
   18362             : 
   18363             : /* Create the FUNCTION_DECL for a function definition.
   18364             :    DECLSPECS and DECLARATOR are the parts of the declaration;
   18365             :    they describe the return type and the name of the function,
   18366             :    but twisted together in a fashion that parallels the syntax of C.
   18367             : 
   18368             :    This function creates a binding context for the function body
   18369             :    as well as setting up the FUNCTION_DECL in current_function_decl.
   18370             : 
   18371             :    Returns a FUNCTION_DECL on success.
   18372             : 
   18373             :    If the DECLARATOR is not suitable for a function (it defines a datum
   18374             :    instead), we return 0, which tells yyparse to report a parse error.
   18375             : 
   18376             :    May return void_type_node indicating that this method is actually
   18377             :    a friend.  See grokfield for more details.
   18378             : 
   18379             :    Came here with a `.pushlevel' .
   18380             : 
   18381             :    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
   18382             :    CHANGES TO CODE IN `grokfield'.  */
   18383             : 
   18384             : tree
   18385    43321946 : grokmethod (cp_decl_specifier_seq *declspecs,
   18386             :             const cp_declarator *declarator, tree attrlist)
   18387             : {
   18388    43321946 :   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
   18389    43321946 :                                 &attrlist);
   18390             : 
   18391    43321946 :   if (fndecl == error_mark_node)
   18392             :     return error_mark_node;
   18393             : 
   18394    43321839 :   if (attrlist)
   18395           0 :     cplus_decl_attributes (&fndecl, attrlist, 0);
   18396             : 
   18397             :   /* Pass friends other than inline friend functions back.  */
   18398    43321839 :   if (fndecl == void_type_node)
   18399             :     return fndecl;
   18400             : 
   18401    43321839 :   if (DECL_IN_AGGR_P (fndecl))
   18402             :     {
   18403           0 :       if (DECL_CLASS_SCOPE_P (fndecl))
   18404           0 :         error ("%qD is already defined in class %qT", fndecl,
   18405           0 :                DECL_CONTEXT (fndecl));
   18406           0 :       return error_mark_node;
   18407             :     }
   18408             : 
   18409    43321839 :   check_template_shadow (fndecl);
   18410             : 
   18411             :   /* p1779 ABI-Isolation makes inline not a default for in-class
   18412             :      definitions in named module purview.  If the user explicitly
   18413             :      made it inline, grokdeclarator will already have done the right
   18414             :      things.  */
   18415    43321839 :   if ((!named_module_purview_p ()
   18416         246 :        || flag_module_implicit_inline
   18417             :       /* Lambda's operator function remains inline.  */
   18418         477 :        || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
   18419             :       /* If the user explicitly asked for this to be inline, we don't
   18420             :          need to do more, but more importantly we want to warn if we
   18421             :          can't inline it.  */
   18422    43321605 :       && !DECL_DECLARED_INLINE_P (fndecl))
   18423             :     {
   18424    34818649 :       if (TREE_PUBLIC (fndecl))
   18425    34405484 :         DECL_COMDAT (fndecl) = 1;
   18426    34818649 :       DECL_DECLARED_INLINE_P (fndecl) = 1;
   18427             :       /* It's ok if we can't inline this.  */
   18428    34818649 :       DECL_NO_INLINE_WARNING_P (fndecl) = 1;
   18429             :     }
   18430             : 
   18431             :   /* We process method specializations in finish_struct_1.  */
   18432    43321839 :   if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
   18433             :     {
   18434             :       /* Avoid calling decl_spec_seq... until we have to.  */
   18435    35775151 :       bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
   18436    35775151 :       fndecl = push_template_decl (fndecl, friendp);
   18437    35775151 :       if (fndecl == error_mark_node)
   18438             :         return fndecl;
   18439             :     }
   18440             : 
   18441    43321830 :   if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
   18442             :     {
   18443           0 :       fndecl = copy_node (fndecl);
   18444           0 :       TREE_CHAIN (fndecl) = NULL_TREE;
   18445             :     }
   18446             : 
   18447    43321830 :   cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
   18448             : 
   18449    43321830 :   DECL_IN_AGGR_P (fndecl) = 1;
   18450    43321830 :   return fndecl;
   18451             : }
   18452             : 
   18453             : 
   18454             : /* VAR is a VAR_DECL.  If its type is incomplete, remember VAR so that
   18455             :    we can lay it out later, when and if its type becomes complete.
   18456             : 
   18457             :    Also handle constexpr variables where the initializer involves
   18458             :    an unlowered PTRMEM_CST because the class isn't complete yet.  */
   18459             : 
   18460             : void
   18461    54387082 : maybe_register_incomplete_var (tree var)
   18462             : {
   18463    54387082 :   gcc_assert (VAR_P (var));
   18464             : 
   18465             :   /* Keep track of variables with incomplete types.  */
   18466    23333127 :   if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
   18467    77718514 :       && DECL_EXTERNAL (var))
   18468             :     {
   18469     3821421 :       tree inner_type = TREE_TYPE (var);
   18470             : 
   18471     3936845 :       while (TREE_CODE (inner_type) == ARRAY_TYPE)
   18472      115424 :         inner_type = TREE_TYPE (inner_type);
   18473     3821421 :       inner_type = TYPE_MAIN_VARIANT (inner_type);
   18474             : 
   18475     3840356 :       if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
   18476             :           /* RTTI TD entries are created while defining the type_info.  */
   18477     3821421 :           || (TYPE_LANG_SPECIFIC (inner_type)
   18478     1538381 :               && TYPE_BEING_DEFINED (inner_type)))
   18479             :         {
   18480       18935 :           incomplete_var iv = {var, inner_type};
   18481       18935 :           vec_safe_push (incomplete_vars, iv);
   18482             :         }
   18483     7331867 :       else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
   18484     2476028 :                && decl_constant_var_p (var)
   18485     4329801 :                && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
   18486             :         {
   18487             :           /* When the outermost open class is complete we can resolve any
   18488             :              pointers-to-members.  */
   18489          13 :           tree context = outermost_open_class ();
   18490          13 :           incomplete_var iv = {var, context};
   18491          13 :           vec_safe_push (incomplete_vars, iv);
   18492             :         }
   18493             :     }
   18494    54387082 : }
   18495             : 
   18496             : /* Called when a class type (given by TYPE) is defined.  If there are
   18497             :    any existing VAR_DECLs whose type has been completed by this
   18498             :    declaration, update them now.  */
   18499             : 
   18500             : void
   18501    37164175 : complete_vars (tree type)
   18502             : {
   18503    37164175 :   unsigned ix;
   18504    37164175 :   incomplete_var *iv;
   18505             : 
   18506    39249200 :   for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
   18507             :     {
   18508     2085025 :       if (same_type_p (type, iv->incomplete_type))
   18509             :         {
   18510       17238 :           tree var = iv->decl;
   18511       17238 :           tree type = TREE_TYPE (var);
   18512             : 
   18513       17238 :           if (type != error_mark_node
   18514       17238 :               && (TYPE_MAIN_VARIANT (strip_array_types (type))
   18515       17234 :                   == iv->incomplete_type))
   18516             :             {
   18517             :               /* Complete the type of the variable.  */
   18518       17221 :               complete_type (type);
   18519       17221 :               cp_apply_type_quals_to_decl (cp_type_quals (type), var);
   18520       17221 :               if (COMPLETE_TYPE_P (type))
   18521       17201 :                 layout_var_decl (var);
   18522             :             }
   18523             : 
   18524             :           /* Remove this entry from the list.  */
   18525       17238 :           incomplete_vars->unordered_remove (ix);
   18526             :         }
   18527             :       else
   18528     2067787 :         ix++;
   18529             :     }
   18530    37164175 : }
   18531             : 
   18532             : /* If DECL is of a type which needs a cleanup, build and return an
   18533             :    expression to perform that cleanup here.  Return NULL_TREE if no
   18534             :    cleanup need be done.  DECL can also be a _REF when called from
   18535             :    split_nonconstant_init_1.  */
   18536             : 
   18537             : tree
   18538    32521292 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
   18539             : {
   18540    32521292 :   tree type;
   18541    32521292 :   tree attr;
   18542    32521292 :   tree cleanup;
   18543             : 
   18544             :   /* Assume no cleanup is required.  */
   18545    32521292 :   cleanup = NULL_TREE;
   18546             : 
   18547    32521292 :   if (error_operand_p (decl))
   18548             :     return cleanup;
   18549             : 
   18550             :   /* Handle "__attribute__((cleanup))".  We run the cleanup function
   18551             :      before the destructor since the destructor is what actually
   18552             :      terminates the lifetime of the object.  */
   18553    32521292 :   if (DECL_P (decl))
   18554    32481709 :     attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
   18555             :   else
   18556             :     attr = NULL_TREE;
   18557    32481709 :   if (attr)
   18558             :     {
   18559         114 :       tree id;
   18560         114 :       tree fn;
   18561         114 :       tree arg;
   18562             : 
   18563             :       /* Get the name specified by the user for the cleanup function.  */
   18564         114 :       id = TREE_VALUE (TREE_VALUE (attr));
   18565             :       /* Look up the name to find the cleanup function to call.  It is
   18566             :          important to use lookup_name here because that is what is
   18567             :          used in c-common.cc:handle_cleanup_attribute when performing
   18568             :          initial checks on the attribute.  Note that those checks
   18569             :          include ensuring that the function found is not an overloaded
   18570             :          function, or an object with an overloaded call operator,
   18571             :          etc.; we can rely on the fact that the function found is an
   18572             :          ordinary FUNCTION_DECL.  */
   18573         114 :       fn = lookup_name (id);
   18574         114 :       arg = build_address (decl);
   18575         114 :       if (!mark_used (decl, complain) && !(complain & tf_error))
   18576           0 :         return error_mark_node;
   18577         114 :       cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
   18578         114 :       if (cleanup == error_mark_node)
   18579             :         return error_mark_node;
   18580             :     }
   18581             :   /* Handle ordinary C++ destructors.  */
   18582    32521284 :   type = TREE_TYPE (decl);
   18583    32521284 :   if (type_build_dtor_call (type))
   18584             :     {
   18585     3087190 :       int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
   18586     3087190 :       tree addr;
   18587     3087190 :       tree call;
   18588             : 
   18589     3087190 :       if (TREE_CODE (type) == ARRAY_TYPE)
   18590             :         addr = decl;
   18591             :       else
   18592     3085622 :         addr = build_address (decl);
   18593             : 
   18594     3087190 :       call = build_delete (input_location, TREE_TYPE (addr), addr,
   18595             :                            sfk_complete_destructor, flags, 0, complain);
   18596     3087190 :       if (call == error_mark_node)
   18597             :         cleanup = error_mark_node;
   18598     3087163 :       else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
   18599             :         /* Discard the call.  */;
   18600     2478762 :       else if (decl_maybe_constant_destruction (decl, type)
   18601     2478809 :                && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
   18602          47 :         cxx_constant_dtor (call, decl);
   18603     2478715 :       else if (cleanup)
   18604           4 :         cleanup = cp_build_compound_expr (cleanup, call, complain);
   18605             :       else
   18606             :         cleanup = call;
   18607             :     }
   18608             : 
   18609             :   /* build_delete sets the location of the destructor call to the
   18610             :      current location, even though the destructor is going to be
   18611             :      called later, at the end of the current scope.  This can lead to
   18612             :      a "jumpy" behavior for users of debuggers when they step around
   18613             :      the end of the block.  So let's unset the location of the
   18614             :      destructor call instead.  */
   18615    32521284 :   protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
   18616    32521284 :   if (cleanup && CONVERT_EXPR_P (cleanup))
   18617           0 :     protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
   18618             : 
   18619           0 :   if (cleanup
   18620     2478844 :       && DECL_P (decl)
   18621     2478740 :       && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
   18622             :       /* Treat objects with destructors as used; the destructor may do
   18623             :          something substantive.  */
   18624     2478732 :       && !mark_used (decl, complain) && !(complain & tf_error))
   18625           0 :     return error_mark_node;
   18626             : 
   18627     2478844 :   if (cleanup && cfun && !processing_template_decl
   18628    34687847 :       && !expr_noexcept_p (cleanup, tf_none))
   18629        3529 :     cp_function_chain->throwing_cleanup = true;
   18630             : 
   18631             :   return cleanup;
   18632             : }
   18633             : 
   18634             : 
   18635             : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
   18636             :    FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
   18637             :    METHOD_TYPE or FUNCTION_TYPE, or pointer to member function.  */
   18638             : 
   18639             : tree
   18640     1135039 : static_fn_type (tree memfntype)
   18641             : {
   18642     1135039 :   tree fntype;
   18643     1135039 :   tree args;
   18644             : 
   18645     1135039 :   if (TYPE_PTRMEMFUNC_P (memfntype))
   18646       43085 :     memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
   18647     1135039 :   if (INDIRECT_TYPE_P (memfntype)
   18648      970260 :       || TREE_CODE (memfntype) == FUNCTION_DECL)
   18649     1009179 :     memfntype = TREE_TYPE (memfntype);
   18650     1135039 :   if (TREE_CODE (memfntype) == FUNCTION_TYPE)
   18651             :     return memfntype;
   18652      318613 :   gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
   18653      318613 :   args = TYPE_ARG_TYPES (memfntype);
   18654      318613 :   fntype = build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
   18655      318613 :   fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
   18656      318613 :   fntype = (cp_build_type_attribute_variant
   18657      318613 :             (fntype, TYPE_ATTRIBUTES (memfntype)));
   18658      318613 :   fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
   18659      318613 :   return fntype;
   18660             : }
   18661             : 
   18662             : /* DECL was originally constructed as a non-static member function,
   18663             :    but turned out to be static.  Update it accordingly.  */
   18664             : 
   18665             : void
   18666      108111 : revert_static_member_fn (tree decl)
   18667             : {
   18668      108111 :   tree stype = static_fn_type (decl);
   18669      108111 :   cp_cv_quals quals = type_memfn_quals (stype);
   18670      108111 :   cp_ref_qualifier rqual = type_memfn_rqual (stype);
   18671             : 
   18672      108111 :   if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
   18673           7 :     stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
   18674             : 
   18675      108111 :   TREE_TYPE (decl) = stype;
   18676             : 
   18677      108111 :   if (DECL_ARGUMENTS (decl))
   18678      108111 :     DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
   18679      108111 :   DECL_STATIC_FUNCTION_P (decl) = 1;
   18680      108111 : }
   18681             : 
   18682             : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
   18683             :    one of the language-independent trees.  */
   18684             : 
   18685             : enum cp_tree_node_structure_enum
   18686 22025345353 : cp_tree_node_structure (union lang_tree_node * t)
   18687             : {
   18688 22025345353 :   switch (TREE_CODE (&t->generic))
   18689             :     {
   18690             :     case ARGUMENT_PACK_SELECT:  return TS_CP_ARGUMENT_PACK_SELECT;
   18691    95410522 :     case BASELINK:              return TS_CP_BASELINK;
   18692     3438768 :     case CONSTRAINT_INFO:       return TS_CP_CONSTRAINT_INFO;
   18693     6096084 :     case DEFERRED_NOEXCEPT:     return TS_CP_DEFERRED_NOEXCEPT;
   18694     1978305 :     case DEFERRED_PARSE:        return TS_CP_DEFERRED_PARSE;
   18695  1453359788 :     case IDENTIFIER_NODE:       return TS_CP_IDENTIFIER;
   18696      475543 :     case LAMBDA_EXPR:           return TS_CP_LAMBDA_EXPR;
   18697      316219 :     case BINDING_VECTOR:                return TS_CP_BINDING_VECTOR;
   18698   419083981 :     case OVERLOAD:              return TS_CP_OVERLOAD;
   18699        1090 :     case PTRMEM_CST:            return TS_CP_PTRMEM;
   18700     9984671 :     case STATIC_ASSERT:         return TS_CP_STATIC_ASSERT;
   18701   434162763 :     case TEMPLATE_DECL:         return TS_CP_TEMPLATE_DECL;
   18702   956683862 :     case TEMPLATE_INFO:         return TS_CP_TEMPLATE_INFO;
   18703   431637319 :     case TEMPLATE_PARM_INDEX:   return TS_CP_TPI;
   18704     9017841 :     case TRAIT_EXPR:            return TS_CP_TRAIT_EXPR;
   18705     1669735 :     case USERDEF_LITERAL:       return TS_CP_USERDEF_LITERAL;
   18706 18202028862 :     default:                    return TS_CP_GENERIC;
   18707             :     }
   18708             : }
   18709             : 
   18710             : bool
   18711        7475 : cp_missing_noreturn_ok_p (tree decl)
   18712             : {
   18713             :   /* A missing noreturn is ok for the `main' function.  */
   18714        7475 :   return DECL_MAIN_P (decl);
   18715             : }
   18716             : 
   18717             : /* Return the decl used to identify the COMDAT group into which DECL should
   18718             :    be placed.  */
   18719             : 
   18720             : tree
   18721    41355946 : cxx_comdat_group (tree decl)
   18722             : {
   18723             :   /* Virtual tables, construction virtual tables, and virtual table
   18724             :      tables all go in a single COMDAT group, named after the primary
   18725             :      virtual table.  */
   18726    41355946 :   if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
   18727      272557 :     decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
   18728             :   /* For all other DECLs, the COMDAT group is the mangled name of the
   18729             :      declaration itself.  */
   18730             :   else
   18731             :     {
   18732    41083389 :       while (DECL_THUNK_P (decl))
   18733             :         {
   18734             :           /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
   18735             :              into the same section as the target function.  In that case
   18736             :              we must return target's name.  */
   18737           0 :           tree target = THUNK_TARGET (decl);
   18738           0 :           if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
   18739           0 :               && DECL_SECTION_NAME (target) != NULL
   18740           0 :               && DECL_ONE_ONLY (target))
   18741             :             decl = target;
   18742             :           else
   18743             :             break;
   18744             :         }
   18745             :     }
   18746             : 
   18747    41355946 :   return decl;
   18748             : }
   18749             : 
   18750             : /* Returns the return type for FN as written by the user, which may include
   18751             :    a placeholder for a deduced return type.  */
   18752             : 
   18753             : tree
   18754   313869880 : fndecl_declared_return_type (tree fn)
   18755             : {
   18756   313869880 :   fn = STRIP_TEMPLATE (fn);
   18757   313869880 :   if (FNDECL_USED_AUTO (fn))
   18758        1532 :     return DECL_SAVED_AUTO_RETURN_TYPE (fn);
   18759             : 
   18760   313868348 :   return TREE_TYPE (TREE_TYPE (fn));
   18761             : }
   18762             : 
   18763             : /* Returns true iff DECL is a variable or function declared with an auto type
   18764             :    that has not yet been deduced to a real type.  */
   18765             : 
   18766             : bool
   18767   333513458 : undeduced_auto_decl (tree decl)
   18768             : {
   18769   333513458 :   if (cxx_dialect < cxx11)
   18770             :     return false;
   18771   331721010 :   STRIP_ANY_LOCATION_WRAPPER (decl);
   18772   331721010 :   return ((VAR_OR_FUNCTION_DECL_P (decl)
   18773   136833070 :            || TREE_CODE (decl) == TEMPLATE_DECL)
   18774   331745162 :           && type_uses_auto (TREE_TYPE (decl)));
   18775             : }
   18776             : 
   18777             : /* Complain if DECL has an undeduced return type.  */
   18778             : 
   18779             : bool
   18780   192804955 : require_deduced_type (tree decl, tsubst_flags_t complain)
   18781             : {
   18782   192804955 :   if (undeduced_auto_decl (decl))
   18783             :     {
   18784         207 :       if (TREE_CODE (decl) == FUNCTION_DECL
   18785         181 :           && fndecl_built_in_p (decl, BUILT_IN_FRONTEND)
   18786         252 :           && DECL_FE_FUNCTION_CODE (decl) == CP_BUILT_IN_SOURCE_LOCATION)
   18787             :         {
   18788             :           /* Set the return type of __builtin_source_location.  */
   18789          45 :           tree type = get_source_location_impl_type ();
   18790          45 :           if (type == error_mark_node)
   18791             :             {
   18792          11 :               inform (input_location, "using %qs", "__builtin_source_location");
   18793          11 :               return false;
   18794             :             }
   18795          34 :           type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
   18796          34 :           type = build_pointer_type (type);
   18797          34 :           apply_deduced_return_type (decl, type);
   18798          34 :           return true;
   18799             :         }
   18800             : 
   18801         162 :       if (warning_suppressed_p (decl) && seen_error ())
   18802             :         /* We probably already complained about deduction failure.  */;
   18803          65 :       else if (complain & tf_error)
   18804          52 :         error ("use of %qD before deduction of %<auto%>", decl);
   18805         162 :       note_failed_type_completion_for_satisfaction (decl);
   18806         162 :       return false;
   18807             :     }
   18808             :   return true;
   18809             : }
   18810             : 
   18811             : /* Create a representation of the explicit-specifier with
   18812             :    constant-expression of EXPR.  COMPLAIN is as for tsubst.  */
   18813             : 
   18814             : tree
   18815     3543064 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
   18816             : {
   18817     3543064 :   if (check_for_bare_parameter_packs (expr))
   18818           1 :     return error_mark_node;
   18819             : 
   18820     3543063 :   if (instantiation_dependent_expression_p (expr))
   18821             :     /* Wait for instantiation, tsubst_function_decl will handle it.  */
   18822             :     return expr;
   18823             : 
   18824     3521693 :   expr = build_converted_constant_bool_expr (expr, complain);
   18825     3521693 :   expr = instantiate_non_dependent_expr (expr, complain);
   18826     3521693 :   expr = cxx_constant_value (expr, complain);
   18827     3521693 :   return expr;
   18828             : }
   18829             : 
   18830             : #include "gt-cp-decl.h"

Generated by: LCOV version 1.16